forked from bblanchon/ArduinoJson
Added unit tests for all members of the gbathree JSON string
This commit is contained in:
@ -18,6 +18,8 @@ namespace ArduinoJsonParserTests
|
|||||||
|
|
||||||
TEST_METHOD_INITIALIZE(Initialize)
|
TEST_METHOD_INITIALIZE(Initialize)
|
||||||
{
|
{
|
||||||
|
// BUG described here:
|
||||||
|
// http://forum.arduino.cc/index.php?topic=172578.msg1608219#msg1608219
|
||||||
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]}");
|
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);
|
root = parser.parseHashTable(json);
|
||||||
}
|
}
|
||||||
@ -33,20 +35,188 @@ namespace ArduinoJsonParserTests
|
|||||||
Assert::AreEqual(string("fluorescence"), protocol_name);
|
Assert::AreEqual(string("fluorescence"), protocol_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(Measlights)
|
TEST_METHOD(Repeats)
|
||||||
{
|
{
|
||||||
// measlights:[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
|
Assert::AreEqual(1L, root.getLong("repeats"));
|
||||||
|
}
|
||||||
|
|
||||||
JsonArray measlights = root.getArray("altd");
|
TEST_METHOD(Wait)
|
||||||
Assert::IsTrue(measlights.success());
|
{
|
||||||
Assert::AreEqual(4, measlights.getLength());
|
Assert::AreEqual(0L, root.getLong("wait"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Measurements)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(3L, root.getLong("measurements"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Meas2_Light)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(15L, root.getLong("meas2_light"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Meas1_Baseline)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(0L, root.getLong("meas1_baseline"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Act_Light)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(20L, root.getLong("act_light"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Pulsesize)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(25L, root.getLong("pulsesize"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Pulsedistance)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(10000L, root.getLong("pulsedistance"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Actintensity1)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(50L, root.getLong("actintensity1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Actintensity2)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(255L, root.getLong("actintensity2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Measintensity)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(255L, root.getLong("measintensity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Calintensity)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(255L, root.getLong("calintensity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Pulses)
|
||||||
|
{
|
||||||
|
// "pulses":[50,50,50]
|
||||||
|
|
||||||
|
JsonArray array = root.getArray("pulses");
|
||||||
|
Assert::IsTrue(array.success());
|
||||||
|
|
||||||
|
Assert::AreEqual(3, array.getLength());
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(50L, array.getLong(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Act)
|
||||||
|
{
|
||||||
|
// "act":[2,1,2,2]
|
||||||
|
|
||||||
|
JsonArray array = root.getArray("act");
|
||||||
|
Assert::IsTrue(array.success());
|
||||||
|
|
||||||
|
Assert::AreEqual(4, array.getLength());
|
||||||
|
Assert::AreEqual(2L, array.getLong(0));
|
||||||
|
Assert::AreEqual(1L, array.getLong(1));
|
||||||
|
Assert::AreEqual(2L, array.getLong(2));
|
||||||
|
Assert::AreEqual(2L, array.getLong(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Detectors)
|
||||||
|
{
|
||||||
|
// "detectors":[[34,34,34,34],[34,34,34,34],[34,34,34,34],[34,34,34,34]]
|
||||||
|
|
||||||
|
JsonArray array = root.getArray("detectors");
|
||||||
|
Assert::IsTrue(array.success());
|
||||||
|
Assert::AreEqual(4, array.getLength());
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
Assert::AreEqual(4, measlights.getArray(i).getLength());
|
Assert::AreEqual(4, array.getArray(i).getLength());
|
||||||
|
|
||||||
for (int j = 0; j < 4; j++)
|
for (int j = 0; j < 4; j++)
|
||||||
Assert::AreEqual(15L, measlights.getArray(i).getLong(j));
|
Assert::AreEqual(34L, array.getArray(i).getLong(j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Alta)
|
||||||
|
{
|
||||||
|
// alta:[2,2,2,2]
|
||||||
|
|
||||||
|
JsonArray array = root.getArray("alta");
|
||||||
|
Assert::IsTrue(array.success());
|
||||||
|
|
||||||
|
Assert::AreEqual(4, array.getLength());
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(2L, array.getLong(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Altb)
|
||||||
|
{
|
||||||
|
// altb:[2,2,2,2]
|
||||||
|
|
||||||
|
JsonArray array = root.getArray("altb");
|
||||||
|
Assert::IsTrue(array.success());
|
||||||
|
|
||||||
|
Assert::AreEqual(4, array.getLength());
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(2L, array.getLong(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Measlights)
|
||||||
|
{
|
||||||
|
// "measlights":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
|
||||||
|
|
||||||
|
JsonArray array = root.getArray("measlights");
|
||||||
|
Assert::IsTrue(array.success());
|
||||||
|
Assert::AreEqual(4, array.getLength());
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(4, array.getArray(i).getLength());
|
||||||
|
|
||||||
|
for (int j = 0; j < 4; j++)
|
||||||
|
Assert::AreEqual(15L, array.getArray(i).getLong(j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Measlights2)
|
||||||
|
{
|
||||||
|
// "measlights2":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
|
||||||
|
|
||||||
|
JsonArray array = root.getArray("measlights2");
|
||||||
|
Assert::IsTrue(array.success());
|
||||||
|
Assert::AreEqual(4, array.getLength());
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(4, array.getArray(i).getLength());
|
||||||
|
|
||||||
|
for (int j = 0; j < 4; j++)
|
||||||
|
Assert::AreEqual(15L, array.getArray(i).getLong(j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(Altc)
|
||||||
|
{
|
||||||
|
// altc:[2,2,2,2]
|
||||||
|
|
||||||
|
JsonArray array = root.getArray("altc");
|
||||||
|
Assert::IsTrue(array.success());
|
||||||
|
|
||||||
|
Assert::AreEqual(4, array.getLength());
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(2L, array.getLong(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,14 +224,14 @@ namespace ArduinoJsonParserTests
|
|||||||
{
|
{
|
||||||
// altd:[2,2,2,2]
|
// altd:[2,2,2,2]
|
||||||
|
|
||||||
JsonArray altd = root.getArray("altd");
|
JsonArray array = root.getArray("altd");
|
||||||
Assert::IsTrue(altd.success());
|
Assert::IsTrue(array.success());
|
||||||
|
|
||||||
Assert::AreEqual(4, altd.getLength());
|
Assert::AreEqual(4, array.getLength());
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
Assert::AreEqual(2L, altd.getLong(i));
|
Assert::AreEqual(2L, array.getLong(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user