From 292c965ac07ab0da8684e22e7502d45894ebfeb8 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Tue, 29 Oct 2024 13:17:02 +0100 Subject: [PATCH] Rewrite searchcore query unit test to gtest. --- .../src/tests/proton/matching/CMakeLists.txt | 1 + .../src/tests/proton/matching/query_test.cpp | 259 ++++++++++-------- 2 files changed, 144 insertions(+), 116 deletions(-) diff --git a/searchcore/src/tests/proton/matching/CMakeLists.txt b/searchcore/src/tests/proton/matching/CMakeLists.txt index d5f01ef1e745..7ea18d44cd49 100644 --- a/searchcore/src/tests/proton/matching/CMakeLists.txt +++ b/searchcore/src/tests/proton/matching/CMakeLists.txt @@ -36,6 +36,7 @@ vespa_add_executable(searchcore_query_test_app TEST DEPENDS searchcore_server searchcore_matching + GTest::gtest ) vespa_add_test(NAME searchcore_query_test_app COMMAND searchcore_query_test_app) vespa_add_executable(searchcore_termdataextractor_test_app TEST diff --git a/searchcore/src/tests/proton/matching/query_test.cpp b/searchcore/src/tests/proton/matching/query_test.cpp index 7948d40a8089..85f66fa2b7ae 100644 --- a/searchcore/src/tests/proton/matching/query_test.cpp +++ b/searchcore/src/tests/proton/matching/query_test.cpp @@ -31,11 +31,7 @@ #include #include #include -#include -#include - -#include -LOG_SETUP("query_test"); +#include using document::PositionDataType; using search::fef::FieldInfo; @@ -125,6 +121,7 @@ InitializeGlobals globals; struct Fixture { Fixture(); + ~Fixture(); SearchIterator::UP getIterator(Node &node, ISearchContext &context); MatchData::UP _match_data; Blueprint::UP _blueprint; @@ -138,6 +135,8 @@ Fixture::Fixture() { } +Fixture::~Fixture() = default; + SearchIterator::UP Fixture::getIterator(Node &node, ISearchContext &context) { MatchDataLayout mdl; @@ -203,7 +202,8 @@ Node::UP buildSameElementQueryTree(const ViewResolver &resolver, return node; } -TEST("requireThatMatchDataIsReserved") { +TEST(QueryTest, requireThatMatchDataIsReserved) +{ Node::UP node = buildQueryTree(ViewResolver(), plain_index_env); MatchDataLayout mdl; @@ -211,7 +211,7 @@ TEST("requireThatMatchDataIsReserved") { node->accept(visitor); MatchData::UP match_data = mdl.createMatchData(); - EXPECT_EQUAL(term_count, match_data->getNumTermFields()); + EXPECT_EQ(term_count, match_data->getNumTermFields()); } ViewResolver getViewResolver() { @@ -221,7 +221,8 @@ ViewResolver getViewResolver() { return resolver; } -TEST("requireThatMatchDataIsReservedForEachFieldInAView") { +TEST(QueryTest, requireThatMatchDataIsReservedForEachFieldInAView) +{ Node::UP node = buildQueryTree(getViewResolver(), resolved_index_env); MatchDataLayout mdl; @@ -229,7 +230,7 @@ TEST("requireThatMatchDataIsReservedForEachFieldInAView") { node->accept(visitor); MatchData::UP match_data = mdl.createMatchData(); - EXPECT_EQUAL(term_count * 2, match_data->getNumTermFields()); + EXPECT_EQ(term_count * 2, match_data->getNumTermFields()); } class LookupTestCheckerVisitor : public CustomTypeTermVisitor @@ -237,9 +238,9 @@ class LookupTestCheckerVisitor : public CustomTypeTermVisitor public: template void checkNode(const TermType &n, int estimatedHitCount, bool empty) { - EXPECT_EQUAL(empty, (estimatedHitCount == 0)); - EXPECT_EQUAL(static_cast(estimatedHitCount), n.field(0).get_doc_freq().frequency); - EXPECT_EQUAL(static_cast(doc_count), n.field(0).get_doc_freq().count); + EXPECT_EQ(empty, (estimatedHitCount == 0)); + EXPECT_EQ(static_cast(estimatedHitCount), n.field(0).get_doc_freq().frequency); + EXPECT_EQ(static_cast(doc_count), n.field(0).get_doc_freq().count); } void visit(ProtonNumberTerm &n) override { checkNode(n, 1, false); } @@ -260,7 +261,8 @@ class LookupTestCheckerVisitor : public CustomTypeTermVisitor void visit(ProtonInTerm&) override {} }; -TEST("requireThatTermsAreLookedUp") { +TEST(QueryTest, requireThatTermsAreLookedUp) +{ FakeRequestContext requestContext; Node::UP node = buildQueryTree(ViewResolver(), plain_index_env); @@ -291,10 +293,11 @@ TEST("requireThatTermsAreLookedUp") { Blueprint::UP blueprint = BlueprintBuilder::build(requestContext, *node, context); LookupTestCheckerVisitor checker; - TEST_DO(node->accept(checker)); + node->accept(checker); } -TEST("requireThatTermsAreLookedUpInMultipleFieldsFromAView") { +TEST(QueryTest, requireThatTermsAreLookedUpInMultipleFieldsFromAView) +{ Node::UP node = buildQueryTree(getViewResolver(), resolved_index_env); FakeRequestContext requestContext; @@ -327,10 +330,11 @@ TEST("requireThatTermsAreLookedUpInMultipleFieldsFromAView") { Blueprint::UP blueprint = BlueprintBuilder::build(requestContext, *node, context); LookupTestCheckerVisitor checker; - TEST_DO(node->accept(checker)); + node->accept(checker); } -TEST("requireThatAttributeTermsAreLookedUpInAttributeSource") { +TEST(QueryTest, requireThatAttributeTermsAreLookedUpInAttributeSource) +{ const string term = "bar"; ProtonStringTerm node(term, field, 1, Weight(2)); node.resolve(ViewResolver(), attribute_index_env); @@ -346,10 +350,11 @@ TEST("requireThatAttributeTermsAreLookedUpInAttributeSource") { Blueprint::UP blueprint = BlueprintBuilder::build(requestContext, node, context); EXPECT_TRUE(!blueprint->getState().estimate().empty); - EXPECT_EQUAL(1u, blueprint->getState().estimate().estHits); + EXPECT_EQ(1u, blueprint->getState().estimate().estHits); } -TEST("requireThatAttributeTermDataHandlesAreAllocated") { +TEST(QueryTest, requireThatAttributeTermDataHandlesAreAllocated) +{ const string term = "bar"; ProtonStringTerm node(term, field, 1, Weight(2)); node.resolve(ViewResolver(), attribute_index_env); @@ -363,7 +368,7 @@ TEST("requireThatAttributeTermDataHandlesAreAllocated") { Blueprint::UP blueprint = BlueprintBuilder::build(requestContext, node, context); MatchData::UP match_data = mdl.createMatchData(); - EXPECT_EQUAL(1u, match_data->getNumTermFields()); + EXPECT_EQ(1u, match_data->getNumTermFields()); EXPECT_TRUE(node.field(0).attribute_field); } @@ -379,16 +384,16 @@ class SetUpTermDataTestCheckerVisitor void visit(ProtonStringTerm &n) override { const ITermData &term_data = n; - EXPECT_EQUAL(string_weight.percent(), term_data.getWeight().percent()); - EXPECT_EQUAL(1u, term_data.getPhraseLength()); - EXPECT_EQUAL(string_id, term_data.getUniqueId()); - EXPECT_EQUAL(term_data.numFields(), n.numFields()); + EXPECT_EQ(string_weight.percent(), term_data.getWeight().percent()); + EXPECT_EQ(1u, term_data.getPhraseLength()); + EXPECT_EQ(string_id, term_data.getUniqueId()); + EXPECT_EQ(term_data.numFields(), n.numFields()); for (size_t i = 0; i < term_data.numFields(); ++i) { const ITermFieldData &term_field_data = term_data.field(i); - EXPECT_EQUAL(2u, term_field_data.get_doc_freq().frequency); - EXPECT_EQUAL(static_cast(doc_count), term_field_data.get_doc_freq().count); + EXPECT_EQ(2u, term_field_data.get_doc_freq().frequency); + EXPECT_EQ(static_cast(doc_count), term_field_data.get_doc_freq().count); EXPECT_TRUE(!n.field(i).attribute_field); - EXPECT_EQUAL(field_id + i, term_field_data.getFieldId()); + EXPECT_EQ(field_id + i, term_field_data.getFieldId()); } } @@ -396,7 +401,7 @@ class SetUpTermDataTestCheckerVisitor void visit(ProtonSuffixTerm &) override {} void visit(ProtonPhrase &n) override { const ITermData &term_data = n; - EXPECT_EQUAL(2u, term_data.getPhraseLength()); + EXPECT_EQ(2u, term_data.getPhraseLength()); } void visit(ProtonWeightedSetTerm &) override {} void visit(ProtonDotProduct &) override {} @@ -408,7 +413,8 @@ class SetUpTermDataTestCheckerVisitor void visit(ProtonInTerm&) override { } }; -TEST("requireThatTermDataIsFilledIn") { +TEST(QueryTest, requireThatTermDataIsFilledIn) +{ Node::UP node = buildQueryTree(getViewResolver(), resolved_index_env); FakeRequestContext requestContext; @@ -424,10 +430,8 @@ TEST("requireThatTermDataIsFilledIn") { Blueprint::UP blueprint = BlueprintBuilder::build(requestContext, *node, context); - TEST_DO( - SetUpTermDataTestCheckerVisitor checker; - node->accept(checker); - ); + SetUpTermDataTestCheckerVisitor checker; + node->accept(checker); } FakeIndexSearchable getFakeSearchable(const string &term, int doc1, int doc2) { @@ -437,7 +441,9 @@ FakeIndexSearchable getFakeSearchable(const string &term, int doc1, int doc2) { return source; } -TEST_F("requireThatSingleIndexCanUseBlendingAsBlacklisting", Fixture) { +TEST(QueryTest, requireThatSingleIndexCanUseBlendingAsBlacklisting) +{ + Fixture f; QueryBuilder builder; builder.addStringTerm(string_term, field, 1, Weight(2)) .resolve(ViewResolver(), plain_index_env); @@ -456,7 +462,9 @@ TEST_F("requireThatSingleIndexCanUseBlendingAsBlacklisting", Fixture) { iterator->unpack(5); } -TEST_F("requireThatIteratorsAreBuiltWithBlending", Fixture) { +TEST(QueryTest, requireThatIteratorsAreBuiltWithBlending) +{ + Fixture f; QueryBuilder builder; builder.addStringTerm(string_term, field, 1, Weight(2)) .resolve(ViewResolver(), plain_index_env); @@ -479,7 +487,9 @@ TEST_F("requireThatIteratorsAreBuiltWithBlending", Fixture) { EXPECT_TRUE(iterator->seek(7)); } -TEST_F("requireThatIteratorsAreBuiltForAllTermNodes", Fixture) { +TEST(QueryTest, requireThatIteratorsAreBuiltForAllTermNodes) +{ + Fixture f; Node::UP node = buildQueryTree(ViewResolver(), plain_index_env); ASSERT_TRUE(node); @@ -509,7 +519,9 @@ TEST_F("requireThatIteratorsAreBuiltForAllTermNodes", Fixture) { EXPECT_TRUE(iterator->seek(42)); } -TEST_F("requireThatNearIteratorsCanBeBuilt", Fixture) { +TEST(QueryTest, requireThatNearIteratorsCanBeBuilt) +{ + Fixture f; QueryBuilder builder; builder.addNear(2, 4); builder.addStringTerm(string_term, field, 1, Weight(2)); @@ -533,7 +545,9 @@ TEST_F("requireThatNearIteratorsCanBeBuilt", Fixture) { EXPECT_TRUE(iterator->seek(8)); } -TEST_F("requireThatONearIteratorsCanBeBuilt", Fixture) { +TEST(QueryTest, requireThatONearIteratorsCanBeBuilt) +{ + Fixture f; QueryBuilder builder; builder.addONear(2, 4); builder.addStringTerm(string_term, field, 1, Weight(2)); @@ -557,7 +571,9 @@ TEST_F("requireThatONearIteratorsCanBeBuilt", Fixture) { EXPECT_TRUE(iterator->seek(8)); } -TEST_F("requireThatPhraseIteratorsCanBeBuilt", Fixture) { +TEST(QueryTest, requireThatPhraseIteratorsCanBeBuilt) +{ + Fixture f; QueryBuilder builder; builder.addPhrase(3, field, 0, Weight(42)); builder.addStringTerm(string_term, field, 1, Weight(2)); @@ -594,8 +610,9 @@ TEST_F("requireThatPhraseIteratorsCanBeBuilt", Fixture) { EXPECT_TRUE(iterator->isAtEnd()); } -TEST_F("requireThatUnknownFieldActsEmpty", Fixture) +TEST(QueryTest, requireThatUnknownFieldActsEmpty) { + Fixture f; FakeSearchContext context; context.addIdx(0).idx(0).getFake() .addResult(unknown_field, string_term, FakeResult() @@ -610,15 +627,15 @@ TEST_F("requireThatUnknownFieldActsEmpty", Fixture) SearchIterator::UP iterator = f.getIterator(node, context); - ASSERT_TRUE(EXPECT_EQUAL(1u, terms.size())); - EXPECT_EQUAL(0u, terms[0]->numFields()); + ASSERT_EQ(1u, terms.size()); + EXPECT_EQ(0u, terms[0]->numFields()); ASSERT_TRUE(iterator); EXPECT_TRUE(!iterator->seek(1)); EXPECT_TRUE(iterator->isAtEnd()); } -TEST("requireThatIllegalFieldsAreIgnored") +TEST(QueryTest, requireThatIllegalFieldsAreIgnored) { ProtonNodeTypes::StringTerm node(string_term, unknown_field, string_id, string_weight); node.resolve(ViewResolver(), plain_index_env); @@ -631,12 +648,13 @@ TEST("requireThatIllegalFieldsAreIgnored") node.accept(reserve_visitor); Blueprint::UP blueprint = BlueprintBuilder::build(requestContext, node, context); - EXPECT_EQUAL(0u, node.numFields()); + EXPECT_EQ(0u, node.numFields()); MatchData::UP match_data = mdl.createMatchData(); - EXPECT_EQUAL(0u, match_data->getNumTermFields()); + EXPECT_EQ(0u, match_data->getNumTermFields()); } -TEST("requireThatQueryGluesEverythingTogether") { +TEST(QueryTest, requireThatQueryGluesEverythingTogether) +{ QueryBuilder builder; builder.addStringTerm(string_term, field, 1, Weight(2)); string stack_dump = StackDumpCreator::create(*builder.build()); @@ -645,7 +663,7 @@ TEST("requireThatQueryGluesEverythingTogether") { query.buildTree(stack_dump, "", ViewResolver(), plain_index_env); vector term_data; query.extractTerms(term_data); - EXPECT_EQUAL(1u, term_data.size()); + EXPECT_EQ(1u, term_data.size()); FakeRequestContext requestContext; FakeSearchContext context; @@ -653,7 +671,7 @@ TEST("requireThatQueryGluesEverythingTogether") { MatchDataLayout mdl; query.reserveHandles(requestContext, context, mdl); MatchData::UP md = mdl.createMatchData(); - EXPECT_EQUAL(1u, md->getNumTermFields()); + EXPECT_EQ(1u, md->getNumTermFields()); query.optimize(true, true); query.fetchPostings(ExecuteInfo::FULL); @@ -678,7 +696,7 @@ checkQueryAddsLocation(const string &loc_in, const string &loc_out) { ViewResolver(), index_environment); vector term_data; query.extractTerms(term_data); - EXPECT_EQUAL(2u, term_data.size()); + EXPECT_EQ(2u, term_data.size()); FakeRequestContext requestContext; FakeSearchContext context; @@ -686,16 +704,14 @@ checkQueryAddsLocation(const string &loc_in, const string &loc_out) { MatchDataLayout mdl; query.reserveHandles(requestContext, context, mdl); MatchData::UP md = mdl.createMatchData(); - EXPECT_EQUAL(2u, md->getNumTermFields()); + EXPECT_EQ(2u, md->getNumTermFields()); // query.optimize(true, true); query.fetchPostings(ExecuteInfo::FULL); SearchIterator::UP search = query.createSearch(*md); ASSERT_TRUE(search); - if (!EXPECT_NOT_EQUAL(string::npos, search->asString().find(loc_out))) { - fprintf(stderr, "search (missing loc_out '%s'): %s", - loc_out.c_str(), search->asString().c_str()); - } + EXPECT_NE(string::npos, search->asString().find(loc_out)) << "search (missing loc_out '" << loc_out << "'): " << + search->asString(); } template @@ -720,16 +736,16 @@ void verifyThatRankBlueprintAndAndNotStaysOnTopAfterLocation(QueryBuilder(query.peekRoot()); ASSERT_TRUE(root != nullptr); - EXPECT_EQUAL(2u, root->childCnt()); + EXPECT_EQ(2u, root->childCnt()); const IntermediateBlueprint * second = dynamic_cast(&root->getChild(0)); ASSERT_TRUE(second != nullptr); - EXPECT_EQUAL(2u, second->childCnt()); + EXPECT_EQ(2u, second->childCnt()); auto first = dynamic_cast(&second->getChild(0)); ASSERT_TRUE(first != nullptr); - EXPECT_EQUAL(2u, first->childCnt()); + EXPECT_EQ(2u, first->childCnt()); EXPECT_TRUE(dynamic_cast(&first->getChild(0))); auto bottom = dynamic_cast(&first->getChild(0)); - EXPECT_EQUAL(2u, bottom->childCnt()); + EXPECT_EQ(2u, bottom->childCnt()); EXPECT_TRUE(dynamic_cast(&bottom->getChild(0))); EXPECT_TRUE(dynamic_cast(&bottom->getChild(1))); EXPECT_TRUE(dynamic_cast(&first->getChild(1))); @@ -737,7 +753,8 @@ void verifyThatRankBlueprintAndAndNotStaysOnTopAfterLocation(QueryBuilder(&root->getChild(1))); } -TEST("requireThatLocationIsAddedTheCorrectPlace") { +TEST(QueryTest, requireThatLocationIsAddedTheCorrectPlace) +{ { QueryBuilder builder; builder.addRank(2); @@ -752,19 +769,21 @@ TEST("requireThatLocationIsAddedTheCorrectPlace") { } } -TEST("requireThatQueryAddsLocation") { +TEST(QueryTest, requireThatQueryAddsLocation) +{ checkQueryAddsLocation("(2,10,10,3,0,1,0,0)", "{p:{x:10,y:10},r:3,b:{x:[7,13],y:[7,13]}}"); checkQueryAddsLocation("{p:{x:10,y:10},r:3}", "{p:{x:10,y:10},r:3,b:{x:[7,13],y:[7,13]}}"); checkQueryAddsLocation("{b:{x:[6,11],y:[8,15]},p:{x:10,y:10},r:3}", "{p:{x:10,y:10},r:3,b:{x:[7,11],y:[8,13]}}"); checkQueryAddsLocation("{a:12345,b:{x:[8,10],y:[8,10]},p:{x:10,y:10},r:3}", "{p:{x:10,y:10},r:3,a:12345,b:{x:[8,10],y:[8,10]}}"); } -TEST("requireThatQueryAddsLocationCutoff") { +TEST(QueryTest, requireThatQueryAddsLocationCutoff) +{ checkQueryAddsLocation("[2,10,11,23,24]", "{b:{x:[10,23],y:[11,24]}}"); checkQueryAddsLocation("{b:{y:[11,24],x:[10,23]}}", "{b:{x:[10,23],y:[11,24]}}"); } -TEST("requireThatFakeFieldSearchDumpsDiffer") +TEST(QueryTest, requireThatFakeFieldSearchDumpsDiffer) { FakeRequestContext requestContext; uint32_t fieldId = 0; @@ -807,12 +826,13 @@ TEST("requireThatFakeFieldSearchDumpsDiffer") SearchIterator::UP s3(l3->createSearch(*match_data)); SearchIterator::UP s4(l4->createSearch(*match_data)); - EXPECT_NOT_EQUAL(s1->asString(), s2->asString()); - EXPECT_NOT_EQUAL(s1->asString(), s3->asString()); - EXPECT_NOT_EQUAL(s1->asString(), s4->asString()); + EXPECT_NE(s1->asString(), s2->asString()); + EXPECT_NE(s1->asString(), s3->asString()); + EXPECT_NE(s1->asString(), s4->asString()); } -TEST("requireThatNoDocsGiveZeroDocFrequency") { +TEST(QueryTest, requireThatNoDocsGiveZeroDocFrequency) +{ ProtonStringTerm node(string_term, field, string_id, string_weight); node.resolve(ViewResolver(), plain_index_env); FakeSearchContext context; @@ -825,12 +845,13 @@ TEST("requireThatNoDocsGiveZeroDocFrequency") { Blueprint::UP blueprint = BlueprintBuilder::build(requestContext, node, context); - EXPECT_EQUAL(1u, node.numFields()); - EXPECT_EQUAL(0u, node.field(0).get_doc_freq().frequency); - EXPECT_EQUAL(1u, node.field( 0).get_doc_freq().count); + EXPECT_EQ(1u, node.numFields()); + EXPECT_EQ(0u, node.field(0).get_doc_freq().frequency); + EXPECT_EQ(1u, node.field( 0).get_doc_freq().count); } -TEST("requireThatWeakAndBlueprintsAreCreatedCorrectly") { +TEST(QueryTest, requireThatWeakAndBlueprintsAreCreatedCorrectly) +{ using search::queryeval::WeakAndBlueprint; ProtonWeakAnd wand(123, "view"); @@ -854,16 +875,17 @@ TEST("requireThatWeakAndBlueprintsAreCreatedCorrectly") { Blueprint::UP blueprint = BlueprintBuilder::build(requestContext, wand, context); auto *wbp = dynamic_cast(blueprint.get()); ASSERT_TRUE(wbp != nullptr); - ASSERT_EQUAL(2u, wbp->getWeights().size()); - ASSERT_EQUAL(2u, wbp->childCnt()); - EXPECT_EQUAL(123u, wbp->getN()); - EXPECT_EQUAL(3u, wbp->getWeights()[0]); - EXPECT_EQUAL(7u, wbp->getWeights()[1]); - EXPECT_EQUAL(2u, wbp->getChild(0).getState().estimate().estHits); - EXPECT_EQUAL(3u, wbp->getChild(1).getState().estimate().estHits); + ASSERT_EQ(2u, wbp->getWeights().size()); + ASSERT_EQ(2u, wbp->childCnt()); + EXPECT_EQ(123u, wbp->getN()); + EXPECT_EQ(3u, wbp->getWeights()[0]); + EXPECT_EQ(7u, wbp->getWeights()[1]); + EXPECT_EQ(2u, wbp->getChild(0).getState().estimate().estHits); + EXPECT_EQ(3u, wbp->getChild(1).getState().estimate().estHits); } -TEST("requireThatParallelWandBlueprintsAreCreatedCorrectly") { +TEST(QueryTest, requireThatParallelWandBlueprintsAreCreatedCorrectly) +{ using search::queryeval::WeakAndBlueprint; ProtonWandTerm wand(2, field, 42, Weight(100), 123, 9000, 1.25); @@ -888,12 +910,12 @@ TEST("requireThatParallelWandBlueprintsAreCreatedCorrectly") { Blueprint::UP blueprint = BlueprintBuilder::build(requestContext, wand, context); auto *wbp = dynamic_cast(blueprint.get()); ASSERT_TRUE(wbp != nullptr); - EXPECT_EQUAL(9000, wbp->getScoreThreshold()); - EXPECT_EQUAL(1.25, wbp->getThresholdBoostFactor()); - EXPECT_EQUAL(1000u, wbp->get_docid_limit()); + EXPECT_EQ(9000, wbp->getScoreThreshold()); + EXPECT_EQ(1.25, wbp->getThresholdBoostFactor()); + EXPECT_EQ(1000u, wbp->get_docid_limit()); } -TEST("requireThatWhiteListBlueprintCanBeUsed") +TEST(QueryTest, requireThatWhiteListBlueprintCanBeUsed) { QueryBuilder builder; builder.addStringTerm("foo", field, field_id, string_weight); @@ -920,7 +942,7 @@ TEST("requireThatWhiteListBlueprintCanBeUsed") SimpleResult exp = SimpleResult().addHit(1).addHit(5).addHit(7).addHit(11); SimpleResult act; act.search(*search); - EXPECT_EQUAL(exp, act); + EXPECT_EQ(exp, act); } template @@ -943,27 +965,29 @@ void verifyThatRankBlueprintAndAndNotStaysOnTopAfterWhiteListing(QueryBuilder(query.peekRoot()); ASSERT_TRUE(root != nullptr); - EXPECT_EQUAL(2u, root->childCnt()); + EXPECT_EQ(2u, root->childCnt()); const IntermediateBlueprint * second = dynamic_cast(&root->getChild(0)); ASSERT_TRUE(second != nullptr); - EXPECT_EQUAL(2u, second->childCnt()); + EXPECT_EQ(2u, second->childCnt()); auto first = dynamic_cast(&second->getChild(0)); ASSERT_TRUE(first != nullptr); - EXPECT_EQUAL(2u, first->childCnt()); + EXPECT_EQ(2u, first->childCnt()); EXPECT_TRUE(dynamic_cast(&first->getChild(0))); EXPECT_TRUE(dynamic_cast(&first->getChild(1))); EXPECT_TRUE(dynamic_cast(&second->getChild(1))); EXPECT_TRUE(dynamic_cast(&root->getChild(1))); } -TEST("requireThatRankBlueprintStaysOnTopAfterWhiteListing") { +TEST(QueryTest, requireThatRankBlueprintStaysOnTopAfterWhiteListing) +{ QueryBuilder builder; builder.addRank(2); builder.addAndNot(2); verifyThatRankBlueprintAndAndNotStaysOnTopAfterWhiteListing(builder); } -TEST("requireThatAndNotBlueprintStaysOnTopAfterWhiteListing") { +TEST(QueryTest, requireThatAndNotBlueprintStaysOnTopAfterWhiteListing) +{ QueryBuilder builder; builder.addAndNot(2); builder.addRank(2); @@ -986,48 +1010,50 @@ make_same_element_stack_dump(const std::string &prefix, const std::string &term_ return query; } -TEST("requireThatSameElementTermsAreProperlyPrefixed") +TEST(QueryTest, requireThatSameElementTermsAreProperlyPrefixed) { search::query::Node::UP query = make_same_element_stack_dump("", ""); auto * root = dynamic_cast(query.get()); - EXPECT_EQUAL(root->getView(), ""); - EXPECT_EQUAL(root->getChildren().size(), 2u); - EXPECT_EQUAL(dynamic_cast(root->getChildren()[0])->getView(), "f1"); - EXPECT_EQUAL(dynamic_cast(root->getChildren()[1])->getView(), "f2"); + EXPECT_EQ(root->getView(), ""); + EXPECT_EQ(root->getChildren().size(), 2u); + EXPECT_EQ(dynamic_cast(root->getChildren()[0])->getView(), "f1"); + EXPECT_EQ(dynamic_cast(root->getChildren()[1])->getView(), "f2"); query = make_same_element_stack_dump("abc", ""); root = dynamic_cast(query.get()); - EXPECT_EQUAL(root->getView(), "abc"); - EXPECT_EQUAL(root->getChildren().size(), 2u); - EXPECT_EQUAL(dynamic_cast(root->getChildren()[0])->getView(), "abc.f1"); - EXPECT_EQUAL(dynamic_cast(root->getChildren()[1])->getView(), "abc.f2"); + EXPECT_EQ(root->getView(), "abc"); + EXPECT_EQ(root->getChildren().size(), 2u); + EXPECT_EQ(dynamic_cast(root->getChildren()[0])->getView(), "abc.f1"); + EXPECT_EQ(dynamic_cast(root->getChildren()[1])->getView(), "abc.f2"); query = make_same_element_stack_dump("abc", "xyz."); root = dynamic_cast(query.get()); - EXPECT_EQUAL(root->getView(), "abc"); - EXPECT_EQUAL(root->getChildren().size(), 2u); - EXPECT_EQUAL(dynamic_cast(root->getChildren()[0])->getView(), "abc.xyz.f1"); - EXPECT_EQUAL(dynamic_cast(root->getChildren()[1])->getView(), "abc.xyz.f2"); + EXPECT_EQ(root->getView(), "abc"); + EXPECT_EQ(root->getChildren().size(), 2u); + EXPECT_EQ(dynamic_cast(root->getChildren()[0])->getView(), "abc.xyz.f1"); + EXPECT_EQ(dynamic_cast(root->getChildren()[1])->getView(), "abc.xyz.f2"); query = make_same_element_stack_dump("abc", "abc."); root = dynamic_cast(query.get()); - EXPECT_EQUAL(root->getView(), "abc"); - EXPECT_EQUAL(root->getChildren().size(), 2u); - EXPECT_EQUAL(dynamic_cast(root->getChildren()[0])->getView(), "abc.abc.f1"); - EXPECT_EQUAL(dynamic_cast(root->getChildren()[1])->getView(), "abc.abc.f2"); + EXPECT_EQ(root->getView(), "abc"); + EXPECT_EQ(root->getChildren().size(), 2u); + EXPECT_EQ(dynamic_cast(root->getChildren()[0])->getView(), "abc.abc.f1"); + EXPECT_EQ(dynamic_cast(root->getChildren()[1])->getView(), "abc.abc.f2"); } -TEST("requireThatSameElementAllocatesMatchData") +TEST(QueryTest, requireThatSameElementAllocatesMatchData) { Node::UP node = buildSameElementQueryTree(ViewResolver(), plain_index_env); MatchDataLayout mdl; MatchDataReserveVisitor visitor(mdl); node->accept(visitor); MatchData::UP match_data = mdl.createMatchData(); - EXPECT_EQUAL(1u, match_data->getNumTermFields()); + EXPECT_EQ(1u, match_data->getNumTermFields()); } -TEST_F("requireThatSameElementIteratorsCanBeBuilt", Fixture) { +TEST(QueryTest, requireThatSameElementIteratorsCanBeBuilt) +{ + Fixture f; Node::UP node = buildSameElementQueryTree(ViewResolver(), plain_index_env); FakeSearchContext context(10); context.addIdx(0).idx(0).getFake() @@ -1041,7 +1067,8 @@ TEST_F("requireThatSameElementIteratorsCanBeBuilt", Fixture) { EXPECT_TRUE(iterator->seek(8)); } -TEST("requireThatConstBoolBlueprintsAreCreatedCorrectly") { +TEST(QueryTest, requireThatConstBoolBlueprintsAreCreatedCorrectly) +{ using search::queryeval::AlwaysTrueBlueprint; using search::queryeval::EmptyBlueprint; @@ -1083,7 +1110,7 @@ class GlobalFilterBlueprint : public SimpleBlueprint { GlobalFilterBlueprint::~GlobalFilterBlueprint() = default; -TEST("global_filter_is_calculated_and_handled") +TEST(QueryTest, global_filter_is_calculated_and_handled) { // estimated hits = 3, estimated hit ratio = 0.3 auto result = SimpleResult().addHit(3).addHit(5).addHit(7); @@ -1093,14 +1120,14 @@ TEST("global_filter_is_calculated_and_handled") auto res = Query::handle_global_filter(bp, docid_limit, 0, 1, ttb(), nullptr); EXPECT_FALSE(res); EXPECT_FALSE(bp.filter); - EXPECT_EQUAL(-1.0, bp.estimated_hit_ratio); + EXPECT_EQ(-1.0, bp.estimated_hit_ratio); } { // estimated_hit_ratio < global_filter_lower_limit GlobalFilterBlueprint bp(result, true); auto res = Query::handle_global_filter(bp, docid_limit, 0.31, 1, ttb(), nullptr); EXPECT_FALSE(res); EXPECT_FALSE(bp.filter); - EXPECT_EQUAL(-1.0, bp.estimated_hit_ratio); + EXPECT_EQ(-1.0, bp.estimated_hit_ratio); } { // estimated_hit_ratio <= global_filter_upper_limit GlobalFilterBlueprint bp(result, true); @@ -1108,9 +1135,9 @@ TEST("global_filter_is_calculated_and_handled") EXPECT_TRUE(res); EXPECT_TRUE(bp.filter); EXPECT_TRUE(bp.filter->is_active()); - EXPECT_EQUAL(0.3, bp.estimated_hit_ratio); + EXPECT_EQ(0.3, bp.estimated_hit_ratio); - EXPECT_EQUAL(3u, bp.filter->count()); + EXPECT_EQ(3u, bp.filter->count()); EXPECT_TRUE(bp.filter->check(3)); EXPECT_TRUE(bp.filter->check(5)); EXPECT_TRUE(bp.filter->check(7)); @@ -1121,11 +1148,11 @@ TEST("global_filter_is_calculated_and_handled") EXPECT_TRUE(res); EXPECT_TRUE(bp.filter); EXPECT_FALSE(bp.filter->is_active()); - EXPECT_EQUAL(0.3, bp.estimated_hit_ratio); + EXPECT_EQ(0.3, bp.estimated_hit_ratio); } } } // namespace } // namespace proton::matching -TEST_MAIN() { TEST_RUN_ALL(); } +GTEST_MAIN_RUN_ALL_TESTS()