aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-01-03 18:36:46 +0100
committerGitHub <noreply@github.com>2024-01-03 18:36:46 +0100
commit776ace0650b26fd6ba0e1452c81c139d7554834d (patch)
treecdea7c473cdaaf97b2818bcfb9841edaa1be9a4c
parentec85223814c612a4cf2abb4e99c30e7a53605b38 (diff)
parentc24931ca041a3027e9ae38b00ffa67f93d684ddc (diff)
Merge pull request #29789 from vespa-engine/geirst/direct-posting-store-gtestv8.282.24
Rewrite unit tests to GTest.
-rw-r--r--searchlib/src/tests/attribute/direct_posting_store/CMakeLists.txt1
-rw-r--r--searchlib/src/tests/attribute/direct_posting_store/direct_posting_store_test.cpp123
2 files changed, 65 insertions, 59 deletions
diff --git a/searchlib/src/tests/attribute/direct_posting_store/CMakeLists.txt b/searchlib/src/tests/attribute/direct_posting_store/CMakeLists.txt
index 0cb45e6b18f..3c8e76bc9b2 100644
--- a/searchlib/src/tests/attribute/direct_posting_store/CMakeLists.txt
+++ b/searchlib/src/tests/attribute/direct_posting_store/CMakeLists.txt
@@ -5,5 +5,6 @@ vespa_add_executable(searchlib_direct_posting_store_test_app TEST
DEPENDS
searchlib
searchlib_test
+ GTest::GTest
)
vespa_add_test(NAME searchlib_direct_posting_store_test_app COMMAND searchlib_direct_posting_store_test_app)
diff --git a/searchlib/src/tests/attribute/direct_posting_store/direct_posting_store_test.cpp b/searchlib/src/tests/attribute/direct_posting_store/direct_posting_store_test.cpp
index d6b0ff2a4b6..28039d30bfe 100644
--- a/searchlib/src/tests/attribute/direct_posting_store/direct_posting_store_test.cpp
+++ b/searchlib/src/tests/attribute/direct_posting_store/direct_posting_store_test.cpp
@@ -9,10 +9,11 @@
#include <vespa/searchlib/attribute/i_docid_with_weight_posting_store.h>
#include <vespa/searchlib/index/dummyfileheadercontext.h>
#include <vespa/searchlib/queryeval/docid_with_weight_search_iterator.h>
+#define ENABLE_GTEST_MIGRATION
#include <vespa/searchlib/test/searchiteratorverifier.h>
#include <vespa/searchlib/util/randomgenerator.h>
+#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/test/insertion_operators.h>
-#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/log/log.h>
LOG_SETUP("direct_posting_store_test");
@@ -32,7 +33,7 @@ void add_docs(AttributeVector::SP attr_ptr, size_t limit = 1000) {
attr_ptr->addDoc(docid);
}
attr_ptr->commit();
- ASSERT_EQUAL((limit - 1), docid);
+ ASSERT_EQ((limit - 1), docid);
}
template <typename ATTR, typename KEY>
@@ -56,36 +57,40 @@ void populate_string(AttributeVector::SP attr_ptr) {
set_doc(attr, 7, "foo", 10);
}
-struct LongFixture {
+struct DirectPostingStoreTest : public ::testing::Test {
AttributeVector::SP attr;
const IDocidWithWeightPostingStore *api;
- LongFixture() : attr(make_attribute(BasicType::INT64, CollectionType::WSET, true)),
- api(attr->as_docid_with_weight_posting_store())
+
+ DirectPostingStoreTest(BasicType type, CollectionType col_type)
+ : attr(make_attribute(type, col_type, true)),
+ api(attr->as_docid_with_weight_posting_store())
{
- ASSERT_TRUE(api != nullptr);
+ assert(api != nullptr);
add_docs(attr);
+ }
+ ~DirectPostingStoreTest() {}
+};
+
+struct DirectIntegerTest : public DirectPostingStoreTest {
+ DirectIntegerTest() : DirectPostingStoreTest(BasicType::INT64, CollectionType::WSET)
+ {
populate_long(attr);
}
};
-struct StringFixture {
- AttributeVector::SP attr;
- const IDocidWithWeightPostingStore *api;
- StringFixture() : attr(make_attribute(BasicType::STRING, CollectionType::WSET, true)),
- api(attr->as_docid_with_weight_posting_store())
+struct DirectStringTest : public DirectPostingStoreTest {
+ DirectStringTest() : DirectPostingStoreTest(BasicType::STRING, CollectionType::WSET)
{
- ASSERT_TRUE(api != nullptr);
- add_docs(attr);
populate_string(attr);
}
};
-TEST("require that appropriate attributes support the IDocidWithWeightPostingStore interface") {
+TEST(DirectPostingStoreApiTest, attributes_support_IDocidWithWeightPostingStore_interface) {
EXPECT_TRUE(make_attribute(BasicType::INT64, CollectionType::WSET, true)->as_docid_with_weight_posting_store() != nullptr);
EXPECT_TRUE(make_attribute(BasicType::STRING, CollectionType::WSET, true)->as_docid_with_weight_posting_store() != nullptr);
}
-TEST("require that inappropriate attributes do not support the IDocidWithWeightPostingStore interface") {
+TEST(DirectPostingStoreApiTest, attributes_do_not_support_IDocidWithWeightPostingStore_interface) {
EXPECT_TRUE(make_attribute(BasicType::INT64, CollectionType::SINGLE, false)->as_docid_with_weight_posting_store() == nullptr);
EXPECT_TRUE(make_attribute(BasicType::INT64, CollectionType::ARRAY, false)->as_docid_with_weight_posting_store() == nullptr);
EXPECT_TRUE(make_attribute(BasicType::INT64, CollectionType::WSET, false)->as_docid_with_weight_posting_store() == nullptr);
@@ -102,26 +107,26 @@ TEST("require that inappropriate attributes do not support the IDocidWithWeightP
void verify_valid_lookup(IDirectPostingStore::LookupResult result) {
EXPECT_TRUE(result.posting_idx.valid());
- EXPECT_EQUAL(3u, result.posting_size);
- EXPECT_EQUAL(5, result.min_weight);
- EXPECT_EQUAL(20, result.max_weight);
+ EXPECT_EQ(3u, result.posting_size);
+ EXPECT_EQ(5, result.min_weight);
+ EXPECT_EQ(20, result.max_weight);
}
void verify_invalid_lookup(IDirectPostingStore::LookupResult result) {
EXPECT_FALSE(result.posting_idx.valid());
- EXPECT_EQUAL(0u, result.posting_size);
- EXPECT_EQUAL(0, result.min_weight);
- EXPECT_EQUAL(0, result.max_weight);
+ EXPECT_EQ(0u, result.posting_size);
+ EXPECT_EQ(0, result.min_weight);
+ EXPECT_EQ(0, result.max_weight);
}
-TEST_F("require that integer lookup works correctly", LongFixture) {
- verify_valid_lookup(f1.api->lookup("111", f1.api->get_dictionary_snapshot()));
- verify_invalid_lookup(f1.api->lookup("222", f1.api->get_dictionary_snapshot()));
+TEST_F(DirectIntegerTest, lookup_works_correctly) {
+ verify_valid_lookup(api->lookup("111", api->get_dictionary_snapshot()));
+ verify_invalid_lookup(api->lookup("222", api->get_dictionary_snapshot()));
}
-TEST_F("require string lookup works correctly", StringFixture) {
- verify_valid_lookup(f1.api->lookup("foo", f1.api->get_dictionary_snapshot()));
- verify_invalid_lookup(f1.api->lookup("bar", f1.api->get_dictionary_snapshot()));
+TEST_F(DirectStringTest, lookup_works_correctly) {
+ verify_valid_lookup(api->lookup("foo", api->get_dictionary_snapshot()));
+ verify_invalid_lookup(api->lookup("bar", api->get_dictionary_snapshot()));
}
void verify_posting(const IDocidWithWeightPostingStore &api, const char *term) {
@@ -129,64 +134,64 @@ void verify_posting(const IDocidWithWeightPostingStore &api, const char *term) {
ASSERT_TRUE(result.posting_idx.valid());
std::vector<DocidWithWeightIterator> itr_store;
api.create(result.posting_idx, itr_store);
- ASSERT_EQUAL(1u, itr_store.size());
+ ASSERT_EQ(1u, itr_store.size());
{
DocidWithWeightIterator &itr = itr_store[0];
if (itr.valid() && itr.getKey() < 1) {
itr.linearSeek(1);
}
ASSERT_TRUE(itr.valid());
- EXPECT_EQUAL(1u, itr.getKey()); // docid
- EXPECT_EQUAL(20, itr.getData()); // weight
+ EXPECT_EQ(1u, itr.getKey()); // docid
+ EXPECT_EQ(20, itr.getData()); // weight
itr.linearSeek(2);
ASSERT_TRUE(itr.valid());
- EXPECT_EQUAL(5u, itr.getKey()); // docid
- EXPECT_EQUAL(5, itr.getData()); // weight
+ EXPECT_EQ(5u, itr.getKey()); // docid
+ EXPECT_EQ(5, itr.getData()); // weight
itr.linearSeek(6);
ASSERT_TRUE(itr.valid());
- EXPECT_EQUAL(7u, itr.getKey()); // docid
- EXPECT_EQUAL(10, itr.getData()); // weight
+ EXPECT_EQ(7u, itr.getKey()); // docid
+ EXPECT_EQ(10, itr.getData()); // weight
itr.linearSeek(8);
EXPECT_FALSE(itr.valid());
}
}
-TEST_F("require that integer iterators are created correctly", LongFixture) {
- verify_posting(*f1.api, "111");
+TEST_F(DirectIntegerTest, iterators_are_created_correctly) {
+ verify_posting(*api, "111");
}
-TEST_F("require that string iterators are created correctly", StringFixture) {
- verify_posting(*f1.api, "foo");
+TEST_F(DirectStringTest, iterators_are_created_correctly) {
+ verify_posting(*api, "foo");
}
-TEST_F("require that collect_folded works for string", StringFixture)
+TEST_F(DirectStringTest, collect_folded_works)
{
- StringAttribute *attr = static_cast<StringAttribute *>(f1.attr.get());
- set_doc(attr, 2, "bar", 30);
+ auto* sa = static_cast<StringAttribute*>(attr.get());
+ set_doc(sa, 2, "bar", 30);
attr->commit();
- set_doc(attr, 3, "FOO", 30);
+ set_doc(sa, 3, "FOO", 30);
attr->commit();
- auto dictionary_snapshot = f1.api->get_dictionary_snapshot();
- auto lookup1 = f1.api->lookup("foo", dictionary_snapshot);
+ auto dictionary_snapshot = api->get_dictionary_snapshot();
+ auto lookup1 = api->lookup("foo", dictionary_snapshot);
std::vector<vespalib::string> folded;
- std::function<void(vespalib::datastore::EntryRef)> save_folded = [&folded,attr](vespalib::datastore::EntryRef enum_idx) { folded.emplace_back(attr->getFromEnum(enum_idx.ref())); };
- f1.api->collect_folded(lookup1.enum_idx, dictionary_snapshot, save_folded);
+ std::function<void(vespalib::datastore::EntryRef)> save_folded = [&folded,sa](vespalib::datastore::EntryRef enum_idx) { folded.emplace_back(sa->getFromEnum(enum_idx.ref())); };
+ api->collect_folded(lookup1.enum_idx, dictionary_snapshot, save_folded);
std::vector<vespalib::string> expected_folded{"FOO", "foo"};
- EXPECT_EQUAL(expected_folded, folded);
+ EXPECT_EQ(expected_folded, folded);
}
-TEST_F("require that collect_folded works for integers", LongFixture)
+TEST_F(DirectIntegerTest, collect_folded_works)
{
- IntegerAttributeTemplate<int64_t> *attr = dynamic_cast<IntegerAttributeTemplate<int64_t> *>(f1.attr.get());
- set_doc(attr, 2, int64_t(112), 30);
+ auto* ia = dynamic_cast<IntegerAttributeTemplate<int64_t>*>(attr.get());
+ set_doc(ia, 2, int64_t(112), 30);
attr->commit();
- auto dictionary_snapshot = f1.api->get_dictionary_snapshot();
- auto lookup1 = f1.api->lookup("111", dictionary_snapshot);
+ auto dictionary_snapshot = api->get_dictionary_snapshot();
+ auto lookup1 = api->lookup("111", dictionary_snapshot);
std::vector<int64_t> folded;
- std::function<void(vespalib::datastore::EntryRef)> save_folded = [&folded,attr](vespalib::datastore::EntryRef enum_idx) { folded.emplace_back(attr->getFromEnum(enum_idx.ref())); };
- f1.api->collect_folded(lookup1.enum_idx, dictionary_snapshot, save_folded);
+ std::function<void(vespalib::datastore::EntryRef)> save_folded = [&folded,ia](vespalib::datastore::EntryRef enum_idx) { folded.emplace_back(ia->getFromEnum(enum_idx.ref())); };
+ api->collect_folded(lookup1.enum_idx, dictionary_snapshot, save_folded);
std::vector<int64_t> expected_folded{int64_t(111)};
- EXPECT_EQUAL(expected_folded, folded);
+ EXPECT_EQ(expected_folded, folded);
}
class Verifier : public search::test::SearchIteratorVerifier {
@@ -196,9 +201,9 @@ public:
SearchIterator::UP create(bool strict) const override {
(void) strict;
const auto* api = _attr->as_docid_with_weight_posting_store();
- ASSERT_TRUE(api != nullptr);
+ assert(api != nullptr);
auto dict_entry = api->lookup("123", api->get_dictionary_snapshot());
- ASSERT_TRUE(dict_entry.posting_idx.valid());
+ assert(dict_entry.posting_idx.valid());
return std::make_unique<queryeval::DocidWithWeightSearchIterator>(_tfmd, *api, dict_entry);
}
private:
@@ -218,9 +223,9 @@ Verifier::Verifier()
}
Verifier::~Verifier() {}
-TEST("verify document weight search iterator") {
+TEST(VerifierTest, verify_document_weight_search_iterator) {
Verifier verifier;
verifier.verify();
}
-TEST_MAIN() { TEST_RUN_ALL(); }
+GTEST_MAIN_RUN_ALL_TESTS()