public void TestOpenBundle()
        {
            RunTestVariants(() => {
                var config    = C4DatabaseConfig.Clone(Native.c4db_getConfig(Db));
                config.flags |= C4DatabaseFlags.Bundled;
                var tmp       = config;

                var bundlePath = Path.Combine(TestDir, "cbl_core_test_bundle") + "/";
                Native.c4db_deleteAtPath(bundlePath, &config, null);
                var bundle = (C4Database *)LiteCoreBridge.Check(err => {
                    var localConfig = tmp;
                    return(Native.c4db_open(bundlePath, &localConfig, err));
                });

                var path = Native.c4db_getPath(bundle);
                path.Should().Be(bundlePath, "because the database should store the correct path");
                LiteCoreBridge.Check(err => Native.c4db_close(bundle, err));
                Native.c4db_free(bundle);

                // Reopen without the 'create' flag:
                config.flags &= ~C4DatabaseFlags.Create;
                tmp           = config;
                bundle        = (C4Database *)LiteCoreBridge.Check(err => {
                    var localConfig = tmp;
                    return(Native.c4db_open(bundlePath, &localConfig, err));
                });
                LiteCoreBridge.Check(err => Native.c4db_close(bundle, err));
                Native.c4db_free(bundle);

                // Reopen with wrong storage type:
                Native.c4log_warnOnErrors(false);
                if (config.storageEngine == C4StorageEngine.SQLite)
                {
                    config.storageEngine = C4StorageEngine.ForestDB;
                }
                else
                {
                    config.storageEngine = C4StorageEngine.SQLite;
                }

                C4Error error;
                ((long)Native.c4db_open(bundlePath, &config, &error)).Should().Be(0,
                                                                                  "because the storage engine is invalid");

                ((long)Native.c4db_open(Path.Combine(TestDir, "no_such_bundle"), &config, &error)).Should().Be(0,
                                                                                                               "because the storage engine is invalid");
                Native.c4log_warnOnErrors(true);
                config.Dispose();
            });
        }
Пример #2
0
        public void TestOpenBundle()
        {
            RunTestVariants(() => {
                var config    = C4DatabaseConfig.Clone(Native.c4db_getConfig(Db));
                config.flags |= C4DatabaseFlags.Bundled;
                var tmp       = config;

                var bundlePath = Path.Combine(TestDir, $"cbl_core_test_bundle{Path.DirectorySeparatorChar}");
                Native.c4db_deleteAtPath(bundlePath, &config, null);
                var bundle = (C4Database *)LiteCoreBridge.Check(err => {
                    var localConfig = tmp;
                    return(Native.c4db_open(bundlePath, &localConfig, err));
                });

                var path = Native.c4db_getPath(bundle);
                path.Should().Be(bundlePath, "because the database should store the correct path");
                LiteCoreBridge.Check(err => Native.c4db_close(bundle, err));
                Native.c4db_free(bundle);

                // Reopen without the 'create' flag:
                config.flags &= ~C4DatabaseFlags.Create;
                tmp           = config;
                bundle        = (C4Database *)LiteCoreBridge.Check(err => {
                    var localConfig = tmp;
                    return(Native.c4db_open(bundlePath, &localConfig, err));
                });
                LiteCoreBridge.Check(err => Native.c4db_close(bundle, err));
                Native.c4db_free(bundle);

                // Reopen with wrong storage type:
                NativePrivate.c4log_warnOnErrors(false);
                var engine           = config.storageEngine;
                config.storageEngine = "b0gus";
                ((long)Native.c4db_open(bundlePath, &config, null)).Should().Be(0, "because the storage engine is nonsense");
                config.storageEngine = engine;

                // Open nonexistent bundle
                ((long)Native.c4db_open($"no_such_bundle{Path.DirectorySeparatorChar}", &config, null)).Should().Be(0, "because the bundle does not exist");
                NativePrivate.c4log_warnOnErrors(true);

                config.Dispose();
            });
        }