diff options
Diffstat (limited to 'searchlib')
8 files changed, 183 insertions, 208 deletions
diff --git a/searchlib/src/tests/diskindex/bitvector/CMakeLists.txt b/searchlib/src/tests/diskindex/bitvector/CMakeLists.txt index b227d3d5fa8..f70a1efd23c 100644 --- a/searchlib/src/tests/diskindex/bitvector/CMakeLists.txt +++ b/searchlib/src/tests/diskindex/bitvector/CMakeLists.txt @@ -4,5 +4,6 @@ vespa_add_executable(searchlib_bitvector_test-diskindex_app TEST bitvector_test.cpp DEPENDS searchlib + GTest::gtest ) vespa_add_test(NAME searchlib_bitvector_test-diskindex_app COMMAND searchlib_bitvector_test-diskindex_app) diff --git a/searchlib/src/tests/diskindex/bitvector/bitvector_test.cpp b/searchlib/src/tests/diskindex/bitvector/bitvector_test.cpp index 6032b7156ff..5e4b8763534 100644 --- a/searchlib/src/tests/diskindex/bitvector/bitvector_test.cpp +++ b/searchlib/src/tests/diskindex/bitvector/bitvector_test.cpp @@ -1,16 +1,13 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/testapp.h> #include <vespa/searchlib/index/field_length_info.h> #include <vespa/searchlib/diskindex/bitvectordictionary.h> #include <vespa/searchlib/diskindex/fieldwriter.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/searchcommon/common/schema.h> +#include <vespa/vespalib/gtest/gtest.h> #include <filesystem> -#include <vespa/log/log.h> -LOG_SETUP("bitvector_test"); - using namespace search::index; using search::index::schema::DataType; @@ -58,38 +55,57 @@ FieldWriterWrapper::add(uint32_t docId) daf.elements().emplace_back(0); daf.elements().back().setNumOccs(1); daf.word_positions().emplace_back(0); - //LOG(info, "add(%" PRIu64 ", %u)", wordNum, docId); _writer.add(daf); return *this; } -class Test : public vespalib::TestApp +struct TestParam { + bool directio; + bool readmmap; +}; + +std::ostream& operator<<(std::ostream& os, const TestParam& param) +{ + os << (param.directio ? "directio" : "normal") << (param.readmmap ? "mmap" : "read"); + return os; +} + +class BitVectorTest : public ::testing::TestWithParam<TestParam> { -private: +protected: Schema _schema; uint32_t _indexId; -public: - void requireThatDictionaryHandlesNoEntries(bool directio, bool readmmap); - void requireThatDictionaryHandlesMultipleEntries(bool directio, bool readmmap); - - Test(); - ~Test() override; - int Main() override; + BitVectorTest(); + ~BitVectorTest() override; }; -void -Test::requireThatDictionaryHandlesNoEntries(bool directio, bool readmmap) +BitVectorTest::BitVectorTest() + : ::testing::TestWithParam<TestParam>(), + _schema(), + _indexId(0) +{ + _schema.addIndexField(Schema::IndexField("f1", DataType::STRING)); +} + +BitVectorTest::~BitVectorTest() = default; + +INSTANTIATE_TEST_SUITE_P(BitVectorMultiTest, BitVectorTest, + ::testing::Values(TestParam{false, false}, TestParam{true, false}, TestParam{false, true}), + ::testing::PrintToStringParamName()); + +TEST_P(BitVectorTest, require_that_dictionary_handles_no_entries) { TuneFileSeqWrite tuneFileWrite; TuneFileRandRead tuneFileRead; DummyFileHeaderContext fileHeaderContext; - if (directio) { + if (GetParam().directio) { tuneFileWrite.setWantDirectIO(); tuneFileRead.setWantDirectIO(); } - if (readmmap) + if (GetParam().readmmap) { tuneFileRead.setWantMemoryMap(); + } std::filesystem::create_directory(std::filesystem::path("dump")); FieldWriterWrapper fww(5, 2, "dump/1/"); EXPECT_TRUE(fww.open(_schema, _indexId, tuneFileWrite, fileHeaderContext)); @@ -100,25 +116,25 @@ Test::requireThatDictionaryHandlesNoEntries(bool directio, bool readmmap) BitVectorDictionary dict; BitVectorKeyScope bvScope(BitVectorKeyScope::PERFIELD_WORDS); EXPECT_TRUE(dict.open("dump/1/", tuneFileRead, bvScope)); - EXPECT_EQUAL(5u, dict.getDocIdLimit()); - EXPECT_EQUAL(0u, dict.getEntries().size()); + EXPECT_EQ(5u, dict.getDocIdLimit()); + EXPECT_EQ(0u, dict.getEntries().size()); EXPECT_FALSE(dict.lookup(1)); EXPECT_FALSE(dict.lookup(2)); } -void -Test::requireThatDictionaryHandlesMultipleEntries(bool directio, bool readmmap) +TEST_P(BitVectorTest, require_that_dictionary_handles_multiple_entries) { TuneFileSeqWrite tuneFileWrite; TuneFileRandRead tuneFileRead; DummyFileHeaderContext fileHeaderContext; - if (directio) { + if (GetParam().directio) { tuneFileWrite.setWantDirectIO(); tuneFileRead.setWantDirectIO(); } - if (readmmap) + if (GetParam().readmmap) { tuneFileRead.setWantMemoryMap(); + } FieldWriterWrapper fww(64, 6, "dump/2/"); EXPECT_TRUE(fww.open(_schema, _indexId, tuneFileWrite, fileHeaderContext)); // must have >16 docs in order to create bitvector for a word @@ -149,16 +165,16 @@ Test::requireThatDictionaryHandlesMultipleEntries(bool directio, bool readmmap) BitVectorDictionary dict; BitVectorKeyScope bvScope(BitVectorKeyScope::PERFIELD_WORDS); EXPECT_TRUE(dict.open("dump/2/", tuneFileRead, bvScope)); - EXPECT_EQUAL(64u, dict.getDocIdLimit()); - EXPECT_EQUAL(2u, dict.getEntries().size()); + EXPECT_EQ(64u, dict.getDocIdLimit()); + EXPECT_EQ(2u, dict.getEntries().size()); BitVectorWordSingleKey e; e = dict.getEntries()[0]; - EXPECT_EQUAL(1u, e._wordNum); - EXPECT_EQUAL(17u, e._numDocs); + EXPECT_EQ(1u, e._wordNum); + EXPECT_EQ(17u, e._numDocs); e = dict.getEntries()[1]; - EXPECT_EQUAL(5u, e._wordNum); - EXPECT_EQUAL(23u, e._numDocs); + EXPECT_EQ(5u, e._wordNum); + EXPECT_EQ(23u, e._numDocs); EXPECT_FALSE(dict.lookup(2)); EXPECT_FALSE(dict.lookup(3)); @@ -174,33 +190,14 @@ Test::requireThatDictionaryHandlesMultipleEntries(bool directio, bool readmmap) EXPECT_TRUE(*bv5exp == *bv5act); } -Test::Test() - : _schema(), - _indexId(0) -{ - _schema.addIndexField(Schema::IndexField("f1", DataType::STRING)); } -Test::~Test() = default; - int -Test::Main() +main(int argc, char* argv[]) { - TEST_INIT("bitvector_test"); - - if (_argc > 0) { - DummyFileHeaderContext::setCreator(_argv[0]); + ::testing::InitGoogleTest(&argc, argv); + if (argc > 0) { + search::index::DummyFileHeaderContext::setCreator(argv[0]); } - TEST_DO(requireThatDictionaryHandlesNoEntries(false, false)); - TEST_DO(requireThatDictionaryHandlesMultipleEntries(false, false)); - TEST_DO(requireThatDictionaryHandlesNoEntries(true, false)); - TEST_DO(requireThatDictionaryHandlesMultipleEntries(true, false)); - TEST_DO(requireThatDictionaryHandlesNoEntries(false, true)); - TEST_DO(requireThatDictionaryHandlesMultipleEntries(false, true)); - - TEST_DONE(); + return RUN_ALL_TESTS(); } - -} - -TEST_APPHOOK(search::diskindex::Test); diff --git a/searchlib/src/tests/fef/attributecontent/CMakeLists.txt b/searchlib/src/tests/fef/attributecontent/CMakeLists.txt index 48d8375dbb9..d9c88fb9eaf 100644 --- a/searchlib/src/tests/fef/attributecontent/CMakeLists.txt +++ b/searchlib/src/tests/fef/attributecontent/CMakeLists.txt @@ -4,5 +4,6 @@ vespa_add_executable(searchlib_attributecontent_test_app TEST attributecontent_test.cpp DEPENDS searchlib + GTest::gtest ) vespa_add_test(NAME searchlib_attributecontent_test_app COMMAND searchlib_attributecontent_test_app) diff --git a/searchlib/src/tests/fef/attributecontent/attributecontent_test.cpp b/searchlib/src/tests/fef/attributecontent/attributecontent_test.cpp index 1c75d47a134..d501d259ea5 100644 --- a/searchlib/src/tests/fef/attributecontent/attributecontent_test.cpp +++ b/searchlib/src/tests/fef/attributecontent/attributecontent_test.cpp @@ -1,34 +1,21 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/testapp.h> #include <vespa/searchcommon/attribute/attributecontent.h> #include <vespa/searchcommon/attribute/config.h> #include <vespa/searchlib/attribute/attributefactory.h> #include <vespa/searchlib/attribute/integerbase.h> -#include <vespa/log/log.h> -LOG_SETUP("attributecontent_test"); +#include <vespa/vespalib/gtest/gtest.h> using namespace search::attribute; -namespace search { -namespace fef { +namespace search::fef { -class Test : public vespalib::TestApp { -private: - void testWriteAndRead(); - void testFill(); - -public: - int Main() override; -}; - -void -Test::testWriteAndRead() +TEST(AttributeContentTest, test_write_and_read) { using UintContent = search::attribute::AttributeContent<uint32_t>; UintContent buf; - EXPECT_EQUAL(buf.capacity(), 16u); - EXPECT_EQUAL(buf.size(), 0u); + EXPECT_EQ(buf.capacity(), 16u); + EXPECT_EQ(buf.size(), 0u); uint32_t i; uint32_t * data; @@ -37,34 +24,33 @@ Test::testWriteAndRead() *data = i; } buf.setSize(16); - EXPECT_EQUAL(buf.size(), 16u); + EXPECT_EQ(buf.size(), 16u); for (i = 0, itr = buf.begin(); itr != buf.end(); ++i, ++itr) { - EXPECT_EQUAL(*itr, i); - EXPECT_EQUAL(buf[i], i); + EXPECT_EQ(*itr, i); + EXPECT_EQ(buf[i], i); } - EXPECT_EQUAL(i, 16u); + EXPECT_EQ(i, 16u); buf.allocate(10); - EXPECT_EQUAL(buf.capacity(), 16u); - EXPECT_EQUAL(buf.size(), 16u); + EXPECT_EQ(buf.capacity(), 16u); + EXPECT_EQ(buf.size(), 16u); buf.allocate(32); - EXPECT_EQUAL(buf.capacity(), 32u); - EXPECT_EQUAL(buf.size(), 0u); + EXPECT_EQ(buf.capacity(), 32u); + EXPECT_EQ(buf.size(), 0u); for (i = 0, data = buf.data(); i < 32; ++i, ++data) { *data = i; } buf.setSize(32); - EXPECT_EQUAL(buf.size(), 32u); + EXPECT_EQ(buf.size(), 32u); for (i = 0, itr = buf.begin(); itr != buf.end(); ++i, ++itr) { - EXPECT_EQUAL(*itr, i); - EXPECT_EQUAL(buf[i], i); + EXPECT_EQ(*itr, i); + EXPECT_EQ(buf[i], i); } - EXPECT_EQUAL(i, 32u); + EXPECT_EQ(i, 32u); } -void -Test::testFill() +TEST(AttributeContentTest, test_fill) { Config cfg(BasicType::INT32, CollectionType::ARRAY); AttributeVector::SP av = AttributeFactory::createAttribute("aint32", cfg); @@ -77,29 +63,17 @@ Test::testFill() const IAttributeVector & iav = *av.get(); IntegerContent buf; buf.fill(iav, 0); - EXPECT_EQUAL(1u, buf.size()); - EXPECT_EQUAL(10, buf[0]); + EXPECT_EQ(1u, buf.size()); + EXPECT_EQ(10, buf[0]); buf.fill(iav, 1); - EXPECT_EQUAL(2u, buf.size()); - EXPECT_EQUAL(20, buf[0]); - EXPECT_EQUAL(30, buf[1]); + EXPECT_EQ(2u, buf.size()); + EXPECT_EQ(20, buf[0]); + EXPECT_EQ(30, buf[1]); buf.fill(iav, 0); - EXPECT_EQUAL(1u, buf.size()); - EXPECT_EQUAL(10, buf[0]); + EXPECT_EQ(1u, buf.size()); + EXPECT_EQ(10, buf[0]); } -int -Test::Main() -{ - TEST_INIT("attributecontent_test"); - - testWriteAndRead(); - testFill(); - - TEST_DONE(); } -} // namespace fef -} // namespace search - -TEST_APPHOOK(search::fef::Test); +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/searchlib/src/tests/fef/featurenameparser/CMakeLists.txt b/searchlib/src/tests/fef/featurenameparser/CMakeLists.txt index e7874558122..cb040472a6f 100644 --- a/searchlib/src/tests/fef/featurenameparser/CMakeLists.txt +++ b/searchlib/src/tests/fef/featurenameparser/CMakeLists.txt @@ -4,5 +4,6 @@ vespa_add_executable(searchlib_featurenameparser_test_app TEST featurenameparser_test.cpp DEPENDS searchlib + GTest::gtest ) vespa_add_test(NAME searchlib_featurenameparser_test_app COMMAND searchlib_featurenameparser_test_app) diff --git a/searchlib/src/tests/fef/featurenameparser/featurenameparser_test.cpp b/searchlib/src/tests/fef/featurenameparser/featurenameparser_test.cpp index 90a9135389a..ee22a49f8db 100644 --- a/searchlib/src/tests/fef/featurenameparser/featurenameparser_test.cpp +++ b/searchlib/src/tests/fef/featurenameparser/featurenameparser_test.cpp @@ -1,13 +1,15 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> -LOG_SETUP("featurenameparser_test"); -#include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/vespalib/testkit/testapp.h> -#include <vespa/vespalib/util/size_literals.h> + #include <vespa/searchlib/fef/featurenameparser.h> +#include <vespa/vespalib/gtest/gtest.h> +#include <vespa/vespalib/testkit/test_path.h> +#include <vespa/vespalib/util/size_literals.h> #include <vector> #include <string> +#include <vespa/log/log.h> +LOG_SETUP("featurenameparser_test"); + using namespace search::fef; struct ParamList { @@ -31,20 +33,10 @@ std::ostream &operator<<(std::ostream &os, const ParamList &pl) { return os; } -class Test : public vespalib::TestApp -{ -public: - bool testParse(const vespalib::string &input, bool valid, - const vespalib::string &base, ParamList pl, - const vespalib::string &output); - void testFile(const vespalib::string &name); - int Main() override; -}; - bool -Test::testParse(const vespalib::string &input, bool valid, - const vespalib::string &base, ParamList pl, - const vespalib::string &output) +testParse(const vespalib::string &input, bool valid, + const vespalib::string &base, ParamList pl, + const vespalib::string &output) { bool ok = true; FeatureNameParser parser(input); @@ -52,15 +44,15 @@ Test::testParse(const vespalib::string &input, bool valid, LOG(warning, "parse error: input:'%s', rest:'%s'", input.c_str(), input.substr(parser.parsedBytes()).c_str()); } - ok &= EXPECT_EQUAL(parser.valid(), valid); - ok &= EXPECT_EQUAL(parser.baseName(), base); - ok &= EXPECT_EQUAL(ParamList(parser.parameters()), pl); - ok &= EXPECT_EQUAL(parser.output(), output); + EXPECT_EQ(parser.valid(), valid) << (ok = false, ""); + EXPECT_EQ(parser.baseName(), base) << (ok = false, ""); + EXPECT_EQ(ParamList(parser.parameters()), pl) << (ok = false, ""); + EXPECT_EQ(parser.output(), output) << (ok = false, ""); return ok; } void -Test::testFile(const vespalib::string &name) +testFile(const vespalib::string &name) { char buf[4_Ki]; uint32_t lineN = 0; @@ -76,13 +68,16 @@ Test::testFile(const vespalib::string &name) continue; } uint32_t idx = line.find("<=>"); - if (!EXPECT_TRUE(idx < line.size())) { + bool failed = false; + EXPECT_TRUE(idx < line.size()) << (failed = true, ""); + if (failed) { LOG(error, "(%s:%u): malformed line: '%s'", name.c_str(), lineN, line.c_str()); } else { vespalib::string input = line.substr(0, idx); vespalib::string expect = line.substr(idx + strlen("<=>")); - if (!EXPECT_EQUAL(FeatureNameParser(input).featureName(), expect)) { + EXPECT_EQ(FeatureNameParser(input).featureName(), expect) << (failed = true, ""); + if (failed) { LOG(error, "(%s:%u): test failed: '%s'", name.c_str(), lineN, line.c_str()); } @@ -92,42 +87,54 @@ Test::testFile(const vespalib::string &name) fclose(f); } -int -Test::Main() +TEST(FeatureNameParserTest, test_normal_cases) { - TEST_INIT("featurenameparser_test"); - // normal cases EXPECT_TRUE(testParse("foo", true, "foo", ParamList(), "")); EXPECT_TRUE(testParse("foo.out", true, "foo", ParamList(), "out")); EXPECT_TRUE(testParse("foo(a)", true, "foo", ParamList().add("a"), "")); EXPECT_TRUE(testParse("foo(a,b)", true, "foo", ParamList().add("a").add("b"), "")); EXPECT_TRUE(testParse("foo(a,b).out", true, "foo", ParamList().add("a").add("b"), "out")); +} +TEST(FeatureNameParserTest, test_0_in_feature_name) +{ // @ in feature name (for macros) EXPECT_TRUE(testParse("foo@", true, "foo@", ParamList(), "")); EXPECT_TRUE(testParse("foo@.out", true, "foo@", ParamList(), "out")); EXPECT_TRUE(testParse("foo@(a)", true, "foo@", ParamList().add("a"), "")); EXPECT_TRUE(testParse("foo@(a,b)", true, "foo@", ParamList().add("a").add("b"), "")); EXPECT_TRUE(testParse("foo@(a,b).out", true, "foo@", ParamList().add("a").add("b"), "out")); +} +TEST(FeatureNameParserTest, test_dollar_in_feature_name) +{ // $ in feature name (for macros) EXPECT_TRUE(testParse("foo$", true, "foo$", ParamList(), "")); EXPECT_TRUE(testParse("foo$.out", true, "foo$", ParamList(), "out")); EXPECT_TRUE(testParse("foo$(a)", true, "foo$", ParamList().add("a"), "")); EXPECT_TRUE(testParse("foo$(a,b)", true, "foo$", ParamList().add("a").add("b"), "")); EXPECT_TRUE(testParse("foo$(a,b).out", true, "foo$", ParamList().add("a").add("b"), "out")); +} +TEST(FeatureNameParserTest, test_de_quoting_of_parameters) +{ // de-quoting of parameters EXPECT_TRUE(testParse("foo(a,\"b\")", true, "foo", ParamList().add("a").add("b"), "")); EXPECT_TRUE(testParse("foo(a,\" b \")", true, "foo", ParamList().add("a").add(" b "), "")); EXPECT_TRUE(testParse("foo( \"a\" , \" b \" )", true, "foo", ParamList().add("a").add(" b "), "")); EXPECT_TRUE(testParse("foo(\"\\\"\\\\\\t\\n\\r\\f\\x20\")", true, "foo", ParamList().add("\"\\\t\n\r\f "), "")); +} +TEST(FeatureNameParserTest, test_no_default_output_when_ending_with_dot) +{ // only default output if '.' not specified EXPECT_TRUE(testParse("foo.", false, "", ParamList(), "")); EXPECT_TRUE(testParse("foo(a,b).", false, "", ParamList(), "")); +} +TEST(FeatureNameParserTest, test_string_cannot_end_in_parmeter_list) +{ // string cannot end in parameter list EXPECT_TRUE(testParse("foo(", false, "", ParamList(), "")); EXPECT_TRUE(testParse("foo(a", false, "", ParamList(), "")); @@ -135,7 +142,10 @@ Test::Main() EXPECT_TRUE(testParse("foo(a\\)", false, "", ParamList(), "")); EXPECT_TRUE(testParse("foo(a,", false, "", ParamList(), "")); EXPECT_TRUE(testParse("foo(a,b", false, "", ParamList(), "")); +} +TEST(FeatureNameParserTest, test_empty_parameters) +{ // empty parameters EXPECT_TRUE(testParse("foo()", true, "foo", ParamList().add(""), "")); EXPECT_TRUE(testParse("foo(,)", true, "foo", ParamList().add("").add(""), "")); @@ -144,9 +154,11 @@ Test::Main() EXPECT_TRUE(testParse("foo( )", true, "foo", ParamList().add(""), "")); EXPECT_TRUE(testParse("foo( , , )", true, "foo", ParamList().add("").add("").add(""), "")); EXPECT_TRUE(testParse("foo( \t , \n , \r , \f )", true, "foo", ParamList().add("").add("").add("").add(""), "")); +} +TEST(FeatureNameParserTest, test_cases_from_file) +{ testFile(TEST_PATH("parsetest.txt")); - TEST_DONE(); } -TEST_APPHOOK(Test); +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/searchlib/src/tests/fef/parameter/CMakeLists.txt b/searchlib/src/tests/fef/parameter/CMakeLists.txt index da847e061f9..b238e09c98b 100644 --- a/searchlib/src/tests/fef/parameter/CMakeLists.txt +++ b/searchlib/src/tests/fef/parameter/CMakeLists.txt @@ -4,5 +4,6 @@ vespa_add_executable(searchlib_parameter_test_app TEST parameter_test.cpp DEPENDS searchlib + GTest::gtest ) vespa_add_test(NAME searchlib_parameter_test_app NO_VALGRIND COMMAND searchlib_parameter_test_app) diff --git a/searchlib/src/tests/fef/parameter/parameter_test.cpp b/searchlib/src/tests/fef/parameter/parameter_test.cpp index fa29f16f1d5..a8acd2ea34d 100644 --- a/searchlib/src/tests/fef/parameter/parameter_test.cpp +++ b/searchlib/src/tests/fef/parameter/parameter_test.cpp @@ -1,32 +1,34 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> -LOG_SETUP("parameter_test"); -#include <vespa/vespalib/testkit/testapp.h> #include <vespa/searchlib/fef/parametervalidator.h> #include <vespa/searchlib/fef/test/indexenvironment.h> #include <vespa/searchlib/fef/test/indexenvironmentbuilder.h> +#include <vespa/vespalib/gtest/gtest.h> + +#include <vespa/log/log.h> +LOG_SETUP("parameter_test"); using namespace search::fef::test; using CollectionType = search::fef::FieldInfo::CollectionType; using DataType = search::fef::FieldInfo::DataType; -namespace search { -namespace fef { +namespace search::fef { class StringList : public std::vector<vespalib::string> { public: StringList & add(const vespalib::string & str) { push_back(str); return *this; } }; -class ParameterTest : public vespalib::TestApp { -private: +class ParameterTest : public ::testing::Test { +protected: using PDS = ParameterDescriptions; using PT = ParameterType; using P = Parameter; using SL = StringList; using PVR = ParameterValidator::Result; + ParameterTest(); + ~ParameterTest() override; bool assertParameter(const Parameter & exp, const Parameter & act); bool validate(const IIndexEnvironment & env, const std::vector<vespalib::string> & params, @@ -35,24 +37,20 @@ private: const std::vector<vespalib::string> & params, const ParameterDescriptions & descs, const ParameterValidator::Result & result); - - void testDescriptions(); - void testValidator(); - void testParameters(); - -public: - int Main() override; }; +ParameterTest::ParameterTest() = default; +ParameterTest::~ParameterTest() = default; + bool ParameterTest::assertParameter(const Parameter & exp, const Parameter & act) { bool retval = true; - if (!EXPECT_EQUAL(exp.getType(), act.getType())) retval = false; - if (!EXPECT_EQUAL(exp.getValue(), act.getValue())) retval = false; - if (!EXPECT_EQUAL(exp.asDouble(), act.asDouble())) retval = false; - if (!EXPECT_EQUAL(exp.asInteger(), act.asInteger())) retval = false; - if (!EXPECT_EQUAL(exp.asField(), act.asField())) retval = false; + EXPECT_EQ(exp.getType(), act.getType()) << (retval = false, ""); + EXPECT_EQ(exp.getValue(), act.getValue()) << (retval = false, ""); + EXPECT_EQ(exp.asDouble(), act.asDouble()) << (retval = false, ""); + EXPECT_EQ(exp.asInteger(), act.asInteger()) << (retval = false, ""); + EXPECT_EQ(exp.asField(), act.asField()) << (retval = false, ""); return retval; } @@ -76,8 +74,15 @@ ParameterTest::validate(const IIndexEnvironment & env, if (!validate(env, params, descs)) return false; ParameterValidator pv(env, params, descs); ParameterValidator::Result actual = pv.validate(); - if (!EXPECT_EQUAL(result.getTag(), actual.getTag())) return false; - if (!EXPECT_EQUAL(result.getParameters().size(), actual.getParameters().size())) return false; + bool failed = false; + EXPECT_EQ(result.getTag(), actual.getTag()) << (failed = true, ""); + if (failed) { + return false; + } + EXPECT_EQ(result.getParameters().size(), actual.getParameters().size()) << (failed = true, ""); + if (failed) { + return false; + } bool retval = true; for (size_t i = 0; i < result.getParameters().size(); ++i) { if (!assertParameter(result.getParameters()[i], actual.getParameters()[i])) retval = false; @@ -85,52 +90,50 @@ ParameterTest::validate(const IIndexEnvironment & env, return retval; } -void -ParameterTest::testDescriptions() +TEST_F(ParameterTest, test_descriptions) { PDS descs = PDS(). desc().indexField(ParameterCollection::SINGLE).indexField(ParameterCollection::ARRAY).indexField(ParameterCollection::WEIGHTEDSET).attribute(ParameterCollection::ANY).attributeField(ParameterCollection::ANY).field(). desc(5).feature().number().string().attribute(ParameterCollection::ANY). desc().string().number().repeat(2); const PDS::DescriptionVector & v = descs.getDescriptions(); - EXPECT_EQUAL(v.size(), 3u); - EXPECT_EQUAL(v[0].getTag(), 0u); + EXPECT_EQ(v.size(), 3u); + EXPECT_EQ(v[0].getTag(), 0u); EXPECT_TRUE(!v[0].hasRepeat()); - EXPECT_EQUAL(v[0].getParams().size(), 6u); - EXPECT_EQUAL(v[0].getParam(0).type, ParameterType::INDEX_FIELD); - EXPECT_EQUAL(v[0].getParam(1).type, ParameterType::INDEX_FIELD); - EXPECT_EQUAL(v[0].getParam(2).type, ParameterType::INDEX_FIELD); - EXPECT_EQUAL(v[0].getParam(3).type, ParameterType::ATTRIBUTE); - EXPECT_EQUAL(v[0].getParam(4).type, ParameterType::ATTRIBUTE_FIELD); - EXPECT_EQUAL(v[0].getParam(5).type, ParameterType::FIELD); - EXPECT_EQUAL(v[0].getParam(0).collection, ParameterCollection::SINGLE); - EXPECT_EQUAL(v[0].getParam(1).collection, ParameterCollection::ARRAY); - EXPECT_EQUAL(v[0].getParam(2).collection, ParameterCollection::WEIGHTEDSET); - EXPECT_EQUAL(v[0].getParam(3).collection, ParameterCollection::ANY); - EXPECT_EQUAL(v[0].getParam(4).collection, ParameterCollection::ANY); - EXPECT_EQUAL(v[0].getParam(5).collection, ParameterCollection::ANY); + EXPECT_EQ(v[0].getParams().size(), 6u); + EXPECT_EQ(v[0].getParam(0).type, ParameterType::INDEX_FIELD); + EXPECT_EQ(v[0].getParam(1).type, ParameterType::INDEX_FIELD); + EXPECT_EQ(v[0].getParam(2).type, ParameterType::INDEX_FIELD); + EXPECT_EQ(v[0].getParam(3).type, ParameterType::ATTRIBUTE); + EXPECT_EQ(v[0].getParam(4).type, ParameterType::ATTRIBUTE_FIELD); + EXPECT_EQ(v[0].getParam(5).type, ParameterType::FIELD); + EXPECT_EQ(v[0].getParam(0).collection, ParameterCollection::SINGLE); + EXPECT_EQ(v[0].getParam(1).collection, ParameterCollection::ARRAY); + EXPECT_EQ(v[0].getParam(2).collection, ParameterCollection::WEIGHTEDSET); + EXPECT_EQ(v[0].getParam(3).collection, ParameterCollection::ANY); + EXPECT_EQ(v[0].getParam(4).collection, ParameterCollection::ANY); + EXPECT_EQ(v[0].getParam(5).collection, ParameterCollection::ANY); - EXPECT_EQUAL(v[1].getTag(), 5u); + EXPECT_EQ(v[1].getTag(), 5u); EXPECT_TRUE(!v[1].hasRepeat()); - EXPECT_EQUAL(v[1].getParams().size(), 4u); - EXPECT_EQUAL(v[1].getParam(0).type, ParameterType::FEATURE); - EXPECT_EQUAL(v[1].getParam(1).type, ParameterType::NUMBER); - EXPECT_EQUAL(v[1].getParam(2).type, ParameterType::STRING); - EXPECT_EQUAL(v[1].getParam(3).type, ParameterType::ATTRIBUTE); + EXPECT_EQ(v[1].getParams().size(), 4u); + EXPECT_EQ(v[1].getParam(0).type, ParameterType::FEATURE); + EXPECT_EQ(v[1].getParam(1).type, ParameterType::NUMBER); + EXPECT_EQ(v[1].getParam(2).type, ParameterType::STRING); + EXPECT_EQ(v[1].getParam(3).type, ParameterType::ATTRIBUTE); - EXPECT_EQUAL(v[2].getTag(), 6u); + EXPECT_EQ(v[2].getTag(), 6u); EXPECT_TRUE(v[2].hasRepeat()); - EXPECT_EQUAL(v[2].getParams().size(), 2u); - EXPECT_EQUAL(v[2].getParam(0).type, ParameterType::STRING); - EXPECT_EQUAL(v[2].getParam(1).type, ParameterType::NUMBER); - EXPECT_EQUAL(v[2].getParam(2).type, ParameterType::STRING); - EXPECT_EQUAL(v[2].getParam(3).type, ParameterType::NUMBER); - EXPECT_EQUAL(v[2].getParam(4).type, ParameterType::STRING); - EXPECT_EQUAL(v[2].getParam(5).type, ParameterType::NUMBER); + EXPECT_EQ(v[2].getParams().size(), 2u); + EXPECT_EQ(v[2].getParam(0).type, ParameterType::STRING); + EXPECT_EQ(v[2].getParam(1).type, ParameterType::NUMBER); + EXPECT_EQ(v[2].getParam(2).type, ParameterType::STRING); + EXPECT_EQ(v[2].getParam(3).type, ParameterType::NUMBER); + EXPECT_EQ(v[2].getParam(4).type, ParameterType::STRING); + EXPECT_EQ(v[2].getParam(5).type, ParameterType::NUMBER); } -void -ParameterTest::testValidator() +TEST_F(ParameterTest, test_validator) { IndexEnvironment env; IndexEnvironmentBuilder builder(env); @@ -201,8 +204,7 @@ ParameterTest::testValidator() EXPECT_TRUE(!validate(env, SL().add("str").add("bar").add("foo").add("bar"), d2)); } -void -ParameterTest::testParameters() +TEST_F(ParameterTest, test_parameters) { IndexEnvironment env; IndexEnvironmentBuilder builder(env); @@ -254,20 +256,6 @@ ParameterTest::testParameters() PVR(20).addParameter(P(PT::STRING, "baz")))); // second desc matching } -int -ParameterTest::Main() -{ - TEST_INIT("parameter_test"); - - testDescriptions(); - testValidator(); - testParameters(); - - TEST_DONE(); } -} -} - -TEST_APPHOOK(search::fef::ParameterTest); - +GTEST_MAIN_RUN_ALL_TESTS() |