diff --git a/streamingvisitors/src/tests/docsum/CMakeLists.txt b/streamingvisitors/src/tests/docsum/CMakeLists.txt index 15c1e26b08b0..4634a8c60b07 100644 --- a/streamingvisitors/src/tests/docsum/CMakeLists.txt +++ b/streamingvisitors/src/tests/docsum/CMakeLists.txt @@ -4,5 +4,6 @@ vespa_add_executable(vsm_docsum_test_app TEST docsum_test.cpp DEPENDS streamingvisitors + GTest::gtest ) vespa_add_test(NAME vsm_docsum_test_app COMMAND vsm_docsum_test_app) diff --git a/streamingvisitors/src/tests/docsum/docsum_test.cpp b/streamingvisitors/src/tests/docsum/docsum_test.cpp index d6535046e876..112a4e7f6796 100644 --- a/streamingvisitors/src/tests/docsum/docsum_test.cpp +++ b/streamingvisitors/src/tests/docsum/docsum_test.cpp @@ -1,5 +1,5 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include + #include #include #include @@ -9,6 +9,7 @@ #include #include #include +#include using namespace document; @@ -48,24 +49,29 @@ class TestDocument : public vsm::Document }; -class DocsumTest : public vespalib::TestApp +class DocsumTest : public ::testing::Test { -private: +protected: ArrayFieldValue createFieldValue(const StringList & fv); WeightedSetFieldValue createFieldValue(const WeightedStringList & fv); - void assertFlattenDocsumWriter(const FieldValue & fv, const std::string & exp) { + void assertFlattenDocsumWriter(const FieldValue & fv, const std::string & exp, const std::string& label) { FlattenDocsumWriter fdw; - assertFlattenDocsumWriter(fdw, fv, exp); + assertFlattenDocsumWriter(fdw, fv, exp, label); } - void assertFlattenDocsumWriter(FlattenDocsumWriter & fdw, const FieldValue & fv, const std::string & exp); - void testFlattenDocsumWriter(); - void testDocSumCache(); + void assertFlattenDocsumWriter(FlattenDocsumWriter & fdw, const FieldValue & fv, const std::string & exp, const std::string& label); -public: - int Main() override; + DocsumTest(); + ~DocsumTest() override; }; +DocsumTest::DocsumTest() + : ::testing::Test() +{ +} + +DocsumTest::~DocsumTest() = default; + ArrayFieldValue DocsumTest::createFieldValue(const StringList & fv) { @@ -90,62 +96,54 @@ DocsumTest::createFieldValue(const WeightedStringList & fv) } void -DocsumTest::assertFlattenDocsumWriter(FlattenDocsumWriter & fdw, const FieldValue & fv, const std::string & exp) +DocsumTest::assertFlattenDocsumWriter(FlattenDocsumWriter & fdw, const FieldValue & fv, const std::string & exp, const std::string& label) { + SCOPED_TRACE(label); FieldPath empty; fv.iterateNested(empty.getFullRange(), fdw); std::string actual(fdw.getResult().getBuffer(), fdw.getResult().getPos()); - EXPECT_EQUAL(actual, exp); + EXPECT_EQ(exp, actual); } -void -DocsumTest::testFlattenDocsumWriter() +TEST_F(DocsumTest, flatten_docsum_writer_basic) { - { // basic tests - TEST_DO(assertFlattenDocsumWriter(StringFieldValue("foo bar"), "foo bar")); - TEST_DO(assertFlattenDocsumWriter(RawFieldValue("foo bar"), "foo bar")); - TEST_DO(assertFlattenDocsumWriter(BoolFieldValue(true), "true")); - TEST_DO(assertFlattenDocsumWriter(BoolFieldValue(false), "false")); - TEST_DO(assertFlattenDocsumWriter(LongFieldValue(123456789), "123456789")); - TEST_DO(assertFlattenDocsumWriter(createFieldValue(StringList().add("foo bar").add("baz").add(" qux ")), - "foo bar baz qux ")); - } - { // test mulitple invocations - FlattenDocsumWriter fdw("#"); - TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("foo"), "foo")); - TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("bar"), "foo#bar")); - fdw.clear(); - TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("baz"), "baz")); - TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("qux"), "baz qux")); - } - { // test resizing - FlattenDocsumWriter fdw("#"); - EXPECT_EQUAL(fdw.getResult().getPos(), 0u); - EXPECT_EQUAL(fdw.getResult().getLength(), 32u); - TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("aaaabbbbccccddddeeeeffffgggghhhh"), - "aaaabbbbccccddddeeeeffffgggghhhh")); - EXPECT_EQUAL(fdw.getResult().getPos(), 32u); - EXPECT_EQUAL(fdw.getResult().getLength(), 32u); - TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("aaaa"), "aaaabbbbccccddddeeeeffffgggghhhh#aaaa")); - EXPECT_EQUAL(fdw.getResult().getPos(), 37u); - EXPECT_TRUE(fdw.getResult().getLength() >= 37u); - fdw.clear(); - EXPECT_EQUAL(fdw.getResult().getPos(), 0u); - EXPECT_TRUE(fdw.getResult().getLength() >= 37u); - } + assertFlattenDocsumWriter(StringFieldValue("foo bar"), "foo bar", "string foo bar"); + assertFlattenDocsumWriter(RawFieldValue("foo bar"), "foo bar", "raw foo bar"); + assertFlattenDocsumWriter(BoolFieldValue(true), "true", "bool true"); + assertFlattenDocsumWriter(BoolFieldValue(false), "false", "bool false"); + assertFlattenDocsumWriter(LongFieldValue(123456789), "123456789", "long"); + assertFlattenDocsumWriter(createFieldValue(StringList().add("foo bar").add("baz").add(" qux ")), + "foo bar baz qux ", "wset"); } -int -DocsumTest::Main() +TEST_F(DocsumTest, flatten_docsum_writer_multiple_invocations) { - TEST_INIT("docsum_test"); - - TEST_DO(testFlattenDocsumWriter()); - - TEST_DONE(); + FlattenDocsumWriter fdw("#"); + assertFlattenDocsumWriter(fdw, StringFieldValue("foo"), "foo", "string foo"); + assertFlattenDocsumWriter(fdw, StringFieldValue("bar"), "foo#bar", "string bar"); + fdw.clear(); + assertFlattenDocsumWriter(fdw, StringFieldValue("baz"), "baz", "string baz"); + assertFlattenDocsumWriter(fdw, StringFieldValue("qux"), "baz qux", "string qux"); } +TEST_F(DocsumTest, flatten_docsum_writer_resizing) +{ + FlattenDocsumWriter fdw("#"); + EXPECT_EQ(fdw.getResult().getPos(), 0u); + EXPECT_EQ(fdw.getResult().getLength(), 32u); + assertFlattenDocsumWriter(fdw, StringFieldValue("aaaabbbbccccddddeeeeffffgggghhhh"), + "aaaabbbbccccddddeeeeffffgggghhhh", + "string long"); + EXPECT_EQ(fdw.getResult().getPos(), 32u); + EXPECT_EQ(fdw.getResult().getLength(), 32u); + assertFlattenDocsumWriter(fdw, StringFieldValue("aaaa"), "aaaabbbbccccddddeeeeffffgggghhhh#aaaa", "string second long"); + EXPECT_EQ(fdw.getResult().getPos(), 37u); + EXPECT_TRUE(fdw.getResult().getLength() >= 37u); + fdw.clear(); + EXPECT_EQ(fdw.getResult().getPos(), 0u); + EXPECT_TRUE(fdw.getResult().getLength() >= 37u); } -TEST_APPHOOK(vsm::DocsumTest); +} +GTEST_MAIN_RUN_ALL_TESTS()