mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
initial commit
This commit is contained in:
54
lib_standalone/ArduinoJson/extras/tests/Misc/CMakeLists.txt
Normal file
54
lib_standalone/ArduinoJson/extras/tests/Misc/CMakeLists.txt
Normal file
@@ -0,0 +1,54 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
add_executable(MiscTests
|
||||
conflicts.cpp
|
||||
FloatParts.cpp
|
||||
Readers.cpp
|
||||
StringAdapters.cpp
|
||||
StringWriter.cpp
|
||||
TypeTraits.cpp
|
||||
unsigned_char.cpp
|
||||
Utf8.cpp
|
||||
Utf16.cpp
|
||||
version.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MiscTests catch)
|
||||
set_target_properties(MiscTests PROPERTIES UNITY_BUILD OFF)
|
||||
|
||||
add_test(Misc MiscTests)
|
||||
|
||||
macro(build_should_fail target)
|
||||
set_target_properties(${target}
|
||||
PROPERTIES
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
EXCLUDE_FROM_DEFAULT_BUILD TRUE
|
||||
)
|
||||
add_test(
|
||||
NAME
|
||||
${target}
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} --build . --target ${target} --config $<CONFIGURATION>
|
||||
WORKING_DIRECTORY
|
||||
${CMAKE_BINARY_DIR}
|
||||
)
|
||||
set_tests_properties(${target}
|
||||
|
||||
|
||||
|
||||
PROPERTIES
|
||||
WILL_FAIL TRUE)
|
||||
endmacro()
|
||||
|
||||
|
||||
add_executable(Issue978
|
||||
Issue978.cpp
|
||||
)
|
||||
build_should_fail(Issue978)
|
||||
|
||||
add_executable(Issue1189
|
||||
Issue1189.cpp
|
||||
)
|
||||
build_should_fail(Issue1189)
|
||||
44
lib_standalone/ArduinoJson/extras/tests/Misc/FloatParts.cpp
Normal file
44
lib_standalone/ArduinoJson/extras/tests/Misc/FloatParts.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Numbers/FloatParts.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("FloatParts<double>") {
|
||||
SECTION("1.7976931348623157E+308") {
|
||||
FloatParts<double> parts(1.7976931348623157E+308);
|
||||
REQUIRE(parts.integral == 1);
|
||||
REQUIRE(parts.decimal == 797693135);
|
||||
REQUIRE(parts.decimalPlaces == 9);
|
||||
REQUIRE(parts.exponent == 308);
|
||||
}
|
||||
|
||||
SECTION("4.94065645841247e-324") {
|
||||
FloatParts<double> parts(4.94065645841247e-324);
|
||||
REQUIRE(parts.integral == 4);
|
||||
REQUIRE(parts.decimal == 940656458);
|
||||
REQUIRE(parts.decimalPlaces == 9);
|
||||
REQUIRE(parts.exponent == -324);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("FloatParts<float>") {
|
||||
SECTION("3.4E+38") {
|
||||
FloatParts<float> parts(3.4E+38f);
|
||||
REQUIRE(parts.integral == 3);
|
||||
REQUIRE(parts.decimal == 4);
|
||||
REQUIRE(parts.decimalPlaces == 1);
|
||||
REQUIRE(parts.exponent == 38);
|
||||
}
|
||||
|
||||
SECTION("1.17549435e−38") {
|
||||
FloatParts<float> parts(1.17549435e-38f);
|
||||
REQUIRE(parts.integral == 1);
|
||||
REQUIRE(parts.decimal == 175494);
|
||||
REQUIRE(parts.decimalPlaces == 6);
|
||||
REQUIRE(parts.exponent == -38);
|
||||
}
|
||||
}
|
||||
13
lib_standalone/ArduinoJson/extras/tests/Misc/Issue1189.cpp
Normal file
13
lib_standalone/ArduinoJson/extras/tests/Misc/Issue1189.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
// a function should not be able to get a JsonDocument by value
|
||||
void f(JsonDocument) {}
|
||||
|
||||
int main() {
|
||||
DynamicJsonDocument doc(1024);
|
||||
f(doc);
|
||||
}
|
||||
13
lib_standalone/ArduinoJson/extras/tests/Misc/Issue978.cpp
Normal file
13
lib_standalone/ArduinoJson/extras/tests/Misc/Issue978.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
struct Stream {};
|
||||
|
||||
int main() {
|
||||
Stream* stream = 0;
|
||||
DynamicJsonDocument doc(1024);
|
||||
deserializeJson(doc, stream);
|
||||
}
|
||||
225
lib_standalone/ArduinoJson/extras/tests/Misc/Readers.cpp
Normal file
225
lib_standalone/ArduinoJson/extras/tests/Misc/Readers.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1
|
||||
#include <ArduinoJson/Deserialization/Reader.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("Reader<std::istringstream>") {
|
||||
SECTION("read()") {
|
||||
std::istringstream src("\x01\xFF");
|
||||
Reader<std::istringstream> reader(src);
|
||||
|
||||
REQUIRE(reader.read() == 0x01);
|
||||
REQUIRE(reader.read() == 0xFF);
|
||||
REQUIRE(reader.read() == -1);
|
||||
}
|
||||
|
||||
SECTION("readBytes() all at once") {
|
||||
std::istringstream src("ABC");
|
||||
Reader<std::istringstream> reader(src);
|
||||
|
||||
char buffer[8] = "abcd";
|
||||
REQUIRE(reader.readBytes(buffer, 4) == 3);
|
||||
|
||||
REQUIRE(buffer[0] == 'A');
|
||||
REQUIRE(buffer[1] == 'B');
|
||||
REQUIRE(buffer[2] == 'C');
|
||||
REQUIRE(buffer[3] == 'd');
|
||||
}
|
||||
|
||||
SECTION("readBytes() in two parts") {
|
||||
std::istringstream src("ABCDEF");
|
||||
Reader<std::istringstream> reader(src);
|
||||
|
||||
char buffer[12] = "abcdefg";
|
||||
REQUIRE(reader.readBytes(buffer, 4) == 4);
|
||||
REQUIRE(reader.readBytes(buffer + 4, 4) == 2);
|
||||
|
||||
REQUIRE(buffer[0] == 'A');
|
||||
REQUIRE(buffer[1] == 'B');
|
||||
REQUIRE(buffer[2] == 'C');
|
||||
REQUIRE(buffer[3] == 'D');
|
||||
REQUIRE(buffer[4] == 'E');
|
||||
REQUIRE(buffer[5] == 'F');
|
||||
REQUIRE(buffer[6] == 'g');
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("BoundedReader<const char*>") {
|
||||
SECTION("read") {
|
||||
BoundedReader<const char*> reader("\x01\xFF", 2);
|
||||
REQUIRE(reader.read() == 0x01);
|
||||
REQUIRE(reader.read() == 0xFF);
|
||||
REQUIRE(reader.read() == -1);
|
||||
REQUIRE(reader.read() == -1);
|
||||
}
|
||||
|
||||
SECTION("readBytes() all at once") {
|
||||
BoundedReader<const char*> reader("ABCD", 3);
|
||||
|
||||
char buffer[8] = "abcd";
|
||||
REQUIRE(reader.readBytes(buffer, 4) == 3);
|
||||
|
||||
REQUIRE(buffer[0] == 'A');
|
||||
REQUIRE(buffer[1] == 'B');
|
||||
REQUIRE(buffer[2] == 'C');
|
||||
REQUIRE(buffer[3] == 'd');
|
||||
}
|
||||
|
||||
SECTION("readBytes() in two parts") {
|
||||
BoundedReader<const char*> reader("ABCDEF", 6);
|
||||
|
||||
char buffer[8] = "abcdefg";
|
||||
REQUIRE(reader.readBytes(buffer, 4) == 4);
|
||||
REQUIRE(reader.readBytes(buffer + 4, 4) == 2);
|
||||
|
||||
REQUIRE(buffer[0] == 'A');
|
||||
REQUIRE(buffer[1] == 'B');
|
||||
REQUIRE(buffer[2] == 'C');
|
||||
REQUIRE(buffer[3] == 'D');
|
||||
REQUIRE(buffer[4] == 'E');
|
||||
REQUIRE(buffer[5] == 'F');
|
||||
REQUIRE(buffer[6] == 'g');
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Reader<const char*>") {
|
||||
SECTION("read()") {
|
||||
Reader<const char*> reader("\x01\xFF\x00\x12");
|
||||
REQUIRE(reader.read() == 0x01);
|
||||
REQUIRE(reader.read() == 0xFF);
|
||||
REQUIRE(reader.read() == 0);
|
||||
REQUIRE(reader.read() == 0x12);
|
||||
}
|
||||
|
||||
SECTION("readBytes() all at once") {
|
||||
Reader<const char*> reader("ABCD");
|
||||
|
||||
char buffer[8] = "abcd";
|
||||
REQUIRE(reader.readBytes(buffer, 3) == 3);
|
||||
|
||||
REQUIRE(buffer[0] == 'A');
|
||||
REQUIRE(buffer[1] == 'B');
|
||||
REQUIRE(buffer[2] == 'C');
|
||||
REQUIRE(buffer[3] == 'd');
|
||||
}
|
||||
|
||||
SECTION("readBytes() in two parts") {
|
||||
Reader<const char*> reader("ABCDEF");
|
||||
|
||||
char buffer[8] = "abcdefg";
|
||||
REQUIRE(reader.readBytes(buffer, 4) == 4);
|
||||
REQUIRE(reader.readBytes(buffer + 4, 2) == 2);
|
||||
|
||||
REQUIRE(buffer[0] == 'A');
|
||||
REQUIRE(buffer[1] == 'B');
|
||||
REQUIRE(buffer[2] == 'C');
|
||||
REQUIRE(buffer[3] == 'D');
|
||||
REQUIRE(buffer[4] == 'E');
|
||||
REQUIRE(buffer[5] == 'F');
|
||||
REQUIRE(buffer[6] == 'g');
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("IteratorReader") {
|
||||
SECTION("read()") {
|
||||
std::string src("\x01\xFF");
|
||||
IteratorReader<std::string::const_iterator> reader(src.begin(), src.end());
|
||||
|
||||
REQUIRE(reader.read() == 0x01);
|
||||
REQUIRE(reader.read() == 0xFF);
|
||||
REQUIRE(reader.read() == -1);
|
||||
}
|
||||
|
||||
SECTION("readBytes() all at once") {
|
||||
std::string src("ABC");
|
||||
IteratorReader<std::string::const_iterator> reader(src.begin(), src.end());
|
||||
|
||||
char buffer[8] = "abcd";
|
||||
REQUIRE(reader.readBytes(buffer, 4) == 3);
|
||||
|
||||
REQUIRE(buffer[0] == 'A');
|
||||
REQUIRE(buffer[1] == 'B');
|
||||
REQUIRE(buffer[2] == 'C');
|
||||
REQUIRE(buffer[3] == 'd');
|
||||
}
|
||||
|
||||
SECTION("readBytes() in two parts") {
|
||||
std::string src("ABCDEF");
|
||||
IteratorReader<std::string::const_iterator> reader(src.begin(), src.end());
|
||||
|
||||
char buffer[12] = "abcdefg";
|
||||
REQUIRE(reader.readBytes(buffer, 4) == 4);
|
||||
REQUIRE(reader.readBytes(buffer + 4, 4) == 2);
|
||||
|
||||
REQUIRE(buffer[0] == 'A');
|
||||
REQUIRE(buffer[1] == 'B');
|
||||
REQUIRE(buffer[2] == 'C');
|
||||
REQUIRE(buffer[3] == 'D');
|
||||
REQUIRE(buffer[4] == 'E');
|
||||
REQUIRE(buffer[5] == 'F');
|
||||
REQUIRE(buffer[6] == 'g');
|
||||
}
|
||||
}
|
||||
|
||||
class StreamStub : public Stream {
|
||||
public:
|
||||
StreamStub(const char* s) : _stream(s) {}
|
||||
|
||||
int read() {
|
||||
return _stream.get();
|
||||
}
|
||||
|
||||
size_t readBytes(char* buffer, size_t length) {
|
||||
_stream.read(buffer, static_cast<std::streamsize>(length));
|
||||
return static_cast<size_t>(_stream.gcount());
|
||||
}
|
||||
|
||||
private:
|
||||
std::istringstream _stream;
|
||||
};
|
||||
|
||||
TEST_CASE("Reader<Stream>") {
|
||||
SECTION("read()") {
|
||||
StreamStub src("\x01\xFF");
|
||||
Reader<StreamStub> reader(src);
|
||||
|
||||
REQUIRE(reader.read() == 0x01);
|
||||
REQUIRE(reader.read() == 0xFF);
|
||||
REQUIRE(reader.read() == -1);
|
||||
}
|
||||
|
||||
SECTION("readBytes() all at once") {
|
||||
StreamStub src("ABC");
|
||||
Reader<StreamStub> reader(src);
|
||||
|
||||
char buffer[8] = "abcd";
|
||||
REQUIRE(reader.readBytes(buffer, 4) == 3);
|
||||
|
||||
REQUIRE(buffer[0] == 'A');
|
||||
REQUIRE(buffer[1] == 'B');
|
||||
REQUIRE(buffer[2] == 'C');
|
||||
REQUIRE(buffer[3] == 'd');
|
||||
}
|
||||
|
||||
SECTION("readBytes() in two parts") {
|
||||
StreamStub src("ABCDEF");
|
||||
Reader<StreamStub> reader(src);
|
||||
|
||||
char buffer[12] = "abcdefg";
|
||||
REQUIRE(reader.readBytes(buffer, 4) == 4);
|
||||
REQUIRE(reader.readBytes(buffer + 4, 4) == 2);
|
||||
|
||||
REQUIRE(buffer[0] == 'A');
|
||||
REQUIRE(buffer[1] == 'B');
|
||||
REQUIRE(buffer[2] == 'C');
|
||||
REQUIRE(buffer[3] == 'D');
|
||||
REQUIRE(buffer[4] == 'E');
|
||||
REQUIRE(buffer[5] == 'F');
|
||||
REQUIRE(buffer[6] == 'g');
|
||||
}
|
||||
}
|
||||
148
lib_standalone/ArduinoJson/extras/tests/Misc/StringAdapters.cpp
Normal file
148
lib_standalone/ArduinoJson/extras/tests/Misc/StringAdapters.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include "custom_string.hpp"
|
||||
#include "progmem_emulation.hpp"
|
||||
#include "weird_strcmp.hpp"
|
||||
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/FlashStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/SizedRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/StlStringAdapter.hpp>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("ConstRamStringAdapter") {
|
||||
SECTION("null") {
|
||||
ConstRamStringAdapter adapter(NULL);
|
||||
|
||||
CHECK(adapter.compare("bravo") < 0);
|
||||
CHECK(adapter.compare(NULL) == 0);
|
||||
|
||||
CHECK(adapter.equals(NULL));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
ConstRamStringAdapter adapter("bravo");
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SizedRamStringAdapter") {
|
||||
SECTION("null") {
|
||||
SizedRamStringAdapter adapter(NULL, 10);
|
||||
|
||||
CHECK(adapter.compare("bravo") < 0);
|
||||
CHECK(adapter.compare(NULL) == 0);
|
||||
|
||||
CHECK(adapter.equals(NULL));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 10);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
SizedRamStringAdapter adapter("bravo", 5);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("FlashStringAdapter") {
|
||||
SECTION("null") {
|
||||
FlashStringAdapter adapter(NULL);
|
||||
|
||||
CHECK(adapter.compare("bravo") < 0);
|
||||
CHECK(adapter.compare(NULL) == 0);
|
||||
|
||||
CHECK(adapter.equals(NULL));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
FlashStringAdapter adapter = adaptString(F("bravo"));
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("std::string") {
|
||||
std::string str("bravo");
|
||||
StlStringAdapter<std::string> adapter = adaptString(str);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("custom_string") {
|
||||
custom_string str("bravo");
|
||||
StlStringAdapter<custom_string> adapter = adaptString(str);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("IsString<T>") {
|
||||
SECTION("std::string") {
|
||||
CHECK(IsString<std::string>::value == true);
|
||||
}
|
||||
|
||||
SECTION("basic_string<wchar_t>") {
|
||||
CHECK(IsString<std::basic_string<wchar_t> >::value == false);
|
||||
}
|
||||
|
||||
SECTION("custom_string") {
|
||||
CHECK(IsString<custom_string>::value == true);
|
||||
}
|
||||
|
||||
SECTION("const __FlashStringHelper*") {
|
||||
CHECK(IsString<const __FlashStringHelper*>::value == true);
|
||||
}
|
||||
}
|
||||
118
lib_standalone/ArduinoJson/extras/tests/Misc/StringWriter.cpp
Normal file
118
lib_standalone/ArduinoJson/extras/tests/Misc/StringWriter.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
|
||||
#define ARDUINOJSON_STRING_BUFFER_SIZE 5
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
#include "custom_string.hpp"
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
template <typename StringWriter>
|
||||
static size_t print(StringWriter& sb, const char* s) {
|
||||
return sb.write(reinterpret_cast<const uint8_t*>(s), strlen(s));
|
||||
}
|
||||
|
||||
template <typename StringWriter, typename String>
|
||||
void common_tests(StringWriter& sb, const String& output) {
|
||||
SECTION("InitialState") {
|
||||
REQUIRE(std::string("") == output);
|
||||
}
|
||||
|
||||
SECTION("EmptyString") {
|
||||
REQUIRE(0 == print(sb, ""));
|
||||
REQUIRE(std::string("") == output);
|
||||
}
|
||||
|
||||
SECTION("OneString") {
|
||||
REQUIRE(4 == print(sb, "ABCD"));
|
||||
REQUIRE(std::string("ABCD") == output);
|
||||
}
|
||||
|
||||
SECTION("TwoStrings") {
|
||||
REQUIRE(4 == print(sb, "ABCD"));
|
||||
REQUIRE(4 == print(sb, "EFGH"));
|
||||
REQUIRE(std::string("ABCDEFGH") == output);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("StaticStringWriter") {
|
||||
char output[20];
|
||||
StaticStringWriter sb(output, sizeof(output));
|
||||
|
||||
common_tests(sb, static_cast<const char*>(output));
|
||||
|
||||
SECTION("OverCapacity") {
|
||||
REQUIRE(19 == print(sb, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
||||
REQUIRE(0 == print(sb, "ABC"));
|
||||
REQUIRE(std::string("ABCDEFGHIJKLMNOPQRS") == output);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Writer<std::string>") {
|
||||
std::string output;
|
||||
Writer<std::string> sb(output);
|
||||
common_tests(sb, output);
|
||||
}
|
||||
|
||||
TEST_CASE("Writer<String>") {
|
||||
::String output;
|
||||
Writer< ::String> sb(output);
|
||||
|
||||
common_tests(sb, output);
|
||||
|
||||
SECTION("Writes characters to temporary buffer") {
|
||||
// accumulate in buffer
|
||||
sb.write('a');
|
||||
sb.write('b');
|
||||
sb.write('c');
|
||||
REQUIRE(output == "");
|
||||
|
||||
// flush when full
|
||||
sb.write('d');
|
||||
REQUIRE(output == "abcd");
|
||||
|
||||
// flush on destruction
|
||||
sb.write('e');
|
||||
sb.~Writer();
|
||||
REQUIRE(output == "abcde");
|
||||
}
|
||||
|
||||
SECTION("Writes strings to temporary buffer") {
|
||||
// accumulate in buffer
|
||||
print(sb, "abc");
|
||||
REQUIRE(output == "");
|
||||
|
||||
// flush when full, and continue to accumulate
|
||||
print(sb, "de");
|
||||
REQUIRE(output == "abcd");
|
||||
|
||||
// flush on destruction
|
||||
sb.~Writer();
|
||||
REQUIRE(output == "abcde");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Writer<custom_string>") {
|
||||
custom_string output;
|
||||
Writer<custom_string> sb(output);
|
||||
|
||||
REQUIRE(4 == print(sb, "ABCD"));
|
||||
REQUIRE("ABCD" == output);
|
||||
}
|
||||
|
||||
TEST_CASE("IsWriteableString") {
|
||||
SECTION("std::string") {
|
||||
REQUIRE(IsWriteableString<std::string>::value == true);
|
||||
}
|
||||
|
||||
SECTION("custom_string") {
|
||||
REQUIRE(IsWriteableString<custom_string>::value == true);
|
||||
}
|
||||
|
||||
SECTION("basic_string<wchar_t>") {
|
||||
REQUIRE(IsWriteableString<std::basic_string<wchar_t> >::value == false);
|
||||
}
|
||||
}
|
||||
92
lib_standalone/ArduinoJson/extras/tests/Misc/TypeTraits.cpp
Normal file
92
lib_standalone/ArduinoJson/extras/tests/Misc/TypeTraits.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
class EmptyClass {};
|
||||
enum EmptyEnum {};
|
||||
|
||||
TEST_CASE("Polyfills/type_traits") {
|
||||
SECTION("is_base_of") {
|
||||
REQUIRE_FALSE(
|
||||
static_cast<bool>(is_base_of<std::istream, std::ostringstream>::value));
|
||||
REQUIRE(
|
||||
static_cast<bool>(is_base_of<std::istream, std::istringstream>::value));
|
||||
}
|
||||
|
||||
SECTION("is_array") {
|
||||
REQUIRE_FALSE((is_array<const char*>::value));
|
||||
REQUIRE((is_array<const char[]>::value));
|
||||
REQUIRE((is_array<const char[10]>::value));
|
||||
}
|
||||
|
||||
SECTION("is_const") {
|
||||
CHECK(is_const<char>::value == false);
|
||||
CHECK(is_const<const char>::value == true);
|
||||
}
|
||||
|
||||
SECTION("is_signed") {
|
||||
CHECK(is_signed<char>::value == true);
|
||||
CHECK(is_signed<signed char>::value == true);
|
||||
CHECK(is_signed<signed int>::value == true);
|
||||
CHECK(is_signed<signed short>::value == true);
|
||||
CHECK(is_signed<signed long>::value == true);
|
||||
CHECK(is_signed<float>::value == true);
|
||||
CHECK(is_signed<double>::value == true);
|
||||
CHECK(is_signed<bool>::value == false);
|
||||
}
|
||||
|
||||
SECTION("is_unsigned") {
|
||||
CHECK(is_unsigned<unsigned char>::value == true);
|
||||
CHECK(is_unsigned<unsigned int>::value == true);
|
||||
CHECK(is_unsigned<unsigned short>::value == true);
|
||||
CHECK(is_unsigned<unsigned long>::value == true);
|
||||
CHECK(is_unsigned<bool>::value == true);
|
||||
CHECK(is_unsigned<char>::value == false);
|
||||
CHECK(is_unsigned<float>::value == false);
|
||||
CHECK(is_unsigned<double>::value == false);
|
||||
}
|
||||
|
||||
SECTION("is_convertible") {
|
||||
CHECK((is_convertible<short, int>::value == true));
|
||||
CHECK((is_convertible<int, int>::value == true));
|
||||
CHECK((is_convertible<EmptyEnum, int>::value == true));
|
||||
CHECK((is_convertible<int*, int>::value == false));
|
||||
CHECK((is_convertible<EmptyClass, int>::value == false));
|
||||
}
|
||||
|
||||
SECTION("is_class") {
|
||||
CHECK((is_class<int>::value == false));
|
||||
CHECK((is_class<EmptyEnum>::value == false));
|
||||
CHECK((is_class<int*>::value == false));
|
||||
CHECK((is_class<EmptyClass>::value == true));
|
||||
}
|
||||
|
||||
SECTION("is_enum") {
|
||||
CHECK(is_enum<int>::value == false);
|
||||
CHECK(is_enum<EmptyEnum>::value == true);
|
||||
CHECK(is_enum<int*>::value == false);
|
||||
CHECK(is_enum<EmptyClass>::value == false);
|
||||
CHECK(is_enum<bool>::value == false);
|
||||
CHECK(is_enum<double>::value == false);
|
||||
}
|
||||
|
||||
SECTION("IsVisitable") {
|
||||
CHECK(IsVisitable<DeserializationError>::value == false);
|
||||
CHECK(IsVisitable<JsonPair>::value == false);
|
||||
CHECK(IsVisitable<VariantRef>::value == true);
|
||||
CHECK(IsVisitable<VariantConstRef>::value == true);
|
||||
CHECK(IsVisitable<ArrayRef>::value == true);
|
||||
CHECK(IsVisitable<ElementProxy<ArrayRef> >::value == true);
|
||||
CHECK(IsVisitable<ArrayConstRef>::value == true);
|
||||
CHECK(IsVisitable<ObjectRef>::value == true);
|
||||
CHECK((IsVisitable<MemberProxy<ObjectRef, const char*> >::value == true));
|
||||
CHECK(IsVisitable<ObjectConstRef>::value == true);
|
||||
CHECK(IsVisitable<DynamicJsonDocument>::value == true);
|
||||
CHECK(IsVisitable<StaticJsonDocument<10> >::value == true);
|
||||
}
|
||||
}
|
||||
68
lib_standalone/ArduinoJson/extras/tests/Misc/Utf16.cpp
Normal file
68
lib_standalone/ArduinoJson/extras/tests/Misc/Utf16.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Json/Utf16.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
static void testUtf16Codepoint(uint16_t codeunit, uint32_t expectedCodepoint) {
|
||||
Utf16::Codepoint cp;
|
||||
REQUIRE(cp.append(codeunit) == true);
|
||||
REQUIRE(cp.value() == expectedCodepoint);
|
||||
}
|
||||
|
||||
static void testUtf16Codepoint(uint16_t codeunit1, uint16_t codeunit2,
|
||||
uint32_t expectedCodepoint) {
|
||||
Utf16::Codepoint cp;
|
||||
REQUIRE(cp.append(codeunit1) == false);
|
||||
REQUIRE(cp.append(codeunit2) == true);
|
||||
REQUIRE(cp.value() == expectedCodepoint);
|
||||
}
|
||||
|
||||
TEST_CASE("Utf16::Codepoint()") {
|
||||
SECTION("U+0000") {
|
||||
testUtf16Codepoint(0x0000, 0x000000);
|
||||
}
|
||||
|
||||
SECTION("U+0001") {
|
||||
testUtf16Codepoint(0x0001, 0x000001);
|
||||
}
|
||||
|
||||
SECTION("U+D7FF") {
|
||||
testUtf16Codepoint(0xD7FF, 0x00D7FF);
|
||||
}
|
||||
|
||||
SECTION("U+E000") {
|
||||
testUtf16Codepoint(0xE000, 0x00E000);
|
||||
}
|
||||
|
||||
SECTION("U+FFFF") {
|
||||
testUtf16Codepoint(0xFFFF, 0x00FFFF);
|
||||
}
|
||||
|
||||
SECTION("U+010000") {
|
||||
testUtf16Codepoint(0xD800, 0xDC00, 0x010000);
|
||||
}
|
||||
|
||||
SECTION("U+010001") {
|
||||
testUtf16Codepoint(0xD800, 0xDC01, 0x010001);
|
||||
}
|
||||
|
||||
SECTION("U+0103FF") {
|
||||
testUtf16Codepoint(0xD800, 0xDFFF, 0x0103FF);
|
||||
}
|
||||
|
||||
SECTION("U+010400") {
|
||||
testUtf16Codepoint(0xD801, 0xDC00, 0x010400);
|
||||
}
|
||||
|
||||
SECTION("U+010400") {
|
||||
testUtf16Codepoint(0xDBFF, 0xDC00, 0x10FC00);
|
||||
}
|
||||
|
||||
SECTION("U+10FFFF") {
|
||||
testUtf16Codepoint(0xDBFF, 0xDFFF, 0x10FFFF);
|
||||
}
|
||||
}
|
||||
59
lib_standalone/ArduinoJson/extras/tests/Misc/Utf8.cpp
Normal file
59
lib_standalone/ArduinoJson/extras/tests/Misc/Utf8.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
static void testCodepoint(uint32_t codepoint, std::string expected) {
|
||||
char buffer[4096];
|
||||
MemoryPool pool(buffer, 4096);
|
||||
StringBuilder str(&pool);
|
||||
|
||||
CAPTURE(codepoint);
|
||||
Utf8::encodeCodepoint(codepoint, str);
|
||||
|
||||
REQUIRE(str.complete() == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("Utf8::encodeCodepoint()") {
|
||||
SECTION("U+0000") {
|
||||
testCodepoint(0x0000, "");
|
||||
}
|
||||
|
||||
SECTION("U+0001") {
|
||||
testCodepoint(0x0001, "\x01");
|
||||
}
|
||||
|
||||
SECTION("U+007F") {
|
||||
testCodepoint(0x007F, "\x7f");
|
||||
}
|
||||
|
||||
SECTION("U+0080") {
|
||||
testCodepoint(0x0080, "\xc2\x80");
|
||||
}
|
||||
|
||||
SECTION("U+07FF") {
|
||||
testCodepoint(0x07FF, "\xdf\xbf");
|
||||
}
|
||||
|
||||
SECTION("U+0800") {
|
||||
testCodepoint(0x0800, "\xe0\xa0\x80");
|
||||
}
|
||||
|
||||
SECTION("U+FFFF") {
|
||||
testCodepoint(0xFFFF, "\xef\xbf\xbf");
|
||||
}
|
||||
|
||||
SECTION("U+10000") {
|
||||
testCodepoint(0x10000, "\xf0\x90\x80\x80");
|
||||
}
|
||||
|
||||
SECTION("U+10FFFF") {
|
||||
testCodepoint(0x10FFFF, "\xf4\x8f\xbf\xbf");
|
||||
}
|
||||
}
|
||||
47
lib_standalone/ArduinoJson/extras/tests/Misc/conflicts.cpp
Normal file
47
lib_standalone/ArduinoJson/extras/tests/Misc/conflicts.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
// Include any header that might use the conflicting macros
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
// All cores
|
||||
#define bit()
|
||||
#define constrain()
|
||||
#define DEFAULT
|
||||
#define DISABLED
|
||||
#define HIGH
|
||||
#define INPUT
|
||||
#define LOW
|
||||
#define max()
|
||||
#define min()
|
||||
#define OUTPUT
|
||||
#define round()
|
||||
#define sq()
|
||||
#define word()
|
||||
#define bitRead()
|
||||
#define bitSet()
|
||||
#define bitClear()
|
||||
#define bitWrite()
|
||||
#define interrupts()
|
||||
#define lowByte()
|
||||
#define highByte()
|
||||
#define DEC
|
||||
#define HEX
|
||||
#define OCT
|
||||
#define BIN
|
||||
#define cbi()
|
||||
#define sbi()
|
||||
|
||||
// ESP8266
|
||||
#define _max()
|
||||
#define _min()
|
||||
|
||||
// issue #839
|
||||
#define BLOCKSIZE
|
||||
#define CAPACITY
|
||||
|
||||
// catch.hpp mutes several warnings, this file also allows to detect them
|
||||
#include "ArduinoJson.h"
|
||||
@@ -0,0 +1,12 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
struct custom_char_traits : std::char_traits<char> {};
|
||||
struct custom_allocator : std::allocator<char> {};
|
||||
typedef std::basic_string<char, custom_char_traits, custom_allocator>
|
||||
custom_string;
|
||||
271
lib_standalone/ArduinoJson/extras/tests/Misc/unsigned_char.cpp
Normal file
271
lib_standalone/ArduinoJson/extras/tests/Misc/unsigned_char.cpp
Normal file
@@ -0,0 +1,271 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#if defined(__clang__)
|
||||
#define CONFLICTS_WITH_BUILTIN_OPERATOR
|
||||
#endif
|
||||
|
||||
TEST_CASE("unsigned char[]") {
|
||||
SECTION("deserializeJson()") {
|
||||
unsigned char input[] = "{\"a\":42}";
|
||||
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(1)> doc;
|
||||
DeserializationError err = deserializeJson(doc, input);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
}
|
||||
|
||||
SECTION("deserializeMsgPack()") {
|
||||
unsigned char input[] = "\xDE\x00\x01\xA5Hello\xA5world";
|
||||
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(2)> doc;
|
||||
DeserializationError err = deserializeMsgPack(doc, input);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
}
|
||||
|
||||
SECTION("serializeMsgPack(unsigned char[])") {
|
||||
unsigned char buffer[32];
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(2)> doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeMsgPack(doc, buffer);
|
||||
|
||||
REQUIRE(n == 13);
|
||||
REQUIRE(memcmp(buffer, "\x81\xA5hello\xA5world", 13) == 0);
|
||||
}
|
||||
|
||||
SECTION("serializeMsgPack(unsigned char*)") {
|
||||
unsigned char buffer[32];
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(2)> doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeMsgPack(doc, buffer, sizeof(buffer));
|
||||
|
||||
REQUIRE(n == 13);
|
||||
REQUIRE(memcmp(buffer, "\x81\xA5hello\xA5world", 13) == 0);
|
||||
}
|
||||
|
||||
SECTION("serializeJson(unsigned char[])") {
|
||||
unsigned char buffer[32];
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(2)> doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeJson(doc, buffer);
|
||||
|
||||
REQUIRE(n == 17);
|
||||
REQUIRE(memcmp(buffer, "{\"hello\":\"world\"}", n) == 0);
|
||||
}
|
||||
|
||||
SECTION("serializeJson(unsigned char*)") {
|
||||
unsigned char buffer[32];
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(2)> doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeJson(doc, buffer, sizeof(buffer));
|
||||
|
||||
REQUIRE(n == 17);
|
||||
REQUIRE(memcmp(buffer, "{\"hello\":\"world\"}", n) == 0);
|
||||
}
|
||||
|
||||
SECTION("serializeJsonPretty(unsigned char[])") {
|
||||
unsigned char buffer[32];
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(2)> doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeJsonPretty(doc, buffer);
|
||||
|
||||
REQUIRE(n == 24);
|
||||
}
|
||||
|
||||
SECTION("serializeJsonPretty(unsigned char*)") {
|
||||
unsigned char buffer[32];
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(2)> doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeJsonPretty(doc, buffer, sizeof(buffer));
|
||||
|
||||
REQUIRE(n == 24);
|
||||
}
|
||||
|
||||
SECTION("JsonVariant") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
|
||||
SECTION("set") {
|
||||
unsigned char value[] = "42";
|
||||
|
||||
JsonVariant variant = doc.to<JsonVariant>();
|
||||
variant.set(value);
|
||||
|
||||
REQUIRE(42 == variant.as<int>());
|
||||
}
|
||||
|
||||
#ifndef CONFLICTS_WITH_BUILTIN_OPERATOR
|
||||
SECTION("operator[]") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
JsonVariant variant = doc.as<JsonVariant>();
|
||||
|
||||
REQUIRE(std::string("world") == variant[key]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFLICTS_WITH_BUILTIN_OPERATOR
|
||||
SECTION("operator[] const") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
const JsonVariant variant = doc.as<JsonVariant>();
|
||||
|
||||
REQUIRE(std::string("world") == variant[key]);
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("operator==") {
|
||||
unsigned char comparand[] = "hello";
|
||||
|
||||
JsonVariant variant = doc.to<JsonVariant>();
|
||||
variant.set("hello");
|
||||
|
||||
REQUIRE(comparand == variant);
|
||||
REQUIRE(variant == comparand);
|
||||
REQUIRE_FALSE(comparand != variant);
|
||||
REQUIRE_FALSE(variant != comparand);
|
||||
}
|
||||
|
||||
SECTION("operator!=") {
|
||||
unsigned char comparand[] = "hello";
|
||||
|
||||
JsonVariant variant = doc.to<JsonVariant>();
|
||||
variant.set("world");
|
||||
|
||||
REQUIRE(comparand != variant);
|
||||
REQUIRE(variant != comparand);
|
||||
REQUIRE_FALSE(comparand == variant);
|
||||
REQUIRE_FALSE(variant == comparand);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("JsonObject") {
|
||||
#ifndef CONFLICTS_WITH_BUILTIN_OPERATOR
|
||||
SECTION("operator[]") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj[key] = "world";
|
||||
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("JsonObject::operator[] const") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
REQUIRE(std::string("world") == obj[key]);
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("containsKey()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
REQUIRE(true == obj.containsKey(key));
|
||||
}
|
||||
|
||||
SECTION("remove()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
obj.remove(key);
|
||||
|
||||
REQUIRE(0 == obj.size());
|
||||
}
|
||||
|
||||
SECTION("createNestedArray()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj.createNestedArray(key);
|
||||
}
|
||||
|
||||
SECTION("createNestedObject()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj.createNestedObject(key);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("MemberProxy") {
|
||||
SECTION("operator=") { // issue #416
|
||||
unsigned char value[] = "world";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj["hello"] = value;
|
||||
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("set()") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj["hello"].set(value);
|
||||
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("JsonArray") {
|
||||
SECTION("add()") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
arr.add(value);
|
||||
|
||||
REQUIRE(std::string("world") == arr[0]);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("ElementProxy") {
|
||||
SECTION("set()") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
arr.add("hello");
|
||||
arr[0].set(value);
|
||||
|
||||
REQUIRE(std::string("world") == arr[0]);
|
||||
}
|
||||
|
||||
SECTION("operator=") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
arr.add("hello");
|
||||
arr[0] = value;
|
||||
|
||||
REQUIRE(std::string("world") == arr[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
lib_standalone/ArduinoJson/extras/tests/Misc/version.cpp
Normal file
18
lib_standalone/ArduinoJson/extras/tests/Misc/version.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/version.hpp>
|
||||
#include <catch.hpp>
|
||||
#include <sstream>
|
||||
|
||||
using Catch::Matchers::StartsWith;
|
||||
|
||||
TEST_CASE("ARDUINOJSON_VERSION") {
|
||||
std::stringstream version;
|
||||
|
||||
version << ARDUINOJSON_VERSION_MAJOR << "." << ARDUINOJSON_VERSION_MINOR
|
||||
<< "." << ARDUINOJSON_VERSION_REVISION;
|
||||
|
||||
REQUIRE_THAT(ARDUINOJSON_VERSION, StartsWith(version.str()));
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
|
||||
// Issue #1198: strcmp() implementation that returns a value larger than 8-bit
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
int strcmp(const char* a, const char* b) {
|
||||
int result = ::strcmp(a, b);
|
||||
if (result > 0)
|
||||
return 2147483647;
|
||||
if (result < 0)
|
||||
return -214748364;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int strncmp(const char* a, const char* b, size_t n) {
|
||||
int result = ::strncmp(a, b, n);
|
||||
if (result > 0)
|
||||
return 2147483647;
|
||||
if (result < 0)
|
||||
return -214748364;
|
||||
return 0;
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
Reference in New Issue
Block a user