forked from bblanchon/ArduinoJson
36 lines
863 B
C++
36 lines
863 B
C++
![]() |
// 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]");
|
||
|
|
||
|
JsonError err = deserializeJson(doc, input);
|
||
|
|
||
|
REQUIRE(err == JsonError::Ok);
|
||
|
}
|
||
|
|
||
|
SECTION("should accept temporary string") {
|
||
|
JsonError err = deserializeJson(doc, std::string("[42]"));
|
||
|
|
||
|
REQUIRE(err == JsonError::Ok);
|
||
|
}
|
||
|
|
||
|
SECTION("should duplicate content") {
|
||
|
std::string input("[\"hello\"]");
|
||
|
|
||
|
JsonError err = deserializeJson(doc, input);
|
||
|
input[2] = 'X'; // alter the string tomake sure we made a copy
|
||
|
|
||
|
JsonArray &array = doc.as<JsonArray>();
|
||
|
REQUIRE(err == JsonError::Ok);
|
||
|
REQUIRE(std::string("hello") == array[0]);
|
||
|
}
|
||
|
}
|