mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 21:12:25 +02:00
Extracted a class to test strings
This commit is contained in:
@ -11,33 +11,27 @@ using namespace ArduinoJson::Parser;
|
|||||||
|
|
||||||
namespace ArduinoJsonParserTests
|
namespace ArduinoJsonParserTests
|
||||||
{
|
{
|
||||||
TEST_CLASS(JsonArrayTests)
|
TEST_CLASS(JsonArrayTests)
|
||||||
{
|
{
|
||||||
JsonArray array;
|
JsonArray array;
|
||||||
char json[256];
|
char json[256];
|
||||||
jsmntok_t tokens[32];
|
jsmntok_t tokens[32];
|
||||||
JsonParserBase parser = JsonParserBase(tokens, 32);
|
JsonParserBase parser = JsonParserBase(tokens, 32);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TEST_METHOD(EmptyString)
|
TEST_METHOD(TooFewClosingBrackets)
|
||||||
{
|
{
|
||||||
whenInputIs("");
|
|
||||||
parseMustFail();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_METHOD(TooFewClosingBrackets)
|
|
||||||
{
|
|
||||||
whenInputIs("[[]");
|
whenInputIs("[[]");
|
||||||
parseMustFail();
|
parseMustFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(TooManyClosingBrackets)
|
TEST_METHOD(TooManyClosingBrackets)
|
||||||
{
|
{
|
||||||
whenInputIs("[]]");
|
whenInputIs("[]]");
|
||||||
parseMustFail();
|
parseMustFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(EmptyArray)
|
TEST_METHOD(EmptyArray)
|
||||||
{
|
{
|
||||||
whenInputIs("[]");
|
whenInputIs("[]");
|
||||||
@ -55,8 +49,8 @@ namespace ArduinoJsonParserTests
|
|||||||
itemMustNotExist(0);
|
itemMustNotExist(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(TwoIntegers)
|
TEST_METHOD(TwoIntegers)
|
||||||
{
|
{
|
||||||
setTokenCountTo(3);
|
setTokenCountTo(3);
|
||||||
|
|
||||||
whenInputIs("[1,2]");
|
whenInputIs("[1,2]");
|
||||||
@ -66,7 +60,7 @@ namespace ArduinoJsonParserTests
|
|||||||
itemMustBe(0, 1L);
|
itemMustBe(0, 1L);
|
||||||
itemMustBe(1, 2L);
|
itemMustBe(1, 2L);
|
||||||
itemMustNotExist(2);
|
itemMustNotExist(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(TwoBooleans)
|
TEST_METHOD(TwoBooleans)
|
||||||
{
|
{
|
||||||
@ -94,8 +88,8 @@ namespace ArduinoJsonParserTests
|
|||||||
itemMustNotExist(2);
|
itemMustNotExist(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(TwoDimensionsArray)
|
TEST_METHOD(TwoDimensionsArray)
|
||||||
{
|
{
|
||||||
setTokenCountTo(7);
|
setTokenCountTo(7);
|
||||||
|
|
||||||
whenInputIs("[[1,2],[3,4]]");
|
whenInputIs("[[1,2],[3,4]]");
|
||||||
@ -107,7 +101,7 @@ namespace ArduinoJsonParserTests
|
|||||||
itemMustBe(1, 0, 3L);
|
itemMustBe(1, 0, 3L);
|
||||||
itemMustBe(1, 1, 4L);
|
itemMustBe(1, 1, 4L);
|
||||||
itemMustNotExist(2);
|
itemMustNotExist(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(ThreeDimensionsArray)
|
TEST_METHOD(ThreeDimensionsArray)
|
||||||
{
|
{
|
||||||
@ -127,7 +121,7 @@ namespace ArduinoJsonParserTests
|
|||||||
itemMustBe(1, 1, 1, 8L);
|
itemMustBe(1, 1, 1, 8L);
|
||||||
itemMustNotExist(2);
|
itemMustNotExist(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void setTokenCountTo(int n)
|
void setTokenCountTo(int n)
|
||||||
@ -191,5 +185,5 @@ namespace ArduinoJsonParserTests
|
|||||||
Assert::AreEqual(0L, array.getLong(index));
|
Assert::AreEqual(0L, array.getLong(index));
|
||||||
Assert::IsNull(array.getString(index));
|
Assert::IsNull(array.getString(index));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -23,12 +23,6 @@ namespace ArduinoJsonParserTests
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TEST_METHOD(EmptyString)
|
|
||||||
{
|
|
||||||
whenInputIs("");
|
|
||||||
parseMustFail();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_METHOD(EmptyHashTable)
|
TEST_METHOD(EmptyHashTable)
|
||||||
{
|
{
|
||||||
whenInputIs("{}");
|
whenInputIs("{}");
|
||||||
|
@ -90,6 +90,7 @@
|
|||||||
<ClCompile Include="JsonArrayIteratorTests.cpp" />
|
<ClCompile Include="JsonArrayIteratorTests.cpp" />
|
||||||
<ClCompile Include="JsonObjectTests.cpp" />
|
<ClCompile Include="JsonObjectTests.cpp" />
|
||||||
<ClCompile Include="GbathreeBug.cpp" />
|
<ClCompile Include="GbathreeBug.cpp" />
|
||||||
|
<ClCompile Include="JsonStringTests.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\JsonParser\JsonParser.vcxproj">
|
<ProjectReference Include="..\JsonParser\JsonParser.vcxproj">
|
||||||
|
@ -15,9 +15,6 @@
|
|||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="JsonArrayTests.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="GbathreeBug.cpp">
|
<ClCompile Include="GbathreeBug.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -30,5 +27,11 @@
|
|||||||
<ClCompile Include="JsonObjectIteratorTests.cpp">
|
<ClCompile Include="JsonObjectIteratorTests.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="JsonArrayTests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="JsonStringTests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
53
JsonParserTests/JsonStringTests.cpp
Normal file
53
JsonParserTests/JsonStringTests.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Arduino JSON library
|
||||||
|
* Benoit Blanchon 2014 - MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CppUnitTest.h"
|
||||||
|
#include "JsonParser.h"
|
||||||
|
|
||||||
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
using namespace ArduinoJson::Parser;
|
||||||
|
|
||||||
|
namespace ArduinoJsonParserTests
|
||||||
|
{
|
||||||
|
TEST_CLASS(JsonStringTests)
|
||||||
|
{
|
||||||
|
const char* actual;
|
||||||
|
char json[256];
|
||||||
|
JsonParser<32> parser;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
TEST_METHOD(EmptyString)
|
||||||
|
{
|
||||||
|
whenInputIs("");
|
||||||
|
outputMustBe(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(JustOneQuote)
|
||||||
|
{
|
||||||
|
whenInputIs("\"");
|
||||||
|
outputMustBe(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(EscapedQuote)
|
||||||
|
{
|
||||||
|
whenInputIs("\\\"");
|
||||||
|
outputMustBe("\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void whenInputIs(const char* input)
|
||||||
|
{
|
||||||
|
strcpy(json, input);
|
||||||
|
actual = parser.parse(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
void outputMustBe(const char* expected)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(expected, actual);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue
Block a user