Serenity Operating System
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Tests: Add a basic UTF-8 to UTF-8 LibTextCodec test

authored by

Karol Kosek and committed by
Andreas Kling
dcb24e94 b006a603

+40
+7
Meta/Lagom/CMakeLists.txt
··· 596 596 lagom_test(${source} LIBS LagomSQL) 597 597 endforeach() 598 598 599 + # TextCodec 600 + file(GLOB LIBTEXTCODEC_TESTS CONFIGURE_DEPENDS "../../Tests/LibTextCodec/*.cpp") 601 + foreach(source ${LIBTEXTCODEC_TESTS}) 602 + lagom_test(${source} LIBS LagomTextCodec 603 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibTextCodec) 604 + endforeach() 605 + 599 606 # TLS 600 607 file(GLOB LIBTLS_TESTS CONFIGURE_DEPENDS "../../Tests/LibTLS/*.cpp") 601 608 foreach(source ${LIBTLS_TESTS})
+1
Tests/CMakeLists.txt
··· 17 17 add_subdirectory(LibRegex) 18 18 add_subdirectory(LibSQL) 19 19 add_subdirectory(LibTest) 20 + add_subdirectory(LibTextCodec) 20 21 add_subdirectory(LibThreading) 21 22 add_subdirectory(LibTimeZone) 22 23 add_subdirectory(LibUnicode)
+7
Tests/LibTextCodec/CMakeLists.txt
··· 1 + set(TEST_SOURCES 2 + TestTextDecoders.cpp 3 + ) 4 + 5 + foreach(source IN LISTS TEST_SOURCES) 6 + serenity_test("${source}" LibTextCodec LIBS LibTextCodec) 7 + endforeach()
+25
Tests/LibTextCodec/TestTextDecoders.cpp
··· 1 + /* 2 + * Copyright (c) 2022, the SerenityOS developers. 3 + * 4 + * SPDX-License-Identifier: BSD-2-Clause 5 + */ 6 + 7 + #include <AK/Vector.h> 8 + #include <LibTest/TestCase.h> 9 + #include <LibTextCodec/Decoder.h> 10 + 11 + TEST_CASE(test_utf8_decode) 12 + { 13 + auto decoder = TextCodec::UTF8Decoder(); 14 + // Bytes for U+1F600 GRINNING FACE 15 + auto test_string = "\xf0\x9f\x98\x80"; 16 + 17 + Vector<u32> processed_code_points; 18 + decoder.process(test_string, [&](u32 code_point) { 19 + processed_code_points.append(code_point); 20 + }); 21 + EXPECT(processed_code_points.size() == 1); 22 + EXPECT(processed_code_points[0] == 0x1F600); 23 + 24 + EXPECT(decoder.to_utf8(test_string) == test_string); 25 + }