Utf16.cpp 1.5 KB

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