]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_stringstream / assign / 1.cc
1 // { dg-do run { target c++11 } }
2
3 // Copyright (C) 2014-2019 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 // 27.8.5.2 Assign and swap [stringstream.assign]
21
22 #include <sstream>
23 #include <string>
24 #include <testsuite_hooks.h>
25
26 void
27 test01()
28 {
29 std::stringstream s1;
30 s1 << "absence of a signal";
31 std::string s;
32 s1 >> s;
33
34 std::stringstream s2;
35 s2 = std::move(s1);
36 s2 >> s;
37 VERIFY(s == "of");
38
39 std::stringstream s3;
40 s3.swap(s2);
41 s3 >> s;
42 VERIFY(s == "a");
43
44 swap(s1, s3);
45 s1 >> s;
46 VERIFY(s == "signal");
47
48 s2 << "should never be used as a signal";
49 s1 = std::move(s2);
50 getline(s1, s);
51 VERIFY(s == "should never be used as a signal");
52 s3 = std::move(s1);
53 VERIFY(s3.eof());
54 }
55
56 void test02()
57 {
58 std::stringstream s0;
59 s0 << " 1234.5 ";
60 std::stringstream s;
61 s = std::move(s0);
62 char c{};
63 s >> c;
64 VERIFY( c == '1' );
65 int i{};
66 s >> i;
67 VERIFY( i == 234 );
68 double d{};
69 s >> d;
70 VERIFY( d == .5 );
71 }
72
73 void test03()
74 {
75 #ifdef _GLIBCXX_USE_WCHAR_T
76 std::wstringstream s0;
77 s0 << L" 1234.5 ";
78 std::wstringstream s;
79 s = std::move(s0);
80 s.swap(s0);
81 swap(s, s0);
82 wchar_t c{};
83 s >> c;
84 VERIFY( c == L'1' );
85 int i{};
86 s >> i;
87 VERIFY( i == 234 );
88 double d{};
89 s >> d;
90 VERIFY( d == .5 );
91 #endif
92 }
93
94 int
95 main()
96 {
97 test01();
98 test02();
99 test03();
100 }