diff options
author | ed <ed@FreeBSD.org> | 2013-06-03 17:17:56 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2013-06-03 17:17:56 +0000 |
commit | d6e16cad4cb99e7f1641cb8c31881f910b1b427b (patch) | |
tree | 925fa5249e7eb65c98a1c3fed8e18bbc85e4efd2 /tools/regression/lib | |
parent | e1000eed34082643bcda3a70a3dd280f2da839e7 (diff) | |
download | FreeBSD-src-d6e16cad4cb99e7f1641cb8c31881f910b1b427b.zip FreeBSD-src-d6e16cad4cb99e7f1641cb8c31881f910b1b427b.tar.gz |
Add libiconv based versions of *c16*() and *c32*().
I initially thought wchar_t was locale independent, but this seems to be
only the case on Linux. This means that we cannot depend on the *wc*()
routines to implement *c16*() and *c32*(). Instead, use the Citrus
libiconv that is part of libc.
I'll see if there is anything I can do to make the existing functions
somewhat useful in case the system is built without libiconv in the
nearby future. If not, I'll simply remove the broken implementations.
Reviewed by: jilles, gabor
Diffstat (limited to 'tools/regression/lib')
-rw-r--r-- | tools/regression/lib/libc/locale/test-c16rtomb.c | 30 | ||||
-rw-r--r-- | tools/regression/lib/libc/locale/test-mbrtoc16.c | 45 |
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); |