diff options
author | Henning Baldersheim <balder@oath.com> | 2018-08-20 13:38:58 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-08-20 13:38:58 +0200 |
commit | 9cb7442c74b6c7d4f3aac89f26f849ab11ec110f (patch) | |
tree | 9d458a456c7805f8a0bfe7ce43889e227006cdd0 /searchlib/src/tests | |
parent | 59ffc5091b8246674843deea81a11a917abf801e (diff) |
Use std::make_xxx
nested namespace
And various other style changes.
Diffstat (limited to 'searchlib/src/tests')
6 files changed, 150 insertions, 296 deletions
diff --git a/searchlib/src/tests/attribute/attribute_test.cpp b/searchlib/src/tests/attribute/attribute_test.cpp index f44a1c39baf..d4f716acb7a 100644 --- a/searchlib/src/tests/attribute/attribute_test.cpp +++ b/searchlib/src/tests/attribute/attribute_test.cpp @@ -31,19 +31,20 @@ using search::common::FileHeaderContext; using search::index::DummyFileHeaderContext; using search::attribute::BasicType; using search::attribute::IAttributeVector; +using vespalib::stringref; +using vespalib::string; namespace { -vespalib::string empty; -vespalib::string tmpDir("tmp"); -vespalib::string clsDir("clstmp"); -vespalib::string asuDir("asutmp"); +string empty; +string tmpDir("tmp"); +string clsDir("clstmp"); +string asuDir("asutmp"); bool isUnsignedSmallIntAttribute(const BasicType::Type &type) { - switch (type) - { + switch (type) { case BasicType::UINT1: case BasicType::UINT2: case BasicType::UINT4: @@ -68,13 +69,13 @@ expectZero(const BufferType &b) template <> void -expectZero(const vespalib::string &b) +expectZero(const string &b) { EXPECT_EQUAL(empty, b); } uint64_t -statSize(const vespalib::string &fileName) +statSize(const string &fileName) { FastOS_StatInfo statInfo; if (EXPECT_TRUE(FastOS_File::Stat(fileName.c_str(), &statInfo))) { @@ -112,14 +113,14 @@ preciseEstimatedSize(const AttributeVector &a) return true; } -vespalib::string -baseFileName(const vespalib::string &attrName) +string +baseFileName(const string &attrName) { return tmpDir + "/" + attrName; } AttributeVector::SP -createAttribute(const vespalib::string &attrName, const search::attribute::Config &cfg) +createAttribute(stringref attrName, const search::attribute::Config &cfg) { return search::AttributeFactory::createAttribute(baseFileName(attrName), cfg); } @@ -162,7 +163,7 @@ private: template <typename T> void fillNumeric(std::vector<T> & values, uint32_t numValues); - void fillString(std::vector<vespalib::string> & values, uint32_t numValues); + void fillString(std::vector<string> & values, uint32_t numValues); template <typename VectorType, typename BufferType> bool appendToVector(VectorType & v, uint32_t doc, uint32_t valueCount, const std::vector<BufferType> & values); @@ -218,9 +219,7 @@ private: template <typename VectorType, typename BufferType> void - testCompactLidSpace(const Config &config, - bool fs, - bool es); + testCompactLidSpace(const Config &config, bool fs, bool es); template <typename VectorType, typename BufferType> void @@ -427,7 +426,7 @@ void AttributeTest::testReloadString(const AttributePtr & a, const AttributePtr if (a->hasWeightedSetType()) { testReload<StringAttribute, StringAttribute::WeightedString>(a, b, c); } else { - testReload<StringAttribute, vespalib::string>(a, b, c); + testReload<StringAttribute, string>(a, b, c); } } @@ -696,7 +695,7 @@ AttributeTest::testMemorySaverString(const AttributePtr & a, const AttributePtr if (a->hasWeightedSetType()) { testMemorySaver<StringAttribute, StringAttribute::WeightedString>(a, b); } else { - testMemorySaver<StringAttribute, vespalib::string>(a, b); + testMemorySaver<StringAttribute, string>(a, b); } } @@ -762,7 +761,6 @@ AttributeTest::testMemorySaver() } } - template <typename T> void AttributeTest::fillNumeric(std::vector<T> & values, uint32_t numValues) @@ -775,7 +773,7 @@ AttributeTest::fillNumeric(std::vector<T> & values, uint32_t numValues) } void -AttributeTest::fillString(std::vector<vespalib::string> & values, uint32_t numValues) +AttributeTest::fillString(std::vector<string> & values, uint32_t numValues) { values.clear(); values.reserve(numValues); @@ -941,19 +939,19 @@ AttributeTest::testSingle() } { - std::vector<vespalib::string> values; + std::vector<string> values; fillString(values, numUniques); { AttributePtr ptr = createAttribute("sv-string", Config(BasicType::STRING, CollectionType::SINGLE)); addDocs(ptr, numDocs); - testSingle<StringAttribute, vespalib::string, vespalib::string>(ptr, values); + testSingle<StringAttribute, string, string>(ptr, values); } { Config cfg(Config(BasicType::STRING, CollectionType::SINGLE)); cfg.setFastSearch(true); AttributePtr ptr = createAttribute("sv-fs-string", cfg); addDocs(ptr, numDocs); - testSingle<StringAttribute, vespalib::string, vespalib::string>(ptr, values); + testSingle<StringAttribute, string, string>(ptr, values); } } } @@ -1052,7 +1050,6 @@ AttributeTest::testArray(const AttributePtr & ptr, const std::vector<BufferType> } EXPECT_TRUE(!v.remove(ptr->getNumDocs(), values[0], 1)); - // test clearDoc() for (uint32_t doc = 0; doc < ptr->getNumDocs(); ++doc) { uint32_t valueCount = doc % numUniques; @@ -1132,19 +1129,19 @@ AttributeTest::testArray() } } { // StringAttribute - std::vector<vespalib::string> values; + std::vector<string> values; fillString(values, numUniques); { AttributePtr ptr = createAttribute("a-string", Config(BasicType::STRING, CollectionType::ARRAY)); addDocs(ptr, numDocs); - testArray<StringAttribute, vespalib::string>(ptr, values); + testArray<StringAttribute, string>(ptr, values); } { Config cfg(BasicType::STRING, CollectionType::ARRAY); cfg.setFastSearch(true); AttributePtr ptr = createAttribute("afs-string", cfg); addDocs(ptr, numDocs); - testArray<StringAttribute, vespalib::string>(ptr, values); + testArray<StringAttribute, string>(ptr, values); } } } @@ -1266,8 +1263,7 @@ AttributeTest::testWeightedSet() } { - AttributePtr ptr = createAttribute - ("wsint32", Config(BasicType::INT32, CollectionType::WSET)); + AttributePtr ptr = createAttribute("wsint32", Config(BasicType::INT32, CollectionType::WSET)); addDocs(ptr, numDocs); testWeightedSet<IntegerAttribute, AttributeVector::WeightedInt>(ptr, values); } @@ -1319,8 +1315,7 @@ AttributeTest::testWeightedSet() } { - AttributePtr ptr = createAttribute - ("wsstr", Config(BasicType::STRING, CollectionType::WSET)); + AttributePtr ptr = createAttribute("wsstr", Config(BasicType::STRING, CollectionType::WSET)); addDocs(ptr, numDocs); testWeightedSet<StringAttribute, AttributeVector::WeightedString>(ptr, values); } @@ -1571,14 +1566,10 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 6u); EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 0u); - EXPECT_TRUE(ptr->apply(0, MapVU(initFieldValue, - ArithVU(ArithVU::Add, 10)))); - EXPECT_TRUE(ptr->apply(1, MapVU(initFieldValue, - ArithVU(ArithVU::Sub, 10)))); - EXPECT_TRUE(ptr->apply(2, MapVU(initFieldValue, - ArithVU(ArithVU::Mul, 10)))); - EXPECT_TRUE(ptr->apply(3, MapVU(initFieldValue, - ArithVU(ArithVU::Div, 10)))); + EXPECT_TRUE(ptr->apply(0, MapVU(initFieldValue, ArithVU(ArithVU::Add, 10)))); + EXPECT_TRUE(ptr->apply(1, MapVU(initFieldValue, ArithVU(ArithVU::Sub, 10)))); + EXPECT_TRUE(ptr->apply(2, MapVU(initFieldValue, ArithVU(ArithVU::Mul, 10)))); + EXPECT_TRUE(ptr->apply(3, MapVU(initFieldValue, ArithVU(ArithVU::Div, 10)))); ptr->commit(); EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 10u); EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 4u); @@ -1594,8 +1585,7 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue EXPECT_EQUAL(buf[0].getWeight(), 10); // removeifzero - EXPECT_TRUE(ptr->apply(4, MapVU(initFieldValue, - ArithVU(ArithVU::Sub, 100)))); + EXPECT_TRUE(ptr->apply(4, MapVU(initFieldValue, ArithVU(ArithVU::Sub, 100)))); ptr->commit(); if (removeIfZero) { EXPECT_EQUAL(ptr->get(4, &buf[0], 2), uint32_t(0)); @@ -1607,8 +1597,7 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 5u); // createifnonexistant - EXPECT_TRUE(ptr->apply(5, MapVU(nonExistant, - ArithVU(ArithVU::Add, 10)))); + EXPECT_TRUE(ptr->apply(5, MapVU(nonExistant, ArithVU(ArithVU::Add, 10)))); ptr->commit(); if (createIfNonExistant) { EXPECT_EQUAL(ptr->get(5, &buf[0], 2), uint32_t(2)); @@ -1639,25 +1628,21 @@ void AttributeTest::testMapValueUpdate() { { // regular set - AttributePtr ptr = createAttribute - ("wsint32", Config(BasicType::INT32, CollectionType::WSET)); + AttributePtr ptr = createAttribute("wsint32", Config(BasicType::INT32, CollectionType::WSET)); testMapValueUpdate<IntegerAttribute, AttributeVector::WeightedInt> - (ptr, AttributeVector::WeightedInt(64, 1), IntFieldValue(64), - IntFieldValue(32), false, false); + (ptr, AttributeVector::WeightedInt(64, 1), IntFieldValue(64), IntFieldValue(32), false, false); } { // remove if zero - AttributePtr ptr = createAttribute - ("wsint32", Config(BasicType::INT32, CollectionType(CollectionType::WSET, true, false))); + AttributePtr ptr = createAttribute("wsint32", Config(BasicType::INT32, + CollectionType(CollectionType::WSET, true, false))); testMapValueUpdate<IntegerAttribute, AttributeVector::WeightedInt> - (ptr, AttributeVector::WeightedInt(64, 1), IntFieldValue(64), - IntFieldValue(32), true, false); + (ptr, AttributeVector::WeightedInt(64, 1), IntFieldValue(64), IntFieldValue(32), true, false); } { // create if non existant - AttributePtr ptr = createAttribute - ("wsint32", Config(BasicType::INT32, CollectionType(CollectionType::WSET, false, true))); + AttributePtr ptr = createAttribute("wsint32", Config(BasicType::INT32, + CollectionType(CollectionType::WSET, false, true))); testMapValueUpdate<IntegerAttribute, AttributeVector::WeightedInt> - (ptr, AttributeVector::WeightedInt(64, 1), IntFieldValue(64), - IntFieldValue(32), false, true); + (ptr, AttributeVector::WeightedInt(64, 1), IntFieldValue(64), IntFieldValue(32), false, true); } Config setCfg(Config(BasicType::STRING, CollectionType::WSET)); @@ -1667,20 +1652,17 @@ AttributeTest::testMapValueUpdate() { // regular set AttributePtr ptr = createAttribute("wsstr", setCfg); testMapValueUpdate<StringAttribute, AttributeVector::WeightedString> - (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), - StringFieldValue("second"), false, false); + (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), StringFieldValue("second"), false, false); } { // remove if zero AttributePtr ptr = createAttribute("wsstr", setRemoveCfg); testMapValueUpdate<StringAttribute, AttributeVector::WeightedString> - (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), - StringFieldValue("second"), true, false); + (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), StringFieldValue("second"), true, false); } { // create if non existant AttributePtr ptr = createAttribute("wsstr", setCreateCfg); testMapValueUpdate<StringAttribute, AttributeVector::WeightedString> - (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), - StringFieldValue("second"), false, true); + (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), StringFieldValue("second"), false, true); } // fast-search - posting lists @@ -1688,46 +1670,38 @@ AttributeTest::testMapValueUpdate() setCfg.setFastSearch(true); AttributePtr ptr = createAttribute("wsfsstr", setCfg); testMapValueUpdate<StringAttribute, AttributeVector::WeightedString> - (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), - StringFieldValue("second"), false, false); + (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), StringFieldValue("second"), false, false); } { // remove if zero setRemoveCfg.setFastSearch(true); AttributePtr ptr = createAttribute("wsfsstr", setRemoveCfg); testMapValueUpdate<StringAttribute, AttributeVector::WeightedString> - (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), - StringFieldValue("second"), true, false); + (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), StringFieldValue("second"), true, false); } { // create if non existant setCreateCfg.setFastSearch(true); AttributePtr ptr = createAttribute("wsfsstr", setCreateCfg); testMapValueUpdate<StringAttribute, AttributeVector::WeightedString> - (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), - StringFieldValue("second"), false, true); + (ptr, AttributeVector::WeightedString("first", 1), StringFieldValue("first"), StringFieldValue("second"), false, true); } } - - void AttributeTest::commit(const AttributePtr & ptr) { ptr->commit(); } - void AttributeTest::testStatus() { - std::vector<vespalib::string> values; + std::vector<string> values; fillString(values, 16); uint32_t numDocs = 100; // No posting list - static constexpr size_t LeafNodeSize = - 4 + sizeof(EnumStoreBase::Index) * EnumTreeTraits::LEAF_SLOTS; + static constexpr size_t LeafNodeSize = 4 + sizeof(EnumStoreBase::Index) * EnumTreeTraits::LEAF_SLOTS; static constexpr size_t InternalNodeSize = - 8 + (sizeof(EnumStoreBase::Index) + - sizeof(datastore::EntryRef)) * EnumTreeTraits::INTERNAL_SLOTS; + 8 + (sizeof(EnumStoreBase::Index) + sizeof(datastore::EntryRef)) * EnumTreeTraits::INTERNAL_SLOTS; static constexpr size_t NestedVectorSize = 24; // sizeof(vespalib::Array) { @@ -1782,9 +1756,9 @@ AttributeTest::testNullProtection() size_t len1 = strlen("evil"); size_t len2 = strlen("string"); size_t len = len1 + 1 + len2; - vespalib::string good("good"); - vespalib::string evil("evil string"); - vespalib::string pureEvil("evil"); + string good("good"); + string evil("evil string"); + string pureEvil("evil"); EXPECT_EQUAL(strlen(evil.data()), len); EXPECT_EQUAL(strlen(evil.c_str()), len); evil[len1] = 0; // replace space with '\0' @@ -1797,7 +1771,7 @@ AttributeTest::testNullProtection() EXPECT_EQUAL(evil.size(), len); { // string AttributeVector::DocId docId; - std::vector<vespalib::string> buf(16); + std::vector<string> buf(16); AttributePtr attr = createAttribute("string", Config(BasicType::STRING, CollectionType::SINGLE)); StringAttribute &v = static_cast<StringAttribute &>(*attr.get()); EXPECT_TRUE(v.addDoc(docId)); @@ -1809,7 +1783,7 @@ AttributeTest::testNullProtection() } { // string array AttributeVector::DocId docId; - std::vector<vespalib::string> buf(16); + std::vector<string> buf(16); AttributePtr attr = createAttribute("string", Config(BasicType::STRING, CollectionType::ARRAY)); StringAttribute &v = static_cast<StringAttribute &>(*attr.get()); EXPECT_TRUE(v.addDoc(docId)); @@ -2047,7 +2021,6 @@ AttributeTest::testCompactLidSpace(const Config &config, compare<VectorType, BufferType>(v, v3); } - template <typename VectorType, typename BufferType> void AttributeTest::testCompactLidSpace(const Config &config) @@ -2061,7 +2034,6 @@ AttributeTest::testCompactLidSpace(const Config &config) testCompactLidSpace<VectorType, BufferType>(config, true, true); } - void AttributeTest::testCompactLidSpace(const Config &config) { @@ -2074,28 +2046,24 @@ AttributeTest::testCompactLidSpace(const Config &config) case BasicType::INT32: case BasicType::INT64: if (config.collectionType() == CollectionType::WSET) { - testCompactLidSpace<IntegerAttribute, - IntegerAttribute::WeightedInt>(config); + testCompactLidSpace<IntegerAttribute, IntegerAttribute::WeightedInt>(config); } else { - testCompactLidSpace<IntegerAttribute, - IntegerAttribute::largeint_t>(config); + testCompactLidSpace<IntegerAttribute, IntegerAttribute::largeint_t>(config); } break; case BasicType::FLOAT: case BasicType::DOUBLE: if (config.collectionType() == CollectionType::WSET) { - testCompactLidSpace<FloatingPointAttribute, - FloatingPointAttribute::WeightedFloat>(config); + testCompactLidSpace<FloatingPointAttribute, FloatingPointAttribute::WeightedFloat>(config); } else { testCompactLidSpace<FloatingPointAttribute, double>(config); } break; case BasicType::STRING: if (config.collectionType() == CollectionType::WSET) { - testCompactLidSpace<StringAttribute, - StringAttribute::WeightedString>(config); + testCompactLidSpace<StringAttribute, StringAttribute::WeightedString>(config); } else { - testCompactLidSpace<StringAttribute, vespalib::string>(config); + testCompactLidSpace<StringAttribute, string>(config); } break; default: @@ -2103,58 +2071,33 @@ AttributeTest::testCompactLidSpace(const Config &config) } } - void AttributeTest::testCompactLidSpace() { - TEST_DO(testCompactLidSpace(Config(BasicType::UINT1, - CollectionType::SINGLE))); - TEST_DO(testCompactLidSpace(Config(BasicType::UINT2, - CollectionType::SINGLE))); - TEST_DO(testCompactLidSpace(Config(BasicType::UINT4, - CollectionType::SINGLE))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT8, - CollectionType::SINGLE))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT8, - CollectionType::ARRAY))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT8, - CollectionType::WSET))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT16, - CollectionType::SINGLE))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT16, - CollectionType::ARRAY))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT16, - CollectionType::WSET))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT32, - CollectionType::SINGLE))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT32, - CollectionType::ARRAY))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT32, - CollectionType::WSET))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT64, - CollectionType::SINGLE))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT64, - CollectionType::ARRAY))); - TEST_DO(testCompactLidSpace(Config(BasicType::INT64, - CollectionType::WSET))); - TEST_DO(testCompactLidSpace(Config(BasicType::FLOAT, - CollectionType::SINGLE))); - TEST_DO(testCompactLidSpace(Config(BasicType::FLOAT, - CollectionType::ARRAY))); - TEST_DO(testCompactLidSpace(Config(BasicType::FLOAT, - CollectionType::WSET))); - TEST_DO(testCompactLidSpace(Config(BasicType::DOUBLE, - CollectionType::SINGLE))); - TEST_DO(testCompactLidSpace(Config(BasicType::DOUBLE, - CollectionType::ARRAY))); - TEST_DO(testCompactLidSpace(Config(BasicType::DOUBLE, - CollectionType::WSET))); - TEST_DO(testCompactLidSpace(Config(BasicType::STRING, - CollectionType::SINGLE))); - TEST_DO(testCompactLidSpace(Config(BasicType::STRING, - CollectionType::ARRAY))); - TEST_DO(testCompactLidSpace(Config(BasicType::STRING, - CollectionType::WSET))); + TEST_DO(testCompactLidSpace(Config(BasicType::UINT1, CollectionType::SINGLE))); + TEST_DO(testCompactLidSpace(Config(BasicType::UINT2, CollectionType::SINGLE))); + TEST_DO(testCompactLidSpace(Config(BasicType::UINT4, CollectionType::SINGLE))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT8, CollectionType::SINGLE))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT8, CollectionType::ARRAY))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT8, CollectionType::WSET))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT16, CollectionType::SINGLE))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT16, CollectionType::ARRAY))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT16, CollectionType::WSET))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT32, CollectionType::SINGLE))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT32, CollectionType::ARRAY))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT32, CollectionType::WSET))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT64, CollectionType::SINGLE))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT64, CollectionType::ARRAY))); + TEST_DO(testCompactLidSpace(Config(BasicType::INT64, CollectionType::WSET))); + TEST_DO(testCompactLidSpace(Config(BasicType::FLOAT, CollectionType::SINGLE))); + TEST_DO(testCompactLidSpace(Config(BasicType::FLOAT, CollectionType::ARRAY))); + TEST_DO(testCompactLidSpace(Config(BasicType::FLOAT, CollectionType::WSET))); + TEST_DO(testCompactLidSpace(Config(BasicType::DOUBLE, CollectionType::SINGLE))); + TEST_DO(testCompactLidSpace(Config(BasicType::DOUBLE, CollectionType::ARRAY))); + TEST_DO(testCompactLidSpace(Config(BasicType::DOUBLE, CollectionType::WSET))); + TEST_DO(testCompactLidSpace(Config(BasicType::STRING, CollectionType::SINGLE))); + TEST_DO(testCompactLidSpace(Config(BasicType::STRING, CollectionType::ARRAY))); + TEST_DO(testCompactLidSpace(Config(BasicType::STRING, CollectionType::WSET))); } template <typename AttributeType> @@ -2220,7 +2163,6 @@ AttributeTest::requireThatAddressSpaceUsageIsReported() TEST_DO(requireThatAddressSpaceUsageIsReported<StringAttribute>(Config(BasicType::STRING, CollectionType::ARRAY))); } - template <typename AttributeType, typename BufferType> void AttributeTest::testReaderDuringLastUpdate(const Config &config, bool fs, bool compact) @@ -2230,7 +2172,7 @@ AttributeTest::testReaderDuringLastUpdate(const Config &config, bool fs, bool co config.collectionType().asString() << (fs ? "-fs" : "") << (compact ? "-compact" : ""); - vespalib::string name(ss.str()); + string name(ss.str()); Config cfg = config; cfg.setFastSearch(fs); cfg.setGrowStrategy(GrowStrategy::make(100, 50, 0)); @@ -2261,7 +2203,6 @@ AttributeTest::testReaderDuringLastUpdate(const Config &config, bool fs, bool co } } - template <typename AttributeType, typename BufferType> void AttributeTest::testReaderDuringLastUpdate(const Config &config) @@ -2281,8 +2222,8 @@ AttributeTest::testReaderDuringLastUpdate() TEST_DO((testReaderDuringLastUpdate<FloatingPointAttribute,double>(Config(BasicType::FLOAT, CollectionType::SINGLE)))); TEST_DO((testReaderDuringLastUpdate<FloatingPointAttribute,double>(Config(BasicType::FLOAT, CollectionType::ARRAY)))); TEST_DO((testReaderDuringLastUpdate<FloatingPointAttribute,FloatingPointAttribute::WeightedFloat>(Config(BasicType::FLOAT, CollectionType::WSET)))); - TEST_DO((testReaderDuringLastUpdate<StringAttribute,vespalib::string>(Config(BasicType::STRING, CollectionType::SINGLE)))); - TEST_DO((testReaderDuringLastUpdate<StringAttribute,vespalib::string>(Config(BasicType::STRING, CollectionType::ARRAY)))); + TEST_DO((testReaderDuringLastUpdate<StringAttribute,string>(Config(BasicType::STRING, CollectionType::SINGLE)))); + TEST_DO((testReaderDuringLastUpdate<StringAttribute,string>(Config(BasicType::STRING, CollectionType::ARRAY)))); TEST_DO((testReaderDuringLastUpdate<StringAttribute,StringAttribute::WeightedString>(Config(BasicType::STRING, CollectionType::WSET)))); } @@ -2374,5 +2315,4 @@ int AttributeTest::Main() } - TEST_APPHOOK(search::AttributeTest); diff --git a/searchlib/src/tests/attribute/attributemanager/attributemanager_test.cpp b/searchlib/src/tests/attribute/attributemanager/attributemanager_test.cpp index 3e6760ec5e4..5911d74dcb0 100644 --- a/searchlib/src/tests/attribute/attributemanager/attributemanager_test.cpp +++ b/searchlib/src/tests/attribute/attributemanager/attributemanager_test.cpp @@ -1,6 +1,5 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> -LOG_SETUP("attribute_test"); + #include <vespa/searchlib/attribute/attribute.h> #include <vespa/searchlib/attribute/attributeguard.h> #include <vespa/searchlib/attribute/attributefactory.h> @@ -10,13 +9,16 @@ LOG_SETUP("attribute_test"); #include <vespa/searchlib/attribute/multinumericattribute.hpp> #include <vespa/searchlib/attribute/stringattribute.h> #include <vespa/vespalib/testkit/testapp.h> -#include <algorithm> + +#include <vespa/log/log.h> +LOG_SETUP("attribute_test"); using namespace config; using namespace vespa::config::search; using namespace search; using namespace search::attribute; using std::shared_ptr; +using vespalib::stringref; typedef BasicType BT; typedef CollectionType CT; @@ -59,40 +61,14 @@ class TestAttribute : public TestAttributeBase { public: TestAttribute(const std::string &name) - : - TestAttributeBase(name) - { - } - - generation_t - getGen() const - { - return getCurrentGeneration(); - } - - uint32_t - getRefCount(generation_t gen) const - { - return getGenerationRefCount(gen); - } - - void - incGen() - { - incGeneration(); - } - - void - updateFirstUsedGen() - { - updateFirstUsedGeneration(); - } - - generation_t - getFirstUsedGen() const - { - return getFirstUsedGeneration(); - } + : TestAttributeBase(name) + {} + + generation_t getGen() const { return getCurrentGeneration(); } + uint32_t getRefCount(generation_t gen) const { return getGenerationRefCount(gen); } + void incGen() { incGeneration(); } + void updateFirstUsedGen() { updateFirstUsedGeneration(); } + generation_t getFirstUsedGen() const { return getFirstUsedGeneration(); } }; @@ -216,8 +192,7 @@ AttributeManagerTest::testLoad() bool -AttributeManagerTest::assertDataType(BT::Type exp, - AttributesConfig::Attribute::Datatype in) +AttributeManagerTest::assertDataType(BT::Type exp, AttributesConfig::Attribute::Datatype in) { AttributesConfig::Attribute a; a.datatype = in; @@ -227,10 +202,8 @@ AttributeManagerTest::assertDataType(BT::Type exp, bool AttributeManagerTest:: -assertCollectionType(CollectionType exp, - AttributesConfig::Attribute::Collectiontype in, - bool removeIfZ, - bool createIfNe) +assertCollectionType(CollectionType exp, AttributesConfig::Attribute::Collectiontype in, + bool removeIfZ, bool createIfNe) { AttributesConfig::Attribute a; a.collectiontype = in; @@ -239,8 +212,7 @@ assertCollectionType(CollectionType exp, AttributeVector::Config out = ConfigConverter::convert(a); return EXPECT_EQUAL(exp.type(), out.collectionType().type()) && EXPECT_EQUAL(exp.removeIfZero(), out.collectionType().removeIfZero()) && - EXPECT_EQUAL(exp.createIfNonExistant(), - out.collectionType().createIfNonExistant()); + EXPECT_EQUAL(exp.createIfNonExistant(), out.collectionType().createIfNonExistant()); } @@ -308,14 +280,10 @@ AttributeManagerTest::testContext() { std::vector<AVSP> attrs; // create various attributes vectors - attrs.push_back(AttributeFactory::createAttribute("sint32", - Config(BT::INT32, CT::SINGLE))); - attrs.push_back(AttributeFactory::createAttribute("aint32", - Config(BT::INT32, CT::ARRAY))); - attrs.push_back(AttributeFactory::createAttribute("wsint32", - Config(BT::INT32, CT::WSET))); - attrs.push_back(AttributeFactory::createAttribute("dontcare", - Config(BT::INT32, CT::SINGLE))); + attrs.push_back(AttributeFactory::createAttribute("sint32", Config(BT::INT32, CT::SINGLE))); + attrs.push_back(AttributeFactory::createAttribute("aint32", Config(BT::INT32, CT::ARRAY))); + attrs.push_back(AttributeFactory::createAttribute("wsint32", Config(BT::INT32, CT::WSET))); + attrs.push_back(AttributeFactory::createAttribute("dontcare", Config(BT::INT32, CT::SINGLE))); // add docs for (uint32_t i = 0; i < attrs.size(); ++i) { diff --git a/searchlib/src/tests/attribute/enumeratedsave/enumeratedsave_test.cpp b/searchlib/src/tests/attribute/enumeratedsave/enumeratedsave_test.cpp index 8ec9d59da86..432396d635e 100644 --- a/searchlib/src/tests/attribute/enumeratedsave/enumeratedsave_test.cpp +++ b/searchlib/src/tests/attribute/enumeratedsave/enumeratedsave_test.cpp @@ -103,32 +103,24 @@ public: typedef std::shared_ptr<MemAttr> SP; MemAttr(); - ~MemAttr(); - - // Implements IAttributeSaveTarget - virtual bool setup() override { return true; } - virtual void close() override {} - virtual IAttributeFileWriter &datWriter() override { return _datWriter; } - virtual IAttributeFileWriter &idxWriter() override { return _idxWriter; } - virtual IAttributeFileWriter &weightWriter() override { + ~MemAttr() override; + + bool setup() override { return true; } + void close() override {} + IAttributeFileWriter &datWriter() override { return _datWriter; } + IAttributeFileWriter &idxWriter() override { return _idxWriter; } + IAttributeFileWriter &weightWriter() override { return _weightWriter; } - virtual IAttributeFileWriter &udatWriter() override { return _udatWriter; } + IAttributeFileWriter &udatWriter() override { return _udatWriter; } - bool - bufEqual(const Buffer &lhs, const Buffer &rhs) const; + bool bufEqual(const Buffer &lhs, const Buffer &rhs) const; - bool - operator==(const MemAttr &rhs) const; + bool operator==(const MemAttr &rhs) const; }; -MemAttr::MemAttr() - : _datWriter(), - _idxWriter(), - _weightWriter(), - _udatWriter() -{ } -MemAttr::~MemAttr() {} +MemAttr::MemAttr() = default; +MemAttr::~MemAttr() = default; class EnumeratedSaveTest { @@ -136,20 +128,11 @@ private: typedef AttributeVector::SP AttributePtr; template <typename VectorType> - VectorType & - as(AttributePtr &v); - - IntegerAttribute & - asInt(AttributePtr &v); - - StringAttribute & - asString(AttributePtr &v); - - FloatingPointAttribute & - asFloat(AttributePtr &v); - - void - addDocs(const AttributePtr &v, size_t sz); + VectorType & as(AttributePtr &v); + IntegerAttribute & asInt(AttributePtr &v); + StringAttribute & asString(AttributePtr &v); + FloatingPointAttribute & asFloat(AttributePtr &v); + void addDocs(const AttributePtr &v, size_t sz); template <typename VectorType> void populate(VectorType &v, unsigned seed, BasicType bt); @@ -157,65 +140,34 @@ private: template <typename VectorType, typename BufferType> void compare(VectorType &a, VectorType &b); - void - buildTermQuery(std::vector<char> & buffer, - const vespalib::string & index, - const vespalib::string & term, bool prefix); + void buildTermQuery(std::vector<char> & buffer, const vespalib::string & index, + const vespalib::string & term, bool prefix); template <typename V, typename T> - SearchContextPtr - getSearch(const V & vec, const T & term, bool prefix); + SearchContextPtr getSearch(const V & vec, const T & term, bool prefix); template <typename V> - SearchContextPtr - getSearch(const V & vec); - - MemAttr::SP - saveMem(AttributeVector &v); + SearchContextPtr getSearch(const V & vec); - void - checkMem(AttributeVector &v, const MemAttr &e, bool enumerated); - - MemAttr::SP - saveBoth(AttributePtr v); - - AttributePtr - make(Config cfg, - const vespalib::string &pref, - bool fastSearch = false); - - void - load(AttributePtr v, const vespalib::string &name); + MemAttr::SP saveMem(AttributeVector &v); + void checkMem(AttributeVector &v, const MemAttr &e, bool enumerated); + MemAttr::SP saveBoth(AttributePtr v); + AttributePtr make(Config cfg, const vespalib::string &pref, bool fastSearch = false); + void load(AttributePtr v, const vespalib::string &name); template <typename VectorType, typename BufferType> - void - checkLoad(AttributePtr v, - const vespalib::string &name, - AttributePtr ev); + void checkLoad(AttributePtr v, const vespalib::string &name, AttributePtr ev); template <typename VectorType, typename BufferType> - void - testReload(AttributePtr v0, - AttributePtr v1, - AttributePtr v2, - MemAttr::SP mv0, - MemAttr::SP mv1, - MemAttr::SP mv2, - MemAttr::SP emv0, - MemAttr::SP emv1, - MemAttr::SP emv2, - Config cfg, - const vespalib::string &pref, - bool fastSearch); + void testReload(AttributePtr v0, AttributePtr v1, AttributePtr v2, + MemAttr::SP mv0, MemAttr::SP mv1, MemAttr::SP mv2, + MemAttr::SP emv0, MemAttr::SP emv1, MemAttr::SP emv2, + Config cfg, const vespalib::string &pref, bool fastSearch); public: template <typename VectorType, typename BufferType> - void - test(BasicType bt, CollectionType ct, const vespalib::string &pref); + void test(BasicType bt, CollectionType ct, const vespalib::string &pref); - EnumeratedSaveTest() - { - } }; @@ -605,9 +557,7 @@ EnumeratedSaveTest::saveBoth(AttributePtr v) EnumeratedSaveTest::AttributePtr -EnumeratedSaveTest::make(Config cfg, - const vespalib::string &pref, - bool fastSearch) +EnumeratedSaveTest::make(Config cfg, const vespalib::string &pref, bool fastSearch) { cfg.setFastSearch(fastSearch); AttributePtr v = AttributeFactory::createAttribute(pref, cfg); @@ -751,13 +701,11 @@ EnumeratedSaveTest::test(BasicType bt, CollectionType ct, TEST_DO((testReload<VectorType, BufferType>(v0, v1, v2, mv0, mv1, mv2, emv0, emv1, emv2, - cfg, pref, - false))); + cfg, pref, false))); TEST_DO((testReload<VectorType, BufferType>(v0, v1, v2, mv0, mv1, mv2, emv0, emv1, emv2, - cfg, pref, - true))); + cfg, pref, true))); } TEST_F("Test enumerated save with single value int8", EnumeratedSaveTest) diff --git a/searchlib/src/tests/attribute/postinglistattribute/postinglistattribute_test.cpp b/searchlib/src/tests/attribute/postinglistattribute/postinglistattribute_test.cpp index d5b1c9566c4..c6270e32c85 100644 --- a/searchlib/src/tests/attribute/postinglistattribute/postinglistattribute_test.cpp +++ b/searchlib/src/tests/attribute/postinglistattribute/postinglistattribute_test.cpp @@ -1003,10 +1003,8 @@ PostingListAttributeTest::testMinMax() { Config cfg(Config(BasicType::INT32, CollectionType::WSET)); cfg.setFastSearch(true); - AttributePtr ptr1 = - AttributeFactory::createAttribute("wsint32_1", cfg); - AttributePtr ptr2 = - AttributeFactory::createAttribute("wsint32_2", cfg); + AttributePtr ptr1 = AttributeFactory::createAttribute("wsint32_1", cfg); + AttributePtr ptr2 = AttributeFactory::createAttribute("wsint32_2", cfg); testMinMax<IntegerAttribute>(ptr1, ptr2); } { diff --git a/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp b/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp index 69aa612d5b8..bc6ce97fc37 100644 --- a/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp +++ b/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp @@ -1,6 +1,4 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> -LOG_SETUP("stringattribute_test"); #include <vespa/vespalib/testkit/testapp.h> #include <vespa/searchlib/attribute/enumstore.h> #include <vespa/searchlib/attribute/singlestringattribute.h> @@ -14,6 +12,9 @@ LOG_SETUP("stringattribute_test"); #include <vespa/searchlib/attribute/multistringattribute.h> #include <vespa/searchlib/attribute/multistringpostattribute.hpp> +#include <vespa/log/log.h> +LOG_SETUP("stringattribute_test"); + namespace search { using attribute::CollectionType; @@ -430,11 +431,8 @@ StringAttributeTest::Main() TEST_INIT("stringattribute_test"); testMultiValue(); - testMultiValueMultipleClearDocBetweenCommit(); - testMultiValueRemove(); - testSingleValue(); TEST_DONE(); diff --git a/searchlib/src/tests/features/prod_features_attributematch.cpp b/searchlib/src/tests/features/prod_features_attributematch.cpp index 4ddb3170efe..e5d37e62bee 100644 --- a/searchlib/src/tests/features/prod_features_attributematch.cpp +++ b/searchlib/src/tests/features/prod_features_attributematch.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 <vespa/log/log.h> -LOG_SETUP(".prod_features_attributematch"); #include "prod_features.h" #include <vespa/searchlib/features/attributematchfeature.h> #include <vespa/searchlib/attribute/attributefactory.h> +#include <vespa/searchlib/attribute/attributevector.h> + +#include <vespa/log/log.h> +LOG_SETUP(".prod_features_attributematch"); using namespace search::features; using namespace search::fef; |