From a5edd60f3fa9494e88ce4088f0f7f8760ee96321 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Sat, 9 Mar 2024 16:48:35 +0100 Subject: Rewrite struct anno unit test to gtest. --- document/src/tests/struct_anno/CMakeLists.txt | 1 + .../src/tests/struct_anno/struct_anno_test.cpp | 34 +++++++--------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/document/src/tests/struct_anno/CMakeLists.txt b/document/src/tests/struct_anno/CMakeLists.txt index 855cba606a3..2d688454058 100644 --- a/document/src/tests/struct_anno/CMakeLists.txt +++ b/document/src/tests/struct_anno/CMakeLists.txt @@ -4,5 +4,6 @@ vespa_add_executable(document_struct_anno_test_app TEST struct_anno_test.cpp DEPENDS document + GTest::gtest ) vespa_add_test(NAME document_struct_anno_test_app COMMAND document_struct_anno_test_app) diff --git a/document/src/tests/struct_anno/struct_anno_test.cpp b/document/src/tests/struct_anno/struct_anno_test.cpp index 31d3900c6bc..7dc37710143 100644 --- a/document/src/tests/struct_anno/struct_anno_test.cpp +++ b/document/src/tests/struct_anno/struct_anno_test.cpp @@ -11,8 +11,9 @@ #include #include #include +#include #include -#include +#include #include using std::ostringstream; @@ -23,23 +24,12 @@ using namespace document; namespace { -class Test : public vespalib::TestApp { - void requireThatStructFieldsCanContainAnnotations(); - -public: - int Main() override; -}; +template int arraysize(const T (&)[N]) { return N; } -int Test::Main() { - if (getenv("TEST_SUBSET") != 0) { return 0; } - TEST_INIT("struct_anno_test"); - TEST_DO(requireThatStructFieldsCanContainAnnotations()); - TEST_DONE(); } -template int arraysize(const T (&)[N]) { return N; } - -void Test::requireThatStructFieldsCanContainAnnotations() { +TEST(StructAnnoTest, require_that_struct_fields_can_contain_nnotations) +{ DocumentTypeRepo repo(readDocumenttypesConfig(TEST_PATH("documenttypes.cfg"))); FastOS_File file(TEST_PATH("document.dat").c_str()); @@ -62,19 +52,17 @@ void Test::requireThatStructFieldsCanContainAnnotations() { const StringFieldValue *str = dynamic_cast(strRef.get()); ASSERT_TRUE(str != NULL); - SpanTree::UP tree = std::move(str->getSpanTrees().front()); + auto tree = std::move(str->getSpanTrees().front()); - EXPECT_EQUAL("my_tree", tree->getName()); + EXPECT_EQ("my_tree", tree->getName()); const SimpleSpanList *root = dynamic_cast(&tree->getRoot()); ASSERT_TRUE(root != NULL); - EXPECT_EQUAL(1u, root->size()); + EXPECT_EQ(1u, root->size()); SimpleSpanList::const_iterator it = root->begin(); - EXPECT_EQUAL(Span(0, 6), (*it++)); + EXPECT_EQ(Span(0, 6), (*it++)); EXPECT_TRUE(it == root->end()); - EXPECT_EQUAL(1u, tree->numAnnotations()); + EXPECT_EQ(1u, tree->numAnnotations()); } -} // namespace - -TEST_APPHOOK(Test); +GTEST_MAIN_RUN_ALL_TESTS() -- cgit v1.2.3