From 94bfe8d2d3f2cc84f41cad0ec33c419a2fdf2f8b Mon Sep 17 00:00:00 2001 From: ntrifunovic Date: Sat, 26 Sep 2009 01:13:26 +0000 Subject: [PATCH] Added a regression test to detect a sequence of multiple trail surrogate code units git-svn-id: http://svn.code.sf.net/p/utfcpp/code@99 a809a056-fc17-0410-9590-b4f493f8b08e Conflicts: v2_0/test_drivers/regression_tests/reg_tests_driver.cpp --- .../r2_2_2/basic_functionality.h | 24 +++++++++++++++++++ .../regression_tests/reg_tests_driver.cpp | 8 ++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100755 test_drivers/regression_tests/r2_2_2/basic_functionality.h diff --git a/test_drivers/regression_tests/r2_2_2/basic_functionality.h b/test_drivers/regression_tests/r2_2_2/basic_functionality.h new file mode 100755 index 0000000..f6315cd --- /dev/null +++ b/test_drivers/regression_tests/r2_2_2/basic_functionality.h @@ -0,0 +1,24 @@ +#include "../../../source/utf8.h" +using namespace utf8; + +// [ 2852872 ] invalid utf16 strings were parsed without any error +void id_2852872() +{ + const unsigned short two_trail_surrogates[] = {0xdd00, 0xdd01, 0}; + vector utf8_result; + try + { + utf8::utf16to8(two_trail_surrogates, two_trail_surrogates+2, back_inserter(utf8_result)); + // should throw in the previous line and never get here + check(false); + } + catch(utf8::invalid_utf16&) + { + // this is what we expect + } + catch(...) + { + // an unexpected exception happened + check(false); + } +} diff --git a/test_drivers/regression_tests/reg_tests_driver.cpp b/test_drivers/regression_tests/reg_tests_driver.cpp index 19a5ac3..b7e023a 100644 --- a/test_drivers/regression_tests/reg_tests_driver.cpp +++ b/test_drivers/regression_tests/reg_tests_driver.cpp @@ -1,4 +1,5 @@ #include +#include using namespace std; inline void check_impl (bool condition, const char* file, int line) @@ -18,7 +19,8 @@ inline void check_impl (bool condition, const char* file, int line) // Release 1.0 Beta 3 #include "r1_0Beta3/basic_functionality.h" - +// Release 2.2.2 +#include "r2_2_2/basic_functionality.h" int main() { @@ -37,4 +39,8 @@ int main() // Release 1.0 Beta 3 //r1_0Beta3/basic_functionality.h id_1538338(); + +// Release 2.2.2 +//r2_2_2/basic_functionality.h + id_2852872(); }