Group test in a test fixture

This commit is contained in:
Benoit Blanchon
2014-09-27 15:19:03 +02:00
parent 75588946c6
commit 0495297c6c
2 changed files with 20 additions and 24 deletions

View File

@ -7,6 +7,10 @@ struct JsonNode;
class JsonObject class JsonObject
{ {
public: public:
JsonObject()
: _node(0)
{
}
JsonObject(JsonBuffer* buffer, JsonNode* node) JsonObject(JsonBuffer* buffer, JsonNode* node)
: _buffer(buffer), _node(node) : _buffer(buffer), _node(node)
@ -16,8 +20,8 @@ public:
size_t size(); size_t size();
JsonValue operator[](const char* key); JsonValue operator[](const char* key);
private:
private:
JsonBuffer* _buffer; JsonBuffer* _buffer;
JsonNode* _node; JsonNode* _node;
JsonNode* getOrCreateNodeAt(char const* key); JsonNode* getOrCreateNodeAt(char const* key);

View File

@ -2,12 +2,20 @@
#include <StaticJsonBuffer.h> #include <StaticJsonBuffer.h>
#include <JsonValue.h> #include <JsonValue.h>
TEST(JsonObjectTests, WhenValueIsAdded_ThenSizeIsIncreasedByOne) class JsonObjectTests : public ::testing::Test
{ {
protected:
virtual void SetUp()
{
object = json.createObject();
}
StaticJsonBuffer<42> json; StaticJsonBuffer<42> json;
JsonObject object;
};
JsonObject object = json.createObject(); TEST_F(JsonObjectTests, Grow_WhenValuesAreAdded)
{
object["hello"]; object["hello"];
EXPECT_EQ(1, object.size()); EXPECT_EQ(1, object.size());
@ -15,12 +23,8 @@ TEST(JsonObjectTests, WhenValueIsAdded_ThenSizeIsIncreasedByOne)
EXPECT_EQ(2, object.size()); EXPECT_EQ(2, object.size());
} }
TEST(JsonObjectTests, WhenTheSameValueIsAddedTwice_ThenSizeIsOnlyIncreasedByOne) TEST_F(JsonObjectTests, DoNotGrow_WhenSameValueIsAdded)
{ {
StaticJsonBuffer<42> json;
JsonObject object = json.createObject();
object["hello"]; object["hello"];
EXPECT_EQ(1, object.size()); EXPECT_EQ(1, object.size());
@ -28,12 +32,8 @@ TEST(JsonObjectTests, WhenTheSameValueIsAddedTwice_ThenSizeIsOnlyIncreasedByOne)
EXPECT_EQ(1, object.size()); 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["hello"] = 123;
object["world"] = 456; object["world"] = 456;
@ -41,12 +41,8 @@ TEST(JsonObjectTests, GivenAnIntegerStored_WhenRetreivingTheValue_ThenTheValueIs
EXPECT_EQ(456, (int) object["world"]); 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["hello"] = 123.45;
object["world"] = 456.78; 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["hello"] = true;
object["world"] = false; object["world"] = false;