3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009
4 // Free Software Foundation, Inc.
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)
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.
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/>.
21 // 21.3.7.9 inserters and extractors
23 // NB: This file is predicated on sstreams, istreams, and ostreams
24 // working, not to mention other major details like char_traits, and
25 // all of the string class.
32 #include <testsuite_hooks.h>
36 bool test __attribute__((unused)) = true;
37 typedef std::wstring::size_type csize_type;
38 typedef std::wstring::const_reference cref;
39 typedef std::wstring::reference ref;
41 const std::wstring str01(L"sailing grand traverse bay\n"
42 L"\t\t\t from Elk Rapids to the point reminds me of miles");
43 const std::wstring str02(L"sailing");
44 const std::wstring str03(L"grand");
45 const std::wstring str04(L"traverse");
46 const std::wstring str05;
49 // istream& operator>>(istream&, string&)
50 std::wistringstream istrs01(str01);
52 VERIFY( str10 == str02 );
55 std::wistringstream::int_type i01 = istrs01.peek(); //a-boo
56 VERIFY( std::wistringstream::traits_type::to_char_type(i01) == L' ' );
58 catch(std::exception& fail)
60 VERIFY( false ); // shouldn't throw
65 VERIFY( str10 == str03 );
68 VERIFY( str10 == str04 ); // sentry picks out the white spaces. .
70 std::wistringstream istrs02(str05); // empty
72 VERIFY( str10 == str04 );
74 // istream& getline(istream&, string&, char)
75 // istream& getline(istream&, string&)
79 getline(istrs01, str10);
80 VERIFY( !istrs01.fail() );
81 VERIFY( !istrs01.eof() );
82 VERIFY( istrs01.good() );
83 VERIFY( str10 == L" bay" );
85 catch(std::exception& fail)
87 VERIFY( false ); // shouldn't throw
93 getline(istrs01, str10, L'\t');
94 VERIFY( !istrs01.fail() );
95 VERIFY( !istrs01.eof() );
96 VERIFY( istrs01.good() );
97 VERIFY( str10 == str05 );
99 catch(std::exception& fail)
101 VERIFY( false ); // shouldn't throw
107 getline(istrs01, str10, L'\t');
108 VERIFY( !istrs01.fail() );
109 VERIFY( !istrs01.eof() );
110 VERIFY( istrs01.good() );
111 VERIFY( str10 == str05 );
113 catch(std::exception& fail)
115 VERIFY( false ); // shouldn't throw
121 getline(istrs01, str10, L'.');
122 VERIFY( !istrs01.fail() );
123 VERIFY( istrs01.eof() );
124 VERIFY( !istrs01.good() );
125 VERIFY( str10 == L"\t from Elk Rapids to the point reminds me of miles" );
127 catch(std::exception& fail)
129 VERIFY( false ); // shouldn't throw
134 getline(istrs02, str10);
135 VERIFY( istrs02.fail() );
136 VERIFY( istrs02.eof() );
137 VERIFY( str10 == L"\t from Elk Rapids to the point reminds me of miles" );
139 catch(std::exception& fail)
141 VERIFY( false ); // shouldn't throw
144 // ostream& operator<<(ostream&, const basic_string&)
145 std::wostringstream ostrs01;
149 VERIFY( ostrs01.str() == str01 );
151 catch(std::exception& fail)
156 std::wstring hello_world;
157 std::wcout << hello_world;