|
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("TPartial")); |
|
32 |
|
33 /////////////////////////////////////////////////////////////////////////////////////// |
|
34 /////////////////////////////////////////////////////////////////////////////////////// |
|
35 //Tests macroses and functions. |
|
36 static void Check(TInt aValue, TInt aLine) |
|
37 { |
|
38 if(!aValue) |
|
39 { |
|
40 TheTest(EFalse, aLine); |
|
41 } |
|
42 } |
|
43 #define TEST(arg) ::Check((arg), __LINE__) |
|
44 |
|
45 /////////////////////////////////////////////////////////////////////////////////////// |
|
46 /////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
48 const TInt KUtfBufferLength=100; |
|
49 const TUint KIllegalUtfByteValue=0xff; |
|
50 const TUint KIllegalUnicodeCharacter=0xffff; |
|
51 |
|
52 LOCAL_C void FillWithIllegalUtf(TUint8* aUtfBuffer) |
|
53 { |
|
54 for (TInt i=0; i<KUtfBufferLength; ++i) |
|
55 { |
|
56 aUtfBuffer[i]=KIllegalUtfByteValue; |
|
57 } |
|
58 } |
|
59 |
|
60 LOCAL_C TBool FillWithIllegalUtfReturningIfMatched(TUint8* aUtfBuffer, const TDes8& aDescriptorAroundBuffer, const TDesC8& aUtfToMatch) |
|
61 { |
|
62 __ASSERT_ALWAYS(aDescriptorAroundBuffer.Ptr()==aUtfBuffer, User::Panic(_L("TPARTIAL"), 0)); |
|
63 __ASSERT_ALWAYS(aDescriptorAroundBuffer.MaxLength()>=aUtfToMatch.Length(), User::Panic(_L("TPARTIAL"), 1)); |
|
64 __ASSERT_ALWAYS(aDescriptorAroundBuffer.MaxLength()<=KUtfBufferLength, User::Panic(_L("TPARTIAL"), 2)); |
|
65 TBool matched=TPtrC8(aUtfBuffer, aUtfToMatch.Length())==aUtfToMatch; |
|
66 if (matched) |
|
67 { |
|
68 for (TInt i=aDescriptorAroundBuffer.MaxLength(); i<KUtfBufferLength; ++i) |
|
69 { |
|
70 if (aUtfBuffer[i]!=KIllegalUtfByteValue) |
|
71 { |
|
72 matched=EFalse; |
|
73 break; |
|
74 } |
|
75 } |
|
76 } |
|
77 FillWithIllegalUtf(aUtfBuffer); |
|
78 return matched; |
|
79 } |
|
80 |
|
81 LOCAL_C void FillWithIllegalUnicode(TUint16* aUnicodeBuffer) |
|
82 { |
|
83 for (TInt i=0; i<KUtfBufferLength; ++i) |
|
84 { |
|
85 aUnicodeBuffer[i]=KIllegalUnicodeCharacter; |
|
86 } |
|
87 } |
|
88 |
|
89 LOCAL_C TBool FillWithIllegalUnicodeReturningIfMatched(TUint16* aUnicodeBuffer, const TDesC16& aUnicodeToMatch) |
|
90 { |
|
91 const TInt lengthToMatch=aUnicodeToMatch.Length(); |
|
92 TBool matched=TPtrC16(aUnicodeBuffer, lengthToMatch)==aUnicodeToMatch; |
|
93 if (matched) |
|
94 { |
|
95 for (TInt i=lengthToMatch; i<KUtfBufferLength; ++i) |
|
96 { |
|
97 if (aUnicodeBuffer[i]!=KIllegalUnicodeCharacter) |
|
98 { |
|
99 matched=EFalse; |
|
100 break; |
|
101 } |
|
102 } |
|
103 } |
|
104 FillWithIllegalUnicode(aUnicodeBuffer); |
|
105 return matched; |
|
106 } |
|
107 /** |
|
108 @SYMTestCaseID SYSLIB-CHARCONV-CT-0572 |
|
109 @SYMTestCaseDesc Tests that partial conversions work |
|
110 @SYMTestPriority Medium |
|
111 @SYMTestActions Tests for converting to Unicode from UTF- 7 |
|
112 @SYMTestExpectedResults Test must not fail |
|
113 @SYMREQ REQ0000 |
|
114 */ |
|
115 LOCAL_C void TestConvertingToUtf(TUint8* aUtfBuffer, TInt aMaximumLengthOfUtfDescriptor, const TDesC16& aUnicode, TBool aBoolParameter, TInt aNumberOfUnicodeItemsExpectedToBeConverted, const TDesC8& aFirstHalfOfUtfExpected, const TDesC8& aSecondHalfOfUtfExpected) |
|
116 { |
|
117 TPtr8 utf(aUtfBuffer, aMaximumLengthOfUtfDescriptor); |
|
118 FillWithIllegalUtf(aUtfBuffer); |
|
119 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf7(utf, aUnicode, aBoolParameter)==aNumberOfUnicodeItemsExpectedToBeConverted); |
|
120 TEST(FillWithIllegalUtfReturningIfMatched(aUtfBuffer, utf, aFirstHalfOfUtfExpected)); |
|
121 TPtr8 restOfUtf(aUtfBuffer, KUtfBufferLength); |
|
122 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf7(restOfUtf, aUnicode.Right(aNumberOfUnicodeItemsExpectedToBeConverted), aBoolParameter)==0); |
|
123 TEST(FillWithIllegalUtfReturningIfMatched(aUtfBuffer, restOfUtf, aSecondHalfOfUtfExpected)); |
|
124 TBuf8<KUtfBufferLength> originalUtf(aFirstHalfOfUtfExpected); |
|
125 originalUtf.Append(aSecondHalfOfUtfExpected); |
|
126 TBuf16<20> generatedUnicode; |
|
127 TInt state=CnvUtfConverter::KStateDefault; |
|
128 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, originalUtf, state)==0); |
|
129 TEST(state==CnvUtfConverter::KStateDefault); |
|
130 TEST(generatedUnicode==aUnicode); |
|
131 } |
|
132 /** |
|
133 @SYMTestCaseID SYSLIB-CHARCONV-CT-0573 |
|
134 @SYMTestCaseDesc Tests that partial conversions work |
|
135 @SYMTestPriority Medium |
|
136 @SYMTestActions Tests for converting to Unicode from UTF- 7 |
|
137 @SYMTestExpectedResults Test must not fail |
|
138 @SYMREQ REQ0000 |
|
139 */ |
|
140 LOCAL_C void TestUtf7StatePreservation(const TDesC8& aUtf7) |
|
141 { |
|
142 TInt state=CnvUtfConverter::KStateDefault; |
|
143 TBuf16<50> wholeGeneratedUnicode; |
|
144 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(wholeGeneratedUnicode, aUtf7, state)==0); |
|
145 for (TInt i=aUtf7.Length()-1; i>=0; --i) |
|
146 { |
|
147 state=CnvUtfConverter::KStateDefault; |
|
148 TBuf16<50> generatedUnicode1; |
|
149 TInt numberOfUtf7BytesNotConvertedByFirstCall=CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode1, aUtf7.Left(i), state); |
|
150 if (numberOfUtf7BytesNotConvertedByFirstCall<0) |
|
151 { |
|
152 TEST(numberOfUtf7BytesNotConvertedByFirstCall==CnvUtfConverter::EErrorIllFormedInput); |
|
153 numberOfUtf7BytesNotConvertedByFirstCall=i; |
|
154 generatedUnicode1=KNullDesC16; |
|
155 state=CnvUtfConverter::KStateDefault; |
|
156 } |
|
157 TEST(numberOfUtf7BytesNotConvertedByFirstCall>=0); |
|
158 TBuf16<50> generatedUnicode2; |
|
159 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode2, aUtf7.Mid(i-numberOfUtf7BytesNotConvertedByFirstCall), state)==0); |
|
160 generatedUnicode1+=generatedUnicode2; |
|
161 TEST(generatedUnicode1==wholeGeneratedUnicode); |
|
162 } |
|
163 } |
|
164 |
|
165 LOCAL_C void TestConvertingToUtf(TUint8* aUtfBuffer, TInt aMaximumLengthOfUtfDescriptor, const TDesC16& aUnicode, TInt aNumberOfUnicodeItemsExpectedToBeConverted, const TDesC8& aFirstHalfOfUtfExpected, const TDesC8& aSecondHalfOfUtfExpected) |
|
166 { |
|
167 TestConvertingToUtf(aUtfBuffer, aMaximumLengthOfUtfDescriptor, aUnicode, EFalse, aNumberOfUnicodeItemsExpectedToBeConverted, aFirstHalfOfUtfExpected, aSecondHalfOfUtfExpected); |
|
168 } |
|
169 |
|
170 GLDEF_C TInt E32Main() |
|
171 { |
|
172 TheTest.Title(); |
|
173 TheTest.Start(_L("Checking that partial conversions work")); |
|
174 TUint8 utfBuffer[KUtfBufferLength]; |
|
175 TUint16 unicodeBuffer[KUtfBufferLength]; |
|
176 TheTest.Next(_L("Testing trivial UTF-7 and UTF-8")); |
|
177 { |
|
178 for (TInt i=0; i<6; ++i) |
|
179 { |
|
180 const TInt numberOfUnconvertedItemsAtEndOfInputDescriptor=5-i; |
|
181 TPtr8 utf(utfBuffer, i); |
|
182 FillWithIllegalUtf(utfBuffer); |
|
183 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf7(utf, _L16("abcde"), EFalse)==numberOfUnconvertedItemsAtEndOfInputDescriptor); |
|
184 TEST(FillWithIllegalUtfReturningIfMatched(utfBuffer, utf, _L8("abcde").Left(i))); |
|
185 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf7(utf, _L16("abcde"), ETrue)==numberOfUnconvertedItemsAtEndOfInputDescriptor); |
|
186 TEST(FillWithIllegalUtfReturningIfMatched(utfBuffer, utf, _L8("abcde").Left(i))); |
|
187 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(utf, _L16("abcde"))==numberOfUnconvertedItemsAtEndOfInputDescriptor); |
|
188 TEST(FillWithIllegalUtfReturningIfMatched(utfBuffer, utf, _L8("abcde").Left(i))); |
|
189 TPtr16 unicode(unicodeBuffer, i); |
|
190 TInt state=CnvUtfConverter::KStateDefault; |
|
191 FillWithIllegalUnicode(unicodeBuffer); |
|
192 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(unicode, _L8("abcde"), state)==numberOfUnconvertedItemsAtEndOfInputDescriptor); |
|
193 TEST(FillWithIllegalUnicodeReturningIfMatched(unicodeBuffer, _L16("abcde").Left(i))); |
|
194 TEST(state==CnvUtfConverter::KStateDefault); |
|
195 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(unicode, _L8("abcde"))==numberOfUnconvertedItemsAtEndOfInputDescriptor); |
|
196 TEST(FillWithIllegalUnicodeReturningIfMatched(unicodeBuffer, _L16("abcde").Left(i))); |
|
197 } |
|
198 } |
|
199 TheTest.Next(_L("Testing converting to UTF-7")); |
|
200 { |
|
201 TBuf16<20> originalUnicode; |
|
202 TBuf16<20> generatedUnicode; |
|
203 TBuf8<20> generatedUtf; |
|
204 originalUnicode.Format(_L16("%c%c%c%c?"), 0x8fd9, 0x662f, 0x4ec0, 0x4e48); // Chinese: zhe4 shi4 shen2 me? |
|
205 TInt i; |
|
206 for (i=0; i<=4; ++i) |
|
207 { |
|
208 TestConvertingToUtf(utfBuffer, i, originalUnicode, 5, KNullDesC8, _L8("+j9lmL07ATkg-?")); |
|
209 } |
|
210 for (i=5; i<=7; ++i) |
|
211 { |
|
212 TestConvertingToUtf(utfBuffer, i, originalUnicode, 4, _L8("+j9k-"), _L8("+Zi9OwE5I-?")); |
|
213 } |
|
214 for (i=8; i<=9; ++i) |
|
215 { |
|
216 TestConvertingToUtf(utfBuffer, i, originalUnicode, 3, _L8("+j9lmLw-"), _L8("+TsBOSA-?")); |
|
217 } |
|
218 for (i=10; i<=12; ++i) |
|
219 { |
|
220 TestConvertingToUtf(utfBuffer, i, originalUnicode, 2, _L8("+j9lmL07A-"), _L8("+Tkg-?")); |
|
221 } |
|
222 TestConvertingToUtf(utfBuffer, 13, originalUnicode, 1, _L8("+j9lmL07ATkg-"), _L8("?")); |
|
223 TestConvertingToUtf(utfBuffer, 14, originalUnicode, 0, _L8("+j9lmL07ATkg-?"), KNullDesC8); |
|
224 originalUnicode.Format(_L16("%c %c%c %c%c%c%c."), 0x042f, 0x043d, 0x0435, 0x0437, 0x043d, 0x0430, 0x044e); // Russian: ya nye znayu. |
|
225 for (i=0; i<=4; ++i) |
|
226 { |
|
227 TestConvertingToUtf(utfBuffer, i, originalUnicode, 10, KNullDesC8, _L8("+BC8- +BD0ENQ- +BDcEPQQwBE4-.")); |
|
228 } |
|
229 TestConvertingToUtf(utfBuffer, 5, originalUnicode, 9, _L8("+BC8-"), _L8(" +BD0ENQ- +BDcEPQQwBE4-.")); |
|
230 for (i=6; i<=10; ++i) |
|
231 { |
|
232 TestConvertingToUtf(utfBuffer, i, originalUnicode, 8, _L8("+BC8- "), _L8("+BD0ENQ- +BDcEPQQwBE4-.")); |
|
233 } |
|
234 for (i=11; i<=13; ++i) |
|
235 { |
|
236 TestConvertingToUtf(utfBuffer, i, originalUnicode, 7, _L8("+BC8- +BD0-"), _L8("+BDU- +BDcEPQQwBE4-.")); |
|
237 } |
|
238 TestConvertingToUtf(utfBuffer, 14, originalUnicode, 6, _L8("+BC8- +BD0ENQ-"), _L8(" +BDcEPQQwBE4-.")); |
|
239 for (i=15; i<=19; ++i) |
|
240 { |
|
241 TestConvertingToUtf(utfBuffer, i, originalUnicode, 5, _L8("+BC8- +BD0ENQ- "), _L8("+BDcEPQQwBE4-.")); |
|
242 } |
|
243 for (i=20; i<=22; ++i) |
|
244 { |
|
245 TestConvertingToUtf(utfBuffer, i, originalUnicode, 4, _L8("+BC8- +BD0ENQ- +BDc-"), _L8("+BD0EMARO-.")); |
|
246 } |
|
247 for (i=23; i<=24; ++i) |
|
248 { |
|
249 TestConvertingToUtf(utfBuffer, i, originalUnicode, 3, _L8("+BC8- +BD0ENQ- +BDcEPQ-"), _L8("+BDAETg-.")); |
|
250 } |
|
251 for (i=25; i<=27; ++i) |
|
252 { |
|
253 TestConvertingToUtf(utfBuffer, i, originalUnicode, 2, _L8("+BC8- +BD0ENQ- +BDcEPQQw-"), _L8("+BE4-.")); |
|
254 } |
|
255 TestConvertingToUtf(utfBuffer, 28, originalUnicode, 1, _L8("+BC8- +BD0ENQ- +BDcEPQQwBE4-"), _L8(".")); |
|
256 TestConvertingToUtf(utfBuffer, 29, originalUnicode, 0, _L8("+BC8- +BD0ENQ- +BDcEPQQwBE4-."), KNullDesC8); |
|
257 TheTest.Next(_L("Testing converting UCS-2 ending in truncated sequences")); |
|
258 originalUnicode.Format(_L16(" %c"), 0xd800); |
|
259 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf7(generatedUtf, originalUnicode, EFalse)==0); |
|
260 TEST(generatedUtf==_L8(" +2AA-")); |
|
261 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf7(generatedUtf, originalUnicode, ETrue)==0); |
|
262 TEST(generatedUtf==_L8(" +2AA-")); |
|
263 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf, originalUnicode)==1); |
|
264 TEST(generatedUtf.Length()==1); |
|
265 TEST(generatedUtf[0]==' '); |
|
266 originalUnicode.Format(_L16("%c"), 0xd800); |
|
267 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf7(generatedUtf, originalUnicode, EFalse)==0); |
|
268 TEST(generatedUtf==_L8("+2AA-")); |
|
269 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf7(generatedUtf, originalUnicode, ETrue)==0); |
|
270 TEST(generatedUtf==_L8("+2AA-")); |
|
271 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf, originalUnicode)==CnvUtfConverter::EErrorIllFormedInput); |
|
272 originalUnicode.Format(_L16("%c%c"), 0xd800, 0xdbff); |
|
273 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf, originalUnicode)==CnvUtfConverter::EErrorIllFormedInput); |
|
274 originalUnicode.Format(_L16("%c%c"), 0xd800, 0xdc00); |
|
275 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf, originalUnicode)==0); |
|
276 TEST(generatedUtf==_L8("\xf0\x90\x80\x80")); |
|
277 TheTest.Next(_L("Testing converting UTF-7 ending in truncated sequences")); |
|
278 TInt state=CnvUtfConverter::KStateDefault; |
|
279 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("+"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
280 state=CnvUtfConverter::KStateDefault; |
|
281 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("e+"), state)==1); |
|
282 TEST(generatedUnicode.Length()==1); |
|
283 TEST(generatedUnicode[0]=='e'); |
|
284 TEST(state==CnvUtfConverter::KStateDefault); |
|
285 state=CnvUtfConverter::KStateDefault; |
|
286 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("+-"), state)==0); |
|
287 TEST(generatedUnicode==_L16("+")); |
|
288 TEST(state==CnvUtfConverter::KStateDefault); |
|
289 state=CnvUtfConverter::KStateDefault; |
|
290 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++"), state)==1); |
|
291 TEST(generatedUnicode.Length()==0); |
|
292 TEST(state!=CnvUtfConverter::KStateDefault); |
|
293 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("+"), state)==CnvUtfConverter::EErrorIllFormedInput); // before resetting state |
|
294 state=CnvUtfConverter::KStateDefault; |
|
295 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++-"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
296 state=CnvUtfConverter::KStateDefault; |
|
297 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("+++"), state)==2); |
|
298 TEST(generatedUnicode.Length()==0); |
|
299 TEST(state!=CnvUtfConverter::KStateDefault); |
|
300 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++"), state)==CnvUtfConverter::EErrorIllFormedInput); // before resetting state |
|
301 state=CnvUtfConverter::KStateDefault; |
|
302 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("+++-"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
303 state=CnvUtfConverter::KStateDefault; |
|
304 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++"), state)==3); |
|
305 TEST(generatedUnicode.Length()==0); |
|
306 TEST(state!=CnvUtfConverter::KStateDefault); |
|
307 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("+++"), state)==CnvUtfConverter::EErrorIllFormedInput); // before resetting state |
|
308 state=CnvUtfConverter::KStateDefault; |
|
309 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++-"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
310 state=CnvUtfConverter::KStateDefault; |
|
311 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("+++8"), state)==0); |
|
312 TEST(generatedUnicode.Length()==1); |
|
313 TEST(generatedUnicode[0]==0xfbef); |
|
314 TEST(state!=CnvUtfConverter::KStateDefault); // this is imporant, as even though we've converted all the input UTF-7, the input may be being received in chunks, in which case, we need to make sure we remember when converting the next chunk that we were previously in a base-64 sequence |
|
315 state=CnvUtfConverter::KStateDefault; |
|
316 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("+++8-"), state)==0); |
|
317 TEST(generatedUnicode.Length()==1); |
|
318 TEST(generatedUnicode[0]==0xfbef); |
|
319 TEST(state==CnvUtfConverter::KStateDefault); |
|
320 state=CnvUtfConverter::KStateDefault; |
|
321 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++/"), state)==1); |
|
322 TEST(generatedUnicode.Length()==1); |
|
323 TEST(generatedUnicode[0]==0xfbef); |
|
324 TEST(state!=CnvUtfConverter::KStateDefault); |
|
325 state=CnvUtfConverter::KStateDefault; |
|
326 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++/-"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
327 state=CnvUtfConverter::KStateDefault; |
|
328 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++//"), state)==2); |
|
329 TEST(generatedUnicode.Length()==1); |
|
330 TEST(generatedUnicode[0]==0xfbef); |
|
331 TEST(state!=CnvUtfConverter::KStateDefault); |
|
332 state=CnvUtfConverter::KStateDefault; |
|
333 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++//-"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
334 state=CnvUtfConverter::KStateDefault; |
|
335 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++///"), state)==3); |
|
336 TEST(generatedUnicode.Length()==1); |
|
337 TEST(generatedUnicode[0]==0xfbef); |
|
338 TEST(state!=CnvUtfConverter::KStateDefault); |
|
339 state=CnvUtfConverter::KStateDefault; |
|
340 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++///-"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
341 state=CnvUtfConverter::KStateDefault; |
|
342 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++//w"), state)==0); |
|
343 TEST(generatedUnicode.Length()==2); |
|
344 TEST(generatedUnicode[0]==0xfbef); |
|
345 TEST(generatedUnicode[1]==0xbfff); |
|
346 TEST(state!=CnvUtfConverter::KStateDefault); // this is imporant, as even though we've converted all the input UTF-7, the input may be being received in chunks, in which case, we need to make sure we remember when converting the next chunk that we were previously in a base-64 sequence |
|
347 state=CnvUtfConverter::KStateDefault; |
|
348 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++//w-"), state)==0); |
|
349 TEST(generatedUnicode.Length()==2); |
|
350 TEST(generatedUnicode[0]==0xfbef); |
|
351 TEST(generatedUnicode[1]==0xbfff); |
|
352 TEST(state==CnvUtfConverter::KStateDefault); |
|
353 state=CnvUtfConverter::KStateDefault; |
|
354 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++///h"), state)==1); |
|
355 TEST(generatedUnicode.Length()==2); |
|
356 TEST(generatedUnicode[0]==0xfbef); |
|
357 TEST(generatedUnicode[1]==0xbfff); |
|
358 TEST(state!=CnvUtfConverter::KStateDefault); |
|
359 state=CnvUtfConverter::KStateDefault; |
|
360 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++///h-"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
361 state=CnvUtfConverter::KStateDefault; |
|
362 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++///hh"), state)==0); |
|
363 TEST(generatedUnicode.Length()==3); |
|
364 TEST(generatedUnicode[0]==0xfbef); |
|
365 TEST(generatedUnicode[1]==0xbfff); |
|
366 TEST(generatedUnicode[2]==0xf861); |
|
367 TEST(state!=CnvUtfConverter::KStateDefault); // this is imporant, as even though we've converted all the input UTF-7, the input may be being received in chunks, in which case, we need to make sure we remember when converting the next chunk that we were previously in a base-64 sequence |
|
368 state=CnvUtfConverter::KStateDefault; |
|
369 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++///hh-"), state)==0); |
|
370 TEST(generatedUnicode.Length()==3); |
|
371 TEST(generatedUnicode[0]==0xfbef); |
|
372 TEST(generatedUnicode[1]==0xbfff); |
|
373 TEST(generatedUnicode[2]==0xf861); |
|
374 TEST(state==CnvUtfConverter::KStateDefault); |
|
375 state=CnvUtfConverter::KStateDefault; |
|
376 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++///hht"), state)==1); |
|
377 TEST(generatedUnicode.Length()==3); |
|
378 TEST(generatedUnicode[0]==0xfbef); |
|
379 TEST(generatedUnicode[1]==0xbfff); |
|
380 TEST(generatedUnicode[2]==0xf861); |
|
381 TEST(state!=CnvUtfConverter::KStateDefault); |
|
382 state=CnvUtfConverter::KStateDefault; |
|
383 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++///hht-"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
384 state=CnvUtfConverter::KStateDefault; |
|
385 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++///hhtt"), state)==2); |
|
386 TEST(generatedUnicode.Length()==3); |
|
387 TEST(generatedUnicode[0]==0xfbef); |
|
388 TEST(generatedUnicode[1]==0xbfff); |
|
389 TEST(generatedUnicode[2]==0xf861); |
|
390 TEST(state!=CnvUtfConverter::KStateDefault); |
|
391 state=CnvUtfConverter::KStateDefault; |
|
392 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("++++///hhtt-"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
393 state=CnvUtfConverter::KStateDefault; |
|
394 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(generatedUnicode, _L8("+34-"), state)==CnvUtfConverter::EErrorIllFormedInput); |
|
395 TestUtf7StatePreservation(_L8("++34-")); |
|
396 TestUtf7StatePreservation(_L8("+rY4/5b+al3V98w-")); |
|
397 TestUtf7StatePreservation(_L8("+ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/-")); |
|
398 TheTest.Next(_L("Testing converting UTF-8 ending in truncated sequences")); |
|
399 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xc8"))==CnvUtfConverter::EErrorIllFormedInput); |
|
400 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("x\xc8"))==1); |
|
401 TEST(generatedUnicode.Length()==1); |
|
402 TEST(generatedUnicode[0]=='x'); |
|
403 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xc8\xc0"))==1); |
|
404 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xc8\xb0"))==0); |
|
405 TEST(generatedUnicode.Length()==1); |
|
406 TEST(generatedUnicode[0]==0x0230); |
|
407 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xe4"))==CnvUtfConverter::EErrorIllFormedInput); |
|
408 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("y\xe4"))==1); |
|
409 TEST(generatedUnicode.Length()==1); |
|
410 TEST(generatedUnicode[0]=='y'); |
|
411 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xe4\x80"))==CnvUtfConverter::EErrorIllFormedInput); |
|
412 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("H\xe4\x80"))==2); |
|
413 TEST(generatedUnicode.Length()==1); |
|
414 TEST(generatedUnicode[0]=='H'); |
|
415 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xe4\xc0"))==CnvUtfConverter::EErrorIllFormedInput); |
|
416 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("e\xe4\xc0"))==2); |
|
417 TEST(generatedUnicode.Length()==1); |
|
418 TEST(generatedUnicode[0]=='e'); |
|
419 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xe4\x80\xc0"))==1); |
|
420 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xe4\x80\xb0"))==0); |
|
421 TEST(generatedUnicode.Length()==1); |
|
422 TEST(generatedUnicode[0]==0x4030); |
|
423 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xf2"))==CnvUtfConverter::EErrorIllFormedInput); |
|
424 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("7\xf2"))==1); |
|
425 TEST(generatedUnicode.Length()==1); |
|
426 TEST(generatedUnicode[0]=='7'); |
|
427 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xf2\x80"))==CnvUtfConverter::EErrorIllFormedInput); |
|
428 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\\\xf2\x80"))==2); |
|
429 TEST(generatedUnicode.Length()==1); |
|
430 TEST(generatedUnicode[0]=='\\'); |
|
431 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xf2\xc0"))==CnvUtfConverter::EErrorIllFormedInput); |
|
432 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("$\xf2\xc0"))==2); |
|
433 TEST(generatedUnicode.Length()==1); |
|
434 TEST(generatedUnicode[0]=='$'); |
|
435 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xf2\x80\x80"))==CnvUtfConverter::EErrorIllFormedInput); |
|
436 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("{\xf2\x80\x80"))==3); |
|
437 TEST(generatedUnicode.Length()==1); |
|
438 TEST(generatedUnicode[0]=='{'); |
|
439 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xf2\x80\xc0"))==CnvUtfConverter::EErrorIllFormedInput); |
|
440 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8(" \xf2\x80\xc0"))==3); |
|
441 TEST(generatedUnicode.Length()==1); |
|
442 TEST(generatedUnicode[0]==' '); |
|
443 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xf2\x80\x80\xc0"))==1); |
|
444 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, _L8("\xf2\x80\x80\xb0"))==0); |
|
445 TEST(generatedUnicode.Length()==2); |
|
446 TEST(generatedUnicode[0]==0xd9c0); |
|
447 TEST(generatedUnicode[1]==0xdc30); |
|
448 } |
|
449 TheTest.End(); |
|
450 TheTest.Close(); |
|
451 return KErrNone; |
|
452 } |
|
453 |