diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-05 07:14:05 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-05 07:14:05 +0000 |
commit | 1734571166515a3454ec8f8025bd38ce4932f117 (patch) | |
tree | f8294618792faa0739acf9b2ef42b93e6727e06b /document/src/tests | |
parent | 0c79dd8a46277f48d108298bc3511297e7a18ea7 (diff) |
As a first step to reduce code complexity around FieldValue move test-only convenience
methods out to test-only helpers.
Diffstat (limited to 'document/src/tests')
-rw-r--r-- | document/src/tests/documentselectparsertest.cpp | 23 | ||||
-rw-r--r-- | document/src/tests/documenttestcase.cpp | 10 | ||||
-rw-r--r-- | document/src/tests/documentupdatetestcase.cpp | 9 | ||||
-rw-r--r-- | document/src/tests/fieldpathupdatetestcase.cpp | 7 | ||||
-rw-r--r-- | document/src/tests/serialization/vespadocumentserializer_test.cpp | 3 | ||||
-rw-r--r-- | document/src/tests/weightedsetfieldvaluetest.cpp | 23 |
6 files changed, 41 insertions, 34 deletions
diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index f40aec41e16..8308c3bc693 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -1,5 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/document/test/fieldvalue_helpers.h> #include <vespa/document/repo/configbuilder.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/update/assignvalueupdate.h> @@ -193,17 +194,15 @@ DocumentSelectParserTest::createDocs() amval.put(StringFieldValue("bar"), abval); _doc.back()->setValue("structarrmap", amval); - WeightedSetFieldValue wsval( - _doc.back()->getField("stringweightedset").getDataType()); - wsval.add("foo"); - wsval.add("val1"); - wsval.add("val2"); - wsval.add("val3"); - wsval.add("val4"); + WeightedSetFieldValue wsval(_doc.back()->getField("stringweightedset").getDataType()); + WSetHelper(wsval).add("foo"); + WSetHelper(wsval).add("val1"); + WSetHelper(wsval).add("val2"); + WSetHelper(wsval).add("val3"); + WSetHelper(wsval).add("val4"); _doc.back()->setValue("stringweightedset", wsval); - WeightedSetFieldValue wsbytes( - _doc.back()->getField("byteweightedset").getDataType()); + WeightedSetFieldValue wsbytes(_doc.back()->getField("byteweightedset").getDataType()); wsbytes.add(ByteFieldValue(5)); wsbytes.add(ByteFieldValue(75)); wsbytes.add(ByteFieldValue(static_cast<int8_t>(255))); @@ -211,14 +210,12 @@ DocumentSelectParserTest::createDocs() _doc.back()->setValue("byteweightedset", wsbytes); } - _doc.push_back(createDoc( - "testdoctype1", "id:myspace:testdoctype1:n=1234:footype1", 15, 1.0, "some", "some", 0)); // DOC 2 + _doc.push_back(createDoc("testdoctype1", "id:myspace:testdoctype1:n=1234:footype1", 15, 1.0, "some", "some", 0)); // DOC 2 // Add empty struct and array { StructFieldValue sval(_doc.back()->getField("mystruct").getDataType()); _doc.back()->setValue("mystruct", sval); - ArrayFieldValue aval( - _doc.back()->getField("structarray").getDataType()); + ArrayFieldValue aval(_doc.back()->getField("structarray").getDataType()); _doc.back()->setValue("structarray", aval); } _doc.push_back(createDoc("testdoctype1", "id:myspace:testdoctype1:g=yahoo:bar", 14, 2.4, "Yet", "\xE4\xB8\xBA\xE4\xBB\x80", 0)); // DOC 3 diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index fde702f2080..bcf0cbad5fe 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -1,5 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/document/test/fieldvalue_helpers.h> #include <vespa/document/base/testdocman.h> #include <vespa/document/datatype/documenttype.h> #include <vespa/document/datatype/mapdatatype.h> @@ -349,11 +350,12 @@ TEST(DocumentTest, testModifyDocument) structmap1.put(StringFieldValue("test"), l2s1); l1s1.setValue(structmapF, structmap1); - WeightedSetFieldValue wset1(wset); + WeightedSetFieldValue wwset1(wset); + WSetHelper wset1(wwset1); wset1.add("foo"); wset1.add("bar"); wset1.add("zoo"); - l1s1.setValue(wsetF, wset1); + l1s1.setValue(wsetF, wwset1); WeightedSetFieldValue wset2(structwset); wset2.add(l2s1); @@ -716,8 +718,8 @@ TEST(DocumentTest,testReadSerializedAllVersions) docInDoc.set("stringindocfield", "Elvis is dead"); doc.setValue("docfield", docInDoc); ArrayFieldValue floatArray(*arrayOfFloatDataType); - floatArray.add(1.0); - floatArray.add(2.0); + CollectionHelper(floatArray).add(1.0); + CollectionHelper(floatArray).add(2.0); doc.setValue("arrayoffloatfield", floatArray); WeightedSetFieldValue weightedSet(*weightedSetDataType); weightedSet.add(StringFieldValue("Weighted 0"), 50); diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index 8a9aef0bde4..d5905d63455 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -1,5 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/document/test/fieldvalue_helpers.h> #include <vespa/document/base/testdocman.h> #include <vespa/document/base/exceptions.h> #include <vespa/document/datatype/tensor_data_type.h> @@ -1287,9 +1288,9 @@ TEST(DocumentUpdateTest, array_element_update_applies_to_specified_element) ArrayUpdateFixture f; ArrayFieldValue array_value(f.array_field.getDataType()); - array_value.add("foo"); - array_value.add("baz"); - array_value.add("blarg"); + CollectionHelper(array_value).add("foo"); + CollectionHelper(array_value).add("baz"); + CollectionHelper(array_value).add("blarg"); f.doc->setValue(f.array_field, array_value); f.update->applyTo(*f.doc); @@ -1306,7 +1307,7 @@ TEST(DocumentUpdateTest, array_element_update_for_invalid_index_is_ignored) ArrayUpdateFixture f; ArrayFieldValue array_value(f.array_field.getDataType()); - array_value.add("jerry"); + CollectionHelper(array_value).add("jerry"); f.doc->setValue(f.array_field, array_value); f.update->applyTo(*f.doc); // MapValueUpdate for index 1, which does not exist diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp index 3ebf3699763..3d41a5bcacd 100644 --- a/document/src/tests/fieldpathupdatetestcase.cpp +++ b/document/src/tests/fieldpathupdatetestcase.cpp @@ -1,4 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/document/test/fieldvalue_helpers.h> #include <vespa/document/base/testdocman.h> #include <vespa/document/fieldvalue/iteratorhandler.h> #include <vespa/document/fieldvalue/intfieldvalue.h> @@ -128,11 +130,12 @@ createTestDocument(const DocumentTypeRepo &repo) structmap1.put(StringFieldValue("test"), l2s1); l1s1.setValue("structmap", structmap1); - WeightedSetFieldValue wset1(*wset); + WeightedSetFieldValue wwset1(*wset); + WSetHelper wset1(wwset1); wset1.add("foo"); wset1.add("bar"); wset1.add("zoo"); - l1s1.setValue("wset", wset1); + l1s1.setValue("wset", wwset1); WeightedSetFieldValue wset2(*structwset); wset2.add(l2s1); diff --git a/document/src/tests/serialization/vespadocumentserializer_test.cpp b/document/src/tests/serialization/vespadocumentserializer_test.cpp index d85d5240b64..33e8c521e09 100644 --- a/document/src/tests/serialization/vespadocumentserializer_test.cpp +++ b/document/src/tests/serialization/vespadocumentserializer_test.cpp @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. // Unit tests for vespadocumentserializer. +#include <vespa/document/test/fieldvalue_helpers.h> #include <vespa/document/annotation/annotation.h> #include <vespa/document/annotation/span.h> #include <vespa/document/annotation/spantree.h> @@ -345,7 +346,7 @@ void checkArrayFieldValue(SizeType value_count) { ArrayDataType array_type(*DataType::INT); ArrayFieldValue value(array_type); for (uint32_t i = 0; i < value_count; ++i) { - value.add(static_cast<int32_t>(i)); + CollectionHelper(value).add(static_cast<int32_t>(i)); } nbostream stream; diff --git a/document/src/tests/weightedsetfieldvaluetest.cpp b/document/src/tests/weightedsetfieldvaluetest.cpp index 325267e9da6..61f727120d1 100644 --- a/document/src/tests/weightedsetfieldvaluetest.cpp +++ b/document/src/tests/weightedsetfieldvaluetest.cpp @@ -1,5 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/document/test/fieldvalue_helpers.h> #include <vespa/document/fieldvalue/weightedsetfieldvalue.h> #include <vespa/document/fieldvalue/arrayfieldvalue.h> #include <vespa/document/fieldvalue/longfieldvalue.h> @@ -255,7 +256,8 @@ TEST(WeightedSetFieldValueTest, testWeightedSet) WeightedSetDataType mytype2(*DataType::STRING, true, true); EXPECT_EQ(*DataType::TAG, static_cast<DataType &>(mytype2)); - WeightedSetFieldValue val1(mytype1); + WeightedSetFieldValue wsval1(mytype1); + WSetHelper val1(wsval1); val1.add("foo", 4); try{ val1.increment("bar", 2); @@ -272,25 +274,26 @@ TEST(WeightedSetFieldValueTest, testWeightedSet) val1.decrement("foo", 3); EXPECT_EQ(7, val1.get("foo")); val1.decrement("foo", 7); - EXPECT_TRUE(val1.contains("foo")); + EXPECT_TRUE(CollectionHelper(wsval1).contains("foo")); - WeightedSetFieldValue val2(mytype2); + WeightedSetFieldValue wsval2(mytype2); + WSetHelper val2(wsval2); val2.add("foo", 4); val2.increment("bar", 2); EXPECT_EQ(2, val2.get("bar")); val2.decrement("bar", 4); EXPECT_EQ(-2, val2.get("bar")); val2.increment("bar", 2); - EXPECT_TRUE(!val2.contains("bar")); + EXPECT_TRUE(!CollectionHelper(wsval2).contains("bar")); val2.decrement("foo", 4); - EXPECT_TRUE(!val2.contains("foo")); + EXPECT_TRUE(!CollectionHelper(wsval2).contains("foo")); val2.decrement("foo", 4); EXPECT_EQ(-4, val2.get("foo")); val2.add("foo", 0); - EXPECT_TRUE(!val2.contains("foo")); + EXPECT_TRUE(!CollectionHelper(wsval2).contains("foo")); } } @@ -301,12 +304,12 @@ TEST(WeightedSetFieldValueTest, testAddIgnoreZeroWeight) WeightedSetFieldValue ws(wsetType); ws.addIgnoreZeroWeight(StringFieldValue("yarn"), 0); - EXPECT_TRUE(ws.contains("yarn")); - EXPECT_EQ(0, ws.get("yarn")); + EXPECT_TRUE(CollectionHelper(ws).contains("yarn")); + EXPECT_EQ(0, WSetHelper(ws).get("yarn")); ws.addIgnoreZeroWeight(StringFieldValue("flarn"), 1); - EXPECT_TRUE(ws.contains("flarn")); - EXPECT_EQ(1, ws.get("flarn")); + EXPECT_TRUE(CollectionHelper(ws).contains("flarn")); + EXPECT_EQ(1, WSetHelper(ws).get("flarn")); } } // document |