diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | stdio-common/vfscanf.c | 4 | ||||
-rw-r--r-- | time/Makefile | 2 | ||||
-rw-r--r-- | time/tst-strptime.c | 46 |
4 files changed, 46 insertions, 11 deletions
@@ -1,3 +1,8 @@ +2001-08-09 Ulrich Drepper <drepper@redhat.com> + + * time/tst-strptime.c: Add tests in different locales. + * time/Makefile (tst-strptime-ENV): Define. + 2001-08-09 Jakub Jelinek <jakub@redhat.com> * catgets/catgets.c (catclose): Be liberal about catalog_desc in diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c index 6312af719e..3c5bccbdc6 100644 --- a/stdio-common/vfscanf.c +++ b/stdio-common/vfscanf.c @@ -755,7 +755,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr) { /* We have to convert the multibyte input sequence to wide characters. */ - char buf[0]; + char buf[1]; mbstate_t cstate; memset (&cstate, '\0', sizeof (cstate)); @@ -1058,7 +1058,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr) } #else { - char buf[0]; + char buf[1]; buf[0] = c; diff --git a/time/Makefile b/time/Makefile index ae5c844492..f60dee0e28 100644 --- a/time/Makefile +++ b/time/Makefile @@ -49,3 +49,5 @@ CFLAGS-test_time.c = -Wno-format tst-getdate-ENV= DATEMSK=datemsk TZDIR=${common-objpfx}timezone/testdata test_time-ARGS= EST5EDT CST + +tst-strptime-ENV = LOCPATH=${common-objpfx}localedata diff --git a/time/tst-strptime.c b/time/tst-strptime.c index d866923903..ac692a6d67 100644 --- a/time/tst-strptime.c +++ b/time/tst-strptime.c @@ -18,25 +18,32 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <locale.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <time.h> static const struct { + const char *locale; const char *input; const char *format; int wday; int yday; + int mon; + int mday; } day_tests[] = { - { "2000-01-01", "%Y-%m-%d", 6, 0 }, - { "03/03/00", "%D", 5, 62 }, - { "9/9/99", "%x", 4, 251 }, - { "19990502123412", "%Y%m%d%H%M%S", 0, 121 }, - { "2001 20 Mon", "%Y %U %a", 1, 140 }, - { "2001 21 Mon", "%Y %W %a", 1, 140 }, + { "C", "2000-01-01", "%Y-%m-%d", 6, 0, 0, 1 }, + { "C", "03/03/00", "%D", 5, 62, 2, 3 }, + { "C", "9/9/99", "%x", 4, 251, 8, 9 }, + { "C", "19990502123412", "%Y%m%d%H%M%S", 0, 121, 4, 2 }, + { "C", "2001 20 Mon", "%Y %U %a", 1, 140, 4, 21 }, + { "C", "2001 21 Mon", "%Y %W %a", 1, 140, 4, 21 }, + { "ja_JP.EUC-JP", "2001 20 \xb7\xee", "%Y %U %a", 1, 140, 4, 21 }, + { "ja_JP.EUC-JP", "2001 21 \xb7\xee", "%Y %W %a", 1, 140, 4, 21 }, }; @@ -114,6 +121,12 @@ main (int argc, char *argv[]) { memset (&tm, '\0', sizeof (tm)); + if (setlocale (LC_ALL, day_tests[i].locale) == NULL) + { + printf ("cannot set locale %s: %m\n", day_tests[i].locale); + exit (EXIT_FAILURE); + } + if (*strptime (day_tests[i].input, day_tests[i].format, &tm) != '\0') { printf ("not all of `%s' read\n", day_tests[i].input); @@ -121,11 +134,12 @@ main (int argc, char *argv[]) } printf ("strptime (\"%s\", \"%s\", ...)\n" - "\tshould be: wday = %d, yday = %3d\n" - "\t is: wday = %d, yday = %3d\n", + "\tshould be: wday = %d, yday = %3d, mon = %2d, mday = %2d\n" + "\t is: wday = %d, yday = %3d, mon = %2d, mday = %2d\n", day_tests[i].input, day_tests[i].format, day_tests[i].wday, day_tests[i].yday, - tm.tm_wday, tm.tm_yday); + day_tests[i].mon, day_tests[i].mday, + tm.tm_wday, tm.tm_yday, tm.tm_mon, tm.tm_mday); if (tm.tm_wday != day_tests[i].wday) { @@ -139,8 +153,22 @@ main (int argc, char *argv[]) day_tests[i].input, tm.tm_yday, day_tests[i].yday); result = 1; } + if (tm.tm_mon != day_tests[i].mon) + { + printf ("month for `%s' incorrect: %d instead of %d\n", + day_tests[i].input, tm.tm_mon, day_tests[i].mon); + result = 1; + } + if (tm.tm_mday != day_tests[i].mday) + { + printf ("monthday for `%s' incorrect: %d instead of %d\n", + day_tests[i].input, tm.tm_mday, day_tests[i].mday); + result = 1; + } } + setlocale (LC_ALL, "C"); + result |= test_tm (); return result; |