forked from bblanchon/ArduinoJson
Switched to Google coding style to match cpplint expectations
This commit is contained in:
@ -12,7 +12,7 @@ struct Person {
|
||||
};
|
||||
|
||||
class Issue10 : public testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
Person boss;
|
||||
boss.id = 1;
|
||||
@ -47,8 +47,8 @@ TEST_F(Issue10, PopulateArrayByAddingAnObject) {
|
||||
object["id"] = persons[i].id;
|
||||
object["name"] = persons[i].name;
|
||||
|
||||
array.add(object); // <- adds a reference to an existing objet (creates 2
|
||||
// extra proxy nodes)
|
||||
array.add(object); // <- adds a reference to an existing objet (creates 2
|
||||
// extra proxy nodes)
|
||||
}
|
||||
|
||||
checkJsonString(array);
|
||||
|
@ -5,16 +5,18 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonArray_Container_Tests : public ::testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
virtual void SetUp() { array = json.createArray(); }
|
||||
|
||||
void nodeCountMustBe(int expected) { EXPECT_EQ(expected, json.size()); }
|
||||
|
||||
template <typename T> void firstElementMustBe(T expected) {
|
||||
template <typename T>
|
||||
void firstElementMustBe(T expected) {
|
||||
elementAtIndexMustBe(0, expected);
|
||||
}
|
||||
|
||||
template <typename T> void secondElementMustBe(T expected) {
|
||||
template <typename T>
|
||||
void secondElementMustBe(T expected) {
|
||||
elementAtIndexMustBe(1, expected);
|
||||
}
|
||||
|
||||
@ -23,8 +25,9 @@ protected:
|
||||
StaticJsonBuffer<42> json;
|
||||
JsonArray array;
|
||||
|
||||
private:
|
||||
template <typename T> void elementAtIndexMustBe(int index, T expected) {
|
||||
private:
|
||||
template <typename T>
|
||||
void elementAtIndexMustBe(int index, T expected) {
|
||||
EXPECT_EQ(expected, array[index].as<T>());
|
||||
}
|
||||
};
|
||||
|
@ -15,10 +15,10 @@ TEST(JsonArray_Iterator_Test, SimpleTest) {
|
||||
JsonArrayIterator end = array.end();
|
||||
|
||||
EXPECT_NE(end, it);
|
||||
EXPECT_EQ(12, (*it).as<int>()); // TODO: use ->
|
||||
EXPECT_EQ(12, (*it).as<int>()); // TODO: use ->
|
||||
++it;
|
||||
EXPECT_NE(end, it);
|
||||
EXPECT_EQ(34, (*it).as<int>()); // TODO: use ->
|
||||
EXPECT_EQ(34, (*it).as<int>()); // TODO: use ->
|
||||
++it;
|
||||
EXPECT_EQ(array.end(), it);
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonArray_PrettyPrintTo_Tests : public testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
JsonArray array;
|
||||
StaticJsonBuffer<30> json;
|
||||
|
||||
@ -24,7 +24,7 @@ protected:
|
||||
EXPECT_EQ(strlen(expected), n);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
char buffer[256];
|
||||
};
|
||||
|
||||
@ -33,29 +33,32 @@ TEST_F(JsonArray_PrettyPrintTo_Tests, Empty) { outputMustBe("[]"); }
|
||||
TEST_F(JsonArray_PrettyPrintTo_Tests, OneElement) {
|
||||
array.add(1);
|
||||
|
||||
outputMustBe("[\r\n"
|
||||
" 1\r\n"
|
||||
"]");
|
||||
outputMustBe(
|
||||
"[\r\n"
|
||||
" 1\r\n"
|
||||
"]");
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_PrettyPrintTo_Tests, TwoElements) {
|
||||
array.add(1);
|
||||
array.add(2);
|
||||
|
||||
outputMustBe("[\r\n"
|
||||
" 1,\r\n"
|
||||
" 2\r\n"
|
||||
"]");
|
||||
outputMustBe(
|
||||
"[\r\n"
|
||||
" 1,\r\n"
|
||||
" 2\r\n"
|
||||
"]");
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_PrettyPrintTo_Tests, EmptyNestedArrays) {
|
||||
array.createNestedArray();
|
||||
array.createNestedArray();
|
||||
|
||||
outputMustBe("[\r\n"
|
||||
" [],\r\n"
|
||||
" []\r\n"
|
||||
"]");
|
||||
outputMustBe(
|
||||
"[\r\n"
|
||||
" [],\r\n"
|
||||
" []\r\n"
|
||||
"]");
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_PrettyPrintTo_Tests, NestedArrays) {
|
||||
@ -66,13 +69,14 @@ TEST_F(JsonArray_PrettyPrintTo_Tests, NestedArrays) {
|
||||
JsonObject nested2 = array.createNestedObject();
|
||||
nested2["key"] = 3;
|
||||
|
||||
outputMustBe("[\r\n"
|
||||
" [\r\n"
|
||||
" 1,\r\n"
|
||||
" 2\r\n"
|
||||
" ],\r\n"
|
||||
" {\r\n"
|
||||
" \"key\": 3\r\n"
|
||||
" }\r\n"
|
||||
"]");
|
||||
outputMustBe(
|
||||
"[\r\n"
|
||||
" [\r\n"
|
||||
" 1,\r\n"
|
||||
" 2\r\n"
|
||||
" ],\r\n"
|
||||
" {\r\n"
|
||||
" \"key\": 3\r\n"
|
||||
" }\r\n"
|
||||
"]");
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonArray_PrintTo_Tests : public testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
JsonArray array;
|
||||
StaticJsonBuffer<3> json;
|
||||
|
||||
@ -23,7 +23,7 @@ protected:
|
||||
EXPECT_EQ(strlen(expected), n);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
char buffer[256];
|
||||
};
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonObject_Container_Tests : public ::testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
virtual void SetUp() { object = json.createObject(); }
|
||||
|
||||
StaticJsonBuffer<42> json;
|
||||
|
@ -11,7 +11,7 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonObject_PrettyPrintTo_Tests : public testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
JsonObject object;
|
||||
StaticJsonBuffer<30> json;
|
||||
|
||||
@ -23,7 +23,7 @@ protected:
|
||||
EXPECT_EQ(strlen(expected), n);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
char buffer[256];
|
||||
};
|
||||
|
||||
@ -32,29 +32,32 @@ TEST_F(JsonObject_PrettyPrintTo_Tests, EmptyObject) { outputMustBe("{}"); }
|
||||
TEST_F(JsonObject_PrettyPrintTo_Tests, OneMember) {
|
||||
object["key"] = "value";
|
||||
|
||||
outputMustBe("{\r\n"
|
||||
" \"key\": \"value\"\r\n"
|
||||
"}");
|
||||
outputMustBe(
|
||||
"{\r\n"
|
||||
" \"key\": \"value\"\r\n"
|
||||
"}");
|
||||
}
|
||||
|
||||
TEST_F(JsonObject_PrettyPrintTo_Tests, TwoMembers) {
|
||||
object["key1"] = "value1";
|
||||
object["key2"] = "value2";
|
||||
|
||||
outputMustBe("{\r\n"
|
||||
" \"key1\": \"value1\",\r\n"
|
||||
" \"key2\": \"value2\"\r\n"
|
||||
"}");
|
||||
outputMustBe(
|
||||
"{\r\n"
|
||||
" \"key1\": \"value1\",\r\n"
|
||||
" \"key2\": \"value2\"\r\n"
|
||||
"}");
|
||||
}
|
||||
|
||||
TEST_F(JsonObject_PrettyPrintTo_Tests, EmptyNestedContainers) {
|
||||
object.createNestedObject("key1");
|
||||
object.createNestedArray("key2");
|
||||
|
||||
outputMustBe("{\r\n"
|
||||
" \"key1\": {},\r\n"
|
||||
" \"key2\": []\r\n"
|
||||
"}");
|
||||
outputMustBe(
|
||||
"{\r\n"
|
||||
" \"key1\": {},\r\n"
|
||||
" \"key2\": []\r\n"
|
||||
"}");
|
||||
}
|
||||
|
||||
TEST_F(JsonObject_PrettyPrintTo_Tests, NestedContainers) {
|
||||
@ -64,12 +67,13 @@ TEST_F(JsonObject_PrettyPrintTo_Tests, NestedContainers) {
|
||||
JsonArray nested2 = object.createNestedArray("key2");
|
||||
nested2.add(2);
|
||||
|
||||
outputMustBe("{\r\n"
|
||||
" \"key1\": {\r\n"
|
||||
" \"a\": 1\r\n"
|
||||
" },\r\n"
|
||||
" \"key2\": [\r\n"
|
||||
" 2\r\n"
|
||||
" ]\r\n"
|
||||
"}");
|
||||
outputMustBe(
|
||||
"{\r\n"
|
||||
" \"key1\": {\r\n"
|
||||
" \"a\": 1\r\n"
|
||||
" },\r\n"
|
||||
" \"key2\": [\r\n"
|
||||
" 2\r\n"
|
||||
" ]\r\n"
|
||||
"}");
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonObject_Serialization_Tests : public testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
virtual void SetUp() { object = json.createObject(); }
|
||||
|
||||
void outputMustBe(const char *expected) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonParser_Array_Tests : public testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
void whenInputIs(const char *json) {
|
||||
strcpy(_jsonString, json);
|
||||
_array = _jsonBuffer.parseArray(_jsonString);
|
||||
@ -20,15 +20,18 @@ protected:
|
||||
|
||||
void sizeMustBe(int expected) { EXPECT_EQ(expected, _array.size()); }
|
||||
|
||||
template <typename T> void firstElementMustBe(T expected) {
|
||||
template <typename T>
|
||||
void firstElementMustBe(T expected) {
|
||||
elementAtIndexMustBe(0, expected);
|
||||
}
|
||||
|
||||
template <typename T> void secondElementMustBe(T expected) {
|
||||
template <typename T>
|
||||
void secondElementMustBe(T expected) {
|
||||
elementAtIndexMustBe(1, expected);
|
||||
}
|
||||
|
||||
template <typename T> void elementAtIndexMustBe(int index, T expected) {
|
||||
template <typename T>
|
||||
void elementAtIndexMustBe(int index, T expected) {
|
||||
EXPECT_EQ(expected, _array[index].as<T>());
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonParser_Object_Test : public testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
void whenInputIs(const char *jsonString) {
|
||||
strcpy(_jsonString, jsonString);
|
||||
_object = _jsonBuffer.parseObject(_jsonString);
|
||||
@ -21,11 +21,12 @@ protected:
|
||||
EXPECT_STREQ(expected, _object[key].as<const char *>());
|
||||
}
|
||||
|
||||
template <typename T> void keyMustHaveValue(const char *key, T expected) {
|
||||
template <typename T>
|
||||
void keyMustHaveValue(const char *key, T expected) {
|
||||
EXPECT_EQ(expected, _object[key].as<T>());
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
StaticJsonBuffer<10> _jsonBuffer;
|
||||
JsonObject _object;
|
||||
char _jsonString[256];
|
||||
|
@ -5,7 +5,7 @@
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonValueTests : public ::testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
jsonValue1 = json.createValue();
|
||||
jsonValue2 = json.createValue();
|
||||
|
@ -4,7 +4,7 @@
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
class QuotedString_ExtractFrom_Tests : public testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
void whenInputIs(const char *json) {
|
||||
strcpy(_jsonString, json);
|
||||
_result = QuotedString::extractFrom(_jsonString, &_trailing);
|
||||
@ -16,7 +16,7 @@ protected:
|
||||
EXPECT_STREQ(expected, _trailing);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
char _jsonString[256];
|
||||
char *_result;
|
||||
char *_trailing;
|
||||
|
@ -6,7 +6,7 @@
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
class QuotedString_PrintTo_Tests : public testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
void whenInputIs(const char *input) {
|
||||
StringBuilder sb(buffer, sizeof(buffer));
|
||||
returnValue = QuotedString::printTo(input, &sb);
|
||||
@ -17,7 +17,7 @@ protected:
|
||||
EXPECT_EQ(strlen(expected), returnValue);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
char buffer[1024];
|
||||
size_t returnValue;
|
||||
};
|
||||
@ -44,7 +44,7 @@ TEST_F(QuotedString_PrintTo_Tests, ReverseSolidus) {
|
||||
|
||||
TEST_F(QuotedString_PrintTo_Tests, Solidus) {
|
||||
whenInputIs("/");
|
||||
outputMustBe("\"/\""); // but the JSON format allows \/
|
||||
outputMustBe("\"/\""); // but the JSON format allows \/
|
||||
}
|
||||
|
||||
TEST_F(QuotedString_PrintTo_Tests, Backspace) {
|
||||
|
@ -4,7 +4,7 @@
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
class StringBuilderTests : public testing::Test {
|
||||
protected:
|
||||
protected:
|
||||
virtual void SetUp() { sb = new StringBuilder(buffer, sizeof(buffer)); }
|
||||
|
||||
void print(const char *value) { returnValue = sb->print(value); }
|
||||
@ -13,7 +13,7 @@ protected:
|
||||
|
||||
void resultMustBe(size_t expected) { EXPECT_EQ(expected, returnValue); }
|
||||
|
||||
private:
|
||||
private:
|
||||
char buffer[20];
|
||||
Print *sb;
|
||||
size_t returnValue;
|
||||
|
Reference in New Issue
Block a user