aboutsummaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-01-22 13:53:24 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-01-22 13:53:24 +0000
commit261fc7a26287fad35437988acb1bc20ab883bc8a (patch)
treef4f71cc6d8b888b6c1ace0f7e06ad478af266f5c /document
parent8372a883c5a5fa100f88fc9b80824359b5bb70cd (diff)
Add tests for the obscure virtual assignment operators.
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/primitivefieldvaluetest.cpp37
-rw-r--r--document/src/vespa/document/fieldvalue/boolfieldvalue.cpp21
-rw-r--r--document/src/vespa/document/fieldvalue/boolfieldvalue.h6
3 files changed, 64 insertions, 0 deletions
diff --git a/document/src/tests/primitivefieldvaluetest.cpp b/document/src/tests/primitivefieldvaluetest.cpp
index 3ccb5aa714b..87e9e22293f 100644
--- a/document/src/tests/primitivefieldvaluetest.cpp
+++ b/document/src/tests/primitivefieldvaluetest.cpp
@@ -18,12 +18,14 @@ struct PrimitiveFieldValueTest : public CppUnit::TestFixture {
void testRaw();
void testNumerics();
void testFloatDoubleCasts();
+ void testBool();
CPPUNIT_TEST_SUITE(PrimitiveFieldValueTest);
CPPUNIT_TEST(testLiterals);
CPPUNIT_TEST(testRaw);
CPPUNIT_TEST(testNumerics);
CPPUNIT_TEST(testFloatDoubleCasts);
+ CPPUNIT_TEST(testBool);
CPPUNIT_TEST_SUITE_END();
};
@@ -325,6 +327,41 @@ PrimitiveFieldValueTest::testFloatDoubleCasts()
}
void
+PrimitiveFieldValueTest::testBool()
+{
+ BoolFieldValue v;
+ CPPUNIT_ASSERT( ! v.getValue() );
+
+ v = BoolFieldValue(true);
+ CPPUNIT_ASSERT(v.getValue());
+
+ v = 0;
+ CPPUNIT_ASSERT( ! v.getValue());
+ v = 1;
+ CPPUNIT_ASSERT(v.getValue());
+
+ v = 0L;
+ CPPUNIT_ASSERT( ! v.getValue());
+ v = 1L;
+ CPPUNIT_ASSERT(v.getValue());
+
+ v = 0.0f;
+ CPPUNIT_ASSERT( ! v.getValue());
+ v = 1.0f;
+ CPPUNIT_ASSERT(v.getValue());
+
+ v = 0.0;
+ CPPUNIT_ASSERT( ! v.getValue());
+ v = 1.0;
+ CPPUNIT_ASSERT(v.getValue());
+
+ v = vespalib::stringref("true");
+ CPPUNIT_ASSERT(v.getValue());
+ v = vespalib::stringref("something not true");
+ CPPUNIT_ASSERT( ! v.getValue());
+}
+
+void
PrimitiveFieldValueTest::testNumerics()
{
testNumeric<ByteFieldValue>("127", false);
diff --git a/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp b/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp
index 88ad1ddd11b..6eb5adc875c 100644
--- a/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp
@@ -82,4 +82,25 @@ BoolFieldValue::getAsString() const {
return _value ? "true" : "false";
}
+FieldValue& BoolFieldValue::operator=(vespalib::stringref v) {
+ _value = (v == "true");
+ return *this;
+}
+FieldValue& BoolFieldValue::operator=(int32_t v) {
+ _value = (v != 0);
+ return *this;
+}
+FieldValue& BoolFieldValue::operator=(int64_t v) {
+ _value = (v != 0);
+ return *this;
+}
+FieldValue& BoolFieldValue::operator=(float v) {
+ _value = (v != 0);
+ return *this;
+}
+FieldValue& BoolFieldValue::operator=(double v) {
+ _value = (v != 0);
+ return *this;
+}
+
} // namespace document
diff --git a/document/src/vespa/document/fieldvalue/boolfieldvalue.h b/document/src/vespa/document/fieldvalue/boolfieldvalue.h
index 7d3b30787e9..e87a337856f 100644
--- a/document/src/vespa/document/fieldvalue/boolfieldvalue.h
+++ b/document/src/vespa/document/fieldvalue/boolfieldvalue.h
@@ -41,6 +41,12 @@ public:
double getAsDouble() const override;
vespalib::string getAsString() const override;
+ FieldValue& operator=(vespalib::stringref) override;
+ FieldValue& operator=(int32_t) override;
+ FieldValue& operator=(int64_t) override;
+ FieldValue& operator=(float) override;
+ FieldValue& operator=(double) override;
+
DECLARE_IDENTIFIABLE(BoolFieldValue);
};