OSDN Git Service

locale: Add wcsftime()
[uclinux-h8/uClibc.git] / test / time / tst_wcsftime.c
1 #include <stdio.h>
2 #include <time.h>
3 #include <features.h>
4 #include <wchar.h>
5 #include <locale.h>
6
7 #define NUM_OF_DATES 7
8 #define NUM_OF_LOCALES 3
9 #define BUF_SIZE 256
10
11 int
12 main (void)
13 {
14   wchar_t buf[BUF_SIZE];
15   struct tm *tp;
16   time_t time_list[NUM_OF_DATES] = {
17           500, 68200000, 694223999,
18           694224000, 704900000, 705000000,
19           705900000
20   };
21   char *locale_list[NUM_OF_LOCALES] = {
22           "C",
23           "fr_FR.ISO-8859-1",
24           "ja_JP.UTF-8"
25   };
26   int result = 0, ddd, lll;
27   size_t n;
28
29   for (lll = 0; lll < NUM_OF_LOCALES; lll++) {
30           printf ("\nUsing locale: %s\n", locale_list[lll]);
31           char* set = setlocale(LC_ALL, locale_list[lll]);
32           if (set == NULL) {
33                   printf ("FAILED!\n\n");
34                   continue;
35           } else
36                   printf ("\n");
37           for (ddd = 0; ddd < NUM_OF_DATES; ddd++) {
38                   tp = localtime(&time_list[ddd]);
39                   printf ("%ld corresponds to ", time_list[ddd]);
40
41                   n = wcsftime (buf, sizeof (buf) / sizeof (buf[0]),
42                                 L"%H:%M:%S  %Y-%m-%d%n", tp);
43                   if (n != 21) {
44                         result = 1;
45                         printf ("FAILED!\n");
46                   }
47
48                   printf ("%ls", buf);
49
50                   wcsftime (buf, sizeof (buf) / sizeof (buf[0]),
51                         L"%tor, as %%D %%T: %D %T%n", tp);
52                   printf ("%ls", buf);
53
54                   wcsftime (buf, sizeof (buf) / sizeof (buf[0]), L"%A (%a)%n", tp);
55                   printf ("The weekday was %ls", buf);
56
57                   wcsftime (buf, sizeof (buf) / sizeof (buf[0]), L"%B (%b) %Y%n", tp);
58                   /* glibc bug? forgets aigu from french february fĂ©vrier
59                    * See s/printf (/wprintf (L/g */
60                   //wprintf (L"Month was %ls", buf);
61                   printf ("Month was %ls", buf);
62           }
63   }
64   return result;
65 }