1//
2// UnicodeConverterTest.h
3//
4// Definition of the UnicodeConverterTest class.
5//
6// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
7// and Contributors.
8//
9// SPDX-License-Identifier: BSL-1.0
10//
11
12
13#ifndef UnicodeConverterTest_INCLUDED
14#define UnicodeConverterTest_INCLUDED
15
16
17#include "Poco/Foundation.h"
18#include "Poco/CppUnit/TestCase.h"
19#include "Poco/UnicodeConverter.h"
20#include "Poco/UTFString.h"
21#include <cstring>
22
23
24class UnicodeConverterTest: public CppUnit::TestCase
25{
26public:
27 UnicodeConverterTest(const std::string& name);
28 ~UnicodeConverterTest();
29
30 void testUTF16();
31 void testUTF32();
32
33 void setUp();
34 void tearDown();
35
36 static CppUnit::Test* suite();
37
38private:
39 template <typename T>
40 void runTests()
41 {
42 const unsigned char supp[] = {0x41, 0x42, 0xf0, 0x90, 0x82, 0xa4, 0xf0, 0xaf, 0xa6, 0xa0, 0xf0, 0xaf, 0xa8, 0x9d, 0x00};
43 std::string text((const char*) supp);
44
45 // Convert from UTF-8 to wide
46 T wtext, wtext2, wtext3;
47 Poco::UnicodeConverter::convert(text, wtext);
48 if (sizeof(typename T::value_type) == 2)
49 assertTrue (Poco::UnicodeConverter::UTFStrlen(wtext.data()) == 8);
50 else if (sizeof(typename T::value_type) == 4)
51 assertTrue (Poco::UnicodeConverter::UTFStrlen(wtext.data()) == 5);
52 Poco::UnicodeConverter::convert((const char*) supp, strlen((const char*) supp), wtext2);
53 Poco::UnicodeConverter::convert((const char*)supp, wtext3);
54 assertTrue (wtext == wtext2);
55 assertTrue (wtext == wtext3);
56
57 std::string text2, text3, text4;
58 assertTrue (text != text2);
59 assertTrue (text != text3);
60 assertTrue (text != text4);
61
62 // Convert from wide to UTF-8
63 Poco::UnicodeConverter::convert(wtext, text2);
64 Poco::UnicodeConverter::convert(wtext2, text3);
65 Poco::UnicodeConverter::convert(wtext3, text4);
66
67 assertTrue (text == text2);
68 assertTrue (text == text3);
69 assertTrue (text == text4);
70 }
71};
72
73
74#endif // UnicodeConverterTest_INCLUDED
75