2018-05-14 17:12:59 +02:00
|
|
|
// ArduinoJson - arduinojson.org
|
|
|
|
// Copyright Benoit Blanchon 2014-2018
|
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
TEST_CASE("deserializeJson(const std::string&)") {
|
|
|
|
DynamicJsonDocument doc;
|
|
|
|
|
|
|
|
SECTION("should accept const string") {
|
|
|
|
const std::string input("[42]");
|
|
|
|
|
2018-05-15 18:23:09 +02:00
|
|
|
DeserializationError err = deserializeJson(doc, input);
|
2018-05-14 17:12:59 +02:00
|
|
|
|
2018-05-15 18:23:09 +02:00
|
|
|
REQUIRE(err == DeserializationError::Ok);
|
2018-05-14 17:12:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("should accept temporary string") {
|
2018-05-15 18:23:09 +02:00
|
|
|
DeserializationError err = deserializeJson(doc, std::string("[42]"));
|
2018-05-14 17:12:59 +02:00
|
|
|
|
2018-05-15 18:23:09 +02:00
|
|
|
REQUIRE(err == DeserializationError::Ok);
|
2018-05-14 17:12:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("should duplicate content") {
|
|
|
|
std::string input("[\"hello\"]");
|
|
|
|
|
2018-05-15 18:23:09 +02:00
|
|
|
DeserializationError err = deserializeJson(doc, input);
|
2018-05-14 17:12:59 +02:00
|
|
|
input[2] = 'X'; // alter the string tomake sure we made a copy
|
|
|
|
|
2018-07-02 09:35:21 +02:00
|
|
|
JsonArray array = doc.as<JsonArray>();
|
2018-05-15 18:23:09 +02:00
|
|
|
REQUIRE(err == DeserializationError::Ok);
|
2018-05-14 17:12:59 +02:00
|
|
|
REQUIRE(std::string("hello") == array[0]);
|
|
|
|
}
|
|
|
|
}
|