public void TestOpenBundle() { RunTestVariants(() => { string bundleDBName = "cbl_core_test_bundle"; var config2 = C4DatabaseConfig2.Clone(Native.c4db_getConfig2(Db)); var tmp = config2; var bundlePath = Path.Combine(TestDir, $"{bundleDBName}.cblite2{Path.DirectorySeparatorChar}"); Native.c4db_deleteNamed(bundleDBName, TestDir, null); var bundle = (C4Database *)LiteCoreBridge.Check(err => { var localConfig = tmp; return(Native.c4db_openNamed(bundleDBName, &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_release(bundle); // Reopen without the 'create' flag: config2.flags &= ~C4DatabaseFlags.Create; tmp = config2; bundle = (C4Database *)LiteCoreBridge.Check(err => { var localConfig = tmp; return(Native.c4db_openNamed(bundleDBName, &localConfig, err)); }); LiteCoreBridge.Check(err => Native.c4db_close(bundle, err)); Native.c4db_release(bundle); // Open nonexistent bundle ((long)Native.c4db_openNamed($"no_such_bundle{Path.DirectorySeparatorChar}", &config2, null)).Should().Be(0, "because the bundle does not exist"); NativePrivate.c4log_warnOnErrors(true); }); }
protected override void SetupVariant(int option) { _objectCount = Native.c4_getObjectCount(); Native.c4_shutdown(null); var encryptedStr = (option & 1) == 1 ? "encrypted " : String.Empty; WriteLine($"Opening {encryptedStr} SQLite database"); C4Error err; var encryptionKey = new C4EncryptionKey(); if ((option & 1) == 1) { encryptionKey.algorithm = C4EncryptionAlgorithm.AES256; var i = 0; foreach (var b in Encoding.UTF8.GetBytes("this is not a random key at all.")) { encryptionKey.bytes[i++] = b; } } DBConfig2 = new C4DatabaseConfig2() { ParentDirectory = TestDir, flags = C4DatabaseFlags.Create | C4DatabaseFlags.SharedKeys, encryptionKey = encryptionKey }; LiteCoreBridge.Check(error => Native.c4db_deleteNamed(DBName, TestDir, error)); var config = DBConfig2; Db = Native.c4db_openNamed(DBName, &config, &err); ((long)Db).Should().NotBe(0, "because otherwise the database failed to open"); }