|
1 /* |
|
2 * Copyright (c) 1997-2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 #include <e32std.h> |
|
26 #include <e32test.h> |
|
27 #include <utf.h> |
|
28 |
|
29 /////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
31 RTest TheTest(_L("TSimple8")); |
|
32 |
|
33 /////////////////////////////////////////////////////////////////////////////////////// |
|
34 /////////////////////////////////////////////////////////////////////////////////////// |
|
35 //Tests macroses and functions. |
|
36 //If (!aValue) then the test will be panicked, the test data files will be deleted. |
|
37 static void Check(TInt aValue, TInt aLine) |
|
38 { |
|
39 if(!aValue) |
|
40 { |
|
41 TheTest(EFalse, aLine); |
|
42 } |
|
43 } |
|
44 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted. |
|
45 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
46 { |
|
47 if(aValue != aExpected) |
|
48 { |
|
49 TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
50 TheTest(EFalse, aLine); |
|
51 } |
|
52 } |
|
53 //Use these to test conditions. |
|
54 #define TEST(arg) ::Check((arg), __LINE__) |
|
55 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
56 |
|
57 /////////////////////////////////////////////////////////////////////////////////////// |
|
58 /////////////////////////////////////////////////////////////////////////////////////// |
|
59 /** |
|
60 @SYMTestCaseID SYSLIB-CHARCONV-CT-0563 |
|
61 @SYMTestCaseDesc Conversion tests from Unicode to UTF-8 character set |
|
62 @SYMTestPriority Medium |
|
63 @SYMTestActions Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8(), |
|
64 CnvUtfConverter::ConvertToUnicodeFromUtf8L() function |
|
65 @SYMTestExpectedResults Test must not fail |
|
66 @SYMREQ REQ0000 |
|
67 */ |
|
68 LOCAL_C void DoE32MainL() |
|
69 { |
|
70 TheTest.Start(_L("Testing simple UTF-8 round trips")); |
|
71 TBuf16<256> originalUnicode; |
|
72 TBuf8<256> generatedUtf8; |
|
73 TBuf16<256> generatedUnicode; |
|
74 // |
|
75 TheTest.Next(_L("Empty descriptor")); |
|
76 originalUnicode=_L16(""); |
|
77 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0); |
|
78 TEST(generatedUtf8==_L8("")); |
|
79 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0); |
|
80 TEST(generatedUnicode==originalUnicode); |
|
81 // Testing the new API |
|
82 HBufC8* testbuffer8; |
|
83 HBufC* testbuffer; |
|
84 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode); |
|
85 TPtr8 comparebuffer8 = testbuffer8->Des(); |
|
86 TEST(comparebuffer8==generatedUtf8); |
|
87 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8); |
|
88 TPtr compareBuffer = testbuffer->Des(); |
|
89 TEST(compareBuffer == originalUnicode); |
|
90 delete testbuffer8; |
|
91 delete testbuffer; |
|
92 |
|
93 TheTest.Next(_L("English \"Hello!\"")); |
|
94 originalUnicode=_L16("Hello!"); |
|
95 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0); |
|
96 TEST(generatedUtf8==_L8("Hello!")); |
|
97 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0); |
|
98 TEST(generatedUnicode==originalUnicode); |
|
99 // Testing the new API |
|
100 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode); |
|
101 comparebuffer8.Set(testbuffer8->Des()); |
|
102 TEST(comparebuffer8==generatedUtf8); |
|
103 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8); |
|
104 compareBuffer.Set(testbuffer->Des()); |
|
105 TEST(compareBuffer == originalUnicode); |
|
106 delete testbuffer8; |
|
107 delete testbuffer; |
|
108 |
|
109 TheTest.Next(_L("Russian \"Hello!\"")); |
|
110 originalUnicode.Format(_L16("%c%c%c%c%c%c%c%c%c%c%c%c%c"), 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, 0x0439, 0x0442, 0x0435, 0x0021); |
|
111 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0); |
|
112 TEST(generatedUtf8==_L8("\xd0\x97\xd0\xb4\xd1\x80\xd0\xb0\xd0\xb2\xd1\x81\xd1\x82\xd0\xb2\xd1\x83\xd0\xb9\xd1\x82\xd0\xb5\x21")); |
|
113 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0); |
|
114 TEST(generatedUnicode==originalUnicode); |
|
115 // Testing the new API |
|
116 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode); |
|
117 comparebuffer8.Set(testbuffer8->Des()); |
|
118 TEST(comparebuffer8==generatedUtf8); |
|
119 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8); |
|
120 compareBuffer.Set(testbuffer->Des()); |
|
121 TEST(compareBuffer == originalUnicode); |
|
122 delete testbuffer8; |
|
123 delete testbuffer; |
|
124 |
|
125 TheTest.Next(_L("Greek \"Hello!\"")); |
|
126 originalUnicode.Format(_L16("%c%c%c%c%c%c"), 0x0393, 0x03b1, 0x03c3, 0x03bf, 0x03c5, 0x0021); |
|
127 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0); |
|
128 TEST(generatedUtf8==_L8("\xce\x93\xce\xb1\xcf\x83\xce\xbf\xcf\x85\x21")); |
|
129 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0); |
|
130 TEST(generatedUnicode==originalUnicode); |
|
131 // Testing the new API |
|
132 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode); |
|
133 comparebuffer8.Set(testbuffer8->Des()); |
|
134 TEST(comparebuffer8==generatedUtf8); |
|
135 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8); |
|
136 compareBuffer.Set(testbuffer->Des()); |
|
137 TEST(compareBuffer == originalUnicode); |
|
138 delete testbuffer8; |
|
139 delete testbuffer; |
|
140 |
|
141 TheTest.Next(_L("Chinese \"Hello!\"")); |
|
142 originalUnicode.Format(_L16("%c%c%c"), 0x4f60, 0x597d, 0x0021); |
|
143 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0); |
|
144 TEST(generatedUtf8==_L8("\xe4\xbd\xa0\xe5\xa5\xbd\x21")); |
|
145 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0); |
|
146 TEST(generatedUnicode==originalUnicode); |
|
147 // Testing the new API |
|
148 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode); |
|
149 comparebuffer8.Set(testbuffer8->Des()); |
|
150 TEST(comparebuffer8==generatedUtf8); |
|
151 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8); |
|
152 compareBuffer.Set(testbuffer->Des()); |
|
153 TEST(compareBuffer == originalUnicode); |
|
154 delete testbuffer8; |
|
155 delete testbuffer; |
|
156 |
|
157 TheTest.Next(_L("Japanese \"Hello!\"")); |
|
158 originalUnicode.Format(_L16("%c%c%c%c"), 0x4eca, 0x65e5, 0x306f, 0x0021); |
|
159 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0); |
|
160 TEST(generatedUtf8==_L8("\xe4\xbb\x8a\xe6\x97\xa5\xe3\x81\xaf\x21")); |
|
161 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0); |
|
162 TEST(generatedUnicode==originalUnicode); |
|
163 // Testing the new API |
|
164 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode); |
|
165 comparebuffer8.Set(testbuffer8->Des()); |
|
166 TEST(comparebuffer8==generatedUtf8); |
|
167 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8); |
|
168 compareBuffer.Set(testbuffer->Des()); |
|
169 TEST(compareBuffer == originalUnicode); |
|
170 delete testbuffer8; |
|
171 delete testbuffer; |
|
172 } |
|
173 |
|
174 GLDEF_C TInt E32Main() |
|
175 { |
|
176 __UHEAP_MARK; |
|
177 |
|
178 TheTest.Title(); |
|
179 |
|
180 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
181 TEST(trapCleanup != NULL); |
|
182 |
|
183 TRAPD(error, DoE32MainL()); |
|
184 TEST2(error, KErrNone); |
|
185 |
|
186 delete trapCleanup; |
|
187 |
|
188 TheTest.End(); |
|
189 TheTest.Close(); |
|
190 |
|
191 __UHEAP_MARKEND; |
|
192 return KErrNone; |
|
193 } |
|
194 |