2018-05-14 17:12:59 +02:00
|
|
|
// ArduinoJson - arduinojson.org
|
2021-01-25 09:14:15 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2021
|
2018-05-14 17:12:59 +02:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
static void eraseString(std::string &str) {
|
|
|
|
char *p = const_cast<char *>(str.c_str());
|
|
|
|
while (*p) *p++ = '*';
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("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
|
|
|
|
|
|
|
SECTION("add()") {
|
|
|
|
std::string value("hello");
|
|
|
|
array.add(value);
|
|
|
|
eraseString(value);
|
|
|
|
REQUIRE(std::string("hello") == array[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("operator[]") {
|
|
|
|
std::string value("world");
|
|
|
|
array.add("hello");
|
|
|
|
array[0] = value;
|
|
|
|
eraseString(value);
|
|
|
|
REQUIRE(std::string("world") == array[0]);
|
|
|
|
}
|
|
|
|
}
|