Test that doubles in JsonValue are copied

This commit is contained in:
Benoit Blanchon
2014-09-28 21:22:20 +02:00
parent 42ce5ab31f
commit d549070fd3
2 changed files with 16 additions and 2 deletions

View File

@ -61,10 +61,16 @@ void JsonValue::operator=(JsonValue const& value)
_node->content.asInteger = value._node->content.asInteger; _node->content.asInteger = value._node->content.asInteger;
break; break;
case JSON_DOUBLE_0_DECIMALS:
case JSON_OBJECT: case JSON_OBJECT:
case JSON_ARRAY: case JSON_ARRAY:
case JSON_PROXY: case JSON_PROXY:
setAsProxyTo(value._node); setAsProxyTo(value._node);
default:
*_node = *value._node;
break;
} }
} }

View File

@ -59,12 +59,20 @@ TEST_F(JsonValueTests, CanStoreObject)
EXPECT_EQ(innerObject1, (JsonObject) jsonValue1); EXPECT_EQ(innerObject1, (JsonObject) jsonValue1);
} }
TEST_F(JsonValueTests, CanCopyInteger) TEST_F(JsonValueTests, IntegerValuesAreCopied)
{ {
jsonValue1 = 123; jsonValue1 = 123;
jsonValue2 = jsonValue1; jsonValue2 = jsonValue1;
jsonValue1 = 456; jsonValue1 = 456;
EXPECT_EQ(456, (int) jsonValue1);
EXPECT_EQ(123, (int) jsonValue2); EXPECT_EQ(123, (int) jsonValue2);
} }
TEST_F(JsonValueTests, DoubleValuesAreCopied)
{
jsonValue1 = 123.45;
jsonValue2 = jsonValue1;
jsonValue1 = 456.78;
EXPECT_EQ(123.45, (double) jsonValue2);
}