1// 2001-09-21 Benjamin Kosnik <bkoz@redhat.com> 2 3// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009 4// Free Software Foundation 5// 6// This file is part of the GNU ISO C++ Library. This library is free 7// software; you can redistribute it and/or modify it under the 8// terms of the GNU General Public License as published by the 9// Free Software Foundation; either version 3, or (at your option) 10// any later version. 11 12// This library is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17// You should have received a copy of the GNU General Public License along 18// with this library; see the file COPYING3. If not see 19// <http://www.gnu.org/licenses/>. 20 21// 22.2.5.1.1 time_get members 22 23#include <locale> 24#include <sstream> 25#include <testsuite_hooks.h> 26 27void test01() 28{ 29 using namespace std; 30 bool test __attribute__((unused)) = true; 31 32 typedef istreambuf_iterator<char> 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 = __gnu_test::test_tm(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 istringstream iss; 50 iss.imbue(loc_c); 51 const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc()); 52 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 ); 60 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 ); 68 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 == ' ' ); 78 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 ); 89 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 == ' ' ); 99 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' ); 110} 111 112int main() 113{ 114 test01(); 115 return 0; 116} 117