c6bfa9a9dc9c414483755b253fb663d35ce1b7a5
[platform/upstream/gcc48.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / inserters_extractors / wchar_t / 1.cc
1 // 1999-07-01 bkoz
2
3 // Copyright (C) 1999-2013 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 3, 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 COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 21.3.7.9 inserters and extractors
21
22 // NB: This file is predicated on sstreams, istreams, and ostreams
23 // working, not to mention other major details like char_traits, and
24 // all of the string class.
25
26 #include <string>
27 #include <stdexcept>
28 #include <sstream>
29 #include <fstream>
30 #include <iostream>
31 #include <testsuite_hooks.h>
32
33 bool test01(void)
34 {
35   bool test __attribute__((unused)) = true;
36   typedef std::wstring::size_type csize_type;
37   typedef std::wstring::const_reference cref;
38   typedef std::wstring::reference ref;
39
40   const std::wstring str01(L"sailing grand traverse bay\n"
41                L"\t\t\t    from Elk Rapids to the point reminds me of miles");
42   const std::wstring str02(L"sailing");
43   const std::wstring str03(L"grand");
44   const std::wstring str04(L"traverse");
45   const std::wstring str05;
46   std::wstring str10;
47   
48   // istream& operator>>(istream&, string&)
49   std::wistringstream istrs01(str01);
50   istrs01 >> str10;
51   VERIFY( str10 == str02 );
52   try 
53     {
54       std::wistringstream::int_type i01 = istrs01.peek(); //a-boo
55       VERIFY( std::wistringstream::traits_type::to_char_type(i01) == L' ' );
56     }
57   catch(std::exception& fail) 
58     {
59       VERIFY( false ); // shouldn't throw
60     }
61
62   istrs01.clear();
63   istrs01 >> str10; 
64   VERIFY( str10 == str03 ); 
65   istrs01.clear();
66   istrs01 >> str10; 
67   VERIFY( str10 == str04 ); // sentry picks out the white spaces. . 
68
69   std::wistringstream istrs02(str05); // empty
70   istrs02 >> str10;
71   VERIFY( str10 == str04 );
72  
73   // istream& getline(istream&, string&, char)
74   // istream& getline(istream&, string&)
75   try 
76     {
77       istrs01.clear();
78       getline(istrs01, str10);
79       VERIFY( !istrs01.fail() );
80       VERIFY( !istrs01.eof() );
81       VERIFY( istrs01.good() );
82       VERIFY( str10 == L" bay" );
83     }
84   catch(std::exception& fail) 
85     {
86       VERIFY( false ); // shouldn't throw
87     }
88
89   try 
90     {
91       istrs01.clear();
92       getline(istrs01, str10, L'\t');
93       VERIFY( !istrs01.fail() );
94       VERIFY( !istrs01.eof() );
95       VERIFY( istrs01.good() );
96       VERIFY( str10 == str05 );
97     }
98   catch(std::exception& fail) 
99     {
100       VERIFY( false ); // shouldn't throw
101     }
102   
103   try 
104     {
105       istrs01.clear();
106       getline(istrs01, str10, L'\t');
107       VERIFY( !istrs01.fail() );
108       VERIFY( !istrs01.eof() );
109       VERIFY( istrs01.good() );
110       VERIFY( str10 == str05 );
111     }
112   catch(std::exception& fail) 
113     {
114       VERIFY( false ); // shouldn't throw
115     }
116   
117   try 
118     {
119       istrs01.clear();
120       getline(istrs01, str10, L'.');
121       VERIFY( !istrs01.fail() );
122       VERIFY( istrs01.eof() );
123       VERIFY( !istrs01.good() );
124       VERIFY( str10 == L"\t    from Elk Rapids to the point reminds me of miles" );
125     }
126   catch(std::exception& fail) 
127     {
128       VERIFY( false ); // shouldn't throw
129     }
130
131   try 
132     {
133       getline(istrs02, str10);
134       VERIFY( istrs02.fail() );
135       VERIFY( istrs02.eof() );
136       VERIFY( str10 == L"\t    from Elk Rapids to the point reminds me of miles" );
137     }
138   catch(std::exception& fail) 
139     {
140       VERIFY( false ); // shouldn't throw
141     }
142   
143   // ostream& operator<<(ostream&, const basic_string&)
144   std::wostringstream ostrs01;
145   try 
146     {
147       ostrs01 << str01;
148       VERIFY( ostrs01.str() == str01 );
149     }
150   catch(std::exception& fail) 
151     {
152       VERIFY( false );
153     }
154   
155   std::wstring hello_world;
156   std::wcout << hello_world;
157   return test;
158 }
159
160 int main()
161
162   test01();
163   return 0;
164 }