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