diff options
author | Tom Honermann <tom@honermann.net> | 2019-02-19 02:55:05 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-02-19 02:55:05 +0000 |
commit | 46ca1dd73c97c5bf85057d450adf4b885a427e77 (patch) | |
tree | bb7dac034e30fbbe342d837c64f61962be6db738 /libstdc++-v3/testsuite/22_locale | |
parent | c124af936b6b225eb548ccdd7f01400511d784dc (diff) | |
download | gcc-46ca1dd73c97c5bf85057d450adf4b885a427e77.zip gcc-46ca1dd73c97c5bf85057d450adf4b885a427e77.tar.gz gcc-46ca1dd73c97c5bf85057d450adf4b885a427e77.tar.bz2 |
P0482R5 char8_t: New standard library tests
2019-02-19 Tom Honermann <tom@honermann.net>
* testsuite/18_support/numeric_limits/char8_t.cc: New test cloned
from char16_32_t.cc; validates numeric_limits<char8_t>.
* testsuite/21_strings/basic_string/literals/types-char8_t.cc: New
test cloned from types.cc; validates operator""s for char8_t
returns u8string.
* testsuite/21_strings/basic_string/literals/values-char8_t.cc: New
test cloned from values.cc; validates construction and comparison
of u8string values.
* testsuite/21_strings/basic_string/requirements/
/explicit_instantiation/char8_t/1.cc: New test cloned from
char16_t/1.cc; validates explicit instantiation of
basic_string<char8_t>.
* testsuite/21_strings/basic_string_view/literals/types-char8_t.cc:
New test cloned from types.cc; validates operator""sv for char8_t
returns u8string_view.
* testsuite/21_strings/basic_string_view/literals/
values-char8_t.cc: New test cloned from values.cc; validates
construction and comparison of u8string_view values.
* testsuite/21_strings/basic_string_view/requirements/
explicit_instantiation/char8_t/1.cc: New test cloned from
char16_t/1.cc; validates explicit instantiation of
basic_string_view<char8_t>.
* testsuite/21_strings/char_traits/requirements/char8_t/65049.cc:
New test cloned from char16_t/65049.cc; validates that
char_traits<char8_t> is not vulnerable to the concerns in PR65049.
* testsuite/21_strings/char_traits/requirements/char8_t/
typedefs.cc: New test cloned from char16_t/typedefs.cc; validates
that char_traits<char8_t> member typedefs are present and correct.
* testsuite/21_strings/char_traits/requirements/
explicit_instantiation/char8_t/1.cc: New test cloned from
char16_t/1.cc; validates explicit instantiation of
char_traits<char8_t>.
* testsuite/22_locale/codecvt/char16_t-char8_t.cc: New test cloned
from char16_t.cc: validates
codecvt<char16_t, char8_t, mbstate_t>.
* testsuite/22_locale/codecvt/char32_t-char8_t.cc: New test cloned
from char32_t.cc: validates
codecvt<char32_t, char8_t, mbstate_t>.
* testsuite/22_locale/codecvt/utf8-char8_t.cc: New test cloned from
utf8.cc; validates codecvt<char16_t, char8_t, std::mbstate_t> and
codecvt<char32_t, char8_t, std::mbstate_t>.
* testsuite/27_io/filesystem/path/native/string-char8_t.cc: New
test cloned from string.cc; validates filesystem::path construction
from char8_t input.
* testsuite/experimental/feat-char8_t.cc: New test; validates that
the __cpp_lib_char8_t feature test macro is defined with the
correct value.
* testsuite/experimental/filesystem/path/native/string-char8_t.cc:
New test cloned from string.cc; validates filesystem::path
construction from char8_t input.
* testsuite/experimental/string_view/literals/types-char8_t.cc: New
test cloned from types.cc; validates operator""sv for char8_t
returns u8string_view.
* testsuite/experimental/string_view/literals/values-char8_t.cc:
New test cloned from values.cc; validates construction and
comparison of u8string_view values.
* testsuite/experimental/string_view/requirements/
explicit_instantiation/char8_t/1.cc: New test cloned from
char16_t/1.cc; validates explicit instantiation of
basic_string_view<char8_t>.
* testsuite/ext/char8_t/atomic-1.cc: New test; validates that
ATOMIC_CHAR8_T_LOCK_FREE is not defined if char8_t support is not
enabled.
From-SVN: r269005
Diffstat (limited to 'libstdc++-v3/testsuite/22_locale')
3 files changed, 275 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/char16_t-char8_t.cc b/libstdc++-v3/testsuite/22_locale/codecvt/char16_t-char8_t.cc new file mode 100644 index 0000000..135a377 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/codecvt/char16_t-char8_t.cc @@ -0,0 +1,98 @@ +// Copyright (C) 2015-2017 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-do run { target c++11 } } +// { dg-require-cstdint "" } +// { dg-options "-fchar8_t" } + +// [locale.codecvt], C++11 22.4.1.4. specialization. + +#include <locale> +#include <cstring> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std; + typedef codecvt<char16_t, char8_t, mbstate_t> codecvt_c16; + locale loc_c = locale::classic(); + VERIFY(has_facet<codecvt_c16>(loc_c)); + const codecvt_c16* const cvt = &use_facet<codecvt_c16>(loc_c); + + VERIFY(!cvt->always_noconv()); + VERIFY(cvt->max_length() == 4); + VERIFY(cvt->encoding() == 0); + + const char8_t u8dat[] = u8"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD " + u8"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA " + u8"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E" + u8"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05"; + const char8_t* const u8dat_end = std::end(u8dat); + + const char16_t u16dat[] = u"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD " + u"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA " + u"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E" + u"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05"; + const char16_t* const u16dat_end = std::end(u16dat); + + { + const size_t len = u16dat_end - u16dat + 1; + char16_t* const buffer = new char16_t[len]; + char16_t* const buffer_end = buffer + len; + + const char8_t* from_next; + char16_t* to_next; + + codecvt_c16::state_type state01; + state01 = {}; + codecvt_base::result res = cvt->in(state01, u8dat, u8dat_end, from_next, + buffer, buffer_end, to_next); + + VERIFY(res == codecvt_base::ok); + VERIFY(from_next == u8dat_end); + VERIFY(std::memcmp((void*)buffer, (void*)u16dat, sizeof(u16dat)) == 0); + + delete[] buffer; + } + + { + const size_t len = u8dat_end - u8dat + 1; + char8_t* const buffer = new char8_t[len]; + char8_t* const buffer_end = buffer + len; + + const char16_t* from_next; + char8_t* to_next; + + codecvt_c16::state_type state01; + state01 = {}; + codecvt_base::result res = cvt->out(state01, u16dat, u16dat_end, from_next, + buffer, buffer_end, to_next); + + VERIFY(res == codecvt_base::ok); + VERIFY(from_next == u16dat_end); + VERIFY(std::memcmp((void*)buffer, (void*)u8dat, sizeof(u8dat)) == 0); + + delete[] buffer; + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/char32_t-char8_t.cc b/libstdc++-v3/testsuite/22_locale/codecvt/char32_t-char8_t.cc new file mode 100644 index 0000000..3acfa0b --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/codecvt/char32_t-char8_t.cc @@ -0,0 +1,100 @@ +// { dg-do run { target c++11 } } +// { dg-require-cstdint "" } +// { dg-options "-fchar8_t" } + +// 2014-04-24 Rüdiger Sonderfeld + +// Copyright (C) 2015-2017 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/>. + +// [locale.codecvt], C++11 22.4.1.4. specialization. + +#include <locale> +#include <cstring> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std; + typedef codecvt<char32_t, char8_t, mbstate_t> codecvt_c32; + locale loc_c = locale::classic(); + VERIFY(has_facet<codecvt_c32>(loc_c)); + const codecvt_c32* const cvt = &use_facet<codecvt_c32>(loc_c); + + VERIFY(!cvt->always_noconv()); + VERIFY(cvt->max_length() == 4); + VERIFY(cvt->encoding() == 0); + + const char8_t u8dat[] = u8"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD " + u8"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA " + u8"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E" + u8"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05"; + const char8_t* const u8dat_end = std::end(u8dat); + + const char32_t u32dat[] = U"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD " + U"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA " + U"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E" + U"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05"; + const char32_t* const u32dat_end = std::end(u32dat); + + { + const size_t len = u32dat_end - u32dat + 1; + char32_t* const buffer = new char32_t[len]; + char32_t* const buffer_end = buffer + len; + + const char8_t* from_next; + char32_t* to_next; + + codecvt_c32::state_type state01; + state01 = {}; + codecvt_base::result res = cvt->in(state01, u8dat, u8dat_end, from_next, + buffer, buffer_end, to_next); + + VERIFY(res == codecvt_base::ok); + VERIFY(from_next == u8dat_end); + VERIFY(std::memcmp((void*)buffer, (void*)u32dat, sizeof(u32dat)) == 0); + + delete[] buffer; + } + + { + const size_t len = u8dat_end - u8dat + 1; + char8_t* const buffer = new char8_t[len]; + char8_t* const buffer_end = buffer + len; + + const char32_t* from_next; + char8_t* to_next; + + codecvt_c32::state_type state01; + state01 = {}; + codecvt_base::result res = cvt->out(state01, u32dat, u32dat_end, from_next, + buffer, buffer_end, to_next); + + VERIFY(res == codecvt_base::ok); + VERIFY(from_next == u32dat_end); + VERIFY(std::memcmp((void*)buffer, (void*)u8dat, sizeof(u8dat)) == 0); + + delete[] buffer; + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/utf8-char8_t.cc b/libstdc++-v3/testsuite/22_locale/codecvt/utf8-char8_t.cc new file mode 100644 index 0000000..62df461 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/codecvt/utf8-char8_t.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2015-2017 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-do run { target c++11 } } +// { dg-require-cstdint "" } +// { dg-options "-fchar8_t" } + +#include <locale> +#include <iterator> +#include <string> +#include <testsuite_hooks.h> + +const char8_t expected[] = u8"£¥€"; +const std::size_t expected_len = std::char_traits<char8_t>::length(expected); + +template<typename C> +void test(const C* from) +{ + auto len = std::char_traits<C>::length(from); + std::mbstate_t state{}; + char8_t buf[16] = { }; + using test_type = std::codecvt<C, char8_t, std::mbstate_t>; + const test_type& cvt = std::use_facet<test_type>(std::locale::classic()); + auto from_end = from + len; + auto from_next = from; + auto buf_end = std::end(buf); + auto buf_next = buf; + auto res = cvt.out(state, from, from_end, from_next, buf, buf_end, buf_next); + VERIFY( res == std::codecvt_base::ok ); + VERIFY( from_next == from_end ); + VERIFY( (buf_next - buf) == expected_len ); + VERIFY( 0 == std::char_traits<char8_t>::compare(buf, expected, expected_len) ); + + C buf2[16]; + auto exp_end = expected + expected_len; + auto exp_next = expected; + auto buf2_end = std::end(buf2); + auto buf2_next = buf2; + res = cvt.in(state, expected, exp_end, exp_next, buf2, buf2_end, buf2_next); + VERIFY( res == std::codecvt_base::ok ); + VERIFY( exp_next == exp_end ); + VERIFY( (buf2_next - buf2) == len ); + VERIFY( 0 == std::char_traits<C>::compare(buf2, from, len) ); +} + +void +test01() +{ + test(u"£¥€"); +} + +void +test02() +{ + test(U"£¥€"); +} + +int +main() +{ + test01(); + test02(); +} |