summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2024-03-11 23:07:25 +0100
committerTor Egge <Tor.Egge@online.no>2024-03-11 23:07:25 +0100
commit6c2559902b36f19b05a6a238dd2df9561c62c0c6 (patch)
tree20d066c4350399bdcd5e222173964a07b2e8da63
parent3de0460b18304c733effe35b763f73b48db5ba7f (diff)
Rewrite searchlib attribute posting list unit test to gtest.
-rw-r--r--searchlib/src/tests/attribute/postinglist/CMakeLists.txt1
-rw-r--r--searchlib/src/tests/attribute/postinglist/postinglist_test.cpp42
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 <vespa/vespalib/btree/btreestore.hpp>
#include <vespa/vespalib/datastore/datastore.h>
#include <vespa/vespalib/util/rand48.h>
-#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/gtest/gtest.h>
#include <set>
#include <map>
#include <cinttypes>
@@ -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<uint32_t>;
using STLValueTree = std::map<int, STLPostingList>;
@@ -96,7 +96,6 @@ private:
};
std::vector<RandomValue> _randomValues;
-public:
using IntKeyStore = vespalib::datastore::DataStore<int>;
using AttributePosting = vespalib::btree::BTreeKeyData<uint32_t, vespalib::btree::BTreeNoLeafData>;
using PostingList = vespalib::btree::BTreeStore<uint32_t,
@@ -134,7 +133,7 @@ public:
using TreeManager = IntEnumNodeAllocator;
using ValueHandle = IntKeyStore;
using RandomValuesVector = std::vector<RandomValue>;
-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()