Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libstdc++-v3 / testsuite / 22_locale / time_get / get_monthname / char / 1.cc
blob5de1464dc7a56aa83ce95fab12a0170004885a23
1 // 2001-09-21 Benjamin Kosnik <bkoz@redhat.com>
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.
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.
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.
21 // 22.2.5.1.1 time_get members
23 #include <locale>
24 #include <sstream>
25 #include <testsuite_hooks.h>
27 void test01()
29 using namespace std;
30 bool test __attribute__((unused)) = true;
32 typedef istreambuf_iterator<char> iterator_type;
34 const ios_base::iostate good = ios_base::goodbit;
35 ios_base::iostate errorstate = good;
37 // basic construction
38 locale loc_c = locale::classic();
40 // create "C" time objects
41 const tm time_bday = { 0, 0, 12, 4, 3, 71, 0, 93, 0 };
43 // iter_type
44 // get_monthname(iter_type, iter_type, ios_base&,
45 // ios_base::iostate&, tm*) const
47 // sanity checks for "C" locale
48 iterator_type end;
49 istringstream iss;
50 iss.imbue(loc_c);
51 const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc());
53 iss.str("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 );
61 iss.str("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 );
69 iss.str("Apr ");
70 iterator_type is_it03(iss);
71 tm time03;
72 errorstate = good;
73 iterator_type ret03 = tim_get.get_monthname(is_it03, end, iss, errorstate,
74 &time03);
75 VERIFY( time03.tm_mon == time_bday.tm_mon );
76 VERIFY( errorstate == good );
77 VERIFY( *ret03 == ' ' );
79 iss.str("Aar");
80 iterator_type is_it04(iss);
81 tm time04;
82 time04.tm_mon = 5;
83 errorstate = good;
84 iterator_type ret04 = tim_get.get_monthname(is_it04, end, iss, errorstate,
85 &time04);
86 VERIFY( time04.tm_mon == 5 );
87 VERIFY( *ret04 == 'a' );
88 VERIFY( errorstate == ios_base::failbit );
90 iss.str("December ");
91 iterator_type is_it05(iss);
92 tm time05;
93 errorstate = good;
94 iterator_type ret05 = tim_get.get_monthname(is_it05, end, iss, errorstate,
95 &time05);
96 VERIFY( time05.tm_mon == 11 );
97 VERIFY( errorstate == good );
98 VERIFY( *ret05 == ' ' );
100 iss.str("Decelember ");
101 iterator_type is_it06(iss);
102 tm time06;
103 time06.tm_mon = 4;
104 errorstate = good;
105 iterator_type ret06 = tim_get.get_monthname(is_it06, end, iss, errorstate,
106 &time06);
107 VERIFY( time06.tm_mon == 4 );
108 VERIFY( errorstate == ios_base::failbit );
109 VERIFY( *ret06 == 'l' );
112 int main()
114 test01();
115 return 0;