summaryrefslogtreecommitdiffstats
path: root/tools/regression/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tools/regression/lib')
-rw-r--r--tools/regression/lib/libc/locale/test-c16rtomb.c30
-rw-r--r--tools/regression/lib/libc/locale/test-mbrtoc16.c45
2 files changed, 75 insertions, 0 deletions
diff --git a/tools/regression/lib/libc/locale/test-c16rtomb.c b/tools/regression/lib/libc/locale/test-c16rtomb.c
index eb88946..2c188fa 100644
--- a/tools/regression/lib/libc/locale/test-c16rtomb.c
+++ b/tools/regression/lib/libc/locale/test-c16rtomb.c
@@ -82,6 +82,34 @@ main(int argc, char *argv[])
assert(c16rtomb(buf, 0xd83d, &s) == 0);
assert(c16rtomb(buf, 0xdca9, &s) == (size_t)-1);
assert(errno == EILSEQ);
+ assert((unsigned char)buf[0] == 0xcc);
+
+ /*
+ * ISO8859-1.
+ */
+
+ assert(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-1"),
+ "en_US.ISO8859-1") == 0);
+
+ /* Unicode character 'Euro sign'. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ assert(c16rtomb(buf, 0x20ac, &s) == (size_t)-1);
+ assert(errno == EILSEQ);
+ assert((unsigned char)buf[0] == 0xcc);
+
+ /*
+ * ISO8859-15.
+ */
+
+ assert(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-15"),
+ "en_US.ISO8859-15") == 0);
+
+ /* Unicode character 'Euro sign'. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ assert(c16rtomb(buf, 0x20ac, &s) == 1);
+ assert((unsigned char)buf[0] == 0xa4 && (unsigned char)buf[1] == 0xcc);
/*
* UTF-8.
@@ -104,12 +132,14 @@ main(int argc, char *argv[])
assert(c16rtomb(buf, 0xd83d, &s) == 0);
assert(c16rtomb(buf, L'A', &s) == (size_t)-1);
assert(errno == EILSEQ);
+ assert((unsigned char)buf[0] == 0xcc);
/* Invalid code; 'Pile of poo' without the lead surrogate. */
memset(&s, 0, sizeof(s));
memset(buf, 0xcc, sizeof(buf));
assert(c16rtomb(buf, 0xdca9, &s) == (size_t)-1);
assert(errno == EILSEQ);
+ assert((unsigned char)buf[0] == 0xcc);
printf("ok 1 - c16rtomb()\n");
}
diff --git a/tools/regression/lib/libc/locale/test-mbrtoc16.c b/tools/regression/lib/libc/locale/test-mbrtoc16.c
index 88e8091..f709a9c 100644
--- a/tools/regression/lib/libc/locale/test-mbrtoc16.c
+++ b/tools/regression/lib/libc/locale/test-mbrtoc16.c
@@ -85,6 +85,37 @@ main(int argc, char *argv[])
assert(mbrtoc16(&c16, "", 0, &s) == (size_t)-2);
assert(c16 == L'z');
+ /* Check that mbrtoc16() doesn't read ahead too aggressively. */
+ memset(&s, 0, sizeof(s));
+ assert(mbrtoc16(&c16, "AB", 2, &s) == 1);
+ assert(c16 == L'A');
+ assert(mbrtoc16(&c16, "C", 1, &s) == 1);
+ assert(c16 == L'C');
+
+ /*
+ * ISO-8859-1.
+ */
+
+ assert(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-1"),
+ "en_US.ISO8859-1") == 0);
+
+ /* Currency sign. */
+ memset(&s, 0, sizeof(s));
+ assert(mbrtoc16(&c16, "\xa4", 1, &s) == 1);
+ assert(c16 == 0xa4);
+
+ /*
+ * ISO-8859-15.
+ */
+
+ assert(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-15"),
+ "en_US.ISO8859-15") == 0);
+
+ /* Euro sign. */
+ memset(&s, 0, sizeof(s));
+ assert(mbrtoc16(&c16, "\xa4", 1, &s) == 1);
+ assert(c16 == 0x20ac);
+
/*
* UTF-8.
*/
@@ -144,6 +175,20 @@ main(int argc, char *argv[])
assert(mbrtoc16(&c16, "", 0, &s) == (size_t)-3);
assert(c16 == 0xdca9);
+ /* Letter e with acute, precomposed. */
+ memset(&s, 0, sizeof(s));
+ c16 = 0;
+ assert(mbrtoc16(&c16, "\xc3\xa9", 2, &s) == 2);
+ assert(c16 == 0xe9);
+
+ /* Letter e with acute, combined. */
+ memset(&s, 0, sizeof(s));
+ c16 = 0;
+ assert(mbrtoc16(&c16, "\x65\xcc\x81", 3, &s) == 1);
+ assert(c16 == 0x65);
+ assert(mbrtoc16(&c16, "\xcc\x81", 2, &s) == 2);
+ assert(c16 == 0x301);
+
printf("ok 1 - mbrtoc16()\n");
return (0);
OpenPOWER on IntegriCloud