summaryrefslogtreecommitdiff
path: root/cpp/test
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2014-05-15 16:00:06 -0400
committerBernard Normier <bernard@zeroc.com>2014-05-15 16:00:06 -0400
commitd8fe24d5c280459780af492af6a20d2f647031c9 (patch)
treee4ba306b38e24ea7c9b259463f08cb5f474616a4 /cpp/test
parentSimplified bi-dir demo (diff)
downloadice-d8fe24d5c280459780af492af6a20d2f647031c9.tar.bz2
ice-d8fe24d5c280459780af492af6a20d2f647031c9.tar.xz
ice-d8fe24d5c280459780af492af6a20d2f647031c9.zip
Fixed ICE-710: error handling test for Unicode functions
Diffstat (limited to 'cpp/test')
-rw-r--r--cpp/test/IceUtil/unicode/Client.cpp56
1 files changed, 55 insertions, 1 deletions
diff --git a/cpp/test/IceUtil/unicode/Client.cpp b/cpp/test/IceUtil/unicode/Client.cpp
index 94f568ff334..63c2658dc32 100644
--- a/cpp/test/IceUtil/unicode/Client.cpp
+++ b/cpp/test/IceUtil/unicode/Client.cpp
@@ -128,7 +128,7 @@ main(int argc, char* argv[])
}
{
- cout << "wstring (" << wstringEncoding << ") to UTF-8 conversion... ";
+ cout << "testing wstring (" << wstringEncoding << ") to UTF-8 conversion... ";
IceUtilInternal::ifstream bis((dir + wcoeurFile), ios_base::binary);
test(bis.good());
@@ -183,6 +183,60 @@ main(int argc, char* argv[])
cout << "ok" << endl;
}
+ {
+ cout << "testing error handling... ";
+
+ // From http://stackoverflow.com/questions/1301402/example-invalid-utf8-string
+
+ string badUTF8[] = {
+ "\xc3\x28",
+ "\xa0\xa1",
+ "\xe2\x28\xa1",
+ "\xe2\x82\x28",
+ "\xf0\x28\x8c\xbc",
+ "\xf0\x90\x28\xbc",
+ "\xf0\x28\x8c\x28",
+ "\xf8\xa1\xa1\xa1\xa1",
+ "\xfc\xa1\xa1\xa1\xa1\xa1",
+ ""
+ };
+
+ for(size_t i = 0; badUTF8[i] != ""; ++i)
+ {
+ test(isLegalUTF8Sequence(reinterpret_cast<const Byte*>(badUTF8[i].data()),
+ reinterpret_cast<const Byte*>(badUTF8[i].data() + badUTF8[i].size())) == false);
+
+ try
+ {
+ wstring ws = IceUtil::nativeToWnative(0, 0, badUTF8[i]);
+ test(false);
+ }
+ catch(const IceUtil::UTFConversionException&)
+ {}
+ }
+
+ wstring badWstring[] = {
+ wstring(1, wchar_t(0xD800)),
+ wstring(2, wchar_t(0xDB7F)),
+ L""
+ };
+
+ for(size_t i = 0; badWstring[i] != L""; ++i)
+ {
+ try
+ {
+ string s = IceUtil::wnativeToNative(0, 0, badWstring[i]);
+ test(false);
+ }
+ catch(const IceUtil::UTFConversionException&)
+ {}
+ }
+
+ cout << "ok" << endl;
+
+ }
+
+
#ifndef __MINGW32__
{
cout << "testing UTF-8 filename... ";