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