| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- // ArduinoJson - arduinojson.org
- // Copyright Benoit Blanchon 2014-2018
- // MIT License
- #include <ArduinoJson.h>
- #include <catch.hpp>
- TEST_CASE("StaticJsonDocument") {
- SECTION("capacity()") {
- SECTION("matches template argument") {
- StaticJsonDocument<256> doc;
- REQUIRE(doc.capacity() == 256);
- }
- SECTION("rounds up template argument") {
- StaticJsonDocument<253> doc;
- REQUIRE(doc.capacity() == 256);
- }
- }
- SECTION("serializeJson()") {
- StaticJsonDocument<200> doc;
- JsonObject obj = doc.to<JsonObject>();
- obj["hello"] = "world";
- std::string json;
- serializeJson(doc, json);
- REQUIRE(json == "{\"hello\":\"world\"}");
- }
- SECTION("Copy assignment") {
- StaticJsonDocument<200> doc1, doc2;
- doc1.to<JsonVariant>().set(666);
- deserializeJson(doc2, "{\"hello\":\"world\"}");
- doc1 = doc2;
- std::string json;
- serializeJson(doc1, json);
- REQUIRE(json == "{\"hello\":\"world\"}");
- }
- SECTION("Copy constructor") {
- StaticJsonDocument<200> doc1;
- deserializeJson(doc1, "{\"hello\":\"world\"}");
- StaticJsonDocument<200> doc2 = doc1;
- std::string json;
- serializeJson(doc2, json);
- REQUIRE(json == "{\"hello\":\"world\"}");
- }
- SECTION("Assign from StaticJsonDocument of different capacity") {
- StaticJsonDocument<200> doc1;
- StaticJsonDocument<300> doc2;
- doc1.to<JsonVariant>().set(666);
- deserializeJson(doc2, "{\"hello\":\"world\"}");
- doc1 = doc2;
- std::string json;
- serializeJson(doc1, json);
- REQUIRE(json == "{\"hello\":\"world\"}");
- }
- SECTION("Assign from DynamicJsonDocument") {
- StaticJsonDocument<200> doc1;
- DynamicJsonDocument doc2(4096);
- doc1.to<JsonVariant>().set(666);
- deserializeJson(doc2, "{\"hello\":\"world\"}");
- doc1 = doc2;
- std::string json;
- serializeJson(doc1, json);
- REQUIRE(json == "{\"hello\":\"world\"}");
- }
- SECTION("Construct from StaticJsonDocument of different size") {
- StaticJsonDocument<300> doc2;
- deserializeJson(doc2, "{\"hello\":\"world\"}");
- StaticJsonDocument<200> doc1 = doc2;
- std::string json;
- serializeJson(doc1, json);
- REQUIRE(json == "{\"hello\":\"world\"}");
- }
- SECTION("Construct from DynamicJsonDocument") {
- DynamicJsonDocument doc2(4096);
- deserializeJson(doc2, "{\"hello\":\"world\"}");
- StaticJsonDocument<200> doc1 = doc2;
- std::string json;
- serializeJson(doc1, json);
- REQUIRE(json == "{\"hello\":\"world\"}");
- }
- }
|