|
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_CP936.exe")); |
|
20 |
|
21 _LIT16(Uni_1, "\x0053\x0059\x004D\x3125\x312F\x3122\xFFFF\x9673\xFA29"); |
|
22 _LIT8(CP936_1, "\x53\x59\x4D\xA8\xE5\x5F\xA8\xE2\x5F\xEA\x90\xFE\x4F"); |
|
23 _LIT16(Uni_2, "\x0032\x20AC\xFFFD\xFFFD\x7FB1"); |
|
24 _LIT8(CP936_2, "\x32\x80\xA1\x70\xC1\x7F\xC1\x7E"); |
|
25 |
|
26 _LIT(KName,"CP936"); |
|
27 const TUid KPluginUid={0x10206A91}; |
|
28 |
|
29 |
|
30 // Used for supressing warning in OOM tests |
|
31 #define __UNUSED_VAR(var) var = var |
|
32 |
|
33 /** |
|
34 @SYMTestCaseID SYSLIB-FATCHARSETCONV-CT-1778 |
|
35 @SYMTestCaseDesc Tests API behaviours of UnicodeConv class |
|
36 @SYMTestPriority High |
|
37 @SYMTestActions Tests for conversions from/to Unicode, using a function pointer |
|
38 @SYMTestExpectedResults Test must not fail |
|
39 */ |
|
40 void Test() |
|
41 { |
|
42 test.Next(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1778 ")); |
|
43 RLibrary lib; |
|
44 |
|
45 const TUidType serverUid(KNullUid,KNullUid,KPluginUid); |
|
46 // load the dll |
|
47 TInt returnValue = lib.Load(KName,serverUid); |
|
48 test(returnValue==0); |
|
49 |
|
50 // get a pointer to the specified ordinal function and call it |
|
51 TLibraryFunction function1 = lib.Lookup(1); |
|
52 TLibraryFunction function2 = lib.Lookup(2); |
|
53 TLibraryFunction function3 = lib.Lookup(3); |
|
54 |
|
55 //cast the function pointer f to a function of type void with two arguments |
|
56 typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); |
|
57 TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1); |
|
58 |
|
59 typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&); |
|
60 TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2); |
|
61 |
|
62 typedef TBool (*TIsLegalShortNameCharacter)(TUint); |
|
63 TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast <TIsLegalShortNameCharacter> (function3); |
|
64 |
|
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(CP936_1); |
|
72 test(error==0); |
|
73 foreign1.Zero(); |
|
74 |
|
75 const TDesC8& foreign2(CP936_2); |
|
76 (*aConvertToUnicodeL)(unicode2,foreign2); //testing conversion to Unicode |
|
77 error = unicode2.Compare(Uni_2); |
|
78 test(error==0); |
|
79 unicode2.Zero(); |
|
80 |
|
81 |
|
82 //testing for legal short name character |
|
83 TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character |
|
84 test(result==1); |
|
85 result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character |
|
86 test(result==0); |
|
87 result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character |
|
88 test(result==0); |
|
89 result = (*aIsLegalShortNameCharacter)(0x4E02); //testing for a double byte character |
|
90 test(result==1); |
|
91 |
|
92 lib.Close(); |
|
93 } |
|
94 |
|
95 /** |
|
96 @SYMTestCaseID SYSLIB-FATCHARSETCONV-CT-1847-0001 |
|
97 @SYMTestCaseDesc Tests API behaviours of UnicodeConv class as part of INC090073 |
|
98 @SYMTestPriority High |
|
99 @SYMTestActions Tests for correct character conversion on certain chinese characters for CP936 |
|
100 @SYMTestExpectedResults Test must not fail |
|
101 */ |
|
102 void TestINC090073() |
|
103 { |
|
104 test.Next(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1847-0001 ")); |
|
105 _LIT16(unicode, "\x7CCD\x74EF\x8026\x8F8F\x94F3\x7633\x6DFC\x9785\x7F81\x7A37\x61A9\x80B1\x86A3\x89E5\x80F2\x9B48\x9E47\x6C19\x7B71\x946B\x6B46\x6615"); |
|
106 _LIT8(CP932Code, "\xF4\xD9\xEA\xB1\xF1\xEE\xEA\xA3\xEF\xA5\xF1\xAC\xED\xB5\xF7\xB1\xEE\xBF\xF0\xA2\xED\xAC\xEB\xC5\xF2\xBC\xF6\xA1\xEB\xDC\xF7\xCC\xF0\xC2\xEB\xAF\xF3\xE3\xF6\xCE\xEC\xA7\xEA\xBF"); |
|
107 |
|
108 RLibrary lib; |
|
109 |
|
110 const TUidType serverUid(KNullUid,KNullUid,KPluginUid); |
|
111 // load the dll |
|
112 TInt returnValue = lib.Load(KName,serverUid); |
|
113 test(returnValue==0); |
|
114 |
|
115 // get a pointer to the specified ordinal function and call it |
|
116 TLibraryFunction function1 = lib.Lookup(1); |
|
117 |
|
118 |
|
119 //cast the function pointer f to a function of type void with two arguments |
|
120 typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); |
|
121 TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1); |
|
122 |
|
123 TBuf8<50> foreign1; |
|
124 |
|
125 foreign1.Zero(); |
|
126 const TDesC16& unicode1(unicode); |
|
127 TRAPD(err,(*aConvertFromUnicodeL)(foreign1, unicode1)); //testing conversion from Unicode |
|
128 test(err==0); |
|
129 TInt error = foreign1.Compare(CP932Code); |
|
130 test(error==0); |
|
131 foreign1.Zero(); |
|
132 |
|
133 lib.Close(); |
|
134 } |
|
135 |
|
136 void OOMTest() |
|
137 { |
|
138 test.Next(_L("OOM testing")); |
|
139 TInt err, tryCount = 0; |
|
140 do |
|
141 { |
|
142 __UHEAP_MARK; |
|
143 // find out the number of open handles |
|
144 TInt startProcessHandleCount; |
|
145 TInt startThreadHandleCount; |
|
146 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
147 |
|
148 // Setting Heap failure for OOM test |
|
149 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); |
|
150 |
|
151 TRAP(err,Test()); |
|
152 |
|
153 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
154 |
|
155 // check that no handles have leaked |
|
156 TInt endProcessHandleCount; |
|
157 TInt endThreadHandleCount; |
|
158 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
159 |
|
160 test(startProcessHandleCount == endProcessHandleCount); |
|
161 test(startThreadHandleCount == endThreadHandleCount); |
|
162 |
|
163 __UHEAP_MARKEND; |
|
164 }while (err == KErrNoMemory); |
|
165 |
|
166 test(err == KErrNone); |
|
167 test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount); |
|
168 } |
|
169 |
|
170 |
|
171 LOCAL_C void DoE32MainL() |
|
172 { |
|
173 __UHEAP_MARK; |
|
174 |
|
175 Test(); |
|
176 TestINC090073(); |
|
177 OOMTest(); |
|
178 |
|
179 __UHEAP_MARKEND; |
|
180 } |
|
181 |
|
182 GLDEF_C TInt E32Main() |
|
183 { |
|
184 __UHEAP_MARK; |
|
185 |
|
186 test.Title(); |
|
187 test.Start(_L("CP936 test...")); |
|
188 |
|
189 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
190 TRAPD(error, DoE32MainL()); |
|
191 test(error==KErrNone); |
|
192 |
|
193 delete trapCleanup; |
|
194 |
|
195 test.End(); |
|
196 test.Close(); |
|
197 |
|
198 __UHEAP_MARKEND; |
|
199 return error; |
|
200 } |