From d138c1667dfaf921d2fea1990f7964df1a4a48f8 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 5 Mar 2019 10:32:58 +0000 Subject: Add a simple Trace Object wrapping the slime. --- .../src/tests/engine/searchapi/searchapi_test.cpp | 78 ++++++++++++++-------- 1 file changed, 49 insertions(+), 29 deletions(-) (limited to 'searchlib/src/tests/engine') diff --git a/searchlib/src/tests/engine/searchapi/searchapi_test.cpp b/searchlib/src/tests/engine/searchapi/searchapi_test.cpp index a517890620c..f06ce5c188c 100644 --- a/searchlib/src/tests/engine/searchapi/searchapi_test.cpp +++ b/searchlib/src/tests/engine/searchapi/searchapi_test.cpp @@ -1,10 +1,12 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -LOG_SETUP("searchapi_test"); + #include #include #include #include +#include +#include +LOG_SETUP("searchapi_test"); using namespace search::engine; using namespace search::fs4transport; @@ -28,18 +30,8 @@ template void copyPacket(T &src, T &dst) { } // namespace -class Test : public vespalib::TestApp -{ -public: - void propertyNames(); - void convertToRequest(); - void convertFromReply(); - int Main() override; -}; - -void -Test::propertyNames() -{ + +TEST("propertyNames") { EXPECT_EQUAL(search::MapNames::RANK, "rank"); EXPECT_EQUAL(search::MapNames::FEATURE, "feature"); EXPECT_EQUAL(search::MapNames::HIGHLIGHTTERMS, "highlightterms"); @@ -47,9 +39,7 @@ Test::propertyNames() EXPECT_EQUAL(search::MapNames::CACHES, "caches"); } -void -Test::convertToRequest() -{ +TEST("convertToReques") { FS4Packet_QUERYX src; src._offset = 2u; src._maxhits = 3u; @@ -116,9 +106,7 @@ Test::convertToRequest() } } -void -Test::convertFromReply() -{ +TEST("convertFromReply") { SearchReply src; src.offset = 1u; src.totalHitCount = 2u; @@ -240,14 +228,46 @@ Test::convertFromReply() } } -int -Test::Main() -{ - TEST_INIT("searchapi_test"); - propertyNames(); - convertToRequest(); - convertFromReply(); - TEST_DONE(); +void verify(vespalib::stringref expected, const vespalib::Slime & slime) { + vespalib::Slime expectedSlime; + vespalib::slime::JsonFormat::decode(expected, expectedSlime); + EXPECT_EQUAL(expectedSlime, slime); +} + +TEST("verify trace") { + Trace t(7); + verify("{" + " traces: [" + " ]," + " creation_time: 7" + "}", + t.getRoot()); + + t.createCursor("tag_a"); + verify("{" + " traces: [" + " {" + " tag: 'tag_a'" + " }" + " ]," + " creation_time: 7" + "}", + t.getRoot()); + Trace::Cursor & tagB = t.createCursor("tag_b"); + tagB.setLong("long", 19); + verify("{" + " traces: [" + " {" + " tag: 'tag_a'" + " }," + " {" + " tag: 'tag_b'," + " long: 19" + " }" + " ]," + " creation_time: 7" + "}", + t.getRoot()); } -TEST_APPHOOK(Test); +TEST_MAIN() { TEST_RUN_ALL(); } \ No newline at end of file -- cgit v1.2.3