From 1d583f68da00b3d1419a7a5e580dcd41acb74289 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Wed, 9 Aug 2023 18:58:30 +0200 Subject: [PATCH] Add stubs for `JSON_ARRAY_SIZE`, `JSON_OBJECT_SIZE`, and `JSON_STRING_SIZE` --- extras/tests/Deprecated/CMakeLists.txt | 3 ++- extras/tests/Deprecated/macros.cpp | 18 ++++++++++++++++++ src/ArduinoJson/compatibility.hpp | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 extras/tests/Deprecated/macros.cpp diff --git a/extras/tests/Deprecated/CMakeLists.txt b/extras/tests/Deprecated/CMakeLists.txt index dd86f047..03e3bece 100644 --- a/extras/tests/Deprecated/CMakeLists.txt +++ b/extras/tests/Deprecated/CMakeLists.txt @@ -4,7 +4,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") add_compile_options( - -Wno-deprecated-declarations + -w ) endif() @@ -20,6 +20,7 @@ add_executable(DeprecatedTests createNestedObject.cpp BasicJsonDocument.cpp DynamicJsonDocument.cpp + macros.cpp memoryUsage.cpp shallowCopy.cpp StaticJsonDocument.cpp diff --git a/extras/tests/Deprecated/macros.cpp b/extras/tests/Deprecated/macros.cpp new file mode 100644 index 00000000..9ddb4dfb --- /dev/null +++ b/extras/tests/Deprecated/macros.cpp @@ -0,0 +1,18 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2023, Benoit BLANCHON +// MIT License + +#include +#include + +TEST_CASE("JSON_ARRAY_SIZE") { + REQUIRE(JSON_ARRAY_SIZE(10) == ArduinoJson::detail::sizeofArray(10)); +} + +TEST_CASE("JSON_OBJECT_SIZE") { + REQUIRE(JSON_OBJECT_SIZE(10) == ArduinoJson::detail::sizeofObject(10)); +} + +TEST_CASE("JSON_STRING_SIZE") { + REQUIRE(JSON_STRING_SIZE(10) == ArduinoJson::detail::sizeofString(10)); +} diff --git a/src/ArduinoJson/compatibility.hpp b/src/ArduinoJson/compatibility.hpp index 5016f40f..d0dc103a 100644 --- a/src/ArduinoJson/compatibility.hpp +++ b/src/ArduinoJson/compatibility.hpp @@ -24,6 +24,26 @@ #define ARDUINOJSON_NAMESPACE _Pragma ("GCC warning \"ARDUINOJSON_NAMESPACE is deprecated, use ArduinoJson instead\"") ArduinoJson +// DEPRECATED: you don't need to compute the size anymore +#define JSON_ARRAY_SIZE(N) _Pragma ("GCC warning \"JSON_ARRAY_SIZE is deprecated, you don't need to compute the size anymore\"") (ArduinoJson::detail::sizeofArray(N)) + +// DEPRECATED: you don't need to compute the size anymore +#define JSON_OBJECT_SIZE(N) _Pragma ("GCC warning \"JSON_OBJECT_SIZE is deprecated, you don't need to compute the size anymore\"") (ArduinoJson::detail::sizeofObject(N)) + +// DEPRECATED: you don't need to compute the size anymore +#define JSON_STRING_SIZE(N) _Pragma ("GCC warning \"JSON_STRING_SIZE is deprecated, you don't need to compute the size anymore\"") (ArduinoJson::detail::sizeofString(N)) + +#else + +// DEPRECATED: you don't need to compute the size anymore +#define JSON_ARRAY_SIZE(N) (ArduinoJson::detail::sizeofArray(N)) + +// DEPRECATED: you don't need to compute the size anymore +#define JSON_OBJECT_SIZE(N) (ArduinoJson::detail::sizeofObject(N)) + +// DEPRECATED: you don't need to compute the size anymore +#define JSON_STRING_SIZE(N) (ArduinoJson::detail::sizeofString(N)) + #endif // clang-format on