mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-15 19:42:12 +02:00
RawJson()
accepts any kind of string and obeys to duplication rules
This commit is contained in:
@ -84,7 +84,7 @@ TEST_CASE("JsonArray::add()") {
|
||||
REQUIRE(expectedSize == _jsonBuffer.size());
|
||||
}
|
||||
|
||||
SECTION("should duplicate char*") {
|
||||
SECTION("should duplicate char*") {
|
||||
_array.add(const_cast<char*>("world"));
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + 6;
|
||||
REQUIRE(expectedSize == _jsonBuffer.size());
|
||||
@ -95,4 +95,16 @@ TEST_CASE("JsonArray::add()") {
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + 6;
|
||||
REQUIRE(expectedSize == _jsonBuffer.size());
|
||||
}
|
||||
|
||||
SECTION("should not duplicate RawJson(const char*)") {
|
||||
_array.add(RawJson("{}"));
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1);
|
||||
REQUIRE(expectedSize == _jsonBuffer.size());
|
||||
}
|
||||
|
||||
SECTION("should duplicate RawJson(char*)") {
|
||||
_array.add(RawJson(const_cast<char*>("{}")));
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + 3;
|
||||
REQUIRE(expectedSize == _jsonBuffer.size());
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,10 @@
|
||||
static void check(JsonArray &array, std::string expected) {
|
||||
std::string actual;
|
||||
size_t actualLen = array.printTo(actual);
|
||||
size_t measuredLen = array.measureLength();
|
||||
CHECK(actualLen == expected.size());
|
||||
CHECK(measuredLen == expected.size());
|
||||
REQUIRE(expected == actual);
|
||||
REQUIRE(actualLen == expected.size());
|
||||
size_t measuredLen = array.measureLength();
|
||||
REQUIRE(measuredLen == expected.size());
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArray::printTo()") {
|
||||
@ -67,12 +67,22 @@ TEST_CASE("JsonArray::printTo()") {
|
||||
check(array, "[1,2]");
|
||||
}
|
||||
|
||||
SECTION("RawJson") {
|
||||
SECTION("RawJson(const char*)") {
|
||||
array.add(RawJson("{\"key\":\"value\"}"));
|
||||
|
||||
check(array, "[{\"key\":\"value\"}]");
|
||||
}
|
||||
|
||||
SECTION("RawJson(char*)") {
|
||||
DynamicJsonBuffer jb2;
|
||||
JsonArray &arr = jb2.createArray();
|
||||
|
||||
char tmp[] = "{\"key\":\"value\"}";
|
||||
arr.add(RawJson(tmp));
|
||||
|
||||
check(arr, "[{\"key\":\"value\"}]");
|
||||
}
|
||||
|
||||
SECTION("OneIntegerOverCapacity") {
|
||||
array.add(1);
|
||||
array.add(2);
|
||||
|
Reference in New Issue
Block a user