forked from bblanchon/ArduinoJson
Added unit tests of the JsonArray example
This commit is contained in:
@ -95,6 +95,7 @@
|
||||
<ClCompile Include="..\JsonHashTable.cpp" />
|
||||
<ClCompile Include="..\JsonObjectBase.cpp" />
|
||||
<ClCompile Include="..\utility\jsmn.cpp" />
|
||||
<ClCompile Include="TestArrayExample.cpp" />
|
||||
<ClCompile Include="TestHashTableExample.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@ -47,5 +47,8 @@
|
||||
<ClCompile Include="TestHashTableExample.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TestArrayExample.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
50
tests/TestArrayExample.cpp
Normal file
50
tests/TestArrayExample.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include "CppUnitTest.h"
|
||||
#include "JsonParser.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace ArduinoJsonParserTests
|
||||
{
|
||||
TEST_CLASS(TestArrayExample)
|
||||
{
|
||||
char json[128];
|
||||
JsonParser<32> parser;
|
||||
JsonArray array;
|
||||
|
||||
public:
|
||||
|
||||
TEST_METHOD_INITIALIZE(Initialize)
|
||||
{
|
||||
strcpy(json, "[[1.2,3.4],[5.6,7.8]]");
|
||||
array = parser.parseArray(json);
|
||||
}
|
||||
|
||||
TEST_METHOD(Array_Success_ReturnsTrue)
|
||||
{
|
||||
Assert::IsTrue(array.success());
|
||||
}
|
||||
|
||||
TEST_METHOD(Array_GetLength_Returns2)
|
||||
{
|
||||
Assert::AreEqual(2, array.getLength());
|
||||
}
|
||||
|
||||
TEST_METHOD(Array_GetArray0_ReturnsInnerArray0)
|
||||
{
|
||||
JsonArray innerArray = array.getArray(0);
|
||||
|
||||
Assert::AreEqual(2, innerArray.getLength());
|
||||
Assert::AreEqual(1.2, innerArray.getDouble(0));
|
||||
Assert::AreEqual(3.4, innerArray.getDouble(1));
|
||||
}
|
||||
|
||||
TEST_METHOD(Array_GetArray1_ReturnsInnerArray1)
|
||||
{
|
||||
JsonArray innerArray = array.getArray(1);
|
||||
|
||||
Assert::AreEqual(2, innerArray.getLength());
|
||||
Assert::AreEqual(5.6, innerArray.getDouble(0));
|
||||
Assert::AreEqual(7.8, innerArray.getDouble(1));
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user