forked from bblanchon/ArduinoJson
Fixed bug in JsonObject::begin() and end()
This commit is contained in:
@ -42,12 +42,12 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
JsonObjectIterator begin()
|
JsonObjectIterator begin()
|
||||||
{
|
{
|
||||||
return firstChild();
|
return isObject() ? firstChild() : null();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObjectIterator end()
|
JsonObjectIterator end()
|
||||||
{
|
{
|
||||||
return nextSibling();
|
return isObject() ? nextSibling() : null();
|
||||||
}
|
}
|
||||||
|
|
||||||
DEPRECATED JsonArray getArray(const char* key);
|
DEPRECATED JsonArray getArray(const char* key);
|
||||||
|
@ -7,26 +7,24 @@ using namespace ArduinoJson::Parser;
|
|||||||
|
|
||||||
namespace JsonParserTests
|
namespace JsonParserTests
|
||||||
{
|
{
|
||||||
TEST_CLASS(JsonObjectIteratorTests)
|
TEST_CLASS(JsonArrayIteratorTests)
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TEST_METHOD(ThreeStrings)
|
TEST_METHOD(ThreeIntegers)
|
||||||
{
|
{
|
||||||
char json [] = "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}";
|
char json [] = "[1,2,3]";
|
||||||
char* expectedKeys [] = { "key1", "key2", "key3" };
|
long expected [] = { 1, 2, 3 };
|
||||||
char* expectedValues [] = { "value1", "value2", "value3" };
|
JsonParser<4> parser;
|
||||||
JsonParser<7> parser;
|
|
||||||
|
|
||||||
JsonHashTable a = parser.parse(json);
|
JsonValue v = parser.parse(json);
|
||||||
|
JsonArray a = (ArduinoJson::Parser::JsonArray)v;
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
for (auto i : a)
|
for (long i : a)
|
||||||
{
|
{
|
||||||
Assert::AreEqual(expectedKeys[index], i.key());
|
Assert::AreEqual(expected[index++], i);
|
||||||
Assert::AreEqual(expectedValues[index], (const char*) i.value());
|
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,24 +7,60 @@ using namespace ArduinoJson::Parser;
|
|||||||
|
|
||||||
namespace JsonParserTests
|
namespace JsonParserTests
|
||||||
{
|
{
|
||||||
TEST_CLASS(JsonArrayIteratorTests)
|
TEST_CLASS(JsonObjectIteratorTests)
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TEST_METHOD(ThreeIntegers)
|
TEST_METHOD(EmptyObject)
|
||||||
{
|
{
|
||||||
char json [] = "[1,2,3]";
|
char json [] = "{}";
|
||||||
long expected [] = { 1, 2, 3 };
|
JsonParser<1> parser;
|
||||||
JsonParser<4> parser;
|
|
||||||
|
|
||||||
JsonValue v = parser.parse(json);
|
JsonHashTable a = parser.parse(json);
|
||||||
JsonArray a = (ArduinoJson::Parser::JsonArray)v;
|
|
||||||
|
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;
|
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++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,9 +91,9 @@
|
|||||||
<ClCompile Include="..\JsonParser\JsonParserBase.cpp" />
|
<ClCompile Include="..\JsonParser\JsonParserBase.cpp" />
|
||||||
<ClCompile Include="..\JsonParser\JsonToken.cpp" />
|
<ClCompile Include="..\JsonParser\JsonToken.cpp" />
|
||||||
<ClCompile Include="..\JsonParser\JsonValue.cpp" />
|
<ClCompile Include="..\JsonParser\JsonValue.cpp" />
|
||||||
<ClCompile Include="JsonArrayIteratorTests.cpp" />
|
|
||||||
<ClCompile Include="JsonArrayTests.cpp" />
|
|
||||||
<ClCompile Include="JsonObjectIteratorTests.cpp" />
|
<ClCompile Include="JsonObjectIteratorTests.cpp" />
|
||||||
|
<ClCompile Include="JsonArrayTests.cpp" />
|
||||||
|
<ClCompile Include="JsonArrayIteratorTests.cpp" />
|
||||||
<ClCompile Include="JsonObjectTests.cpp" />
|
<ClCompile Include="JsonObjectTests.cpp" />
|
||||||
<ClCompile Include="GbathreeBug.cpp" />
|
<ClCompile Include="GbathreeBug.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -33,9 +33,6 @@
|
|||||||
<ClCompile Include="..\JsonParser\JsonValue.cpp">
|
<ClCompile Include="..\JsonParser\JsonValue.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="JsonArrayIteratorTests.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\JsonParser\JsonToken.cpp">
|
<ClCompile Include="..\JsonParser\JsonToken.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -45,6 +42,9 @@
|
|||||||
<ClCompile Include="JsonObjectTests.cpp">
|
<ClCompile Include="JsonObjectTests.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="JsonArrayIteratorTests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="JsonObjectIteratorTests.cpp">
|
<ClCompile Include="JsonObjectIteratorTests.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
Reference in New Issue
Block a user