|
1 // Copyright (c) 2005-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 <f32file.h> |
|
18 #include <ecom/ecom.h> |
|
19 #include <startup.hrh> |
|
20 #include "EComSessionAux.h" |
|
21 #include "EcomTestUtils.h" |
|
22 #include "EcomTestIniFileUtils.h" |
|
23 #include "EcomTestCompTestabilityUtils.h" |
|
24 |
|
25 static RFs TheFs; |
|
26 static RTest TheTest(_L("T_EcomSsaEnabled")); |
|
27 |
|
28 _LIT(KEComExampleDllOnZ, "Z:\\RAMOnly\\EComExample3.dll"); |
|
29 _LIT(KEComExampleDllOnC, "C:\\sys\\bin\\EComExample3.dll"); |
|
30 _LIT(KEComPluginRscOnZ, "Z:\\RAMOnly\\EComExample3.rsc"); |
|
31 _LIT(KEComPluginRscOnC, "C:\\resource\\plugins\\EComExample3.rsc"); |
|
32 |
|
33 #ifdef __ECOM_SERVER_TESTABILITY__ |
|
34 |
|
35 _LIT8(KImplementationDataOnZ, "RomOnly"); |
|
36 _LIT8(KImplementationDataOnC, "RamOnly"); |
|
37 |
|
38 #endif |
|
39 |
|
40 // |
|
41 // |
|
42 //Test macroes and functions |
|
43 // |
|
44 // |
|
45 #ifdef __ECOM_SERVER_TESTABILITY__ |
|
46 |
|
47 static void Check(TInt aValue, TInt aLine) |
|
48 { |
|
49 if(!aValue) |
|
50 { |
|
51 TheTest(EFalse, aLine); |
|
52 } |
|
53 } |
|
54 #define TEST(arg) ::Check((arg), __LINE__) |
|
55 |
|
56 #endif |
|
57 |
|
58 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
59 { |
|
60 if(aValue != aExpected) |
|
61 { |
|
62 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
63 TheTest(EFalse, aLine); |
|
64 } |
|
65 } |
|
66 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
67 |
|
68 // |
|
69 // |
|
70 //Helper functions |
|
71 // |
|
72 // |
|
73 |
|
74 /** |
|
75 * Add plugins to C: drive so they can be discovered during NonStatic discovery |
|
76 * state. |
|
77 */ |
|
78 static void SetupFiles() |
|
79 { |
|
80 TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExampleDllOnZ, KEComExampleDllOnC)); |
|
81 TEST2(err, KErrNone); |
|
82 |
|
83 TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginRscOnZ, KEComPluginRscOnC)); |
|
84 TEST2(err, KErrNone); |
|
85 } |
|
86 |
|
87 /** |
|
88 * Remove the plugins from C: drive so we can leave a clean environment for |
|
89 * the next test. |
|
90 */ |
|
91 static void CleanupFiles() |
|
92 { |
|
93 TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComExampleDllOnC)); |
|
94 TEST2(err, KErrNone); |
|
95 |
|
96 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginRscOnC)); |
|
97 TEST2(err, KErrNone); |
|
98 } |
|
99 |
|
100 static void KillEComServerL() |
|
101 { |
|
102 //Need to ensure that the EComServer process is killed before even starting this test by using |
|
103 //the EComTestUtils library |
|
104 _LIT(KEComServerProcessName,"ecomserver"); |
|
105 TRAPD(error, EComTestUtils::KillProcessL(KEComServerProcessName)); |
|
106 error=error; |
|
107 } |
|
108 |
|
109 #ifdef __ECOM_SERVER_TESTABILITY__ |
|
110 /** |
|
111 * Test if the requested plugin is discovered |
|
112 *@param aInterfaceUid A UID specifying the required interface. |
|
113 *@param aResolutionParameters A descriptor specifying any additional |
|
114 * implementation characteristics to be fulfilled. |
|
115 *@return return TRUE if plugin exists |
|
116 */ |
|
117 static TBool TestForPlugin(TUid aInterfaceUid, |
|
118 const TDesC8& aDataType) |
|
119 { |
|
120 TBool result = EFalse; |
|
121 RImplInfoPtrArray aImplInfoArray; |
|
122 TEComResolverParams resolverParams; |
|
123 resolverParams.SetDataType(aDataType); |
|
124 resolverParams.SetGenericMatch(ETrue); // Allow wildcard matching |
|
125 |
|
126 REComSession::ListImplementationsL( |
|
127 aInterfaceUid, |
|
128 resolverParams, |
|
129 aImplInfoArray); |
|
130 |
|
131 if(aImplInfoArray.Count() > 0) |
|
132 { |
|
133 result = ETrue; |
|
134 } |
|
135 |
|
136 aImplInfoArray.ResetAndDestroy(); |
|
137 |
|
138 return result; |
|
139 } |
|
140 #endif |
|
141 |
|
142 // |
|
143 // |
|
144 //Test functions |
|
145 // |
|
146 // |
|
147 #ifdef __ECOM_SERVER_TESTABILITY__ |
|
148 /** |
|
149 Wrapper function to call change and process startup state test functions |
|
150 and check the current startup state is matched with the expected startup state. |
|
151 @param aState A startup state to be set in ECOM |
|
152 @param aExpectedState An expected startup state in ECOM |
|
153 */ |
|
154 LOCAL_C void ChangeAndProcessStartupState(TInt aState, TInt aExpectedState) |
|
155 { |
|
156 |
|
157 TInt state = EStartupStateUndefined; |
|
158 TRAPD(err, ChangeStartupStateL(aState)); |
|
159 TEST2(err, KErrNone); |
|
160 TRAP(err, ProcessCurrentStartupStateL()); |
|
161 TEST2(err, KErrNone); |
|
162 TRAP(err, state = GetCurrentStartupStateL()); |
|
163 TEST2(err, KErrNone); |
|
164 TEST2(state, aExpectedState); |
|
165 } |
|
166 |
|
167 /** |
|
168 @SYMTestCaseID SYSLIB-ECOM-CIT-0188 |
|
169 @SYMTestCaseDesc The SSA is enabled, the ECOM will do a staged discovery with the |
|
170 simulated Domain Manager. |
|
171 @SYMTestPriority High |
|
172 @SYMTestActions Check the plugins and the state of ECOM are correct at each state |
|
173 using client API GetCurrentStartupStateL and ListImplementationsL. |
|
174 @SYMTestExpectedResults The test must not fail. |
|
175 @SYMPREQ PREQ967 |
|
176 */ |
|
177 LOCAL_C void TestEcomSsaEnabledL() |
|
178 { |
|
179 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CIT-0188 ")); |
|
180 // Set up for heap leak checking |
|
181 __UHEAP_MARK; |
|
182 |
|
183 // and leaking thread handles |
|
184 TInt startProcessHandleCount; |
|
185 TInt startThreadHandleCount; |
|
186 TInt endProcessHandleCount; |
|
187 TInt endThreadHandleCount; |
|
188 // Test Starts... |
|
189 |
|
190 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
191 |
|
192 TUid ifUid = {0x10009DC0}; |
|
193 |
|
194 EnableSsa(TheTest, TheFs); |
|
195 |
|
196 //Change the state to a user defined state then |
|
197 //check that current state is still EStartupStateUndefined |
|
198 ChangeAndProcessStartupState(EStartupStateUndefined+1,EStartupStateUndefined); |
|
199 |
|
200 //Change the state to a user defined state then |
|
201 //check that current state is still EStartupStateUndefined |
|
202 ChangeAndProcessStartupState(EStartupStateCriticalStatic-1,EStartupStateUndefined ); |
|
203 |
|
204 //Change the state to EStartupStateCriticalStatic then |
|
205 //check that current state is EStartupStateCriticalStatic |
|
206 //check that a plugin from RO drive is discovered |
|
207 ChangeAndProcessStartupState(EStartupStateCriticalStatic,EStartupStateCriticalStatic ); |
|
208 TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnZ())); |
|
209 |
|
210 //Change the state to a user defined state then |
|
211 //check that current state is still EStartupStateCriticalStatic |
|
212 ChangeAndProcessStartupState(EStartupStateCriticalStatic+1,EStartupStateCriticalStatic); |
|
213 |
|
214 //Change the state to a user defined state then |
|
215 //check that current state is still EStartupStateCriticalStatic |
|
216 ChangeAndProcessStartupState(EStartupStateCriticalDynamic-1,EStartupStateCriticalStatic); |
|
217 |
|
218 //Change the state to EStartupStateCriticalDynamic then |
|
219 //check that current state is EStartupStateCriticalDynamic |
|
220 ChangeAndProcessStartupState(EStartupStateCriticalDynamic, EStartupStateCriticalDynamic); |
|
221 |
|
222 //Change the state to a user defined state then |
|
223 //check that current state is still EStartupStateCriticalDynamic |
|
224 ChangeAndProcessStartupState(EStartupStateCriticalDynamic+1, EStartupStateCriticalDynamic); |
|
225 |
|
226 //Change the state to a user defined state then |
|
227 //check that current state is still EStartupStateCriticalDynamic |
|
228 ChangeAndProcessStartupState(EStartupStateNonCritical-1,EStartupStateCriticalDynamic); |
|
229 |
|
230 //Change the state to EStartupStateNonCritical then |
|
231 //check that current state is EStartupStateNonCritical |
|
232 //check that a plugin from RO drive is discovered |
|
233 ChangeAndProcessStartupState(EStartupStateNonCritical,EStartupStateNonCritical ); |
|
234 TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnC())); |
|
235 |
|
236 //Change the state to a user defined state then |
|
237 //check that current state is still EStartupStateNonCritical |
|
238 ChangeAndProcessStartupState(EStartupStateNonCritical+1, EStartupStateNonCritical); |
|
239 |
|
240 REComSession::FinalClose(); |
|
241 |
|
242 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
243 |
|
244 TEST(startProcessHandleCount == endProcessHandleCount); |
|
245 TEST(startThreadHandleCount == endThreadHandleCount); |
|
246 |
|
247 // Test Ends... |
|
248 |
|
249 __UHEAP_MARKEND; |
|
250 } |
|
251 #endif //__ECOM_SERVER_TESTABILITY__ |
|
252 |
|
253 #ifdef __ECOM_SERVER_TESTABILITY__ |
|
254 // Type definition for pointer to member function. |
|
255 // Used in calling T_EcomSsaEnabled test functions. |
|
256 typedef void (*ClassFuncPtrL) (void); |
|
257 |
|
258 /** |
|
259 Wrapper function to call all test functions |
|
260 @param testFunc pointer to test function |
|
261 @param aTestDesc test function name |
|
262 */ |
|
263 LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc) |
|
264 { |
|
265 TheTest.Next(aTestDesc); |
|
266 |
|
267 __UHEAP_MARK; |
|
268 // find out the number of open handles |
|
269 TInt startProcessHandleCount; |
|
270 TInt startThreadHandleCount; |
|
271 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
272 |
|
273 testFuncL(); |
|
274 |
|
275 // check that no handles have leaked |
|
276 TInt endProcessHandleCount; |
|
277 TInt endThreadHandleCount; |
|
278 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
279 |
|
280 TEST(startProcessHandleCount == endProcessHandleCount); |
|
281 TEST(startThreadHandleCount == endThreadHandleCount); |
|
282 |
|
283 __UHEAP_MARKEND; |
|
284 } |
|
285 #endif //__ECOM_SERVER_TESTABILITY__ |
|
286 |
|
287 LOCAL_C void DoTestsL() |
|
288 { |
|
289 #ifdef __ECOM_SERVER_TESTABILITY__ |
|
290 DoBasicTestL(&TestEcomSsaEnabledL, _L("TestEcomSsaEnabledL")); |
|
291 #endif //__ECOM_SERVER_TESTABILITY__ |
|
292 |
|
293 //We are not going to run OOM tests for several reasons: |
|
294 //1- These tests are already done as part of the CEcomServer and |
|
295 //CServerStartupMgr OOM tests |
|
296 //2- EcomServer is running on another process |
|
297 //3- We need to kill the EcomServer and start it again. |
|
298 |
|
299 //For similar reasons to why we do not run OOM tests we should also |
|
300 //not test Ecom startup behaviour in this component test executable. |
|
301 //We will need to implement a new test executable for each test. |
|
302 } |
|
303 |
|
304 GLDEF_C TInt E32Main() |
|
305 { |
|
306 __UHEAP_MARK; |
|
307 TheTest.Printf(_L("\n")); |
|
308 TheTest.Title(); |
|
309 TheTest.Start(_L("Ecom Ssa Tests")); |
|
310 |
|
311 TEST2(TheFs.Connect(), KErrNone); |
|
312 |
|
313 // get clean-up stack |
|
314 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
315 |
|
316 TRAPD(err, ::KillEComServerL()); |
|
317 TEST2(err, KErrNone); |
|
318 |
|
319 EnableEcomTestBehaviour(TheTest, TheFs); |
|
320 |
|
321 SetupFiles(); //Add plugins to C: drive |
|
322 |
|
323 TRAP(err,DoTestsL()); |
|
324 TEST2(err, KErrNone); |
|
325 |
|
326 CleanupFiles(); //Cleanup after test. Remove the plugins from C: drive |
|
327 |
|
328 DisableEcomTestBehaviour(TheTest, TheFs); |
|
329 |
|
330 ResetSsa(TheTest, TheFs); |
|
331 |
|
332 //Make sure that following tests start a fresh version of EComServer |
|
333 TRAP(err, ::KillEComServerL()); |
|
334 |
|
335 TheTest.End(); |
|
336 TheTest.Close(); |
|
337 |
|
338 //delete scheduler; |
|
339 delete cleanup; |
|
340 |
|
341 TheFs.Close(); |
|
342 |
|
343 __UHEAP_MARKEND; |
|
344 |
|
345 User::Heap().Check(); |
|
346 |
|
347 return KErrNone; |
|
348 } |
|
349 |