]>
Commit | Line | Data |
---|---|---|
99dee823 | 1 | // Copyright (C) 2020-2021 Free Software Foundation, Inc. |
95cb0fc8 JW |
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 | // 29.8.3.4 basic_istringstream member functions [istringstream.members] | |
19 | ||
20 | // { dg-options "-std=gnu++2a" } | |
21 | // { dg-do run { target c++2a } } | |
22 | // { dg-require-effective-target cxx11-abi } | |
23 | ||
24 | #include <sstream> | |
25 | #include <testsuite_hooks.h> | |
26 | #include <testsuite_allocator.h> | |
27 | ||
28 | void test01() | |
29 | { | |
30 | const std::string s0 = "this is not a short string"; | |
31 | std::istringstream ss; | |
32 | ss.str(s0); | |
33 | VERIFY( ss.str() == s0 ); | |
34 | VERIFY( ss.str() == s0 ); | |
35 | ||
36 | using Alloc = __gnu_test::uneq_allocator<char>; | |
37 | const Alloc a1(1); | |
38 | std::basic_string<char, std::char_traits<char>, Alloc> s1 = ss.str(a1); | |
39 | VERIFY( s1.get_allocator() == a1 ); | |
40 | VERIFY( ss.str(a1).get_allocator() == a1 ); | |
41 | VERIFY( ss.str(a1) == s1 ); | |
42 | VERIFY( std::move(ss).str(a1) == s1 ); | |
43 | VERIFY( std::move(ss).str(a1) == s1 ); | |
44 | ||
45 | const Alloc a2(2); | |
46 | VERIFY( ss.str(a2).get_allocator() == a2 ); | |
47 | VERIFY( ss.str(a2) == s1 ); | |
48 | ||
49 | VERIFY( std::move(ss).str() == s0 ); | |
50 | VERIFY( std::move(ss).str().empty() ); | |
51 | VERIFY( ss.str().empty() ); | |
52 | VERIFY( ss.str(a1).empty() ); | |
53 | } | |
54 | ||
55 | void test02() | |
56 | { | |
57 | std::istringstream ss("123"); | |
58 | std::string str = "ABCDEF"; | |
59 | ss.str(str); | |
60 | VERIFY( ss.str() == str ); | |
61 | VERIFY( std::move(ss).str() == str ); | |
62 | VERIFY( std::move(ss).str().empty() ); | |
63 | } | |
64 | ||
65 | void test03() | |
66 | { | |
67 | std::istringstream ss; | |
68 | using Alloc = __gnu_test::tracker_allocator<char>; | |
69 | using Str = std::basic_string<char, std::char_traits<char>, Alloc>; | |
70 | Str s1 = "string that is not short, quite long even"; | |
71 | auto count1 = __gnu_test::tracker_allocator_counter::get_allocation_count(); | |
72 | ss.str(s1); | |
73 | auto count2 = __gnu_test::tracker_allocator_counter::get_allocation_count(); | |
74 | VERIFY( count1 == count2 ); | |
75 | VERIFY( ss.str() == s1.c_str() ); | |
76 | } | |
77 | ||
78 | void test04() | |
79 | { | |
80 | std::istringstream ss; | |
81 | const std::string str = "Another quite long string, not at all short"; | |
82 | std::string str2 = str; | |
83 | ss.str(std::move(str2)); | |
84 | VERIFY( str2.empty() ); | |
85 | VERIFY( ss.str() == str ); | |
86 | } | |
87 | ||
88 | int main() | |
89 | { | |
90 | test01(); | |
91 | test02(); | |
92 | test03(); | |
93 | test04(); | |
94 | } |