mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-22 23:07:29 +02:00
Huge refactoring in progress...
This commit is contained in:
@ -13,11 +13,12 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonObject_PrettyPrintTo_Tests : public testing::Test {
|
||||
protected:
|
||||
JsonObject object;
|
||||
StaticJsonBuffer<30> json;
|
||||
public:
|
||||
JsonObject_PrettyPrintTo_Tests() : object(json.createObject()) {}
|
||||
|
||||
virtual void SetUp() { object = json.createObject(); }
|
||||
protected:
|
||||
JsonObject &object;
|
||||
StaticJsonBuffer<30> json;
|
||||
|
||||
void outputMustBe(const char *expected) {
|
||||
size_t n = object.prettyPrintTo(buffer, sizeof(buffer));
|
||||
@ -63,10 +64,10 @@ TEST_F(JsonObject_PrettyPrintTo_Tests, EmptyNestedContainers) {
|
||||
}
|
||||
|
||||
TEST_F(JsonObject_PrettyPrintTo_Tests, NestedContainers) {
|
||||
JsonObject nested1 = object.createNestedObject("key1");
|
||||
JsonObject &nested1 = object.createNestedObject("key1");
|
||||
nested1["a"] = 1;
|
||||
|
||||
JsonArray nested2 = object.createNestedArray("key2");
|
||||
JsonArray &nested2 = object.createNestedArray("key2");
|
||||
nested2.add(2);
|
||||
|
||||
outputMustBe(
|
||||
|
@ -13,9 +13,10 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonObject_Serialization_Tests : public testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() { object = json.createObject(); }
|
||||
public:
|
||||
JsonObject_Serialization_Tests() : object(json.createObject()) {}
|
||||
|
||||
protected:
|
||||
void outputMustBe(const char *expected) {
|
||||
char actual[256];
|
||||
int result = object.printTo(actual, sizeof(actual));
|
||||
@ -24,7 +25,7 @@ class JsonObject_Serialization_Tests : public testing::Test {
|
||||
EXPECT_EQ(strlen(expected), result);
|
||||
}
|
||||
|
||||
JsonObject object;
|
||||
JsonObject &object;
|
||||
StaticJsonBuffer<5> json;
|
||||
};
|
||||
|
||||
@ -113,7 +114,7 @@ TEST_F(JsonObject_Serialization_Tests, OneFalse) {
|
||||
}
|
||||
|
||||
TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedArrayViaProxy) {
|
||||
JsonArray nestedArray = json.createArray();
|
||||
JsonArray &nestedArray = json.createArray();
|
||||
|
||||
object["key"] = nestedArray;
|
||||
|
||||
@ -121,7 +122,7 @@ TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedArrayViaProxy) {
|
||||
}
|
||||
|
||||
TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedObjectViaProxy) {
|
||||
JsonObject nestedArray = json.createObject();
|
||||
JsonObject &nestedArray = json.createObject();
|
||||
|
||||
object["key"] = nestedArray;
|
||||
|
||||
|
@ -15,17 +15,17 @@ class JsonParser_Array_Tests : public testing::Test {
|
||||
protected:
|
||||
void whenInputIs(const char *json) {
|
||||
strcpy(_jsonString, json);
|
||||
_array = _jsonBuffer.parseArray(_jsonString);
|
||||
_array = &_jsonBuffer.parseArray(_jsonString);
|
||||
}
|
||||
|
||||
void parseMustSucceed() { EXPECT_TRUE(_array.success()); }
|
||||
void parseMustSucceed() { EXPECT_TRUE(_array->success()); }
|
||||
|
||||
void parseMustFail() {
|
||||
EXPECT_FALSE(_array.success());
|
||||
EXPECT_EQ(0, _array.size());
|
||||
EXPECT_FALSE(_array->success());
|
||||
EXPECT_EQ(0, _array->size());
|
||||
}
|
||||
|
||||
void sizeMustBe(int expected) { EXPECT_EQ(expected, _array.size()); }
|
||||
void sizeMustBe(int expected) { EXPECT_EQ(expected, _array->size()); }
|
||||
|
||||
template <typename T>
|
||||
void firstElementMustBe(T expected) {
|
||||
@ -39,15 +39,15 @@ class JsonParser_Array_Tests : public testing::Test {
|
||||
|
||||
template <typename T>
|
||||
void elementAtIndexMustBe(int index, T expected) {
|
||||
EXPECT_EQ(expected, _array[index].as<T>());
|
||||
EXPECT_EQ(expected, _array->at(index).as<T>());
|
||||
}
|
||||
|
||||
void elementAtIndexMustBe(int index, const char *expected) {
|
||||
EXPECT_STREQ(expected, _array[index].as<const char *>());
|
||||
EXPECT_STREQ(expected, _array->at(index).as<const char *>());
|
||||
}
|
||||
|
||||
StaticJsonBuffer<42> _jsonBuffer;
|
||||
JsonArray _array;
|
||||
JsonArray *_array;
|
||||
char _jsonString[256];
|
||||
};
|
||||
|
||||
|
@ -15,9 +15,9 @@ TEST(JsonParser_Nested_Tests, ArrayNestedInObject) {
|
||||
StaticJsonBuffer<42> jsonBuffer;
|
||||
char jsonString[] = " { \"ab\" : [ 1 , 2 ] , \"cd\" : [ 3 , 4 ] } ";
|
||||
|
||||
JsonObject object = jsonBuffer.parseObject(jsonString);
|
||||
JsonArray array1 = object["ab"];
|
||||
JsonArray array2 = object["cd"];
|
||||
JsonObject &object = jsonBuffer.parseObject(jsonString);
|
||||
JsonArray &array1 = object["ab"];
|
||||
JsonArray &array2 = object["cd"];
|
||||
|
||||
ASSERT_TRUE(object.success());
|
||||
|
||||
@ -39,9 +39,9 @@ TEST(JsonParser_Nested_Tests, ObjectNestedInArray) {
|
||||
char jsonString[] =
|
||||
" [ { \"a\" : 1 , \"b\" : 2 } , { \"c\" : 3 , \"d\" : 4 } ] ";
|
||||
|
||||
JsonArray array = jsonBuffer.parseArray(jsonString);
|
||||
JsonObject object1 = array[0];
|
||||
JsonObject object2 = array[1];
|
||||
JsonArray &array = jsonBuffer.parseArray(jsonString);
|
||||
JsonObject &object1 = array[0];
|
||||
JsonObject &object2 = array[1];
|
||||
|
||||
ASSERT_TRUE(array.success());
|
||||
|
||||
|
@ -15,27 +15,27 @@ class JsonParser_Object_Test : public testing::Test {
|
||||
protected:
|
||||
void whenInputIs(const char *jsonString) {
|
||||
strcpy(_jsonString, jsonString);
|
||||
_object = _jsonBuffer.parseObject(_jsonString);
|
||||
_object = &_jsonBuffer.parseObject(_jsonString);
|
||||
}
|
||||
|
||||
void parseMustSucceed() { EXPECT_TRUE(_object.success()); }
|
||||
void parseMustSucceed() { EXPECT_TRUE(_object->success()); }
|
||||
|
||||
void parseMustFail() { EXPECT_FALSE(_object.success()); }
|
||||
void parseMustFail() { EXPECT_FALSE(_object->success()); }
|
||||
|
||||
void sizeMustBe(int expected) { EXPECT_EQ(expected, _object.size()); }
|
||||
void sizeMustBe(int expected) { EXPECT_EQ(expected, _object->size()); }
|
||||
|
||||
void keyMustHaveValue(const char *key, const char *expected) {
|
||||
EXPECT_STREQ(expected, _object[key].as<const char *>());
|
||||
EXPECT_STREQ(expected, _object->at(key).as<const char *>());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void keyMustHaveValue(const char *key, T expected) {
|
||||
EXPECT_EQ(expected, _object[key].as<T>());
|
||||
EXPECT_EQ(expected, _object->at(key).as<T>());
|
||||
}
|
||||
|
||||
private:
|
||||
StaticJsonBuffer<10> _jsonBuffer;
|
||||
JsonObject _object;
|
||||
JsonObject *_object;
|
||||
char _jsonString[256];
|
||||
};
|
||||
|
||||
|
@ -15,11 +15,6 @@ using namespace ArduinoJson;
|
||||
|
||||
class JsonValueTests : public ::testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
jsonValue1 = json.createValue();
|
||||
jsonValue2 = json.createValue();
|
||||
}
|
||||
|
||||
StaticJsonBuffer<42> json;
|
||||
JsonValue jsonValue1;
|
||||
JsonValue jsonValue2;
|
||||
@ -54,11 +49,11 @@ TEST_F(JsonValueTests, CanStoreString) {
|
||||
}
|
||||
|
||||
TEST_F(JsonValueTests, CanStoreObject) {
|
||||
JsonObject innerObject1 = json.createObject();
|
||||
JsonObject &innerObject1 = json.createObject();
|
||||
|
||||
jsonValue1 = innerObject1;
|
||||
|
||||
EXPECT_EQ(innerObject1, jsonValue1.as<JsonObject>());
|
||||
EXPECT_EQ(innerObject1, jsonValue1.asObject());
|
||||
}
|
||||
|
||||
TEST_F(JsonValueTests, IntegersAreCopiedByValue) {
|
||||
@ -94,21 +89,21 @@ TEST_F(JsonValueTests, StringsAreCopiedByValue) {
|
||||
}
|
||||
|
||||
TEST_F(JsonValueTests, ObjectsAreCopiedByReference) {
|
||||
JsonObject object = json.createObject();
|
||||
JsonObject &object = json.createObject();
|
||||
|
||||
jsonValue1 = object;
|
||||
|
||||
object["hello"] = "world";
|
||||
|
||||
EXPECT_EQ(1, jsonValue1.as<JsonObject>().size());
|
||||
EXPECT_EQ(1, jsonValue1.asObject().size());
|
||||
}
|
||||
|
||||
TEST_F(JsonValueTests, ArraysAreCopiedByReference) {
|
||||
JsonArray array = json.createArray();
|
||||
JsonArray &array = json.createArray();
|
||||
|
||||
jsonValue1 = array;
|
||||
|
||||
array.add("world");
|
||||
|
||||
EXPECT_EQ(1, jsonValue1.as<JsonArray>().size());
|
||||
EXPECT_EQ(1, jsonValue1.asArray().size());
|
||||
}
|
||||
|
@ -46,14 +46,14 @@ TEST(StaticJsonBuffer,
|
||||
WhenCreateObjectIsCalled_ThenAnEmptyJsonObjectIsReturned) {
|
||||
StaticJsonBuffer<42> json;
|
||||
|
||||
JsonObject obj = json.createObject();
|
||||
JsonObject &obj = json.createObject();
|
||||
EXPECT_EQ(0, obj.size());
|
||||
}
|
||||
|
||||
TEST(StaticJsonBuffer,
|
||||
GivenAJsonObject_WhenValuesAreAdded_ThenSizeIsIncreasedByTwo) {
|
||||
StaticJsonBuffer<42> json;
|
||||
JsonObject obj = json.createObject();
|
||||
JsonObject &obj = json.createObject();
|
||||
|
||||
obj["hello"];
|
||||
EXPECT_EQ(3, json.size());
|
||||
@ -66,7 +66,7 @@ TEST(
|
||||
StaticJsonBuffer,
|
||||
GivenAJsonObject_WhenSameValuesAreAddedTwice_ThenSizeIsOnlyIncreasedByTwo) {
|
||||
StaticJsonBuffer<42> json;
|
||||
JsonObject obj = json.createObject();
|
||||
JsonObject &obj = json.createObject();
|
||||
|
||||
obj["hello"];
|
||||
EXPECT_EQ(3, json.size());
|
||||
|
Reference in New Issue
Block a user