|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <e32des8.h> |
|
18 |
|
19 LOCAL_D RTest test(_L("T_CP950.exe")); |
|
20 |
|
21 _LIT16(Uni_1, "\x0053\x3125\x3122\xAAAA\x9673\x2593\xFA0C\x3000"); |
|
22 _LIT8(CP950_1, "\x53\xA3\xB6\xA3\xB3\x5F\xB3\xAF\xF9\xFE\xC9\x4A\xA1\x40"); |
|
23 _LIT16(Uni_2, "\x0032\xFFFD\xFE3E\xFFFD\xFFFD"); |
|
24 _LIT8(CP950_2, "\x32\x80\xA1\x70\xC1\x7F\xA7"); |
|
25 |
|
26 _LIT(KName,"CP950"); |
|
27 const TUid KPluginUid={0x10206A8C}; |
|
28 |
|
29 |
|
30 // Used for supressing warning in OOM tests |
|
31 #define __UNUSED_VAR(var) var = var |
|
32 |
|
33 // |
|
34 /** |
|
35 @SYMTestCaseID SYSLIB-FATCHARSETCONV-CT-1776 |
|
36 @SYMTestCaseDesc Tests API behaviours of UnicodeConv class |
|
37 @SYMTestPriority High |
|
38 @SYMTestActions Tests for conversions from/to Unicode, using a function pointer |
|
39 @SYMTestExpectedResults Test must not fail |
|
40 */ |
|
41 void Test() |
|
42 { |
|
43 test.Next(_L("@SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1776")); |
|
44 RLibrary lib; |
|
45 |
|
46 const TUidType serverUid(KNullUid,KNullUid,KPluginUid); |
|
47 // load the dll |
|
48 TInt returnValue = lib.Load(KName,serverUid); |
|
49 test(returnValue==0); |
|
50 |
|
51 // get a pointer to the specified ordinal function and call it |
|
52 TLibraryFunction function1 = lib.Lookup(1); |
|
53 TLibraryFunction function2 = lib.Lookup(2); |
|
54 TLibraryFunction function3 = lib.Lookup(3); |
|
55 |
|
56 //cast the function pointer f to a function of type void with two arguments |
|
57 typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); |
|
58 TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1); |
|
59 |
|
60 typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&); |
|
61 TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2); |
|
62 |
|
63 typedef TBool (*TIsLegalShortNameCharacter)(TUint); |
|
64 TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast <TIsLegalShortNameCharacter> (function3); |
|
65 |
|
66 TBuf8<20> foreign1; |
|
67 TBuf16<20> unicode2; |
|
68 |
|
69 const TDesC16& unicode1(Uni_1); |
|
70 (*aConvertFromUnicodeL)(foreign1, unicode1); //testing conversion from Unicode |
|
71 TInt error = foreign1.Compare(CP950_1); |
|
72 |
|
73 test(error==0); |
|
74 foreign1.Zero(); |
|
75 |
|
76 const TDesC8& foreign2(CP950_2); |
|
77 (*aConvertToUnicodeL)(unicode2,foreign2); //testing conversion to Unicode |
|
78 error = unicode2.Compare(Uni_2); |
|
79 test(error==0); |
|
80 unicode2.Zero(); |
|
81 |
|
82 |
|
83 //testing for legal short name character |
|
84 TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character |
|
85 test(result==1); |
|
86 result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character |
|
87 test(result==0); |
|
88 result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character |
|
89 test(result==0); |
|
90 result = (*aIsLegalShortNameCharacter)(0x3000); //testing for a double byte character |
|
91 test(result==1); |
|
92 |
|
93 lib.Close(); |
|
94 } |
|
95 |
|
96 // test code for INC080460: FATCharsetConv panics - stops china build booting |
|
97 void TestINC080460() |
|
98 { |
|
99 RLibrary lib; |
|
100 const TUidType serverUid(KNullUid,KNullUid,KPluginUid); |
|
101 |
|
102 // load the dll |
|
103 TInt returnValue = lib.Load(KName,serverUid); |
|
104 test(returnValue==0); |
|
105 |
|
106 // get a pointer to the specified ordinal function and call it |
|
107 TLibraryFunction function1 = lib.Lookup(1); |
|
108 TLibraryFunction function2 = lib.Lookup(2); |
|
109 |
|
110 //cast the function pointer f to a function of type void with two arguments |
|
111 typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); |
|
112 TConvertFromUnicodeL ConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1); |
|
113 |
|
114 typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&); |
|
115 TConvertToUnicodeL ConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2); |
|
116 |
|
117 // the problem in this defect is when the foreign buffer is not big enough the code panics |
|
118 // the solution is for the code to leave |
|
119 |
|
120 // the foreign buffer is 11 (8+3) and there are 17 unicode characters |
|
121 TBuf8<11> foreign; |
|
122 _LIT16(longUnicode, "\x0053\x3125\x3122\xAAAA\x0053\x3125\x3122\xAAAA\x0053\x3125\x3122\xAAAA\x0053\x3125\x3122\xAAAA"); |
|
123 const TDesC16& testUnicode1(longUnicode); |
|
124 TInt error = KErrNone; |
|
125 |
|
126 // ConvertFromUnicodeL - check that this call leaves |
|
127 foreign.Zero(); |
|
128 TRAP( error, ConvertFromUnicodeL(foreign, testUnicode1)); //testing conversion from Unicode |
|
129 test(error == KErrOverflow ); |
|
130 |
|
131 // ConvertFromUnicodeL - test 1 character to long leaves |
|
132 _LIT16(longUnicode2, "FilenameEx\x3122"); |
|
133 const TDesC16& testUnicode2(longUnicode2); |
|
134 foreign.Zero(); |
|
135 error = KErrNone; |
|
136 TRAP( error, ConvertFromUnicodeL(foreign, testUnicode2)); //testing conversion from Unicode |
|
137 test(error == KErrOverflow ); |
|
138 |
|
139 // ConvertFromUnicodeL - test 11 character does not leave |
|
140 _LIT16(longUnicode3, "FilenameExt"); |
|
141 const TDesC16& testUnicode3(longUnicode3); |
|
142 foreign.Zero(); |
|
143 error = KErrNone; |
|
144 TRAP( error, ConvertFromUnicodeL(foreign, testUnicode3)); //testing conversion from Unicode |
|
145 test(error == KErrNone ); |
|
146 |
|
147 // check ConvertToUnicodeL leaves when the buffer is too small |
|
148 TBuf16<6> unicodeBuffer; |
|
149 _LIT8(sampletext, "this is far to big to fit"); |
|
150 const TDesC8& sample(sampletext); |
|
151 |
|
152 unicodeBuffer.Zero(); |
|
153 error = KErrNone; |
|
154 TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample)); //testing conversion to Unicode |
|
155 test(error==KErrOverflow); |
|
156 |
|
157 // test 6 characters does NOT leave |
|
158 _LIT8( chars6, "abcdef"); |
|
159 const TDesC8& sample6(chars6); |
|
160 unicodeBuffer.Zero(); |
|
161 error = KErrNone; |
|
162 TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample6)); //testing conversion to Unicode |
|
163 test(error==KErrNone); |
|
164 |
|
165 // test 7 characters does leave |
|
166 _LIT8( chars7, "abcdefg"); |
|
167 const TDesC8& sample7(chars7); |
|
168 unicodeBuffer.Zero(); |
|
169 error = KErrNone; |
|
170 TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample7)); //testing conversion to Unicode |
|
171 test(error==KErrOverflow); |
|
172 |
|
173 // test when 7 foreign characters fits in 5 unicode it does NOT leave |
|
174 _LIT8( CP950_sample, "\x32\x80\xA1\x70\xC1\x7F\xA7"); |
|
175 const TDesC8& sample7to5(CP950_sample); |
|
176 unicodeBuffer.Zero(); |
|
177 error = KErrNone; |
|
178 TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample7to5)); //testing conversion to Unicode |
|
179 test(error==KErrNone); |
|
180 |
|
181 lib.Close(); |
|
182 } |
|
183 |
|
184 |
|
185 /** |
|
186 @SYMTestCaseID SYSLIB-FATCHARSETCONV-CT-1847-0003 |
|
187 @SYMTestCaseDesc Tests API behaviours of UnicodeConv class as part of INC090073 |
|
188 @SYMTestPriority High |
|
189 @SYMTestActions Tests for correct character conversion on certain chinese characters for CP936 |
|
190 @SYMTestExpectedResults Test must not fail |
|
191 */ |
|
192 void TestINC090073() |
|
193 { |
|
194 test.Next(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1847-0003 ")); |
|
195 _LIT16(unicode, "\x7C91\x8026\x8160\x7633\x6DFC\x715C\x6600\x9785\x86D8\x7A37\x61A9\x80B1\x86A3\x89E5\x80F2\x9B48\x6C19\x7B71\x946B\x6B46\x6615"); |
|
196 _LIT8(CP950Code, "\xD3\x4A\xBD\xA2\xDF\x73\xEA\x6F\xD9\xE7\xB7\xD4\xA9\xFB\xBB\xDF\xDB\xB1\xBD\x5E\xBE\xCD\xAA\xD0\xB0\x47\xDF\xFD\xD3\x6A\xEF\x69\xCB\x49\xDF\x4E\xF8\xCA\xDD\xF5\xA9\xFD"); |
|
197 |
|
198 RLibrary lib; |
|
199 |
|
200 const TUidType serverUid(KNullUid,KNullUid,KPluginUid); |
|
201 // load the dll |
|
202 TInt returnValue = lib.Load(KName,serverUid); |
|
203 test(returnValue==0); |
|
204 |
|
205 // get a pointer to the specified ordinal function and call it |
|
206 TLibraryFunction function1 = lib.Lookup(1); |
|
207 |
|
208 //cast the function pointer f to a function of type void with two arguments |
|
209 typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); |
|
210 TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1); |
|
211 |
|
212 TBuf8<50> foreign1; |
|
213 |
|
214 foreign1.Zero(); |
|
215 const TDesC16& unicode1(unicode); |
|
216 TRAPD(err,(*aConvertFromUnicodeL)(foreign1, unicode1)); //testing conversion from Unicode |
|
217 test(err==0); |
|
218 TInt error = foreign1.Compare(CP950Code); |
|
219 test(error==0); |
|
220 foreign1.Zero(); |
|
221 |
|
222 lib.Close(); |
|
223 } |
|
224 |
|
225 void OOMTest() |
|
226 { |
|
227 test.Next(_L("OOM testing")); |
|
228 TInt err, tryCount = 0; |
|
229 do |
|
230 { |
|
231 __UHEAP_MARK; |
|
232 // find out the number of open handles |
|
233 TInt startProcessHandleCount; |
|
234 TInt startThreadHandleCount; |
|
235 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
236 |
|
237 // Setting Heap failure for OOM test |
|
238 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); |
|
239 |
|
240 TRAP(err,Test()); |
|
241 |
|
242 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
243 |
|
244 // check that no handles have leaked |
|
245 TInt endProcessHandleCount; |
|
246 TInt endThreadHandleCount; |
|
247 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
248 |
|
249 test(startProcessHandleCount == endProcessHandleCount); |
|
250 test(startThreadHandleCount == endThreadHandleCount); |
|
251 |
|
252 __UHEAP_MARKEND; |
|
253 }while (err == KErrNoMemory); |
|
254 |
|
255 test(err == KErrNone); |
|
256 test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount); |
|
257 } |
|
258 |
|
259 |
|
260 LOCAL_C void DoE32MainL() |
|
261 { |
|
262 Test(); |
|
263 TestINC090073(); |
|
264 TestINC080460(); |
|
265 OOMTest(); |
|
266 } |
|
267 |
|
268 GLDEF_C TInt E32Main() |
|
269 { |
|
270 __UHEAP_MARK; |
|
271 |
|
272 test.Title(); |
|
273 test.Start(_L("CP950 test...")); |
|
274 |
|
275 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
276 TRAPD(error, DoE32MainL()); |
|
277 delete trapCleanup; |
|
278 |
|
279 test.End(); |
|
280 test.Close(); |
|
281 |
|
282 __UHEAP_MARKEND; |
|
283 return error; |
|
284 } |