Added JsonParser_String_Tests.cpp

This commit is contained in:
Benoit Blanchon
2014-10-16 21:54:42 +02:00
parent a0a82c0f4e
commit 2a62132bf0
3 changed files with 55 additions and 2 deletions

View File

@ -26,7 +26,9 @@ public:
JsonValue createValue();
JsonArray parseArray(char* string);
JsonArray parseArray(char* json);
JsonValue parseValue(char* json);
protected:
virtual void* allocateNode() = 0;
@ -41,4 +43,3 @@ private:
JsonNode* createObjectNode();
JsonNode* createStringNode(const char* value);
};

View File

@ -25,6 +25,12 @@ JsonArray JsonBuffer::parseArray(char* json)
return JsonArray(parser.parseAnything());
}
JsonValue JsonBuffer::parseValue(char* json)
{
JsonParser parser(this, json);
return JsonValue(parser.parseAnything());
}
JsonNode* JsonBuffer::createArrayNode()
{
JsonNode* node = createNode();

View File

@ -0,0 +1,46 @@
#include <gtest/gtest.h>
#include <ArduinoJson/StaticJsonBuffer.h>
#include <ArduinoJson/JsonValue.h>
class JsonParser_String_Tests : public testing::Test
{
protected:
void whenInputIs(const char* json)
{
strcpy(_jsonString, json);
_result = _jsonBuffer.parseValue(_jsonString);
}
void outputMustBe(const char* expected)
{
EXPECT_STREQ(expected, _result);
}
char _jsonString[256];
StaticJsonBuffer<42> _jsonBuffer;
const char* _result;
};
TEST_F(JsonParser_String_Tests, SimpleString)
{
whenInputIs("\"hello world\"");
outputMustBe("hello world");
}
TEST_F(JsonParser_String_Tests, CurlyBraces)
{
whenInputIs("\"{hello:world}\"");
outputMustBe("{hello:world}");
}
TEST_F(JsonParser_String_Tests, SquareBraquets)
{
whenInputIs("\"[hello,world]\"");
outputMustBe("[hello,world]");
}
TEST_F(JsonParser_String_Tests, EscapedQuote)
{
whenInputIs("\"hello \\\"world\\\"\"");
outputMustBe("hello \"world\"");
}