1// 1999-07-08 bkoz
2
3// Copyright (C) 1999, 2003 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 2, 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 COPYING.  If not, write to the Free
18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19// USA.
20
21// 21.3.5.2 basic_string::append
22
23#include <string>
24#include <stdexcept>
25#include <testsuite_hooks.h>
26
27bool test01(void)
28{
29  bool test __attribute__((unused)) = true;
30  typedef std::string::size_type csize_type;
31  typedef std::string::const_reference cref;
32  typedef std::string::reference ref;
33  csize_type csz01;
34
35  const char str_lit01[] = "point bolivar, texas";
36  const std::string str01(str_lit01);
37  const std::string str02("corpus, ");
38  const std::string str03;
39  std::string str05;
40
41
42  // string& append(const string&)
43  str05 = str02;
44  str05.append(str05);
45  VERIFY( str05 == "corpus, corpus, " );
46  str05.append(str01);
47  VERIFY( str05 == "corpus, corpus, point bolivar, texas" );
48  str05.append(str03);
49  VERIFY( str05 == "corpus, corpus, point bolivar, texas" );
50  std::string str06;
51  str06.append(str05);
52  VERIFY( str06 == str05 );
53
54
55  // string& append(const string&, size_type pos, size_type n)
56  str05.erase();
57  str06.erase();
58  csz01 = str03.size();
59  try {
60    str06.append(str03, csz01 + 1, 0);
61    VERIFY( false );
62  }
63  catch(std::out_of_range& fail) {
64    VERIFY( true );
65  }
66  catch(...) {
67    VERIFY( false );
68  }
69
70  csz01 = str01.size();
71  try {
72    str06.append(str01, csz01 + 1, 0);
73    VERIFY( false );
74  }
75  catch(std::out_of_range& fail) {
76    VERIFY( true );
77  }
78  catch(...) {
79    VERIFY( false );
80  }
81
82  str05 = str02;
83  str05.append(str01, 0, std::string::npos);
84  VERIFY( str05 == "corpus, point bolivar, texas" );
85  VERIFY( str05 != str02 );
86
87  str06 = str02;
88  str06.append(str01, 15, std::string::npos);
89  VERIFY( str06 == "corpus, texas" );
90  VERIFY( str02 != str06 );
91
92
93  // string& append(const char* s)
94  str05.erase();
95  str06.erase();
96  str05.append("");
97  VERIFY( str05 == str03 );
98
99  str05.append(str_lit01);
100  VERIFY( str05 == str01 );
101
102  str06 = str02;
103  str06.append("corpus, ");
104  VERIFY( str06 == "corpus, corpus, " );
105
106
107  // string& append(const char* s, size_type n)
108  str05.erase();
109  str06.erase();
110  str05.append("", 0);
111  VERIFY( str05.size() == 0 );
112  VERIFY( str05 == str03 );
113
114  str05.append(str_lit01, sizeof(str_lit01) - 1);
115  VERIFY( str05 == str01 );
116
117  str06 = str02;
118  str06.append("corpus, ", 6);
119  VERIFY( str06 == "corpus, corpus" );
120
121  str06 = str02;
122  str06.append("corpus, ", 12);
123  VERIFY( str06 != "corpus, corpus, " );
124
125
126  // string& append(size_type n, char c)
127  str05.erase();
128  str06.erase();
129  str05.append(0, 'a');
130  VERIFY( str05 == str03 );
131  str06.append(8, '.');
132  VERIFY( str06 == "........" );
133
134
135  // template<typename InputIter>
136  //  string& append(InputIter first, InputIter last)
137  str05.erase();
138  str06.erase();
139  str05.append(str03.begin(), str03.end());
140  VERIFY( str05 == str03 );
141
142  str06 = str02;
143  str06.append(str01.begin(), str01.begin() + str01.find('r'));
144  VERIFY( str06 == "corpus, point boliva" );
145  VERIFY( str06 != str01 );
146  VERIFY( str06 != str02 );
147
148  str05 = str01;
149  str05.append(str05.begin(), str05.begin() + str05.find('r'));
150  VERIFY( str05 ==  "point bolivar, texaspoint boliva" );
151  VERIFY( str05 != str01 );
152  return test;
153}
154
155int main()
156{
157  test01();
158  return 0;
159}
160