mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 12:32:17 +02:00
Added support for non zero-terminated strings (fixes #704)
This commit is contained in:
35
test/JsonDeserializer/std_string.cpp
Normal file
35
test/JsonDeserializer/std_string.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
// 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]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user