|
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 "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 <ecom/ecom.h> |
|
18 #include "Interface.h" // ECOM CExampleInterface class |
|
19 #include "exampleNine.h" // CRoguePlugin class |
|
20 |
|
21 |
|
22 //Test utils for copying plugin to C |
|
23 #include "EcomTestUtils.h" |
|
24 |
|
25 _LIT(KTestTitle, "DEF094656 Rogue plugin should not override build-in"); |
|
26 |
|
27 LOCAL_D RTest TheTest(_L("Rogue plugin with duplicated Impl. UID")); |
|
28 |
|
29 LOCAL_D TBool correctTypeCastPassed = EFalse; |
|
30 |
|
31 _LIT(KRoguePluginDllOnZ, "Z:\\RAMOnly\\exampleNine.dll"); |
|
32 _LIT(KRoguePluginDllOnC, "C:\\sys\\bin\\exampleNine.dll"); |
|
33 _LIT(KRoguePluginRscOnZ, "Z:\\RAMOnly\\exampleNine.rsc"); |
|
34 _LIT(KRoguePluginRscOnC, "C:\\resource\\plugins\\exampleNine.rsc"); |
|
35 |
|
36 /** Copy the rogue plugin to C: drive |
|
37 */ |
|
38 LOCAL_C void CopyPluginsL() |
|
39 { |
|
40 // Copy the dlls and .rsc files on to RAM |
|
41 EComTestUtils::FileManCopyFileL(KRoguePluginDllOnZ, KRoguePluginDllOnC); |
|
42 EComTestUtils::FileManCopyFileL(KRoguePluginRscOnZ, KRoguePluginRscOnC); |
|
43 // Pause in case ECOM server is already up and running and needs |
|
44 // time to activate the scanning timer active object. |
|
45 User::After(3000000); |
|
46 } |
|
47 |
|
48 /** Remove resource file and dll copied to C: drive |
|
49 */ |
|
50 LOCAL_C void DeleteTestPlugin() |
|
51 { |
|
52 TRAPD(ignoreErr, EComTestUtils::FileManDeleteFileL(KRoguePluginRscOnC)); |
|
53 TRAP(ignoreErr, EComTestUtils::RLoaderDeleteFileL(KRoguePluginDllOnC)); |
|
54 } |
|
55 |
|
56 /** |
|
57 Test rogue plugin trying to override a ROM based plugin by |
|
58 duplicating the legitimate DLL's implementation UID (different |
|
59 interface UID so that ECOM not treat it as an update). |
|
60 |
|
61 @SYMTestCaseID SYSLIB-ECOM-CIT-3161 |
|
62 @SYMTestCaseDesc Copy a rogue plugin to C drive. This plugin duplicates the |
|
63 implementation UID of a built-in dll. Test if the rogue |
|
64 plugin will over shadow the built-in dll. |
|
65 @SYMTestPriority High |
|
66 @SYMTestActions 1. copy the rsc and dll of the rogue plugin to C: |
|
67 2. Use the CreateImplementation API which does not specify |
|
68 the i/f UID to instantiate the built-in implementation. |
|
69 Test the instance works normally. |
|
70 3. Repeat 2 but instantiate the pointer as the rogue plugin |
|
71 class. Pass NULL as the initialising param in the call |
|
72 to CreateImplementationL. Because the actual plugin returned by |
|
73 ECOM needs this initParam, KERN-EXEC 3 panic occurs. |
|
74 @SYMTestExpectedResults The test must not fail. |
|
75 @SYMDEF DEF094656 |
|
76 */ |
|
77 LOCAL_C void DEF094656_TestCaseL() |
|
78 { |
|
79 // DuplicateImplUidTestL SYSLIB-ECOM-CT-3157 is similar to this testcase. |
|
80 // CT-3157 tests higher driver letter > lower driver letter, |
|
81 // and lower i/f UID > higher i/f UID. |
|
82 |
|
83 // Note that this function is expected to panic. Hence not bother |
|
84 // with __UHEAP_MARK. |
|
85 |
|
86 //Check if the rogue plugin is in the registry. |
|
87 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CIT-3161 ")); |
|
88 RImplInfoPtrArray ifArray; |
|
89 REComSession::ListImplementationsL(KRogueInterfaceUid, ifArray); |
|
90 |
|
91 TInt count = ifArray.Count(); |
|
92 TheTest.Printf(_L("Found %d implementations of I/f 0x%X"), count, KRogueInterfaceUid.iUid); |
|
93 |
|
94 TheTest(count == 1); |
|
95 TheTest(KRogueImplUid == ifArray[0]->ImplementationUid()); |
|
96 |
|
97 ifArray.ResetAndDestroy(); |
|
98 |
|
99 TUid dtor_key; |
|
100 // Initialisation parameter needed by CImplementationClassOne |
|
101 CExampleInterface::TExampleInterfaceInitParams initParams; |
|
102 initParams.integer = 0; |
|
103 initParams.descriptor = NULL; |
|
104 |
|
105 // First test creating the correct class. |
|
106 CExampleInterface* correctDll = reinterpret_cast<CExampleInterface*>( |
|
107 REComSession::CreateImplementationL(KRogueImplUid, |
|
108 dtor_key, |
|
109 &initParams) ); |
|
110 TheTest(correctDll != NULL); |
|
111 |
|
112 TUid testUid = correctDll->ImplId(); |
|
113 // the example plugins should return the value 10009DC3. |
|
114 TheTest(testUid == KRogueImplUid); |
|
115 |
|
116 REComSession::DestroyedImplementation(dtor_key); |
|
117 delete correctDll; |
|
118 |
|
119 // Indicate to thread creator that first stage test passed. |
|
120 correctTypeCastPassed = ETrue; |
|
121 |
|
122 // This create should crash because the plugin returned by |
|
123 // ECOM is really CImplementationClassOne which needs a properly |
|
124 // constructed initParam. |
|
125 CRoguePlugin* wrongDll = reinterpret_cast<CRoguePlugin*>( |
|
126 REComSession::CreateImplementationL(KRogueImplUid, |
|
127 dtor_key, |
|
128 NULL) ); |
|
129 |
|
130 // If gets here then someone has changed CImplementationClassOne::NewL |
|
131 // or 10009DC3 has been updated by another implementation. |
|
132 if (wrongDll) |
|
133 { |
|
134 REComSession::DestroyedImplementation(dtor_key); |
|
135 delete wrongDll; |
|
136 } |
|
137 |
|
138 REComSession::FinalClose(); |
|
139 |
|
140 TheTest(EFalse); |
|
141 } |
|
142 |
|
143 LOCAL_C void ThreadMainL() |
|
144 { |
|
145 CConsoleBase* newConsole = Console::NewL(KTestTitle, |
|
146 TSize(KConsFullScreen, KConsFullScreen)); |
|
147 |
|
148 // Thread creator needs to save the original console because this |
|
149 // thread is expected to crash, hence cannot cleanup. |
|
150 TheTest.SetConsole(newConsole); |
|
151 DEF094656_TestCaseL(); |
|
152 TheTest.SetConsole(NULL); |
|
153 |
|
154 delete newConsole; |
|
155 } |
|
156 |
|
157 LOCAL_C TInt ThreadFunc(TAny*) |
|
158 { |
|
159 __UHEAP_MARK; |
|
160 CTrapCleanup* threadcleanup = CTrapCleanup::New(); |
|
161 TRAPD(err, ThreadMainL()); |
|
162 delete threadcleanup; |
|
163 __UHEAP_MARKEND; |
|
164 return err; |
|
165 } |
|
166 |
|
167 LOCAL_C void RunTestThreadL() |
|
168 { |
|
169 __UHEAP_MARK; |
|
170 |
|
171 CopyPluginsL(); |
|
172 |
|
173 _LIT(KThreadName, "RoguePluginTest"); |
|
174 |
|
175 TBool jit = User::JustInTime(); |
|
176 User::SetJustInTime(EFalse); |
|
177 |
|
178 TheTest.Start(KTestTitle); |
|
179 |
|
180 // Save the console because the created thread must use its own |
|
181 // console. |
|
182 CConsoleBase* savedConsole = TheTest.Console(); |
|
183 |
|
184 RThread tt; |
|
185 TInt err = tt.Create(KThreadName, &ThreadFunc, KDefaultStackSize, |
|
186 KMinHeapSize, 0x100000, 0); |
|
187 User::LeaveIfError(err); |
|
188 |
|
189 TRequestStatus status; |
|
190 tt.Logon(status); |
|
191 tt.Resume(); |
|
192 |
|
193 User::WaitForRequest(status); |
|
194 |
|
195 // restore console |
|
196 TheTest.SetConsole(savedConsole); |
|
197 |
|
198 TExitCategoryName exitcategory = tt.ExitCategory(); |
|
199 TExitType exittype = tt.ExitType(); |
|
200 TInt exitReason = tt.ExitReason(); |
|
201 tt.Close(); |
|
202 |
|
203 TheTest.Printf(_L("Thread exit type %d, reason %d, category %S"), exittype, exitReason, &exitcategory); |
|
204 |
|
205 User::SetJustInTime(jit); |
|
206 DeleteTestPlugin(); |
|
207 |
|
208 // Check if tt thread passes this checkpoint |
|
209 TheTest(correctTypeCastPassed); |
|
210 |
|
211 // Check if tt thread die of KERN-EXEC. |
|
212 _LIT(KKernExec, "KERN-EXEC"); |
|
213 TheTest(exitcategory.CompareF(KKernExec) == 0); |
|
214 |
|
215 TheTest.End(); |
|
216 TheTest.Close(); |
|
217 |
|
218 __UHEAP_MARKEND; |
|
219 } |
|
220 |
|
221 GLDEF_C TInt E32Main() |
|
222 { |
|
223 __UHEAP_MARK; |
|
224 |
|
225 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
226 CActiveScheduler* scheduler = new(ELeave)CActiveScheduler; |
|
227 CActiveScheduler::Install(scheduler); |
|
228 |
|
229 TRAP_IGNORE( RunTestThreadL() ); |
|
230 |
|
231 delete scheduler; |
|
232 delete cleanup; |
|
233 |
|
234 __UHEAP_MARKEND; |
|
235 return KErrNone; |
|
236 } |