os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomSsaDisabledTest/t_EcomSsaDisabled.cpp
First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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"
26 static RTest TheTest(_L("T_EcomSsaDisabled"));
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");
33 #ifdef __ECOM_SERVER_TESTABILITY__
35 _LIT8(KImplementationDataOnZ, "RomOnly");
36 _LIT8(KImplementationDataOnC, "RamOnly");
38 const TInt KOneSecond = 1000000;
44 //Test macroes and functions
47 #ifdef __ECOM_SERVER_TESTABILITY__
48 static void Check(TInt aValue, TInt aLine)
52 TheTest(EFalse, aLine);
55 #define TEST(arg) ::Check((arg), __LINE__)
59 static void Check(TInt aValue, TInt aExpected, TInt aLine)
61 if(aValue != aExpected)
63 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
64 TheTest(EFalse, aLine);
67 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
76 * Add plugins to C: drive so they can be discovered during NonStatic discovery
79 static void SetupFiles()
81 TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExampleDllOnZ, KEComExampleDllOnC));
84 TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginRscOnZ, KEComPluginRscOnC));
89 * Remove the plugins from C: drive so we can leave a clean environment for
92 static void CleanupFiles()
94 TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComExampleDllOnC));
97 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginRscOnC));
101 static void KillEComServerL()
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));
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
117 TBool TestForPlugin(TUid aInterfaceUid,
118 const TDesC8& aDataType)
120 TBool result = EFalse;
121 RImplInfoPtrArray aImplInfoArray;
122 TEComResolverParams resolverParams;
123 resolverParams.SetDataType(aDataType);
124 resolverParams.SetGenericMatch(ETrue); // Allow wildcard matching
126 REComSession::ListImplementationsL(
131 if(aImplInfoArray.Count() > 0)
136 aImplInfoArray.ResetAndDestroy();
146 #ifdef __ECOM_SERVER_TESTABILITY__
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.
157 LOCAL_C void TestEcomSsaDisabledL()
159 // Set up for heap leak checking
162 // and leaking thread handles
163 TInt startProcessHandleCount;
164 TInt startThreadHandleCount;
165 TInt endProcessHandleCount;
166 TInt endThreadHandleCount;
167 TInt state = EStartupStateUndefined;
171 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
173 TUid ifUid = {0x10009DC0};
175 DisableSsa(TheTest, TheFs);
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);
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()));
192 REComSession::FinalClose();
194 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
196 TEST(startProcessHandleCount == endProcessHandleCount);
197 TEST(startThreadHandleCount == endThreadHandleCount);
203 #endif //__ECOM_SERVER_TESTABILITY__
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);
211 Wrapper function to call all test functions
212 @param testFunc pointer to test function
213 @param aTestDesc test function name
215 LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
217 TheTest.Next(aTestDesc);
220 // find out the number of open handles
221 TInt startProcessHandleCount;
222 TInt startThreadHandleCount;
223 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
227 // check that no handles have leaked
228 TInt endProcessHandleCount;
229 TInt endThreadHandleCount;
230 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
232 TEST(startProcessHandleCount == endProcessHandleCount);
233 TEST(startThreadHandleCount == endThreadHandleCount);
237 #endif //__ECOM_SERVER_TESTABILITY__
239 LOCAL_C void DoTestsL()
241 #ifdef __ECOM_SERVER_TESTABILITY__
242 DoBasicTestL(&TestEcomSsaDisabledL, _L("TestEcomSsaDisabledL"));
243 #endif //__ECOM_SERVER_TESTABILITY__
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.
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.
256 GLDEF_C TInt E32Main()
259 TheTest.Printf(_L("\n"));
261 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-ECOM-CIT-0187 Ecom Ssa Tests "));
263 TEST2(TheFs.Connect(), KErrNone);
265 // get clean-up stack
266 CTrapCleanup* cleanup = CTrapCleanup::New();
268 TRAPD(err, ::KillEComServerL());
269 TEST2(err, KErrNone);
271 DisableEcomTestBehaviour(TheTest, TheFs);
273 SetupFiles(); //Add plugins to C: drive
275 TRAP(err,DoTestsL());
276 TEST2(err, KErrNone);
278 CleanupFiles(); //Cleanup after test. Remove the plugins from C: drive
280 ResetSsa(TheTest, TheFs);
282 //Make sure that following tests start a fresh version of EComServer
283 TRAP(err, ::KillEComServerL());
295 User::Heap().Check();