Skip to content

Commit

Permalink
add basic UTFstring API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robUx4 committed Dec 23, 2023
1 parent d0a39b4 commit 51a3e5b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ if (BUILD_TESTING)
target_link_libraries(test_infinite PUBLIC ebml)
add_test(test_infinite test_infinite)

add_executable(test_utfstring test/test_utfstring.cxx)
target_link_libraries(test_utfstring PUBLIC ebml)
add_test(test_utfstring test_utfstring)

endif(BUILD_TESTING)


Expand Down
65 changes: 65 additions & 0 deletions test/test_utfstring.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright © 2023 Steve Lhomme.
// SPDX-License-Identifier: ISC

#include <ebml/EbmlUnicodeString.h>

using namespace libebml;

constexpr char emoji_8[] = "\xF0\x9F\x98\x80";
constexpr wchar_t emoji_w[] = L"\U0001f600";

int main(void)
{
UTFstring ascii{ L"latin1" };

if (ascii != L"latin1")
return 1;

if (wcscmp(ascii.c_str(), L"latin1") != 0)
return 1;

if (ascii.GetUTF8() != "latin1")
return 1;

UTFstring utf8;
utf8.SetUTF8( emoji_8 );

if (utf8.length() != (4 / sizeof(wchar_t)))
return 1;

if (utf8 != emoji_w)
return 1;

// UTFstring invalid;
// FIXME don't crash invalid.SetUTF8( "\x1\xF6\x00" );

UTFstring empty{0};
if (empty.length() != 0)
return 1;

UTFstring padded{L"padded\0\0"};
if (padded.length() != 6)
return 1;

if (padded != L"padded")
return 1;

UTFstring copy = utf8;
if (copy.length() != (4 / sizeof(wchar_t)))
return 1;

if (copy != emoji_w)
return 1;

if (copy.c_str() == utf8.c_str())
return 1;

UTFstring copy2(utf8);
if (copy2 != emoji_w)
return 1;

if (copy2.c_str() == utf8.c_str())
return 1;

return 0;
}

0 comments on commit 51a3e5b

Please sign in to comment.