summaryrefslogtreecommitdiffhomepage
path: root/src/test-unicode.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2021-12-22 14:17:56 +0100
committerRoland Reichwein <mail@reichwein.it>2021-12-22 14:17:56 +0100
commitcd7e832e2f47fa35d36794808582118cb34eca3f (patch)
treeb30ac429297d08670c0a28c071e4881dc723dba0 /src/test-unicode.cpp
parent65c8f3fa5856b216816a25c2d3dc9d87bd3896ee (diff)
Added tests
Diffstat (limited to 'src/test-unicode.cpp')
-rw-r--r--src/test-unicode.cpp64
1 files changed, 61 insertions, 3 deletions
diff --git a/src/test-unicode.cpp b/src/test-unicode.cpp
index c325f6c..59d55b9 100644
--- a/src/test-unicode.cpp
+++ b/src/test-unicode.cpp
@@ -384,7 +384,9 @@ namespace {
template<>
std::basic_string<utf8_t> std_convert<utf8_t, utf8_t>(const std::basic_string<utf8_t>& s)
{
- return s;
+ std::string a{s.begin(), s.end()};
+ a = conv32.to_bytes(conv32.from_bytes(a));
+ return std::basic_string<utf8_t>{a.begin(), a.end()};
}
template<>
@@ -411,7 +413,7 @@ namespace {
template<>
std::basic_string<char16_t> std_convert<char16_t, char16_t>(const std::basic_string<char16_t>& s)
{
- return s;
+ return conv16.from_bytes(conv16.to_bytes(s));
}
template<>
@@ -436,7 +438,7 @@ namespace {
template<>
std::basic_string<char32_t> std_convert<char32_t, char32_t>(const std::basic_string<char32_t>& s)
{
- return s;
+ return conv32.from_bytes(conv32.to_bytes(s));
}
}
@@ -459,6 +461,8 @@ void test_random_valid(random_context& rc, size_t length, const std::string& des
BOOST_CHECK(list[i].size() >= u32list[i].size());
To result{unicode::convert<typename unicode::Encoding<typename From::value_type>::Facet,typename unicode::Encoding<typename To::value_type>::Facet>(list[i])};
BOOST_CHECK(result.size() >= u32list[i].size());
+ auto boost_result{boost::locale::conv::utf_to_utf<typename To::value_type, typename From::value_type>(list[i])};
+ BOOST_CHECK_EQUAL(result, boost_result);
}
{
@@ -609,3 +613,57 @@ BOOST_AUTO_TEST_CASE(string_u8string)
BOOST_CHECK(a == std::string{"\xc3\xa4"});
}
+
+// check environment: demonstrate how boost convert u8->u8 throws exception on invalid input
+BOOST_AUTO_TEST_CASE(utf_to_utf_failure_boost_u8_u8)
+{
+ for (auto& s: failure_strings_char8_t) {
+ try {
+ auto result1{boost::locale::conv::utf_to_utf<utf8_t, utf8_t>(s, boost::locale::conv::stop)};
+ BOOST_FAIL("Expected boost convert to fail");
+ } catch(...) {
+ // expected
+ }
+ }
+}
+
+// check environment: demonstrate how boost convert u8->u16 throws exception on invalid input
+BOOST_AUTO_TEST_CASE(utf_to_utf_failure_boost_u8_u16)
+{
+ for (auto& s: failure_strings_char8_t) {
+ try {
+ auto result1{boost::locale::conv::utf_to_utf<char16_t, utf8_t>(s, boost::locale::conv::stop)};
+ BOOST_FAIL("Expected boost convert to fail");
+ } catch(...) {
+ // expected
+ }
+ }
+}
+
+// check environment: demonstrate how std u8->u8 throws exception on invalid input
+BOOST_AUTO_TEST_CASE(utf_to_utf_failure_std_u8_u8)
+{
+ for (auto& s: failure_strings_char8_t) {
+ try {
+ auto result2{std_convert<utf8_t, utf8_t>(s)};
+ BOOST_FAIL("Expected std_convert to fail");
+ } catch(...) {
+ // expected
+ }
+
+ }
+}
+
+// check environment: demonstrate how std u8->u16 throws exception on invalid input
+BOOST_AUTO_TEST_CASE(utf_to_utf_failure_std_u8_u16)
+{
+ for (auto& s: failure_strings_char8_t) {
+ try {
+ auto result2{std_convert<utf8_t, char16_t>(s)};
+ BOOST_FAIL("Expected std_convert to fail");
+ } catch(...) {
+ // expected
+ }
+
+ }
+}