summaryrefslogtreecommitdiffhomepage
path: root/src/test-unicode.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2021-02-03 13:18:25 +0100
committerRoland Reichwein <mail@reichwein.it>2021-02-03 13:18:25 +0100
commit5572e23e8e2109abd73b916f4f0d278e1aa21f34 (patch)
treea31b61aa9381bef63be637b203ae6f030f33027d /src/test-unicode.cpp
parent9dfd49e5def7357c59f8bc676981f5466bdb2d2c (diff)
Add msbuild files
Diffstat (limited to 'src/test-unicode.cpp')
-rw-r--r--src/test-unicode.cpp47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/test-unicode.cpp b/src/test-unicode.cpp
index e1aa23d..c169fc9 100644
--- a/src/test-unicode.cpp
+++ b/src/test-unicode.cpp
@@ -35,11 +35,13 @@ std::vector<types_collection_type> success_sets {
// Error cases: throwing upon convert to all other types
std::vector<std::basic_string<utf8_t>> failure_strings_char8_t {
- u8"\x80", // utf-8 continuation byte
- u8"\x81", // utf-8 continuation byte
- u8"\xc3\xc3\xa4", // initial byte of utf-8 "ä", followed by valid utf-8 "ä"
- u8"\xF8\x80\x80\x80\x80", // overlong encoding
- u8"\xF7\xBF\xBF\xBF", // valid encoding of invalid code point
+ // Note: don't encode this as u8"" since MSVC will interpret \x80 as \u0080,
+// yet to be encoded to UTF-8 for execution encoding
+ "\x80", // utf-8 continuation byte
+ "\x81", // utf-8 continuation byte
+ "\xc3\xc3\xa4", // initial byte of utf-8 "ä", followed by valid utf-8 "ä"
+ "\xF8\x80\x80\x80\x80", // overlong encoding
+ "\xF7\xBF\xBF\xBF", // valid encoding of invalid code point
};
std::vector<std::basic_string<char16_t>> failure_strings_char16_t {
@@ -156,16 +158,20 @@ void test_utf_to_utf_failure(std::basic_string<From>& s)
try {
(void) unicode::convert<From,To>(s);
BOOST_ERROR("Base: Expected exception at index: " << index << ", " << typeid(From).name() << " -> " << typeid(To).name());
- } catch (...) {
- // OK
+ } catch (const std::invalid_argument&) {
+ // OK: this is an expected exception for convert() on bad input
+ } catch (const std::exception& ex) {
+ BOOST_ERROR("Unexpected error on convert(): " << ex.what());
};
// via facet
try {
(void) unicode::convert<typename unicode::Encoding<From>::Facet,typename unicode::Encoding<To>::Facet>(s);
BOOST_ERROR("Facet: Expected exception at index: " << index << ", " << typeid(From).name() << " -> " << typeid(To).name());
- } catch (...) {
- // OK
+ } catch (const std::invalid_argument&) {
+ // OK: this is an expected exception for convert() on bad input
+ } catch (const std::exception& ex) {
+ BOOST_ERROR("Unexpected error on convert(): " << ex.what());
};
// iterate over remaining types
@@ -229,15 +235,16 @@ BOOST_AUTO_TEST_CASE(is_valid_unicode)
struct random_context {
std::random_device rd; // OS random number engine to seed RNG (below)
std::mt19937 gen{rd()};
- std::uniform_int_distribution<> sequence_length{0, 100000}; // length of sequence: 0 ... 100000 code units
+ std::uniform_int_distribution<size_t> sequence_length{0, 100000}; // length of sequence: 0 ... 100000 code units
};
template<typename T>
T generate_random(random_context& rc, size_t length)
{
- std::uniform_int_distribution<> code_unit(0, std::numeric_limits<typename T::value_type>::max()); // code unit value
+ // Using unsigned long for std::uniform_int_distribution<> because it needs to be basic type according to MSVC
+ std::uniform_int_distribution<unsigned long> code_unit(std::numeric_limits<typename T::value_type>::max()); // code unit value
T result;
- std::generate_n(std::back_inserter(result), length, [&](){return code_unit(rc.gen);});
+ std::generate_n(std::back_inserter(result), length, [&](){return static_cast<typename T::value_type>(code_unit(rc.gen));});
return result;
}
@@ -248,7 +255,7 @@ void test_random(random_context& rc, size_t length)
//std::cerr << "LENGTH: " << length << std::endl;
typedef typename std::tuple_element<i,ToTypesCollectionType>::type To;
- From r {generate_random<From>(rc, length)};
+ From r {static_cast<From>(generate_random<From>(rc, length))};
// base type interface
try {
@@ -259,10 +266,10 @@ void test_random(random_context& rc, size_t length)
} else {
BOOST_CHECK(!result.empty());
}
- } catch (const std::runtime_error&) {
- // OK: this is an expected exception for utf_to_utf on bad input
} catch (const std::invalid_argument&) {
- // OK: this is an expected exception for utf_to_utf on bad input
+ // OK: this is an expected exception for convert() on bad input
+ } catch (const std::exception& ex) {
+ BOOST_ERROR("Unexpected error on convert(): " << ex.what());
}
// facet interface
@@ -274,13 +281,11 @@ void test_random(random_context& rc, size_t length)
} else {
BOOST_CHECK(!result.empty());
}
- } catch (const std::runtime_error&) {
- // OK: this is an expected exception for utf_to_utf on bad input
} catch (const std::invalid_argument&) {
- // OK: this is an expected exception for utf_to_utf on bad input
+ // OK: this is an expected exception for convert() on bad input
+ } catch (const std::exception& ex) {
+ BOOST_ERROR("Unexpected error on convert(): " << ex.what());
}
- //std::cerr << "DEBUG: " << typeid(From).name() << std::endl;
- //std::cerr << " DEBUG2: " << typeid(To).name() << std::endl;
// iterate over remaining To types
if constexpr (i + 1 < std::tuple_size<ToTypesCollectionType>::value)