From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; 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. --- .../21_strings/basic_string/compare/char/1.cc | 135 +++++++++++++++++++++ .../21_strings/basic_string/compare/char/13650.cc | 47 +++++++ .../21_strings/basic_string/compare/wchar_t/1.cc | 133 ++++++++++++++++++++ .../basic_string/compare/wchar_t/13650.cc | 47 +++++++ 4 files changed, 362 insertions(+) create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/compare/char/1.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/compare/char/13650.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/compare/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/compare/wchar_t/13650.cc (limited to 'libstdc++-v3/testsuite/21_strings/basic_string/compare') 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 000000000..d58b02336 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/compare/char/1.cc @@ -0,0 +1,135 @@ +// 980930 bkoz work with libstdc++v3 + +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007, 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 +// . + +// 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 +#include +#include + +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 test __attribute__((unused)) = true; + 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 + } + VERIFY(pass); + 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 + +// Copyright (C) 2004, 2009 Free Software Foundation +// +// 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 +// . + +// 21.3.6.8 basic_string::compare [lib.string::compare] + +#include +#include + +// libstdc++/13650 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char lit_01[] = { 'w', 'e', '\0', 'r', 'd' }; + const char lit_02[] = { 'w', 'e', 'i', '\0', 'd' }; + + const char lit_ref_a[] = { 'w', 'e', '\0', 'q', 'd' }; + const string str_a(lit_ref_a, 5); + VERIFY( str_a.compare(0, 5, lit_01, 5) < 0 ); + + const char lit_ref_b[] = { 'w', 'e', 'i' }; + const string str_b(lit_ref_b, 3); + VERIFY( str_b.compare(0, 3, lit_02, 5) < 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 000000000..78cb0db4d --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/compare/wchar_t/1.cc @@ -0,0 +1,133 @@ +// 980930 bkoz work with libstdc++v3 + +// Copyright (C) 1998, 1999, 2003, 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 +// . + +// 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 +#include + +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 test __attribute__((unused)) = true; + 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 + } + + VERIFY(pass); + 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 + +// Copyright (C) 2004, 2009 Free Software Foundation +// +// 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 +// . + +// 21.3.6.8 basic_string::compare [lib.string::compare] + +#include +#include + +// libstdc++/13650 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const wchar_t lit_01[] = { L'w', L'e', L'\0', L'r', L'd' }; + const wchar_t lit_02[] = { L'w', L'e', L'i', L'\0', L'd' }; + + const wchar_t lit_ref_a[] = { L'w', L'e', L'\0', L'q', L'd' }; + const wstring str_a(lit_ref_a, 5); + VERIFY( str_a.compare(0, 5, lit_01, 5) < 0 ); + + const wchar_t lit_ref_b[] = { L'w', L'e', L'i' }; + const wstring str_b(lit_ref_b, 3); + VERIFY( str_b.compare(0, 3, lit_02, 5) < 0 ); +} + +int main() +{ + test01(); + return 0; +} -- cgit v1.2.3