Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / testsuite / 21_strings / basic_string / insert / wchar_t / 1.cc
blob296c7cc052b5a1b6e0be7ae60605761b0eea11b5
1 // 1999-06-03 bkoz
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.
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.
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.
21 // 21.3.5.4 basic_string::insert
23 #include <string>
24 #include <stdexcept>
25 #include <testsuite_hooks.h>
27 int test01(void)
29 bool test __attribute__((unused)) = true;
30 typedef std::wstring::size_type csize_type;
31 typedef std::wstring::iterator citerator;
32 csize_type csz01, csz02;
34 const std::wstring str01(L"rodeo beach, marin");
35 const std::wstring str02(L"baker beach, san francisco");
36 std::wstring str03;
38 // wstring& insert(size_type p1, const wstring& str, size_type p2, size_type n)
39 // requires:
40 // 1) p1 <= size()
41 // 2) p2 <= str.size()
42 // 3) rlen = min(n, str.size() - p2)
43 // throws:
44 // 1) out_of_range if p1 > size() || p2 > str.size()
45 // 2) length_error if size() >= npos - rlen
46 // effects:
47 // replaces *this with new wstring of length size() + rlen such that
48 // nstr[0] to nstr[p1] == thisstr[0] to thisstr[p1]
49 // nstr[p1 + 1] to nstr[p1 + rlen] == str[p2] to str[p2 + rlen]
50 // nstr[p1 + 1 + rlen] to nstr[...] == thisstr[p1 + 1] to thisstr[...]
51 str03 = str01;
52 csz01 = str03.size();
53 csz02 = str02.size();
54 try {
55 str03.insert(csz01 + 1, str02, 0, 5);
56 VERIFY( false );
58 catch(std::out_of_range& fail) {
59 VERIFY( true );
61 catch(...) {
62 VERIFY( false );
65 str03 = str01;
66 csz01 = str03.size();
67 csz02 = str02.size();
68 try {
69 str03.insert(0, str02, csz02 + 1, 5);
70 VERIFY( false );
72 catch(std::out_of_range& fail) {
73 VERIFY( true );
75 catch(...) {
76 VERIFY( false );
79 csz01 = str01.max_size();
80 try {
81 std::wstring str04(csz01, L'b');
82 str03 = str04;
83 csz02 = str02.size();
84 try {
85 str03.insert(0, str02, 0, 5);
86 VERIFY( false );
88 catch(std::length_error& fail) {
89 VERIFY( true );
91 catch(...) {
92 VERIFY( false );
95 catch(std::bad_alloc& failure){
96 VERIFY( true );
98 catch(std::exception& failure){
99 VERIFY( false );
102 str03 = str01;
103 csz01 = str03.size();
104 csz02 = str02.size();
105 str03.insert(13, str02, 0, 12);
106 VERIFY( str03 == L"rodeo beach, baker beach,marin" );
108 str03 = str01;
109 csz01 = str03.size();
110 csz02 = str02.size();
111 str03.insert(0, str02, 0, 12);
112 VERIFY( str03 == L"baker beach,rodeo beach, marin" );
114 str03 = str01;
115 csz01 = str03.size();
116 csz02 = str02.size();
117 str03.insert(csz01, str02, 0, csz02);
118 VERIFY( str03 == L"rodeo beach, marinbaker beach, san francisco" );
120 // wstring& insert(size_type __p, const wstring& wstr);
121 // insert(p1, str, 0, npos)
122 str03 = str01;
123 csz01 = str03.size();
124 csz02 = str02.size();
125 str03.insert(csz01, str02);
126 VERIFY( str03 == L"rodeo beach, marinbaker beach, san francisco" );
128 str03 = str01;
129 csz01 = str03.size();
130 csz02 = str02.size();
131 str03.insert(0, str02);
132 VERIFY( str03 == L"baker beach, san franciscorodeo beach, marin" );
134 // wstring& insert(size_type __p, const wchar_t* s, size_type n);
135 // insert(p1, wstring(s,n))
136 str03 = str02;
137 csz01 = str03.size();
138 str03.insert(0, L"-break at the bridge", 20);
139 VERIFY( str03 == L"-break at the bridgebaker beach, san francisco" );
141 // wstring& insert(size_type __p, const wchar_t* s);
142 // insert(p1, wstring(s))
143 str03 = str02;
144 str03.insert(0, L"-break at the bridge");
145 VERIFY( str03 == L"-break at the bridgebaker beach, san francisco" );
147 // wstring& insert(size_type __p, size_type n, wchar_t c)
148 // insert(p1, wstring(n,c))
149 str03 = str02;
150 csz01 = str03.size();
151 str03.insert(csz01, 5, L'z');
152 VERIFY( str03 == L"baker beach, san franciscozzzzz" );
154 // iterator insert(iterator p, wchar_t c)
155 // inserts a copy of c before the character referred to by p
156 str03 = str02;
157 citerator cit01 = str03.begin();
158 str03.insert(cit01, L'u');
159 VERIFY( str03 == L"ubaker beach, san francisco" );
161 // iterator insert(iterator p, size_type n, wchar_t c)
162 // inserts n copies of c before the character referred to by p
163 str03 = str02;
164 cit01 = str03.begin();
165 str03.insert(cit01, 5, L'u');
166 VERIFY( str03 == L"uuuuubaker beach, san francisco" );
168 // template<inputit>
169 // void
170 // insert(iterator p, inputit first, inputit, last)
171 // ISO-14882: defect #7 part 1 clarifies this member function to be:
172 // insert(p - begin(), wstring(first,last))
173 str03 = str02;
174 csz01 = str03.size();
175 str03.insert(str03.begin(), str01.begin(), str01.end());
176 VERIFY( str03 == L"rodeo beach, marinbaker beach, san francisco" );
178 str03 = str02;
179 csz01 = str03.size();
180 str03.insert(str03.end(), str01.begin(), str01.end());
181 VERIFY( str03 == L"baker beach, san franciscorodeo beach, marin" );
182 return test;
185 int main()
187 __gnu_test::set_memory_limits();
188 test01();
189 return 0;