Update ArduinoJSON, esp-nimble-cpp, Arduino Core, ESP-IDF (#448)
* ArduinoJSON 7.1.0 * Update nimble and arduino core * Update nuki_ble
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
#include <stdint.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("JsonVariant::add(T)") {
|
||||
JsonDocument doc;
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
@@ -23,7 +26,7 @@ TEST_CASE("JsonVariant::add(T)") {
|
||||
}
|
||||
|
||||
SECTION("add std::string to new variant") {
|
||||
var.add(std::string("hello"));
|
||||
var.add("hello"_s);
|
||||
|
||||
REQUIRE(var.as<std::string>() == "[\"hello\"]");
|
||||
}
|
||||
@@ -56,15 +59,58 @@ TEST_CASE("JsonVariant::add<T>()") {
|
||||
REQUIRE(doc.as<std::string>() == "[[1,2]]");
|
||||
}
|
||||
|
||||
SECTION("JsonObject") {
|
||||
JsonObject object = var.add<JsonObject>();
|
||||
object["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "[{\"hello\":\"world\"}]");
|
||||
}
|
||||
|
||||
SECTION("JsonVariant") {
|
||||
JsonVariant variant = var.add<JsonVariant>();
|
||||
variant.set(42);
|
||||
REQUIRE(doc.as<std::string>() == "[42]");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObject::add(JsonObject) ") {
|
||||
JsonDocument doc1;
|
||||
doc1["hello"_s] = "world"_s;
|
||||
|
||||
TimebombAllocator allocator(10);
|
||||
SpyingAllocator spy(&allocator);
|
||||
JsonDocument doc2(&spy);
|
||||
JsonVariant variant = doc2.to<JsonVariant>();
|
||||
|
||||
SECTION("success") {
|
||||
bool result = variant.add(doc1.as<JsonObject>());
|
||||
|
||||
REQUIRE(result == true);
|
||||
REQUIRE(doc2.as<std::string>() == "[{\"hello\":\"world\"}]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("hello")),
|
||||
Allocate(sizeofString("world")),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("partial failure") { // issue #2081
|
||||
allocator.setCountdown(2);
|
||||
|
||||
bool result = variant.add(doc1.as<JsonObject>());
|
||||
|
||||
REQUIRE(result == false);
|
||||
REQUIRE(doc2.as<std::string>() == "[]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("hello")),
|
||||
AllocateFail(sizeofString("world")),
|
||||
Deallocate(sizeofString("hello")),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("complete failure") {
|
||||
allocator.setCountdown(0);
|
||||
|
||||
bool result = variant.add(doc1.as<JsonObject>());
|
||||
|
||||
REQUIRE(result == false);
|
||||
REQUIRE(doc2.as<std::string>() == "[]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
AllocateFail(sizeofPool()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <stdint.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Literals.hpp"
|
||||
|
||||
namespace my {
|
||||
using ArduinoJson::detail::isinf;
|
||||
} // namespace my
|
||||
@@ -25,6 +27,8 @@ TEST_CASE("JsonVariant::as()") {
|
||||
REQUIRE(0 == variant.as<const char*>());
|
||||
REQUIRE("null" == variant.as<std::string>());
|
||||
REQUIRE(variant.as<JsonString>().isNull());
|
||||
REQUIRE(variant.as<MsgPackBinary>().data() == nullptr);
|
||||
REQUIRE(variant.as<MsgPackExtension>().data() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("set(4.2)") {
|
||||
@@ -36,6 +40,8 @@ TEST_CASE("JsonVariant::as()") {
|
||||
REQUIRE(variant.as<long>() == 4L);
|
||||
REQUIRE(variant.as<unsigned>() == 4U);
|
||||
REQUIRE(variant.as<JsonString>().isNull());
|
||||
REQUIRE(variant.as<MsgPackBinary>().data() == nullptr);
|
||||
REQUIRE(variant.as<MsgPackExtension>().data() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("set(0.0)") {
|
||||
@@ -44,6 +50,8 @@ TEST_CASE("JsonVariant::as()") {
|
||||
REQUIRE(variant.as<bool>() == false);
|
||||
REQUIRE(variant.as<long>() == 0L);
|
||||
REQUIRE(variant.as<JsonString>().isNull());
|
||||
REQUIRE(variant.as<MsgPackBinary>().data() == nullptr);
|
||||
REQUIRE(variant.as<MsgPackExtension>().data() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("set(false)") {
|
||||
@@ -54,6 +62,8 @@ TEST_CASE("JsonVariant::as()") {
|
||||
REQUIRE(variant.as<long>() == 0L);
|
||||
REQUIRE(variant.as<std::string>() == "false");
|
||||
REQUIRE(variant.as<JsonString>().isNull());
|
||||
REQUIRE(variant.as<MsgPackBinary>().data() == nullptr);
|
||||
REQUIRE(variant.as<MsgPackExtension>().data() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("set(true)") {
|
||||
@@ -64,6 +74,8 @@ TEST_CASE("JsonVariant::as()") {
|
||||
REQUIRE(variant.as<long>() == 1L);
|
||||
REQUIRE(variant.as<std::string>() == "true");
|
||||
REQUIRE(variant.as<JsonString>().isNull());
|
||||
REQUIRE(variant.as<MsgPackBinary>().data() == nullptr);
|
||||
REQUIRE(variant.as<MsgPackExtension>().data() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("set(42)") {
|
||||
@@ -75,6 +87,8 @@ TEST_CASE("JsonVariant::as()") {
|
||||
REQUIRE(variant.as<unsigned int>() == 42U); // issue #1601
|
||||
REQUIRE(variant.as<std::string>() == "42");
|
||||
REQUIRE(variant.as<JsonString>().isNull());
|
||||
REQUIRE(variant.as<MsgPackBinary>().data() == nullptr);
|
||||
REQUIRE(variant.as<MsgPackExtension>().data() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("set(42L)") {
|
||||
@@ -144,20 +158,20 @@ TEST_CASE("JsonVariant::as()") {
|
||||
|
||||
REQUIRE(variant.as<bool>() == true);
|
||||
REQUIRE(variant.as<long>() == 0L);
|
||||
REQUIRE(variant.as<const char*>() == std::string("hello"));
|
||||
REQUIRE(variant.as<const char*>() == std::string("hello"));
|
||||
REQUIRE(variant.as<std::string>() == std::string("hello"));
|
||||
REQUIRE(variant.as<const char*>() == "hello"_s);
|
||||
REQUIRE(variant.as<const char*>() == "hello"_s);
|
||||
REQUIRE(variant.as<std::string>() == "hello"_s);
|
||||
REQUIRE(variant.as<JsonString>() == "hello");
|
||||
}
|
||||
|
||||
SECTION("set(std::string(\"4.2\"))") {
|
||||
variant.set(std::string("4.2"));
|
||||
variant.set("4.2"_s);
|
||||
|
||||
REQUIRE(variant.as<bool>() == true);
|
||||
REQUIRE(variant.as<long>() == 4L);
|
||||
REQUIRE(variant.as<double>() == 4.2);
|
||||
REQUIRE(variant.as<const char*>() == std::string("4.2"));
|
||||
REQUIRE(variant.as<std::string>() == std::string("4.2"));
|
||||
REQUIRE(variant.as<const char*>() == "4.2"_s);
|
||||
REQUIRE(variant.as<std::string>() == "4.2"_s);
|
||||
REQUIRE(variant.as<JsonString>() == "4.2");
|
||||
REQUIRE(variant.as<JsonString>().isLinked() == false);
|
||||
}
|
||||
@@ -199,6 +213,13 @@ TEST_CASE("JsonVariant::as()") {
|
||||
REQUIRE(variant.as<JsonString>().isNull());
|
||||
}
|
||||
|
||||
SECTION("set(serialized(\"hello\"))") {
|
||||
variant.set(serialized("hello"));
|
||||
|
||||
REQUIRE(variant.as<MsgPackBinary>().data() == nullptr);
|
||||
REQUIRE(variant.as<MsgPackExtension>().data() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("to<JsonObject>()") {
|
||||
JsonObject obj = variant.to<JsonObject>();
|
||||
obj["key"] = "value";
|
||||
@@ -208,13 +229,13 @@ TEST_CASE("JsonVariant::as()") {
|
||||
}
|
||||
|
||||
SECTION("as<std::string>()") {
|
||||
REQUIRE(variant.as<std::string>() == std::string("{\"key\":\"value\"}"));
|
||||
REQUIRE(variant.as<std::string>() == "{\"key\":\"value\"}"_s);
|
||||
}
|
||||
|
||||
SECTION("ObjectAsJsonObject") {
|
||||
JsonObject o = variant.as<JsonObject>();
|
||||
REQUIRE(o.size() == 1);
|
||||
REQUIRE(o["key"] == std::string("value"));
|
||||
REQUIRE(o["key"] == "value"_s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +249,7 @@ TEST_CASE("JsonVariant::as()") {
|
||||
}
|
||||
|
||||
SECTION("as<std::string>()") {
|
||||
REQUIRE(variant.as<std::string>() == std::string("[4,2]"));
|
||||
REQUIRE(variant.as<std::string>() == "[4,2]"_s);
|
||||
}
|
||||
|
||||
SECTION("as<JsonArray>()") {
|
||||
@@ -245,7 +266,7 @@ TEST_CASE("JsonVariant::as()") {
|
||||
REQUIRE(variant.as<long long>() == -9223372036854775807 - 1);
|
||||
}
|
||||
|
||||
SECTION("Biggerst int64 positive") {
|
||||
SECTION("Biggest int64 positive") {
|
||||
variant.set("9223372036854775807");
|
||||
REQUIRE(variant.as<long long>() == 9223372036854775807);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("JsonVariant::clear()") {
|
||||
SpyingAllocator spy;
|
||||
@@ -28,7 +29,7 @@ TEST_CASE("JsonVariant::clear()") {
|
||||
}
|
||||
|
||||
SECTION("releases owned string") {
|
||||
var.set(std::string("hello"));
|
||||
var.set("hello"_s);
|
||||
var.clear();
|
||||
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
|
||||
@@ -113,6 +113,42 @@ TEST_CASE("Compare JsonVariant with JsonVariant") {
|
||||
CHECK_FALSE(a == b);
|
||||
}
|
||||
|
||||
SECTION("MsgPackBinary('abc') vs MsgPackBinary('abc')") {
|
||||
a.set(MsgPackBinary("abc", 4));
|
||||
b.set(MsgPackBinary("abc", 4));
|
||||
|
||||
CHECK(a == b);
|
||||
CHECK(a <= b);
|
||||
CHECK(a >= b);
|
||||
CHECK_FALSE(a != b);
|
||||
CHECK_FALSE(a < b);
|
||||
CHECK_FALSE(a > b);
|
||||
}
|
||||
|
||||
SECTION("MsgPackBinary('abc') vs MsgPackBinary('bcd')") {
|
||||
a.set(MsgPackBinary("abc", 4));
|
||||
b.set(MsgPackBinary("bcd", 4));
|
||||
|
||||
CHECK(a != b);
|
||||
CHECK(a < b);
|
||||
CHECK(a <= b);
|
||||
CHECK_FALSE(a == b);
|
||||
CHECK_FALSE(a > b);
|
||||
CHECK_FALSE(a >= b);
|
||||
}
|
||||
|
||||
SECTION("MsgPackBinary('bcd') vs MsgPackBinary('abc')") {
|
||||
a.set(MsgPackBinary("bcd", 4));
|
||||
b.set(MsgPackBinary("abc", 4));
|
||||
|
||||
CHECK(a != b);
|
||||
CHECK(a > b);
|
||||
CHECK(a >= b);
|
||||
CHECK_FALSE(a < b);
|
||||
CHECK_FALSE(a <= b);
|
||||
CHECK_FALSE(a == b);
|
||||
}
|
||||
|
||||
SECTION("false vs true") {
|
||||
a.set(false);
|
||||
b.set(true);
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <stdint.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("JsonVariant::containsKey()") {
|
||||
JsonDocument doc;
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
@@ -20,7 +22,15 @@ TEST_CASE("JsonVariant::containsKey()") {
|
||||
SECTION("containsKey(std::string)") {
|
||||
var["hello"] = "world";
|
||||
|
||||
REQUIRE(var.containsKey(std::string("hello")) == true);
|
||||
REQUIRE(var.containsKey(std::string("world")) == false);
|
||||
REQUIRE(var.containsKey("hello"_s) == true);
|
||||
REQUIRE(var.containsKey("world"_s) == false);
|
||||
}
|
||||
|
||||
SECTION("containsKey(JsonVariant)") {
|
||||
var["hello"] = "world";
|
||||
var["key"] = "hello";
|
||||
|
||||
REQUIRE(var.containsKey(doc["key"]) == true);
|
||||
REQUIRE(var.containsKey(doc["foo"]) == false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,15 +140,3 @@ TEST_CASE("Custom converter with specialization") {
|
||||
REQUIRE(doc["value"]["imag"] == 3);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ConverterNeedsWriteableRef") {
|
||||
using namespace ArduinoJson::detail;
|
||||
CHECK(ConverterNeedsWriteableRef<int>::value == false);
|
||||
CHECK(ConverterNeedsWriteableRef<float>::value == false);
|
||||
CHECK(ConverterNeedsWriteableRef<JsonVariant>::value == true);
|
||||
CHECK(ConverterNeedsWriteableRef<JsonVariantConst>::value == false);
|
||||
CHECK(ConverterNeedsWriteableRef<JsonObject>::value == true);
|
||||
CHECK(ConverterNeedsWriteableRef<JsonObjectConst>::value == false);
|
||||
CHECK(ConverterNeedsWriteableRef<JsonArray>::value == true);
|
||||
CHECK(ConverterNeedsWriteableRef<JsonArrayConst>::value == false);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <catch.hpp>
|
||||
#include "Allocators.hpp"
|
||||
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("JsonVariant::set(JsonVariant)") {
|
||||
KillswitchAllocator killswitch;
|
||||
SpyingAllocator spyingAllocator(&killswitch);
|
||||
@@ -72,7 +74,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") {
|
||||
}
|
||||
|
||||
SECTION("stores std::string by copy") {
|
||||
var1.set(std::string("hello!!"));
|
||||
var1.set("hello!!"_s);
|
||||
spyingAllocator.clearLog();
|
||||
|
||||
var2.set(var1);
|
||||
@@ -106,7 +108,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") {
|
||||
}
|
||||
|
||||
SECTION("stores Serialized<std::string> by copy") {
|
||||
var1.set(serialized(std::string("hello!!")));
|
||||
var1.set(serialized("hello!!"_s));
|
||||
spyingAllocator.clearLog();
|
||||
|
||||
var2.set(var1);
|
||||
@@ -117,7 +119,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") {
|
||||
}
|
||||
|
||||
SECTION("fails gracefully if raw string allocation fails") {
|
||||
var1.set(serialized(std::string("hello!!")));
|
||||
var1.set(serialized("hello!!"_s));
|
||||
killswitch.on();
|
||||
spyingAllocator.clearLog();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
using ArduinoJson::detail::sizeofArray;
|
||||
|
||||
@@ -15,9 +16,9 @@ TEST_CASE("JsonVariant::remove(int)") {
|
||||
JsonDocument doc(&spy);
|
||||
|
||||
SECTION("release top level strings") {
|
||||
doc.add(std::string("hello"));
|
||||
doc.add(std::string("hello"));
|
||||
doc.add(std::string("world"));
|
||||
doc.add("hello"_s);
|
||||
doc.add("hello"_s);
|
||||
doc.add("world"_s);
|
||||
|
||||
JsonVariant var = doc.as<JsonVariant>();
|
||||
REQUIRE(var.as<std::string>() == "[\"hello\",\"hello\",\"world\"]");
|
||||
@@ -43,7 +44,7 @@ TEST_CASE("JsonVariant::remove(int)") {
|
||||
}
|
||||
|
||||
SECTION("release strings in nested array") {
|
||||
doc[0][0] = std::string("hello");
|
||||
doc[0][0] = "hello"_s;
|
||||
|
||||
JsonVariant var = doc.as<JsonVariant>();
|
||||
REQUIRE(var.as<std::string>() == "[[\"hello\"]]");
|
||||
@@ -77,7 +78,34 @@ TEST_CASE("JsonVariant::remove(std::string)") {
|
||||
var["a"] = 1;
|
||||
var["b"] = 2;
|
||||
|
||||
var.remove(std::string("b"));
|
||||
var.remove("b"_s);
|
||||
|
||||
REQUIRE(var.as<std::string>() == "{\"a\":1}");
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant::remove(JsonVariant) from object") {
|
||||
JsonDocument doc;
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
|
||||
var["a"] = "a";
|
||||
var["b"] = 2;
|
||||
var["c"] = "b";
|
||||
|
||||
var.remove(var["c"]);
|
||||
|
||||
REQUIRE(var.as<std::string>() == "{\"a\":\"a\",\"c\":\"b\"}");
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant::remove(JsonVariant) from array") {
|
||||
JsonDocument doc;
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
|
||||
var[0] = 3;
|
||||
var[1] = 2;
|
||||
var[2] = 1;
|
||||
|
||||
var.remove(var[2]);
|
||||
var.remove(var[3]); // noop
|
||||
|
||||
REQUIRE(var.as<std::string>() == "[3,1]");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
using ArduinoJson::detail::sizeofObject;
|
||||
|
||||
@@ -137,14 +138,14 @@ TEST_CASE("JsonVariant::set() with not enough memory") {
|
||||
JsonVariant v = doc.to<JsonVariant>();
|
||||
|
||||
SECTION("std::string") {
|
||||
bool result = v.set(std::string("hello world!!"));
|
||||
bool result = v.set("hello world!!"_s);
|
||||
|
||||
REQUIRE(result == false);
|
||||
REQUIRE(v.isNull());
|
||||
}
|
||||
|
||||
SECTION("Serialized<std::string>") {
|
||||
bool result = v.set(serialized(std::string("hello world!!")));
|
||||
bool result = v.set(serialized("hello world!!"_s));
|
||||
|
||||
REQUIRE(result == false);
|
||||
REQUIRE(v.isNull());
|
||||
@@ -178,7 +179,7 @@ TEST_CASE("JsonVariant::set(JsonDocument)") {
|
||||
TEST_CASE("JsonVariant::set() releases the previous value") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
doc["hello"] = std::string("world");
|
||||
doc["hello"] = "world"_s;
|
||||
spy.clearLog();
|
||||
|
||||
JsonVariant v = doc["hello"];
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("JsonVariant::operator[]") {
|
||||
JsonDocument doc;
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
@@ -31,9 +33,9 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
|
||||
REQUIRE(2 == var.size());
|
||||
var[0].as<std::string>();
|
||||
// REQUIRE(std::string("element at index 0") == );
|
||||
REQUIRE(std::string("element at index 1") == var[1]);
|
||||
REQUIRE(std::string("element at index 0") ==
|
||||
// REQUIRE("element at index 0"_s == );
|
||||
REQUIRE("element at index 1"_s == var[1]);
|
||||
REQUIRE("element at index 0"_s ==
|
||||
var[static_cast<unsigned char>(0)]); // issue #381
|
||||
REQUIRE(var[666].isNull());
|
||||
REQUIRE(var[3].isNull());
|
||||
@@ -46,7 +48,7 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
var[1] = "world";
|
||||
|
||||
REQUIRE(var.size() == 2);
|
||||
REQUIRE(std::string("world") == var[1]);
|
||||
REQUIRE("world"_s == var[1]);
|
||||
}
|
||||
|
||||
SECTION("set value in a nested object") {
|
||||
@@ -56,7 +58,7 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
|
||||
REQUIRE(1 == var.size());
|
||||
REQUIRE(1 == var[0].size());
|
||||
REQUIRE(std::string("world") == var[0]["hello"]);
|
||||
REQUIRE("world"_s == var[0]["hello"]);
|
||||
}
|
||||
|
||||
SECTION("variant[0] when variant contains an integer") {
|
||||
@@ -67,6 +69,15 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
REQUIRE(var.is<int>());
|
||||
REQUIRE(var.as<int>() == 123);
|
||||
}
|
||||
|
||||
SECTION("use JsonVariant as index") {
|
||||
array.add("A");
|
||||
array.add("B");
|
||||
array.add(1);
|
||||
|
||||
REQUIRE(var[var[2]] == "B");
|
||||
REQUIRE(var[var[3]].isNull());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("The JsonVariant is a JsonObject") {
|
||||
@@ -77,8 +88,8 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
object["b"] = "element at key \"b\"";
|
||||
|
||||
REQUIRE(2 == var.size());
|
||||
REQUIRE(std::string("element at key \"a\"") == var["a"]);
|
||||
REQUIRE(std::string("element at key \"b\"") == var["b"]);
|
||||
REQUIRE("element at key \"a\""_s == var["a"]);
|
||||
REQUIRE("element at key \"b\""_s == var["b"]);
|
||||
REQUIRE(var["c"].isNull());
|
||||
REQUIRE(var[0].isNull());
|
||||
}
|
||||
@@ -87,7 +98,7 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
var["hello"] = "world";
|
||||
|
||||
REQUIRE(1 == var.size());
|
||||
REQUIRE(std::string("world") == var["hello"]);
|
||||
REQUIRE("world"_s == var["hello"]);
|
||||
}
|
||||
|
||||
SECTION("set value, key is a char[]") {
|
||||
@@ -96,13 +107,22 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
key[0] = '!'; // make sure the key is duplicated
|
||||
|
||||
REQUIRE(1 == var.size());
|
||||
REQUIRE(std::string("world") == var["hello"]);
|
||||
REQUIRE("world"_s == var["hello"]);
|
||||
}
|
||||
|
||||
SECTION("var[key].to<JsonArray>()") {
|
||||
JsonArray arr = var["hello"].to<JsonArray>();
|
||||
REQUIRE(arr.isNull() == false);
|
||||
}
|
||||
|
||||
SECTION("use JsonVariant as key") {
|
||||
object["a"] = "a";
|
||||
object["b"] = "b";
|
||||
object["c"] = "b";
|
||||
|
||||
REQUIRE(var[var["c"]] == "b");
|
||||
REQUIRE(var[var["d"]].isNull());
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HAS_VARIABLE_LENGTH_ARRAY) && \
|
||||
@@ -115,7 +135,7 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
JsonVariant variant = doc.as<JsonVariant>();
|
||||
|
||||
REQUIRE(std::string("world") == variant[vla]);
|
||||
REQUIRE("world"_s == variant[vla]);
|
||||
}
|
||||
|
||||
SECTION("key is a VLA, const JsonVariant") {
|
||||
@@ -126,7 +146,7 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
const JsonVariant variant = doc.as<JsonVariant>();
|
||||
|
||||
REQUIRE(std::string("world") == variant[vla]);
|
||||
REQUIRE("world"_s == variant[vla]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("Unbound JsonVariant") {
|
||||
JsonVariant variant;
|
||||
|
||||
@@ -21,6 +23,10 @@ TEST_CASE("Unbound JsonVariant") {
|
||||
CHECK(variant.as<JsonObject>().isNull());
|
||||
CHECK(variant.as<JsonObjectConst>().isNull());
|
||||
CHECK(variant.as<JsonString>().isNull());
|
||||
CHECK(variant.as<MsgPackBinary>().data() == nullptr);
|
||||
CHECK(variant.as<MsgPackBinary>().size() == 0);
|
||||
CHECK(variant.as<MsgPackExtension>().data() == nullptr);
|
||||
CHECK(variant.as<MsgPackExtension>().size() == 0);
|
||||
}
|
||||
|
||||
SECTION("is<T>()") {
|
||||
@@ -44,8 +50,10 @@ TEST_CASE("Unbound JsonVariant") {
|
||||
CHECK_FALSE(variant.set(42L));
|
||||
CHECK_FALSE(variant.set(42U));
|
||||
CHECK_FALSE(variant.set(serialized("42")));
|
||||
CHECK_FALSE(variant.set(serialized(std::string("42"))));
|
||||
CHECK_FALSE(variant.set(serialized("42"_s)));
|
||||
CHECK_FALSE(variant.set(true));
|
||||
CHECK_FALSE(variant.set(MsgPackBinary("hello", 5)));
|
||||
CHECK_FALSE(variant.set(MsgPackExtension(1, "hello", 5)));
|
||||
}
|
||||
|
||||
SECTION("add()") {
|
||||
@@ -62,7 +70,7 @@ TEST_CASE("Unbound JsonVariant") {
|
||||
CHECK(variant["key"].isNull());
|
||||
CHECK_FALSE(variant[0].set(1));
|
||||
CHECK_FALSE(variant["key"].set(1));
|
||||
CHECK_FALSE(variant[std::string("key")].set(1));
|
||||
CHECK_FALSE(variant["key"_s].set(1));
|
||||
}
|
||||
|
||||
SECTION("containsKey()") {
|
||||
|
||||
Reference in New Issue
Block a user