From 6c2559902b36f19b05a6a238dd2df9561c62c0c6 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Mon, 11 Mar 2024 23:07:25 +0100 Subject: Rewrite searchlib attribute posting list unit test to gtest. --- .../src/tests/attribute/postinglist/CMakeLists.txt | 1 + .../attribute/postinglist/postinglist_test.cpp | 42 ++++++++-------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/searchlib/src/tests/attribute/postinglist/CMakeLists.txt b/searchlib/src/tests/attribute/postinglist/CMakeLists.txt index 20e2dff1b13..e88b37696fc 100644 --- a/searchlib/src/tests/attribute/postinglist/CMakeLists.txt +++ b/searchlib/src/tests/attribute/postinglist/CMakeLists.txt @@ -4,5 +4,6 @@ vespa_add_executable(searchlib_postinglist_test_app TEST postinglist_test.cpp DEPENDS searchlib + GTest::gtest ) vespa_add_test(NAME searchlib_postinglist_test_app COMMAND searchlib_postinglist_test_app) diff --git a/searchlib/src/tests/attribute/postinglist/postinglist_test.cpp b/searchlib/src/tests/attribute/postinglist/postinglist_test.cpp index c6b627f97e2..16b28d038c5 100644 --- a/searchlib/src/tests/attribute/postinglist/postinglist_test.cpp +++ b/searchlib/src/tests/attribute/postinglist/postinglist_test.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include @@ -24,9 +24,9 @@ using vespalib::GenerationHandler; * TODO: Make it pass MALLOC_OPTIONS=AJ on freebsd and valgrind on Linux. */ -class AttributePostingListTest : public vespalib::TestApp +class AttributePostingListTest : public ::testing::Test { -private: +protected: /* Limited STL version for validation of full version */ using STLPostingList = std::set; using STLValueTree = std::map; @@ -96,7 +96,6 @@ private: }; std::vector _randomValues; -public: using IntKeyStore = vespalib::datastore::DataStore; using AttributePosting = vespalib::btree::BTreeKeyData; using PostingList = vespalib::btree::BTreeStore; -private: + GenerationHandler _handler; IntKeyStore *_intKeyStore; IntEnumNodeAllocator *_intNodeAlloc; @@ -210,15 +209,12 @@ private: { return frozen ? "frozen" : "thawed"; } -public: AttributePostingListTest(); - ~AttributePostingListTest(); - - int Main() override; + ~AttributePostingListTest() override; }; AttributePostingListTest::AttributePostingListTest() - : vespalib::TestApp(), + : ::testing::Test(), _randomValues(), _handler(), _intKeyStore(NULL), @@ -228,7 +224,8 @@ AttributePostingListTest::AttributePostingListTest() _stlTree(NULL), _randomGenerator() {} -AttributePostingListTest::~AttributePostingListTest() {} + +AttributePostingListTest::~AttributePostingListTest() = default; void AttributePostingListTest::allocTree() @@ -368,7 +365,7 @@ insertRandomValues(Tree &tree, } else { } ASSERT_TRUE(itr.valid()); - EXPECT_EQUAL(i->_value, valueHandle.getEntry(itr.getKey())); + EXPECT_EQ(i->_value, valueHandle.getEntry(itr.getKey())); /* TODO: Insert docid to postinglist */ PostingIdx oldIdx = itr.getData(); @@ -669,30 +666,21 @@ reclaim_memory(Tree &tree, postings.reclaim_memory(_handler.get_oldest_used_generation()); } -int -AttributePostingListTest::Main() +TEST_F(AttributePostingListTest, test_posting_list) { - TEST_INIT("postinglist_test"); - fillRandomValues(1000, 10); allocTree(); - insertRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings, - _stlTree, _randomValues); - lookupRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings, - _stlTree, _randomValues); + ASSERT_NO_FATAL_FAILURE(insertRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings, _stlTree, _randomValues)); + ASSERT_NO_FATAL_FAILURE(lookupRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings, _stlTree, _randomValues)); _intNodeAlloc->freeze(); _intNodeAlloc->assign_generation(_handler.getCurrentGeneration()); doCompactEnumStore(*_intTree, *_intNodeAlloc, *_intKeyStore); - removeRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings, - _stlTree, _randomValues); - insertRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings, - _stlTree, _randomValues); + ASSERT_NO_FATAL_FAILURE(removeRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings, _stlTree, _randomValues)); + ASSERT_NO_FATAL_FAILURE(insertRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings, _stlTree, _randomValues)); freeTree(true); - - TEST_DONE(); } } -TEST_APPHOOK(search::AttributePostingListTest); +GTEST_MAIN_RUN_ALL_TESTS() -- cgit v1.2.3