diff options
author | Ulrich Drepper <drepper@redhat.com> | 2002-08-29 06:14:44 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2002-08-29 06:14:44 +0000 |
commit | 653e58951271cf55a3b2d778ea02107b9ea44d78 (patch) | |
tree | 94aeb165a127cc0aeb64376df3ee865a3d541c2e /time | |
parent | 9a411bf59fc681103e6a509ec3e13c68e8c61224 (diff) | |
download | glibc-653e58951271cf55a3b2d778ea02107b9ea44d78.tar glibc-653e58951271cf55a3b2d778ea02107b9ea44d78.tar.gz glibc-653e58951271cf55a3b2d778ea02107b9ea44d78.tar.bz2 glibc-653e58951271cf55a3b2d778ea02107b9ea44d78.zip |
Test for strftime_l and wcsftime_l.
Diffstat (limited to 'time')
-rw-r--r-- | time/tst-ftime_l.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/time/tst-ftime_l.c b/time/tst-ftime_l.c new file mode 100644 index 0000000000..6ebc973feb --- /dev/null +++ b/time/tst-ftime_l.c @@ -0,0 +1,85 @@ +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <wchar.h> + + +int +main (void) +{ + locale_t l; + struct tm tm; + char buf[1000]; + wchar_t wbuf[1000]; + int result = 0; + + l = newlocale (LC_ALL_MASK, "de_DE.ISO-8859-1", NULL); + if (l == NULL) + { + puts ("newlocale failed"); + exit (1); + } + + memset (&tm, '\0', sizeof (tm)); + + tm.tm_year = 102; + tm.tm_mon = 2; + tm.tm_mday = 1; + + if (strftime (buf, sizeof (buf), "%e %^B %Y", &tm) == 0) + { + puts ("initial strftime failed"); + exit (1); + } + if (strcmp (buf, " 1 MARCH 2002") != 0) + { + printf ("initial strftime: expected \"%s\", got \"%s\"\n", + " 1 MARCH 2002", buf); + result = 1; + } + else + printf ("got \"%s\"\n", buf); + + /* Now using the extended locale model. */ + if (strftime_l (buf, sizeof (buf), "%e %^B %Y", &tm, l) == 0) + { + puts ("strftime_l failed"); + result = 1; + } + else if (strcmp (buf, " 1 M\xc4RZ 2002") != 0) + { + printf ("strftime_l: expected \"%s\", got \"%s\"\n", + " 1 M\xc4RZ 2002", buf); + result = 1; + } + else + { + setlocale (LC_ALL, "de_DE.ISO-8859-1"); + printf ("got \"%s\"\n", buf); + setlocale (LC_ALL, "C"); + } + + /* And the wide character version. */ + if (wcsftime_l (wbuf, sizeof (wbuf) / sizeof (wbuf[0]), L"%e %^B %Y", &tm, l) + == 0) + { + puts ("wcsftime_l failed"); + result = 1; + } + else if (wcscmp (wbuf, L" 1 M\x00c4RZ 2002") != 0) + { + printf ("wcsftime_l: expected \"%ls\", got \"%ls\"\n", + L" 1 M\x00c4RZ 2002", wbuf); + result = 1; + } + else + { + setlocale (LC_ALL, "de_DE.ISO-8859-1"); + printf ("got \"%ls\"\n", wbuf); + setlocale (LC_ALL, "C"); + } + + return result; +} |