mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-14 11:06:35 +02:00
Huge refactoring in progress...
This commit is contained in:
@ -15,30 +15,43 @@ using namespace ArduinoJson;
|
||||
|
||||
class JsonArray_Container_Tests : public ::testing::Test {
|
||||
protected:
|
||||
JsonArray_Container_Tests()
|
||||
: array(json.createArray()) {
|
||||
JsonArray_Container_Tests() : array(json.createArray()) {}
|
||||
|
||||
template <typename T>
|
||||
void firstMustEqual(T expected) {
|
||||
itemMustEqual(0, expected);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void firstElementMustBe(T expected) {
|
||||
elementAtIndexMustBe(0, expected);
|
||||
void secondMustEqual(T expected) {
|
||||
itemMustEqual(1, expected);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void secondElementMustBe(T expected) {
|
||||
elementAtIndexMustBe(1, expected);
|
||||
void firstMustReference(const T& expected) {
|
||||
itemMustReference(0, expected);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void secondMustReference(const T& expected) {
|
||||
itemMustReference(1, expected);
|
||||
}
|
||||
|
||||
void sizeMustBe(int expected) { EXPECT_EQ(expected, array.size()); }
|
||||
|
||||
StaticJsonBuffer<256> json;
|
||||
JsonArray &array;
|
||||
JsonArray& array;
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void elementAtIndexMustBe(int index, T expected) {
|
||||
void itemMustEqual(int index, T expected) {
|
||||
EXPECT_EQ(expected, array[index].as<T>());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void itemMustReference(int index, const T& expected) {
|
||||
EXPECT_EQ(&expected, &array[index].as<T&>());
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(JsonArray_Container_Tests, SuccessIsTrue) {
|
||||
@ -59,24 +72,24 @@ TEST_F(JsonArray_Container_Tests, CanStoreIntegers) {
|
||||
array.add(123);
|
||||
array.add(456);
|
||||
|
||||
firstElementMustBe(123);
|
||||
secondElementMustBe(456);
|
||||
firstMustEqual(123);
|
||||
secondMustEqual(456);
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_Container_Tests, CanStoreDoubles) {
|
||||
array.add(123.45);
|
||||
array.add(456.78);
|
||||
|
||||
firstElementMustBe(123.45);
|
||||
secondElementMustBe(456.78);
|
||||
firstMustEqual(123.45);
|
||||
secondMustEqual(456.78);
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_Container_Tests, CanStoreBooleans) {
|
||||
array.add(true);
|
||||
array.add(false);
|
||||
|
||||
firstElementMustBe(true);
|
||||
secondElementMustBe(false);
|
||||
firstMustEqual(true);
|
||||
secondMustEqual(false);
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_Container_Tests, CanStoreStrings) {
|
||||
@ -86,44 +99,44 @@ TEST_F(JsonArray_Container_Tests, CanStoreStrings) {
|
||||
array.add(firstString);
|
||||
array.add(secondString);
|
||||
|
||||
firstElementMustBe(firstString);
|
||||
secondElementMustBe(secondString);
|
||||
firstMustEqual(firstString);
|
||||
secondMustEqual(secondString);
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_Container_Tests, CanStoreNestedArrays) {
|
||||
JsonArray &innerarray1 = json.createArray();
|
||||
JsonArray &innerarray2 = json.createArray();
|
||||
JsonArray& innerarray1 = json.createArray();
|
||||
JsonArray& innerarray2 = json.createArray();
|
||||
|
||||
array.add(innerarray1);
|
||||
array.add(innerarray2);
|
||||
|
||||
firstElementMustBe(innerarray1);
|
||||
secondElementMustBe(innerarray2);
|
||||
firstMustReference(innerarray1);
|
||||
secondMustReference(innerarray2);
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_Container_Tests, CanStoreNestedObjects) {
|
||||
JsonObject innerObject1 = json.createObject();
|
||||
JsonObject innerObject2 = json.createObject();
|
||||
JsonObject& innerObject1 = json.createObject();
|
||||
JsonObject& innerObject2 = json.createObject();
|
||||
|
||||
array.add(innerObject1);
|
||||
array.add(innerObject2);
|
||||
|
||||
firstElementMustBe(innerObject1);
|
||||
secondElementMustBe(innerObject2);
|
||||
firstMustReference(innerObject1);
|
||||
secondMustReference(innerObject2);
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_Container_Tests, CanCreateNestedArrays) {
|
||||
JsonArray innerarray1 = array.createNestedArray();
|
||||
JsonArray innerarray2 = array.createNestedArray();
|
||||
JsonArray& innerarray1 = array.createNestedArray();
|
||||
JsonArray& innerarray2 = array.createNestedArray();
|
||||
|
||||
firstElementMustBe(innerarray1);
|
||||
secondElementMustBe(innerarray2);
|
||||
firstMustReference(innerarray1);
|
||||
secondMustReference(innerarray2);
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_Container_Tests, CanCreateNestedObjects) {
|
||||
JsonObject innerObject1 = array.createNestedObject();
|
||||
JsonObject innerObject2 = array.createNestedObject();
|
||||
JsonObject& innerObject1 = array.createNestedObject();
|
||||
JsonObject& innerObject2 = array.createNestedObject();
|
||||
|
||||
firstElementMustBe(innerObject1);
|
||||
secondElementMustBe(innerObject2);
|
||||
firstMustReference(innerObject1);
|
||||
secondMustReference(innerObject2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user