]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/time_get/get_monthname/wchar_t/1.cc
streambuf_iterator.h (class istreambuf_iterator): Consistently use _M_c to cache...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / time_get / get_monthname / wchar_t / 1.cc
1 // 2001-09-21 Benjamin Kosnik <bkoz@redhat.com>
2
3 // Copyright (C) 2001, 2002, 2003, 2004 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 void test01()
28 {
29 using namespace std;
30 bool test __attribute__((unused)) = true;
31
32 typedef istreambuf_iterator<wchar_t> iterator_type;
33
34 const ios_base::iostate good = ios_base::goodbit;
35 ios_base::iostate errorstate = good;
36
37 // basic construction
38 locale loc_c = locale::classic();
39
40 // create "C" time objects
41 const tm time_bday = { 0, 0, 12, 4, 3, 71, 0, 93, 0 };
42
43 // iter_type
44 // get_monthname(iter_type, iter_type, ios_base&,
45 // ios_base::iostate&, tm*) const
46
47 // sanity checks for "C" locale
48 iterator_type end;
49 wistringstream iss;
50 iss.imbue(loc_c);
51 const time_get<wchar_t>& tim_get = use_facet<time_get<wchar_t> >(iss.getloc());
52
53 iss.str(L"April");
54 iterator_type is_it01(iss);
55 tm time01;
56 errorstate = good;
57 tim_get.get_monthname(is_it01, end, iss, errorstate, &time01);
58 VERIFY( time01.tm_mon == time_bday.tm_mon );
59 VERIFY( errorstate == ios_base::eofbit );
60
61 iss.str(L"Apr");
62 iterator_type is_it02(iss);
63 tm time02;
64 errorstate = good;
65 tim_get.get_monthname(is_it02, end, iss, errorstate, &time02);
66 VERIFY( time02.tm_mon == time_bday.tm_mon );
67 VERIFY( errorstate == ios_base::eofbit );
68
69 iss.str(L"Apr ");
70 iterator_type is_it03(iss);
71 tm time03;
72 errorstate = good;
73 tim_get.get_monthname(is_it03, end, iss, errorstate, &time03);
74 VERIFY( time03.tm_mon == time_bday.tm_mon );
75 VERIFY( errorstate == good );
76 VERIFY( *is_it03 == L' ' );
77
78 iss.str(L"Aar");
79 iterator_type is_it04(iss);
80 tm time04;
81 time04.tm_mon = 5;
82 errorstate = good;
83 tim_get.get_monthname(is_it04, end, iss, errorstate, &time04);
84 VERIFY( time04.tm_mon == 5 );
85 VERIFY( *is_it04 == L'a' );
86 VERIFY( errorstate == ios_base::failbit );
87
88 iss.str(L"December ");
89 iterator_type is_it05(iss);
90 tm time05;
91 errorstate = good;
92 tim_get.get_monthname(is_it05, end, iss, errorstate, &time05);
93 VERIFY( time05.tm_mon == 11 );
94 VERIFY( errorstate == good );
95 VERIFY( *is_it05 == L' ' );
96
97 iss.str(L"Decelember ");
98 iterator_type is_it06(iss);
99 tm time06;
100 time06.tm_mon = 4;
101 errorstate = good;
102 tim_get.get_monthname(is_it06, end, iss, errorstate, &time06);
103 VERIFY( time06.tm_mon == 4 );
104 VERIFY( errorstate == ios_base::failbit );
105 VERIFY( *is_it06 == L'l' );
106 }
107
108 int main()
109 {
110 test01();
111 return 0;
112 }