index: Access functions for global block filter indexes.

This commit is contained in:
Jim Posen
2018-08-30 08:30:23 -07:00
parent 2bc90e4e7b
commit accc8b8b18
3 changed files with 98 additions and 0 deletions

View File

@@ -265,4 +265,43 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, TestChain100Setup)
filter_index.Stop();
}
BOOST_FIXTURE_TEST_CASE(blockfilter_index_init_destroy, BasicTestingSetup)
{
SetDataDir("tempdir");
BlockFilterIndex* filter_index;
filter_index = GetBlockFilterIndex(BlockFilterType::BASIC);
BOOST_CHECK(filter_index == nullptr);
BOOST_CHECK(InitBlockFilterIndex(BlockFilterType::BASIC, 1 << 20, true, false));
filter_index = GetBlockFilterIndex(BlockFilterType::BASIC);
BOOST_CHECK(filter_index != nullptr);
BOOST_CHECK(filter_index->GetFilterType() == BlockFilterType::BASIC);
// Initialize returns false if index already exists.
BOOST_CHECK(!InitBlockFilterIndex(BlockFilterType::BASIC, 1 << 20, true, false));
int iter_count = 0;
ForEachBlockFilterIndex([&iter_count](BlockFilterIndex& _index) { iter_count++; });
BOOST_CHECK_EQUAL(iter_count, 1);
BOOST_CHECK(DestroyBlockFilterIndex(BlockFilterType::BASIC));
// Destroy returns false because index was already destroyed.
BOOST_CHECK(!DestroyBlockFilterIndex(BlockFilterType::BASIC));
filter_index = GetBlockFilterIndex(BlockFilterType::BASIC);
BOOST_CHECK(filter_index == nullptr);
// Reinitialize index.
BOOST_CHECK(InitBlockFilterIndex(BlockFilterType::BASIC, 1 << 20, true, false));
DestroyAllBlockFilterIndexes();
filter_index = GetBlockFilterIndex(BlockFilterType::BASIC);
BOOST_CHECK(filter_index == nullptr);
}
BOOST_AUTO_TEST_SUITE_END()