]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istringstream / cons / char / 1.cc
CommitLineData
99dee823 1// Copyright (C) 2020-2021 Free Software Foundation, Inc.
a0e4d7b4
TR
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// C++20 29.8.2.2 basic_stringbuf constructors [stringbuf.cons
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 <string>
26#include <testsuite_allocator.h>
27#include <testsuite_hooks.h>
28
29void
30test01()
31{
32 std::istringstream::allocator_type a;
33 std::istringstream stm(std::ios_base::in, a);
34}
35
432258be 36auto const cstr = "This is a test string";
a0e4d7b4
TR
37
38void
39test02()
40{
41 std::string s1(cstr);
42 std::istringstream stm(std::move(s1));
43 VERIFY( s1.empty() );
44
45 std::string s2(cstr);
46 VERIFY( stm.str() == s2 );
47}
48
49void
50test03()
51{
52 using alloc_type = __gnu_test::tracker_allocator<char>;
53 using str_type = std::basic_string<char, std::char_traits<char>, alloc_type>;
54
55 auto const mode = std::ios_base::in;
56 str_type s1(cstr);
57
58 {
59 std::istringstream::allocator_type a;
60 std::istringstream sbuf(s1, mode, a);
61 std::string s2(cstr);
62 VERIFY( sbuf.str() == s2 );
63 }
64
65 {
66 std::istringstream sbuf(s1, mode);
67 std::string s2(cstr);
68 VERIFY( sbuf.str() == s2 );
69 }
70
71 {
72 std::istringstream sbuf(s1);
73 std::string s2(cstr);
74 VERIFY( sbuf.str() == s2 );
75 }
76}
77
432258be
JW
78// A minimal allocator with no default constructor
79template<typename T>
80 struct NoDefaultCons : __gnu_test::SimpleAllocator<T>
81 {
82 using __gnu_test::SimpleAllocator<T>::SimpleAllocator;
83
84 NoDefaultCons() = delete;
85
86 NoDefaultCons(int) { }
87 };
88
89void
90test04()
91{
92 using sstream = std::basic_istringstream<char, std::char_traits<char>,
93 NoDefaultCons<char>>;
94
95 NoDefaultCons<char> a(1);
96 const std::string str(cstr);
97
98 sstream ss1(str, a);
99 VERIFY( ss1.str() == cstr );
100 VERIFY( ss1.get() == cstr[0] );
101
102 sstream ss2(str, std::ios::out, a);
103 VERIFY( ss2.str() == cstr );
104 VERIFY( ss2.get() == cstr[0] );
105
106 sstream ss3(std::string(str), std::ios::out, a);
107 VERIFY( ss3.str() == cstr );
108 VERIFY( ss3.get() == cstr[0] );
109}
110
a0e4d7b4
TR
111int
112main()
113{
114 test01();
115 test02();
116 test03();
432258be 117 test04();
a0e4d7b4 118}