Skip to content

Commit 995aa7d

Browse files
committed
Added unit tests of sample string given by gbatree
1 parent a58fb13 commit 995aa7d

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

tests/ArduinoJsonParserTests.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<ClCompile Include="..\utility\jsmn.cpp" />
9898
<ClCompile Include="TestArrayExample.cpp" />
9999
<ClCompile Include="TestHashTableExample.cpp" />
100+
<ClCompile Include="TestGbathreeStrings.cpp" />
100101
</ItemGroup>
101102
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
102103
<ImportGroup Label="ExtensionTargets">

tests/ArduinoJsonParserTests.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
<ClCompile Include="TestArrayExample.cpp">
5151
<Filter>Source Files</Filter>
5252
</ClCompile>
53+
<ClCompile Include="TestGbathreeStrings.cpp">
54+
<Filter>Source Files</Filter>
55+
</ClCompile>
5356
</ItemGroup>
5457
</Project>

tests/TestGbathreeStrings.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include "CppUnitTest.h"
2+
#include "JsonParser.h"
3+
#include <string>
4+
5+
using namespace std;
6+
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
7+
8+
namespace ArduinoJsonParserTests
9+
{
10+
TEST_CLASS(TestGbathreeSample1)
11+
{
12+
char json[1024];
13+
JsonParser<200> parser;
14+
JsonHashTable root;
15+
16+
17+
public:
18+
19+
TEST_METHOD_INITIALIZE(Initialize)
20+
{
21+
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]}");
22+
root = parser.parseHashTable(json);
23+
}
24+
25+
TEST_METHOD(Root)
26+
{
27+
Assert::IsTrue(root.success());
28+
}
29+
30+
TEST_METHOD(ProtocolName)
31+
{
32+
string protocol_name = root.getString("protocol_name");
33+
Assert::AreEqual(string("fluorescence"), protocol_name);
34+
}
35+
36+
TEST_METHOD(Measlights)
37+
{
38+
// measlights:[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
39+
40+
JsonArray measlights = root.getArray("altd");
41+
Assert::IsTrue(measlights.success());
42+
Assert::AreEqual(4, measlights.getLength());
43+
44+
for (int i = 0; i < 4; i++)
45+
{
46+
Assert::AreEqual(4, measlights.getArray(i).getLength());
47+
48+
for (int j = 0; j < 4; j++)
49+
Assert::AreEqual(15L, measlights.getArray(i).getLong(j));
50+
}
51+
}
52+
53+
TEST_METHOD(Altd)
54+
{
55+
// altd:[2,2,2,2]
56+
57+
JsonArray altd = root.getArray("altd");
58+
Assert::IsTrue(altd.success());
59+
60+
Assert::AreEqual(4, altd.getLength());
61+
62+
for (int i = 0; i < 4; i++)
63+
{
64+
Assert::AreEqual(2L, altd.getLong(i));
65+
}
66+
}
67+
};
68+
}

0 commit comments

Comments
 (0)