arduino/libraries/ArduinoJson/test/JsonObject/invalid.cpp

36 lines
732 B
C++
Raw Normal View History

2018-11-03 20:21:33 +00:00
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2018
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace Catch::Matchers;
TEST_CASE("JsonObject::invalid()") {
JsonObject obj;
SECTION("SubscriptFails") {
REQUIRE(obj["key"].isNull());
}
SECTION("AddFails") {
obj.set("hello", "world");
REQUIRE(0 == obj.size());
}
SECTION("CreateNestedArrayFails") {
REQUIRE(obj.createNestedArray("hello").isNull());
}
SECTION("CreateNestedObjectFails") {
REQUIRE(obj.createNestedObject("world").isNull());
}
SECTION("serialize to 'null'") {
char buffer[32];
serializeJson(obj, buffer, sizeof(buffer));
REQUIRE_THAT(buffer, Equals("null"));
}
}