]>
Commit | Line | Data |
---|---|---|
61f1ed59 PC |
1 | // 1999-06-03 bkoz |
2 | ||
405feeb8 | 3 | // Copyright (C) 1999-2013 Free Software Foundation, Inc. |
61f1ed59 PC |
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) |
61f1ed59 PC |
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/>. | |
61f1ed59 PC |
19 | |
20 | // 21.3.5.4 basic_string::insert | |
21 | ||
22 | #include <string> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | // More | |
26 | // wstring& insert(size_type __p, const wchar_t* s, size_type n); | |
27 | // wstring& insert(size_type __p, const wchar_t* s); | |
28 | // but now s points inside the _Rep | |
29 | int test02(void) | |
30 | { | |
11f10e6b | 31 | bool test __attribute__((unused)) = true; |
61f1ed59 PC |
32 | |
33 | std::wstring str01; | |
34 | const wchar_t* title = L"Everything was beautiful, and nothing hurt"; | |
35 | // Increasing size: str01 is reallocated every time. | |
36 | str01 = title; | |
37 | str01.insert(0, str01.c_str() + str01.size() - 4, 4); | |
38 | VERIFY( str01 == L"hurtEverything was beautiful, and nothing hurt" ); | |
39 | str01 = title; | |
40 | str01.insert(0, str01.c_str(), 5); | |
41 | VERIFY( str01 == L"EveryEverything was beautiful, and nothing hurt" ); | |
42 | str01 = title; | |
43 | str01.insert(10, str01.c_str() + 4, 6); | |
44 | VERIFY( str01 == L"Everythingything was beautiful, and nothing hurt" ); | |
45 | str01 = title; | |
46 | str01.insert(15, str01.c_str(), 10); | |
47 | VERIFY( str01 == L"Everything was Everythingbeautiful, and nothing hurt" ); | |
48 | str01 = title; | |
49 | str01.insert(15, str01.c_str() + 11, 13); | |
50 | VERIFY( str01 == L"Everything was was beautifulbeautiful, and nothing hurt" ); | |
51 | str01 = title; | |
52 | str01.insert(0, str01.c_str()); | |
53 | VERIFY( str01 == L"Everything was beautiful, and nothing hurt" | |
54 | L"Everything was beautiful, and nothing hurt"); | |
55 | // Again: no reallocations. | |
56 | str01 = title; | |
57 | str01.insert(0, str01.c_str() + str01.size() - 4, 4); | |
58 | VERIFY( str01 == L"hurtEverything was beautiful, and nothing hurt" ); | |
59 | str01 = title; | |
60 | str01.insert(0, str01.c_str(), 5); | |
61 | VERIFY( str01 == L"EveryEverything was beautiful, and nothing hurt" ); | |
62 | str01 = title; | |
63 | str01.insert(10, str01.c_str() + 4, 6); | |
64 | VERIFY( str01 == L"Everythingything was beautiful, and nothing hurt" ); | |
65 | str01 = title; | |
66 | str01.insert(15, str01.c_str(), 10); | |
67 | VERIFY( str01 == L"Everything was Everythingbeautiful, and nothing hurt" ); | |
68 | str01 = title; | |
69 | str01.insert(15, str01.c_str() + 11, 13); | |
70 | VERIFY( str01 == L"Everything was was beautifulbeautiful, and nothing hurt" ); | |
71 | str01 = title; | |
72 | str01.insert(0, str01.c_str()); | |
73 | VERIFY( str01 == L"Everything was beautiful, and nothing hurt" | |
74 | L"Everything was beautiful, and nothing hurt"); | |
61f1ed59 PC |
75 | return test; |
76 | } | |
77 | ||
78 | int main() | |
79 | { | |
80 | test02(); | |
81 | return 0; | |
82 | } |