aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/tests
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-03-07 08:14:04 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-03-07 08:14:04 +0000
commite658f2c3499901cf7e7750ca3d5be0e6e6953e8c (patch)
tree6b297ebd65ab7ea1c7970420982c0a3f6f9c2123 /document/src/tests
parent2e05df2de19c2d5b87befa2ee6c4fd182dcb5630 (diff)
GC redundant convenience wasy of assigning primitive field values.
Diffstat (limited to 'document/src/tests')
-rw-r--r--document/src/tests/documentselectparsertest.cpp20
-rw-r--r--document/src/tests/documenttestcase.cpp36
-rw-r--r--document/src/tests/documentupdatetestcase.cpp4
-rw-r--r--document/src/tests/fieldvalue/fieldvalue_test.cpp14
-rw-r--r--document/src/tests/primitivefieldvaluetest.cpp55
5 files changed, 38 insertions, 91 deletions
diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp
index 8308c3bc693..3d2e4e983d7 100644
--- a/document/src/tests/documentselectparsertest.cpp
+++ b/document/src/tests/documentselectparsertest.cpp
@@ -153,18 +153,18 @@ DocumentSelectParserTest::createDocs()
// Add some arrays and structs to doc 1
{
StructFieldValue sval(_doc.back()->getField("mystruct").getDataType());
- sval.set("key", 14);
- sval.set("value", "structval");
+ sval.setValue("key", std::make_unique<IntFieldValue>(14));
+ sval.setValue("value", std::make_unique<StringFieldValue>("structval"));
_doc.back()->setValue("mystruct", sval);
ArrayFieldValue
aval(_doc.back()->getField("structarray").getDataType());
{
StructFieldValue sval1(aval.getNestedType());
- sval1.set("key", 15);
- sval1.set("value", "structval1");
+ sval1.setValue("key", std::make_unique<IntFieldValue>(15));
+ sval1.setValue("value", std::make_unique<StringFieldValue>("structval1"));
StructFieldValue sval2(aval.getNestedType());
- sval2.set("key", 16);
- sval2.set("value", "structval2");
+ sval2.setValue("key", std::make_unique<IntFieldValue>(16));
+ sval2.setValue("value", std::make_unique<StringFieldValue>("structval2"));
aval.add(sval1);
aval.add(sval2);
}
@@ -182,11 +182,11 @@ DocumentSelectParserTest::createDocs()
ArrayFieldValue abval(_doc.back()->getField("structarray").getDataType());
{
StructFieldValue sval1(aval.getNestedType());
- sval1.set("key", 17);
- sval1.set("value", "structval3");
+ sval1.setValue("key", std::make_unique<IntFieldValue>(17));
+ sval1.setValue("value", std::make_unique<StringFieldValue>("structval3"));
StructFieldValue sval2(aval.getNestedType());
- sval2.set("key", 18);
- sval2.set("value", "structval4");
+ sval2.setValue("key", std::make_unique<IntFieldValue>(18));
+ sval2.setValue("value", std::make_unique<StringFieldValue>("structval4"));
abval.add(sval1);
abval.add(sval2);
}
diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp
index bcf0cbad5fe..73d94452b28 100644
--- a/document/src/tests/documenttestcase.cpp
+++ b/document/src/tests/documenttestcase.cpp
@@ -707,15 +707,15 @@ TEST(DocumentTest,testReadSerializedAllVersions)
// Create a memory instance of document
{
Document doc(*docType, DocumentId("id:ns:serializetest::http://test.doc.id/"));
- doc.set("intfield", 5);
- doc.set("floatfield", -9.23);
- doc.set("stringfield", "This is a string.");
- doc.set("longfield", static_cast<int64_t>(398420092938472983LL));
- doc.set("doublefield", 98374532.398820);
- doc.set("bytefield", -2);
- doc.setValue("rawfield", RawFieldValue("RAW DATA", 8));
+ doc.setValue("intfield", std::make_unique<IntFieldValue>(5));
+ doc.setValue("floatfield", std::make_unique<FloatFieldValue>(-9.23));
+ doc.setValue("stringfield", std::make_unique<StringFieldValue>("This is a string."));
+ doc.setValue("longfield", std::make_unique<LongFieldValue>(static_cast<int64_t>(398420092938472983LL)));
+ doc.setValue("doublefield", std::make_unique<DoubleFieldValue>(98374532.398820));
+ doc.setValue("bytefield", std::make_unique<ByteFieldValue>(-2));
+ doc.setValue("rawfield", std::make_unique<RawFieldValue>("RAW DATA", 8));
Document docInDoc(*docInDocType, DocumentId("id:ns:docindoc::http://doc.in.doc/"));
- docInDoc.set("stringindocfield", "Elvis is dead");
+ docInDoc.setValue("stringindocfield", std::make_unique<StringFieldValue>("Elvis is dead"));
doc.setValue("docfield", docInDoc);
ArrayFieldValue floatArray(*arrayOfFloatDataType);
CollectionHelper(floatArray).add(1.0);
@@ -830,14 +830,14 @@ TEST(DocumentTest, testGenerateSerializedFile)
DocumentTypeRepo repo(readDocumenttypesConfig(file_name));
Document doc(*repo.getDocumentType("serializetest"), DocumentId("id:ns:serializetest::http://test.doc.id/"));
- doc.set("intfield", 5);
- doc.set("floatfield", -9.23);
- doc.set("stringfield", "This is a string.");
- doc.set("longfield", (int64_t) 398420092938472983ll);
- doc.set("doublefield", 98374532.398820);
- doc.set("urifield", "http://this.is.a.test/");
- doc.set("bytefield", -2);
- doc.set("rawfield", "RAW DATA");
+ doc.setValue("intfield", std::make_unique<IntFieldValue>(5));
+ doc.setValue("floatfield", std::make_unique<FloatFieldValue>(-9.23));
+ doc.setValue("stringfield", std::make_unique<StringFieldValue>("This is a string."));
+ doc.setValue("longfield", std::make_unique<LongFieldValue>((int64_t) 398420092938472983ll));
+ doc.setValue("doublefield", std::make_unique<DoubleFieldValue>(98374532.398820));
+ doc.setValue("urifield", std::make_unique<StringFieldValue>("http://this.is.a.test/"));
+ doc.setValue("bytefield", std::make_unique<ByteFieldValue>(-2));
+ doc.setValue("rawfield", std::make_unique<RawFieldValue>("RAW DATA"));
const DocumentType *docindoc_type = repo.getDocumentType("docindoc");
EXPECT_TRUE(docindoc_type);
@@ -951,7 +951,7 @@ TEST(DocumentTest, testHasChanged)
Document doc2(test_repo.getTypeRepo(), buf);
EXPECT_TRUE(!doc2.hasChanged());
- doc2.set("headerval", 13);
+ doc2.setValue("headerval", std::make_unique<IntFieldValue>(13));
EXPECT_TRUE(doc2.hasChanged());
}
// Overwriting a value in doc tags us changed.
@@ -959,7 +959,7 @@ TEST(DocumentTest, testHasChanged)
buf.rp(0);
Document doc2(test_repo.getTypeRepo(), buf);
- doc2.set("hstringval", "bla bla bla bla bla");
+ doc2.setValue("hstringval", std::make_unique<StringFieldValue>("bla bla bla bla bla"));
EXPECT_TRUE(doc2.hasChanged());
}
// Clearing value tags us changed.
diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp
index d5905d63455..28d254e8982 100644
--- a/document/src/tests/documentupdatetestcase.cpp
+++ b/document/src/tests/documentupdatetestcase.cpp
@@ -139,8 +139,8 @@ TEST(DocumentUpdateTest, testSimpleUsage)
// Create a test document
Document doc(*docType, DocumentId("id:ns:test::1"));
- doc.set("bytef", 0);
- doc.set("intf", 5);
+ doc.setValue("bytef", std::make_unique<ByteFieldValue>(0));
+ doc.setValue("intf", std::make_unique<IntFieldValue>(5));
ArrayFieldValue array(*arrayType);
array.add(IntFieldValue(3));
array.add(IntFieldValue(7));
diff --git a/document/src/tests/fieldvalue/fieldvalue_test.cpp b/document/src/tests/fieldvalue/fieldvalue_test.cpp
index b70fd0d18a8..d8712768000 100644
--- a/document/src/tests/fieldvalue/fieldvalue_test.cpp
+++ b/document/src/tests/fieldvalue/fieldvalue_test.cpp
@@ -1,15 +1,15 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Unit tests for fieldvalue.
-#include <vespa/log/log.h>
-LOG_SETUP("fieldvalue_test");
-
#include <vespa/document/fieldvalue/stringfieldvalue.h>
#include <vespa/document/fieldvalue/longfieldvalue.h>
#include <vespa/document/fieldvalue/intfieldvalue.h>
#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/log/log.h>
+LOG_SETUP("fieldvalue_test");
+
using namespace document;
namespace {
@@ -18,14 +18,6 @@ TEST("require that StringFieldValue can be assigned primitives") {
StringFieldValue val;
val = "foo";
EXPECT_EQUAL("foo", val.getValue());
- val = 1;
- EXPECT_EQUAL("1", val.getValue());
- val = static_cast<int64_t>(2);
- EXPECT_EQUAL("2", val.getValue());
- val = 3.0f;
- EXPECT_EQUAL("3", val.getValue());
- val = 4.0;
- EXPECT_EQUAL("4", val.getValue());
}
TEST("require that FieldValues does not change their storage size.") {
diff --git a/document/src/tests/primitivefieldvaluetest.cpp b/document/src/tests/primitivefieldvaluetest.cpp
index 7c734544f27..ea78baa4ee6 100644
--- a/document/src/tests/primitivefieldvaluetest.cpp
+++ b/document/src/tests/primitivefieldvaluetest.cpp
@@ -3,7 +3,6 @@
#include <vespa/document/fieldvalue/fieldvalues.h>
#include <vespa/document/serialization/vespadocumentdeserializer.h>
#include <vespa/vespalib/objects/nbostream.h>
-#include <vespa/document/util/bytebuffer.h>
#include <vespa/document/repo/documenttyperepo.h>
#include <limits>
#include <gtest/gtest.h>
@@ -32,7 +31,7 @@ void deserialize(nbostream & stream, T &value) {
const Type& medium2, const Type& largest)
{
try{
- // Less
+ // Less
EXPECT_TRUE(!(smallest < smallest));
EXPECT_TRUE(smallest < medium1);
EXPECT_TRUE(smallest < medium2);
@@ -203,31 +202,6 @@ TEST(PrimitiveFieldValueTest, testRaw)
value.getValueRef().size()) == 0);
}
-#define ASSERT_FAILED_CONV(getter, totype, floating) \
-{ \
- totype toType; \
- FieldValue::UP copy(value.clone()); \
- try{ \
- getter; \
- std::ostringstream ost; \
- ost << "Conversion unexpectedly worked from max value of " \
- << *value.getDataType() << " to " << *toType.getDataType(); \
- FAIL() << ost.str(); \
- } catch (std::exception& e) { \
- EXPECT_EQ( \
- std::string("bad numeric conversion: positive overflow"), \
- std::string(e.what())); \
- } \
- /* Verify that we can convert to smaller type if value is within \
- range. Only tests integer to integer. No floating point. */ \
- if (!floating) { \
- totype::Number maxV = std::numeric_limits<totype::Number>::max(); \
- value.setValue((Number) maxV); \
- getter; \
- } \
- value.assign(*copy); \
-}
-
namespace {
template<typename Numeric>
@@ -258,25 +232,21 @@ namespace {
// representation can keep the value.
if (floatingPoint || sizeof(Number) > sizeof(unsigned char)) {
// No longer throws. This is guarded on the perimeter by java code.
- // ASSERT_FAILED_CONV(value.getAsByte(), ByteFieldValue, floatingPoint);
} else {
EXPECT_EQ((char) maxValue, value.getAsByte());
}
if (floatingPoint || sizeof(Number) > sizeof(int32_t)) {
// No longer throws. This is guarded on the perimeter by java code.
- // ASSERT_FAILED_CONV(value.getAsInt(), IntFieldValue, floatingPoint);
} else {
EXPECT_EQ((int32_t) maxValue, value.getAsInt());
}
if (floatingPoint || sizeof(Number) > sizeof(int64_t)) {
// No longer throws. This is guarded on the perimeter by java code.
- // ASSERT_FAILED_CONV(value.getAsLong(), LongFieldValue, floatingPoint);
} else {
EXPECT_EQ((int64_t) maxValue, value.getAsLong());
}
if (floatingPoint && sizeof(Number) > sizeof(float)) {
// No longer throws. This is guarded on the perimeter by java code.
- // ASSERT_FAILED_CONV(value.getAsFloat(), FloatFieldValue, true);
} else {
EXPECT_EQ((float) maxValue, value.getAsFloat());
}
@@ -303,30 +273,15 @@ TEST(PrimitiveFieldValueTest, testBool)
v = BoolFieldValue(true);
EXPECT_TRUE(v.getValue());
- v = 0;
- EXPECT_TRUE( ! v.getValue());
- v = 1;
- EXPECT_TRUE(v.getValue());
-
- v = INT64_C(0);
- EXPECT_TRUE( ! v.getValue());
- v = INT64_C(1);
- EXPECT_TRUE(v.getValue());
-
- v = 0.0f;
- EXPECT_TRUE( ! v.getValue());
- v = 1.0f;
- EXPECT_TRUE(v.getValue());
-
- v = 0.0;
- EXPECT_TRUE( ! v.getValue());
- v = 1.0;
+ v.setValue(false);
+ EXPECT_FALSE(v.getValue());
+ v.setValue(true);
EXPECT_TRUE(v.getValue());
v = vespalib::stringref("true");
EXPECT_TRUE(v.getValue());
v = vespalib::stringref("something not true");
- EXPECT_TRUE( ! v.getValue());
+ EXPECT_FALSE(v.getValue());
}
TEST(PrimitiveFieldValueTest, testNumerics)