summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/21_strings/basic_string/append
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/21_strings/basic_string/append')
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/append/char/1.cc158
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/append/char/2.cc66
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/append/char/3.cc55
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/1.cc158
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/2.cc66
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/3.cc55
6 files changed, 558 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 000000000..850bd52b7
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/append/char/1.cc
@@ -0,0 +1,158 @@
+// 1999-07-08 bkoz
+
+// Copyright (C) 1999, 2003, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 21.3.5.2 basic_string::append
+
+#include <string>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+bool test01(void)
+{
+ bool test __attribute__((unused)) = true;
+ typedef std::string::size_type csize_type;
+ typedef std::string::const_reference cref;
+ typedef std::string::reference ref;
+ csize_type csz01;
+
+ 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 );
+ return test;
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/append/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/append/char/2.cc
new file mode 100644
index 000000000..acfe69d2b
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/append/char/2.cc
@@ -0,0 +1,66 @@
+// 2004-25-10 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 21.3.5 string modifiers
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// append(const _CharT* __s, size_type __n)
+// append(const _CharT* __s)
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ using namespace std;
+
+ string one;
+ string two;
+ string three;
+ const char * source = "Written in your eyes";
+
+ one.append(source);
+ VERIFY( one == "Written in your eyes" );
+
+ two.append(source, 20);
+ VERIFY( two == "Written in your eyes" );
+
+ three.append(source, 7);
+ VERIFY( three == "Written" );
+
+ three.clear();
+ three.append(source + 8, 2);
+ VERIFY( three == "in" );
+
+ one.append(one.c_str(), 20);
+ VERIFY( one == "Written in your eyesWritten in your eyes" );
+
+ two.append(two.c_str() + 16, 4);
+ VERIFY( two == "Written in your eyeseyes" );
+
+ two.append(two.c_str(), 3);
+ VERIFY( two == "Written in your eyeseyesWri" );
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/append/char/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/append/char/3.cc
new file mode 100644
index 000000000..00f2179aa
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/append/char/3.cc
@@ -0,0 +1,55 @@
+// 2004-25-10 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 21.3.5 string modifiers
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// Upon reallocation (basic_string::reserve) we were copying from
+// deallocated memory.
+void
+test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ using namespace std;
+
+ const char * source = "Kesto";
+
+ for (unsigned i = 0; i < 10; ++i)
+ {
+ string one(source);
+ string two(source);
+ for (unsigned j = 0; j < 18; ++j)
+ {
+ VERIFY( one == two );
+ one.append(one);
+ one += 'x';
+ two.append(two.c_str(), two.size());
+ two += 'x';
+ }
+ }
+}
+
+int main()
+{
+ test03();
+ 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 000000000..81c388980
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/1.cc
@@ -0,0 +1,158 @@
+// 1999-07-08 bkoz
+
+// Copyright (C) 1999, 2003, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 21.3.5.2 basic_string::append
+
+#include <string>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+bool test01(void)
+{
+ bool test __attribute__((unused)) = true;
+ typedef std::wstring::size_type csize_type;
+ typedef std::wstring::const_reference cref;
+ typedef std::wstring::reference ref;
+ csize_type csz01;
+
+ 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) / sizeof(wchar_t) - 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 );
+ return test;
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/2.cc
new file mode 100644
index 000000000..3b30d412a
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/2.cc
@@ -0,0 +1,66 @@
+// 2004-25-10 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 21.3.5 string modifiers
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// append(const _CharT* __s, size_type __n)
+// append(const _CharT* __s)
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ using namespace std;
+
+ wstring one;
+ wstring two;
+ wstring three;
+ const wchar_t * source = L"Written in your eyes";
+
+ one.append(source);
+ VERIFY( one == L"Written in your eyes" );
+
+ two.append(source, 20);
+ VERIFY( two == L"Written in your eyes" );
+
+ three.append(source, 7);
+ VERIFY( three == L"Written" );
+
+ three.clear();
+ three.append(source + 8, 2);
+ VERIFY( three == L"in" );
+
+ one.append(one.c_str(), 20);
+ VERIFY( one == L"Written in your eyesWritten in your eyes" );
+
+ two.append(two.c_str() + 16, 4);
+ VERIFY( two == L"Written in your eyeseyes" );
+
+ two.append(two.c_str(), 3);
+ VERIFY( two == L"Written in your eyeseyesWri" );
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/3.cc
new file mode 100644
index 000000000..dca5dbdaf
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/append/wchar_t/3.cc
@@ -0,0 +1,55 @@
+// 2004-25-10 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 21.3.5 string modifiers
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// Upon reallocation (basic_string::reserve) we were copying from
+// deallocated memory.
+void
+test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ using namespace std;
+
+ const wchar_t * source = L"Kesto";
+
+ for (unsigned i = 0; i < 10; ++i)
+ {
+ wstring one(source);
+ wstring two(source);
+ for (unsigned j = 0; j < 18; ++j)
+ {
+ VERIFY( one == two );
+ one.append(one);
+ one += L'x';
+ two.append(two.c_str(), two.size());
+ two += L'x';
+ }
+ }
+}
+
+int main()
+{
+ test03();
+ return 0;
+}