summaryrefslogtreecommitdiff
path: root/test/locale/tst-xlocale1.c
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2008-07-09 15:05:36 +0000
committerCarmelo Amoroso <carmelo.amoroso@st.com>2008-07-09 15:05:36 +0000
commita691312d8794d5516402bb6bb0d3e90c40ba188b (patch)
treedcac242fcad7d24a4f452722de26c56cfaf8c98a /test/locale/tst-xlocale1.c
parent56df95fe5d0778352abe09225d6587b88643d135 (diff)
Added several tests for locale support (8 bit and multibyte UTF-8)
Basically all tests have been taken from glibc. For testing multibyte encoding EUC_JP parts have been commented out and added new section for UTF-8 that is the only multibyte codeset currently supported on uCLibc. Some tests are still failing due to unsupported/missing features, other have been fixed. Signed-off-by: Filippo Arcidiacono <filippo.arcidiacono@st.com> Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'test/locale/tst-xlocale1.c')
-rw-r--r--test/locale/tst-xlocale1.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/locale/tst-xlocale1.c b/test/locale/tst-xlocale1.c
new file mode 100644
index 000000000..297c9ad7e
--- /dev/null
+++ b/test/locale/tst-xlocale1.c
@@ -0,0 +1,75 @@
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+
+
+static struct
+{
+ const char *locale;
+ const char *str1;
+ const char *str2;
+ int result;
+} tests[] =
+ {
+ { "C", "TRANSLIT", "translit", 0 },
+ { "de_DE.ISO-8859-1", "TRANSLIT", "translit", 0 },
+ { "de_DE.ISO-8859-1", "TRANSLIT", "trÄnslit", -1 },
+ { "de_DE.UTF-8", "TRANSLIT", "translit", 0 },
+ { "de_DE.ISO-8859-1", "ä", "Ä", 1 }
+ };
+#define ntests (sizeof (tests) / sizeof (tests[0]))
+
+
+int
+main (void)
+{
+ size_t cnt;
+ int result = 0;
+ locale_t loc = newlocale (1 << LC_ALL, "C", NULL);
+
+ for (cnt = 0; cnt < ntests; ++cnt)
+ {
+ int r;
+
+ if (setlocale (LC_ALL, tests[cnt].locale) == NULL)
+ {
+ printf ("cannot set locale \"%s\": %m\n", tests[cnt].locale);
+ result = 1;
+ continue;
+ }
+
+ printf ("\nstrcasecmp_l (\"%s\", \"%s\", loc)\n",
+ tests[cnt].str1, tests[cnt].str2);
+
+ r = strcasecmp_l (tests[cnt].str1, tests[cnt].str2, loc);
+ if (tests[cnt].result == 0)
+ {
+ if (r != 0)
+ {
+ printf ("\"%s\" and \"%s\" expected to be the same, result %d\n",
+ tests[cnt].str1, tests[cnt].str2, r);
+ result = 1;
+ }
+ }
+ else if (tests[cnt].result < 0)
+ {
+ if (r >= 0)
+ {
+ printf ("\"%s\" expected to be smaller than \"%s\", result %d\n",
+ tests[cnt].str1, tests[cnt].str2, r);
+ result = 1;
+ }
+ }
+ else
+ {
+ if (r <= 0)
+ {
+ printf ("\"%s\" expected to be larger than \"%s\", result %d\n",
+ tests[cnt].str1, tests[cnt].str2, r);
+ result = 1;
+ }
+ }
+ }
+
+ return result;
+}