|
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_CP1253.exe")); |
|
20 |
|
21 _LIT16(Uni_1, "\x0053\x0059\x004D\x0042\x0049\x0041\x004E\xFFFF\x20AC\x00E8\x017B"); |
|
22 _LIT8(CP1253_1, "\x53\x59\x4D\x42\x49\x41\x4E\x5F\x80\x5F\x5F"); |
|
23 _LIT16(Uni_2, "\x0385\xFFFD\x00AD\xFFFD"); |
|
24 _LIT8(CP1253_2, "\xA1\x98\xAD\x90"); |
|
25 |
|
26 _LIT(KName,"CP1253"); |
|
27 const TUid KPluginUid={0x10206A99}; |
|
28 |
|
29 |
|
30 // Used for supressing warning in OOM tests |
|
31 #define __UNUSED_VAR(var) var = var |
|
32 |
|
33 /** |
|
34 @SYMTestCaseID SYSLIB-FATCHARSETCONV-CT-1786 |
|
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 RLibrary lib; |
|
43 |
|
44 const TUidType serverUid(KNullUid,KNullUid,KPluginUid); |
|
45 // load the dll |
|
46 TInt returnValue = lib.Load(KName,serverUid); |
|
47 test(returnValue==0); |
|
48 |
|
49 // get a pointer to the specified ordinal function and call it |
|
50 TLibraryFunction function1 = lib.Lookup(1); |
|
51 TLibraryFunction function2 = lib.Lookup(2); |
|
52 TLibraryFunction function3 = lib.Lookup(3); |
|
53 |
|
54 //cast the function pointer f to a function of type void with two arguments |
|
55 typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); |
|
56 TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1); |
|
57 |
|
58 typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&); |
|
59 TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2); |
|
60 |
|
61 typedef TBool (*TIsLegalShortNameCharacter)(TUint); |
|
62 TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast <TIsLegalShortNameCharacter> (function3); |
|
63 |
|
64 |
|
65 TBuf8<15> foreign1; |
|
66 TBuf16<15> unicode2; |
|
67 |
|
68 const TDesC16& unicode1(Uni_1); |
|
69 (*aConvertFromUnicodeL)(foreign1, unicode1); //testing conversion from Unicode |
|
70 TInt error = foreign1.Compare(CP1253_1); |
|
71 test(error==0); |
|
72 foreign1.Zero(); |
|
73 |
|
74 const TDesC8& foreign2(CP1253_2); |
|
75 (*aConvertToUnicodeL)(unicode2,foreign2); //testing conversion to Unicode |
|
76 error = unicode2.Compare(Uni_2); |
|
77 test(error==0); |
|
78 unicode2.Zero(); |
|
79 |
|
80 |
|
81 //testing for legal short name character |
|
82 TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character |
|
83 test(result==1); |
|
84 result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character |
|
85 test(result==0); |
|
86 result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character |
|
87 test(result==0); |
|
88 |
|
89 lib.Close(); |
|
90 } |
|
91 |
|
92 void OOMTest() |
|
93 { |
|
94 test.Next(_L("OOM testing")); |
|
95 TInt err, tryCount = 0; |
|
96 do |
|
97 { |
|
98 __UHEAP_MARK; |
|
99 // find out the number of open handles |
|
100 TInt startProcessHandleCount; |
|
101 TInt startThreadHandleCount; |
|
102 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
103 |
|
104 // Setting Heap failure for OOM test |
|
105 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); |
|
106 |
|
107 TRAP(err,Test()); |
|
108 |
|
109 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
110 |
|
111 // check that no handles have leaked |
|
112 TInt endProcessHandleCount; |
|
113 TInt endThreadHandleCount; |
|
114 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
115 |
|
116 test(startProcessHandleCount == endProcessHandleCount); |
|
117 test(startThreadHandleCount == endThreadHandleCount); |
|
118 |
|
119 __UHEAP_MARKEND; |
|
120 }while (err == KErrNoMemory); |
|
121 |
|
122 test(err == KErrNone); |
|
123 test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount); |
|
124 } |
|
125 |
|
126 |
|
127 LOCAL_C void DoE32MainL() |
|
128 { |
|
129 Test(); |
|
130 OOMTest(); |
|
131 } |
|
132 |
|
133 GLDEF_C TInt E32Main() |
|
134 { |
|
135 __UHEAP_MARK; |
|
136 |
|
137 test.Title(); |
|
138 test.Start(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1786 CP1253 tests... ")); |
|
139 |
|
140 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
141 TRAPD(error, DoE32MainL()); |
|
142 delete trapCleanup; |
|
143 |
|
144 test.End(); |
|
145 test.Close(); |
|
146 |
|
147 __UHEAP_MARKEND; |
|
148 return error; |
|
149 } |