]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string/modifiers/append/char/1.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / modifiers / append / char / 1.cc
CommitLineData
b2dad0e3
BK
1// 1999-07-08 bkoz
2
aa118a03 3// Copyright (C) 1999-2014 Free Software Foundation, Inc.
b2dad0e3
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
b2dad0e3
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
b2dad0e3 19
ec61e852 20// 21.3.5.2 basic_string::append
b2dad0e3
BK
21
22#include <string>
23#include <stdexcept>
fe413112 24#include <testsuite_hooks.h>
b2dad0e3
BK
25
26bool test01(void)
27{
11f10e6b 28 bool test __attribute__((unused)) = true;
b2dad0e3
BK
29 typedef std::string::size_type csize_type;
30 typedef std::string::const_reference cref;
31 typedef std::string::reference ref;
11f10e6b 32 csize_type csz01;
b2dad0e3
BK
33
34 const char str_lit01[] = "point bolivar, texas";
35 const std::string str01(str_lit01);
36 const std::string str02("corpus, ");
37 const std::string str03;
38 std::string str05;
39
40
41 // string& append(const string&)
42 str05 = str02;
43 str05.append(str05);
aa1b2f7d 44 VERIFY( str05 == "corpus, corpus, " );
b2dad0e3 45 str05.append(str01);
aa1b2f7d 46 VERIFY( str05 == "corpus, corpus, point bolivar, texas" );
b2dad0e3 47 str05.append(str03);
aa1b2f7d 48 VERIFY( str05 == "corpus, corpus, point bolivar, texas" );
b2dad0e3
BK
49 std::string str06;
50 str06.append(str05);
aa1b2f7d 51 VERIFY( str06 == str05 );
b2dad0e3
BK
52
53
54 // string& append(const string&, size_type pos, size_type n)
55 str05.erase();
56 str06.erase();
57 csz01 = str03.size();
58 try {
59 str06.append(str03, csz01 + 1, 0);
aa1b2f7d 60 VERIFY( false );
b2dad0e3
BK
61 }
62 catch(std::out_of_range& fail) {
aa1b2f7d 63 VERIFY( true );
b2dad0e3
BK
64 }
65 catch(...) {
aa1b2f7d 66 VERIFY( false );
b2dad0e3
BK
67 }
68
69 csz01 = str01.size();
70 try {
71 str06.append(str01, csz01 + 1, 0);
aa1b2f7d 72 VERIFY( false );
b2dad0e3
BK
73 }
74 catch(std::out_of_range& fail) {
aa1b2f7d 75 VERIFY( true );
b2dad0e3
BK
76 }
77 catch(...) {
aa1b2f7d 78 VERIFY( false );
b2dad0e3
BK
79 }
80
81 str05 = str02;
82 str05.append(str01, 0, std::string::npos);
aa1b2f7d
BV
83 VERIFY( str05 == "corpus, point bolivar, texas" );
84 VERIFY( str05 != str02 );
b2dad0e3
BK
85
86 str06 = str02;
87 str06.append(str01, 15, std::string::npos);
aa1b2f7d
BV
88 VERIFY( str06 == "corpus, texas" );
89 VERIFY( str02 != str06 );
b2dad0e3
BK
90
91
92 // string& append(const char* s)
93 str05.erase();
94 str06.erase();
95 str05.append("");
aa1b2f7d 96 VERIFY( str05 == str03 );
b2dad0e3
BK
97
98 str05.append(str_lit01);
aa1b2f7d 99 VERIFY( str05 == str01 );
b2dad0e3
BK
100
101 str06 = str02;
102 str06.append("corpus, ");
aa1b2f7d 103 VERIFY( str06 == "corpus, corpus, " );
b2dad0e3
BK
104
105
106 // string& append(const char* s, size_type n)
107 str05.erase();
108 str06.erase();
109 str05.append("", 0);
aa1b2f7d
BV
110 VERIFY( str05.size() == 0 );
111 VERIFY( str05 == str03 );
b2dad0e3
BK
112
113 str05.append(str_lit01, sizeof(str_lit01) - 1);
aa1b2f7d 114 VERIFY( str05 == str01 );
b2dad0e3
BK
115
116 str06 = str02;
117 str06.append("corpus, ", 6);
aa1b2f7d 118 VERIFY( str06 == "corpus, corpus" );
b2dad0e3
BK
119
120 str06 = str02;
121 str06.append("corpus, ", 12);
aa1b2f7d 122 VERIFY( str06 != "corpus, corpus, " );
b2dad0e3
BK
123
124
125 // string& append(size_type n, char c)
126 str05.erase();
127 str06.erase();
128 str05.append(0, 'a');
aa1b2f7d 129 VERIFY( str05 == str03 );
b2dad0e3 130 str06.append(8, '.');
aa1b2f7d 131 VERIFY( str06 == "........" );
b2dad0e3
BK
132
133
134 // template<typename InputIter>
135 // string& append(InputIter first, InputIter last)
136 str05.erase();
137 str06.erase();
138 str05.append(str03.begin(), str03.end());
aa1b2f7d 139 VERIFY( str05 == str03 );
b2dad0e3
BK
140
141 str06 = str02;
142 str06.append(str01.begin(), str01.begin() + str01.find('r'));
aa1b2f7d
BV
143 VERIFY( str06 == "corpus, point boliva" );
144 VERIFY( str06 != str01 );
145 VERIFY( str06 != str02 );
b2dad0e3
BK
146
147 str05 = str01;
148 str05.append(str05.begin(), str05.begin() + str05.find('r'));
aa1b2f7d
BV
149 VERIFY( str05 == "point bolivar, texaspoint boliva" );
150 VERIFY( str05 != str01 );
b2dad0e3
BK
151 return test;
152}
153
154int main()
155{
156 test01();
04d930e6 157 return 0;
b2dad0e3 158}