diff --git a/srcs/JsonObject.h b/srcs/JsonObject.h index 4a75a7cb..3482f122 100644 --- a/srcs/JsonObject.h +++ b/srcs/JsonObject.h @@ -7,6 +7,10 @@ struct JsonNode; class JsonObject { public: + JsonObject() + : _node(0) + { + } JsonObject(JsonBuffer* buffer, JsonNode* node) : _buffer(buffer), _node(node) @@ -16,8 +20,8 @@ public: size_t size(); JsonValue operator[](const char* key); -private: +private: JsonBuffer* _buffer; JsonNode* _node; JsonNode* getOrCreateNodeAt(char const* key); diff --git a/tests/JsonObjectTests.cpp b/tests/JsonObjectTests.cpp index 796e7c29..533fb2c7 100644 --- a/tests/JsonObjectTests.cpp +++ b/tests/JsonObjectTests.cpp @@ -2,12 +2,20 @@ #include #include -TEST(JsonObjectTests, WhenValueIsAdded_ThenSizeIsIncreasedByOne) +class JsonObjectTests : public ::testing::Test { +protected: + virtual void SetUp() + { + object = json.createObject(); + } + StaticJsonBuffer<42> json; + JsonObject object; +}; - JsonObject object = json.createObject(); - +TEST_F(JsonObjectTests, Grow_WhenValuesAreAdded) +{ object["hello"]; EXPECT_EQ(1, object.size()); @@ -15,12 +23,8 @@ TEST(JsonObjectTests, WhenValueIsAdded_ThenSizeIsIncreasedByOne) EXPECT_EQ(2, object.size()); } -TEST(JsonObjectTests, WhenTheSameValueIsAddedTwice_ThenSizeIsOnlyIncreasedByOne) +TEST_F(JsonObjectTests, DoNotGrow_WhenSameValueIsAdded) { - StaticJsonBuffer<42> json; - - JsonObject object = json.createObject(); - object["hello"]; EXPECT_EQ(1, object.size()); @@ -28,12 +32,8 @@ TEST(JsonObjectTests, WhenTheSameValueIsAddedTwice_ThenSizeIsOnlyIncreasedByOne) EXPECT_EQ(1, object.size()); } -TEST(JsonObjectTests, GivenAnIntegerStored_WhenRetreivingTheValue_ThenTheValueIsTheSame) +TEST_F(JsonObjectTests, CanStoreIntegers) { - StaticJsonBuffer<42> json; - - JsonObject object = json.createObject(); - object["hello"] = 123; object["world"] = 456; @@ -41,12 +41,8 @@ TEST(JsonObjectTests, GivenAnIntegerStored_WhenRetreivingTheValue_ThenTheValueIs EXPECT_EQ(456, (int) object["world"]); } -TEST(JsonObjectTests, GivenAnDoubleStored_WhenRetreivingTheValue_ThenTheValueIsTheSame) +TEST_F(JsonObjectTests, CanStoreDoubles) { - StaticJsonBuffer<42> json; - - JsonObject object = json.createObject(); - object["hello"] = 123.45; object["world"] = 456.78; @@ -55,12 +51,8 @@ TEST(JsonObjectTests, GivenAnDoubleStored_WhenRetreivingTheValue_ThenTheValueIsT } -TEST(JsonObjectTests, GivenABooleanStored_WhenRetreivingTheValue_ThenTheValueIsTheSame) +TEST_F(JsonObjectTests, CanStoreBooleans) { - StaticJsonBuffer<42> json; - - JsonObject object = json.createObject(); - object["hello"] = true; object["world"] = false;