diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/unicode.cxx | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/unit/unicode.cxx b/tests/unit/unicode.cxx index 4618135d..cb15e7e1 100644 --- a/tests/unit/unicode.cxx +++ b/tests/unit/unicode.cxx @@ -53,6 +53,10 @@ struct _ucs4utf8 ucs4utf8[] = { { 0x1f638, "\xf0\x9f\x98\xb8" }, { 0x2d006, "\xf0\xad\x80\x86" }, { 0xfffd, "\xe5\xe4" }, + { 0xfffd, "\xed\xa2\x80" }, + { 0xfffd, "\xed\xbb\xbf" }, + { 0xd880, "\xef\xbf\xbd" }, + { 0xdeff, "\xef\xbf\xbd" }, { 0x110200, "\xef\xbf\xbd" }, }; @@ -84,6 +88,28 @@ struct _utf8utf16 utf8utf16[] = { { "\xed\xa1\xbf", L"\xfffd" }, }; +const char *validutf8[] = { + "abc", + "\xc3\xa5\xc3\xa4\xc3\xb6", + "\xf0\xad\x80\x86", +}; + +const char *invalidutf8[] = { + "\xe5\xe4\xf6", + "\xf8\xa1\xa1\xa1\xa1", + "\xed\xa2\x80", +}; + +const wchar_t *validutf16[] = { + L"abc", + L"\xe5\xe4\xf6", + L"\xd83d\xde38\xd83d\xde41\xd83d\xde42", +}; + +const wchar_t *invalidutf16[] = { + L"\xdc40\xdc12", +}; + #define ARRAY_SIZE(a) (sizeof(a)/sizeof(*a)) int main(int /*argc*/, char** /*argv*/) @@ -196,6 +222,34 @@ int main(int /*argc*/, char** /*argv*/) } } + for (i = 0;i < ARRAY_SIZE(validutf8);i++) { + if (!rfb::isValidUTF8(validutf8[i])) { + printf("FAILED: isValidUTF8() #%d\n", (int)i+1); + failures++; + } + } + + for (i = 0;i < ARRAY_SIZE(invalidutf8);i++) { + if (rfb::isValidUTF8(invalidutf8[i])) { + printf("FAILED: ! isValidUTF8() #%d\n", (int)i+1); + failures++; + } + } + + for (i = 0;i < ARRAY_SIZE(validutf16);i++) { + if (!rfb::isValidUTF16(validutf16[i])) { + printf("FAILED: isValidUTF16() #%d\n", (int)i+1); + failures++; + } + } + + for (i = 0;i < ARRAY_SIZE(invalidutf16);i++) { + if (rfb::isValidUTF16(invalidutf16[i])) { + printf("FAILED: ! isValidUTF16() #%d\n", (int)i+1); + failures++; + } + } + if (failures == 0) { printf("OK\n"); } else { |