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