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