Added unit tests of sample string given by gbatree

This commit is contained in:
Benoit Blanchon
2014-02-26 22:29:20 +01:00
parent a58fb13d37
commit 995aa7dd40
3 changed files with 72 additions and 0 deletions

View File

@ -97,6 +97,7 @@
<ClCompile Include="..\utility\jsmn.cpp" /> <ClCompile Include="..\utility\jsmn.cpp" />
<ClCompile Include="TestArrayExample.cpp" /> <ClCompile Include="TestArrayExample.cpp" />
<ClCompile Include="TestHashTableExample.cpp" /> <ClCompile Include="TestHashTableExample.cpp" />
<ClCompile Include="TestGbathreeStrings.cpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -50,5 +50,8 @@
<ClCompile Include="TestArrayExample.cpp"> <ClCompile Include="TestArrayExample.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="TestGbathreeStrings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,68 @@
#include "CppUnitTest.h"
#include "JsonParser.h"
#include <string>
using namespace std;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace ArduinoJsonParserTests
{
TEST_CLASS(TestGbathreeSample1)
{
char json[1024];
JsonParser<200> parser;
JsonHashTable root;
public:
TEST_METHOD_INITIALIZE(Initialize)
{
strcpy(json, "{ \"protocol_name\":\"fluorescence\",\"repeats\":1,\"wait\":0,\"averages\":1,\"measurements\":3,\"meas2_light\":15,\"meas1_baseline\":0,\"act_light\":20,\"pulsesize\":25,\"pulsedistance\":10000,\"actintensity1\":50,\"actintensity2\":255,\"measintensity\":255,\"calintensity\":255,\"pulses\":[50,50,50],\"act\":[2,1,2,2],\"red\":[2,2,2,2],\"detectors\":[[34,34,34,34],[34,34,34,34],[34,34,34,34],[34,34,34,34]],\"alta\":[2,2,2,2],\"altb\":[2,2,2,2],\"measlights\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]],\"measlights2\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]],\"altc\":[2,2,2,2],\"altd\":[2,2,2,2]}");
root = parser.parseHashTable(json);
}
TEST_METHOD(Root)
{
Assert::IsTrue(root.success());
}
TEST_METHOD(ProtocolName)
{
string protocol_name = root.getString("protocol_name");
Assert::AreEqual(string("fluorescence"), protocol_name);
}
TEST_METHOD(Measlights)
{
// measlights:[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
JsonArray measlights = root.getArray("altd");
Assert::IsTrue(measlights.success());
Assert::AreEqual(4, measlights.getLength());
for (int i = 0; i < 4; i++)
{
Assert::AreEqual(4, measlights.getArray(i).getLength());
for (int j = 0; j < 4; j++)
Assert::AreEqual(15L, measlights.getArray(i).getLong(j));
}
}
TEST_METHOD(Altd)
{
// altd:[2,2,2,2]
JsonArray altd = root.getArray("altd");
Assert::IsTrue(altd.success());
Assert::AreEqual(4, altd.getLength());
for (int i = 0; i < 4; i++)
{
Assert::AreEqual(2L, altd.getLong(i));
}
}
};
}