diff options
Diffstat (limited to 'libstdc++-v3/testsuite/21_strings/basic_string')
73 files changed, 6694 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/append/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/append/char/1.cc new file mode 100644 index 00000000000..a7fc70e7a04 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/append/char/1.cc @@ -0,0 +1,164 @@ +// 1999-07-08 bkoz + +// Copyright (C) 1999, 2003 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.3 basic_string::assign + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::string::size_type csize_type; + typedef std::string::const_reference cref; + typedef std::string::reference ref; + csize_type npos = std::string::npos; + csize_type csz01, csz02; + + const char str_lit01[] = "point bolivar, texas"; + const std::string str01(str_lit01); + const std::string str02("corpus, "); + const std::string str03; + std::string str05; + + + // string& append(const string&) + str05 = str02; + str05.append(str05); + VERIFY( str05 == "corpus, corpus, " ); + str05.append(str01); + VERIFY( str05 == "corpus, corpus, point bolivar, texas" ); + str05.append(str03); + VERIFY( str05 == "corpus, corpus, point bolivar, texas" ); + std::string str06; + str06.append(str05); + VERIFY( str06 == str05 ); + + + // string& append(const string&, size_type pos, size_type n) + str05.erase(); + str06.erase(); + csz01 = str03.size(); + try { + str06.append(str03, csz01 + 1, 0); + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + csz01 = str01.size(); + try { + str06.append(str01, csz01 + 1, 0); + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + str05 = str02; + str05.append(str01, 0, std::string::npos); + VERIFY( str05 == "corpus, point bolivar, texas" ); + VERIFY( str05 != str02 ); + + str06 = str02; + str06.append(str01, 15, std::string::npos); + VERIFY( str06 == "corpus, texas" ); + VERIFY( str02 != str06 ); + + + // string& append(const char* s) + str05.erase(); + str06.erase(); + str05.append(""); + VERIFY( str05 == str03 ); + + str05.append(str_lit01); + VERIFY( str05 == str01 ); + + str06 = str02; + str06.append("corpus, "); + VERIFY( str06 == "corpus, corpus, " ); + + + // string& append(const char* s, size_type n) + str05.erase(); + str06.erase(); + str05.append("", 0); + VERIFY( str05.size() == 0 ); + VERIFY( str05 == str03 ); + + str05.append(str_lit01, sizeof(str_lit01) - 1); + VERIFY( str05 == str01 ); + + str06 = str02; + str06.append("corpus, ", 6); + VERIFY( str06 == "corpus, corpus" ); + + str06 = str02; + str06.append("corpus, ", 12); + VERIFY( str06 != "corpus, corpus, " ); + + + // string& append(size_type n, char c) + str05.erase(); + str06.erase(); + str05.append(0, 'a'); + VERIFY( str05 == str03 ); + str06.append(8, '.'); + VERIFY( str06 == "........" ); + + + // template<typename InputIter> + // string& append(InputIter first, InputIter last) + str05.erase(); + str06.erase(); + str05.append(str03.begin(), str03.end()); + VERIFY( str05 == str03 ); + + str06 = str02; + str06.append(str01.begin(), str01.begin() + str01.find('r')); + VERIFY( str06 == "corpus, point boliva" ); + VERIFY( str06 != str01 ); + VERIFY( str06 != str02 ); + + str05 = str01; + str05.append(str05.begin(), str05.begin() + str05.find('r')); + VERIFY( str05 == "point bolivar, texaspoint boliva" ); + VERIFY( str05 != str01 ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/1.cc new file mode 100644 index 00000000000..ea8cd17b954 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/1.cc @@ -0,0 +1,164 @@ +// 1999-07-08 bkoz + +// Copyright (C) 1999, 2003 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.3 basic_string::assign + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::wstring::size_type csize_type; + typedef std::wstring::const_reference cref; + typedef std::wstring::reference ref; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + + const wchar_t str_lit01[] = L"point bolivar, texas"; + const std::wstring str01(str_lit01); + const std::wstring str02(L"corpus, "); + const std::wstring str03; + std::wstring str05; + + + // wstring& append(const wstring&) + str05 = str02; + str05.append(str05); + VERIFY( str05 == L"corpus, corpus, " ); + str05.append(str01); + VERIFY( str05 == L"corpus, corpus, point bolivar, texas" ); + str05.append(str03); + VERIFY( str05 == L"corpus, corpus, point bolivar, texas" ); + std::wstring str06; + str06.append(str05); + VERIFY( str06 == str05 ); + + + // wstring& append(const wstring&, size_type pos, size_type n) + str05.erase(); + str06.erase(); + csz01 = str03.size(); + try { + str06.append(str03, csz01 + 1, 0); + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + csz01 = str01.size(); + try { + str06.append(str01, csz01 + 1, 0); + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + str05 = str02; + str05.append(str01, 0, std::wstring::npos); + VERIFY( str05 == L"corpus, point bolivar, texas" ); + VERIFY( str05 != str02 ); + + str06 = str02; + str06.append(str01, 15, std::wstring::npos); + VERIFY( str06 == L"corpus, texas" ); + VERIFY( str02 != str06 ); + + + // wstring& append(const wchar_t* s) + str05.erase(); + str06.erase(); + str05.append(L""); + VERIFY( str05 == str03 ); + + str05.append(str_lit01); + VERIFY( str05 == str01 ); + + str06 = str02; + str06.append(L"corpus, "); + VERIFY( str06 == L"corpus, corpus, " ); + + + // wstring& append(const wchar_t* s, size_type n) + str05.erase(); + str06.erase(); + str05.append(L"", 0); + VERIFY( str05.size() == 0 ); + VERIFY( str05 == str03 ); + + str05.append(str_lit01, sizeof(str_lit01) - 1); + VERIFY( str05 == str01 ); + + str06 = str02; + str06.append(L"corpus, ", 6); + VERIFY( str06 == L"corpus, corpus" ); + + str06 = str02; + str06.append(L"corpus, ", 12); + VERIFY( str06 != L"corpus, corpus, " ); + + + // wstring& append(size_type n, char c) + str05.erase(); + str06.erase(); + str05.append(0, L'a'); + VERIFY( str05 == str03 ); + str06.append(8, L'.'); + VERIFY( str06 == L"........" ); + + + // template<typename InputIter> + // wstring& append(InputIter first, InputIter last) + str05.erase(); + str06.erase(); + str05.append(str03.begin(), str03.end()); + VERIFY( str05 == str03 ); + + str06 = str02; + str06.append(str01.begin(), str01.begin() + str01.find(L'r')); + VERIFY( str06 == L"corpus, point boliva" ); + VERIFY( str06 != str01 ); + VERIFY( str06 != str02 ); + + str05 = str01; + str05.append(str05.begin(), str05.begin() + str05.find(L'r')); + VERIFY( str05 == L"point bolivar, texaspoint boliva" ); + VERIFY( str05 != str01 ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/1.cc new file mode 100644 index 00000000000..735c61c86e0 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/1.cc @@ -0,0 +1,53 @@ +// 2001-10-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003 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 string modifiers + +#include <string> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test = true; + + using namespace std; + + const char* strlit = "../the long pier/Hanalei Bay/Kauai/Hawaii"; + string aux = strlit; + string::size_type i = aux.rfind("/"); + if (i != string::npos) + aux.assign(aux, i + 1, string::npos); + VERIFY(aux == "Hawaii"); + + aux = strlit; + i = aux.rfind("r/"); + if (i != string::npos) + aux.assign(aux, i + 1, string::npos); + VERIFY(aux.c_str()[9] == 'B'); + VERIFY(aux == "/Hanalei Bay/Kauai/Hawaii"); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/2.cc new file mode 100644 index 00000000000..9783c45202c --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/2.cc @@ -0,0 +1,59 @@ +// 2001-10-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003 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 string modifiers + +#include <string> +#include <cstdio> +#include <testsuite_hooks.h> + +// assign(const basic_string& __str, size_type __pos, size_type __n) +void +test02() +{ + bool test = true; + + using namespace std; + + string one = "Selling England by the pound"; + string two = one; + string three = "Brilliant trees"; + + one.assign(one, 8, 100); + VERIFY( one == "England by the pound" ); + + one.assign(one, 8, 0); + VERIFY( one == "" ); + + one.assign(two, 8, 7); + VERIFY( one == "England" ); + + one.assign(three, 10, 100); + VERIFY( one == "trees" ); + + three.assign(one, 0, 3); + VERIFY( three == "tre" ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/3.cc new file mode 100644 index 00000000000..cfc35545da4 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/3.cc @@ -0,0 +1,61 @@ +// 2001-10-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003 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 string modifiers + +#include <string> +#include <cstdio> +#include <testsuite_hooks.h> + +// assign(const _CharT* __s, size_type __n) +// assign(const _CharT* __s) +void +test03() +{ + bool test = true; + + using namespace std; + + string one; + string two; + string three = two; + const char * source = "Selling England by the pound"; + + one.assign(source); + VERIFY( one == "Selling England by the pound" ); + + one.assign(source, 28); + VERIFY( one == "Selling England by the pound" ); + + two.assign(source, 7); + VERIFY( two == "Selling" ); + + one.assign(one.c_str() + 8, 20); + VERIFY( one == "England by the pound" ); + + one.assign(one.c_str() + 8, 6); + VERIFY( one == "by the" ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/1.cc new file mode 100644 index 00000000000..5f110598bb9 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/1.cc @@ -0,0 +1,53 @@ +// 2001-10-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003 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 string modifiers + +#include <string> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test = true; + + using namespace std; + + const wchar_t* strlit = L"../the long pier/Hanalei Bay/Kauai/Hawaii"; + wstring aux = strlit; + wstring::size_type i = aux.rfind(L"/"); + if (i != wstring::npos) + aux.assign(aux, i + 1, wstring::npos); + VERIFY(aux == L"Hawaii"); + + aux = strlit; + i = aux.rfind(L"r/"); + if (i != wstring::npos) + aux.assign(aux, i + 1, wstring::npos); + VERIFY(aux.c_str()[9] == L'B'); + VERIFY(aux == L"/Hanalei Bay/Kauai/Hawaii"); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/2.cc new file mode 100644 index 00000000000..458204c522e --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/2.cc @@ -0,0 +1,59 @@ +// 2001-10-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003 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 string modifiers + +#include <string> +#include <cstdio> +#include <testsuite_hooks.h> + +// assign(const basic_string& __str, size_type __pos, size_type __n) +void +test02() +{ + bool test = true; + + using namespace std; + + wstring one = L"Selling England by the pound"; + wstring two = one; + wstring three = L"Brilliant trees"; + + one.assign(one, 8, 100); + VERIFY( one == L"England by the pound" ); + + one.assign(one, 8, 0); + VERIFY( one == L"" ); + + one.assign(two, 8, 7); + VERIFY( one == L"England" ); + + one.assign(three, 10, 100); + VERIFY( one == L"trees" ); + + three.assign(one, 0, 3); + VERIFY( three == L"tre" ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/3.cc new file mode 100644 index 00000000000..fc9b5a21eea --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/3.cc @@ -0,0 +1,61 @@ +// 2001-10-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003 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 string modifiers + +#include <string> +#include <cstdio> +#include <testsuite_hooks.h> + +// assign(const _CharT* __s, size_type __n) +// assign(const _CharT* __s) +void +test03() +{ + bool test = true; + + using namespace std; + + wstring one; + wstring two; + wstring three = two; + const wchar_t* source = L"Selling England by the pound"; + + one.assign(source); + VERIFY( one == L"Selling England by the pound" ); + + one.assign(source, 28); + VERIFY( one == L"Selling England by the pound" ); + + two.assign(source, 7); + VERIFY( two == L"Selling" ); + + one.assign(one.c_str() + 8, 20); + VERIFY( one == L"England by the pound" ); + + one.assign(one.c_str() + 8, 6); + VERIFY( one == L"by the" ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/1.cc new file mode 100644 index 00000000000..0a50ee7d9ed --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/1.cc @@ -0,0 +1,199 @@ +// 1999-05-11 bkoz + +// Copyright (C) 1999, 2002, 2003 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.3 string capacity + +#include <string> +#include <testsuite_hooks.h> + +template<typename T> + struct A { }; + +template<typename T> + bool + operator==(const A<T>& a, const A<T>& b) { return true; } + +template<typename T> + bool + operator<(const A<T>& a, const A<T>& b) { return true; } + +struct B { }; + +// char_traits specialization +namespace std +{ + template<> + struct char_traits<A<B> > + { + typedef A<B> char_type; + // Unsigned as wint_t in unsigned. + typedef unsigned long int_type; + typedef streampos pos_type; + typedef streamoff off_type; + typedef mbstate_t state_type; + + static void + assign(char_type& __c1, const char_type& __c2) + { __c1 = __c2; } + + static bool + eq(const char_type& __c1, const char_type& __c2) + { return __c1 == __c2; } + + static bool + lt(const char_type& __c1, const char_type& __c2) + { return __c1 < __c2; } + + static int + compare(const char_type* __s1, const char_type* __s2, size_t __n) + { + for (size_t __i = 0; __i < __n; ++__i) + if (!eq(__s1[__i], __s2[__i])) + return lt(__s1[__i], __s2[__i]) ? -1 : 1; + return 0; + } + + static size_t + length(const char_type* __s) + { + const char_type* __p = __s; + while (__p) + ++__p; + return (__p - __s); + } + + static const char_type* + find(const char_type* __s, size_t __n, const char_type& __a) + { + for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p) + if (*__p == __a) return __p; + return 0; + } + + static char_type* + move(char_type* __s1, const char_type* __s2, size_t __n) + { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); } + + static char_type* + copy(char_type* __s1, const char_type* __s2, size_t __n) + { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); } + + static char_type* + assign(char_type* __s, size_t __n, char_type __a) + { + for (char_type* __p = __s; __p < __s + __n; ++__p) + assign(*__p, __a); + return __s; + } + + static char_type + to_char_type(const int_type& __c) + { return char_type(); } + + static int_type + to_int_type(const char_type& __c) { return int_type(); } + + static bool + eq_int_type(const int_type& __c1, const int_type& __c2) + { return __c1 == __c2; } + + static int_type + eof() { return static_cast<int_type>(-1); } + + static int_type + not_eof(const int_type& __c) + { return eq_int_type(__c, eof()) ? int_type(0) : __c; } + }; +} // namespace std + +void test01() +{ + bool test = true; + + // non POD types : resize, capacity, reserve + std::basic_string< A<B> > str02; + typedef std::basic_string< A<B> >::size_type size_type_o; + size_type_o sz03; + size_type_o sz04; + + sz03 = str02.capacity(); + str02.reserve(100); + sz04 = str02.capacity(); + VERIFY( sz04 >= sz03 ); + VERIFY( sz04 >= 100 ); + str02.reserve(); + sz03 = str02.capacity(); + VERIFY( sz03 >= 0 ); + + sz03 = str02.size() + 5; + str02.resize(sz03); + sz04 = str02.size(); + VERIFY( sz03 == sz04 ); + + sz03 = str02.size() - 5; + str02.resize(sz03); + sz04 = str02.size(); + VERIFY( sz03 == sz04 ); + + A<B> inst_obj; + std::basic_string<A<B> > str07(30, inst_obj); + std::basic_string<A<B> > str08 = str07; + str07 = str08 + str07; + VERIFY( str07.capacity() >= str07.size() ); + VERIFY( str08.capacity() >= str08.size() ); + + // non-POD types: size, length, max_size, clear(), empty() + bool b01 = str02.empty(); + VERIFY( b01 == true ); + sz03 = str02.size(); + sz04 = str02.length(); + VERIFY( sz03 == sz04 ); + str02.c_str(); + sz03 = str02.size(); + sz04 = str02.length(); + VERIFY( sz03 == sz04 ); + + sz03 = str02.max_size(); + VERIFY( sz03 >= sz04 ); + + sz03 = str02.size(); + str02.clear(); + b01 = str02.empty(); + VERIFY( b01 == true ); + sz04 = str02.size(); + VERIFY( sz03 >= sz04 ); +} + +#if !__GXX_WEAK__ +// Explicitly instantiate for systems with no COMDAT or weak support. +template + std::basic_string< A<B> >::size_type + std::basic_string< A<B> >::_Rep::_S_max_size; + +template + A<B> + std::basic_string< A<B> >::_Rep::_S_terminal; +#endif + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/1.cc new file mode 100644 index 00000000000..6072898318a --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/1.cc @@ -0,0 +1,102 @@ +// 1999-05-11 bkoz + +// Copyright (C) 1999, 2002, 2003 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.3 string capacity + +#include <string> +#include <testsuite_hooks.h> + +void test01() +{ + // POD types : resize, capacity, reserve + bool test = true; + std::string str01; + typedef std::string::size_type size_type_s; + + size_type_s sz01 = str01.capacity(); + str01.reserve(100); + size_type_s sz02 = str01.capacity(); + VERIFY( sz02 >= sz01 ); + VERIFY( sz02 >= 100 ); + str01.reserve(); + sz01 = str01.capacity(); + VERIFY( sz01 >= 0 ); + + sz01 = str01.size() + 5; + str01.resize(sz01); + sz02 = str01.size(); + VERIFY( sz01 == sz02 ); + + sz01 = str01.size() - 5; + str01.resize(sz01); + sz02 = str01.size(); + VERIFY( sz01 == sz02 ); + + std::string str05(30, 'q'); + std::string str06 = str05; + str05 = str06 + str05; + VERIFY( str05.capacity() >= str05.size() ); + VERIFY( str06.capacity() >= str06.size() ); + + // POD types: size, length, max_size, clear(), empty() + bool b01; + std::string str011; + b01 = str01.empty(); + VERIFY( b01 == true ); + sz01 = str01.size(); + sz02 = str01.length(); + VERIFY( sz01 == sz02 ); + str01.c_str(); + sz01 = str01.size(); + sz02 = str01.length(); + VERIFY( sz01 == sz02 ); + + sz01 = str01.length(); + str01.c_str(); + str011 = str01 + "_addendum_"; + str01.c_str(); + sz02 = str01.length(); + VERIFY( sz01 == sz02 ); + sz02 = str011.length(); + VERIFY( sz02 > sz01 ); + + // trickster allocator issues involved with these: + std::string str3 = "8-chars_8-chars_"; + const char* p3 = str3.c_str(); + std::string str4 = str3 + "7-chars"; + const char* p4 = str3.c_str(); + + sz01 = str01.size(); + sz02 = str01.max_size(); + VERIFY( sz02 >= sz01 ); + + sz01 = str01.size(); + str01.clear(); + b01 = str01.empty(); + VERIFY( b01 == true ); + sz02 = str01.size(); + VERIFY( sz01 >= sz02 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/2.cc new file mode 100644 index 00000000000..731a9187065 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/2.cc @@ -0,0 +1,43 @@ +// 1999-05-11 bkoz + +// Copyright (C) 1999, 2002, 2003 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.3 string capacity + +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/4548 +// http://gcc.gnu.org/ml/libstdc++/2001-11/msg00150.html +void test02() +{ + bool test = true; + + std::string str01 = "twelve chars"; + // str01 becomes shared + std::string str02 = str01; + str01.reserve(1); + VERIFY( str01.capacity() == 12 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/1.cc new file mode 100644 index 00000000000..18af608d7d1 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/1.cc @@ -0,0 +1,102 @@ +// 1999-05-11 bkoz + +// Copyright (C) 1999, 2002, 2003 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.3 string capacity + +#include <string> +#include <testsuite_hooks.h> + +void test01() +{ + // POD types : resize, capacity, reserve + bool test = true; + std::wstring str01; + typedef std::wstring::size_type size_type_s; + + size_type_s sz01 = str01.capacity(); + str01.reserve(100); + size_type_s sz02 = str01.capacity(); + VERIFY( sz02 >= sz01 ); + VERIFY( sz02 >= 100 ); + str01.reserve(); + sz01 = str01.capacity(); + VERIFY( sz01 >= 0 ); + + sz01 = str01.size() + 5; + str01.resize(sz01); + sz02 = str01.size(); + VERIFY( sz01 == sz02 ); + + sz01 = str01.size() - 5; + str01.resize(sz01); + sz02 = str01.size(); + VERIFY( sz01 == sz02 ); + + std::wstring str05(30, L'q'); + std::wstring str06 = str05; + str05 = str06 + str05; + VERIFY( str05.capacity() >= str05.size() ); + VERIFY( str06.capacity() >= str06.size() ); + + // POD types: size, length, max_size, clear(), empty() + bool b01; + std::wstring str011; + b01 = str01.empty(); + VERIFY( b01 == true ); + sz01 = str01.size(); + sz02 = str01.length(); + VERIFY( sz01 == sz02 ); + str01.c_str(); + sz01 = str01.size(); + sz02 = str01.length(); + VERIFY( sz01 == sz02 ); + + sz01 = str01.length(); + str01.c_str(); + str011 = str01 + L"_addendum_"; + str01.c_str(); + sz02 = str01.length(); + VERIFY( sz01 == sz02 ); + sz02 = str011.length(); + VERIFY( sz02 > sz01 ); + + // trickster allocator issues involved with these: + std::wstring str3 = L"8-chars_8-chars_"; + const wchar_t* p3 = str3.c_str(); + std::wstring str4 = str3 + L"7-chars"; + const wchar_t* p4 = str3.c_str(); + + sz01 = str01.size(); + sz02 = str01.max_size(); + VERIFY( sz02 >= sz01 ); + + sz01 = str01.size(); + str01.clear(); + b01 = str01.empty(); + VERIFY( b01 == true ); + sz02 = str01.size(); + VERIFY( sz01 >= sz02 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/2.cc new file mode 100644 index 00000000000..08aa2294bfa --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/2.cc @@ -0,0 +1,43 @@ +// 1999-05-11 bkoz + +// Copyright (C) 1999, 2002, 2003 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.3 string capacity + +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/4548 +// http://gcc.gnu.org/ml/libstdc++/2001-11/msg00150.html +void test02() +{ + bool test = true; + + std::wstring str01 = L"twelve chars"; + // str01 becomes shared + std::wstring str02 = str01; + str01.reserve(1); + VERIFY( str01.capacity() == 12 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/compare/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/compare/char/1.cc new file mode 100644 index 00000000000..02b6b79037b --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/compare/char/1.cc @@ -0,0 +1,136 @@ +// 980930 bkoz work with libstdc++v3 + +// Copyright (C) 1998, 1999, 2003 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.6.8 basic_string::compare +// int compare(const basic_string& str) const; +// int compare(size_type pos1, size_type n1, const basic_string& str) const; +// int compare(size_type pos1, size_type n1, const basic_string& str, +// size_type pos2, size_type n2) const; +// int compare(const charT* s) const; +// int compare(size_type pos1, size_type n1, +// const charT* s, size_type n2 = npos) const; + +// NB compare should be thought of as a lexographical compare, ie how +// things would be sorted in a dictionary. + +#include <string> +#include <testsuite_hooks.h> + +enum want_value {lt=0, z=1, gt=2}; + +int +test_value(int result, want_value expected); + +int +test_value(int result, want_value expected) +{ + bool pass = false; + + switch (expected) { + case lt: + if (result < 0) + pass = true; + break; + case z: + if (!result) + pass = true; + break; + case gt: + if (result > 0) + pass = true; + break; + default: + pass = false; //should not get here + } + +#ifdef DEBUG_ASSERT + assert(pass); +#endif + + return 0; +} + + +int +test01() +{ + using namespace std; + + string str_0("costa rica"); + string str_1("costa marbella"); + string str_2; + + //sanity check + test_value(strcmp("costa marbella", "costa rica"), lt); + test_value(strcmp("costa rica", "costa rica"), z); + test_value(strcmp(str_1.data(), str_0.data()), lt); + test_value(strcmp(str_0.data(), str_1.data()), gt); + test_value(strncmp(str_1.data(), str_0.data(), 6), z); + test_value(strncmp(str_1.data(), str_0.data(), 14), lt); + test_value(memcmp(str_1.data(), str_0.data(), 6), z); + test_value(memcmp(str_1.data(), str_0.data(), 14), lt); + test_value(memcmp("costa marbella", "costa rica", 14), lt); + + // int compare(const basic_string& str) const; + test_value(str_0.compare(str_1), gt); //because r>m + test_value(str_1.compare(str_0), lt); //because m<r + str_2 = str_0; + test_value(str_2.compare(str_0), z); + str_2 = "cost"; + test_value(str_2.compare(str_0), lt); + str_2 = "costa ricans"; + test_value(str_2.compare(str_0), gt); + + // int compare(size_type pos1, size_type n1, const basic_string& str) const; + test_value(str_1.compare(0, 6, str_0), lt); + str_2 = "cost"; + test_value(str_1.compare(0, 4, str_2), z); + test_value(str_1.compare(0, 5, str_2), gt); + + // int compare(size_type pos1, size_type n1, const basic_string& str, + // size_type pos2, size_type n2) const; + test_value(str_1.compare(0, 6, str_0, 0, 6), z); + test_value(str_1.compare(0, 7, str_0, 0, 7), lt); + test_value(str_0.compare(0, 7, str_1, 0, 7), gt); + + // int compare(const charT* s) const; + test_value(str_0.compare("costa marbella"), gt); + test_value(str_1.compare("costa rica"), lt); + str_2 = str_0; + test_value(str_2.compare("costa rica"), z); + test_value(str_2.compare("cost"), gt); + test_value(str_2.compare("costa ricans"), lt); + + // int compare(size_type pos, size_type n1, const charT* str, + // size_type n2 = npos) const; + test_value(str_1.compare(0, 6, "costa rica", 0, 6), z); + test_value(str_1.compare(0, 7, "costa rica", 0, 7), lt); + test_value(str_0.compare(0, 7, "costa marbella", 0, 7), gt); + + return 0; +} + + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/compare/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/compare/wchar_t/1.cc new file mode 100644 index 00000000000..25f8abdab97 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/compare/wchar_t/1.cc @@ -0,0 +1,136 @@ +// 980930 bkoz work with libstdc++v3 + +// Copyright (C) 1998, 1999, 2003 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.6.8 basic_string::compare +// int compare(const basic_string& str) const; +// int compare(size_type pos1, size_type n1, const basic_string& str) const; +// int compare(size_type pos1, size_type n1, const basic_string& str, +// size_type pos2, size_type n2) const; +// int compare(const charT* s) const; +// int compare(size_type pos1, size_type n1, +// const charT* s, size_type n2 = npos) const; + +// NB compare should be thought of as a lexographical compare, ie how +// things would be sorted in a dictionary. + +#include <string> +#include <testsuite_hooks.h> + +enum want_value {lt=0, z=1, gt=2}; + +int +test_value(int result, want_value expected); + +int +test_value(int result, want_value expected) +{ + bool pass = false; + + switch (expected) { + case lt: + if (result < 0) + pass = true; + break; + case z: + if (!result) + pass = true; + break; + case gt: + if (result > 0) + pass = true; + break; + default: + pass = false; //should not get here + } + +#ifdef DEBUG_ASSERT + assert(pass); +#endif + + return 0; +} + + +int +test01() +{ + using namespace std; + + wstring str_0(L"costa rica"); + wstring str_1(L"costa marbella"); + wstring str_2; + + //sanity check + test_value(wcscmp(L"costa marbella", L"costa rica"), lt); + test_value(wcscmp(L"costa rica", L"costa rica"), z); + test_value(wcscmp(str_1.data(), str_0.data()), lt); + test_value(wcscmp(str_0.data(), str_1.data()), gt); + test_value(wcsncmp(str_1.data(), str_0.data(), 6), z); + test_value(wcsncmp(str_1.data(), str_0.data(), 14), lt); + test_value(wmemcmp(str_1.data(), str_0.data(), 6), z); + test_value(wmemcmp(str_1.data(), str_0.data(), 14), lt); + test_value(wmemcmp(L"costa marbella", L"costa rica", 14), lt); + + // int compare(const basic_string& str) const; + test_value(str_0.compare(str_1), gt); //because r>m + test_value(str_1.compare(str_0), lt); //because m<r + str_2 = str_0; + test_value(str_2.compare(str_0), z); + str_2 = L"cost"; + test_value(str_2.compare(str_0), lt); + str_2 = L"costa ricans"; + test_value(str_2.compare(str_0), gt); + + // int compare(size_type pos1, size_type n1, const basic_string& str) const; + test_value(str_1.compare(0, 6, str_0), lt); + str_2 = L"cost"; + test_value(str_1.compare(0, 4, str_2), z); + test_value(str_1.compare(0, 5, str_2), gt); + + // int compare(size_type pos1, size_type n1, const basic_string& str, + // size_type pos2, size_type n2) const; + test_value(str_1.compare(0, 6, str_0, 0, 6), z); + test_value(str_1.compare(0, 7, str_0, 0, 7), lt); + test_value(str_0.compare(0, 7, str_1, 0, 7), gt); + + // int compare(const charT* s) const; + test_value(str_0.compare(L"costa marbella"), gt); + test_value(str_1.compare(L"costa rica"), lt); + str_2 = str_0; + test_value(str_2.compare(L"costa rica"), z); + test_value(str_2.compare(L"cost"), gt); + test_value(str_2.compare(L"costa ricans"), lt); + + // int compare(size_type pos, size_type n1, const charT* str, + // size_type n2 = npos) const; + test_value(str_1.compare(0, 6, L"costa rica", 0, 6), z); + test_value(str_1.compare(0, 7, L"costa rica", 0, 7), lt); + test_value(str_0.compare(0, 7, L"costa marbella", 0, 7), gt); + + return 0; +} + + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/1.cc new file mode 100644 index 00000000000..3c92910f312 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/1.cc @@ -0,0 +1,161 @@ +// 1999-06-04 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.1 basic_string constructors. + +#include <new> +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +void 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 char str_lit01[] = "rodeo beach, marin"; + const std::string str01(str_lit01); + const std::string str02("baker beach, san francisco"); + + // basic_string(const string&, size_type pos = 0, siz_type n = npos, alloc) + csz01 = str01.size(); + try { + std::string str03(str01, csz01 + 1); + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + try { + std::string str03(str01, csz01); + VERIFY( str03.size() == 0 ); + VERIFY( str03.size() <= str03.capacity() ); + } + catch(...) { + VERIFY( false ); + } + + // basic_string(const char* s, size_type n, alloc) + csz01 = str01.max_size(); + // NB: As strlen(str_lit01) != csz01, this test is undefined. It + // should not crash, but what gets constructed is a bit arbitrary. + try { + std::string str03(str_lit01, csz01 + 1); + VERIFY( true ); + } + catch(std::length_error& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + // NB: As strlen(str_lit01) != csz01, this test is undefined. It + // should not crash, but what gets constructed is a bit arbitrary. + // The "maverick's" of all string objects. + try { + std::string str04(str_lit01, npos); + VERIFY( true ); + } + catch(std::length_error& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + // Build a maxsize - 1 lengthed string consisting of all A's + try { + std::string str03(csz01 - 1, 'A'); + VERIFY( str03.size() == csz01 - 1 ); + VERIFY( str03.size() <= str03.capacity() ); + } + // NB: bad_alloc is regrettable but entirely kosher for + // out-of-memory situations. + catch(std::bad_alloc& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + // basic_string(const char* s, const allocator& a = allocator()) + std::string str04(str_lit01); + VERIFY( str01 == str04 ); + + + // basic_string(size_type n, char c, const allocator& a = allocator()) + csz01 = str01.max_size(); + try { + std::string str03(csz01 + 1, 'z'); + VERIFY( false ); + } + catch(std::length_error& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + try { + std::string str04(npos, 'b'); // the "maverick's" of all string objects. + VERIFY( false ); + } + catch(std::length_error& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + try { + std::string str03(csz01 - 1, 'z'); + VERIFY( str03.size() != 0 ); + VERIFY( str03.size() <= str03.capacity() ); + } + // NB: bad_alloc is regrettable but entirely kosher for + // out-of-memory situations. + catch(std::bad_alloc& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + + // template<typename _InputIter> + // basic_string(_InputIter begin, _InputIter end, const allocator& a) + std::string str06(str01.begin(), str01.end()); + VERIFY( str06 == str01 ); +} + +int main() +{ + __gnu_cxx_test::set_memory_limits(); + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/2.cc new file mode 100644 index 00000000000..d6458a96712 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/2.cc @@ -0,0 +1,41 @@ +// 1999-06-04 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.1 basic_string constructors. + +#include <string> +#include <testsuite_hooks.h> + +void test02() +{ + bool test = true; + + // template<typename _InputIter> + // basic_string(_InputIter begin, _InputIter end, const allocator& a) + // where _InputIter is integral [21.3.1 para 15] + std::string s(10,0); + VERIFY( s.size() == 10 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/3.cc new file mode 100644 index 00000000000..6f40dda1833 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/3.cc @@ -0,0 +1,69 @@ +// 1999-06-04 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.1 basic_string constructors. + +#include <new> +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +void test03() +{ + bool test = true; + const char* with_nulls = "This contains \0 a zero byte."; + + // These are tests to see how basic_string handles data with NUL + // bytes. Obviously basic_string(char*) will halt at the first one, but + // nothing else should. + std::string s1 (with_nulls, 28); + VERIFY( s1.size() == 28 ); + std::string s2 (s1); + VERIFY( s2.size() == 28 ); + + // Not defined, but libstdc++ throws an exception. + const char* bogus = 0; + try + { + std::string str1(bogus); + VERIFY( false ); + } + catch(std::exception& fail) + { + VERIFY( true ); + } + + // Not defined, but libstdc++ throws an exception. + try + { + std::string str2(bogus, 5); + VERIFY( false ); + } + catch(std::exception& fail) + { + VERIFY( true ); + } +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/4.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/4.cc new file mode 100644 index 00000000000..fe2f3213215 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/4.cc @@ -0,0 +1,43 @@ +// 1999-06-04 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.1 basic_string constructors. + +#include <string> +#include <testsuite_hooks.h> + +// http://gcc.gnu.org/ml/libstdc++/2002-06/msg00025.html +void test04() +{ + bool test = true; + + std::string str01("portofino"); + + std::string::reverse_iterator i1 = str01.rbegin(); + std::string::reverse_iterator i2 = str01.rend(); + std::string str02(i1, i2); + VERIFY( str02 == "onifotrop" ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/5.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/5.cc new file mode 100644 index 00000000000..4b2f4015854 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/5.cc @@ -0,0 +1,44 @@ +// 1999-06-04 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.1 basic_string constructors. + +#include <string> +#include <vector> +#include <testsuite_hooks.h> + +// libstdc++/8347 +void test05() +{ + bool test = true; + + std::vector<char> empty; + std::string empty2(empty.begin(), empty.end()); + + // libstdc++/8716 (same underlying situation, same fix) + char const * s = NULL; + std::string zero_length_built_with_NULL(s,0); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/1.cc new file mode 100644 index 00000000000..eeb3516d236 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/1.cc @@ -0,0 +1,161 @@ +// 1999-06-04 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.1 basic_string constructors. + +#include <new> +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test = true; + typedef std::wstring::size_type csize_type; + typedef std::wstring::iterator citerator; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + + const wchar_t str_lit01[] = L"rodeo beach, marin"; + const std::wstring str01(str_lit01); + const std::wstring str02(L"baker beach, san francisco"); + + // basic_string(const wstring&, size_type pos = 0, siz_type n = npos, alloc) + csz01 = str01.size(); + try { + std::wstring str03(str01, csz01 + 1); + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + try { + std::wstring str03(str01, csz01); + VERIFY( str03.size() == 0 ); + VERIFY( str03.size() <= str03.capacity() ); + } + catch(...) { + VERIFY( false ); + } + + // basic_string(const wchar_t* s, size_type n, alloc) + csz01 = str01.max_size(); + // NB: As strlen(str_lit01) != csz01, this test is undefined. It + // should not crash, but what gets constructed is a bit arbitrary. + try { + std::wstring str03(str_lit01, csz01 + 1); + VERIFY( true ); + } + catch(std::length_error& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + // NB: As strlen(str_lit01) != csz01, this test is undefined. It + // should not crash, but what gets constructed is a bit arbitrary. + // The "maverick's" of all string objects. + try { + std::wstring str04(str_lit01, npos); + VERIFY( true ); + } + catch(std::length_error& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + // Build a maxsize - 1 lengthed string consisting of all A's + try { + std::wstring str03(csz01 - 1, 'A'); + VERIFY( str03.size() == csz01 - 1 ); + VERIFY( str03.size() <= str03.capacity() ); + } + // NB: bad_alloc is regrettable but entirely kosher for + // out-of-memory situations. + catch(std::bad_alloc& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + // basic_string(const wchar_t* s, const allocator& a = allocator()) + std::wstring str04(str_lit01); + VERIFY( str01 == str04 ); + + + // basic_string(size_type n, char c, const allocator& a = allocator()) + csz01 = str01.max_size(); + try { + std::wstring str03(csz01 + 1, L'z'); + VERIFY( false ); + } + catch(std::length_error& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + try { + std::wstring str04(npos, L'b'); // the "maverick's" of all string objects. + VERIFY( false ); + } + catch(std::length_error& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + try { + std::wstring str03(csz01 - 1, L'z'); + VERIFY( str03.size() != 0 ); + VERIFY( str03.size() <= str03.capacity() ); + } + // NB: bad_alloc is regrettable but entirely kosher for + // out-of-memory situations. + catch(std::bad_alloc& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + + // template<typename _InputIter> + // basic_string(_InputIter begin, _InputIter end, const allocator& a) + std::wstring str06(str01.begin(), str01.end()); + VERIFY( str06 == str01 ); +} + +int main() +{ + __gnu_cxx_test::set_memory_limits(); + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/2.cc new file mode 100644 index 00000000000..9eaf4ce2700 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/2.cc @@ -0,0 +1,41 @@ +// 1999-06-04 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.1 basic_string constructors. + +#include <string> +#include <testsuite_hooks.h> + +void test02() +{ + bool test = true; + + // template<typename _InputIter> + // basic_string(_InputIter begin, _InputIter end, const allocator& a) + // where _InputIter is integral [21.3.1 para 15] + std::wstring s(10, 0); + VERIFY( s.size() == 10 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/3.cc new file mode 100644 index 00000000000..46b7287b0e0 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/3.cc @@ -0,0 +1,69 @@ +// 1999-06-04 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.1 basic_string constructors. + +#include <new> +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +void test03() +{ + bool test = true; + const wchar_t* with_nulls = L"This contains \0 a zero byte."; + + // These are tests to see how basic_string handles data with NUL + // bytes. Obviously basic_string(char*) will halt at the first one, but + // nothing else should. + std::wstring s1 (with_nulls, 28); + VERIFY( s1.size() == 28 ); + std::wstring s2 (s1); + VERIFY( s2.size() == 28 ); + + // Not defined, but libstdc++ throws an exception. + const wchar_t* bogus = 0; + try + { + std::wstring str1(bogus); + VERIFY( false ); + } + catch(std::exception& fail) + { + VERIFY( true ); + } + + // Not defined, but libstdc++ throws an exception. + try + { + std::wstring str2(bogus, 5); + VERIFY( false ); + } + catch(std::exception& fail) + { + VERIFY( true ); + } +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/4.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/4.cc new file mode 100644 index 00000000000..87dab121eab --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/4.cc @@ -0,0 +1,43 @@ +// 1999-06-04 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.1 basic_string constructors. + +#include <string> +#include <testsuite_hooks.h> + +// http://gcc.gnu.org/ml/libstdc++/2002-06/msg00025.html +void test04() +{ + bool test = true; + + std::wstring str01(L"portofino"); + + std::wstring::reverse_iterator i1 = str01.rbegin(); + std::wstring::reverse_iterator i2 = str01.rend(); + std::wstring str02(i1, i2); + VERIFY( str02 == L"onifotrop" ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/5.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/5.cc new file mode 100644 index 00000000000..d02dc9c8f4b --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/5.cc @@ -0,0 +1,44 @@ +// 1999-06-04 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.1 basic_string constructors. + +#include <string> +#include <vector> +#include <testsuite_hooks.h> + +// libstdc++/8347 +void test05() +{ + bool test = true; + + std::vector<wchar_t> empty; + std::wstring empty2(empty.begin(), empty.end()); + + // libstdc++/8716 (same underlying situation, same fix) + wchar_t const * s = NULL; + std::wstring zero_length_built_with_NULL(s,0); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/1.cc new file mode 100644 index 00000000000..069aa278680 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/1.cc @@ -0,0 +1,94 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999, 2003 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.4 basic_string element access + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::string::size_type csize_type; + typedef std::string::const_reference cref; + typedef std::string::reference ref; + csize_type npos = std::string::npos; + csize_type csz01, csz02; + + const std::string str01("tamarindo, costa rica"); + std::string str02("41st street beach, capitola, california"); + std::string str03; + + // const_reference operator[] (size_type pos) const; + csz01 = str01.size(); + cref cref1 = str01[csz01 - 1]; + VERIFY( cref1 == 'a' ); + cref cref2 = str01[csz01]; + VERIFY( cref2 == char() ); + + // reference operator[] (size_type pos); + csz02 = str02.size(); + ref ref1 = str02[csz02 - 1]; + VERIFY( ref1 == 'a' ); + ref ref2 = str02[1]; + VERIFY( ref2 == '1' ); + + // const_reference at(size_type pos) const; + csz01 = str01.size(); + cref cref3 = str01.at(csz01 - 1); + VERIFY( cref3 == 'a' ); + try { + cref cref4 = str01.at(csz01); + VERIFY( false ); // Should not get here, as exception thrown. + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + // reference at(size_type pos); + csz01 = str02.size(); + ref ref3 = str02.at(csz02 - 1); + VERIFY( ref3 == 'a' ); + try { + ref ref4 = str02.at(csz02); + VERIFY( false ); // Should not get here, as exception thrown. + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/2.cc new file mode 100644 index 00000000000..fbfa0136b67 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/2.cc @@ -0,0 +1,115 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999, 2003 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 template class basic_string + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +// Do a quick sanity check on known problems with element access and +// ref-counted strings. These should all pass, regardless of the +// underlying string implementation, of course. +bool test01(void) +{ + bool test = true; + typedef std::string::size_type csize_type; + typedef std::string::iterator siterator; + typedef std::string::reverse_iterator sriterator; + csize_type npos = std::string::npos; + csize_type csz01, csz02; + siterator it1; + sriterator rit1; + + std::string str01("montara beach, half moon bay"); + const std::string str02("ocean beach, san francisco"); + std::string str03; + + // 21.3 p 5 + + // References, pointers, and iterators referring to the elements of + // a basic_string may be invalidated by the following uses of that + // basic_string object: + + // ... + + // Susequent to any of the above uses except the forms of insert() + // and erase() which return iterators, the first call to non-const + // member functions operator[](), at(), begin(), rbegin(), end(), or + // rend() + + str03 = str01; + it1 = str01.begin(); + *it1 = 'x'; + VERIFY( str01[0] == 'x' ); + VERIFY( str03[0] == 'm' ); + + str03 = str01; + csz01 = str01.size(); + rit1 = str01.rbegin(); // NB: Pointing at one-past the end, so ... + *rit1 = 'z'; // ... but it's taken care of here + VERIFY( str01[csz01 - 1] == 'z' ); + VERIFY( str03[csz01 - 1] == 'y' ); + + str03 = str01; + csz01 = str01.size(); + std::string::reference r1 = str01.at(csz01 - 2); + VERIFY( str03 == str01 ); + r1 = 'd'; + VERIFY( str01[csz01 - 2] == 'd' ); + VERIFY( str03[csz01 - 2] == 'a' ); + + str03 = str01; + csz01 = str01.size(); + std::string::reference r2 = str01[csz01 - 3]; + VERIFY( str03 == str01 ); + r2 = 'w'; + VERIFY( str01[csz01 - 3] == 'w' ); + VERIFY( str03[csz01 - 3] == 'b' ); + + str03 = str01; + csz02 = str01.size(); + it1 = str01.end(); + VERIFY( str03 == str01 ); + --it1; + *it1 = 'q'; + VERIFY( str01[csz02 - 1] == 'q' ); + VERIFY( str03[csz02 - 1] == 'z' ); + + str03 = str01; + rit1 = str01.rend(); + VERIFY( str03 == str01 ); + --rit1; + *rit1 = 'p'; + VERIFY( str01[0] == 'p' ); + VERIFY( str03[0] == 'x' ); + + // need to also test for const begin/const end +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/3.cc new file mode 100644 index 00000000000..426d0e39638 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/3.cc @@ -0,0 +1,90 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999, 2003 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 template class basic_string + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +// Do another sanity check, this time for member functions that return +// iterators, namely insert and erase. +bool test02(void) +{ + bool test = true; + typedef std::string::size_type csize_type; + typedef std::string::iterator siterator; + typedef std::string::reverse_iterator sriterator; + csize_type npos = std::string::npos; + csize_type csz01, csz02; + siterator it1; + sriterator rit1; + + const std::string str01("its beach, santa cruz"); + + std::string str02 = str01; + std::string str05 = str02; // optional, so that begin below causes a mutate + std::string::iterator p = str02.insert(str02.begin(), ' '); + std::string str03 = str02; + VERIFY( str03 == str02 ); + *p = '!'; + VERIFY( *str03.c_str() == ' ' ); + str03[0] = '@'; + VERIFY( str02[0] == '!' ); + VERIFY( *p == '!' ); + VERIFY( str02 != str05 ); + VERIFY( str02 != str03 ); + + std::string str10 = str01; + std::string::iterator p2 = str10.insert(str10.begin(), 'a'); + std::string str11 = str10; + *p2 = 'e'; + VERIFY( str11 != str10 ); + + std::string str06 = str01; + std::string str07 = str06; // optional, so that begin below causes a mutate + p = str06.erase(str06.begin()); + std::string str08 = str06; + VERIFY( str08 == str06 ); + *p = '!'; + VERIFY( *str08.c_str() == 't' ); + str08[0] = '@'; + VERIFY( str06[0] == '!' ); + VERIFY( *p == '!' ); + VERIFY( str06 != str07 ); + VERIFY( str06 != str08 ); + + std::string str12 = str01; + p2 = str12.erase(str12.begin(), str12.begin() + str12.size() - 1); + std::string str13 = str12; + *p2 = 'e'; + VERIFY( str12 != str13 ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/1.cc new file mode 100644 index 00000000000..00394cf36c8 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/1.cc @@ -0,0 +1,94 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999, 2003 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.4 basic_string element access + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::wstring::size_type csize_type; + typedef std::wstring::const_reference cref; + typedef std::wstring::reference ref; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + + const std::wstring str01(L"tamarindo, costa rica"); + std::wstring str02(L"41st street beach, capitola, california"); + std::wstring str03; + + // const_reference operator[] (size_type pos) const; + csz01 = str01.size(); + cref cref1 = str01[csz01 - 1]; + VERIFY( cref1 == L'a' ); + cref cref2 = str01[csz01]; + VERIFY( cref2 == wchar_t() ); + + // reference operator[] (size_type pos); + csz02 = str02.size(); + ref ref1 = str02[csz02 - 1]; + VERIFY( ref1 == L'a' ); + ref ref2 = str02[1]; + VERIFY( ref2 == L'1' ); + + // const_reference at(size_type pos) const; + csz01 = str01.size(); + cref cref3 = str01.at(csz01 - 1); + VERIFY( cref3 == L'a' ); + try { + cref cref4 = str01.at(csz01); + VERIFY( false ); // Should not get here, as exception thrown. + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + // reference at(size_type pos); + csz01 = str02.size(); + ref ref3 = str02.at(csz02 - 1); + VERIFY( ref3 == L'a' ); + try { + ref ref4 = str02.at(csz02); + VERIFY( false ); // Should not get here, as exception thrown. + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/2.cc new file mode 100644 index 00000000000..37aec1c93ce --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/2.cc @@ -0,0 +1,115 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999, 2003 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 template class basic_string + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +// Do a quick sanity check on known problems with element access and +// ref-counted strings. These should all pass, regardless of the +// underlying string implementation, of course. +bool test01(void) +{ + bool test = true; + typedef std::wstring::size_type csize_type; + typedef std::wstring::iterator siterator; + typedef std::wstring::reverse_iterator sriterator; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + siterator it1; + sriterator rit1; + + std::wstring str01(L"montara beach, half moon bay"); + const std::wstring str02(L"ocean beach, san francisco"); + std::wstring str03; + + // 21.3 p 5 + + // References, pointers, and iterators referring to the elements of + // a basic_string may be invalidated by the following uses of that + // basic_string object: + + // ... + + // Susequent to any of the above uses except the forms of insert() + // and erase() which return iterators, the first call to non-const + // member functions operator[](), at(), begin(), rbegin(), end(), or + // rend() + + str03 = str01; + it1 = str01.begin(); + *it1 = L'x'; + VERIFY( str01[0] == L'x' ); + VERIFY( str03[0] == L'm' ); + + str03 = str01; + csz01 = str01.size(); + rit1 = str01.rbegin(); // NB: Pointing at one-past the end, so ... + *rit1 = L'z'; // ... but it's taken care of here + VERIFY( str01[csz01 - 1] == L'z' ); + VERIFY( str03[csz01 - 1] == L'y' ); + + str03 = str01; + csz01 = str01.size(); + std::wstring::reference r1 = str01.at(csz01 - 2); + VERIFY( str03 == str01 ); + r1 = L'd'; + VERIFY( str01[csz01 - 2] == L'd' ); + VERIFY( str03[csz01 - 2] == L'a' ); + + str03 = str01; + csz01 = str01.size(); + std::wstring::reference r2 = str01[csz01 - 3]; + VERIFY( str03 == str01 ); + r2 = L'w'; + VERIFY( str01[csz01 - 3] == L'w' ); + VERIFY( str03[csz01 - 3] == L'b' ); + + str03 = str01; + csz02 = str01.size(); + it1 = str01.end(); + VERIFY( str03 == str01 ); + --it1; + *it1 = L'q'; + VERIFY( str01[csz02 - 1] == L'q' ); + VERIFY( str03[csz02 - 1] == L'z' ); + + str03 = str01; + rit1 = str01.rend(); + VERIFY( str03 == str01 ); + --rit1; + *rit1 = L'p'; + VERIFY( str01[0] == L'p' ); + VERIFY( str03[0] == L'x' ); + + // need to also test for const begin/const end +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/3.cc new file mode 100644 index 00000000000..b7710382ca8 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/3.cc @@ -0,0 +1,90 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999, 2003 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 template class basic_string + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +// Do another sanity check, this time for member functions that return +// iterators, namely insert and erase. +bool test02(void) +{ + bool test = true; + typedef std::wstring::size_type csize_type; + typedef std::wstring::iterator siterator; + typedef std::wstring::reverse_iterator sriterator; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + siterator it1; + sriterator rit1; + + const std::wstring str01(L"its beach, santa cruz"); + + std::wstring str02 = str01; + std::wstring str05 = str02; // optional, so that begin below causes a mutate + std::wstring::iterator p = str02.insert(str02.begin(), L' '); + std::wstring str03 = str02; + VERIFY( str03 == str02 ); + *p = L'!'; + VERIFY( *str03.c_str() == L' ' ); + str03[0] = L'@'; + VERIFY( str02[0] == L'!' ); + VERIFY( *p == L'!' ); + VERIFY( str02 != str05 ); + VERIFY( str02 != str03 ); + + std::wstring str10 = str01; + std::wstring::iterator p2 = str10.insert(str10.begin(), L'a'); + std::wstring str11 = str10; + *p2 = L'e'; + VERIFY( str11 != str10 ); + + std::wstring str06 = str01; + std::wstring str07 = str06; // optional, so that begin below causes a mutate + p = str06.erase(str06.begin()); + std::wstring str08 = str06; + VERIFY( str08 == str06 ); + *p = L'!'; + VERIFY( *str08.c_str() == L't' ); + str08[0] = L'@'; + VERIFY( str06[0] == L'!' ); + VERIFY( *p == L'!' ); + VERIFY( str06 != str07 ); + VERIFY( str06 != str08 ); + + std::wstring str12 = str01; + p2 = str12.erase(str12.begin(), str12.begin() + str12.size() - 1); + std::wstring str13 = str12; + *p2 = L'e'; + VERIFY( str12 != str13 ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/find/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/find/char/1.cc new file mode 100644 index 00000000000..e59f577374a --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/find/char/1.cc @@ -0,0 +1,198 @@ +// 1999-06-09 bkoz + +// Copyright (C) 1994, 1999, 2000, 2003 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.6.1 basic_string find + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::string::size_type csize_type; + typedef std::string::const_reference cref; + typedef std::string::reference ref; + csize_type npos = std::string::npos; + csize_type csz01, csz02; + + const char str_lit01[] = "mave"; + const std::string str01("mavericks, santa cruz"); + std::string str02(str_lit01); + std::string str03("s, s"); + std::string str04; + + // size_type find(const string&, size_type pos = 0) const; + csz01 = str01.find(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str01, 4); + VERIFY( csz01 == npos ); + csz01 = str01.find(str02, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str02, 3); + VERIFY( csz01 == npos ); + csz01 = str01.find(str03, 0); + VERIFY( csz01 == 8 ); + csz01 = str01.find(str03, 3); + VERIFY( csz01 == 8 ); + csz01 = str01.find(str03, 12); + VERIFY( csz01 == npos ); + + // An empty string consists of no characters + // therefore it should be found at every point in a string, + // except beyond the end + csz01 = str01.find(str04, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str04, 5); + VERIFY( csz01 == 5 ); + csz01 = str01.find(str04, str01.size()); + VERIFY( csz01 == str01.size() ); + csz01 = str01.find(str04, str01.size()+1); + VERIFY( csz01 == npos ); + + // size_type find(const char* s, size_type pos, size_type n) const; + csz01 = str01.find(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str_lit01, 3, 0); + VERIFY( csz01 == 3 ); + + // size_type find(const char* s, size_type pos = 0) const; + csz01 = str01.find(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str_lit01, 3); + VERIFY( csz01 == npos ); + + // size_type find(char c, size_type pos = 0) const; + csz01 = str01.find('z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + csz01 = str01.find('/'); + VERIFY( csz01 == npos ); + + // size_type find_first_of(const string&, size_type pos = 0) const; + std::string str05("xena rulez"); + csz01 = str01.find_first_of(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str01, 4); + VERIFY( csz01 == 4 ); + csz01 = str01.find_first_of(str02, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str02, 3); + VERIFY( csz01 == 3 ); + csz01 = str01.find_first_of(str03, 0); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_of(str03, 3); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_of(str03, 12); + VERIFY( csz01 == 16 ); + csz01 = str01.find_first_of(str05, 0); + VERIFY( csz01 == 1 ); + csz01 = str01.find_first_of(str05, 4); + VERIFY( csz01 == 4 ); + + // An empty string consists of no characters + // therefore it should be found at every point in a string, + // except beyond the end + // However, str1.find_first_of(str2,pos) finds the first character in + // str1 (starting at pos) that exists in str2, which is none for empty str2 + csz01 = str01.find_first_of(str04, 0); + VERIFY( csz01 == npos ); + csz01 = str01.find_first_of(str04, 5); + VERIFY( csz01 == npos ); + + // size_type find_first_of(const char* s, size_type pos, size_type n) const; + csz01 = str01.find_first_of(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str_lit01, 3, 0); + VERIFY( csz01 == npos ); + + // size_type find_first_of(const char* s, size_type pos = 0) const; + csz01 = str01.find_first_of(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str_lit01, 3); + VERIFY( csz01 == 3 ); + + // size_type find_first_of(char c, size_type pos = 0) const; + csz01 = str01.find_first_of('z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + + // size_type find_last_of(const string& str, size_type pos = 0) const; + // size_type find_last_of(const char* s, size_type pos, size_type n) const; + // size_type find_last_of(const char* s, size_type pos = 0) const; + // size_type find_last_of(char c, size_type pos = 0) const; + +#if 1 +// from tstring.cc, from jason merrill, et. al. + std::string x; + std::string::size_type pos; + pos = x.find_last_not_of('X'); + VERIFY( pos == npos ); + pos = x.find_last_not_of("XYZ"); + VERIFY( pos == npos ); + + std::string y("a"); + pos = y.find_last_not_of('X'); + VERIFY( pos == 0 ); + pos = y.find_last_not_of('a'); + VERIFY( pos == npos ); + pos = y.find_last_not_of("XYZ"); + VERIFY( pos == 0 ); + pos = y.find_last_not_of("a"); + VERIFY( pos == npos ); + + std::string z("ab"); + pos = z.find_last_not_of('X'); + VERIFY( pos == 1 ); + pos = z.find_last_not_of("XYZ"); + VERIFY( pos == 1 ); + pos = z.find_last_not_of('b'); + VERIFY( pos == 0 ); + pos = z.find_last_not_of("Xb"); + VERIFY( pos == 0 ); + pos = z.find_last_not_of("Xa"); + VERIFY( pos == 1 ); + pos = z.find_last_of("ab"); + VERIFY( pos == 1 ); + pos = z.find_last_of("Xa"); + VERIFY( pos == 0 ); + pos = z.find_last_of("Xb"); + VERIFY( pos == 1 ); + pos = z.find_last_of("XYZ"); + VERIFY( pos == std::string::npos ); + pos = z.find_last_of('a'); + VERIFY( pos == 0 ); + pos = z.find_last_of('b'); + VERIFY( pos == 1 ); + pos = z.find_last_of('X'); + VERIFY( pos == std::string::npos ); +#endif + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/find/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/find/wchar_t/1.cc new file mode 100644 index 00000000000..4cd643ebcf5 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/find/wchar_t/1.cc @@ -0,0 +1,198 @@ +// 1999-06-09 bkoz + +// Copyright (C) 1994, 1999, 2000, 2003 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.6.1 basic_string find + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::wstring::size_type csize_type; + typedef std::wstring::const_reference cref; + typedef std::wstring::reference ref; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + + const wchar_t str_lit01[] = L"mave"; + const std::wstring str01(L"mavericks, santa cruz"); + std::wstring str02(str_lit01); + std::wstring str03(L"s, s"); + std::wstring str04; + + // size_type find(const wstring&, size_type pos = 0) const; + csz01 = str01.find(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str01, 4); + VERIFY( csz01 == npos ); + csz01 = str01.find(str02, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str02, 3); + VERIFY( csz01 == npos ); + csz01 = str01.find(str03, 0); + VERIFY( csz01 == 8 ); + csz01 = str01.find(str03, 3); + VERIFY( csz01 == 8 ); + csz01 = str01.find(str03, 12); + VERIFY( csz01 == npos ); + + // An empty string consists of no characters + // therefore it should be found at every point in a string, + // except beyond the end + csz01 = str01.find(str04, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str04, 5); + VERIFY( csz01 == 5 ); + csz01 = str01.find(str04, str01.size()); + VERIFY( csz01 == str01.size() ); + csz01 = str01.find(str04, str01.size()+1); + VERIFY( csz01 == npos ); + + // size_type find(const wchar_t* s, size_type pos, size_type n) const; + csz01 = str01.find(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str_lit01, 3, 0); + VERIFY( csz01 == 3 ); + + // size_type find(const wchar_t* s, size_type pos = 0) const; + csz01 = str01.find(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str_lit01, 3); + VERIFY( csz01 == npos ); + + // size_type find(wchar_t c, size_type pos = 0) const; + csz01 = str01.find(L'z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + csz01 = str01.find(L'/'); + VERIFY( csz01 == npos ); + + // size_type find_first_of(const wstring&, size_type pos = 0) const; + std::wstring str05(L"xena rulez"); + csz01 = str01.find_first_of(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str01, 4); + VERIFY( csz01 == 4 ); + csz01 = str01.find_first_of(str02, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str02, 3); + VERIFY( csz01 == 3 ); + csz01 = str01.find_first_of(str03, 0); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_of(str03, 3); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_of(str03, 12); + VERIFY( csz01 == 16 ); + csz01 = str01.find_first_of(str05, 0); + VERIFY( csz01 == 1 ); + csz01 = str01.find_first_of(str05, 4); + VERIFY( csz01 == 4 ); + + // An empty string consists of no characters + // therefore it should be found at every point in a string, + // except beyond the end + // However, str1.find_first_of(str2,pos) finds the first character in + // str1 (starting at pos) that exists in str2, which is none for empty str2 + csz01 = str01.find_first_of(str04, 0); + VERIFY( csz01 == npos ); + csz01 = str01.find_first_of(str04, 5); + VERIFY( csz01 == npos ); + + // size_type find_first_of(const wchar_t* s, size_type pos, size_type n) const; + csz01 = str01.find_first_of(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str_lit01, 3, 0); + VERIFY( csz01 == npos ); + + // size_type find_first_of(const char* s, size_type pos = 0) const; + csz01 = str01.find_first_of(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str_lit01, 3); + VERIFY( csz01 == 3 ); + + // size_type find_first_of(wchar_t c, size_type pos = 0) const; + csz01 = str01.find_first_of(L'z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + + // size_type find_last_of(const wstring& str, size_type pos = 0) const; + // size_type find_last_of(const wchar_t* s, size_type pos, size_type n) const; + // size_type find_last_of(const wchar_t* s, size_type pos = 0) const; + // size_type find_last_of(wchar_t c, size_type pos = 0) const; + +#if 1 +// from tstring.cc, from jason merrill, et. al. + std::wstring x; + std::wstring::size_type pos; + pos = x.find_last_not_of(L'X'); + VERIFY( pos == npos ); + pos = x.find_last_not_of(L"XYZ"); + VERIFY( pos == npos ); + + std::wstring y(L"a"); + pos = y.find_last_not_of(L'X'); + VERIFY( pos == 0 ); + pos = y.find_last_not_of(L'a'); + VERIFY( pos == npos ); + pos = y.find_last_not_of(L"XYZ"); + VERIFY( pos == 0 ); + pos = y.find_last_not_of(L"a"); + VERIFY( pos == npos ); + + std::wstring z(L"ab"); + pos = z.find_last_not_of(L'X'); + VERIFY( pos == 1 ); + pos = z.find_last_not_of(L"XYZ"); + VERIFY( pos == 1 ); + pos = z.find_last_not_of(L'b'); + VERIFY( pos == 0 ); + pos = z.find_last_not_of(L"Xb"); + VERIFY( pos == 0 ); + pos = z.find_last_not_of(L"Xa"); + VERIFY( pos == 1 ); + pos = z.find_last_of(L"ab"); + VERIFY( pos == 1 ); + pos = z.find_last_of(L"Xa"); + VERIFY( pos == 0 ); + pos = z.find_last_of(L"Xb"); + VERIFY( pos == 1 ); + pos = z.find_last_of(L"XYZ"); + VERIFY( pos == std::wstring::npos ); + pos = z.find_last_of(L'a'); + VERIFY( pos == 0 ); + pos = z.find_last_of(L'b'); + VERIFY( pos == 1 ); + pos = z.find_last_of(L'X'); + VERIFY( pos == std::wstring::npos ); +#endif + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/insert/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/insert/char/1.cc new file mode 100644 index 00000000000..a6052e2170b --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/insert/char/1.cc @@ -0,0 +1,195 @@ +// 1999-06-03 bkoz + +// Copyright (C) 1999, 2003 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() +{ + __gnu_cxx_test::set_memory_limits(); + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/insert/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/insert/char/2.cc new file mode 100644 index 00000000000..80b0cee58b7 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/insert/char/2.cc @@ -0,0 +1,87 @@ +// 1999-06-03 bkoz + +// Copyright (C) 1999, 2003 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 <testsuite_hooks.h> + +// More +// string& insert(size_type __p, const char* s, size_type n); +// string& insert(size_type __p, const char* s); +// but now s points inside the _Rep +int test02(void) +{ + bool test = true; + + std::string str01; + const char* title = "Everything was beautiful, and nothing hurt"; + // Increasing size: str01 is reallocated every time. + str01 = title; + str01.insert(0, str01.c_str() + str01.size() - 4, 4); + VERIFY( str01 == "hurtEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str(), 5); + VERIFY( str01 == "EveryEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(10, str01.c_str() + 4, 6); + VERIFY( str01 == "Everythingything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str(), 10); + VERIFY( str01 == "Everything was Everythingbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str() + 11, 13); + VERIFY( str01 == "Everything was was beautifulbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str()); + VERIFY( str01 == "Everything was beautiful, and nothing hurt" + "Everything was beautiful, and nothing hurt"); + // Again: no reallocations. + str01 = title; + str01.insert(0, str01.c_str() + str01.size() - 4, 4); + VERIFY( str01 == "hurtEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str(), 5); + VERIFY( str01 == "EveryEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(10, str01.c_str() + 4, 6); + VERIFY( str01 == "Everythingything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str(), 10); + VERIFY( str01 == "Everything was Everythingbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str() + 11, 13); + VERIFY( str01 == "Everything was was beautifulbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str()); + VERIFY( str01 == "Everything was beautiful, and nothing hurt" + "Everything was beautiful, and nothing hurt"); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/insert/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/insert/wchar_t/1.cc new file mode 100644 index 00000000000..96f71b0839e --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/insert/wchar_t/1.cc @@ -0,0 +1,195 @@ +// 1999-06-03 bkoz + +// Copyright (C) 1999, 2003 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::wstring::size_type csize_type; + typedef std::wstring::iterator citerator; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + + const std::wstring str01(L"rodeo beach, marin"); + const std::wstring str02(L"baker beach, san francisco"); + std::wstring str03; + + // wstring& insert(size_type p1, const wstring& 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 wstring 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::wstring str04(csz01, L'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 == L"rodeo beach, baker beach,marin" ); + + str03 = str01; + csz01 = str03.size(); + csz02 = str02.size(); + str03.insert(0, str02, 0, 12); + VERIFY( str03 == L"baker beach,rodeo beach, marin" ); + + str03 = str01; + csz01 = str03.size(); + csz02 = str02.size(); + str03.insert(csz01, str02, 0, csz02); + VERIFY( str03 == L"rodeo beach, marinbaker beach, san francisco" ); + + // wstring& insert(size_type __p, const wstring& wstr); + // insert(p1, str, 0, npos) + str03 = str01; + csz01 = str03.size(); + csz02 = str02.size(); + str03.insert(csz01, str02); + VERIFY( str03 == L"rodeo beach, marinbaker beach, san francisco" ); + + str03 = str01; + csz01 = str03.size(); + csz02 = str02.size(); + str03.insert(0, str02); + VERIFY( str03 == L"baker beach, san franciscorodeo beach, marin" ); + + // wstring& insert(size_type __p, const wchar_t* s, size_type n); + // insert(p1, wstring(s,n)) + str03 = str02; + csz01 = str03.size(); + str03.insert(0, L"-break at the bridge", 20); + VERIFY( str03 == L"-break at the bridgebaker beach, san francisco" ); + + // wstring& insert(size_type __p, const wchar_t* s); + // insert(p1, wstring(s)) + str03 = str02; + str03.insert(0, L"-break at the bridge"); + VERIFY( str03 == L"-break at the bridgebaker beach, san francisco" ); + + // wstring& insert(size_type __p, size_type n, wchar_t c) + // insert(p1, wstring(n,c)) + str03 = str02; + csz01 = str03.size(); + str03.insert(csz01, 5, L'z'); + VERIFY( str03 == L"baker beach, san franciscozzzzz" ); + + // iterator insert(iterator p, wchar_t c) + // inserts a copy of c before the character referred to by p + str03 = str02; + citerator cit01 = str03.begin(); + str03.insert(cit01, L'u'); + VERIFY( str03 == L"ubaker beach, san francisco" ); + + // iterator insert(iterator p, size_type n, wchar_t c) + // inserts n copies of c before the character referred to by p + str03 = str02; + cit01 = str03.begin(); + str03.insert(cit01, 5, L'u'); + VERIFY( str03 == L"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(), wstring(first,last)) + str03 = str02; + csz01 = str03.size(); + str03.insert(str03.begin(), str01.begin(), str01.end()); + VERIFY( str03 == L"rodeo beach, marinbaker beach, san francisco" ); + + str03 = str02; + csz01 = str03.size(); + str03.insert(str03.end(), str01.begin(), str01.end()); + VERIFY( str03 == L"baker beach, san franciscorodeo beach, marin" ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + __gnu_cxx_test::set_memory_limits(); + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/insert/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/insert/wchar_t/2.cc new file mode 100644 index 00000000000..04cc454e14b --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/insert/wchar_t/2.cc @@ -0,0 +1,87 @@ +// 1999-06-03 bkoz + +// Copyright (C) 1999, 2003 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 <testsuite_hooks.h> + +// More +// wstring& insert(size_type __p, const wchar_t* s, size_type n); +// wstring& insert(size_type __p, const wchar_t* s); +// but now s points inside the _Rep +int test02(void) +{ + bool test = true; + + std::wstring str01; + const wchar_t* title = L"Everything was beautiful, and nothing hurt"; + // Increasing size: str01 is reallocated every time. + str01 = title; + str01.insert(0, str01.c_str() + str01.size() - 4, 4); + VERIFY( str01 == L"hurtEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str(), 5); + VERIFY( str01 == L"EveryEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(10, str01.c_str() + 4, 6); + VERIFY( str01 == L"Everythingything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str(), 10); + VERIFY( str01 == L"Everything was Everythingbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str() + 11, 13); + VERIFY( str01 == L"Everything was was beautifulbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str()); + VERIFY( str01 == L"Everything was beautiful, and nothing hurt" + L"Everything was beautiful, and nothing hurt"); + // Again: no reallocations. + str01 = title; + str01.insert(0, str01.c_str() + str01.size() - 4, 4); + VERIFY( str01 == L"hurtEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str(), 5); + VERIFY( str01 == L"EveryEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(10, str01.c_str() + 4, 6); + VERIFY( str01 == L"Everythingything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str(), 10); + VERIFY( str01 == L"Everything was Everythingbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str() + 11, 13); + VERIFY( str01 == L"Everything was was beautifulbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str()); + VERIFY( str01 == L"Everything was beautiful, and nothing hurt" + L"Everything was beautiful, and nothing hurt"); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/1.cc new file mode 100644 index 00000000000..4b862322653 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/1.cc @@ -0,0 +1,171 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <stdexcept> +#include <sstream> +#include <fstream> +#include <iostream> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::string::size_type csize_type; + typedef std::string::const_reference cref; + typedef std::string::reference ref; + csize_type npos = std::string::npos; + csize_type csz01, csz02; + + const std::string str01("sailing grand traverse bay\n" + "\t\t\t from Elk Rapids to the point reminds me of miles"); + const std::string str02("sailing"); + const std::string str03("grand"); + const std::string str04("traverse"); + const std::string str05; + std::string str10; + + // istream& operator>>(istream&, string&) + std::istringstream istrs01(str01); + istrs01 >> str10; + VERIFY( str10 == str02 ); + try + { + std::istringstream::int_type i01 = istrs01.peek(); //a-boo + VERIFY( std::istringstream::traits_type::to_char_type(i01) == ' ' ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + istrs01.clear(); + istrs01 >> str10; + VERIFY( str10 == str03 ); + istrs01.clear(); + istrs01 >> str10; + VERIFY( str10 == str04 ); // sentry picks out the white spaces. . + + std::istringstream istrs02(str05); // empty + istrs02 >> str10; + VERIFY( str10 == str04 ); + + // istream& getline(istream&, string&, char) + // istream& getline(istream&, string&) + try + { + istrs01.clear(); + getline(istrs01, str10); + VERIFY( !istrs01.fail() ); + VERIFY( !istrs01.eof() ); + VERIFY( istrs01.good() ); + VERIFY( str10 == " bay" ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + try + { + istrs01.clear(); + getline(istrs01, str10,'\t'); + VERIFY( !istrs01.fail() ); + VERIFY( !istrs01.eof() ); + VERIFY( istrs01.good() ); + VERIFY( str10 == str05 ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + try + { + istrs01.clear(); + getline(istrs01, str10,'\t'); + VERIFY( !istrs01.fail() ); + VERIFY( !istrs01.eof() ); + VERIFY( istrs01.good() ); + VERIFY( str10 == str05 ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + try + { + istrs01.clear(); + getline(istrs01, str10, '.'); + VERIFY( !istrs01.fail() ); + VERIFY( istrs01.eof() ); + VERIFY( !istrs01.good() ); + VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + try + { + getline(istrs02, str10); + VERIFY( istrs02.fail() ); + VERIFY( istrs02.eof() ); + VERIFY( str10 =="\t from Elk Rapids to the point reminds me of miles" ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + // ostream& operator<<(ostream&, const basic_string&) + std::ostringstream ostrs01; + try + { + ostrs01 << str01; + VERIFY( ostrs01.str() == str01 ); + } + catch(std::exception& fail) + { + VERIFY( false ); + } + + std::string hello_world; + std::cout << hello_world; + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/4.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/4.cc new file mode 100644 index 00000000000..55eecc19a28 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/4.cc @@ -0,0 +1,69 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +// testing basic_stringbuf::xsputn via stress testing with large strings +// based on a bug report libstdc++ 9 +void test04(int size) +{ + bool test = true; + std::string str(size, 's'); + int expected_size = 2 * (size + 1); + std::ostringstream oss(str); + + // sanity checks + VERIFY( str.size() == size ); + VERIFY( oss.good() ); + + // stress test + oss << str << std::endl; + if (!oss.good()) + test = false; + + oss << str << std::endl; + if (!oss.good()) + test = false; + + VERIFY( str.size() == size ); + VERIFY( oss.good() ); + std::string str_tmp = oss.str(); + VERIFY( str_tmp.size() == expected_size ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +int main() +{ + test04(1); // expected_size == 4 + test04(1000); // expected_size == 2002 + test04(10000); // expected_size == 20002 + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/5.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/5.cc new file mode 100644 index 00000000000..8e24f5b55b7 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/5.cc @@ -0,0 +1,90 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <fstream> +#include <iostream> +#include <testsuite_hooks.h> + +// testing basic_filebuf::xsputn via stress testing with large strings +// based on a bug report libstdc++ 9 +// mode == out +void test05(int size) +{ + bool test = true; + const char filename[] = "inserters_extractors-1.txt"; + const char fillc = 'f'; + std::ofstream ofs(filename); + std::string str(size, fillc); + + // sanity checks + VERIFY( str.size() == size ); + VERIFY( ofs.good() ); + + // stress test + ofs << str << std::endl; + if (!ofs.good()) + test = false; + + ofs << str << std::endl; + if (!ofs.good()) + test = false; + + VERIFY( str.size() == size ); + VERIFY( ofs.good() ); + + ofs.close(); + + // sanity check on the written file + std::ifstream ifs(filename); + int count = 0; + char c; + while (count <= (2 * size) + 4) + { + ifs >> c; + if (ifs.good() && c == fillc) + { + ++count; + c = '0'; + } + else + break; + } + + VERIFY( count == 2 * size ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +int main() +{ + test05(1); + test05(1000); + test05(10000); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/6.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/6.cc new file mode 100644 index 00000000000..5d426259752 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/6.cc @@ -0,0 +1,65 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +// istringstream/stringbuf extractor properly size buffer based on +// actual, not allocated contents (string.size() vs. string.capacity()). +// http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00049.html +void test06(void) +{ + bool test = true; + + typedef std::string::size_type size_type; + std::string str01("@silent"); + size_type i01 = str01.size(); + size_type i02 = str01.capacity(); + str01.erase(0, 1); + size_type i03 = str01.size(); + size_type i04 = str01.capacity(); + VERIFY( i01 - 1 == i03 ); + VERIFY( i02 >= i04 ); + + std::istringstream is(str01); + std::string str02; + is >> str02 >> std::ws; + size_type i05 = str02.size(); + size_type i06 = str02.capacity(); + VERIFY( i05 == i03 ); + VERIFY( i06 <= i04 ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/7.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/7.cc new file mode 100644 index 00000000000..7e6116ec148 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/7.cc @@ -0,0 +1,57 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00085.html +// istream::operator>>(string) +// sets failbit +// NB: this is a defect in the standard. +void test07(void) +{ + bool test = true; + const std::string name("z6.cc"); + std::istringstream iss (name); + int i = 0; + std::string s; + while (iss >> s) + ++i; + + VERIFY( i < 3 ); + VERIFY( static_cast<bool>(iss.rdstate() & std::ios_base::failbit) ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/8.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/8.cc new file mode 100644 index 00000000000..bdc848e8055 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/8.cc @@ -0,0 +1,53 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +// libstdc++/1019 +void test08() +{ + using namespace std; + + bool test = true; + istringstream istrm("enero:2001"); + int year; + char sep; + string month; + + istrm >> setw(5) >> month >> sep >> year; + VERIFY( month.size() == 5 ); + VERIFY( sep == ':' ); + VERIFY( year == 2001 ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/9.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/9.cc new file mode 100644 index 00000000000..fb201c26929 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/9.cc @@ -0,0 +1,56 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +// libstdc++/2830 +void test09() +{ + bool test = true; + std::string blanks( 3, '\0'); + std::string foo = "peace"; + foo += blanks; + foo += "& love"; + + std::ostringstream oss1; + oss1 << foo; + VERIFY( oss1.str() == foo ); + + std::ostringstream oss2; + oss2.width(20); + oss2 << foo; + VERIFY( oss2.str() != foo ); + VERIFY( oss2.str().size() == 20 ); +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/1.cc new file mode 100644 index 00000000000..5297958c453 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/1.cc @@ -0,0 +1,171 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <stdexcept> +#include <sstream> +#include <fstream> +#include <iostream> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::wstring::size_type csize_type; + typedef std::wstring::const_reference cref; + typedef std::wstring::reference ref; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + + const std::wstring str01(L"sailing grand traverse bay\n" + L"\t\t\t from Elk Rapids to the point reminds me of miles"); + const std::wstring str02(L"sailing"); + const std::wstring str03(L"grand"); + const std::wstring str04(L"traverse"); + const std::wstring str05; + std::wstring str10; + + // istream& operator>>(istream&, string&) + std::wistringstream istrs01(str01); + istrs01 >> str10; + VERIFY( str10 == str02 ); + try + { + std::wistringstream::int_type i01 = istrs01.peek(); //a-boo + VERIFY( std::wistringstream::traits_type::to_char_type(i01) == L' ' ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + istrs01.clear(); + istrs01 >> str10; + VERIFY( str10 == str03 ); + istrs01.clear(); + istrs01 >> str10; + VERIFY( str10 == str04 ); // sentry picks out the white spaces. . + + std::wistringstream istrs02(str05); // empty + istrs02 >> str10; + VERIFY( str10 == str04 ); + + // istream& getline(istream&, string&, char) + // istream& getline(istream&, string&) + try + { + istrs01.clear(); + getline(istrs01, str10); + VERIFY( !istrs01.fail() ); + VERIFY( !istrs01.eof() ); + VERIFY( istrs01.good() ); + VERIFY( str10 == L" bay" ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + try + { + istrs01.clear(); + getline(istrs01, str10, L'\t'); + VERIFY( !istrs01.fail() ); + VERIFY( !istrs01.eof() ); + VERIFY( istrs01.good() ); + VERIFY( str10 == str05 ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + try + { + istrs01.clear(); + getline(istrs01, str10, L'\t'); + VERIFY( !istrs01.fail() ); + VERIFY( !istrs01.eof() ); + VERIFY( istrs01.good() ); + VERIFY( str10 == str05 ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + try + { + istrs01.clear(); + getline(istrs01, str10, L'.'); + VERIFY( !istrs01.fail() ); + VERIFY( istrs01.eof() ); + VERIFY( !istrs01.good() ); + VERIFY( str10 == L"\t from Elk Rapids to the point reminds me of miles" ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + try + { + getline(istrs02, str10); + VERIFY( istrs02.fail() ); + VERIFY( istrs02.eof() ); + VERIFY( str10 == L"\t from Elk Rapids to the point reminds me of miles" ); + } + catch(std::exception& fail) + { + VERIFY( false ); // shouldn't throw + } + + // ostream& operator<<(ostream&, const basic_string&) + std::wostringstream ostrs01; + try + { + ostrs01 << str01; + VERIFY( ostrs01.str() == str01 ); + } + catch(std::exception& fail) + { + VERIFY( false ); + } + + std::wstring hello_world; + std::wcout << hello_world; + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/4.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/4.cc new file mode 100644 index 00000000000..f47d8da43aa --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/4.cc @@ -0,0 +1,69 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +// testing basic_stringbuf::xsputn via stress testing with large strings +// based on a bug report libstdc++ 9 +void test04(int size) +{ + bool test = true; + std::wstring str(size, L's'); + int expected_size = 2 * (size + 1); + std::wostringstream oss(str); + + // sanity checks + VERIFY( str.size() == size ); + VERIFY( oss.good() ); + + // stress test + oss << str << std::endl; + if (!oss.good()) + test = false; + + oss << str << std::endl; + if (!oss.good()) + test = false; + + VERIFY( str.size() == size ); + VERIFY( oss.good() ); + std::wstring str_tmp = oss.str(); + VERIFY( str_tmp.size() == expected_size ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +int main() +{ + test04(1); // expected_size == 4 + test04(1000); // expected_size == 2002 + test04(10000); // expected_size == 20002 + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/5.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/5.cc new file mode 100644 index 00000000000..e9a701e8c52 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/5.cc @@ -0,0 +1,90 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <fstream> +#include <iostream> +#include <testsuite_hooks.h> + +// testing basic_filebuf::xsputn via stress testing with large strings +// based on a bug report libstdc++ 9 +// mode == out +void test05(int size) +{ + bool test = true; + const char filename[] = "inserters_extractors-1.txt"; + const wchar_t fillc = L'f'; + std::wofstream ofs(filename); + std::wstring str(size, fillc); + + // sanity checks + VERIFY( str.size() == size ); + VERIFY( ofs.good() ); + + // stress test + ofs << str << std::endl; + if (!ofs.good()) + test = false; + + ofs << str << std::endl; + if (!ofs.good()) + test = false; + + VERIFY( str.size() == size ); + VERIFY( ofs.good() ); + + ofs.close(); + + // sanity check on the written file + std::wifstream ifs(filename); + int count = 0; + wchar_t c; + while (count <= (2 * size) + 4) + { + ifs >> c; + if (ifs.good() && c == fillc) + { + ++count; + c = '0'; + } + else + break; + } + + VERIFY( count == 2 * size ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +int main() +{ + test05(1); + test05(1000); + test05(10000); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/6.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/6.cc new file mode 100644 index 00000000000..aedcdb26391 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/6.cc @@ -0,0 +1,65 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +// istringstream/stringbuf extractor properly size buffer based on +// actual, not allocated contents (string.size() vs. string.capacity()). +// http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00049.html +void test06(void) +{ + bool test = true; + + typedef std::wstring::size_type size_type; + std::wstring str01(L"@silent"); + size_type i01 = str01.size(); + size_type i02 = str01.capacity(); + str01.erase(0, 1); + size_type i03 = str01.size(); + size_type i04 = str01.capacity(); + VERIFY( i01 - 1 == i03 ); + VERIFY( i02 >= i04 ); + + std::wistringstream is(str01); + std::wstring str02; + is >> str02 >> std::ws; + size_type i05 = str02.size(); + size_type i06 = str02.capacity(); + VERIFY( i05 == i03 ); + VERIFY( i06 <= i04 ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/7.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/7.cc new file mode 100644 index 00000000000..4028924674b --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/7.cc @@ -0,0 +1,57 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00085.html +// istream::operator>>(string) +// sets failbit +// NB: this is a defect in the standard. +void test07(void) +{ + bool test = true; + const std::wstring name(L"z6.cc"); + std::wistringstream iss(name); + int i = 0; + std::wstring s; + while (iss >> s) + ++i; + + VERIFY( i < 3 ); + VERIFY( static_cast<bool>(iss.rdstate() & std::ios_base::failbit) ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/8.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/8.cc new file mode 100644 index 00000000000..d43d818633f --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/8.cc @@ -0,0 +1,53 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +// libstdc++/1019 +void test08() +{ + using namespace std; + + bool test = true; + wistringstream istrm(L"enero:2001"); + int year; + wchar_t sep; + wstring month; + + istrm >> setw(5) >> month >> sep >> year; + VERIFY( month.size() == 5 ); + VERIFY( sep == ':' ); + VERIFY( year == 2001 ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/9.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/9.cc new file mode 100644 index 00000000000..726dacc9816 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/9.cc @@ -0,0 +1,56 @@ +// 1999-07-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003 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.7.9 inserters and extractors + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string class. + +#include <string> +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +// libstdc++/2830 +void test09() +{ + bool test = true; + std::wstring blanks(3, L'\0'); + std::wstring foo = L"peace"; + foo += blanks; + foo += L"& love"; + + std::wostringstream oss1; + oss1 << foo; + VERIFY( oss1.str() == foo ); + + std::wostringstream oss2; + oss2.width(20); + oss2 << foo; + VERIFY( oss2.str() != foo ); + VERIFY( oss2.str().size() == 20 ); +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/1.cc new file mode 100644 index 00000000000..da8b30638ff --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/1.cc @@ -0,0 +1,56 @@ +// 1999-05-07 bkoz + +// Copyright (C) 1999, 2003 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.6 string operations + +#include <string> +#include <cstdio> +#include <testsuite_hooks.h> + +int test01(void) +{ + bool test = true; + + std::string str1; + std::string str2; + + // Should get this: + // 1:8-chars_8-chars_ + // 2:8-chars_8-chars_ + str1 = std::string("8-chars_") + "8-chars_"; + const char* p1 = str1.c_str(); + // printf("1:%s\n", str1.c_str()); + str2 = str1 + "7-chars"; + // printf("2:%s\n", str1.c_str()); //str1 is gone + const char* p2 = str1.c_str(); + return 0; + +#ifdef DEBUG_ASSERT + assert(test); +#endif + + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/2.cc new file mode 100644 index 00000000000..c41ac68ffe2 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/2.cc @@ -0,0 +1,300 @@ +// 1998-10-01, 1999-06-25 bkoz + +// Copyright (C) 1998, 1999, 2003 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.7.1 basic_string non-member functions + +// 21.3.7.2 operator== +/* +template<class charT, class traits, class Allocator> + bool operator==(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator==(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator==(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); +*/ + +// 21.3.7.3 operator!= +/* +template<class charT, class traits, class Allocator> + bool operator!=(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator!=(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator!=(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); +*/ + +// 21.3.7.4 operator< +/* +template<class charT, class traits, class Allocator> + bool operator< (const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator< (const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator< (const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +// 21.3.7.5 operator> +/* +template<class charT, class traits, class Allocator> + bool operator> (const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator> (const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator> (const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +//21.3.7.6 operator<= +/* +template<class charT, class traits, class Allocator> + bool operator<=(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator<=(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator<=(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +// 21.3.7.7 operator>= +/* +template<class charT, class traits, class Allocator> + bool operator>=(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator>=(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator>=(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +#include <string> +#include <testsuite_hooks.h> + +int test01(void) +{ + bool test = true; + std::string str_0("costa rica"); + std::string str_1("costa marbella"); + std::string str_2("cost"); + std::string str_3("costa ricans"); + std::string str_4; + + str_4 = str_0; + //comparisons between string objects + VERIFY( !(str_0 == str_1) ); + VERIFY( !(str_0 == str_2) ); + VERIFY( !(str_0 == str_3) ); + VERIFY( !(str_1 == str_0) ); + VERIFY( !(str_2 == str_0) ); + VERIFY( !(str_3 == str_0) ); + VERIFY( str_4 == str_0 ); + VERIFY( str_0 == str_4 ); + + VERIFY( str_0 != str_1 ); + VERIFY( str_0 != str_2 ); + VERIFY( str_0 != str_3 ); + VERIFY( str_1 != str_0 ); + VERIFY( str_2 != str_0 ); + VERIFY( str_3 != str_0 ); + VERIFY( !(str_0 != str_4) ); + VERIFY( !(str_4 != str_0) ); + + VERIFY( str_0 > str_1 ); //true cuz r>m + VERIFY( str_0 > str_2 ); + VERIFY( !(str_0 > str_3) ); + VERIFY( !(str_1 > str_0) ); //false cuz m<r + VERIFY( !(str_2 > str_0) ); + VERIFY( str_3 > str_0 ); + VERIFY( !(str_0 > str_4) ); + VERIFY( !(str_4 > str_0) ); + + VERIFY( !(str_0 < str_1) ); //false cuz r>m + VERIFY( !(str_0 < str_2) ); + VERIFY( str_0 < str_3 ); + VERIFY( str_1 < str_0 ); //true cuz m<r + VERIFY( str_2 < str_0 ); + VERIFY( !(str_3 < str_0) ); + VERIFY( !(str_0 < str_4) ); + VERIFY( !(str_4 < str_0) ); + + VERIFY( str_0 >= str_1 ); //true cuz r>m + VERIFY( str_0 >= str_2 ); + VERIFY( !(str_0 >= str_3) ); + VERIFY( !(str_1 >= str_0) );//false cuz m<r + VERIFY( !(str_2 >= str_0) ); + VERIFY( str_3 >= str_0 ); + VERIFY( str_0 >= str_4 ); + VERIFY( str_4 >= str_0 ); + + VERIFY( !(str_0 <= str_1) );//false cuz r>m + VERIFY( !(str_0 <= str_2) ); + VERIFY( str_0 <= str_3 ); + VERIFY( str_1 <= str_0 );//true cuz m<r + VERIFY( str_2 <= str_0 ); + VERIFY( !(str_3 <= str_0) ); + VERIFY( str_0 <= str_4 ); + VERIFY( str_4 <= str_0 ); + + //comparisons between string object and string literal + VERIFY( !(str_0 == "costa marbella") ); + VERIFY( !(str_0 == "cost") ); + VERIFY( !(str_0 == "costa ricans") ); + VERIFY( !("costa marbella" == str_0) ); + VERIFY( !("cost" == str_0) ); + VERIFY( !("costa ricans" == str_0) ); + VERIFY( "costa rica" == str_0 ); + VERIFY( str_0 == "costa rica" ); + + VERIFY( str_0 != "costa marbella" ); + VERIFY( str_0 != "cost" ); + VERIFY( str_0 != "costa ricans" ); + VERIFY( "costa marbella" != str_0 ); + VERIFY( "cost" != str_0 ); + VERIFY( "costa ricans" != str_0 ); + VERIFY( !("costa rica" != str_0) ); + VERIFY( !(str_0 != "costa rica") ); + + VERIFY( str_0 > "costa marbella" ); //true cuz r>m + VERIFY( str_0 > "cost" ); + VERIFY( !(str_0 > "costa ricans") ); + VERIFY( !("costa marbella" > str_0) );//false cuz m<r + VERIFY( !("cost" > str_0) ); + VERIFY( "costa ricans" > str_0 ); + VERIFY( !("costa rica" > str_0) ); + VERIFY( !(str_0 > "costa rica") ); + + VERIFY( !(str_0 < "costa marbella") );//false cuz r>m + VERIFY( !(str_0 < "cost") ); + VERIFY( str_0 < "costa ricans" ); + VERIFY( "costa marbella" < str_0 );//true cuz m<r + VERIFY( "cost" < str_0 ); + VERIFY( !("costa ricans" < str_0) ); + VERIFY( !("costa rica" < str_0) ); + VERIFY( !(str_0 < "costa rica") ); + + VERIFY( str_0 >= "costa marbella" );//true cuz r>m + VERIFY( str_0 >= "cost" ); + VERIFY( !(str_0 >= "costa ricans") ); + VERIFY( !("costa marbella" >= str_0) );//false cuz m<r + VERIFY( !("cost" >= str_0) ); + VERIFY( "costa ricans" >= str_0 ); + VERIFY( "costa rica" >= str_0 ); + VERIFY( str_0 >= "costa rica" ); + + VERIFY( !(str_0 <= "costa marbella") );//false cuz r>m + VERIFY( !(str_0 <= "cost") ); + VERIFY( str_0 <= "costa ricans" ); + VERIFY( "costa marbella" <= str_0 );//true cuz m<r + VERIFY( "cost" <= str_0 ); + VERIFY( !("costa ricans" <= str_0) ); + VERIFY( "costa rica" <= str_0 ); + VERIFY( str_0 <= "costa rica" ); + + // 21.3.7.1 operator+ +/* +template<class charT, class traits, class Allocator> + basic_string<charT,traits,Allocator> + operator+(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + basic_string<charT,traits,Allocator> + operator+(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + basic_string<charT,traits,Allocator> + operator+(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + basic_string<charT,traits,Allocator> + operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + basic_string<charT,traits,Allocator> + operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs); +*/ + + str_4 = str_0 + "ns"; + VERIFY( str_4 == str_3 ); + + const std::string str_5(" marbella"); + str_4 = "costa" + str_5; + VERIFY( str_4 == str_1 ); + + std::string str_6("ns"); + str_4 = str_0 + str_6; + VERIFY( str_4 == str_3 ); + + str_4 = str_0 + 'n'; + str_4 = str_4 + 's'; + VERIFY( str_4 == str_3 ); + + str_4 = 'a' + str_6; + str_4 = 'c' + str_4; + str_4 = 'i' + str_4; + str_4 = 'r' + str_4; + str_4 = ' ' + str_4; + str_4 = 'a' + str_4; + str_4 = 't' + str_4; + str_4 = 's' + str_4; + str_4 = 'o' + str_4; + str_4 = 'c' + str_4; + VERIFY( str_4 == str_3 ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + + return 0; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operators/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operators/wchar_t/1.cc new file mode 100644 index 00000000000..cd8f18bf663 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operators/wchar_t/1.cc @@ -0,0 +1,56 @@ +// 1999-05-07 bkoz + +// Copyright (C) 1999, 2003 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.6 string operations + +#include <string> +#include <cstdio> +#include <testsuite_hooks.h> + +int test01(void) +{ + bool test = true; + + std::wstring str1; + std::wstring str2; + + // Should get this: + // 1:8-chars_8-chars_ + // 2:8-chars_8-chars_ + str1 = std::wstring(L"8-chars_") + L"8-chars_"; + const wchar_t* p1 = str1.c_str(); + // wprintf("1:%s\n", str1.c_str()); + str2 = str1 + L"7-chars"; + // wprintf("2:%s\n", str1.c_str()); //str1 is gone + const wchar_t* p2 = str1.c_str(); + return 0; + +#ifdef DEBUG_ASSERT + assert(test); +#endif + + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operators/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operators/wchar_t/2.cc new file mode 100644 index 00000000000..11e63f70e93 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operators/wchar_t/2.cc @@ -0,0 +1,300 @@ +// 1998-10-01, 1999-06-25 bkoz + +// Copyright (C) 1998, 1999, 2003 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.7.1 basic_string non-member functions + +// 21.3.7.2 operator== +/* +template<class charT, class traits, class Allocator> + bool operator==(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator==(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator==(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); +*/ + +// 21.3.7.3 operator!= +/* +template<class charT, class traits, class Allocator> + bool operator!=(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator!=(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator!=(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); +*/ + +// 21.3.7.4 operator< +/* +template<class charT, class traits, class Allocator> + bool operator< (const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator< (const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator< (const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +// 21.3.7.5 operator> +/* +template<class charT, class traits, class Allocator> + bool operator> (const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator> (const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator> (const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +//21.3.7.6 operator<= +/* +template<class charT, class traits, class Allocator> + bool operator<=(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator<=(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator<=(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +// 21.3.7.7 operator>= +/* +template<class charT, class traits, class Allocator> + bool operator>=(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator>=(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator>=(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +#include <string> +#include <testsuite_hooks.h> + +int test01(void) +{ + bool test = true; + std::wstring str_0(L"costa rica"); + std::wstring str_1(L"costa marbella"); + std::wstring str_2(L"cost"); + std::wstring str_3(L"costa ricans"); + std::wstring str_4; + + str_4 = str_0; + //comparisons between string objects + VERIFY( !(str_0 == str_1) ); + VERIFY( !(str_0 == str_2) ); + VERIFY( !(str_0 == str_3) ); + VERIFY( !(str_1 == str_0) ); + VERIFY( !(str_2 == str_0) ); + VERIFY( !(str_3 == str_0) ); + VERIFY( str_4 == str_0 ); + VERIFY( str_0 == str_4 ); + + VERIFY( str_0 != str_1 ); + VERIFY( str_0 != str_2 ); + VERIFY( str_0 != str_3 ); + VERIFY( str_1 != str_0 ); + VERIFY( str_2 != str_0 ); + VERIFY( str_3 != str_0 ); + VERIFY( !(str_0 != str_4) ); + VERIFY( !(str_4 != str_0) ); + + VERIFY( str_0 > str_1 ); //true cuz r>m + VERIFY( str_0 > str_2 ); + VERIFY( !(str_0 > str_3) ); + VERIFY( !(str_1 > str_0) ); //false cuz m<r + VERIFY( !(str_2 > str_0) ); + VERIFY( str_3 > str_0 ); + VERIFY( !(str_0 > str_4) ); + VERIFY( !(str_4 > str_0) ); + + VERIFY( !(str_0 < str_1) ); //false cuz r>m + VERIFY( !(str_0 < str_2) ); + VERIFY( str_0 < str_3 ); + VERIFY( str_1 < str_0 ); //true cuz m<r + VERIFY( str_2 < str_0 ); + VERIFY( !(str_3 < str_0) ); + VERIFY( !(str_0 < str_4) ); + VERIFY( !(str_4 < str_0) ); + + VERIFY( str_0 >= str_1 ); //true cuz r>m + VERIFY( str_0 >= str_2 ); + VERIFY( !(str_0 >= str_3) ); + VERIFY( !(str_1 >= str_0) );//false cuz m<r + VERIFY( !(str_2 >= str_0) ); + VERIFY( str_3 >= str_0 ); + VERIFY( str_0 >= str_4 ); + VERIFY( str_4 >= str_0 ); + + VERIFY( !(str_0 <= str_1) );//false cuz r>m + VERIFY( !(str_0 <= str_2) ); + VERIFY( str_0 <= str_3 ); + VERIFY( str_1 <= str_0 );//true cuz m<r + VERIFY( str_2 <= str_0 ); + VERIFY( !(str_3 <= str_0) ); + VERIFY( str_0 <= str_4 ); + VERIFY( str_4 <= str_0 ); + + //comparisons between string object and string literal + VERIFY( !(str_0 == L"costa marbella") ); + VERIFY( !(str_0 == L"cost") ); + VERIFY( !(str_0 == L"costa ricans") ); + VERIFY( !(L"costa marbella" == str_0) ); + VERIFY( !(L"cost" == str_0) ); + VERIFY( !(L"costa ricans" == str_0) ); + VERIFY( L"costa rica" == str_0 ); + VERIFY( str_0 == L"costa rica" ); + + VERIFY( str_0 != L"costa marbella" ); + VERIFY( str_0 != L"cost" ); + VERIFY( str_0 != L"costa ricans" ); + VERIFY( L"costa marbella" != str_0 ); + VERIFY( L"cost" != str_0 ); + VERIFY( L"costa ricans" != str_0 ); + VERIFY( !(L"costa rica" != str_0) ); + VERIFY( !(str_0 != L"costa rica") ); + + VERIFY( str_0 > L"costa marbella" ); //true cuz r>m + VERIFY( str_0 > L"cost" ); + VERIFY( !(str_0 > L"costa ricans") ); + VERIFY( !(L"costa marbella" > str_0) );//false cuz m<r + VERIFY( !(L"cost" > str_0) ); + VERIFY( L"costa ricans" > str_0 ); + VERIFY( !(L"costa rica" > str_0) ); + VERIFY( !(str_0 > L"costa rica") ); + + VERIFY( !(str_0 < L"costa marbella") );//false cuz r>m + VERIFY( !(str_0 < L"cost") ); + VERIFY( str_0 < L"costa ricans" ); + VERIFY( L"costa marbella" < str_0 );//true cuz m<r + VERIFY( L"cost" < str_0 ); + VERIFY( !(L"costa ricans" < str_0) ); + VERIFY( !(L"costa rica" < str_0) ); + VERIFY( !(str_0 < L"costa rica") ); + + VERIFY( str_0 >= L"costa marbella" );//true cuz r>m + VERIFY( str_0 >= L"cost" ); + VERIFY( !(str_0 >= L"costa ricans") ); + VERIFY( !(L"costa marbella" >= str_0) );//false cuz m<r + VERIFY( !(L"cost" >= str_0) ); + VERIFY( L"costa ricans" >= str_0 ); + VERIFY( L"costa rica" >= str_0 ); + VERIFY( str_0 >= L"costa rica" ); + + VERIFY( !(str_0 <= L"costa marbella") );//false cuz r>m + VERIFY( !(str_0 <= L"cost") ); + VERIFY( str_0 <= L"costa ricans" ); + VERIFY( L"costa marbella" <= str_0 );//true cuz m<r + VERIFY( L"cost" <= str_0 ); + VERIFY( !(L"costa ricans" <= str_0) ); + VERIFY( L"costa rica" <= str_0 ); + VERIFY( str_0 <= L"costa rica" ); + + // 21.3.7.1 operator+ +/* +template<class charT, class traits, class Allocator> + basic_string<charT,traits,Allocator> + operator+(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + basic_string<charT,traits,Allocator> + operator+(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + basic_string<charT,traits,Allocator> + operator+(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + basic_string<charT,traits,Allocator> + operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + basic_string<charT,traits,Allocator> + operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs); +*/ + + str_4 = str_0 + L"ns"; + VERIFY( str_4 == str_3 ); + + const std::wstring str_5(L" marbella"); + str_4 = L"costa" + str_5; + VERIFY( str_4 == str_1 ); + + std::wstring str_6(L"ns"); + str_4 = str_0 + str_6; + VERIFY( str_4 == str_3 ); + + str_4 = str_0 + L'n'; + str_4 = str_4 + L's'; + VERIFY( str_4 == str_3 ); + + str_4 = L'a' + str_6; + str_4 = L'c' + str_4; + str_4 = L'i' + str_4; + str_4 = L'r' + str_4; + str_4 = L' ' + str_4; + str_4 = L'a' + str_4; + str_4 = L't' + str_4; + str_4 = L's' + str_4; + str_4 = L'o' + str_4; + str_4 = L'c' + str_4; + VERIFY( str_4 == str_3 ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + + return 0; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/1.cc new file mode 100644 index 00000000000..7145d4c7840 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/1.cc @@ -0,0 +1,87 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1994, 1999, 2001, 2002, 2003 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.6 basic_string::replace + +#include <string> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::string::size_type csize_type; + typedef std::string::const_reference cref; + typedef std::string::reference ref; + csize_type npos = std::string::npos; + csize_type csz01, csz02; + + const char str_lit01[] = "ventura, california"; + const std::string str01(str_lit01); + std::string str02("del mar, california"); + std::string str03(" and "); + std::string str05; + + // string& replace(size_type pos, size_type n, const string& string) + // string& replace(size_type pos1, size_type n1, const string& string, + // size_type pos2, size_type n2) + // string& replace(size_type pos, size_type n1, const char* s, size_type n2) + // string& replace(size_type pos, size_type n1, const char* s) + // string& replace(size_type pos, size_type n1, size_type n2, char c) + // string& replace(iterator it1, iterator it2, const string& str) + // string& replace(iterator it1, iterator it2, const chat* s, size_type n) + // string& replace(iterator it1, iterator it2, const chat* s) + // string& replace(iterator it1, iterator it2, size_type n, char c) + // template<typename InputIter> + // string& replace(iterator it1, iterator it2, InputIter j1, InputIter j2) + + // with mods, from tstring.cc, from jason merrill, et. al. + std::string X = "Hello"; + std::string x = X; + + char ch = x[0]; + VERIFY( ch == 'H' ); + + std::string z = x.substr(2, 3); + VERIFY( z == "llo" ); + + x.replace(2, 2, "r"); + VERIFY( x == "Hero" ); + + x = X; + x.replace(0, 1, "j"); + VERIFY( x == "jello" ); + + int ar[] = { 'H', 'e', 'l', 'l', 'o' }; + x.replace(std::find(x.begin(), x.end(), 'l'), + std::find(x.rbegin(), x.rend(), 'l').base(), ar, + ar + sizeof(ar) / sizeof(ar[0])); + VERIFY( x == "jeHelloo" ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/2.cc new file mode 100644 index 00000000000..7731edd37a4 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/2.cc @@ -0,0 +1,46 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1994, 1999, 2001, 2002, 2003 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.6 basic_string::replace + +#include <string> +#include <testsuite_hooks.h> + +void +test02() +{ + bool test = true; + const char* strlit = "../the long pier/Hanalei Bay/Kauai/Hawaii"; + std::string aux = strlit; + aux.replace(aux.begin()+5, aux.begin()+20, + aux.begin()+10, aux.begin()+15); + VERIFY(aux == "../thg piealei Bay/Kauai/Hawaii"); + + aux = strlit; + aux.replace(aux.begin() + 10, aux.begin() + 15, + aux.begin() + 5, aux.begin() + 20); + VERIFY(aux == "../the lone long pier/Hanr/Hanalei Bay/Kauai/Hawaii"); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/3.cc new file mode 100644 index 00000000000..a04d13d4024 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/3.cc @@ -0,0 +1,74 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1994, 1999, 2001, 2002, 2003 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.6 basic_string::replace + +#include <string> +#include <testsuite_hooks.h> + +// Some more miscellaneous tests +void +test03() +{ + bool test = true; + const char* title01 = "nine types of ambiguity"; + const char* title02 = "ultra"; + std::string str01 = title01; + std::string str02 = title02; + + str01.replace(0, 4, str02); + VERIFY(str01 == "ultra types of ambiguity"); + + str01.replace(15, 9, str02, 2, 2); + VERIFY(str01 == "ultra types of tr"); + + str01 = title01; + str02.replace(0, 0, str01, 0, std::string::npos); + VERIFY(str02 == "nine types of ambiguityultra"); + + str02.replace(11, 2, title02, 5); + VERIFY(str02 == "nine types ultra ambiguityultra"); + + str02.replace(11, 5, title01, 2); + VERIFY(str02 == "nine types ni ambiguityultra"); + + str01.replace(str01.size(), 0, title02); + VERIFY(str01 == "nine types of ambiguityultra"); + + str01 = title01; + str02 = title02; + str01.replace(str01.begin(), str01.end(), str02); + VERIFY(str01 == "ultra"); + + str01.replace(str01.begin(), str01.begin(), title01, 4); + VERIFY(str01 == "nineultra"); + + str01.replace(str01.end(), str01.end(), title01 + 5, 5); + VERIFY(str01 == "nineultratypes"); + + str01.replace(str01.begin(), str01.end(), title02); + VERIFY(str01 == "ultra"); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/4.cc b/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/4.cc new file mode 100644 index 00000000000..47cf335daa0 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/4.cc @@ -0,0 +1,67 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1994, 1999, 2001, 2002, 2003 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.6 basic_string::replace + +#include <string> +#include <testsuite_hooks.h> + +// Some more tests for +// template<typename InputIter> +// string& replace(iterator it1, iterator it2, InputIter j1, InputIter j2) +void +test04() +{ + bool test = true; + std::string str01 = "geogaddi"; + std::string str02; + + typedef std::string::iterator iterator; + typedef std::string::const_iterator const_iterator; + + iterator it1 = str01.begin(); + iterator it2 = str01.end(); + str02.replace(str02.begin(), str02.end(), it1, it2); + VERIFY(str02 == "geogaddi"); + + str02 = "boards"; + const_iterator c_it1 = str01.begin(); + const_iterator c_it2 = str01.end(); + str02.replace(str02.begin(), str02.end(), c_it1, c_it2); + VERIFY(str02 == "geogaddi"); + + str02 = "boards"; + const char* c_ptr1 = str01.c_str(); + const char* c_ptr2 = str01.c_str() + 8; + str02.replace(str02.begin(), str02.end(), c_ptr1, c_ptr2); + VERIFY(str02 == "geogaddi"); + + str02 = "boards"; + char* ptr1 = &*str01.begin(); + char* ptr2 = &*str01.end(); + str02.replace(str02.begin(), str02.end(), ptr1, ptr2); + VERIFY(str02 == "geogaddi"); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/5.cc b/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/5.cc new file mode 100644 index 00000000000..8c112c545ed --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/replace/char/5.cc @@ -0,0 +1,43 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1994, 1999, 2001, 2002, 2003 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.6 basic_string::replace + +#include <string> +#include <testsuite_hooks.h> + +// We wrongly used __n1 instead of __foldn1 in the length_error +// check at the beginning of replace(__pos, __n1, __s, __n2) +void +test05() +{ + bool test = true; + std::string str01 = "londinium"; + std::string str02 = "cydonia"; + + str01.replace(0, 20, str02.c_str(), 3); + VERIFY(str01 == "cyd"); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/1.cc new file mode 100644 index 00000000000..fd0967a86fe --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/1.cc @@ -0,0 +1,87 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1994, 1999, 2001, 2002, 2003 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.6 basic_string::replace + +#include <string> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::wstring::size_type csize_type; + typedef std::wstring::const_reference cref; + typedef std::wstring::reference ref; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + + const wchar_t str_lit01[] = L"ventura, california"; + const std::wstring str01(str_lit01); + std::wstring str02(L"del mar, california"); + std::wstring str03(L" and "); + std::wstring str05; + + // wstring& replace(size_type pos, size_type n, const wstring& string) + // wstring& replace(size_type pos1, size_type n1, const wstring& string, + // size_type pos2, size_type n2) + // wstring& replace(size_type pos, size_type n1, const wchar_t* s, size_type n2) + // wstring& replace(size_type pos, size_type n1, const wchar_t* s) + // wstring& replace(size_type pos, size_type n1, size_type n2, wchar_t c) + // wstring& replace(iterator it1, iterator it2, const wstring& str) + // wstring& replace(iterator it1, iterator it2, const wchar_t* s, size_type n) + // wstring& replace(iterator it1, iterator it2, const wchar_t* s) + // wstring& replace(iterator it1, iterator it2, size_type n, char c) + // template<typename InputIter> + // wstring& replace(iterator it1, iterator it2, InputIter j1, InputIter j2) + + // with mods, from tstring.cc, from jason merrill, et. al. + std::wstring X = L"Hello"; + std::wstring x = X; + + wchar_t ch = x[0]; + VERIFY( ch == L'H' ); + + std::wstring z = x.substr(2, 3); + VERIFY( z == L"llo" ); + + x.replace(2, 2, L"r"); + VERIFY( x == L"Hero" ); + + x = X; + x.replace(0, 1, L"j"); + VERIFY( x == L"jello" ); + + wchar_t ar[] = { L'H', L'e', L'l', L'l', L'o' }; + x.replace(std::find(x.begin(), x.end(), L'l'), + std::find(x.rbegin(), x.rend(), L'l').base(), ar, + ar + sizeof(ar) / sizeof(ar[0])); + VERIFY( x == L"jeHelloo" ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/2.cc new file mode 100644 index 00000000000..da9678a338f --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/2.cc @@ -0,0 +1,47 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1994, 1999, 2001, 2002, 2003 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.6 basic_string::replace + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test02() +{ + bool test = true; + const wchar_t* strlit = L"../the long pier/Hanalei Bay/Kauai/Hawaii"; + std::wstring aux = strlit; + aux.replace(aux.begin()+5, aux.begin()+20, + aux.begin()+10, aux.begin()+15); + VERIFY(aux == L"../thg piealei Bay/Kauai/Hawaii"); + + aux = strlit; + aux.replace(aux.begin() + 10, aux.begin() + 15, + aux.begin() + 5, aux.begin() + 20); + VERIFY(aux == L"../the lone long pier/Hanr/Hanalei Bay/Kauai/Hawaii"); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/3.cc new file mode 100644 index 00000000000..2ff6ef28294 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/3.cc @@ -0,0 +1,74 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1994, 1999, 2001, 2002, 2003 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.6 basic_string::replace + +#include <string> +#include <testsuite_hooks.h> + +// Some more miscellaneous tests +void +test03() +{ + bool test = true; + const wchar_t* title01 = L"nine types of ambiguity"; + const wchar_t* title02 = L"ultra"; + std::wstring str01 = title01; + std::wstring str02 = title02; + + str01.replace(0, 4, str02); + VERIFY(str01 == L"ultra types of ambiguity"); + + str01.replace(15, 9, str02, 2, 2); + VERIFY(str01 == L"ultra types of tr"); + + str01 = title01; + str02.replace(0, 0, str01, 0, std::wstring::npos); + VERIFY(str02 == L"nine types of ambiguityultra"); + + str02.replace(11, 2, title02, 5); + VERIFY(str02 == L"nine types ultra ambiguityultra"); + + str02.replace(11, 5, title01, 2); + VERIFY(str02 == L"nine types ni ambiguityultra"); + + str01.replace(str01.size(), 0, title02); + VERIFY(str01 == L"nine types of ambiguityultra"); + + str01 = title01; + str02 = title02; + str01.replace(str01.begin(), str01.end(), str02); + VERIFY(str01 == L"ultra"); + + str01.replace(str01.begin(), str01.begin(), title01, 4); + VERIFY(str01 == L"nineultra"); + + str01.replace(str01.end(), str01.end(), title01 + 5, 5); + VERIFY(str01 == L"nineultratypes"); + + str01.replace(str01.begin(), str01.end(), title02); + VERIFY(str01 == L"ultra"); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/4.cc b/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/4.cc new file mode 100644 index 00000000000..bc827d03282 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/4.cc @@ -0,0 +1,67 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1994, 1999, 2001, 2002, 2003 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.6 basic_string::replace + +#include <string> +#include <testsuite_hooks.h> + +// Some more tests for +// template<typename InputIter> +// wstring& replace(iterator it1, iterator it2, InputIter j1, InputIter j2) +void +test04() +{ + bool test = true; + std::wstring str01 = L"geogaddi"; + std::wstring str02; + + typedef std::wstring::iterator iterator; + typedef std::wstring::const_iterator const_iterator; + + iterator it1 = str01.begin(); + iterator it2 = str01.end(); + str02.replace(str02.begin(), str02.end(), it1, it2); + VERIFY(str02 == L"geogaddi"); + + str02 = L"boards"; + const_iterator c_it1 = str01.begin(); + const_iterator c_it2 = str01.end(); + str02.replace(str02.begin(), str02.end(), c_it1, c_it2); + VERIFY(str02 == L"geogaddi"); + + str02 = L"boards"; + const wchar_t* c_ptr1 = str01.c_str(); + const wchar_t* c_ptr2 = str01.c_str() + 8; + str02.replace(str02.begin(), str02.end(), c_ptr1, c_ptr2); + VERIFY(str02 == L"geogaddi"); + + str02 = L"boards"; + wchar_t* ptr1 = &*str01.begin(); + wchar_t* ptr2 = &*str01.end(); + str02.replace(str02.begin(), str02.end(), ptr1, ptr2); + VERIFY(str02 == L"geogaddi"); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/5.cc b/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/5.cc new file mode 100644 index 00000000000..f54cfb9a2e7 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/replace/wchar_t/5.cc @@ -0,0 +1,43 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1994, 1999, 2001, 2002, 2003 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.6 basic_string::replace + +#include <string> +#include <testsuite_hooks.h> + +// We wrongly used __n1 instead of __foldn1 in the length_error +// check at the beginning of replace(__pos, __n1, __s, __n2) +void +test05() +{ + bool test = true; + std::wstring str01 = L"londinium"; + std::wstring str02 = L"cydonia"; + + str01.replace(0, 20, str02.c_str(), 3); + VERIFY(str01 == L"cyd"); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/rfind/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/char/1.cc new file mode 100644 index 00000000000..5b9a4181b91 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/char/1.cc @@ -0,0 +1,97 @@ +// 2000-06-22 -=dbv=- (shamelessy copied from bkoz' find.cc) + +// Copyright (C) 2000, 2003 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. + +#include <string> +#include <testsuite_hooks.h> + +// 21.3.6.2 basic_string rfind +bool test01(void) +{ + bool test = true; + typedef std::string::size_type csize_type; + typedef std::string::const_reference cref; + typedef std::string::reference ref; + csize_type npos = std::string::npos; + csize_type csz01, csz02; + + const char str_lit01[] = "mave"; + const std::string str01("mavericks, santa cruz"); + std::string str02(str_lit01); + std::string str03("s, s"); + std::string str04; + + // size_type rfind(const string&, size_type pos = 0) const; + csz01 = str01.rfind(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str01, 4); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str02,3); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str02); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str03); + VERIFY( csz01 == 8 ); + csz01 = str01.rfind(str03, 3); + VERIFY( csz01 == npos ); + csz01 = str01.rfind(str03, 12); + VERIFY( csz01 == 8 ); + + // An empty string consists of no characters + // therefore it should be found at every point in a string, + // except beyond the end + csz01 = str01.rfind(str04, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str04, 5); + VERIFY( csz01 == 5 ); + csz01 = str01.rfind(str04, str01.size()); + VERIFY( csz01 == str01.size() ); + csz01 = str01.rfind(str04, str01.size()+1); + VERIFY( csz01 == str01.size() ); + + // size_type rfind(const char* s, size_type pos, size_type n) const; + csz01 = str01.rfind(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str_lit01, 3, 0); + VERIFY( csz01 == 3 ); + + // size_type rfind(const char* s, size_type pos = 0) const; + csz01 = str01.rfind(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str_lit01, 3); + VERIFY( csz01 == 0 ); + + // size_type rfind(char c, size_type pos = 0) const; + csz01 = str01.rfind('z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + csz01 = str01.rfind('/'); + VERIFY( csz01 == npos ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/rfind/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/char/2.cc new file mode 100644 index 00000000000..9b905df9065 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/char/2.cc @@ -0,0 +1,41 @@ +// 2000-06-22 -=dbv=- (shamelessy copied from bkoz' find.cc) + +// Copyright (C) 2000, 2003 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. + +#include <string> +#include <testsuite_hooks.h> + +// 21.3.6.4 basic_string::find_last_of +bool test02() +{ + bool test = true; + + // test find_last_of + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/rfind/char/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/char/3.cc new file mode 100644 index 00000000000..d8b6c8136ab --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/char/3.cc @@ -0,0 +1,40 @@ +// 2000-06-22 -=dbv=- (shamelessy copied from bkoz' find.cc) + +// Copyright (C) 2000, 2003 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. + +#include <string> +#include <testsuite_hooks.h> + +// 21.3.6.6 basic_string::find_last_not_of +bool test03() +{ + bool test = true; + + // test find_last_not_of + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/rfind/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/wchar_t/1.cc new file mode 100644 index 00000000000..9681bf4c8e4 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/wchar_t/1.cc @@ -0,0 +1,97 @@ +// 2000-06-22 -=dbv=- (shamelessy copied from bkoz' find.cc) + +// Copyright (C) 2000, 2003 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. + +#include <string> +#include <testsuite_hooks.h> + +// 21.3.6.2 basic_string rfind +bool test01(void) +{ + bool test = true; + typedef std::wstring::size_type csize_type; + typedef std::wstring::const_reference cref; + typedef std::wstring::reference ref; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + + const wchar_t str_lit01[] = L"mave"; + const std::wstring str01(L"mavericks, santa cruz"); + std::wstring str02(str_lit01); + std::wstring str03(L"s, s"); + std::wstring str04; + + // size_type rfind(const wstring&, size_type pos = 0) const; + csz01 = str01.rfind(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str01, 4); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str02,3); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str02); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str03); + VERIFY( csz01 == 8 ); + csz01 = str01.rfind(str03, 3); + VERIFY( csz01 == npos ); + csz01 = str01.rfind(str03, 12); + VERIFY( csz01 == 8 ); + + // An empty string consists of no characters + // therefore it should be found at every point in a string, + // except beyond the end + csz01 = str01.rfind(str04, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str04, 5); + VERIFY( csz01 == 5 ); + csz01 = str01.rfind(str04, str01.size()); + VERIFY( csz01 == str01.size() ); + csz01 = str01.rfind(str04, str01.size()+1); + VERIFY( csz01 == str01.size() ); + + // size_type rfind(const wchar_t* s, size_type pos, size_type n) const; + csz01 = str01.rfind(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str_lit01, 3, 0); + VERIFY( csz01 == 3 ); + + // size_type rfind(const wchar_t* s, size_type pos = 0) const; + csz01 = str01.rfind(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str_lit01, 3); + VERIFY( csz01 == 0 ); + + // size_type rfind(wchar_t c, size_type pos = 0) const; + csz01 = str01.rfind(L'z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + csz01 = str01.rfind(L'/'); + VERIFY( csz01 == npos ); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/rfind/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/wchar_t/2.cc new file mode 100644 index 00000000000..9b905df9065 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/wchar_t/2.cc @@ -0,0 +1,41 @@ +// 2000-06-22 -=dbv=- (shamelessy copied from bkoz' find.cc) + +// Copyright (C) 2000, 2003 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. + +#include <string> +#include <testsuite_hooks.h> + +// 21.3.6.4 basic_string::find_last_of +bool test02() +{ + bool test = true; + + // test find_last_of + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/rfind/wchar_t/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/wchar_t/3.cc new file mode 100644 index 00000000000..d8b6c8136ab --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/rfind/wchar_t/3.cc @@ -0,0 +1,40 @@ +// 2000-06-22 -=dbv=- (shamelessy copied from bkoz' find.cc) + +// Copyright (C) 2000, 2003 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. + +#include <string> +#include <testsuite_hooks.h> + +// 21.3.6.6 basic_string::find_last_not_of +bool test03() +{ + bool test = true; + + // test find_last_not_of + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/substr/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/substr/char/1.cc new file mode 100644 index 00000000000..be2a379c581 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/substr/char/1.cc @@ -0,0 +1,80 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1999, 2003 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.6.7 basic_string::substr + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::string::size_type csize_type; + typedef std::string::const_reference cref; + typedef std::string::reference ref; + csize_type npos = std::string::npos; + csize_type csz01, csz02; + + const char str_lit01[] = "rockaway, pacifica"; + const std::string str01(str_lit01); + std::string str02; + + // basic_string<charT, _Traits, _Alloc> + // substr(size_type pos = 0, size_type n = npos) const; + csz01 = str01.size(); + str02 = str01.substr(0, 1); + VERIFY( str02 == "r" ); + str02 = str01.substr(10); + VERIFY( str02 == "pacifica" ); + + try { + str02 = str01.substr(csz01 + 1); + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + try { + str02 = str01.substr(csz01); + VERIFY( str02.size() == 0 ); + } + catch(std::out_of_range& fail) { + VERIFY( false ); + } + catch(...) { + VERIFY( false ); + } + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/substr/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/substr/wchar_t/1.cc new file mode 100644 index 00000000000..843ebb6861a --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/substr/wchar_t/1.cc @@ -0,0 +1,80 @@ +// 1999-06-10 bkoz + +// Copyright (C) 1999, 2003 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.6.7 basic_string::substr + +#include <string> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test = true; + typedef std::wstring::size_type csize_type; + typedef std::wstring::const_reference cref; + typedef std::wstring::reference ref; + csize_type npos = std::wstring::npos; + csize_type csz01, csz02; + + const wchar_t str_lit01[] = L"rockaway, pacifica"; + const std::wstring str01(str_lit01); + std::wstring str02; + + // basic_string<charT, _Traits, _Alloc> + // substr(size_type pos = 0, size_type n = npos) const; + csz01 = str01.size(); + str02 = str01.substr(0, 1); + VERIFY( str02 == L"r" ); + str02 = str01.substr(10); + VERIFY( str02 == L"pacifica" ); + + try { + str02 = str01.substr(csz01 + 1); + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + try { + str02 = str01.substr(csz01); + VERIFY( str02.size() == 0 ); + } + catch(std::out_of_range& fail) { + VERIFY( false ); + } + catch(...) { + VERIFY( false ); + } + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + return 0; +} |