diff options
Diffstat (limited to 'libstdc++-v3/testsuite/22_locale/locale')
25 files changed, 1884 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/22_locale/locale/13630.cc b/libstdc++-v3/testsuite/22_locale/locale/13630.cc new file mode 100644 index 000000000..cb9da1519 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/13630.cc @@ -0,0 +1,36 @@ +// 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1 class locale [lib.locale] + +#include <locale> +#include <typeinfo> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + VERIFY( typeid(locale::category) == typeid(int) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/1.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/1.cc new file mode 100644 index 000000000..87c90a602 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/1.cc @@ -0,0 +1,38 @@ +// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2001, 2002, 2003, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <cwchar> // for mbstate_t +#include <locale> +#include <stdexcept> +#include <testsuite_hooks.h> + +void test00() +{ + // Should be able to do this as the first thing that happens in a + // file and have it not crash. + std::locale loc("C"); +} + +int main() +{ + test00(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/12352.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/12352.cc new file mode 100644 index 000000000..f56bf6786 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/12352.cc @@ -0,0 +1,126 @@ +// { dg-require-namedlocale "" } + +// Copyright (C) 2003, 2005, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <new> +#include <locale> +#include <cstdlib> +#include <cstring> +#include <testsuite_hooks.h> + +int times_to_fail = 0; + +void* allocate(std::size_t n) +{ + if (!times_to_fail--) + return 0; + + void* ret = std::malloc(n ? n : 1); + if (ret) + std::memset(ret, 0xbc, n); + return ret; +} + +void deallocate(void* p) +{ + if (p) + std::free(p); +} + +void* operator new(std::size_t n) throw (std::bad_alloc) +{ + void* ret = allocate(n); + if (!ret) + throw std::bad_alloc(); + return ret; +} + +void* operator new[](std::size_t n) throw (std::bad_alloc) +{ + void* ret = allocate(n); + if (!ret) + throw std::bad_alloc(); + return ret; +} + +void operator delete(void* p) throw() +{ + deallocate(p); +} + +void operator delete[](void* p) throw() +{ + deallocate(p); +} + +void* operator new(std::size_t n, const std::nothrow_t&) throw() +{ + return allocate(n); +} + +void* operator new[](std::size_t n, const std::nothrow_t&) throw() +{ + return allocate(n); +} + +void operator delete(void* p, const std::nothrow_t&) throw() +{ + deallocate(p); +} + +void operator delete[](void* p, const std::nothrow_t&) throw() +{ + deallocate(p); +} + +// libstdc++/12352 +void test01(int iters) +{ + bool test __attribute__((unused)) = true; + + for (int j = 0; j < iters; ++j) + { + for (int i = 0; i < 100; ++i) + { + times_to_fail = i; + try + { + std::locale loc1 = std::locale(""); + std::locale loc2(loc1, std::locale::classic(), + std::locale::numeric); + } + catch (std::exception&) + { + } + } + } +} + +int main(int argc, char* argv[]) +{ + int iters = 1; + if (argc > 1) + iters = std::atoi(argv[1]); + if (iters < 1) + iters = 1; + test01(iters); + + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/12438.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/12438.cc new file mode 100644 index 000000000..090e65331 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/12438.cc @@ -0,0 +1,71 @@ +// { dg-require-namedlocale "" } + +// Copyright (C) 2003, 2005, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <locale> +#include <stdexcept> +#include <cstdlib> +#include <testsuite_hooks.h> + +class MyFacet : public std::locale::facet +{ +public: + static std::locale::id id; +}; + +std::locale::id MyFacet::id; + +// libstdc++/12438 +void test01(int iters) +{ + using namespace std; + bool test __attribute__((unused)) = true; + + for (int i = 0; i < iters; ++i) + { + try + { + locale loc1 = locale::classic(); + locale loc2 = locale(""); + VERIFY( !has_facet<MyFacet>(loc2) ); + + loc1.combine<MyFacet>(loc2); + VERIFY( false ); + } + catch (std::runtime_error&) + { + } + } +} + +int main(int argc, char* argv[]) +{ + // We leaked ~400-500 bytes/iter. + __gnu_test::set_memory_limits(10.0); + int iters = 30000; + + if (argc > 1) + iters = atoi(argv[1]); + if (iters < 1) + iters = 1; + test01(iters); + + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/12658_thread-1.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/12658_thread-1.cc new file mode 100644 index 000000000..86b4216d1 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/12658_thread-1.cc @@ -0,0 +1,69 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthreads" { target *-*-solaris* } } +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "fr_FR" } + +// Copyright (C) 2004, 2005, 2007, 2009, 2010 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <locale> +#include <pthread.h> +#include <testsuite_hooks.h> + +const int max_thread_count = 20; +//const int max_loop_count = 1000000; // orig value +const int max_loop_count = 100000; +const int max_locales = 10; + +void* thread_main(void*) +{ + try + { + std::locale loc_c = std::locale::classic(); + std::locale loc[max_locales]; + for (int j = 0; j < max_locales; ++j) + loc[j] = std::locale(j % 2 ? "en_US" : "fr_FR"); + + for (int i = 0; i < max_loop_count; ++i) + { + int k = i % max_locales; + loc[k] = std::locale::global(loc[k]); + + if (i % 37 == 0) + loc[k] = loc[k].combine<std::ctype<char> >(loc_c); + } + } + catch (...) { } + return 0; +} + +int +main() +{ + pthread_t tid[max_thread_count]; + + for (int i = 0; i < max_thread_count; i++) + pthread_create (&tid[i], 0, thread_main, 0); + + for (int i = 0; i < max_thread_count; i++) + pthread_join (tid[i], 0); + + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/12658_thread-2.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/12658_thread-2.cc new file mode 100644 index 000000000..40c8c6674 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/12658_thread-2.cc @@ -0,0 +1,65 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthreads" { target *-*-solaris* } } +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "fr_FR" } + +// Copyright (C) 2004, 2005, 2007, 2009, 2010 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <locale> +#include <pthread.h> +#include <testsuite_hooks.h> + +const int max_thread_count = 20; +//const int max_loop_count = 1000000; // orig value +const int max_loop_count = 100000; +const int max_locales = 10; +std::locale loc[max_locales]; + +void* thread_main(void*) +{ + try + { + for (int i = 0; i < max_loop_count; ++i) + { + int k = i % max_locales; + std::locale::global(loc[k]); + } + } + catch (...) { } + return 0; +} + +int +main() +{ + pthread_t tid[max_thread_count]; + + for (int j = 0; j < max_locales; ++j) + loc[j] = std::locale(j % 2 ? "en_US" : "fr_FR"); + + for (int i = 0; i < max_thread_count; i++) + pthread_create(&tid[i], 0, thread_main, 0); + + for (int i = 0; i < max_thread_count; i++) + pthread_join(tid[i], 0); + + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/2.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/2.cc new file mode 100644 index 000000000..e859b5746 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/2.cc @@ -0,0 +1,214 @@ +// { dg-require-namedlocale "fr_FR" } + +// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, +// 2009, 2010 +// 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <cwchar> // for mbstate_t +#include <locale> +#include <stdexcept> +#include <typeinfo> +#include <testsuite_hooks.h> + +typedef std::codecvt<char, char, std::mbstate_t> c_codecvt; + +#ifdef _GLIBCXX_USE_WCHAR_T +typedef std::codecvt<wchar_t, char, std::mbstate_t> w_codecvt; +#endif + +class gnu_codecvt: public c_codecvt { }; + +class gnu_facet: public std::locale::facet +{ +public: + static std::locale::id id; +}; + +std::locale::id gnu_facet::id; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // construct a locale object with the C facet + const locale loc01 = locale::classic(); + + // 1 + // template <class Facet> locale(const locale& other, Facet* f) + // construct a locale object with the specialized facet. + locale loc02(locale::classic(), new gnu_codecvt); + VERIFY( loc01 != loc02 ); + VERIFY( loc02.name() == "*" ); + try + { + VERIFY( has_facet<gnu_codecvt>(loc02) ); + VERIFY( has_facet<c_codecvt>(loc02) ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( has_facet<w_codecvt>(loc02) ); +#endif + } + catch(...) + { VERIFY( false ); } + + try + { use_facet<gnu_facet>(loc02); } + catch(bad_cast& obj) + { VERIFY( true ); } + catch(...) + { VERIFY( false ); } + + // 2 + // locale() throw() + locale loc03; + VERIFY( loc03 == loc01 ); + VERIFY( loc03.name() == "C" ); + locale loc04 = locale::global(loc02); + locale loc05; + VERIFY( loc05 != loc03 ); + VERIFY( loc05 == loc02 ); + + // 3 + // explicit locale(const char* std_name) + locale loc06 = locale("fr_FR"); + VERIFY( loc06 != loc01 ); + VERIFY( loc06 != loc02 ); + VERIFY( loc06.name() == "fr_FR"); + locale loc07(""); + VERIFY( loc07 != loc02 ); + VERIFY( loc07.name() != "" ); + try + { locale loc08(static_cast<const char*>(0)); } + catch(runtime_error& obj) + { VERIFY( true ); } + catch(...) + { VERIFY( false ); } + + try + { locale loc08("saturn_SUN*RA"); } + catch(runtime_error& obj) + { VERIFY( true ); } + catch(...) + { VERIFY( false ); } + + // 4 + // locale(const locale& other, const char* std_name, category) + { + // This is the same as 5 only use "C" for loc("C") + locale loc09(loc06, "C", locale::ctype); + VERIFY( loc09.name() != "fr_FR" ); + VERIFY( loc09.name() != "C" ); + VERIFY( loc09.name() != "*" ); + VERIFY( loc09 != loc01 ); + VERIFY( loc09 != loc06 ); + + locale loc10(loc02, "C", locale::ctype); + VERIFY( loc10.name() == "*" ); + VERIFY( loc10 != loc01 ); // As not named, even tho facets same... + VERIFY( loc10 != loc02 ); + + locale loc11(loc01, "C", locale::ctype); + VERIFY( loc11.name() == "C" ); + VERIFY( loc11 == loc01 ); + + try + { locale loc12(loc01, static_cast<const char*>(0), locale::ctype); } + catch(runtime_error& obj) + { VERIFY( true ); } + catch(...) + { VERIFY( false ); } + + try + { locale loc13(loc01, "localized by the wu-tang clan", locale::ctype); } + catch(runtime_error& obj) + { VERIFY( true ); } + catch(...) + { VERIFY( false ); } + + locale loc14(loc06, "C", locale::none); + VERIFY( loc14.name() == "fr_FR" ); + VERIFY( loc14 == loc06 ); + + locale loc15(loc06, "C", locale::collate ); + VERIFY( loc15.name() != "fr_FR" ); + VERIFY( loc15.name() != "C" ); + VERIFY( loc15.name() != "*" ); + VERIFY( loc15.name() != loc09.name() ); + VERIFY( loc15 != loc01 ); + VERIFY( loc15 != loc06 ); + VERIFY( loc15 != loc09 ); + } + + // 5 + // locale(const locale& other, const locale& one, category) + { + // This is the exact same as 4, with locale("C") for "C" + locale loc09(loc06, loc01, locale::ctype); + VERIFY( loc09.name() != "fr_FR" ); + VERIFY( loc09.name() != "C" ); + VERIFY( loc09.name() != "*" ); + VERIFY( loc09 != loc01 ); + VERIFY( loc09 != loc06 ); + + locale loc10(loc02, loc01, locale::ctype); + VERIFY( loc10.name() == "*" ); + VERIFY( loc10 != loc01 ); // As not named, even tho facets same... + VERIFY( loc10 != loc02 ); + + locale loc11(loc01, loc01, locale::ctype); + VERIFY( loc11.name() == "C" ); + VERIFY( loc11 == loc01 ); + + try + { locale loc12(loc01, static_cast<const char*>(0), locale::ctype); } + catch(runtime_error& obj) + { VERIFY( true ); } + catch(...) + { VERIFY( false ); } + + try + { locale loc13(loc01, locale("wu-tang clan"), locale::ctype); } + catch(runtime_error& obj) + { VERIFY( true ); } + catch(...) + { VERIFY( false ); } + + locale loc14(loc06, loc01, locale::none); + VERIFY( loc14.name() == "fr_FR" ); + VERIFY( loc14 == loc06 ); + + locale loc15(loc06, loc01, locale::collate); + VERIFY( loc15.name() != "fr_FR" ); + VERIFY( loc15.name() != "C" ); + VERIFY( loc15.name() != "*" ); + VERIFY( loc15.name() != loc09.name() ); + VERIFY( loc15 != loc01 ); + VERIFY( loc15 != loc06 ); + VERIFY( loc15 != loc09 ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/29217.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/29217.cc new file mode 100644 index 000000000..dca694874 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/29217.cc @@ -0,0 +1,53 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2006, 2009, 2010 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <locale> +#include <testsuite_hooks.h> + +// libstdc++/29217 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + locale::global(locale(locale(), "en_US.UTF-8", + locale::collate | locale::ctype)); + + VERIFY( locale().name() == "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;" + "LC_TIME=C;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=C;" + "LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;" + "LC_MEASUREMENT=C;LC_IDENTIFICATION=C" ); + + VERIFY( locale().name() == setlocale(LC_ALL, 0) ); + + locale loc1 = locale(locale::classic(), "en_US.UTF-8", locale::time); + + VERIFY( loc1.name() == "LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;" + "LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;" + "LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;" + "LC_IDENTIFICATION=C" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/38365.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/38365.cc new file mode 100644 index 000000000..fa33254ed --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/38365.cc @@ -0,0 +1,44 @@ +// { dg-require-namedlocale "en_US" } + +// Copyright (C) 2008, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <locale> +#include <testsuite_hooks.h> + +// libstdc++/38365 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale other(locale("C")); + locale one(locale("en_US"), new ctype<char>()); + locale loc(other, one, locale::collate); + + VERIFY( one.name() == "*" ); + VERIFY( other.name() == "C" ); + VERIFY( loc.name() == "*" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/38368.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/38368.cc new file mode 100644 index 000000000..a02d7e257 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/38368.cc @@ -0,0 +1,53 @@ +// { dg-require-namedlocale "en_US" } + +// Copyright (C) 2008, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <locale> +#include <testsuite_hooks.h> + +// libstdc++/38368 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale("C"), "en_US", locale::collate); + locale loc_copy(loc.name().c_str()); + + const moneypunct<char, true>& mpunt = + use_facet<moneypunct<char, true> >(loc_copy); + VERIFY( mpunt.decimal_point() == '.' ); + VERIFY( mpunt.thousands_sep() == ',' ); + + const moneypunct<char, false>& mpunf = + use_facet<moneypunct<char, false> >(loc_copy); + VERIFY( mpunf.decimal_point() == '.' ); + VERIFY( mpunf.thousands_sep() == ',' ); + + const numpunct<char>& npun = use_facet<numpunct<char> >(loc_copy); + VERIFY( npun.decimal_point() == '.' ); + VERIFY( npun.thousands_sep() == ',' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/4.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/4.cc new file mode 100644 index 000000000..07f02f152 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/4.cc @@ -0,0 +1,49 @@ +// { dg-require-namedlocale "it_IT" } + +// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2001, 2002, 2003, 2005, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <cwchar> // for mbstate_t +#include <cstdlib> +#include <locale> +#include <stdexcept> +#include <testsuite_hooks.h> + +// libstdc++/7811 +void test03() +{ + bool test __attribute__((unused)) = true; +#ifdef _GLIBCXX_HAVE_SETENV + const char* LC_ALL_orig = getenv("LC_ALL"); + if (!setenv("LC_ALL", "it_IT", 1)) + { + std::locale loc = std::locale(""); + VERIFY( loc.name() == "it_IT" ); + setenv("LC_ALL", LC_ALL_orig ? LC_ALL_orig : "", 1); + } +#endif +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/40184.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/40184.cc new file mode 100644 index 000000000..2445e43eb --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/40184.cc @@ -0,0 +1,60 @@ +// { dg-require-namedlocale "ja_JP.eucjp" } + +// Copyright (C) 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <locale> +#include <testsuite_hooks.h> + +// libstdc++/40184 +void test01() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + using namespace std; + bool test __attribute__((unused)) = true; + + locale locf(locale("C"), "ja_JP.eucjp", locale::monetary); + + const moneypunct<wchar_t, false>& mpf = + use_facet<moneypunct<wchar_t, false> >(locf); + + locale locf_copy(locf.name().c_str()); + const moneypunct<wchar_t, false>& mpf_copy = + use_facet<moneypunct<wchar_t, false> >(locf_copy); + + VERIFY( mpf.curr_symbol() == mpf_copy.curr_symbol() ); + + locale loct(locale("C"), "ja_JP.eucjp", locale::monetary); + + const moneypunct<wchar_t, true>& mpt = + use_facet<moneypunct<wchar_t, true> >(loct); + + locale loct_copy(loct.name().c_str()); + const moneypunct<wchar_t, true>& mpt_copy = + use_facet<moneypunct<wchar_t, true> >(loct_copy); + + VERIFY( mpt.curr_symbol() == mpt_copy.curr_symbol() ); +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/5.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/5.cc new file mode 100644 index 000000000..812f469b3 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/5.cc @@ -0,0 +1,204 @@ +// { dg-require-namedlocale "en_PH" } +// { dg-require-namedlocale "de_DE" } +// { dg-require-namedlocale "it_IT" } + +// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <cwchar> // for mbstate_t +#include <cstring> +#include <cstdlib> +#include <locale> +#include <stdexcept> +#include <testsuite_hooks.h> + +// More tests for locale("") == POSIX locale::name. +void test04() +{ + bool test __attribute__((unused)) = true; + using namespace std; + +#ifdef _GLIBCXX_HAVE_SETENV + + const char* LANG_orig = getenv("LANG") ? strdup(getenv("LANG")) : ""; + const char* LC_ALL_orig = getenv("LC_ALL") ? strdup(getenv("LC_ALL")) : ""; + const char* LC_CTYPE_orig = + getenv("LC_CTYPE") ? strdup(getenv("LC_CTYPE")) : ""; + const char* LC_NUMERIC_orig = + getenv("LC_NUMERIC") ? strdup(getenv("LC_NUMERIC")) : ""; + const char* LC_TIME_orig = + getenv("LC_TIME") ? strdup(getenv("LC_TIME")) : ""; + const char* LC_COLLATE_orig = + getenv("LC_COLLATE") ? strdup(getenv("LC_COLLATE")) : ""; + const char* LC_MONETARY_orig = + getenv("LC_MONETARY") ? strdup(getenv("LC_MONETARY")) : ""; + const char* LC_MESSAGES_orig = + getenv("LC_MESSAGES") ? strdup(getenv("LC_MESSAGES")) : ""; +#if _GLIBCXX_NUM_CATEGORIES + const char* LC_PAPER_orig = + getenv("LC_PAPER") ? strdup(getenv("LC_PAPER")) : ""; + const char* LC_NAME_orig = + getenv("LC_NAME") ? strdup(getenv("LC_NAME")) : ""; + const char* LC_ADDRESS_orig = + getenv("LC_ADDRESS") ? strdup(getenv("LC_ADDRESS")) : ""; + const char* LC_TELEPHONE_orig = + getenv("LC_TELEPHONE") ? strdup(getenv("LC_TELEPHONE")) : ""; + const char* LC_MEASUREMENT_orig = + getenv("LC_MEASUREMENT") ? strdup(getenv("LC_MEASUREMENT")) : ""; + const char* LC_IDENTIFICATION_orig = + getenv("LC_IDENTIFICATION") ? strdup(getenv("LC_IDENTIFICATION")) : ""; +#endif + + // Check that a "POSIX" LC_ALL is equivalent to "C". + if (!setenv("LC_ALL", "POSIX", 1)) + { + locale loc = locale(""); + VERIFY( loc.name() == "C" ); + } + setenv("LC_ALL", "", 1); + + // Check that a "en_PH" LC_ALL is equivalent to "en_PH". + if (!setenv("LC_ALL", "en_PH", 1)) + { + locale loc = locale(""); + VERIFY( loc.name() == "en_PH" ); + } + setenv("LC_ALL", "", 1); + + // Explicit check that LC_ALL sets regardless of LC_* and LANG. + if (!setenv("LANG", "es_MX", 1) && !setenv("LC_COLLATE", "de_DE", 1)) + { + if (!setenv("LC_ALL", "en_PH", 1)) + { + locale loc = locale(""); + VERIFY( loc.name() == "en_PH" ); + } + setenv("LC_ALL", "", 1); + setenv("LANG", LANG_orig ? LANG_orig : "", 1); + setenv("LC_COLLATE", LC_COLLATE_orig ? LC_COLLATE_orig : "", 1); + } + + // NB: LANG checks all LC_* macro settings. As such, all LC_* macros + // must be cleared for these tests, and then restored. + setenv("LC_ALL", "", 1); + setenv("LC_CTYPE", "", 1); + setenv("LC_NUMERIC", "", 1); + setenv("LC_TIME", "", 1); + setenv("LC_COLLATE", "", 1); + setenv("LC_MONETARY", "", 1); + setenv("LC_MESSAGES", "", 1); +#if _GLIBCXX_NUM_CATEGORIES + setenv("LC_PAPER", "", 1); + setenv("LC_NAME", "", 1); + setenv("LC_ADDRESS", "", 1); + setenv("LC_TELEPHONE", "", 1); + setenv("LC_MEASUREMENT", "", 1); + setenv("LC_IDENTIFICATION", "", 1); +#endif + + // Check the default set by LANG. + if (!setenv("LANG", "fr_FR", 1)) + { + locale loc = locale(""); + VERIFY( loc.name() == "fr_FR" ); + } + + // Check that a "POSIX" LANG is equivalent to "C". + if (!setenv("LANG", "POSIX", 1)) + { + locale loc(""); + VERIFY( loc.name() == "C" ); + } + + // Setting a category in the "C" default. + if (!setenv("LC_COLLATE", "de_DE", 1)) + { + locale loc = locale(""); + +#if _GLIBCXX_NUM_CATEGORIES + VERIFY( loc.name() == "LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=C;" + "LC_COLLATE=de_DE;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;" + "LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;" + "LC_IDENTIFICATION=C" ); +#else + VERIFY( loc.name() == "LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=C;" + "LC_COLLATE=de_DE;LC_MONETARY=C;LC_MESSAGES=C" ); +#endif + } + + // Changing the LANG default while LC_COLLATE is set. + if (!setenv("LANG", "fr_FR", 1)) + { + locale loc = locale(""); +#if _GLIBCXX_NUM_CATEGORIES + VERIFY( loc.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;" + "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;" + "LC_MESSAGES=fr_FR;LC_PAPER=fr_FR;LC_NAME=fr_FR;" + "LC_ADDRESS=fr_FR;LC_TELEPHONE=fr_FR;LC_MEASUREMENT=fr_FR;" + "LC_IDENTIFICATION=fr_FR" ); +#else + VERIFY( loc.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;" + "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;" + "LC_MESSAGES=fr_FR" ); +#endif + } + + // Changing another (C only) category. +#if _GLIBCXX_NUM_CATEGORIES + if (!setenv("LC_IDENTIFICATION", "it_IT", 1)) + { + locale loc = locale(""); + VERIFY( loc.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;" + "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;" + "LC_MESSAGES=fr_FR;LC_PAPER=fr_FR;LC_NAME=fr_FR;" + "LC_ADDRESS=fr_FR;LC_TELEPHONE=fr_FR;LC_MEASUREMENT=fr_FR;" + "LC_IDENTIFICATION=it_IT" ); + } +#endif + + // Restore the environment. + setenv("LANG", LANG_orig ? LANG_orig : "", 1); + setenv("LC_ALL", LC_ALL_orig ? LC_ALL_orig : "", 1); + setenv("LC_CTYPE", LC_CTYPE_orig ? LC_CTYPE_orig : "", 1); + setenv("LC_NUMERIC", LC_NUMERIC_orig ? LC_NUMERIC_orig : "", 1); + setenv("LC_TIME", LC_TIME_orig ? LC_TIME_orig : "", 1); + setenv("LC_COLLATE", LC_COLLATE_orig ? LC_COLLATE_orig : "", 1); + setenv("LC_MONETARY", LC_MONETARY_orig ? LC_MONETARY_orig : "", 1); + setenv("LC_MESSAGES", LC_MESSAGES_orig ? LC_MESSAGES_orig : "", 1); +#if _GLIBCXX_NUM_CATEGORIES + setenv("LC_PAPER", LC_PAPER_orig ? LC_PAPER_orig : "", 1); + setenv("LC_NAME", LC_NAME_orig ? LC_NAME_orig : "", 1); + setenv("LC_ADDRESS", LC_ADDRESS_orig ? LC_ADDRESS_orig : "", 1); + setenv("LC_TELEPHONE", LC_TELEPHONE_orig ? LC_TELEPHONE_orig : "", 1); + setenv("LC_MEASUREMENT", LC_MEASUREMENT_orig ? LC_MEASUREMENT_orig : "", 1); + setenv("LC_IDENTIFICATION", + LC_IDENTIFICATION_orig ? LC_IDENTIFICATION_orig : "", 1); +#endif + +#endif +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/6.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/6.cc new file mode 100644 index 000000000..c25184203 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/6.cc @@ -0,0 +1,58 @@ +// 2001-01-19 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1 - Class locale [lib.locale] + +#include <locale> +#include <string> +#include <testsuite_hooks.h> + +// creating unnamed locales 1 using new + combine +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const string name_c("C"); + const string str_unnamed("*"); + string str; + + // construct a locale object with the specialized facet. + locale loc_c = locale::classic(); + locale loc_1(locale::classic(), new numpunct<char>); + + // check names + VERIFY( loc_c.name() == name_c ); + VERIFY( loc_1.name() == str_unnamed ); + + // sanity check the constructed locale has the specialized facet. + VERIFY( has_facet<numpunct<char> >(loc_1) ); + VERIFY( has_facet<numpunct<char> >(loc_c) ); + + // attempt to re-synthesize classic locale + locale loc_2 = loc_1.combine<numpunct<char> >(loc_c); + VERIFY( loc_2.name() == str_unnamed ); + VERIFY( loc_2 != loc_c ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/7.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/7.cc new file mode 100644 index 000000000..02e4aee84 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/7.cc @@ -0,0 +1,106 @@ +// { dg-require-namedlocale "is_IS" } + +// 2001-01-19 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1 - Class locale [lib.locale] + +#include <locale> +#include <string> +#include <testsuite_hooks.h> + +void +test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const string name_c("C"); + const string name_no("*"); + string str; + + // construct a locale object with the specialized facet. + locale loc_c = locale::classic(); + locale loc_is = locale("is_IS"); + locale loc_1(locale::classic(), + new numpunct_byname<char>("is_IS")); + + // check names + VERIFY( loc_c.name() == name_c ); + VERIFY( loc_1.name() == name_no ); + + // sanity check the constructed locale has the specialized facet. + VERIFY( has_facet<numpunct<char> >(loc_1) ); + VERIFY( has_facet<numpunct<char> >(loc_c) ); + + // attempt to re-synthesize classic locale + locale loc_2 = loc_1.combine<numpunct<char> >(loc_c); + VERIFY( loc_2.name() == name_no ); + VERIFY( loc_2 != loc_c ); + + // extract facet + const numpunct<char>& nump_1 = use_facet<numpunct<char> >(loc_1); + const numpunct<char>& nump_2 = use_facet<numpunct<char> >(loc_2); + const numpunct<char>& nump_c = use_facet<numpunct<char> >(loc_c); + const numpunct<char>& nump_is = use_facet<numpunct<char> >(loc_is); + + // sanity check the data is correct. + char dp1 = nump_c.decimal_point(); + char th1 = nump_c.thousands_sep(); + string g1 = nump_c.grouping(); + string t1 = nump_c.truename(); + string f1 = nump_c.falsename(); + + char dp2 = nump_1.decimal_point(); + char th2 = nump_1.thousands_sep(); + string g2 = nump_1.grouping(); + string t2 = nump_1.truename(); + string f2 = nump_1.falsename(); + + char dp3 = nump_2.decimal_point(); + char th3 = nump_2.thousands_sep(); + string g3 = nump_2.grouping(); + string t3 = nump_2.truename(); + string f3 = nump_2.falsename(); + + char dp4 = nump_is.decimal_point(); + char th4 = nump_is.thousands_sep(); + string g4 = nump_is.grouping(); + string t4 = nump_is.truename(); + string f4 = nump_is.falsename(); + VERIFY( dp1 != dp2 ); + VERIFY( th1 != th2 ); + + VERIFY( dp1 == dp3 ); + VERIFY( th1 == th3 ); + VERIFY( t1 == t3 ); + VERIFY( f1 == f3 ); + + VERIFY( dp2 == dp4 ); + VERIFY( th2 == th4 ); + VERIFY( t2 == t4 ); + VERIFY( f2 == f4 ); +} + + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/7222-c.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/7222-c.cc new file mode 100644 index 000000000..8f717f2f0 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/7222-c.cc @@ -0,0 +1,41 @@ +// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2001, 2002, 2003, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <cwchar> // for mbstate_t +#include <locale> +#include <stdexcept> +#include <testsuite_hooks.h> + +// libstdc++/7222 +void test02() +{ + bool test __attribute__((unused)) = true; + + std::locale loc_c1("C"); + std::locale loc_c2("C"); + VERIFY( loc_c1 == loc_c2 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/7222-env.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/7222-env.cc new file mode 100644 index 000000000..96f80f39a --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/7222-env.cc @@ -0,0 +1,43 @@ +// { dg-require-namedlocale "" } + +// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2001, 2002, 2003, 2005, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <cwchar> // for mbstate_t +#include <locale> +#include <stdexcept> +#include <testsuite_hooks.h> + +// libstdc++/7222 +void test02() +{ + bool test __attribute__((unused)) = true; + + std::locale loc_1 = std::locale(""); + std::locale loc_2 = std::locale(""); + VERIFY( loc_1 == loc_2 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/8.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/8.cc new file mode 100644 index 000000000..5114130d4 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/8.cc @@ -0,0 +1,42 @@ +// 2003-02-01 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <locale> + +// Const correctness issue: +// http://gcc.gnu.org/ml/libstdc++/2003-01/msg00370.html +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const locale l1("C"); + const locale l2 = + locale(locale::classic(), &use_facet<time_get<char> >(l1)); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc new file mode 100644 index 000000000..546fb4e79 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc @@ -0,0 +1,81 @@ +// { dg-require-iconv "ISO-8859-1" } + +// Copyright (C) 2006, 2007, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include <cwchar> // for mbstate_t +#include <locale> +#include <stdexcept> +#include <typeinfo> +#include <testsuite_hooks.h> +#include <ext/codecvt_specializations.h> + +typedef std::codecvt<char, char, std::mbstate_t> c_codecvt; + +#ifdef _GLIBCXX_USE_WCHAR_T +typedef std::codecvt<wchar_t, char, std::mbstate_t> w_codecvt; +#endif + +class gnu_facet: public std::locale::facet +{ +public: + static std::locale::id id; +}; + +std::locale::id gnu_facet::id; + +void test01() +{ + using namespace std; + typedef unsigned short int_type; + typedef char ext_type; + typedef __gnu_cxx::encoding_state state_type; + typedef codecvt<int_type, ext_type, state_type> unicode_codecvt; + + bool test __attribute__((unused)) = true; + + // unicode_codecvt + locale loc01(locale::classic()); + locale loc13(locale::classic(), new unicode_codecvt); + VERIFY( loc01 != loc13 ); + VERIFY( loc13.name() == "*" ); + try + { + VERIFY( has_facet<c_codecvt>(loc13) ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( has_facet<w_codecvt>(loc13) ); +#endif + VERIFY( has_facet<unicode_codecvt>(loc13) ); + } + catch(...) + { VERIFY( false ); } + + try + { use_facet<gnu_facet>(loc13); } + catch(bad_cast& obj) + { VERIFY( true ); } + catch(...) + { VERIFY( false ); } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/1.cc b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/1.cc new file mode 100644 index 000000000..5c83afa42 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/1.cc @@ -0,0 +1,66 @@ +// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2002, 2003, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.5 locale static members [lib.locale.statics] + +#include <cwchar> // for mbstate_t +#include <locale> +#include <testsuite_hooks.h> + +typedef std::codecvt<char, char, std::mbstate_t> ccodecvt; +class gnu_codecvt: public ccodecvt { }; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + string str1, str2; + + // Construct a locale object with the C facet. + const locale loc01 = locale::classic(); + + // Construct a locale object with the specialized facet. + locale loc02(locale::classic(), new gnu_codecvt); + VERIFY ( loc01 != loc02 ); + VERIFY ( !(loc01 == loc02) ); + + // classic + locale loc06("C"); + VERIFY (loc06 == loc01); + str1 = loc06.name(); + VERIFY( str1 == "C" ); + + // global + locale loc03; + VERIFY ( loc03 == loc01); + locale global_orig = locale::global(loc02); + locale loc05; + VERIFY (loc05 != loc03); + VERIFY (loc05 == loc02); + + // Reset global settings. + locale::global(global_orig); +} + +int main () +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/14071.cc b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/14071.cc new file mode 100644 index 000000000..f0035cbfb --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/14071.cc @@ -0,0 +1,51 @@ +// { dg-require-namedlocale "is_IS" } +// { dg-require-namedlocale "en_US" } + +// 2004-02-09 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2005, 2009, 2010 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.5 locale static members [lib.locale.statics] + +#include <locale> +#include <clocale> +#include <testsuite_hooks.h> + +// libstdc++/14071 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const locale loc_is = locale("is_IS"); + const locale loc_en = locale("en_US"); + + const locale loc(loc_is, loc_en, locale::monetary); + + if (loc.name() != "*") + { + locale::global(loc); + VERIFY( loc.name() == setlocale(LC_ALL, 0) ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/2.cc b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/2.cc new file mode 100644 index 000000000..98b731258 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/2.cc @@ -0,0 +1,73 @@ +// { dg-require-namedlocale "en_PH" } +// { dg-require-namedlocale "es_MX" } + +// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2002, 2003, 2005, 2009, 2010 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.5 locale static members [lib.locale.statics] + +#include <cwchar> // for mbstate_t +#include <locale> +#include <testsuite_hooks.h> + +// Sanity check locale::global(loc) and setlocale. +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const string ph("en_PH"); + const string mx("es_MX"); + const char* orig = setlocale(LC_ALL, 0); + const char* testph = setlocale(LC_ALL, ph.c_str()); + const char* testmx = setlocale(LC_ALL, mx.c_str()); + setlocale(LC_ALL, orig); + + // If the underlying locale doesn't support these names, setlocale + // won't be reset. Therefore, disable unless we know these specific + // named locales work. + if (testph && testmx) + { + const locale loc_ph = locale(ph.c_str()); + const locale loc_mx = locale(mx.c_str()); + + // Use setlocale between two calls to locale("") + const locale loc_env_1 = locale(""); + setlocale(LC_ALL, ph.c_str()); + const locale loc_env_2 = locale(""); + VERIFY( loc_env_1 == loc_env_2 ); + + // Change global locale. + locale global_orig = locale::global(loc_mx); + const char* lc_all_mx = setlocale(LC_ALL, 0); + if (lc_all_mx) + { + VERIFY( mx == lc_all_mx ); + } + + // Restore global settings. + locale::global(global_orig); + } +} + +int main () +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc new file mode 100644 index 000000000..07f8f1d4a --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc @@ -0,0 +1,112 @@ +// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2002, 2003, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.5 locale static members [lib.locale.statics] + +#include <cwchar> // for mbstate_t +#include <locale> +#include <testsuite_hooks.h> + +// Static counter for use in checking ctors/dtors. +static std::size_t counter; + +class surf : public std::locale::facet +{ +public: + static std::locale::id id; + surf(size_t refs = 0): std::locale::facet(refs) { ++counter; } + ~surf() { --counter; } +}; + +std::locale::id surf::id; + +typedef surf facet_type; + +// Verify lifetimes of global objects. +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + string name; + locale global_orig; + // 1: Destroyed when out of scope. + { + { + { + VERIFY( counter == 0 ); + { + locale loc01(locale::classic(), new facet_type); + VERIFY( counter == 1 ); + global_orig = locale::global(loc01); + name = loc01.name(); + } + VERIFY( counter == 1 ); + locale loc02 = locale(); + // Weak, but it's something... + VERIFY( loc02.name() == name ); + } + VERIFY( counter == 1 ); + // NB: loc03 should be a copy of the previous global locale. + locale loc03 = locale::global(global_orig); + VERIFY( counter == 1 ); + VERIFY( loc03.name() == name ); + } + VERIFY( counter == 0 ); + locale loc04 = locale(); + VERIFY( loc04 == global_orig ); + } + + // 2: Not destroyed when out of scope, deliberately leaked. + { + { + { + VERIFY( counter == 0 ); + { + locale loc01(locale::classic(), new facet_type(1)); + VERIFY( counter == 1 ); + global_orig = locale::global(loc01); + name = loc01.name(); + } + VERIFY( counter == 1 ); + locale loc02 = locale(); + // Weak, but it's something... + VERIFY( loc02.name() == name ); + } + VERIFY( counter == 1 ); + // NB: loc03 should be a copy of the previous global locale. + locale loc03 = locale::global(global_orig); + VERIFY( counter == 1 ); + VERIFY( loc03.name() == name ); + } + VERIFY( counter == 1 ); + locale loc04 = locale(); + VERIFY( loc04 == global_orig ); + } + VERIFY( counter == 1 ); + + // Restore global settings. + locale::global(global_orig); +} + +int main () +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/operations/1.cc b/libstdc++-v3/testsuite/22_locale/locale/operations/1.cc new file mode 100644 index 000000000..b4b3850e8 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/operations/1.cc @@ -0,0 +1,66 @@ +// 2000-09-11 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2001, 2002, 2003, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.4 locale operators [lib.locale.operators] + +#include <cwchar> // for mbstate_t +#include <locale> +#include <testsuite_hooks.h> + +typedef std::codecvt<char, char, std::mbstate_t> ccodecvt; +class gnu_codecvt: public ccodecvt { }; + +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + string str1, str2; + + // construct a locale object with the C facet + const locale& cloc = locale::classic(); + // construct a locale object with the specialized facet. + locale loc(locale::classic(), new gnu_codecvt); + VERIFY ( cloc != loc ); + VERIFY ( !(cloc == loc) ); + + str1 = cloc.name(); + str2 = loc.name(); + VERIFY( loc(str1, str2) == false ); +} + +// bool operator()(const string_type&, const string_type&) const +long gnu_count; + +class gnu_collate: public std::collate<char> +{ +protected: + virtual int + do_compare(const char*, const char*, const char*, const char*) const + { ++gnu_count; return 0; } +}; + +int main () +{ + test01(); + return 0; +} + + + diff --git a/libstdc++-v3/testsuite/22_locale/locale/operations/2.cc b/libstdc++-v3/testsuite/22_locale/locale/operations/2.cc new file mode 100644 index 000000000..346a7713e --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/operations/2.cc @@ -0,0 +1,63 @@ +// 2000-09-11 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2000, 2001, 2002, 2003, 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 +// <http://www.gnu.org/licenses/>. + +// 22.1.1.4 locale operators [lib.locale.operators] + +#include <cwchar> // for mbstate_t +#include <locale> +#include <testsuite_hooks.h> + +// bool operator()(const string_type&, const string_type&) const +long gnu_count; + +class gnu_collate: public std::collate<char> +{ +protected: + virtual int + do_compare(const char*, const char*, const char*, const char*) const + { ++gnu_count; return 0; } +}; + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // Sanity check. + locale loc_c = locale::classic(); + string s01("land of "); + string s02("land of look behind"); + VERIFY( !loc_c(s01, s01) ); + VERIFY( loc_c(s01, s02) ); + + // Derivation, MF check. + locale loc_gnu(loc_c, new gnu_collate); + gnu_count = 0; + loc_gnu(s01, s02); + VERIFY( gnu_count == 1 ); +} + +int main () +{ + test02(); + return 0; +} + + + |