From 5ad6e853eaee2533f934575b8509e0e0c5da12e5 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Thu, 6 Jan 2022 11:44:40 +0100 Subject: Type corrections --- src/test-performance.cpp | 2 +- src/test-unicode.cpp | 64 +++++++++++++++++++++++++----------------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/test-performance.cpp b/src/test-performance.cpp index 64535c6..90397b7 100644 --- a/src/test-performance.cpp +++ b/src/test-performance.cpp @@ -54,7 +54,7 @@ T generate_value(T max = std::numeric_limits::max()) uint32_t value{}; do { - for (int i = 0; i < sizeof(value); ++i) { + for (size_t i = 0; i < sizeof(value); ++i) { value = (value << 8) | generate_byte(); } } while (static_cast(value) >= max_modulo); diff --git a/src/test-unicode.cpp b/src/test-unicode.cpp index aebc644..948dbcc 100644 --- a/src/test-unicode.cpp +++ b/src/test-unicode.cpp @@ -681,7 +681,7 @@ BOOST_AUTO_TEST_CASE(exceptions) { // UTF-32: Invalid value std::vector x{(char32_t)U'\xFFFFFFFF'}; try { - auto result{unicode::convert,std::vector>(x)}; + auto result{unicode::convert,std::vector>(x)}; BOOST_FAIL("Expected boost convert to fail"); } catch (const std::invalid_argument& ex) { BOOST_CHECK_EQUAL("Invalid Unicode character: 4294967295"s, ex.what()); @@ -751,40 +751,44 @@ BOOST_AUTO_TEST_CASE(exceptions) } #if defined(_WIN32) || defined(__linux__) - { // Optimization: UTF-8 decoding invalid Unicode value in 3 byte sequence - std::basic_string x{(utf8_t*)"\xED\xA0\x80 aaa"}; - try { - auto result{unicode::convert(x)}; - BOOST_FAIL("Expected boost convert to fail"); - } catch (const std::invalid_argument& ex) { - BOOST_CHECK_EQUAL("Invalid Unicode character in 3 byte UTF-8 sequence"s, ex.what()); - } catch (...) { - BOOST_ERROR("Unexpected error on convert"); + if constexpr (sizeof(size_t) == 8) { + + { // Optimization: UTF-8 decoding invalid Unicode value in 3 byte sequence + std::basic_string x{(utf8_t*)"\xED\xA0\x80 aaa"}; + try { + auto result{unicode::convert(x)}; + BOOST_FAIL("Expected boost convert to fail"); + } catch (const std::invalid_argument& ex) { + BOOST_CHECK_EQUAL("Invalid Unicode character in 3 byte UTF-8 sequence"s, ex.what()); + } catch (...) { + BOOST_ERROR("Unexpected error on convert"); + } } - } - { // Optimization: UTF-8 decoding invalid Unicode value in 4 byte sequence - std::basic_string x{(utf8_t*)"\xF7\xBF\xBF\xBF aaa"}; - try { - auto result{unicode::convert(x)}; - BOOST_FAIL("Expected boost convert to fail"); - } catch (const std::invalid_argument& ex) { - BOOST_CHECK_EQUAL("Invalid Unicode character in 4 byte UTF-8 sequence"s, ex.what()); - } catch (...) { - BOOST_ERROR("Unexpected error on convert"); + { // Optimization: UTF-8 decoding invalid Unicode value in 4 byte sequence + std::basic_string x{(utf8_t*)"\xF7\xBF\xBF\xBF aaa"}; + try { + auto result{unicode::convert(x)}; + BOOST_FAIL("Expected boost convert to fail"); + } catch (const std::invalid_argument& ex) { + BOOST_CHECK_EQUAL("Invalid Unicode character in 4 byte UTF-8 sequence"s, ex.what()); + } catch (...) { + BOOST_ERROR("Unexpected error on convert"); + } } - } - { // Optimization: UTF-8 decoding invalid byte sequence - std::basic_string x{(utf8_t*)"\xC0 aabbbb"}; - try { - auto result{unicode::convert(x)}; - BOOST_FAIL("Expected boost convert to fail"); - } catch (const std::invalid_argument& ex) { - BOOST_CHECK_EQUAL("Invalid UTF-8 byte sequence"s, ex.what()); - } catch (...) { - BOOST_ERROR("Unexpected error on convert"); + { // Optimization: UTF-8 decoding invalid byte sequence + std::basic_string x{(utf8_t*)"\xC0 aabbbb"}; + try { + auto result{unicode::convert(x)}; + BOOST_FAIL("Expected boost convert to fail"); + } catch (const std::invalid_argument& ex) { + BOOST_CHECK_EQUAL("Invalid UTF-8 byte sequence"s, ex.what()); + } catch (...) { + BOOST_ERROR("Unexpected error on convert"); + } } + } #endif -- cgit v1.2.3