OSDN Git Service

* testsuite/22_locale/codecvt_members_char_char.cc: Do not
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 22_locale / time_get_members_char.cc
1 // 2001-09-21 Benjamin Kosnik  <bkoz@redhat.com>
2
3 // Copyright (C) 2001, 2002 Free Software Foundation
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // 22.2.5.1.1 time_get members
22
23 #include <locale>
24 #include <sstream>
25 #include <testsuite_hooks.h>
26
27 // XXX This test is not working for non-glibc locale models.
28 // { dg-do run { xfail *-*-* } }
29
30 void test01()
31 {
32   using namespace std;
33   typedef time_base::dateorder dateorder;
34   typedef istreambuf_iterator<char> iterator_type;
35
36   bool test = true;
37
38   // basic construction and sanity checks.
39   locale loc_c = locale::classic();
40   locale loc_hk("en_HK");
41   locale loc_fr("fr_FR@euro");
42   locale loc_de("de_DE");
43   VERIFY( loc_hk != loc_c );
44   VERIFY( loc_hk != loc_fr );
45   VERIFY( loc_hk != loc_de );
46   VERIFY( loc_de != loc_fr );
47
48   // cache the __timepunct facets, for quicker gdb inspection
49   const __timepunct<char>& time_c = use_facet<__timepunct<char> >(loc_c); 
50   const __timepunct<char>& time_de = use_facet<__timepunct<char> >(loc_de); 
51   const __timepunct<char>& time_hk = use_facet<__timepunct<char> >(loc_hk); 
52   const __timepunct<char>& time_fr = use_facet<__timepunct<char> >(loc_fr); 
53
54   const string empty;
55
56   // create an ostream-derived object, cache the time_get facet
57   iterator_type end;
58
59   istringstream iss;
60   const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc()); 
61
62   const ios_base::iostate good = ios_base::goodbit;
63   ios_base::iostate errorstate = good;
64
65   // create "C" time objects
66   const tm time_bday = { 0, 0, 12, 4, 3, 71 };
67   const char* all = "%a %A %b %B %c %d %H %I %j %m %M %p %s %U "
68                     "%w %W %x %X %y %Y %Z %%";
69   const char* date = "%A, the second of %B";
70   const char* date_ex = "%Ex";
71
72   // 1
73   // dateorder date_order() const
74   iss.imbue(loc_c);
75   dateorder do1 = tim_get.date_order();
76   //  VERIFY( do1 == time_base::mdy );
77   VERIFY( do1 == time_base::no_order );
78
79   // 2
80   // iter_type 
81   // get_time(iter_type, iter_type, ios_base&, ios_base::iostate&, tm*) const
82
83   // sanity checks for "C" locale
84   iss.str("12:00:00");
85   iterator_type is_it01(iss);
86   tm time01;
87   errorstate = good;
88   tim_get.get_time(is_it01, end, iss, errorstate, &time01);
89   VERIFY( time01.tm_sec == time_bday.tm_sec );
90   VERIFY( time01.tm_min == time_bday.tm_min );
91   VERIFY( time01.tm_hour == time_bday.tm_hour );
92   VERIFY( errorstate == ios_base::eofbit );
93
94   iss.str("12:00:00 ");
95   iterator_type is_it02(iss);
96   tm time02;
97   errorstate = good;
98   tim_get.get_time(is_it02, end, iss, errorstate, &time02);
99   VERIFY( time01.tm_sec == time_bday.tm_sec );
100   VERIFY( time01.tm_min == time_bday.tm_min );
101   VERIFY( time01.tm_hour == time_bday.tm_hour );
102   VERIFY( errorstate == good );
103
104   iss.str("12:61:00 ");
105   iterator_type is_it03(iss);
106   tm time03;
107   errorstate = good;
108   tim_get.get_time(is_it03, end, iss, errorstate, &time03);
109   VERIFY( time01.tm_hour == time_bday.tm_hour );
110   VERIFY( errorstate == ios_base::failbit );
111
112   iss.str("12:a:00 ");
113   iterator_type is_it04(iss);
114   tm time04;
115   errorstate = good;
116   tim_get.get_time(is_it04, end, iss, errorstate, &time04);
117   VERIFY( time01.tm_hour == time_bday.tm_hour );
118   VERIFY( *is_it04 == 'a');
119   VERIFY( errorstate == ios_base::failbit );
120
121   // inspection of named locales, de_DE
122   iss.imbue(loc_de);
123   iss.str("12:00:00");
124   iterator_type is_it10(iss);
125   tm time10;
126   errorstate = good;
127   tim_get.get_time(is_it10, end, iss, errorstate, &time10);
128   VERIFY( time10.tm_sec == time_bday.tm_sec );
129   VERIFY( time10.tm_min == time_bday.tm_min );
130   VERIFY( time10.tm_hour == time_bday.tm_hour );
131   VERIFY( errorstate == ios_base::eofbit );
132
133   // inspection of named locales, en_HK
134   iss.imbue(loc_hk);
135   iss.str("12:00:00 PST"); 
136   // Hong Kong in California! Well, they have Paris in Vegas... this
137   // is all a little disney-esque anyway. Besides, you can get decent
138   // Dim Sum in San Francisco.
139   iterator_type is_it20(iss);
140   tm time20;
141   errorstate = good;
142   tim_get.get_time(is_it20, end, iss, errorstate, &time20);
143   VERIFY( time10.tm_sec == time_bday.tm_sec );
144   VERIFY( time10.tm_min == time_bday.tm_min );
145   VERIFY( time10.tm_hour == time_bday.tm_hour );
146   VERIFY( errorstate == ios_base::eofbit );
147 }
148
149 void test02()
150 {
151   using namespace std;
152   typedef time_base::dateorder dateorder;
153   typedef istreambuf_iterator<char> iterator_type;
154
155   bool test = true;
156
157   // basic construction and sanity checks.
158   locale loc_c = locale::classic();
159   locale loc_hk("en_HK");
160   locale loc_fr("fr_FR@euro");
161   locale loc_de("de_DE");
162   VERIFY( loc_hk != loc_c );
163   VERIFY( loc_hk != loc_fr );
164   VERIFY( loc_hk != loc_de );
165   VERIFY( loc_de != loc_fr );
166
167   // cache the __timepunct facets, for quicker gdb inspection
168   const __timepunct<char>& time_c = use_facet<__timepunct<char> >(loc_c); 
169   const __timepunct<char>& time_de = use_facet<__timepunct<char> >(loc_de); 
170   const __timepunct<char>& time_hk = use_facet<__timepunct<char> >(loc_hk); 
171   const __timepunct<char>& time_fr = use_facet<__timepunct<char> >(loc_fr); 
172
173   const string empty;
174
175   // create an ostream-derived object, cache the time_get facet
176   iterator_type end;
177
178   istringstream iss;
179   const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc()); 
180
181   const ios_base::iostate good = ios_base::goodbit;
182   ios_base::iostate errorstate = good;
183
184   // create "C" time objects
185   const tm time_bday = { 0, 0, 12, 4, 3, 71 };
186   const char* all = "%a %A %b %B %c %d %H %I %j %m %M %p %s %U "
187                     "%w %W %x %X %y %Y %Z %%";
188   const char* date = "%A, the second of %B";
189   const char* date_ex = "%Ex";
190
191   // iter_type 
192   // get_weekday(iter_type, iter_type, ios_base&, 
193   //             ios_base::iostate&, tm*) const
194
195   // sanity checks for "C" locale
196   iss.imbue(loc_c);
197   iss.str("Sunday");
198   iterator_type is_it01(iss);
199   tm time01;
200   errorstate = good;
201   tim_get.get_weekday(is_it01, end, iss, errorstate, &time01);
202   VERIFY( time01.tm_wday == time_bday.tm_wday );
203   VERIFY( errorstate == ios_base::eofbit );
204
205   iss.str("Sun");
206   iterator_type is_it02(iss);
207   tm time02;
208   errorstate = good;
209   tim_get.get_weekday(is_it02, end, iss, errorstate, &time02);
210   VERIFY( time02.tm_wday == time_bday.tm_wday );
211   VERIFY( errorstate == ios_base::eofbit );
212
213   iss.str("Sun ");
214   iterator_type is_it03(iss);
215   tm time03;
216   errorstate = good;
217   tim_get.get_weekday(is_it03, end, iss, errorstate, &time03);
218   VERIFY( time03.tm_wday == time_bday.tm_wday );
219   VERIFY( errorstate == good );
220   VERIFY( *is_it03 == ' ');
221
222   iss.str("San");
223   iterator_type is_it04(iss);
224   tm time04;
225   time04.tm_wday = 4;
226   errorstate = good;
227   tim_get.get_weekday(is_it04, end, iss, errorstate, &time04);
228   VERIFY( time04.tm_wday == 4 );
229   VERIFY( *is_it04 == 'n');
230   VERIFY( errorstate == ios_base::failbit );
231
232   iss.str("Tuesday ");
233   iterator_type is_it05(iss);
234   tm time05;
235   errorstate = good;
236   tim_get.get_weekday(is_it05, end, iss, errorstate, &time05);
237   VERIFY( time05.tm_wday == 2 );
238   VERIFY( errorstate == good );
239   VERIFY( *is_it05 == ' ');
240
241   iss.str("Tuesducky "); // Kind of like Fryday, without the swirls.
242   iterator_type is_it06(iss);
243   tm time06;
244   time06.tm_wday = 4;
245   errorstate = good;
246   tim_get.get_weekday(is_it06, end, iss, errorstate, &time06);
247   VERIFY( time06.tm_wday == 4 );
248   VERIFY( errorstate == ios_base::failbit );
249   VERIFY( *is_it05 == 'u');
250
251   // inspection of named locales, de_DE
252   iss.imbue(loc_de);
253   iss.str("Sonntag");
254   iterator_type is_it10(iss);
255   tm time10;
256   errorstate = good;
257   tim_get.get_weekday(is_it10, end, iss, errorstate, &time10);
258   VERIFY( time10.tm_wday == time_bday.tm_wday );
259   VERIFY( errorstate == ios_base::eofbit );
260
261   // inspection of named locales, en_HK
262   iss.imbue(loc_hk);
263   iss.str("Sunday"); 
264   iterator_type is_it20(iss);
265   tm time20;
266   errorstate = good;
267   tim_get.get_weekday(is_it20, end, iss, errorstate, &time20);
268   VERIFY( time20.tm_wday == time_bday.tm_wday );
269   VERIFY( errorstate == ios_base::eofbit );
270 }
271
272 void test03()
273 {
274   using namespace std;
275   typedef time_base::dateorder dateorder;
276   typedef istreambuf_iterator<char> iterator_type;
277
278   bool test = true;
279
280   // basic construction and sanity checks.
281   locale loc_c = locale::classic();
282   locale loc_hk("en_HK");
283   locale loc_fr("fr_FR@euro");
284   locale loc_de("de_DE");
285   VERIFY( loc_hk != loc_c );
286   VERIFY( loc_hk != loc_fr );
287   VERIFY( loc_hk != loc_de );
288   VERIFY( loc_de != loc_fr );
289
290   // cache the __timepunct facets, for quicker gdb inspection
291   const __timepunct<char>& time_c = use_facet<__timepunct<char> >(loc_c); 
292   const __timepunct<char>& time_de = use_facet<__timepunct<char> >(loc_de); 
293   const __timepunct<char>& time_hk = use_facet<__timepunct<char> >(loc_hk); 
294   const __timepunct<char>& time_fr = use_facet<__timepunct<char> >(loc_fr); 
295
296   const string empty;
297
298   // create an ostream-derived object, cache the time_get facet
299   iterator_type end;
300
301   istringstream iss;
302   const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc()); 
303
304   const ios_base::iostate good = ios_base::goodbit;
305   ios_base::iostate errorstate = good;
306
307   // create "C" time objects
308   const tm time_bday = { 0, 0, 12, 4, 3, 71 };
309   const char* all = "%a %A %b %B %c %d %H %I %j %m %M %p %s %U "
310                     "%w %W %x %X %y %Y %Z %%";
311   const char* date = "%A, the second of %B";
312   const char* date_ex = "%Ex";
313
314   // iter_type 
315   // get_monthname(iter_type, iter_type, ios_base&, 
316   //               ios_base::iostate&, tm*) const
317
318   // sanity checks for "C" locale
319   iss.imbue(loc_c);
320   iss.str("April");
321   iterator_type is_it01(iss);
322   tm time01;
323   errorstate = good;
324   tim_get.get_monthname(is_it01, end, iss, errorstate, &time01);
325   VERIFY( time01.tm_wday == time_bday.tm_wday );
326   VERIFY( errorstate == ios_base::eofbit );
327
328   iss.str("Apr");
329   iterator_type is_it02(iss);
330   tm time02;
331   errorstate = good;
332   tim_get.get_monthname(is_it02, end, iss, errorstate, &time02);
333   VERIFY( time02.tm_mon == time_bday.tm_mon );
334   VERIFY( errorstate == ios_base::eofbit );
335
336   iss.str("Apr ");
337   iterator_type is_it03(iss);
338   tm time03;
339   errorstate = good;
340   tim_get.get_monthname(is_it03, end, iss, errorstate, &time03);
341   VERIFY( time03.tm_mon == time_bday.tm_mon );
342   VERIFY( errorstate == good );
343   VERIFY( *is_it03 == ' ');
344
345   iss.str("Aar");
346   iterator_type is_it04(iss);
347   tm time04;
348   time04.tm_mon = 5;
349   errorstate = good;
350   tim_get.get_monthname(is_it04, end, iss, errorstate, &time04);
351   VERIFY( time04.tm_mon == 5 );
352   VERIFY( *is_it04 == 'a');
353   VERIFY( errorstate == ios_base::failbit );
354
355   iss.str("December ");
356   iterator_type is_it05(iss);
357   tm time05;
358   errorstate = good;
359   tim_get.get_monthname(is_it05, end, iss, errorstate, &time05);
360   VERIFY( time05.tm_mon == 11 );
361   VERIFY( errorstate == good );
362   VERIFY( *is_it05 == ' ');
363
364   iss.str("Decelember "); 
365   iterator_type is_it06(iss);
366   tm time06;
367   time06.tm_mon = 4;
368   errorstate = good;
369   tim_get.get_monthname(is_it06, end, iss, errorstate, &time06);
370   VERIFY( time06.tm_mon == 4 );
371   VERIFY( errorstate == ios_base::failbit );
372   VERIFY( *is_it05 == 'l');
373
374   // inspection of named locales, de_DE
375   iss.imbue(loc_de);
376   iss.str("April");
377   iterator_type is_it10(iss);
378   tm time10;
379   errorstate = good;
380   tim_get.get_monthname(is_it10, end, iss, errorstate, &time10);
381   VERIFY( time10.tm_mon == time_bday.tm_mon );
382   VERIFY( errorstate == ios_base::eofbit );
383
384   // inspection of named locales, en_HK
385   iss.imbue(loc_hk);
386   iss.str("April"); 
387   iterator_type is_it20(iss);
388   tm time20;
389   errorstate = good;
390   tim_get.get_monthname(is_it20, end, iss, errorstate, &time20);
391   VERIFY( time20.tm_mon == time_bday.tm_mon );
392   VERIFY( errorstate == ios_base::eofbit );
393 }
394
395 void test04()
396 {
397   using namespace std;
398   typedef time_base::dateorder dateorder;
399   typedef istreambuf_iterator<char> iterator_type;
400
401   bool test = true;
402
403   // basic construction and sanity checks.
404   locale loc_c = locale::classic();
405   locale loc_hk("en_HK");
406   locale loc_fr("fr_FR@euro");
407   locale loc_de("de_DE");
408   VERIFY( loc_hk != loc_c );
409   VERIFY( loc_hk != loc_fr );
410   VERIFY( loc_hk != loc_de );
411   VERIFY( loc_de != loc_fr );
412
413   // cache the __timepunct facets, for quicker gdb inspection
414   const __timepunct<char>& time_c = use_facet<__timepunct<char> >(loc_c); 
415   const __timepunct<char>& time_de = use_facet<__timepunct<char> >(loc_de); 
416   const __timepunct<char>& time_hk = use_facet<__timepunct<char> >(loc_hk); 
417   const __timepunct<char>& time_fr = use_facet<__timepunct<char> >(loc_fr); 
418
419   const string empty;
420
421   // create an ostream-derived object, cache the time_get facet
422   iterator_type end;
423
424   istringstream iss;
425   const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc()); 
426
427   const ios_base::iostate good = ios_base::goodbit;
428   ios_base::iostate errorstate = good;
429
430   // create "C" time objects
431   const tm time_bday = { 0, 0, 12, 4, 3, 71 };
432   const char* all = "%a %A %b %B %c %d %H %I %j %m %M %p %s %U "
433                     "%w %W %x %X %y %Y %Z %%";
434   const char* date = "%A, the second of %B";
435   const char* date_ex = "%Ex";
436
437   // iter_type 
438   // get_year(iter_type, iter_type, ios_base&, ios_base::iostate&, tm*) const
439
440   // sanity checks for "C" locale
441   iss.imbue(loc_c);
442   iss.str("1971");
443   iterator_type is_it01(iss);
444   tm time01;
445   errorstate = good;
446   tim_get.get_year(is_it01, end, iss, errorstate, &time01);
447   VERIFY( time01.tm_year == time_bday.tm_year );
448   VERIFY( errorstate == ios_base::eofbit );
449
450   iss.str("1971 ");
451   iterator_type is_it02(iss);
452   tm time02;
453   errorstate = good;
454   tim_get.get_year(is_it02, end, iss, errorstate, &time02);
455   VERIFY( time02.tm_year == time_bday.tm_year );
456   VERIFY( errorstate == good );
457   VERIFY( *is_it02 == ' ');
458
459   iss.str("197d1 ");
460   iterator_type is_it03(iss);
461   tm time03;
462   time03.tm_year = 3;
463   errorstate = good;
464   tim_get.get_year(is_it03, end, iss, errorstate, &time03);
465   VERIFY( time03.tm_year == 3 );
466   VERIFY( errorstate == ios_base::failbit );
467   VERIFY( *is_it03 == 'd');
468
469   iss.str("71d71");
470   iterator_type is_it04(iss);
471   tm time04;
472   errorstate = good;
473   tim_get.get_year(is_it04, end, iss, errorstate, &time04);
474   VERIFY( time04.tm_year == time_bday.tm_year );
475   VERIFY( errorstate == good );
476   VERIFY( *is_it03 == 'd');
477
478   iss.str("71");
479   iterator_type is_it05(iss);
480   tm time05;
481   errorstate = good;
482   tim_get.get_year(is_it05, end, iss, errorstate, &time05);
483   VERIFY( time05.tm_year == time_bday.tm_year );
484   VERIFY( errorstate == ios_base::eofbit );
485 }
486
487 void test05()
488 {
489   using namespace std;
490   typedef time_base::dateorder dateorder;
491   typedef istreambuf_iterator<char> iterator_type;
492
493   bool test = true;
494
495   // basic construction and sanity checks.
496   locale loc_c = locale::classic();
497   locale loc_hk("en_HK");
498   locale loc_fr("fr_FR@euro");
499   locale loc_de("de_DE");
500   VERIFY( loc_hk != loc_c );
501   VERIFY( loc_hk != loc_fr );
502   VERIFY( loc_hk != loc_de );
503   VERIFY( loc_de != loc_fr );
504
505   // cache the __timepunct facets, for quicker gdb inspection
506   const __timepunct<char>& time_c = use_facet<__timepunct<char> >(loc_c); 
507   const __timepunct<char>& time_de = use_facet<__timepunct<char> >(loc_de); 
508   const __timepunct<char>& time_hk = use_facet<__timepunct<char> >(loc_hk); 
509   const __timepunct<char>& time_fr = use_facet<__timepunct<char> >(loc_fr); 
510
511   const string empty;
512
513   // create an ostream-derived object, cache the time_get facet
514   iterator_type end;
515
516   istringstream iss;
517   const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc()); 
518
519   const ios_base::iostate good = ios_base::goodbit;
520   ios_base::iostate errorstate = good;
521
522   // create "C" time objects
523   const tm time_bday = { 0, 0, 12, 4, 3, 71 };
524   const char* all = "%a %A %b %B %c %d %H %I %j %m %M %p %s %U "
525                     "%w %W %x %X %y %Y %Z %%";
526   const char* date = "%A, the second of %B";
527   const char* date_ex = "%Ex";
528
529   // iter_type 
530   // get_date(iter_type, iter_type, ios_base&, ios_base::iostate&, tm*) const
531
532   // sanity checks for "C" locale
533   iss.imbue(loc_c);
534   iss.str("04/04/71");
535   iterator_type is_it01(iss);
536   tm time01;
537   errorstate = good;
538   tim_get.get_date(is_it01, end, iss, errorstate, &time01);
539   VERIFY( time01.tm_year == time_bday.tm_year );
540   VERIFY( time01.tm_mon == time_bday.tm_mon );
541   VERIFY( time01.tm_mday == time_bday.tm_mday );
542   VERIFY( errorstate == ios_base::eofbit );
543
544   iss.str("04/04/71 ");
545   iterator_type is_it02(iss);
546   tm time02;
547   errorstate = good;
548   tim_get.get_date(is_it02, end, iss, errorstate, &time02);
549   VERIFY( time02.tm_year == time_bday.tm_year );
550   VERIFY( time02.tm_mon == time_bday.tm_mon );
551   VERIFY( time02.tm_mday == time_bday.tm_mday );
552   VERIFY( errorstate == good );
553   VERIFY( *is_it02 == ' ');
554
555   iss.str("04/04d/71 ");
556   iterator_type is_it03(iss);
557   tm time03;
558   time03.tm_year = 3;
559   errorstate = good;
560   tim_get.get_date(is_it03, end, iss, errorstate, &time03);
561   VERIFY( time03.tm_year == 3 );
562   VERIFY( time03.tm_mon == time_bday.tm_mon );
563   VERIFY( time03.tm_mday == time_bday.tm_mday );
564   VERIFY( errorstate == ios_base::failbit );
565   VERIFY( *is_it03 == 'd');
566
567   // inspection of named locales, de_DE
568   iss.imbue(loc_de);
569   iss.str("04.04.1971");
570   iterator_type is_it10(iss);
571   tm time10;
572   errorstate = good;
573   tim_get.get_date(is_it10, end, iss, errorstate, &time10);
574   VERIFY( time10.tm_mon == time_bday.tm_mon );
575   VERIFY( time10.tm_mday == time_bday.tm_mday );
576   VERIFY( time10.tm_year == time_bday.tm_year );
577   VERIFY( errorstate == ios_base::eofbit );
578
579   // inspection of named locales, en_HK
580   iss.imbue(loc_hk);
581   iss.str("Sunday, April 04, 1971"); 
582   iterator_type is_it20(iss);
583   tm time20;
584   errorstate = good;
585   tim_get.get_date(is_it20, end, iss, errorstate, &time20);
586   VERIFY( time20.tm_mon == time_bday.tm_mon );
587   VERIFY( time20.tm_mday == time_bday.tm_mday );
588   VERIFY( time20.tm_year == time_bday.tm_year );
589   VERIFY( errorstate == ios_base::eofbit );
590 }
591
592 void test06()
593 {
594   using namespace std;
595   bool test = true;
596
597   // Check time_get works with other iterators besides streambuf
598   // input iterators.
599   typedef string::const_iterator iter_type;
600   typedef time_get<char, iter_type> time_get_type;
601   const ios_base::iostate goodbit = ios_base::goodbit;
602   const ios_base::iostate eofbit = ios_base::eofbit;
603   ios_base::iostate err = goodbit;
604   const locale loc_c = locale::classic();
605   // Cindy Sherman's Untitled Film Stills
606   // June 26-September 2, 1997
607   const string str = "12:00:00 06/26/97 Tuesday September 1997 Cindy Sherman";
608  
609   // Create "C" time objects
610   const tm time_sanity = { 0, 0, 12, 26, 5, 97, 2 };
611   tm tm1;
612
613   istringstream iss; 
614   iss.imbue(locale(loc_c, new time_get_type));
615
616   // Iterator advanced, state, output.
617   const time_get_type& tg = use_facet<time_get_type>(iss.getloc());
618
619   // 01 get_time
620   // 02 get_date
621   // 03 get_weekday
622   // 04 get_monthname
623   // 05 get_year
624
625   // 01 get_time
626   string res1;
627   err = goodbit;
628   iter_type end1 = tg.get_time(str.begin(), str.end(), iss, err, &tm1);
629   string rem1(end1, str.end());
630   VERIFY( err == goodbit );
631   VERIFY( tm1.tm_sec == time_sanity.tm_sec );
632   VERIFY( tm1.tm_min == time_sanity.tm_min );
633   VERIFY( tm1.tm_hour == time_sanity.tm_hour );
634   VERIFY( rem1 ==  " 06/26/97 Tuesday September 1997 Cindy Sherman" );
635
636   // 02 get_date
637   string res2;
638   err = goodbit;
639   // White space is not eaten, so manually increment past it.
640   iter_type end2 = tg.get_date(++end1, str.end(), iss, err, &tm1);
641   string rem2(end2, str.end());
642   VERIFY( err == goodbit );
643   VERIFY( tm1.tm_year == time_sanity.tm_year );
644   VERIFY( tm1.tm_mon == time_sanity.tm_mon );
645   VERIFY( tm1.tm_mday == time_sanity.tm_mday );
646   VERIFY( rem2 ==  " Tuesday September 1997 Cindy Sherman" );
647
648   // 03 get_weekday
649   string res3;
650   err = goodbit;
651   // White space is not eaten, so manually increment past it.
652   iter_type end3 = tg.get_weekday(++end2, str.end(), iss, err, &tm1);
653   string rem3(end3, str.end());
654   VERIFY( err == goodbit );
655   VERIFY( tm1.tm_wday == time_sanity.tm_wday );
656   VERIFY( rem3 ==  " September 1997 Cindy Sherman" );
657
658   // 04 get_monthname
659   string res4;
660   err = goodbit;
661   // White space is not eaten, so manually increment past it.
662   iter_type end4 = tg.get_monthname(++end3, str.end(), iss, err, &tm1);
663   string rem4(end4, str.end());
664   VERIFY( err == goodbit );
665   VERIFY( tm1.tm_mon == 8 );
666   VERIFY( rem4 ==  " 1997 Cindy Sherman" );
667
668   // 05 get_year
669   string res5;
670   err = goodbit;
671   // White space is not eaten, so manually increment past it.
672   iter_type end5 = tg.get_year(++end4, str.end(), iss, err, &tm1);
673   string rem5(end5, str.end());
674   VERIFY( err == goodbit );
675   VERIFY( tm1.tm_year == time_sanity.tm_year );
676   VERIFY( rem5 ==  " Cindy Sherman" );
677 }
678
679 // libstdc++/5280
680 void test07()
681 {
682 #ifdef _GLIBCPP_HAVE_SETENV 
683   // Set the global locale to non-"C".
684   std::locale loc_de("de_DE");
685   std::locale::global(loc_de);
686
687   // Set LANG environment variable to de_DE.
688   const char* oldLANG = getenv("LANG");
689   if (!setenv("LANG", "de_DE", 1))
690     {
691       test01();
692       test02();
693       test03();
694       test04();
695       test05();
696       test06();
697       setenv("LANG", oldLANG ? oldLANG : "", 1);
698     }
699 #endif
700 }
701
702 int main()
703 {
704   test01();
705   test02();
706   test03();
707   test04();
708   test05();
709   
710   test06();
711   
712   test07();
713   return 0;
714 }