177298Sobrien// 1999-06-03 bkoz
277298Sobrien
377298Sobrien// Copyright (C) 1999, 2003, 2009 Free Software Foundation, Inc.
477298Sobrien//
577298Sobrien// This file is part of the GNU ISO C++ Library.  This library is free
677298Sobrien// software; you can redistribute it and/or modify it under the
777298Sobrien// terms of the GNU General Public License as published by the
877298Sobrien// Free Software Foundation; either version 3, or (at your option)
977298Sobrien// any later version.
1077298Sobrien
1177298Sobrien// This library is distributed in the hope that it will be useful,
1277298Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1377298Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1477298Sobrien// GNU General Public License for more details.
1577298Sobrien
1677298Sobrien// You should have received a copy of the GNU General Public License along
1777298Sobrien// with this library; see the file COPYING3.  If not see
1877298Sobrien// <http://www.gnu.org/licenses/>.
1977298Sobrien
20218822Sdim// 21.3.5.4 basic_string::insert
2177298Sobrien
2277298Sobrien#include <string>
2377298Sobrien#include <testsuite_hooks.h>
2477298Sobrien
2577298Sobrien// More
2677298Sobrien//   string& insert(size_type __p, const char* s, size_type n);
2777298Sobrien//   string& insert(size_type __p, const char* s);
2877298Sobrien// but now s points inside the _Rep
2977298Sobrienint test02(void)
3077298Sobrien{
3177298Sobrien  bool test __attribute__((unused)) = true;
3277298Sobrien
3377298Sobrien  std::string str01;
3477298Sobrien  const char* title = "Everything was beautiful, and nothing hurt";
3577298Sobrien  // Increasing size: str01 is reallocated every time.
3677298Sobrien  str01 = title;
3777298Sobrien  str01.insert(0, str01.c_str() + str01.size() - 4, 4);
3877298Sobrien  VERIFY( str01 == "hurtEverything was beautiful, and nothing hurt" );
3977298Sobrien  str01 = title;
4077298Sobrien  str01.insert(0, str01.c_str(), 5);
4177298Sobrien  VERIFY( str01 == "EveryEverything was beautiful, and nothing hurt" );
4277298Sobrien  str01 = title;
4377298Sobrien  str01.insert(10, str01.c_str() + 4, 6);
4477298Sobrien  VERIFY( str01 == "Everythingything was beautiful, and nothing hurt" );
4577298Sobrien  str01 = title;
4677298Sobrien  str01.insert(15, str01.c_str(), 10);
4777298Sobrien  VERIFY( str01 == "Everything was Everythingbeautiful, and nothing hurt" );
4877298Sobrien  str01 = title;
4977298Sobrien  str01.insert(15, str01.c_str() + 11, 13);
5077298Sobrien  VERIFY( str01 == "Everything was was beautifulbeautiful, and nothing hurt" );
5177298Sobrien  str01 = title;
5277298Sobrien  str01.insert(0, str01.c_str());
5377298Sobrien  VERIFY( str01 == "Everything was beautiful, and nothing hurt"
5477298Sobrien	  "Everything was beautiful, and nothing hurt");
5577298Sobrien  // Again: no reallocations.
5677298Sobrien  str01 = title;
5777298Sobrien  str01.insert(0, str01.c_str() + str01.size() - 4, 4);
5877298Sobrien  VERIFY( str01 == "hurtEverything was beautiful, and nothing hurt" );
5977298Sobrien  str01 = title;
6077298Sobrien  str01.insert(0, str01.c_str(), 5);
6177298Sobrien  VERIFY( str01 == "EveryEverything was beautiful, and nothing hurt" );
6277298Sobrien  str01 = title;
6377298Sobrien  str01.insert(10, str01.c_str() + 4, 6);
6477298Sobrien  VERIFY( str01 == "Everythingything was beautiful, and nothing hurt" );
65218822Sdim  str01 = title;
6677298Sobrien  str01.insert(15, str01.c_str(), 10);
6789857Sobrien  VERIFY( str01 == "Everything was Everythingbeautiful, and nothing hurt" );
6889857Sobrien  str01 = title;
6989857Sobrien  str01.insert(15, str01.c_str() + 11, 13);
7089857Sobrien  VERIFY( str01 == "Everything was was beautifulbeautiful, and nothing hurt" );
7177298Sobrien  str01 = title;
7277298Sobrien  str01.insert(0, str01.c_str());
7377298Sobrien  VERIFY( str01 == "Everything was beautiful, and nothing hurt"
7477298Sobrien	  "Everything was beautiful, and nothing hurt");
7577298Sobrien  return test;
7677298Sobrien}
7777298Sobrien
7877298Sobrienint main()
7977298Sobrien{
8077298Sobrien  test02();
8177298Sobrien  return 0;
82218822Sdim}
8377298Sobrien