diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/21_strings/basic_string/operators/char | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/21_strings/basic_string/operators/char')
4 files changed, 515 insertions, 0 deletions
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 000000000..e9b030e59 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/1.cc @@ -0,0 +1,49 @@ +// 1999-05-07 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.6 string operations + +#include <string> +#include <cstdio> +#include <testsuite_hooks.h> + +int test01(void) +{ + bool test __attribute__((unused)) = 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_"; + str1.c_str(); + // printf("1:%s\n", str1.c_str()); + str2 = str1 + "7-chars"; + // printf("2:%s\n", str1.c_str()); //str1 is gone + str1.c_str(); + return 0; +} + +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 000000000..7be6ae5cc --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/2.cc @@ -0,0 +1,294 @@ +// 1998-10-01, 1999-06-25 bkoz + +// Copyright (C) 1998, 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.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 __attribute__((unused)) = 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 ); + return 0; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/3.cc new file mode 100644 index 000000000..6bd573fe3 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/3.cc @@ -0,0 +1,93 @@ +// 2010-12-17 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. +// +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +#include <string> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::string; + + VERIFY( (string("abc") + string("def") + == string("abcdef")) ); + string s1("abc"); + VERIFY( s1 + string("def") == string("abcdef") ); + string s2("def"); + VERIFY( string("abc") + s2 == string("abcdef") ); + VERIFY( string("abc") + 'd' == string("abcd") ); + VERIFY( string("abc") + "def" == string("abcdef") ); + VERIFY( 'a' + string("bcd") == string("abcd") ); + VERIFY( "abc" + string("def") == string("abcdef") ); + + VERIFY( (string("abcdefghij") + string("klmnopqrst") + == string("abcdefghijklmnopqrst")) ); + string s1l("abcdefghij"); + VERIFY( (s1l + string("klmnopqrst") + == string("abcdefghijklmnopqrst")) ); + string s2l("klmnopqrst"); + VERIFY( (string("abcdefghij") + s2l + == string("abcdefghijklmnopqrst")) ); + VERIFY( (string("abcdefghijklmno") + 'p' + == string("abcdefghijklmnop")) ); + VERIFY( (string("abcdefghijklmno") + "pqrst" + == string("abcdefghijklmnopqrst")) ); + VERIFY( ('a' + string("bcdefghijklmnop") + == string("abcdefghijklmnop")) ); + VERIFY( ("abcde" + string("fghijklmnopqrst") + == string("abcdefghijklmnopqrst")) ); + + VERIFY( (string("abcdefghijklmnopqrst") + string("uvwxy") + == string("abcdefghijklmnopqrstuvwxy")) ); + VERIFY( (string("abcde") + string("fghijklmnopqrstuvwxy") + == string("abcdefghijklmnopqrstuvwxy")) ); + string s1ll1("abcdefghijklmnopqrst"); + VERIFY( (s1ll1 + string("uvwxy") + == string("abcdefghijklmnopqrstuvwxy")) ); + string s1ll2("abcde"); + VERIFY( (s1ll2 + string("fghijklmnopqrstuvwxy") + == string("abcdefghijklmnopqrstuvwxy")) ); + string s2ll1("fghijklmnopqrstuvwxy"); + VERIFY( (string("abcde") + s2ll1 + == string("abcdefghijklmnopqrstuvwxy")) ); + string s2ll2("uvwxy"); + VERIFY( (string("abcdefghijklmnopqrst") + s2ll2 + == string("abcdefghijklmnopqrstuvwxy")) ); + VERIFY( (string("abcdefghijklmnopqrst") + 'u' + == string("abcdefghijklmnopqrstu")) ); + VERIFY( (string("abcdefghijklmnopqrst") + "uvwxy" + == string("abcdefghijklmnopqrstuvwxy")) ); + VERIFY( (string("abcde") + "fghijklmnopqrstuvwxy" + == string("abcdefghijklmnopqrstuvwxy")) ); + VERIFY( ('a' + string("bcdefghijklmnopqrstuvwxy") + == string("abcdefghijklmnopqrstuvwxy")) ); + VERIFY( ("abcde" + string("fghijklmnopqrstuvwxy") + == string("abcdefghijklmnopqrstuvwxy")) ); + VERIFY( ("abcdefghijklmnopqrst" + string("uvwxy") + == string("abcdefghijklmnopqrstuvwxy")) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/4.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/4.cc new file mode 100644 index 000000000..e1e771d2d --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/4.cc @@ -0,0 +1,79 @@ +// 2010-12-19 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. +// +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +#include <string> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::string; + using std::move; + + string s01("abc"); + s01.reserve(30); + string s02("def"); + s02.reserve(30); + VERIFY( move(s01) + move(s02) == string("abcdef") ); + + string s03("abcdefghijklmnopqrstuvw"); + string s04("xyz"); + s04.reserve(30); + VERIFY( move(s03) + move(s04) == string("abcdefghijklmnopqrstuvwxyz") ); + + string s05("abc"); + s05.reserve(30); + string s06("defghijklmnopqrstuvwxyz"); + VERIFY( move(s05) + move(s06) == string("abcdefghijklmnopqrstuvwxyz") ); + + const string sc1("abc"); + string s07("def"); + s07.reserve(30); + VERIFY( sc1 + move(s07) == string("abcdef") ); + + const string sc2("def"); + string s08("abc"); + s08.reserve(30); + VERIFY( move(s08) + sc2 == string("abcdef") ); + + string s09("abc"); + s09.reserve(30); + VERIFY( move(s09) + 'd' == string("abcd") ); + + string s10("abc"); + s10.reserve(30); + VERIFY( move(s10) + "def" == string("abcdef") ); + + string s11("bcd"); + s11.reserve(30); + VERIFY( 'a' + move(s11) == string("abcd") ); + + string s12("def"); + s12.reserve(30); + VERIFY( "abc" + move(s12) == string("abcdef") ); +} + +int main() +{ + test01(); + return 0; +} |