X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=libstdc%2B%2B-v3%2Ftestsuite%2F22_locale%2Fnum_get%2Fget%2Fwchar_t%2F4.cc;fp=libstdc%2B%2B-v3%2Ftestsuite%2F22_locale%2Fnum_get%2Fget%2Fwchar_t%2F4.cc;h=7fcc3f943c25304318910a4d9a9d8662295bb15a;hb=6fed43773c9b0ce596dca5686f37ac3fc0fa11c0;hp=0000000000000000000000000000000000000000;hpb=27b11d56b743098deb193d510b337ba22dc52e5c;p=msp430-gcc.git diff --git a/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/4.cc b/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/4.cc new file mode 100644 index 00000000..7fcc3f94 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/4.cc @@ -0,0 +1,110 @@ +// 2001-11-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 22.2.2.1.1 num_get members + +#include +#include +#include + +// 2002-01-10 David Seymour +// libstdc++/5331 +void test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // Check num_get works with other iterators besides streambuf + // output iterators. (As long as output_iterator requirements are met.) + typedef wstring::const_iterator iter_type; + typedef num_get num_get_type; + const ios_base::iostate goodbit = ios_base::goodbit; + ios_base::iostate err = ios_base::goodbit; + const locale loc_c = locale::classic(); + const wstring str(L"20000106 Elizabeth Durack"); + const wstring str2(L"0 true 0xbffff74c Durack"); + + wistringstream iss; // need an ios, add my num_get facet + iss.imbue(locale(loc_c, new num_get_type)); + + // Iterator advanced, state, output. + const num_get_type& ng = use_facet(iss.getloc()); + + // 01 get(long) + // 02 get(long double) + // 03 get(bool) + // 04 get(void*) + + // 01 get(long) + long i = 0; + err = goodbit; + iter_type end1 = ng.get(str.begin(), str.end(), iss, err, i); + wstring rem1(end1, str.end()); + VERIFY( err == goodbit ); + VERIFY( i == 20000106); + VERIFY( rem1 == L" Elizabeth Durack" ); + + // 02 get(long double) + long double ld = 0.0; + err = goodbit; + iter_type end2 = ng.get(str.begin(), str.end(), iss, err, ld); + wstring rem2(end2, str.end()); + VERIFY( err == goodbit ); + VERIFY( ld == 20000106); + VERIFY( rem2 == L" Elizabeth Durack" ); + + // 03 get(bool) + bool b = 1; + iss.clear(); + err = goodbit; + iter_type end3 = ng.get(str2.begin(), str2.end(), iss, err, b); + wstring rem3(end3, str2.end()); + VERIFY( err == goodbit ); + VERIFY( b == 0 ); + VERIFY( rem3 == L" true 0xbffff74c Durack" ); + + iss.clear(); + err = goodbit; + iss.setf(ios_base::boolalpha); + iter_type end4 = ng.get(++end3, str2.end(), iss, err, b); + wstring rem4(end4, str2.end()); + VERIFY( err == goodbit ); + VERIFY( b == true ); + VERIFY( rem4 == L" 0xbffff74c Durack" ); + + // 04 get(void*) + void* v; + iss.clear(); + err = goodbit; + iss.setf(ios_base::fixed, ios_base::floatfield); + iter_type end5 = ng.get(++end4, str2.end(), iss, err, v); + wstring rem5(end5, str2.end()); + VERIFY( err == goodbit ); + VERIFY( b == true ); + VERIFY( rem5 == L" Durack" ); +} + +int main() +{ + test04(); + return 0; +} + + +// Kathleen Hannah, humanitarian, woman, art-thief