Fixed bug in JsonObject::begin() and end()

This commit is contained in:
Benoit Blanchon
2014-07-19 14:49:59 +02:00
parent e94575b4b8
commit 0fe77176e1
5 changed files with 73 additions and 39 deletions

View File

@ -7,26 +7,62 @@ using namespace ArduinoJson::Parser;
namespace JsonParserTests
{
TEST_CLASS(JsonArrayIteratorTests)
{
public:
TEST_METHOD(ThreeIntegers)
{
char json [] = "[1,2,3]";
long expected [] = { 1, 2, 3 };
JsonParser<4> parser;
TEST_CLASS(JsonObjectIteratorTests)
{
public:
JsonValue v = parser.parse(json);
JsonArray a = (ArduinoJson::Parser::JsonArray)v;
TEST_METHOD(EmptyObject)
{
char json [] = "{}";
JsonParser<1> parser;
JsonHashTable a = parser.parse(json);
int loopCount = 0;
for (auto i : a)
{
loopCount++;
}
Assert::AreEqual(0, loopCount);
}
TEST_METHOD(EmptyJson)
{
char json[] = "";
JsonParser<1> parser;
JsonHashTable a = parser.parse(json);
int loopCount = 0;
for (auto i : a)
{
loopCount++;
}
Assert::AreEqual(0, loopCount);
}
TEST_METHOD(ThreeStrings)
{
char json[] = "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}";
char* expectedKeys[] = { "key1", "key2", "key3" };
char* expectedValues[] = { "value1", "value2", "value3" };
JsonParser<7> parser;
JsonHashTable a = parser.parse(json);
int index = 0;
for (long i : a)
for (auto i : a)
{
Assert::AreEqual(expected[index++], i);
Assert::AreEqual(expectedKeys[index], i.key());
Assert::AreEqual(expectedValues[index], (const char*) i.value());
index++;
}
}
}
};
};
}