Initial commit of Arduino libraries

This commit is contained in:
Sam
2025-05-23 10:47:41 +10:00
commit 5bfce5fc3e
2476 changed files with 1108481 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
# ArduinoJson - https://arduinojson.org
# Copyright © 2014-2025, Benoit BLANCHON
# MIT License
add_executable(JsonObjectConstTests
equals.cpp
isNull.cpp
iterator.cpp
nesting.cpp
size.cpp
subscript.cpp
)
add_test(JsonObjectConst JsonObjectConstTests)
set_tests_properties(JsonObjectConst
PROPERTIES
LABELS "Catch"
)

View File

@@ -0,0 +1,65 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2025, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonObjectConst::operator==()") {
JsonDocument doc1;
JsonObjectConst obj1 = doc1.to<JsonObject>();
JsonDocument doc2;
JsonObjectConst obj2 = doc2.to<JsonObject>();
SECTION("should return false when objs differ") {
doc1["hello"] = "coucou";
doc2["world"] = 1;
REQUIRE_FALSE(obj1 == obj2);
}
SECTION("should return false when LHS has more elements") {
doc1["hello"] = "coucou";
doc1["world"] = 666;
doc2["hello"] = "coucou";
REQUIRE_FALSE(obj1 == obj2);
}
SECTION("should return false when RKS has more elements") {
doc1["hello"] = "coucou";
doc2["hello"] = "coucou";
doc2["world"] = 666;
REQUIRE_FALSE(obj1 == obj2);
}
SECTION("should return true when objs equal") {
doc1["hello"] = "world";
doc1["anwser"] = 42;
// insert in different order
doc2["anwser"] = 42;
doc2["hello"] = "world";
REQUIRE(obj1 == obj2);
}
SECTION("should return false when RHS is null") {
JsonObjectConst null;
REQUIRE_FALSE(obj1 == null);
}
SECTION("should return false when LHS is null") {
JsonObjectConst null;
REQUIRE_FALSE(null == obj2);
}
SECTION("should return true when both are null") {
JsonObjectConst null1, null2;
REQUIRE(null1 == null2);
}
}

View File

@@ -0,0 +1,32 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2025, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonObjectConst::isNull()") {
SECTION("returns true") {
JsonObjectConst obj;
REQUIRE(obj.isNull() == true);
}
SECTION("returns false") {
JsonDocument doc;
JsonObjectConst obj = doc.to<JsonObject>();
REQUIRE(obj.isNull() == false);
}
}
TEST_CASE("JsonObjectConst::operator bool()") {
SECTION("returns false") {
JsonObjectConst obj;
REQUIRE(static_cast<bool>(obj) == false);
}
SECTION("returns true") {
JsonDocument doc;
JsonObjectConst obj = doc.to<JsonObject>();
REQUIRE(static_cast<bool>(obj) == true);
}
}

View File

@@ -0,0 +1,39 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2025, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonObjectConst::begin()/end()") {
JsonDocument doc;
JsonObjectConst obj = doc.to<JsonObject>();
doc["ab"] = 12;
doc["cd"] = 34;
SECTION("Iteration") {
JsonObjectConst::iterator it = obj.begin();
REQUIRE(obj.end() != it);
REQUIRE(it->key() == "ab");
REQUIRE(12 == it->value());
++it;
REQUIRE(obj.end() != it);
JsonPairConst pair = *it;
REQUIRE(pair.key() == "cd");
REQUIRE(34 == pair.value());
++it;
REQUIRE(obj.end() == it);
}
SECTION("Dereferencing end() is safe") {
REQUIRE(obj.end()->key().isNull());
REQUIRE(obj.end()->value().isNull());
}
SECTION("null JsonObjectConst") {
JsonObjectConst null;
REQUIRE(null.begin() == null.end());
}
}

View File

@@ -0,0 +1,35 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2025, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonObjectConst::nesting()") {
JsonDocument doc;
JsonObjectConst obj = doc.to<JsonObject>();
SECTION("return 0 if unbound") {
JsonObjectConst unbound;
REQUIRE(unbound.nesting() == 0);
}
SECTION("returns 1 for empty object") {
REQUIRE(obj.nesting() == 1);
}
SECTION("returns 1 for flat object") {
doc["hello"] = "world";
REQUIRE(obj.nesting() == 1);
}
SECTION("returns 2 with nested array") {
doc["nested"].to<JsonArray>();
REQUIRE(obj.nesting() == 2);
}
SECTION("returns 2 with nested object") {
doc["nested"].to<JsonObject>();
REQUIRE(obj.nesting() == 2);
}
}

View File

@@ -0,0 +1,22 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2025, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
#include <string>
TEST_CASE("JsonObjectConst::size()") {
JsonDocument doc;
JsonObjectConst obj = doc.to<JsonObject>();
SECTION("returns 0 when empty") {
REQUIRE(0 == obj.size());
}
SECTION("returns the number of members") {
doc["hello"] = 1;
doc["world"] = 2;
REQUIRE(2 == obj.size());
}
}

View File

@@ -0,0 +1,46 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2025, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
#include "Allocators.hpp"
#include "Literals.hpp"
TEST_CASE("JsonObjectConst::operator[]") {
JsonDocument doc;
doc["hello"] = "world";
doc["a\0b"_s] = "ABC";
JsonObjectConst obj = doc.as<JsonObjectConst>();
SECTION("supports const char*") {
REQUIRE(obj["hello"] == "world"); // issue #2019
}
SECTION("supports std::string") {
REQUIRE(obj["hello"_s] == "world"); // issue #2019
REQUIRE(obj["a\0b"_s] == "ABC");
}
#if defined(HAS_VARIABLE_LENGTH_ARRAY) && \
!defined(SUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR)
SECTION("supports VLA") {
size_t i = 16;
char vla[i];
strcpy(vla, "hello");
REQUIRE(obj[vla] == "world"_s);
}
#endif
SECTION("supports JsonVariant") {
doc["key1"] = "hello";
doc["key2"] = "a\0b"_s;
doc["key3"] = "foo";
REQUIRE(obj[obj["key1"]] == "world");
REQUIRE(obj[obj["key2"]] == "ABC");
REQUIRE(obj[obj["key3"]] == nullptr);
REQUIRE(obj[obj["key4"]] == nullptr);
}
}