]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/1.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / inserters_extractors / wchar_t / 1.cc
1 // 1999-07-01 bkoz
2
3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009
4 // Free Software Foundation, Inc.
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 // 21.3.7.9 inserters and extractors
22
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.
26
27 #include <string>
28 #include <stdexcept>
29 #include <sstream>
30 #include <fstream>
31 #include <iostream>
32 #include <testsuite_hooks.h>
33
34 bool test01(void)
35 {
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;
40
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;
47 std::wstring str10;
48
49 // istream& operator>>(istream&, string&)
50 std::wistringstream istrs01(str01);
51 istrs01 >> str10;
52 VERIFY( str10 == str02 );
53 try
54 {
55 std::wistringstream::int_type i01 = istrs01.peek(); //a-boo
56 VERIFY( std::wistringstream::traits_type::to_char_type(i01) == L' ' );
57 }
58 catch(std::exception& fail)
59 {
60 VERIFY( false ); // shouldn't throw
61 }
62
63 istrs01.clear();
64 istrs01 >> str10;
65 VERIFY( str10 == str03 );
66 istrs01.clear();
67 istrs01 >> str10;
68 VERIFY( str10 == str04 ); // sentry picks out the white spaces. .
69
70 std::wistringstream istrs02(str05); // empty
71 istrs02 >> str10;
72 VERIFY( str10 == str04 );
73
74 // istream& getline(istream&, string&, char)
75 // istream& getline(istream&, string&)
76 try
77 {
78 istrs01.clear();
79 getline(istrs01, str10);
80 VERIFY( !istrs01.fail() );
81 VERIFY( !istrs01.eof() );
82 VERIFY( istrs01.good() );
83 VERIFY( str10 == L" bay" );
84 }
85 catch(std::exception& fail)
86 {
87 VERIFY( false ); // shouldn't throw
88 }
89
90 try
91 {
92 istrs01.clear();
93 getline(istrs01, str10, L'\t');
94 VERIFY( !istrs01.fail() );
95 VERIFY( !istrs01.eof() );
96 VERIFY( istrs01.good() );
97 VERIFY( str10 == str05 );
98 }
99 catch(std::exception& fail)
100 {
101 VERIFY( false ); // shouldn't throw
102 }
103
104 try
105 {
106 istrs01.clear();
107 getline(istrs01, str10, L'\t');
108 VERIFY( !istrs01.fail() );
109 VERIFY( !istrs01.eof() );
110 VERIFY( istrs01.good() );
111 VERIFY( str10 == str05 );
112 }
113 catch(std::exception& fail)
114 {
115 VERIFY( false ); // shouldn't throw
116 }
117
118 try
119 {
120 istrs01.clear();
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" );
126 }
127 catch(std::exception& fail)
128 {
129 VERIFY( false ); // shouldn't throw
130 }
131
132 try
133 {
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" );
138 }
139 catch(std::exception& fail)
140 {
141 VERIFY( false ); // shouldn't throw
142 }
143
144 // ostream& operator<<(ostream&, const basic_string&)
145 std::wostringstream ostrs01;
146 try
147 {
148 ostrs01 << str01;
149 VERIFY( ostrs01.str() == str01 );
150 }
151 catch(std::exception& fail)
152 {
153 VERIFY( false );
154 }
155
156 std::wstring hello_world;
157 std::wcout << hello_world;
158 return test;
159 }
160
161 int main()
162 {
163 test01();
164 return 0;
165 }