]>
Commit | Line | Data |
---|---|---|
61f1ed59 PC |
1 | // 1999-07-01 bkoz |
2 | ||
3 | // Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. | |
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. | |
10 | ||
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. | |
15 | ||
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. | |
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 = true; | |
37 | typedef std::wstring::size_type csize_type; | |
38 | typedef std::wstring::const_reference cref; | |
39 | typedef std::wstring::reference ref; | |
40 | csize_type npos = std::wstring::npos; | |
41 | csize_type csz01, csz02; | |
42 | ||
43 | const std::wstring str01(L"sailing grand traverse bay\n" | |
44 | L"\t\t\t from Elk Rapids to the point reminds me of miles"); | |
45 | const std::wstring str02(L"sailing"); | |
46 | const std::wstring str03(L"grand"); | |
47 | const std::wstring str04(L"traverse"); | |
48 | const std::wstring str05; | |
49 | std::wstring str10; | |
50 | ||
51 | // istream& operator>>(istream&, string&) | |
52 | std::wistringstream istrs01(str01); | |
53 | istrs01 >> str10; | |
54 | VERIFY( str10 == str02 ); | |
55 | try | |
56 | { | |
57 | std::wistringstream::int_type i01 = istrs01.peek(); //a-boo | |
58 | VERIFY( std::wistringstream::traits_type::to_char_type(i01) == L' ' ); | |
59 | } | |
60 | catch(std::exception& fail) | |
61 | { | |
62 | VERIFY( false ); // shouldn't throw | |
63 | } | |
64 | ||
65 | istrs01.clear(); | |
66 | istrs01 >> str10; | |
67 | VERIFY( str10 == str03 ); | |
68 | istrs01.clear(); | |
69 | istrs01 >> str10; | |
70 | VERIFY( str10 == str04 ); // sentry picks out the white spaces. . | |
71 | ||
72 | std::wistringstream istrs02(str05); // empty | |
73 | istrs02 >> str10; | |
74 | VERIFY( str10 == str04 ); | |
75 | ||
76 | // istream& getline(istream&, string&, char) | |
77 | // istream& getline(istream&, string&) | |
78 | try | |
79 | { | |
80 | istrs01.clear(); | |
81 | getline(istrs01, str10); | |
82 | VERIFY( !istrs01.fail() ); | |
83 | VERIFY( !istrs01.eof() ); | |
84 | VERIFY( istrs01.good() ); | |
85 | VERIFY( str10 == L" bay" ); | |
86 | } | |
87 | catch(std::exception& fail) | |
88 | { | |
89 | VERIFY( false ); // shouldn't throw | |
90 | } | |
91 | ||
92 | try | |
93 | { | |
94 | istrs01.clear(); | |
95 | getline(istrs01, str10, L'\t'); | |
96 | VERIFY( !istrs01.fail() ); | |
97 | VERIFY( !istrs01.eof() ); | |
98 | VERIFY( istrs01.good() ); | |
99 | VERIFY( str10 == str05 ); | |
100 | } | |
101 | catch(std::exception& fail) | |
102 | { | |
103 | VERIFY( false ); // shouldn't throw | |
104 | } | |
105 | ||
106 | try | |
107 | { | |
108 | istrs01.clear(); | |
109 | getline(istrs01, str10, L'\t'); | |
110 | VERIFY( !istrs01.fail() ); | |
111 | VERIFY( !istrs01.eof() ); | |
112 | VERIFY( istrs01.good() ); | |
113 | VERIFY( str10 == str05 ); | |
114 | } | |
115 | catch(std::exception& fail) | |
116 | { | |
117 | VERIFY( false ); // shouldn't throw | |
118 | } | |
119 | ||
120 | try | |
121 | { | |
122 | istrs01.clear(); | |
123 | getline(istrs01, str10, L'.'); | |
124 | VERIFY( !istrs01.fail() ); | |
125 | VERIFY( istrs01.eof() ); | |
126 | VERIFY( !istrs01.good() ); | |
127 | VERIFY( str10 == L"\t from Elk Rapids to the point reminds me of miles" ); | |
128 | } | |
129 | catch(std::exception& fail) | |
130 | { | |
131 | VERIFY( false ); // shouldn't throw | |
132 | } | |
133 | ||
134 | try | |
135 | { | |
136 | getline(istrs02, str10); | |
137 | VERIFY( istrs02.fail() ); | |
138 | VERIFY( istrs02.eof() ); | |
139 | VERIFY( str10 == L"\t from Elk Rapids to the point reminds me of miles" ); | |
140 | } | |
141 | catch(std::exception& fail) | |
142 | { | |
143 | VERIFY( false ); // shouldn't throw | |
144 | } | |
145 | ||
146 | // ostream& operator<<(ostream&, const basic_string&) | |
147 | std::wostringstream ostrs01; | |
148 | try | |
149 | { | |
150 | ostrs01 << str01; | |
151 | VERIFY( ostrs01.str() == str01 ); | |
152 | } | |
153 | catch(std::exception& fail) | |
154 | { | |
155 | VERIFY( false ); | |
156 | } | |
157 | ||
158 | std::wstring hello_world; | |
159 | std::wcout << hello_world; | |
61f1ed59 PC |
160 | return test; |
161 | } | |
162 | ||
163 | int main() | |
164 | { | |
165 | test01(); | |
166 | return 0; | |
167 | } |