3 // Copyright (C) 1999, 2003 Free Software Foundation, Inc.
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)
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 21.3.5.4 basic_string::insert
24 #include <testsuite_hooks.h>
27 // string& insert(size_type __p, const char* s, size_type n);
28 // string& insert(size_type __p, const char* s);
29 // but now s points inside the _Rep
35 const char* title = "Everything was beautiful, and nothing hurt";
36 // Increasing size: str01 is reallocated every time.
38 str01.insert(0, str01.c_str() + str01.size() - 4, 4);
39 VERIFY( str01 == "hurtEverything was beautiful, and nothing hurt" );
41 str01.insert(0, str01.c_str(), 5);
42 VERIFY( str01 == "EveryEverything was beautiful, and nothing hurt" );
44 str01.insert(10, str01.c_str() + 4, 6);
45 VERIFY( str01 == "Everythingything was beautiful, and nothing hurt" );
47 str01.insert(15, str01.c_str(), 10);
48 VERIFY( str01 == "Everything was Everythingbeautiful, and nothing hurt" );
50 str01.insert(15, str01.c_str() + 11, 13);
51 VERIFY( str01 == "Everything was was beautifulbeautiful, and nothing hurt" );
53 str01.insert(0, str01.c_str());
54 VERIFY( str01 == "Everything was beautiful, and nothing hurt"
55 "Everything was beautiful, and nothing hurt");
56 // Again: no reallocations.
58 str01.insert(0, str01.c_str() + str01.size() - 4, 4);
59 VERIFY( str01 == "hurtEverything was beautiful, and nothing hurt" );
61 str01.insert(0, str01.c_str(), 5);
62 VERIFY( str01 == "EveryEverything was beautiful, and nothing hurt" );
64 str01.insert(10, str01.c_str() + 4, 6);
65 VERIFY( str01 == "Everythingything was beautiful, and nothing hurt" );
67 str01.insert(15, str01.c_str(), 10);
68 VERIFY( str01 == "Everything was Everythingbeautiful, and nothing hurt" );
70 str01.insert(15, str01.c_str() + 11, 13);
71 VERIFY( str01 == "Everything was was beautifulbeautiful, and nothing hurt" );
73 str01.insert(0, str01.c_str());
74 VERIFY( str01 == "Everything was beautiful, and nothing hurt"
75 "Everything was beautiful, and nothing hurt");