1 | // |
2 | // DoubleByteEncodingTest.cpp |
3 | // |
4 | // Copyright (c) 2018, Applied Informatics Software Engineering GmbH. |
5 | // and Contributors. |
6 | // |
7 | // SPDX-License-Identifier: Apache-2.0 |
8 | // |
9 | |
10 | |
11 | #include "DoubleByteEncodingTest.h" |
12 | #include "Poco/CppUnit/TestCaller.h" |
13 | #include "Poco/CppUnit/TestSuite.h" |
14 | #include "Poco/ISO8859_4Encoding.h" |
15 | #include "Poco/Windows950Encoding.h" |
16 | |
17 | |
18 | DoubleByteEncodingTest::DoubleByteEncodingTest(const std::string& name): CppUnit::TestCase(name) |
19 | { |
20 | } |
21 | |
22 | |
23 | DoubleByteEncodingTest::~DoubleByteEncodingTest() |
24 | { |
25 | } |
26 | |
27 | |
28 | void DoubleByteEncodingTest::testSingleByte() |
29 | { |
30 | Poco::ISO8859_4Encoding enc; |
31 | |
32 | assertTrue (std::string(enc.canonicalName()) == "ISO-8859-4" ); |
33 | assertTrue (enc.isA("Latin4" )); |
34 | |
35 | unsigned char seq1[] = { 0xF8 }; // 0x00F8 LATIN SMALL LETTER O WITH STROKE |
36 | assertTrue (enc.convert(seq1) == 0x00F8); |
37 | assertTrue (enc.queryConvert(seq1, 1) == 0x00F8); |
38 | assertTrue (enc.sequenceLength(seq1, 1) == 1); |
39 | |
40 | unsigned char seq2[] = { 0xF9 }; // 0x0173 LATIN SMALL LETTER U WITH OGONEK |
41 | assertTrue (enc.convert(seq2) == 0x0173); |
42 | assertTrue (enc.queryConvert(seq2, 1) == 0x0173); |
43 | assertTrue (enc.sequenceLength(seq2, 1) == 1); |
44 | } |
45 | |
46 | |
47 | void DoubleByteEncodingTest::testSingleByteReverse() |
48 | { |
49 | Poco::ISO8859_4Encoding enc; |
50 | |
51 | unsigned char seq[2]; |
52 | |
53 | assertTrue (enc.convert(0x00F8, seq, 2) == 1); |
54 | assertTrue (seq[0] == 0xF8); |
55 | |
56 | assertTrue (enc.convert(0x0173, seq, 2) == 1); |
57 | assertTrue (seq[0] == 0xF9); |
58 | |
59 | assertTrue (enc.convert(0x3000, seq, 2) == 0); |
60 | } |
61 | |
62 | |
63 | void DoubleByteEncodingTest::testDoubleByte() |
64 | { |
65 | Poco::Windows950Encoding enc; |
66 | |
67 | assertTrue (std::string(enc.canonicalName()) == "windows-950" ); |
68 | assertTrue (enc.isA("Windows-950" )); |
69 | assertTrue (enc.isA("cp950" )); |
70 | |
71 | unsigned char seq1[] = { 0x41 }; // 0x0041 LATIN CAPITAL LETTER A |
72 | assertTrue (enc.convert(seq1) == 0x0041); |
73 | assertTrue (enc.queryConvert(seq1, 1) == 0x0041); |
74 | assertTrue (enc.sequenceLength(seq1, 1) == 1); |
75 | |
76 | unsigned char seq2[] = { 0xA1, 0x40 }; // 0x3000 IDEOGRAPHIC SPACE |
77 | assertTrue (enc.convert(seq2) == 0x3000); |
78 | assertTrue (enc.queryConvert(seq2, 1) == -2); |
79 | assertTrue (enc.queryConvert(seq2, 2) == 0x3000); |
80 | assertTrue (enc.sequenceLength(seq2, 1) == 2); |
81 | assertTrue (enc.sequenceLength(seq2, 2) == 2); |
82 | |
83 | unsigned char seq3[] = { 0x92 }; // invalid |
84 | assertTrue (enc.convert(seq3) == -1); |
85 | assertTrue (enc.queryConvert(seq3, 1) == -1); |
86 | assertTrue (enc.sequenceLength(seq3, 1) == -1); |
87 | } |
88 | |
89 | |
90 | void DoubleByteEncodingTest::testDoubleByteReverse() |
91 | { |
92 | Poco::Windows950Encoding enc; |
93 | |
94 | unsigned char seq[2]; |
95 | |
96 | assertTrue (enc.convert(0x0041, seq, 2) == 1); |
97 | assertTrue (seq[0] == 0x41); |
98 | |
99 | assertTrue (enc.convert(0x3000, seq, 2) == 2); |
100 | assertTrue (seq[0] == 0xA1); |
101 | assertTrue (seq[1] == 0x40); |
102 | |
103 | assertTrue (enc.convert(0x3004, seq, 2) == 0); |
104 | } |
105 | |
106 | |
107 | void DoubleByteEncodingTest::setUp() |
108 | { |
109 | } |
110 | |
111 | |
112 | void DoubleByteEncodingTest::tearDown() |
113 | { |
114 | } |
115 | |
116 | |
117 | CppUnit::Test* DoubleByteEncodingTest::suite() |
118 | { |
119 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DoubleByteEncodingTest" ); |
120 | |
121 | CppUnit_addTest(pSuite, DoubleByteEncodingTest, testSingleByte); |
122 | CppUnit_addTest(pSuite, DoubleByteEncodingTest, testSingleByteReverse); |
123 | CppUnit_addTest(pSuite, DoubleByteEncodingTest, testDoubleByte); |
124 | CppUnit_addTest(pSuite, DoubleByteEncodingTest, testDoubleByteReverse); |
125 | |
126 | return pSuite; |
127 | } |
128 | |