]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_stringstream / str / wchar_t / 1.cc
1 // Copyright (C) 2004-2020 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 27.7.6 member functions (stringstream_members)
19
20 #include <sstream>
21 #include <testsuite_hooks.h>
22
23 void test01()
24 {
25 std::wstringstream is01;
26 const std::wstring str00;
27 const std::wstring str01 = L"123";
28 std::wstring str02;
29 const int i01 = 123;
30 int a = 0, b = 0;
31
32 std::ios_base::iostate state1, state2, stateeof;
33 stateeof = std::ios_base::eofbit;
34
35 // string str() const
36 str02 = is01.str();
37 VERIFY( str00 == str02 );
38
39 // void str(const basic_string&)
40 is01.str(str01);
41 str02 = is01.str();
42 VERIFY( str01 == str02 );
43 state1 = is01.rdstate();
44 is01 >> a;
45 state2 = is01.rdstate();
46 VERIFY( a == i01 );
47 // 22.2.2.1.2 num_get virtual functions
48 // p 13
49 // in any case, if stage 2 processing was terminated by the test for
50 // in == end then err != ios_base::eofbit is performed.
51 VERIFY( state1 != state2 );
52 VERIFY( state2 == stateeof );
53
54 is01.str(str01);
55 is01 >> b;
56 VERIFY( b != a );
57 // as is01.good() is false, istream::sentry blocks extraction.
58
59 is01.clear();
60 state1 = is01.rdstate();
61 is01 >> b;
62 state2 = is01.rdstate();
63 VERIFY( b == a );
64 VERIFY( state1 != state2 );
65 VERIFY( state2 == stateeof );
66 }
67
68 int main()
69 {
70 test01();
71 return 0;
72 }