mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 04:52:22 +02:00
Changed JsonArray tests to show the issue
This commit is contained in:
@ -20,12 +20,17 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add(const Printable& nestedObject)
|
||||||
|
{
|
||||||
|
if (count < capacity)
|
||||||
|
items[count++] = nestedObject;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void add(T value)
|
void add(T value)
|
||||||
{
|
{
|
||||||
if (count >= capacity) return;
|
if (count < capacity)
|
||||||
|
items[count++] = value;
|
||||||
items[count++] = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int DIGITS>
|
template<int DIGITS>
|
||||||
|
@ -35,7 +35,7 @@ namespace ArduinoJson
|
|||||||
content.asLong = value;
|
content.asLong = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator=(Printable& value)
|
void operator=(const Printable& value)
|
||||||
{
|
{
|
||||||
printToImpl = &printPrintableTo;
|
printToImpl = &printPrintableTo;
|
||||||
content.asPrintable = &value;
|
content.asPrintable = &value;
|
||||||
@ -89,7 +89,7 @@ namespace ArduinoJson
|
|||||||
return content.asLong;
|
return content.asLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator Printable&()
|
operator const Printable&()
|
||||||
{
|
{
|
||||||
return *content.asPrintable;
|
return *content.asPrintable;
|
||||||
}
|
}
|
||||||
@ -109,11 +109,11 @@ namespace ArduinoJson
|
|||||||
private:
|
private:
|
||||||
union Content
|
union Content
|
||||||
{
|
{
|
||||||
bool asBool;
|
bool asBool;
|
||||||
double asDouble;
|
double asDouble;
|
||||||
long asLong;
|
long asLong;
|
||||||
Printable* asPrintable;
|
const Printable* asPrintable;
|
||||||
const char* asString;
|
const char* asString;
|
||||||
};
|
};
|
||||||
|
|
||||||
Content content;
|
Content content;
|
||||||
|
@ -124,13 +124,19 @@ namespace JsonGeneratorTests
|
|||||||
|
|
||||||
TEST_METHOD(OneEmptyNestedArray)
|
TEST_METHOD(OneEmptyNestedArray)
|
||||||
{
|
{
|
||||||
addNested(JsonArray<1>());
|
JsonArray<1> nestedArray;
|
||||||
|
|
||||||
|
arr.add(nestedArray);
|
||||||
|
|
||||||
outputMustBe("[[]]");
|
outputMustBe("[[]]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(OneEmptyNestedHash)
|
TEST_METHOD(OneEmptyNestedHash)
|
||||||
{
|
{
|
||||||
addNested(JsonHashTable<1>());
|
JsonObject<1> nestedObject;
|
||||||
|
|
||||||
|
arr.add(nestedObject);
|
||||||
|
|
||||||
outputMustBe("[{}]");
|
outputMustBe("[{}]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,18 +145,13 @@ namespace JsonGeneratorTests
|
|||||||
JsonArray<1> nestedArray;
|
JsonArray<1> nestedArray;
|
||||||
nestedArray.add(1);
|
nestedArray.add(1);
|
||||||
|
|
||||||
addNested(nestedArray);
|
arr.add(nestedArray);
|
||||||
|
|
||||||
outputMustBe("[[1]]");
|
outputMustBe("[[1]]");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void addNested(Printable& value)
|
|
||||||
{
|
|
||||||
arr.add<Printable&>(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void add(T value)
|
void add(T value)
|
||||||
{
|
{
|
||||||
|
@ -71,7 +71,7 @@ namespace JsonGeneratorTests
|
|||||||
void setValueAndCheckCast(JsonArray<N>& expected)
|
void setValueAndCheckCast(JsonArray<N>& expected)
|
||||||
{
|
{
|
||||||
value = expected;
|
value = expected;
|
||||||
Printable& actual = value;
|
const Printable& actual = value;
|
||||||
Assert::AreEqual((void*) &expected, (void*) &actual);
|
Assert::AreEqual((void*) &expected, (void*) &actual);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user