|
1 /* |
|
2 * Copyright (c) 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 the License "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 <e32base.h> |
|
27 #include <e32test.h> |
|
28 #include <f32file.h> |
|
29 #include <charconv.h> |
|
30 |
|
31 /////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
33 RTest TheTest(_L("TUCS2")); |
|
34 |
|
35 /////////////////////////////////////////////////////////////////////////////////////// |
|
36 /////////////////////////////////////////////////////////////////////////////////////// |
|
37 //Tests macroses and functions. |
|
38 //If (!aValue) then the test will be panicked, the test data files will be deleted. |
|
39 static void Check(TInt aValue, TInt aLine) |
|
40 { |
|
41 if(!aValue) |
|
42 { |
|
43 TheTest(EFalse, aLine); |
|
44 } |
|
45 } |
|
46 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted. |
|
47 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
48 { |
|
49 if(aValue != aExpected) |
|
50 { |
|
51 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
52 TheTest(EFalse, aLine); |
|
53 } |
|
54 } |
|
55 //Use these to test conditions. |
|
56 #define TEST(arg) ::Check((arg), __LINE__) |
|
57 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
58 |
|
59 /////////////////////////////////////////////////////////////////////////////////////// |
|
60 /////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
62 const TInt KMibValue = 1000; |
|
63 |
|
64 const TInt KBufferLength1=1; |
|
65 const TInt KBufferLength6=6; |
|
66 const TInt KBufferLength8=8; |
|
67 const TInt KBufferLength40=40; |
|
68 |
|
69 const TPtrC8 KForeignBufferEven12LE(_S8("\xff\xfe\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a")); |
|
70 const TPtrC8 KForeignBufferOdd13LE(_S8("\xff\xfe\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b")); |
|
71 const TPtrC8 KForeignBufferEven12BE(_S8("\xfe\xff\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49")); |
|
72 const TPtrC8 KForeignBufferOdd13BE(_S8("\xfe\xff\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4b")); |
|
73 |
|
74 const TPtrC8 KForeignBufferEvenWithoutBOM10LE(_S8("\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a")); |
|
75 const TPtrC8 KForeignBufferOddWithoutBOM11LE(_S8("\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b")); |
|
76 const TPtrC8 KForeignBufferEvenWithoutBOM10BE(_S8("\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49")); |
|
77 const TPtrC8 KForeignBufferOddWithoutBOM11BE(_S8("\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4b")); |
|
78 |
|
79 const TPtrC8 KForeignBufferEven24LE(_S8("\xff\xfe\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56")); |
|
80 const TPtrC8 KForeignBufferOdd25LE(_S8("\xff\xfe\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57")); |
|
81 const TPtrC8 KForeignBufferEven24BE(_S8("\xfe\xff\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4c\x4b\x4e\x4d\x50\x4f\x52\x51\x54\x53\x56\x55")); |
|
82 const TPtrC8 KForeignBufferOdd25BE(_S8("\xfe\xff\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4c\x4b\x4e\x4d\x50\x4f\x52\x51\x54\x53\x56\x55\x57")); |
|
83 |
|
84 const TPtrC8 KForeignBufferEvenWithoutBOM22LE(_S8("\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56")); |
|
85 const TPtrC8 KForeignBufferOddWithoutBOM23LE(_S8("\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57")); |
|
86 const TPtrC8 KForeignBufferEvenWithoutBOM22BE(_S8("\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4c\x4b\x4e\x4d\x50\x4f\x52\x51\x54\x53\x56\x55")); |
|
87 const TPtrC8 KForeignBufferOddWithoutBOM23BE(_S8("\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4c\x4b\x4e\x4d\x50\x4f\x52\x51\x54\x53\x56\x55\x57")); |
|
88 |
|
89 const TPtrC16 KUnicodeBufferEven14BE(_S16("\xfeff\x4142\x4344\x4546\x4748\x494a\x4b4c\x4d4e\x4f50\x5152\x5354\x5556\x5758\x595a")); |
|
90 const TPtrC16 KUnicodeBufferOdd15BE(_S16("\xfeff\x4142\x4344\x4546\x4748\x494a\x4b4c\x4d4e\x4f50\x5152\x5354\x5556\x5758\x595a\x5b5c")); |
|
91 |
|
92 /** |
|
93 @SYMTestCaseID SYSLIB-CHARCONV-CT-0553 |
|
94 @SYMTestCaseDesc 8 bit to UCS2 Little Endian Conversion - Single pass test |
|
95 @SYMTestPriority Medium |
|
96 @SYMTestActions Tests a 8 bit string to 16 bit UCS2 conversion. |
|
97 Test with and without Byte Order Mark. Byte Order Mark is set to Little Endian. |
|
98 Output buffer is large enough to contain the complete input string |
|
99 on a single pass |
|
100 @SYMTestExpectedResults Test must not fail |
|
101 @SYMREQ REQ0000 |
|
102 */ |
|
103 LOCAL_C void LEConversionSinglePassBOM(CCnvCharacterSetConverter& aCharacterSetConverter) |
|
104 { |
|
105 TBuf16<KBufferLength40> generatedUnicode; |
|
106 TInt state=CCnvCharacterSetConverter::KStateDefault; |
|
107 TInt numberOfUnconvertibleCharacters=0; |
|
108 TInt indexOfFirstByteOfFirstUnconvertibleCharacter=0; |
|
109 TInt numberLeft =0; |
|
110 |
|
111 // set the default endianness to little Endian |
|
112 aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::ELittleEndian); |
|
113 |
|
114 // test even number of foreign bytes |
|
115 aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven12LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
116 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49")); |
|
117 TEST(numberOfUnconvertibleCharacters==0); |
|
118 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
119 TheTest.Printf(_L("\nLittleEndianConversionSinglePassEvenBOM - OK")); |
|
120 |
|
121 // test even number of foreign bytes without BOM |
|
122 aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM10LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
123 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49")); |
|
124 TEST(numberOfUnconvertibleCharacters==0); |
|
125 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
126 TheTest.Printf(_L("\nLittleEndianConversionSinglePassEvenBOM - OK")); |
|
127 |
|
128 // test odd number of foreign bytes |
|
129 state=CCnvCharacterSetConverter::KStateDefault; |
|
130 numberLeft = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd13LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
131 TEST(numberLeft==1); |
|
132 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49")); |
|
133 TEST(numberOfUnconvertibleCharacters==0); |
|
134 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
135 |
|
136 // test odd number of foreign bytes without BOM |
|
137 numberLeft = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM11LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
138 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49")); |
|
139 TEST(numberLeft==1); |
|
140 TEST(numberOfUnconvertibleCharacters==0); |
|
141 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
142 |
|
143 TheTest.Printf(_L("\nLittleEndianConversionSinglePassOddBOM - OK")); |
|
144 } |
|
145 /** |
|
146 @SYMTestCaseID SYSLIB-CHARCONV-CT-0554 |
|
147 @SYMTestCaseDesc 8 bit to UCS2 Little Endian Conversion - Multiple pass test |
|
148 @SYMTestPriority Medium |
|
149 @SYMTestActions Tests a 8 bit string to 16 bit UCS2 conversion. |
|
150 With and without Byte Order Mark. Byte Order Mark is set to Little Endian. |
|
151 Output buffer is NOT large enough to contain the complete input string |
|
152 on a single pass. Multiple calls are made to complete translation. |
|
153 @SYMTestExpectedResults Test must not fail |
|
154 @SYMREQ REQ0000 |
|
155 */ |
|
156 LOCAL_C void LEConversionMultiplePassBOM(CCnvCharacterSetConverter& aCharacterSetConverter) |
|
157 { |
|
158 TBuf16<KBufferLength6> generatedUnicode; |
|
159 TInt state=CCnvCharacterSetConverter::KStateDefault; |
|
160 TInt numberOfUnconvertibleCharacters=0; |
|
161 TInt indexOfFirstByteOfFirstUnconvertibleCharacter=0; |
|
162 |
|
163 // set the default endianness to little Endian |
|
164 aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::ELittleEndian); |
|
165 |
|
166 // test even number of foreign bytes |
|
167 // first pass |
|
168 TInt numberUnconverted; |
|
169 numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven24LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
170 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b")); |
|
171 TEST(numberUnconverted==10); |
|
172 TEST(numberOfUnconvertibleCharacters==0); |
|
173 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
174 |
|
175 // test even number of foreign bytes without BOM |
|
176 numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM22LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
177 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b")); |
|
178 TEST(numberUnconverted==10); |
|
179 TEST(numberOfUnconvertibleCharacters==0); |
|
180 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
181 |
|
182 // second pass |
|
183 numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven24LE.Right(numberUnconverted), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
184 TEST(numberUnconverted==0); |
|
185 TEST(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655")); |
|
186 TEST(numberOfUnconvertibleCharacters==0); |
|
187 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
188 TheTest.Printf(_L("\nLittleEndianConversionMultiplePassOddEven - OK")); |
|
189 |
|
190 // without BOM |
|
191 numberOfUnconvertibleCharacters=10; |
|
192 aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM22LE.Right(numberOfUnconvertibleCharacters), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
193 TEST(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655")); |
|
194 TEST(numberOfUnconvertibleCharacters==0); |
|
195 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
196 TheTest.Printf(_L("\nLittleEndianConversionMultiplePassOddEven - OK")); |
|
197 |
|
198 |
|
199 // test odd number of foreign bytes |
|
200 // first pass |
|
201 state=CCnvCharacterSetConverter::KStateDefault; |
|
202 numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd25LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
203 TEST(numberUnconverted==11); |
|
204 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
205 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b")); |
|
206 |
|
207 // without BOM |
|
208 numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM23LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
209 TEST(numberUnconverted==11); |
|
210 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
211 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b")); |
|
212 |
|
213 // second pass |
|
214 numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd25LE.Right(numberUnconverted), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
215 TEST(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655")); |
|
216 TEST(numberUnconverted==1); |
|
217 TEST(numberOfUnconvertibleCharacters==0); |
|
218 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
219 |
|
220 // without BOM |
|
221 numberUnconverted = 11; |
|
222 numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM23LE.Right(numberUnconverted), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
223 TEST(numberUnconverted==1); |
|
224 TEST(numberOfUnconvertibleCharacters==0); |
|
225 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
226 TEST(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655")); |
|
227 |
|
228 |
|
229 TheTest.Printf(_L("\nLittleEndianConversionMultiplePassOddBOM - OK")); |
|
230 } |
|
231 /** |
|
232 @SYMTestCaseID SYSLIB-CHARCONV-CT-0555 |
|
233 @SYMTestCaseDesc 8 bit to UCS2 Big Endian Conversion - Single pass |
|
234 @SYMTestPriority Medium |
|
235 @SYMTestActions Tests a 8 bit string to 16 bit UCS2 conversion. |
|
236 With and without Byte Order Mark. Byte Order Mark is set to Big Endian. |
|
237 Output buffer is large enough to contain the complete input string |
|
238 on a single pass |
|
239 @SYMTestExpectedResults Test must not fail |
|
240 @SYMREQ REQ0000 |
|
241 */ |
|
242 LOCAL_C void BEConversionSinglePassBOM(CCnvCharacterSetConverter& aCharacterSetConverter) |
|
243 { |
|
244 TBuf16<KBufferLength40> generatedUnicode; |
|
245 TInt state=CCnvCharacterSetConverter::KStateDefault; |
|
246 TInt numberOfUnconvertibleCharacters=0; |
|
247 TInt indexOfFirstByteOfFirstUnconvertibleCharacter=0; |
|
248 TInt numberLeft=0; |
|
249 |
|
250 // set the default endianness to Big Endian |
|
251 aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian); |
|
252 |
|
253 // test even number of foreign bytes |
|
254 aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven12BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
255 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49")); |
|
256 TEST(numberOfUnconvertibleCharacters==0); |
|
257 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
258 TheTest.Printf(_L("\nBigEndianConversionSinglePassEvenBOM - OK")); |
|
259 |
|
260 // test even number of foreign bytes without BOM |
|
261 aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM10BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
262 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49")); |
|
263 TEST(numberOfUnconvertibleCharacters==0); |
|
264 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
265 TheTest.Printf(_L("\nBigEndianConversionSinglePassEvenBOM - OK")); |
|
266 |
|
267 |
|
268 // test odd number of foreign bytes |
|
269 state=CCnvCharacterSetConverter::KStateDefault; |
|
270 numberLeft = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd13BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
271 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49")); |
|
272 TEST(numberLeft==1); |
|
273 TEST(numberOfUnconvertibleCharacters==0); |
|
274 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
275 |
|
276 // test odd number of foreign bytes without BOM |
|
277 numberLeft = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM11BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
278 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49")); |
|
279 TEST(numberLeft==1); |
|
280 TEST(numberOfUnconvertibleCharacters==0); |
|
281 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
282 |
|
283 TheTest.Printf(_L("\nBigEndianConversionSinglePassOddBOM - OK")); |
|
284 } |
|
285 /** |
|
286 @SYMTestCaseID SYSLIB-CHARCONV-CT-0556 |
|
287 @SYMTestCaseDesc 8 bit to UCS2 Big Endian Conversion - Multiple pass test |
|
288 @SYMTestPriority Medium |
|
289 @SYMTestActions Tests a 8 bit string to 16 bit UCS2 conversion. |
|
290 With and without Byte Order Mark. Byte Order Mark is set to Big Endian. |
|
291 Output buffer is NOT large enough to contain the complete input string |
|
292 on a single pass. Multiple calls are made to complete translation. |
|
293 @SYMTestExpectedResults Test must not fail |
|
294 @SYMREQ REQ0000 |
|
295 */ |
|
296 LOCAL_C void BEConversionMultiplePassBOM(CCnvCharacterSetConverter& aCharacterSetConverter) |
|
297 { |
|
298 TBuf16<KBufferLength6> generatedUnicode; |
|
299 TInt state=CCnvCharacterSetConverter::KStateDefault; |
|
300 TInt numberOfUnconvertibleCharacters=0; |
|
301 TInt indexOfFirstByteOfFirstUnconvertibleCharacter=0; |
|
302 TInt numberUnconverted=0; |
|
303 |
|
304 // set the default endianness to Big Endian |
|
305 aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian); |
|
306 |
|
307 // test even number of foreign bytes |
|
308 // first pass |
|
309 numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven24BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
310 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b")); |
|
311 TEST(numberUnconverted==10); |
|
312 TEST(numberOfUnconvertibleCharacters==0); |
|
313 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
314 |
|
315 // without BOM |
|
316 numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM22BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
317 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b")); |
|
318 TEST(numberUnconverted==10); |
|
319 TEST(numberOfUnconvertibleCharacters==0); |
|
320 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
321 |
|
322 // second pass |
|
323 numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven24BE.Right(numberUnconverted), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
324 TEST(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655")); |
|
325 TEST(numberUnconverted==0); |
|
326 TEST(numberOfUnconvertibleCharacters==0); |
|
327 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
328 TheTest.Printf(_L("\nBigEndianConversionMultiplePassOddEven - OK")); |
|
329 |
|
330 // without BOM |
|
331 numberOfUnconvertibleCharacters=10; |
|
332 numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM22BE.Right(numberOfUnconvertibleCharacters), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
333 TEST(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655")); |
|
334 TEST(numberOfUnconvertibleCharacters==0); |
|
335 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
336 TheTest.Printf(_L("\nBigEndianConversionMultiplePassOddEven - OK")); |
|
337 |
|
338 // test odd number of foreign bytes |
|
339 // first pass |
|
340 state=CCnvCharacterSetConverter::KStateDefault; |
|
341 numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd25BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
342 TEST(numberUnconverted==11); |
|
343 TEST(numberOfUnconvertibleCharacters==0); |
|
344 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
345 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b")); |
|
346 |
|
347 // without BOM |
|
348 numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM23BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
349 TEST(numberUnconverted==11); |
|
350 TEST(numberOfUnconvertibleCharacters==0); |
|
351 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
352 TEST(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b")); |
|
353 |
|
354 // second pass |
|
355 numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd25BE.Right(numberUnconverted), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
356 TEST(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655")); |
|
357 TEST(numberUnconverted==1); |
|
358 TEST(numberOfUnconvertibleCharacters==0); |
|
359 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
360 |
|
361 // without BOM |
|
362 numberOfUnconvertibleCharacters=11; |
|
363 numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM23BE.Right(numberOfUnconvertibleCharacters), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
364 TEST(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655")); |
|
365 TEST(numberUnconverted==1); |
|
366 TEST(numberOfUnconvertibleCharacters==0); |
|
367 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
368 |
|
369 |
|
370 TheTest.Printf(_L("\nBigEndianConversionMultiplePassOddBOM - OK")); |
|
371 } |
|
372 /** |
|
373 @SYMTestCaseID SYSLIB-CHARCONV-CT-0557 |
|
374 @SYMTestCaseDesc UCS2 to 8 bit Big Endian Conversion - Single pass test |
|
375 @SYMTestPriority Medium |
|
376 @SYMTestActions Tests a 16 bit UCS2 to 8 bit descriptor conversion. |
|
377 Byte Order Mark is present and is set to Big Endian. |
|
378 Output buffer is large enough to contain the complete input string |
|
379 on a single pass |
|
380 @SYMTestExpectedResults Test must not fail |
|
381 @SYMREQ REQ0000 |
|
382 */ |
|
383 LOCAL_C void UCS2BEConversionSinglePassBOM(CCnvCharacterSetConverter& aCharacterSetConverter) |
|
384 { |
|
385 TBuf8<KBufferLength40> generatedForeign; |
|
386 CCnvCharacterSetConverter::TArrayOfAscendingIndices indicesOfUnconvertibleCharacters; |
|
387 |
|
388 // set the default endianness to Big Endian |
|
389 aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian); |
|
390 |
|
391 // test even number of foreign bytes |
|
392 aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
393 KUnicodeBufferEven14BE, |
|
394 indicesOfUnconvertibleCharacters ); |
|
395 |
|
396 TEST(generatedForeign==_L8("\xfe\xff\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a")); |
|
397 TheTest.Printf(_L("\nUCS2BEConversionSinglePassEvenBOM - OK")); |
|
398 |
|
399 // test odd number of foreign bytes |
|
400 aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
401 KUnicodeBufferOdd15BE, |
|
402 indicesOfUnconvertibleCharacters ); |
|
403 |
|
404 TEST(generatedForeign==_L8("\xfe\xff\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c")); |
|
405 TheTest.Printf(_L("\nUCS2BEConversionSinglePassOddBOM - OK")); |
|
406 } |
|
407 /** |
|
408 @SYMTestCaseID SYSLIB-CHARCONV-CT-0558 |
|
409 @SYMTestCaseDesc UCS2 to 8 bit Big Endian Conversion - Multiple pass test |
|
410 @SYMTestPriority Medium |
|
411 @SYMTestActions Tests a 16 bit UCS2 to 8 bit descriptor conversion. |
|
412 Byte Order Mark is present and is set to Big Endian. |
|
413 Output buffer is NOT large enough to contain the complete input string |
|
414 on a single pass |
|
415 @SYMTestExpectedResults Test must not fail |
|
416 @SYMREQ REQ0000 |
|
417 */ |
|
418 LOCAL_C void UCS2BEConversionMultiplePassBOM (CCnvCharacterSetConverter& aCharacterSetConverter) |
|
419 { |
|
420 TBuf8<KBufferLength6> generatedForeign; |
|
421 TBuf8<KBufferLength8> generatedForeign2; |
|
422 TInt result=0; |
|
423 CCnvCharacterSetConverter::TArrayOfAscendingIndices indicesOfUnconvertibleCharacters; |
|
424 |
|
425 // set the default endianness to Big Endian |
|
426 aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian); |
|
427 |
|
428 // *** Test even number of bytes *** |
|
429 // test even number of foreign bytes - pass 1 |
|
430 result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
431 KUnicodeBufferEven14BE, |
|
432 indicesOfUnconvertibleCharacters ); |
|
433 TEST(generatedForeign==_L8("\xfe\xff\x41\x42\x43\x44")); |
|
434 TEST(result==11); |
|
435 |
|
436 // test even number of foreign bytes - pass 2 |
|
437 result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
438 KUnicodeBufferEven14BE.Right(result), |
|
439 indicesOfUnconvertibleCharacters ); |
|
440 TEST(result==8); |
|
441 TEST(generatedForeign==_L8("\x45\x46\x47\x48\x49\x4A")); |
|
442 |
|
443 // test even number of foreign bytes - pass 3 |
|
444 result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
445 KUnicodeBufferEven14BE.Right(result), |
|
446 indicesOfUnconvertibleCharacters ); |
|
447 TEST(result==5); |
|
448 TEST(generatedForeign==_L8("\x4b\x4c\x4d\x4e\x4f\x50")); |
|
449 |
|
450 |
|
451 // test even number of foreign bytes - pass 4 |
|
452 result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
453 KUnicodeBufferEven14BE.Right(result), |
|
454 indicesOfUnconvertibleCharacters ); |
|
455 TEST(result==2); |
|
456 TEST(generatedForeign==_L8("\x51\x52\x53\x54\x55\x56")); |
|
457 |
|
458 // test even number of foreign bytes - pass 5 |
|
459 result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign2, |
|
460 KUnicodeBufferEven14BE.Right(result), |
|
461 indicesOfUnconvertibleCharacters ); |
|
462 TEST(generatedForeign2==_L8("\x57\x58\x59\x5a")); |
|
463 TEST(result==0); |
|
464 |
|
465 TheTest.Printf(_L("\nUCS2LEConversionMultiplePassEvenBOM - OK")); |
|
466 |
|
467 // *** Test odd numer of bytes *** |
|
468 result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
469 KUnicodeBufferOdd15BE, |
|
470 indicesOfUnconvertibleCharacters ); |
|
471 TEST(generatedForeign==_L8("\xfe\xff\x41\x42\x43\x44")); |
|
472 |
|
473 // test even number of foreign bytes - pass 2 |
|
474 result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
475 KUnicodeBufferOdd15BE.Right(result), |
|
476 indicesOfUnconvertibleCharacters ); |
|
477 TEST(generatedForeign==_L8("\x45\x46\x47\x48\x49\x4a")); |
|
478 |
|
479 // test even number of foreign bytes - pass 3 |
|
480 result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
481 KUnicodeBufferOdd15BE.Right(result), |
|
482 indicesOfUnconvertibleCharacters ); |
|
483 TEST(generatedForeign==_L8("\x4b\x4c\x4d\x4e\x4f\x50")); |
|
484 |
|
485 // test even number of foreign bytes - pass 4 |
|
486 result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
487 KUnicodeBufferOdd15BE.Right(result), |
|
488 indicesOfUnconvertibleCharacters ); |
|
489 TEST(generatedForeign==_L8("\x51\x52\x53\x54\x55\x56")); |
|
490 |
|
491 |
|
492 // test even number of foreign bytes - pass 5 |
|
493 result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign, |
|
494 KUnicodeBufferOdd15BE.Right(result), |
|
495 indicesOfUnconvertibleCharacters ); |
|
496 TEST(generatedForeign==_L8("\x57\x58\x59\x5a\x5b\x5c")); |
|
497 TEST(result==0); |
|
498 |
|
499 TheTest.Printf(_L("\nUCS2LEConversionMultiplePassOddBOM - OK")); |
|
500 } |
|
501 /** |
|
502 @SYMTestCaseID SYSLIB-CHARCONV-CT-0559 |
|
503 @SYMTestCaseDesc Tests a 16 bit UCS2 to 8 bit & 16 bit UCS2 to 8 bit conversion with empty buffers. |
|
504 @SYMTestPriority Medium |
|
505 @SYMTestActions Attempt for conversion when input and output buffers are small |
|
506 @SYMTestExpectedResults Test must not fail |
|
507 @SYMREQ REQ0000 |
|
508 */ |
|
509 LOCAL_C void TooSmallBufferConversion (CCnvCharacterSetConverter& aCharacterSetConverter) |
|
510 { |
|
511 TBuf16<KBufferLength1> generatedUnicode1; |
|
512 TBuf8<KBufferLength1> generatedForeign1; |
|
513 |
|
514 TInt state=CCnvCharacterSetConverter::KStateDefault; |
|
515 TInt numberOfUnconvertibleCharacters=0; |
|
516 TInt indexOfFirstByteOfFirstUnconvertibleCharacter=0; |
|
517 |
|
518 CCnvCharacterSetConverter::TArrayOfAscendingIndices indicesOfUnconvertibleCharacters; |
|
519 |
|
520 // set the default endianness to little Endian |
|
521 aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::ELittleEndian); |
|
522 |
|
523 // convert to UCS2 using an output buffer that is too small |
|
524 TInt result = aCharacterSetConverter.ConvertToUnicode(generatedUnicode1, KForeignBufferEven12LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter); |
|
525 TEST(generatedUnicode1==_L16("\x4241")); |
|
526 TEST(result==8); |
|
527 TEST(numberOfUnconvertibleCharacters==0); |
|
528 TEST(indexOfFirstByteOfFirstUnconvertibleCharacter==-1); |
|
529 TheTest.Printf(_L("\n8bit->UCS2 output buffer size 1 - OK")); |
|
530 |
|
531 TheTest.Printf(_L("\nConversionTooSmallBuffer - OK")); |
|
532 } |
|
533 /** |
|
534 @SYMTestCaseID SYSLIB-CHARCONV-CT-0560 |
|
535 @SYMTestCaseDesc Conversion tests from UCS2 GUID to MIB |
|
536 @SYMTestPriority Medium |
|
537 @SYMTestActions Tests retreiving the MIB value from the UCS2 GUID |
|
538 Tests retreiving the UCS2 GUID from the MIB value |
|
539 @SYMTestExpectedResults Test must not fail |
|
540 @SYMREQ REQ0000 |
|
541 */ |
|
542 LOCAL_C void CharacterSetValueAndMIBTests(CCnvCharacterSetConverter& aCharacterSetConverter, RFs& aFileServerSession) |
|
543 { |
|
544 // check that the character set value of '1000' is converted to the UCS2 GUID (0x101ff492) |
|
545 TEST(aCharacterSetConverter.ConvertMibEnumOfCharacterSetToIdentifierL(KMibValue,aFileServerSession)==KCharacterSetIdentifierUcs2); |
|
546 TheTest.Printf(_L("\nMIB->Char Set GUID - OK")); |
|
547 |
|
548 // check that the UCS2 GUID (0x101ff492) is converted to the character set value of '1000' |
|
549 TEST(aCharacterSetConverter.ConvertCharacterSetIdentifierToMibEnumL(KCharacterSetIdentifierUcs2,aFileServerSession)==KMibValue); |
|
550 TheTest.Printf(_L("\nChar Set GUID->MIB - OK")); |
|
551 } |
|
552 |
|
553 |
|
554 LOCAL_C void DoE32MainL() |
|
555 { |
|
556 RFs fileServerSession; |
|
557 CleanupClosePushL(fileServerSession); |
|
558 User::LeaveIfError(fileServerSession.Connect()); |
|
559 CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC(); |
|
560 CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession); |
|
561 TInt i; |
|
562 for (i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i) |
|
563 { |
|
564 const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i]; |
|
565 characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession); |
|
566 TPtrC charactersSetName(charactersSet.Name()); |
|
567 if (charactersSet.NameIsFileName()) |
|
568 { |
|
569 charactersSetName.Set(TParsePtrC(charactersSetName).Name()); |
|
570 } |
|
571 TheTest.Printf(_L(" %S\n"), &charactersSetName); |
|
572 } |
|
573 |
|
574 // test MIB to Character Set ID (and visa versa) conversion |
|
575 CharacterSetValueAndMIBTests(*characterSetConverter, fileServerSession); |
|
576 |
|
577 // prepare for conversion |
|
578 TheTest.Start(_L("\nTesting 8 bit -> UCS2 conversion")); |
|
579 TRAPD( error, characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUcs2, *arrayOfCharacterSetsAvailable, fileServerSession)); |
|
580 if ( error != KErrNone ) |
|
581 { |
|
582 RDebug::Print(_L("PrepareToConvertToOrFromL failed code:%d\n"),error); |
|
583 RDebug::Print(_L("KCharacterSetIdentifierUcs2 is not available so tests failed\n")); |
|
584 User::LeaveIfError(error); |
|
585 } |
|
586 |
|
587 |
|
588 // *** 8 bit to UCS2 conversion *** |
|
589 TheTest.Next(_L("\n8->UCS2 Little Endian Conversion - Single pass")); |
|
590 LEConversionSinglePassBOM(*characterSetConverter); |
|
591 |
|
592 TheTest.Next(_L("\n8->UCS2 Little Endian Conversion - Multiple pass")); |
|
593 LEConversionMultiplePassBOM(*characterSetConverter); |
|
594 |
|
595 TheTest.Next(_L("\n8->UCS2 Big Endian Conversion - Single pass")); |
|
596 BEConversionSinglePassBOM(*characterSetConverter); |
|
597 |
|
598 TheTest.Next(_L("\n8->UCS2 Big Endian Conversion - Multiple pass")); |
|
599 BEConversionMultiplePassBOM(*characterSetConverter); |
|
600 |
|
601 |
|
602 // *** UCS2 to 8 bit conversion *** |
|
603 TheTest.Next(_L("\nUCS2->8 Big Endian Conversion - Single pass")); |
|
604 UCS2BEConversionSinglePassBOM(*characterSetConverter); |
|
605 |
|
606 TheTest.Next(_L("\nUCS2->8 Big Endian Conversion - Multiple pass")); |
|
607 UCS2BEConversionMultiplePassBOM(*characterSetConverter); |
|
608 |
|
609 // *** attempted conversion when input/output buffers are too small |
|
610 TheTest.Next(_L("\nTooSmallBufferConversion")); |
|
611 TooSmallBufferConversion(*characterSetConverter); |
|
612 |
|
613 TheTest.Printf(_L("\n")); |
|
614 CleanupStack::PopAndDestroy(3);// arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession |
|
615 } |
|
616 |
|
617 GLDEF_C TInt E32Main() |
|
618 { |
|
619 __UHEAP_MARK; |
|
620 |
|
621 TheTest.Title(); |
|
622 |
|
623 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
624 TEST(trapCleanup != NULL); |
|
625 |
|
626 TRAPD(error, DoE32MainL()); |
|
627 TEST2(error, KErrNone); |
|
628 |
|
629 delete trapCleanup; |
|
630 |
|
631 TheTest.End(); |
|
632 TheTest.Close(); |
|
633 |
|
634 __UHEAP_MARKEND; |
|
635 return KErrNone; |
|
636 } |
|
637 |