-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benoit Blanchon
committed
Apr 27, 2015
1 parent
877096d
commit 81285f4
Showing
6 changed files
with
159 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright Benoit Blanchon 2014-2015 | ||
// MIT License | ||
// | ||
// Arduino JSON library | ||
// https://github.com/bblanchon/ArduinoJson | ||
|
||
#include <gtest/gtest.h> | ||
#include <ArduinoJson.h> | ||
|
||
class StaticJsonBuffer_ParseArray_Tests : public testing::Test { | ||
protected: | ||
void with(JsonBuffer& jsonBuffer) { _jsonBuffer = &jsonBuffer; } | ||
|
||
void whenInputIs(const char* json) { strcpy(_jsonString, json); } | ||
|
||
void parseMustSucceed() { | ||
EXPECT_TRUE(_jsonBuffer->parseArray(_jsonString).success()); | ||
} | ||
|
||
void parseMustFail() { | ||
EXPECT_FALSE(_jsonBuffer->parseArray(_jsonString).success()); | ||
} | ||
|
||
private: | ||
JsonBuffer* _jsonBuffer; | ||
char _jsonString[256]; | ||
}; | ||
|
||
TEST_F(StaticJsonBuffer_ParseArray_Tests, TooSmallBufferForEmptyArray) { | ||
StaticJsonBuffer<JSON_ARRAY_SIZE(0) - 1> bufferTooSmall; | ||
with(bufferTooSmall); | ||
whenInputIs("[]"); | ||
parseMustFail(); | ||
} | ||
|
||
TEST_F(StaticJsonBuffer_ParseArray_Tests, BufferOfTheRightSizeForEmptyArray) { | ||
StaticJsonBuffer<JSON_ARRAY_SIZE(0)> bufferOfRightSize; | ||
with(bufferOfRightSize); | ||
whenInputIs("[]"); | ||
parseMustSucceed(); | ||
} | ||
|
||
TEST_F(StaticJsonBuffer_ParseArray_Tests, TooSmallBufferForArrayWithOneValue) { | ||
StaticJsonBuffer<JSON_ARRAY_SIZE(1) - 1> bufferTooSmall; | ||
with(bufferTooSmall); | ||
whenInputIs("[1]"); | ||
parseMustFail(); | ||
} | ||
|
||
TEST_F(StaticJsonBuffer_ParseArray_Tests, | ||
BufferOfTheRightSizeForArrayWithOneValue) { | ||
StaticJsonBuffer<JSON_ARRAY_SIZE(1)> bufferOfRightSize; | ||
with(bufferOfRightSize); | ||
whenInputIs("[1]"); | ||
parseMustSucceed(); | ||
} | ||
|
||
TEST_F(StaticJsonBuffer_ParseArray_Tests, | ||
TooSmallBufferForArrayWithNestedObject) { | ||
StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0) - 1> bufferTooSmall; | ||
with(bufferTooSmall); | ||
whenInputIs("[{}]"); | ||
parseMustFail(); | ||
} | ||
|
||
TEST_F(StaticJsonBuffer_ParseArray_Tests, | ||
BufferOfTheRightSizeForArrayWithNestedObject) { | ||
StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0)> bufferOfRightSize; | ||
with(bufferOfRightSize); | ||
whenInputIs("[{}]"); | ||
parseMustSucceed(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright Benoit Blanchon 2014-2015 | ||
// MIT License | ||
// | ||
// Arduino JSON library | ||
// https://github.com/bblanchon/ArduinoJson | ||
|
||
#include <gtest/gtest.h> | ||
#include <ArduinoJson.h> | ||
|
||
class StaticJsonBuffer_ParseObject_Tests : public testing::Test { | ||
protected: | ||
void with(JsonBuffer& jsonBuffer) { _jsonBuffer = &jsonBuffer; } | ||
|
||
void whenInputIs(const char* json) { strcpy(_jsonString, json); } | ||
|
||
void parseMustSucceed() { | ||
EXPECT_TRUE(_jsonBuffer->parseObject(_jsonString).success()); | ||
} | ||
|
||
void parseMustFail() { | ||
EXPECT_FALSE(_jsonBuffer->parseObject(_jsonString).success()); | ||
} | ||
|
||
private: | ||
JsonBuffer* _jsonBuffer; | ||
char _jsonString[256]; | ||
}; | ||
|
||
TEST_F(StaticJsonBuffer_ParseObject_Tests, TooSmallBufferForEmptyObject) { | ||
StaticJsonBuffer<JSON_OBJECT_SIZE(0) - 1> bufferTooSmall; | ||
with(bufferTooSmall); | ||
whenInputIs("{}"); | ||
parseMustFail(); | ||
} | ||
|
||
TEST_F(StaticJsonBuffer_ParseObject_Tests, BufferOfTheRightSizeForEmptyObject) { | ||
StaticJsonBuffer<JSON_OBJECT_SIZE(0)> bufferOfRightSize; | ||
with(bufferOfRightSize); | ||
whenInputIs("{}"); | ||
parseMustSucceed(); | ||
} | ||
|
||
TEST_F(StaticJsonBuffer_ParseObject_Tests, | ||
TooSmallBufferForObjectWithOneValue) { | ||
StaticJsonBuffer<JSON_OBJECT_SIZE(1) - 1> bufferTooSmall; | ||
with(bufferTooSmall); | ||
whenInputIs("{\"a\":1}"); | ||
parseMustFail(); | ||
} | ||
|
||
TEST_F(StaticJsonBuffer_ParseObject_Tests, | ||
BufferOfTheRightSizeForObjectWithOneValue) { | ||
StaticJsonBuffer<JSON_OBJECT_SIZE(1)> bufferOfRightSize; | ||
with(bufferOfRightSize); | ||
whenInputIs("{\"a\":1}"); | ||
parseMustSucceed(); | ||
} | ||
|
||
TEST_F(StaticJsonBuffer_ParseObject_Tests, | ||
TooSmallBufferForObjectWithNestedObject) { | ||
StaticJsonBuffer<JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(0) - 1> bufferTooSmall; | ||
with(bufferTooSmall); | ||
whenInputIs("{\"a\":[]}"); | ||
parseMustFail(); | ||
} | ||
|
||
TEST_F(StaticJsonBuffer_ParseObject_Tests, | ||
BufferOfTheRightSizeForObjectWithNestedObject) { | ||
StaticJsonBuffer<JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(0)> bufferOfRightSize; | ||
with(bufferOfRightSize); | ||
whenInputIs("{\"a\":[]}"); | ||
parseMustSucceed(); | ||
} |