|
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_EcomSsaDisabled")); |
|
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 const TInt KOneSecond = 1000000; |
|
39 |
|
40 #endif |
|
41 |
|
42 // |
|
43 // |
|
44 //Test macroes and functions |
|
45 // |
|
46 // |
|
47 #ifdef __ECOM_SERVER_TESTABILITY__ |
|
48 static void Check(TInt aValue, TInt aLine) |
|
49 { |
|
50 if(!aValue) |
|
51 { |
|
52 TheTest(EFalse, aLine); |
|
53 } |
|
54 } |
|
55 #define TEST(arg) ::Check((arg), __LINE__) |
|
56 #endif |
|
57 |
|
58 |
|
59 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
60 { |
|
61 if(aValue != aExpected) |
|
62 { |
|
63 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
64 TheTest(EFalse, aLine); |
|
65 } |
|
66 } |
|
67 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
68 |
|
69 // |
|
70 // |
|
71 //Helper functions |
|
72 // |
|
73 // |
|
74 |
|
75 /** |
|
76 * Add plugins to C: drive so they can be discovered during NonStatic discovery |
|
77 * state. |
|
78 */ |
|
79 static void SetupFiles() |
|
80 { |
|
81 TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExampleDllOnZ, KEComExampleDllOnC)); |
|
82 TEST2(err, KErrNone); |
|
83 |
|
84 TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginRscOnZ, KEComPluginRscOnC)); |
|
85 TEST2(err, KErrNone); |
|
86 } |
|
87 |
|
88 /** |
|
89 * Remove the plugins from C: drive so we can leave a clean environment for |
|
90 * the next test. |
|
91 */ |
|
92 static void CleanupFiles() |
|
93 { |
|
94 TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComExampleDllOnC)); |
|
95 TEST2(err, KErrNone); |
|
96 |
|
97 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginRscOnC)); |
|
98 TEST2(err, KErrNone); |
|
99 } |
|
100 |
|
101 static void KillEComServerL() |
|
102 { |
|
103 //Need to ensure that the EComServer process is killed before even starting this test by using |
|
104 //the EComTestUtils library |
|
105 _LIT(KEComServerProcessName,"ecomserver"); |
|
106 TRAPD(error, EComTestUtils::KillProcessL(KEComServerProcessName)); |
|
107 error=error; |
|
108 } |
|
109 |
|
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 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 |
|
141 // |
|
142 // |
|
143 //Test functions |
|
144 // |
|
145 // |
|
146 #ifdef __ECOM_SERVER_TESTABILITY__ |
|
147 /** |
|
148 @SYMTestCaseID SYSLIB-ECOM-CIT-0187 |
|
149 @SYMTestCaseDesc The SSA is disabled, the ECOM will do a full discovery with the |
|
150 simulated Domain Manager. |
|
151 @SYMTestPriority High |
|
152 @SYMTestActions Check the plugins and the state of ECOM using client API |
|
153 GetCurrentStartupStateL and ListImplementationsL. |
|
154 @SYMTestExpectedResults The test must not fail. |
|
155 @SYMPREQ PREQ967 |
|
156 */ |
|
157 LOCAL_C void TestEcomSsaDisabledL() |
|
158 { |
|
159 // Set up for heap leak checking |
|
160 __UHEAP_MARK; |
|
161 |
|
162 // and leaking thread handles |
|
163 TInt startProcessHandleCount; |
|
164 TInt startThreadHandleCount; |
|
165 TInt endProcessHandleCount; |
|
166 TInt endThreadHandleCount; |
|
167 TInt state = EStartupStateUndefined; |
|
168 |
|
169 // Test Starts... |
|
170 |
|
171 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
172 |
|
173 TUid ifUid = {0x10009DC0}; |
|
174 |
|
175 DisableSsa(TheTest, TheFs); |
|
176 |
|
177 //Open the ecom session which in turn should start the ecom server. |
|
178 //Next, wait to make sure that all the plugins are discovered. |
|
179 //Finally, get rid of the ecom session. |
|
180 REComSession& ecomSession = REComSession::OpenL(); |
|
181 CleanupClosePushL(ecomSession); |
|
182 User::After(KOneSecond*10); //delay for 10 sec to ensure all plugins are discovered |
|
183 CleanupStack::PopAndDestroy(&ecomSession); |
|
184 |
|
185 //check that current state is EStartupStateUndefined |
|
186 TRAPD(err, state = GetCurrentStartupStateL()); |
|
187 TEST2(err, KErrNone); |
|
188 TEST2(state, EStartupStateNonCritical); |
|
189 TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnZ())); |
|
190 TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnC())); |
|
191 |
|
192 REComSession::FinalClose(); |
|
193 |
|
194 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
195 |
|
196 TEST(startProcessHandleCount == endProcessHandleCount); |
|
197 TEST(startThreadHandleCount == endThreadHandleCount); |
|
198 |
|
199 // Test Ends... |
|
200 |
|
201 __UHEAP_MARKEND; |
|
202 } |
|
203 #endif //__ECOM_SERVER_TESTABILITY__ |
|
204 |
|
205 #ifdef __ECOM_SERVER_TESTABILITY__ |
|
206 // Type definition for pointer to member function. |
|
207 // Used in calling t_ServerStartupMgr test functions. |
|
208 typedef void (*ClassFuncPtrL) (void); |
|
209 |
|
210 /** |
|
211 Wrapper function to call all test functions |
|
212 @param testFunc pointer to test function |
|
213 @param aTestDesc test function name |
|
214 */ |
|
215 LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc) |
|
216 { |
|
217 TheTest.Next(aTestDesc); |
|
218 |
|
219 __UHEAP_MARK; |
|
220 // find out the number of open handles |
|
221 TInt startProcessHandleCount; |
|
222 TInt startThreadHandleCount; |
|
223 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
224 |
|
225 testFuncL(); |
|
226 |
|
227 // check that no handles have leaked |
|
228 TInt endProcessHandleCount; |
|
229 TInt endThreadHandleCount; |
|
230 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
231 |
|
232 TEST(startProcessHandleCount == endProcessHandleCount); |
|
233 TEST(startThreadHandleCount == endThreadHandleCount); |
|
234 |
|
235 __UHEAP_MARKEND; |
|
236 } |
|
237 #endif //__ECOM_SERVER_TESTABILITY__ |
|
238 |
|
239 LOCAL_C void DoTestsL() |
|
240 { |
|
241 #ifdef __ECOM_SERVER_TESTABILITY__ |
|
242 DoBasicTestL(&TestEcomSsaDisabledL, _L("TestEcomSsaDisabledL")); |
|
243 #endif //__ECOM_SERVER_TESTABILITY__ |
|
244 |
|
245 //We are not going to run OOM tests for several reasons: |
|
246 //1- These tests are already done as part of the CEcomServer and |
|
247 //CServerStartupMgr OOM tests |
|
248 //2- EcomServer is running on another process |
|
249 //3- We need to kill the EcomServer and start it again. |
|
250 |
|
251 //For similar reasons to why we do not run OOM tests we should also |
|
252 //not test Ecom startup behaviour in this component test executable. |
|
253 //We will need to implement a new test executable for each test. |
|
254 } |
|
255 |
|
256 GLDEF_C TInt E32Main() |
|
257 { |
|
258 __UHEAP_MARK; |
|
259 TheTest.Printf(_L("\n")); |
|
260 TheTest.Title(); |
|
261 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-ECOM-CIT-0187 Ecom Ssa Tests ")); |
|
262 |
|
263 TEST2(TheFs.Connect(), KErrNone); |
|
264 |
|
265 // get clean-up stack |
|
266 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
267 |
|
268 TRAPD(err, ::KillEComServerL()); |
|
269 TEST2(err, KErrNone); |
|
270 |
|
271 DisableEcomTestBehaviour(TheTest, TheFs); |
|
272 |
|
273 SetupFiles(); //Add plugins to C: drive |
|
274 |
|
275 TRAP(err,DoTestsL()); |
|
276 TEST2(err, KErrNone); |
|
277 |
|
278 CleanupFiles(); //Cleanup after test. Remove the plugins from C: drive |
|
279 |
|
280 ResetSsa(TheTest, TheFs); |
|
281 |
|
282 //Make sure that following tests start a fresh version of EComServer |
|
283 TRAP(err, ::KillEComServerL()); |
|
284 |
|
285 TheTest.End(); |
|
286 TheTest.Close(); |
|
287 |
|
288 //delete scheduler; |
|
289 delete cleanup; |
|
290 |
|
291 TheFs.Close(); |
|
292 |
|
293 __UHEAP_MARKEND; |
|
294 |
|
295 User::Heap().Check(); |
|
296 |
|
297 return KErrNone; |
|
298 } |
|
299 |
|
300 |