
【主 题】:添加库文件 【描 述】: [原因]: [过程]: [影响]: 【结 束】 # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动
26 lines
710 B
C++
26 lines
710 B
C++
// ArduinoJson - https://arduinojson.org
|
|
// Copyright © 2014-2022, Benoit BLANCHON
|
|
// MIT License
|
|
|
|
#include <ArduinoJson.h>
|
|
#include <catch.hpp>
|
|
|
|
using namespace ARDUINOJSON_NAMESPACE;
|
|
|
|
template <typename T>
|
|
static void check(const char* input, T expected) {
|
|
T actual;
|
|
uint8_t* f = reinterpret_cast<uint8_t*>(&actual);
|
|
const uint8_t* d = reinterpret_cast<const uint8_t*>(input);
|
|
doubleToFloat(d, f);
|
|
fixEndianess(actual);
|
|
CHECK(actual == expected);
|
|
}
|
|
|
|
TEST_CASE("doubleToFloat()") {
|
|
check("\x40\x09\x21\xCA\xC0\x83\x12\x6F", 3.1415f);
|
|
check("\x00\x00\x00\x00\x00\x00\x00\x00", 0.0f);
|
|
check("\x80\x00\x00\x00\x00\x00\x00\x00", -0.0f);
|
|
check("\xC0\x5E\xDC\xCC\xCC\xCC\xCC\xCD", -123.45f);
|
|
}
|