aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/22_locale
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2015-01-16 23:38:48 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2015-01-16 23:38:48 +0000
commit96d8c147aacf4b423e072c5da510ac12b0d4b507 (patch)
tree9fa678ce08c8d04a8f9eec47fe99c7d7753d6f94 /libstdc++-v3/testsuite/22_locale
parent28af1fb39dfbf903ccafeafda927d280fd8768d8 (diff)
downloadgcc-96d8c147aacf4b423e072c5da510ac12b0d4b507.zip
gcc-96d8c147aacf4b423e072c5da510ac12b0d4b507.tar.gz
gcc-96d8c147aacf4b423e072c5da510ac12b0d4b507.tar.bz2
locale_conv.h (wstring_convert, [...]): New.
* include/bits/locale_conv.h (wstring_convert, wbuffer_convert): New. * include/std/locale: Include new header. * include/Makefile.am: Add it. * include/Makefile.in: Regenerate. * testsuite/22_locale/conversions/buffer/requirements/typedefs.cc: New. * testsuite/22_locale/conversions/string/1.cc: New. * testsuite/22_locale/conversions/string/2.cc: New. * testsuite/22_locale/conversions/string/requirements/typedefs.cc: New. * testsuite/22_locale/conversions/string/requirements/typedefs-2.cc: New. From-SVN: r219780
Diffstat (limited to 'libstdc++-v3/testsuite/22_locale')
-rw-r--r--libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc36
-rw-r--r--libstdc++-v3/testsuite/22_locale/conversions/string/1.cc74
-rw-r--r--libstdc++-v3/testsuite/22_locale/conversions/string/2.cc60
-rw-r--r--libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc41
-rw-r--r--libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc34
5 files changed, 245 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
new file mode 100644
index 0000000..c59c6d6
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
@@ -0,0 +1,36 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2012 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.3.3.2.3 Buffer conversions
+
+#include <locale>
+#include <type_traits>
+
+void test01()
+{
+ // Check for required typedefs
+ struct cvt_type : std::codecvt<wchar_t, char, mbstate_t> { };
+ typedef std::char_traits<wchar_t> traits_type;
+ typedef std::wbuffer_convert<cvt_type, wchar_t, traits_type> test_type;
+ typedef test_type::state_type state_type;
+
+ static_assert( std::is_same<cvt_type::state_type, state_type>::value,
+ "state type" );
+}
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
new file mode 100644
index 0000000..c2ab6e7
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
@@ -0,0 +1,74 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2012 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.3.3.2.2 String conversions
+
+#include <locale>
+#include <string>
+#include <testsuite_hooks.h>
+
+template<typename Elem>
+struct cvt : std::codecvt<Elem, char, std::mbstate_t> { };
+
+template<typename Elem>
+using str_conv = std::wstring_convert<cvt<Elem>, Elem>;
+
+using std::string;
+using std::wstring;
+
+void test01()
+{
+ typedef str_conv<char> sc; // noconv
+ sc c;
+ string input = "King for a day...";
+ string output = c.from_bytes(input);
+ VERIFY( input == output );
+ VERIFY( c.converted() == output.length() );
+ string roundtrip = c.to_bytes(output);
+ VERIFY( input == roundtrip );
+ VERIFY( c.converted() == roundtrip.length() );
+}
+
+void test02()
+{
+ typedef str_conv<wchar_t> wsc;
+ wsc c;
+ string input = "Fool for a lifetime";
+ wstring output = c.from_bytes(input);
+ VERIFY( c.converted() == output.length() );
+ VERIFY( L"Fool for a lifetime" == output );
+ string roundtrip = c.to_bytes(output);
+ VERIFY( input == roundtrip );
+ VERIFY( c.converted() == roundtrip.length() );
+
+ VERIFY( c.from_bytes(input[0]) == output.substr(0, 1) );
+ VERIFY( c.from_bytes(input.c_str()) == output );
+ VERIFY( c.from_bytes(input.data(), input.data()+input.size()) == output );
+
+ VERIFY( c.to_bytes(output[0]) == input.substr(0, 1) );
+ VERIFY( c.to_bytes(output.c_str()) == input );
+ VERIFY( c.to_bytes(output.data(), output.data()+output.size()) == input );
+}
+
+int main()
+{
+ test01();
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
new file mode 100644
index 0000000..94eb75f
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
@@ -0,0 +1,60 @@
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2012 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.3.3.2.2 String conversions
+
+#include <locale>
+#include <string>
+#include <testsuite_hooks.h>
+
+template<typename Elem>
+struct cvt : std::codecvt<Elem, char, std::mbstate_t> { };
+
+template<typename Elem>
+using str_conv = std::wstring_convert<cvt<Elem>, Elem>;
+
+using std::string;
+using std::wstring;
+
+// test conversion errors, with and without error strings
+
+void test01()
+{
+ typedef str_conv<wchar_t> sc;
+
+ const sc::byte_string berr = "invalid wide string";
+ const sc::wide_string werr = L"invalid byte string";
+
+ sc c(berr, werr);
+ string input = "Stop";
+ input += char(0xff);
+ input += char(0xff);
+ wstring woutput = c.from_bytes(input);
+ VERIFY( werr == woutput );
+ wstring winput = L"Stop";
+ winput += wchar_t(0xff);
+ winput += wchar_t(0xff);
+ string output = c.to_bytes(winput);
+ VERIFY( berr == output );
+}
+
+int main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
new file mode 100644
index 0000000..65a1458
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
@@ -0,0 +1,41 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2012 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.3.3.2.2 String conversions
+
+#include <locale>
+#include <string>
+#include <type_traits>
+#include <testsuite_allocator.h>
+
+template<typename T>
+ using alloc = __gnu_test::uneq_allocator<T>;
+
+template<typename C>
+ using Str = std::basic_string<C, std::char_traits<C>, alloc<C>>;
+
+struct cvt : std::codecvt<wchar_t, char, std::mbstate_t> { };
+
+using wconv = std::wstring_convert<cvt, wchar_t, alloc<wchar_t>, alloc<char>>;
+
+static_assert( std::is_same<wconv::byte_string, Str<char>>::value,
+ "byte string is std::string" );
+static_assert( std::is_same<wconv::wide_string, Str<wchar_t>>::value,
+ "wide string is std::wstring" );
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
new file mode 100644
index 0000000..baed16e
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
@@ -0,0 +1,34 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2012 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.3.3.2.2 String conversions
+
+#include <locale>
+
+void test01()
+{
+ // Check for required typedefs
+ typedef std::codecvt<wchar_t, char, mbstate_t> codecvt_type;
+ typedef std::wstring_convert<codecvt_type> test_type;
+ typedef test_type::byte_string byte_string;
+ typedef test_type::wide_string wide_string;
+ typedef test_type::state_type state_type;
+ typedef test_type::int_type int_type;
+}