From d3cf568d072eeae90f4eb5d6ff8079aa94b43398 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sun, 28 Sep 2014 21:35:08 +0200 Subject: [PATCH] Test that char* are copied --- srcs/JsonValue.cpp | 3 +-- tests/JsonValueTests.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/srcs/JsonValue.cpp b/srcs/JsonValue.cpp index 58bd8fd7..528a6bb1 100644 --- a/srcs/JsonValue.cpp +++ b/srcs/JsonValue.cpp @@ -47,8 +47,7 @@ void JsonValue::operator=(JsonValue const& value) return; } - JsonNodeType nodeType = value._node ? value._node->type : JSON_UNDEFINED; - + JsonNodeType nodeType = value._node ? value._node->type : JSON_UNDEFINED; switch (nodeType) { diff --git a/tests/JsonValueTests.cpp b/tests/JsonValueTests.cpp index 3f17ebfa..edea27e6 100644 --- a/tests/JsonValueTests.cpp +++ b/tests/JsonValueTests.cpp @@ -84,4 +84,13 @@ TEST_F(JsonValueTests, BooleanValuesAreCopied) jsonValue1 = false; EXPECT_TRUE((bool) jsonValue2); +} + +TEST_F(JsonValueTests, CharPointersAreCopied) +{ + jsonValue1 = "hello"; + jsonValue2 = jsonValue1; + jsonValue1 = "world"; + + EXPECT_STREQ("hello", (const char*) jsonValue2); } \ No newline at end of file