
【主 题】:添加库文件 【描 述】: [原因]: [过程]: [影响]: 【结 束】 # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动
40 lines
889 B
C++
40 lines
889 B
C++
#define ARDUINOJSON_ENABLE_INFINITY 1
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <catch.hpp>
|
|
#include <limits>
|
|
|
|
namespace my {
|
|
using ARDUINOJSON_NAMESPACE::isinf;
|
|
} // namespace my
|
|
|
|
TEST_CASE("ARDUINOJSON_ENABLE_INFINITY == 1") {
|
|
DynamicJsonDocument doc(4096);
|
|
|
|
SECTION("serializeJson()") {
|
|
doc.add(std::numeric_limits<double>::infinity());
|
|
doc.add(-std::numeric_limits<double>::infinity());
|
|
|
|
std::string json;
|
|
serializeJson(doc, json);
|
|
|
|
REQUIRE(json == "[Infinity,-Infinity]");
|
|
}
|
|
|
|
SECTION("deserializeJson()") {
|
|
DeserializationError err =
|
|
deserializeJson(doc, "[Infinity,-Infinity,+Infinity]");
|
|
float a = doc[0];
|
|
float b = doc[1];
|
|
float c = doc[2];
|
|
|
|
REQUIRE(err == DeserializationError::Ok);
|
|
REQUIRE(my::isinf(a));
|
|
REQUIRE(a > 0);
|
|
REQUIRE(my::isinf(b));
|
|
REQUIRE(b < 0);
|
|
REQUIRE(my::isinf(c));
|
|
REQUIRE(c > 0);
|
|
}
|
|
}
|