fe413112f8
2001-08-06 Phil Edwards <pme@sources.redhat.com> * acinclude.m4 (GLIBCPP_CONFIGURE_TESTSUITE): New macro, calls... (GLIBCPP_CHECK_SETRLIMIT): ...this new macro, which also uses... (GLIBCPP_CHECK_SETRLIMIT_ancilliary): ...this new macro. * configure.in (AM_CONFIG_HEADER): Also generate testsuite_hooks.h. Call GLIBCPP_CONFIGURE_TESTSUITE. * aclocal.m4: Regenerate. * config.h.in: Regenerate. * configure: Regenerate. * testsuite/lib/libstdc++-v3-dg.exp: Download new header instead of old header. * testsuite_flags.in: Add build dir's testsuite to INCLUDES. * testsuite/debug_assert.h: Removed; contents merged into... * testsuite/testsuite_hooks.h.in: ...here. New file. * testsuite/17_intro/header_ciso646.cc: No longer include debug_assert.h, include testsuite_hooks.h instead. * testsuite/17_intro/header_fstream.cc: Likewise. * testsuite/17_intro/header_iomanip.cc: Likewise. * testsuite/17_intro/header_ios.cc: Likewise. * testsuite/17_intro/header_iosfwd.cc: Likewise. * testsuite/17_intro/header_iostream.cc: Likewise. * testsuite/17_intro/header_istream.cc: Likewise. * testsuite/17_intro/header_ostream.cc: Likewise. * testsuite/17_intro/header_sstream.cc: Likewise. * testsuite/17_intro/header_streambuf.cc: Likewise. * testsuite/18_support/numeric_limits.cc: Likewise. * testsuite/19_diagnostics/stdexceptions.cc: Likewise. * testsuite/20_util/allocator_members.cc: Likewise. * testsuite/20_util/auto_ptr.cc: Likewise. * testsuite/20_util/pairs.cc: Likewise. * testsuite/21_strings/append.cc: Likewise. * testsuite/21_strings/capacity.cc: Likewise. * testsuite/21_strings/char_traits_requirements.cc: Likewise. * testsuite/21_strings/compare.cc: Likewise. * testsuite/21_strings/ctor_copy_dtor.cc: Likewise. Also set up call to (disabled) __set_testsuite_memlimit() wrapper. * testsuite/21_strings/element_access.cc: Likewise. * testsuite/21_strings/find.cc: Likewise. * testsuite/21_strings/insert.cc: Likewise. Also set up call to (disabled) __set_testsuite_memlimit() wrapper. * testsuite/21_strings/inserters_extractors.cc: Likewise. * testsuite/21_strings/invariants.cc: Likewise. * testsuite/21_strings/nonmember.cc: Likewise. * testsuite/21_strings/operations.cc: Likewise. * testsuite/21_strings/replace.cc: Likewise. * testsuite/21_strings/rfind.cc: Likewise. * testsuite/21_strings/substr.cc: Likewise. * testsuite/22_locale/codecvt_char_char.cc: Likewise. * testsuite/22_locale/codecvt_unicode_char.cc: Likewise. * testsuite/22_locale/codecvt_unicode_wchar_t.cc: Likewise. * testsuite/22_locale/codecvt_wchar_t_char.cc: Likewise. * testsuite/22_locale/ctor_copy_dtor.cc: Likewise. * testsuite/22_locale/ctype_char_members.cc: Likewise. * testsuite/22_locale/ctype_wchar_t_members.cc: Likewise. * testsuite/22_locale/facet.cc: Likewise. * testsuite/22_locale/global_templates.cc: Likewise. * testsuite/22_locale/members.cc: Likewise. * testsuite/22_locale/numpunct_byname.cc: Likewise. * testsuite/22_locale/numpunct_char_members.cc: Likewise. * testsuite/22_locale/operators.cc: Likewise. * testsuite/22_locale/static_members.cc: Likewise. * testsuite/23_containers/bitset_ctor.cc: Likewise. * testsuite/23_containers/bitset_members.cc: Likewise. * testsuite/23_containers/bitset_shift.cc: Likewise. * testsuite/23_containers/vector_capacity.cc: Likewise. * testsuite/23_containers/vector_ctor.cc: Likewise. * testsuite/23_containers/vector_element_access.cc: Likewise. * testsuite/23_containers/vector_modifiers.cc: Likewise. * testsuite/24_iterators/istreambuf_iterator.cc: Likewise. * testsuite/24_iterators/iterator.cc: Likewise. * testsuite/24_iterators/ostreambuf_iterator.cc: Likewise. * testsuite/25_algorithms/binary_search.cc: Likewise. * testsuite/25_algorithms/copy.cc: Likewise. * testsuite/25_algorithms/heap.cc: Likewise. * testsuite/25_algorithms/lower_bound.cc: Likewise. * testsuite/25_algorithms/min_max.cc: Likewise. * testsuite/25_algorithms/partition.cc: Likewise. * testsuite/25_algorithms/rotate.cc: Likewise. * testsuite/25_algorithms/sort.cc: Likewise. * testsuite/26_numerics/c_math.cc: Likewise. * testsuite/26_numerics/complex_inserters_extractors.cc: Likewise. * testsuite/26_numerics/complex_value.cc: Likewise. * testsuite/27_io/filebuf.cc: Likewise. * testsuite/27_io/filebuf_members.cc: Likewise. * testsuite/27_io/filebuf_virtuals.cc: Likewise. * testsuite/27_io/fpos.cc: Likewise. * testsuite/27_io/fstream_members.cc: Likewise. * testsuite/27_io/ifstream_members.cc: Likewise. * testsuite/27_io/ios_base_callbacks.cc: Likewise. * testsuite/27_io/ios_base_members_static.cc: Likewise. * testsuite/27_io/ios_base_storage.cc: Likewise. * testsuite/27_io/ios_ctor.cc: Likewise. * testsuite/27_io/ios_init.cc: Likewise. * testsuite/27_io/ios_manip_basefield.cc: Likewise. * testsuite/27_io/ios_manip_fmtflags.cc: Likewise. * testsuite/27_io/ios_members.cc: Likewise. * testsuite/27_io/istream_extractor_arith.cc: Likewise. * testsuite/27_io/istream_extractor_char.cc: Likewise. * testsuite/27_io/istream_extractor_other.cc: Likewise. * testsuite/27_io/istream_manip.cc: Likewise. * testsuite/27_io/istream_seeks.cc: Likewise. * testsuite/27_io/istream_sentry.cc: Likewise. * testsuite/27_io/istream_unformatted.cc: Likewise. * testsuite/27_io/istringstream_members.cc: Likewise. * testsuite/27_io/narrow_stream_objects.cc: Likewise. * testsuite/27_io/ofstream_members.cc: Likewise. * testsuite/27_io/ostream_inserter_arith.cc: Likewise. * testsuite/27_io/ostream_inserter_char.cc: Likewise. * testsuite/27_io/ostream_inserter_other.cc: Likewise. * testsuite/27_io/ostream_manip.cc: Likewise. * testsuite/27_io/ostream_seeks.cc: Likewise. * testsuite/27_io/ostream_unformatted.cc: Likewise. * testsuite/27_io/ostringstream_members.cc: Likewise. * testsuite/27_io/streambuf.cc: Likewise. * testsuite/27_io/stringbuf.cc: Likewise. * testsuite/27_io/stringbuf_virtuals.cc: Likewise. * testsuite/27_io/stringstream.cc: Likewise. * testsuite/27_io/stringstream_members.cc: Likewise. * testsuite/27_io/wide_stream_objects.cc: Likewise. From-SVN: r44679
196 lines
5.4 KiB
C++
196 lines
5.4 KiB
C++
// 1999-06-03 bkoz
|
|
|
|
// Copyright (C) 1999 Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
// software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU General Public License as published by the
|
|
// Free Software Foundation; either version 2, or (at your option)
|
|
// any later version.
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this library; see the file COPYING. If not, write to the Free
|
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
// USA.
|
|
|
|
// 21.3.5.4 basic_string::insert
|
|
|
|
#include <string>
|
|
#include <stdexcept>
|
|
#include <testsuite_hooks.h>
|
|
|
|
int test01(void)
|
|
{
|
|
bool test = true;
|
|
typedef std::string::size_type csize_type;
|
|
typedef std::string::iterator citerator;
|
|
csize_type npos = std::string::npos;
|
|
csize_type csz01, csz02;
|
|
|
|
const std::string str01("rodeo beach, marin");
|
|
const std::string str02("baker beach, san francisco");
|
|
std::string str03;
|
|
|
|
// string& insert(size_type p1, const string& str, size_type p2, size_type n)
|
|
// requires:
|
|
// 1) p1 <= size()
|
|
// 2) p2 <= str.size()
|
|
// 3) rlen = min(n, str.size() - p2)
|
|
// throws:
|
|
// 1) out_of_range if p1 > size() || p2 > str.size()
|
|
// 2) length_error if size() >= npos - rlen
|
|
// effects:
|
|
// replaces *this with new string of length size() + rlen such that
|
|
// nstr[0] to nstr[p1] == thisstr[0] to thisstr[p1]
|
|
// nstr[p1 + 1] to nstr[p1 + rlen] == str[p2] to str[p2 + rlen]
|
|
// nstr[p1 + 1 + rlen] to nstr[...] == thisstr[p1 + 1] to thisstr[...]
|
|
str03 = str01;
|
|
csz01 = str03.size();
|
|
csz02 = str02.size();
|
|
try {
|
|
str03.insert(csz01 + 1, str02, 0, 5);
|
|
VERIFY( false );
|
|
}
|
|
catch(std::out_of_range& fail) {
|
|
VERIFY( true );
|
|
}
|
|
catch(...) {
|
|
VERIFY( false );
|
|
}
|
|
|
|
str03 = str01;
|
|
csz01 = str03.size();
|
|
csz02 = str02.size();
|
|
try {
|
|
str03.insert(0, str02, csz02 + 1, 5);
|
|
VERIFY( false );
|
|
}
|
|
catch(std::out_of_range& fail) {
|
|
VERIFY( true );
|
|
}
|
|
catch(...) {
|
|
VERIFY( false );
|
|
}
|
|
|
|
csz01 = str01.max_size();
|
|
try {
|
|
std::string str04(csz01, 'b');
|
|
str03 = str04;
|
|
csz02 = str02.size();
|
|
try {
|
|
str03.insert(0, str02, 0, 5);
|
|
VERIFY( false );
|
|
}
|
|
catch(std::length_error& fail) {
|
|
VERIFY( true );
|
|
}
|
|
catch(...) {
|
|
VERIFY( false );
|
|
}
|
|
}
|
|
catch(std::bad_alloc& failure){
|
|
VERIFY( true );
|
|
}
|
|
catch(std::exception& failure){
|
|
VERIFY( false );
|
|
}
|
|
|
|
str03 = str01;
|
|
csz01 = str03.size();
|
|
csz02 = str02.size();
|
|
str03.insert(13, str02, 0, 12);
|
|
VERIFY( str03 == "rodeo beach, baker beach,marin" );
|
|
|
|
str03 = str01;
|
|
csz01 = str03.size();
|
|
csz02 = str02.size();
|
|
str03.insert(0, str02, 0, 12);
|
|
VERIFY( str03 == "baker beach,rodeo beach, marin" );
|
|
|
|
str03 = str01;
|
|
csz01 = str03.size();
|
|
csz02 = str02.size();
|
|
str03.insert(csz01, str02, 0, csz02);
|
|
VERIFY( str03 == "rodeo beach, marinbaker beach, san francisco" );
|
|
|
|
// string& insert(size_type __p, const string& string);
|
|
// insert(p1, str, 0, npos)
|
|
str03 = str01;
|
|
csz01 = str03.size();
|
|
csz02 = str02.size();
|
|
str03.insert(csz01, str02);
|
|
VERIFY( str03 == "rodeo beach, marinbaker beach, san francisco" );
|
|
|
|
str03 = str01;
|
|
csz01 = str03.size();
|
|
csz02 = str02.size();
|
|
str03.insert(0, str02);
|
|
VERIFY( str03 == "baker beach, san franciscorodeo beach, marin" );
|
|
|
|
// string& insert(size_type __p, const char* s, size_type n);
|
|
// insert(p1, string(s,n))
|
|
str03 = str02;
|
|
csz01 = str03.size();
|
|
str03.insert(0, "-break at the bridge", 20);
|
|
VERIFY( str03 == "-break at the bridgebaker beach, san francisco" );
|
|
|
|
// string& insert(size_type __p, const char* s);
|
|
// insert(p1, string(s))
|
|
str03 = str02;
|
|
str03.insert(0, "-break at the bridge");
|
|
VERIFY( str03 == "-break at the bridgebaker beach, san francisco" );
|
|
|
|
// string& insert(size_type __p, size_type n, char c)
|
|
// insert(p1, string(n,c))
|
|
str03 = str02;
|
|
csz01 = str03.size();
|
|
str03.insert(csz01, 5, 'z');
|
|
VERIFY( str03 == "baker beach, san franciscozzzzz" );
|
|
|
|
// iterator insert(iterator p, char c)
|
|
// inserts a copy of c before the character referred to by p
|
|
str03 = str02;
|
|
citerator cit01 = str03.begin();
|
|
str03.insert(cit01, 'u');
|
|
VERIFY( str03 == "ubaker beach, san francisco" );
|
|
|
|
// iterator insert(iterator p, size_type n, char c)
|
|
// inserts n copies of c before the character referred to by p
|
|
str03 = str02;
|
|
cit01 = str03.begin();
|
|
str03.insert(cit01, 5, 'u');
|
|
VERIFY( str03 == "uuuuubaker beach, san francisco" );
|
|
|
|
// template<inputit>
|
|
// void
|
|
// insert(iterator p, inputit first, inputit, last)
|
|
// ISO-14882: defect #7 part 1 clarifies this member function to be:
|
|
// insert(p - begin(), string(first,last))
|
|
str03 = str02;
|
|
csz01 = str03.size();
|
|
str03.insert(str03.begin(), str01.begin(), str01.end());
|
|
VERIFY( str03 == "rodeo beach, marinbaker beach, san francisco" );
|
|
|
|
str03 = str02;
|
|
csz01 = str03.size();
|
|
str03.insert(str03.end(), str01.begin(), str01.end());
|
|
VERIFY( str03 == "baker beach, san franciscorodeo beach, marin" );
|
|
|
|
#ifdef DEBUG_ASSERT
|
|
assert(test);
|
|
#endif
|
|
return test;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
__set_testsuite_memlimit();
|
|
test01();
|
|
return 0;
|
|
}
|