FoodDelivery/ArduinoJson/extras/tests/Misc/Utf16.cpp
tk b708b47c4b 【类 型】:fix
【主	题】:添加库文件
【描	述】:
	[原因]:
	[过程]:
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-06-14 17:16:36 +08:00

69 lines
1.5 KiB
C++

// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2022, Benoit BLANCHON
// 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);
}
}