diff options
author | Tor Egge <Tor.Egge@oath.com> | 2018-05-31 11:28:23 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2018-05-31 12:58:45 +0000 |
commit | 4e5b39062404989036addb8369c31ddef93ec20c (patch) | |
tree | 6846df0e42ecf84526e5f135b7a1403382d96007 /searchcore/src/tests/proton/attribute/attribute_test.cpp | |
parent | 721180812680b7a5dd8bae87e1a114ff8ef5ed98 (diff) |
Handle struct map in attribute writer.
Diffstat (limited to 'searchcore/src/tests/proton/attribute/attribute_test.cpp')
-rw-r--r-- | searchcore/src/tests/proton/attribute/attribute_test.cpp | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_test.cpp b/searchcore/src/tests/proton/attribute/attribute_test.cpp index 98a76023c47..3fbaead634e 100644 --- a/searchcore/src/tests/proton/attribute/attribute_test.cpp +++ b/searchcore/src/tests/proton/attribute/attribute_test.cpp @@ -868,7 +868,7 @@ struct StructArrayFixture : public StructFixtureBase StructArrayFixture::~StructArrayFixture() = default; -TEST_F("require that update with doc argument only updates compound attributes", StructArrayFixture) +TEST_F("require that update with doc argument updates compound attributes (array)", StructArrayFixture) { auto doc = f.makeDoc(10, {11, 12}); f.put(10, *doc, 1); @@ -878,6 +878,64 @@ TEST_F("require that update with doc argument only updates compound attributes", TEST_DO(f.checkAttrs(1, 10, {21})); } +struct StructMapFixture : public StructFixtureBase +{ + using StructFixtureBase::makeDoc; + const MapDataType _structMapFieldType; + const Field _structMapField; + + StructMapFixture() + : StructFixtureBase(), + _structMapFieldType(*DataType::INT, _structFieldType), + _structMapField("map", _structMapFieldType, true) + { + addAttribute({"map.value", AVConfig(AVBasicType::INT32, AVCollectionType::ARRAY)}, createSerialNum); + addAttribute({"map.[key]", AVConfig(AVBasicType::INT32, AVCollectionType::ARRAY)}, createSerialNum); + _type.addField(_structMapField); + } + + std::unique_ptr<Document> + makeDoc(int32_t value, const std::map<int32_t, int32_t> &mapValues) + { + auto doc = makeDoc(); + doc->setValue(_valueField, IntFieldValue(value)); + MapFieldValue s(_structMapFieldType); + for (const auto &mapValue : mapValues) { + s.put(IntFieldValue(mapValue.first), *makeStruct(mapValue.second)); + } + doc->setValue(_structMapField, s); + return doc; + } + void checkAttrs(uint32_t lid, int32_t expValue, const std::map<int32_t, int32_t> &expMap) { + auto valueAttr = _m->getAttribute("value")->getSP(); + auto mapKeyAttr = _m->getAttribute("map.[key]")->getSP(); + auto mapValueAttr = _m->getAttribute("map.value")->getSP(); + EXPECT_EQUAL(expValue, valueAttr->getInt(lid)); + attribute::IntegerContent mapKeys; + mapKeys.fill(*mapKeyAttr, lid); + attribute::IntegerContent mapValues; + mapValues.fill(*mapValueAttr, lid); + EXPECT_EQUAL(expMap.size(), mapValues.size()); + EXPECT_EQUAL(expMap.size(), mapKeys.size()); + size_t i = 0; + for (const auto &expMapElem : expMap) { + EXPECT_EQUAL(expMapElem.first, mapKeys[i]); + EXPECT_EQUAL(expMapElem.second, mapValues[i]); + ++i; + } + } +}; + +TEST_F("require that update with doc argument updates compound attributes (map)", StructMapFixture) +{ + auto doc = f.makeDoc(10, {{1, 11}, {2, 12}}); + f.put(10, *doc, 1); + TEST_DO(f.checkAttrs(1, 10, {{1, 11}, {2, 12}})); + doc = f.makeDoc(20, {{42, 21}}); + f.update(11, *doc, 1, true); + TEST_DO(f.checkAttrs(1, 10, {{42, 21}})); +} + TEST_MAIN() { vespalib::rmdir(test_dir, true); |