aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2020-10-05 16:05:15 +0200
committerPierre Ossman <ossman@cendio.se>2020-10-05 16:05:15 +0200
commitd163da9ac89b2587401cd42e9a21309d1ba8fa3f (patch)
treeaa49fdcb725c0ec5cab3d880f613d118dda680bd /tests
parent6345c0f60f37f598a40536578938a6cd623b6e7f (diff)
downloadtigervnc-d163da9ac89b2587401cd42e9a21309d1ba8fa3f.tar.gz
tigervnc-d163da9ac89b2587401cd42e9a21309d1ba8fa3f.zip
Fix conversion of latin-1 to UTF-8
Signed bug prevented anything not ASCII from being coded correctly.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/unicode.cxx34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/unit/unicode.cxx b/tests/unit/unicode.cxx
index 4bcb65b3..bb2525de 100644
--- a/tests/unit/unicode.cxx
+++ b/tests/unit/unicode.cxx
@@ -31,6 +31,11 @@ struct _ucs4utf16 {
const wchar_t *utf16;
};
+struct _latin1utf8 {
+ const char *latin1;
+ const char *utf8;
+};
+
struct _utf8utf16 {
const char *utf8;
const wchar_t *utf16;
@@ -56,6 +61,13 @@ struct _ucs4utf16 ucs4utf16[] = {
{ 0x110200, L"\xfffd" },
};
+struct _latin1utf8 latin1utf8[] = {
+ { "abc", "abc" },
+ { "\xe5\xe4\xf6", "\xc3\xa5\xc3\xa4\xc3\xb6" },
+ { "???", "\xe2\x98\xb9\xe2\x98\xba\xe2\x98\xbb" },
+ { "?", "\xe5\xe4" },
+};
+
struct _utf8utf16 utf8utf16[] = {
{ "abc", L"abc" },
{ "\xc3\xa5\xc3\xa4\xc3\xb6", L"\xe5\xe4\xf6" },
@@ -133,6 +145,28 @@ int main(int argc, char** argv)
}
}
+ for (i = 0;i < ARRAY_SIZE(latin1utf8);i++) {
+ /* Expected failure? */
+ if (strchr(latin1utf8[i].latin1, '?') != NULL)
+ continue;
+
+ out = rfb::latin1ToUTF8(latin1utf8[i].latin1);
+ if (strcmp(out, latin1utf8[i].utf8) != 0) {
+ printf("FAILED: latin1ToUTF8() #%d\n", (int)i+1);
+ failures++;
+ }
+ rfb::strFree(out);
+ }
+
+ for (i = 0;i < ARRAY_SIZE(latin1utf8);i++) {
+ out = rfb::utf8ToLatin1(latin1utf8[i].utf8);
+ if (strcmp(out, latin1utf8[i].latin1) != 0) {
+ printf("FAILED: utf8ToLatin1() #%d\n", (int)i+1);
+ failures++;
+ }
+ rfb::strFree(out);
+ }
+
for (i = 0;i < ARRAY_SIZE(utf8utf16);i++) {
/* Expected failure? */
if (wcscmp(utf8utf16[i].utf16, L"\xfffd") == 0)