Utf16.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2021
  3. // MIT License
  4. #include <ArduinoJson/Json/Utf16.hpp>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. static void testUtf16Codepoint(uint16_t codeunit, uint32_t expectedCodepoint) {
  8. Utf16::Codepoint cp;
  9. REQUIRE(cp.append(codeunit) == true);
  10. REQUIRE(cp.value() == expectedCodepoint);
  11. }
  12. static void testUtf16Codepoint(uint16_t codeunit1, uint16_t codeunit2,
  13. uint32_t expectedCodepoint) {
  14. Utf16::Codepoint cp;
  15. REQUIRE(cp.append(codeunit1) == false);
  16. REQUIRE(cp.append(codeunit2) == true);
  17. REQUIRE(cp.value() == expectedCodepoint);
  18. }
  19. TEST_CASE("Utf16::Codepoint()") {
  20. SECTION("U+0000") {
  21. testUtf16Codepoint(0x0000, 0x000000);
  22. }
  23. SECTION("U+0001") {
  24. testUtf16Codepoint(0x0001, 0x000001);
  25. }
  26. SECTION("U+D7FF") {
  27. testUtf16Codepoint(0xD7FF, 0x00D7FF);
  28. }
  29. SECTION("U+E000") {
  30. testUtf16Codepoint(0xE000, 0x00E000);
  31. }
  32. SECTION("U+FFFF") {
  33. testUtf16Codepoint(0xFFFF, 0x00FFFF);
  34. }
  35. SECTION("U+010000") {
  36. testUtf16Codepoint(0xD800, 0xDC00, 0x010000);
  37. }
  38. SECTION("U+010001") {
  39. testUtf16Codepoint(0xD800, 0xDC01, 0x010001);
  40. }
  41. SECTION("U+0103FF") {
  42. testUtf16Codepoint(0xD800, 0xDFFF, 0x0103FF);
  43. }
  44. SECTION("U+010400") {
  45. testUtf16Codepoint(0xD801, 0xDC00, 0x010400);
  46. }
  47. SECTION("U+010400") {
  48. testUtf16Codepoint(0xDBFF, 0xDC00, 0x10FC00);
  49. }
  50. SECTION("U+10FFFF") {
  51. testUtf16Codepoint(0xDBFF, 0xDFFF, 0x10FFFF);
  52. }
  53. }