void InMemoryDatabase::close() { VLOG(1) << "Closing db... "; debug_only::verifyTrue(is_open_, "database is not open"); is_open_ = false; auto status = destroyDB(); debug_only::verifyTrue(status.isValue(), "InMemoryDatabase::destroyDB couldn't fail"); }
void ClingoPropagator::destroy(Solver* s, bool detach) { if (s && detach) { for (Var v = 1; v <= s->numVars(); ++v) { s->removeWatch(posLit(v), this); s->removeWatch(negLit(v), this); } } destroyDB(db_, s, detach); PostPropagator::destroy(s, detach); }
GTEST_TEST(InMemoryDatabaseTest, test_destroy) { auto db = std::make_unique<InMemoryDatabase>("test"); ASSERT_FALSE(db->open().isError()); ASSERT_FALSE(db->putInt32(kPersistentSettings, "key", 10).isError()); db->close(); // In memory db should be destroyed on close // but we want to test that destroy is not failing for no reason auto result = db->destroyDB(); EXPECT_TRUE(result); ASSERT_FALSE(db->open().isError()); auto get_result = db->getInt32(kPersistentSettings, "key"); EXPECT_FALSE(get_result); EXPECT_EQ(get_result.getError(), DatabaseError::KeyNotFound); }