2018-05-14 17:12:59 +02:00
|
|
|
// ArduinoJson - arduinojson.org
|
2019-02-15 13:31:46 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2019
|
2018-05-14 17:12:59 +02:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
TEST_CASE("serialize JsonArray to std::string") {
|
2019-01-14 10:32:19 +01:00
|
|
|
DynamicJsonDocument doc(4096);
|
2018-07-02 09:35:21 +02:00
|
|
|
JsonArray array = doc.to<JsonArray>();
|
2018-05-14 17:12:59 +02:00
|
|
|
array.add(4);
|
|
|
|
array.add(2);
|
|
|
|
|
|
|
|
SECTION("serializeJson()") {
|
|
|
|
std::string json;
|
|
|
|
serializeJson(array, json);
|
|
|
|
|
2018-05-29 08:31:17 +02:00
|
|
|
REQUIRE("[4,2]" == json);
|
2018-05-14 17:12:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("serializeJsonPretty") {
|
|
|
|
std::string json;
|
|
|
|
serializeJsonPretty(array, json);
|
|
|
|
|
2018-05-29 08:31:17 +02:00
|
|
|
REQUIRE("[\r\n 4,\r\n 2\r\n]" == json);
|
2018-05-14 17:12:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("serialize JsonObject to std::string") {
|
2019-01-14 10:32:19 +01:00
|
|
|
DynamicJsonDocument doc(4096);
|
2018-07-02 09:35:21 +02:00
|
|
|
JsonObject obj = doc.to<JsonObject>();
|
2018-05-14 17:12:59 +02:00
|
|
|
obj["key"] = "value";
|
|
|
|
|
|
|
|
SECTION("object") {
|
|
|
|
std::string json;
|
|
|
|
serializeJson(doc, json);
|
|
|
|
|
2018-05-29 08:31:17 +02:00
|
|
|
REQUIRE("{\"key\":\"value\"}" == json);
|
2018-05-14 17:12:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("serializeJsonPretty") {
|
|
|
|
std::string json;
|
|
|
|
serializeJsonPretty(doc, json);
|
|
|
|
|
2018-05-29 08:31:17 +02:00
|
|
|
REQUIRE("{\r\n \"key\": \"value\"\r\n}" == json);
|
2018-05-14 17:12:59 +02:00
|
|
|
}
|
|
|
|
}
|