]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string/modifiers/insert/char/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / modifiers / insert / char / 2.cc
CommitLineData
61f1ed59
PC
1// 1999-06-03 bkoz
2
cbe34bb5 3// Copyright (C) 1999-2017 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// string& insert(size_type __p, const char* s, size_type n);
27// string& insert(size_type __p, const char* s);
28// but now s points inside the _Rep
118c8424 29void test02(void)
61f1ed59 30{
61f1ed59
PC
31 std::string str01;
32 const char* title = "Everything was beautiful, and nothing hurt";
33 // Increasing size: str01 is reallocated every time.
34 str01 = title;
35 str01.insert(0, str01.c_str() + str01.size() - 4, 4);
36 VERIFY( str01 == "hurtEverything was beautiful, and nothing hurt" );
37 str01 = title;
38 str01.insert(0, str01.c_str(), 5);
39 VERIFY( str01 == "EveryEverything was beautiful, and nothing hurt" );
40 str01 = title;
41 str01.insert(10, str01.c_str() + 4, 6);
42 VERIFY( str01 == "Everythingything was beautiful, and nothing hurt" );
43 str01 = title;
44 str01.insert(15, str01.c_str(), 10);
45 VERIFY( str01 == "Everything was Everythingbeautiful, and nothing hurt" );
46 str01 = title;
47 str01.insert(15, str01.c_str() + 11, 13);
48 VERIFY( str01 == "Everything was was beautifulbeautiful, and nothing hurt" );
49 str01 = title;
50 str01.insert(0, str01.c_str());
51 VERIFY( str01 == "Everything was beautiful, and nothing hurt"
52 "Everything was beautiful, and nothing hurt");
53 // Again: no reallocations.
54 str01 = title;
55 str01.insert(0, str01.c_str() + str01.size() - 4, 4);
56 VERIFY( str01 == "hurtEverything was beautiful, and nothing hurt" );
57 str01 = title;
58 str01.insert(0, str01.c_str(), 5);
59 VERIFY( str01 == "EveryEverything was beautiful, and nothing hurt" );
60 str01 = title;
61 str01.insert(10, str01.c_str() + 4, 6);
62 VERIFY( str01 == "Everythingything was beautiful, and nothing hurt" );
63 str01 = title;
64 str01.insert(15, str01.c_str(), 10);
65 VERIFY( str01 == "Everything was Everythingbeautiful, and nothing hurt" );
66 str01 = title;
67 str01.insert(15, str01.c_str() + 11, 13);
68 VERIFY( str01 == "Everything was was beautifulbeautiful, and nothing hurt" );
69 str01 = title;
70 str01.insert(0, str01.c_str());
71 VERIFY( str01 == "Everything was beautiful, and nothing hurt"
72 "Everything was beautiful, and nothing hurt");
61f1ed59
PC
73}
74
75int main()
76{
77 test02();
78 return 0;
79}