1#include <locale.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <time.h>
6#include <wchar.h>
7
8
9static int
10do_test (void)
11{
12 locale_t l;
13 locale_t old;
14 struct tm tm;
15 char buf[1000];
16 wchar_t wbuf[1000];
17 int result = 0;
18 size_t n;
19
20 l = newlocale (LC_ALL_MASK, locale: "de_DE.ISO-8859-1", NULL);
21 if (l == NULL)
22 {
23 puts (s: "newlocale failed");
24 exit (1);
25 }
26
27 memset (&tm, '\0', sizeof (tm));
28
29 tm.tm_year = 102;
30 tm.tm_mon = 2;
31 tm.tm_mday = 1;
32
33 if (strftime (buf, sizeof (buf), "%e %^B %Y", &tm) == 0)
34 {
35 puts (s: "initial strftime failed");
36 exit (1);
37 }
38 if (strcmp (buf, " 1 MARCH 2002") != 0)
39 {
40 printf (format: "initial strftime: expected \"%s\", got \"%s\"\n",
41 " 1 MARCH 2002", buf);
42 result = 1;
43 }
44 else
45 printf (format: "got \"%s\"\n", buf);
46
47 /* Now using the extended locale model. */
48 if (strftime_l (s: buf, maxsize: sizeof (buf), format: "%e %^B %Y", tp: &tm, loc: l) == 0)
49 {
50 puts (s: "strftime_l failed");
51 result = 1;
52 }
53 else if (strcmp (buf, " 1 M\xc4RZ 2002") != 0)
54 {
55 printf (format: "strftime_l: expected \"%s\", got \"%s\"\n",
56 " 1 M\xc4RZ 2002", buf);
57 result = 1;
58 }
59 else
60 {
61 setlocale (LC_ALL, "de_DE.ISO-8859-1");
62 printf (format: "got \"%s\"\n", buf);
63 setlocale (LC_ALL, "C");
64 }
65
66 /* And the wide character version. */
67 if (wcsftime_l (s: wbuf, maxsize: sizeof (wbuf) / sizeof (wbuf[0]), format: L"%e %^B %Y", tp: &tm, loc: l)
68 == 0)
69 {
70 puts (s: "wcsftime_l failed");
71 result = 1;
72 }
73 else if (wcscmp (s1: wbuf, s2: L" 1 M\x00c4RZ 2002") != 0)
74 {
75 printf (format: "wcsftime_l: expected \"%ls\", got \"%ls\"\n",
76 L" 1 M\x00c4RZ 2002", wbuf);
77 result = 1;
78 }
79 else
80 {
81 setlocale (LC_ALL, "de_DE.ISO-8859-1");
82 printf (format: "got \"%ls\"\n", wbuf);
83 setlocale (LC_ALL, "C");
84 }
85
86 old = uselocale (dataset: l);
87
88 n = strftime (buf, sizeof (buf), "%e %^B %Y", &tm);
89
90 /* Switch back. */
91 (void) uselocale (dataset: old);
92
93 if (n == 0)
94 {
95 puts (s: "strftime after first uselocale failed");
96 result = 1;
97 }
98 else if (strcmp (buf, " 1 M\xc4RZ 2002") != 0)
99 {
100 printf (format: "strftime in non-C locale: expected \"%s\", got \"%s\"\n",
101 " 1 M\xc4RZ 2002", buf);
102 result = 1;
103 }
104 else
105 {
106 setlocale (LC_ALL, "de_DE.ISO-8859-1");
107 printf (format: "got \"%s\"\n", buf);
108 setlocale (LC_ALL, "C");
109 }
110
111 if (strftime (buf, sizeof (buf), "%e %^B %Y", &tm) == 0)
112 {
113 puts (s: "strftime after second uselocale failed");
114 result = 1;
115 }
116 else if (strcmp (buf, " 1 MARCH 2002") != 0)
117 {
118 printf (format: "initial strftime: expected \"%s\", got \"%s\"\n",
119 " 1 MARCH 2002", buf);
120 result = 1;
121 }
122 else
123 printf (format: "got \"%s\"\n", buf);
124
125 return result;
126}
127
128#define TEST_FUNCTION do_test ()
129#include "../test-skeleton.c"
130

source code of glibc/time/tst-ftime_l.c