Update ArduinoJSON
This commit is contained in:
@@ -5,37 +5,60 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
using ElementProxy = ArduinoJson::detail::ElementProxy<JsonDocument&>;
|
||||
|
||||
TEST_CASE("ElementProxy::add()") {
|
||||
JsonDocument doc;
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
doc.add<JsonVariant>();
|
||||
ElementProxy ep = doc[0];
|
||||
const ElementProxy& ep = doc[0];
|
||||
|
||||
SECTION("add(int)") {
|
||||
SECTION("integer") {
|
||||
ep.add(42);
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("add(const char*)") {
|
||||
SECTION("string literal") {
|
||||
ep.add("world");
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("add(char[])") {
|
||||
SECTION("const char*") {
|
||||
const char* s = "world";
|
||||
ep.add(s);
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("world")),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("char[]") {
|
||||
char s[] = "world";
|
||||
ep.add(s);
|
||||
strcpy(s, "!!!!!");
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("world")),
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("set(vla)") {
|
||||
SECTION("VLA") {
|
||||
size_t i = 8;
|
||||
char vla[i];
|
||||
strcpy(vla, "world");
|
||||
@@ -43,6 +66,10 @@ TEST_CASE("ElementProxy::add()") {
|
||||
ep.add(vla);
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("world")),
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -50,7 +77,7 @@ TEST_CASE("ElementProxy::add()") {
|
||||
TEST_CASE("ElementProxy::clear()") {
|
||||
JsonDocument doc;
|
||||
doc.add<JsonVariant>();
|
||||
ElementProxy ep = doc[0];
|
||||
const ElementProxy& ep = doc[0];
|
||||
|
||||
SECTION("size goes back to zero") {
|
||||
ep.add(42);
|
||||
@@ -110,7 +137,7 @@ TEST_CASE("ElementProxy::operator==()") {
|
||||
TEST_CASE("ElementProxy::remove()") {
|
||||
JsonDocument doc;
|
||||
doc.add<JsonVariant>();
|
||||
ElementProxy ep = doc[0];
|
||||
const ElementProxy& ep = doc[0];
|
||||
|
||||
SECTION("remove(int)") {
|
||||
ep.add(1);
|
||||
@@ -157,7 +184,7 @@ TEST_CASE("ElementProxy::remove()") {
|
||||
|
||||
TEST_CASE("ElementProxy::set()") {
|
||||
JsonDocument doc;
|
||||
ElementProxy ep = doc[0];
|
||||
const ElementProxy& ep = doc[0];
|
||||
|
||||
SECTION("set(int)") {
|
||||
ep.set(42);
|
||||
@@ -195,7 +222,7 @@ TEST_CASE("ElementProxy::set()") {
|
||||
TEST_CASE("ElementProxy::size()") {
|
||||
JsonDocument doc;
|
||||
doc.add<JsonVariant>();
|
||||
ElementProxy ep = doc[0];
|
||||
const ElementProxy& ep = doc[0];
|
||||
|
||||
SECTION("returns 0") {
|
||||
REQUIRE(ep.size() == 0);
|
||||
@@ -216,7 +243,7 @@ TEST_CASE("ElementProxy::size()") {
|
||||
|
||||
TEST_CASE("ElementProxy::operator[]") {
|
||||
JsonDocument doc;
|
||||
ElementProxy ep = doc[1];
|
||||
const ElementProxy& ep = doc[1];
|
||||
|
||||
SECTION("set member") {
|
||||
ep["world"] = 42;
|
||||
@@ -247,7 +274,7 @@ TEST_CASE("ElementProxy cast to JsonVariantConst") {
|
||||
JsonDocument doc;
|
||||
doc[0] = "world";
|
||||
|
||||
const ElementProxy ep = doc[0];
|
||||
const ElementProxy& ep = doc[0];
|
||||
|
||||
JsonVariantConst var = ep;
|
||||
|
||||
@@ -258,7 +285,7 @@ TEST_CASE("ElementProxy cast to JsonVariant") {
|
||||
JsonDocument doc;
|
||||
doc[0] = "world";
|
||||
|
||||
ElementProxy ep = doc[0];
|
||||
const ElementProxy& ep = doc[0];
|
||||
|
||||
JsonVariant var = ep;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user