sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "EComSessionAux.h" sl@0: #include "EcomTestUtils.h" sl@0: #include "EcomTestIniFileUtils.h" sl@0: #include "EcomTestCompTestabilityUtils.h" sl@0: sl@0: static RFs TheFs; sl@0: static RTest TheTest(_L("T_EcomSsaDisabled")); sl@0: sl@0: _LIT(KEComExampleDllOnZ, "Z:\\RAMOnly\\EComExample3.dll"); sl@0: _LIT(KEComExampleDllOnC, "C:\\sys\\bin\\EComExample3.dll"); sl@0: _LIT(KEComPluginRscOnZ, "Z:\\RAMOnly\\EComExample3.rsc"); sl@0: _LIT(KEComPluginRscOnC, "C:\\resource\\plugins\\EComExample3.rsc"); sl@0: sl@0: #ifdef __ECOM_SERVER_TESTABILITY__ sl@0: sl@0: _LIT8(KImplementationDataOnZ, "RomOnly"); sl@0: _LIT8(KImplementationDataOnC, "RamOnly"); sl@0: sl@0: const TInt KOneSecond = 1000000; sl@0: sl@0: #endif sl@0: sl@0: // sl@0: // sl@0: //Test macroes and functions sl@0: // sl@0: // sl@0: #ifdef __ECOM_SERVER_TESTABILITY__ sl@0: static void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check((arg), __LINE__) sl@0: #endif sl@0: sl@0: sl@0: static void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: // sl@0: // sl@0: //Helper functions sl@0: // sl@0: // sl@0: sl@0: /** sl@0: * Add plugins to C: drive so they can be discovered during NonStatic discovery sl@0: * state. sl@0: */ sl@0: static void SetupFiles() sl@0: { sl@0: TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExampleDllOnZ, KEComExampleDllOnC)); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginRscOnZ, KEComPluginRscOnC)); sl@0: TEST2(err, KErrNone); sl@0: } sl@0: sl@0: /** sl@0: * Remove the plugins from C: drive so we can leave a clean environment for sl@0: * the next test. sl@0: */ sl@0: static void CleanupFiles() sl@0: { sl@0: TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComExampleDllOnC)); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginRscOnC)); sl@0: TEST2(err, KErrNone); sl@0: } sl@0: sl@0: static void KillEComServerL() sl@0: { sl@0: //Need to ensure that the EComServer process is killed before even starting this test by using sl@0: //the EComTestUtils library sl@0: _LIT(KEComServerProcessName,"ecomserver"); sl@0: TRAPD(error, EComTestUtils::KillProcessL(KEComServerProcessName)); sl@0: error=error; sl@0: } sl@0: sl@0: /** sl@0: * Test if the requested plugin is discovered sl@0: *@param aInterfaceUid A UID specifying the required interface. sl@0: *@param aResolutionParameters A descriptor specifying any additional sl@0: * implementation characteristics to be fulfilled. sl@0: *@return return TRUE if plugin exists sl@0: */ sl@0: TBool TestForPlugin(TUid aInterfaceUid, sl@0: const TDesC8& aDataType) sl@0: { sl@0: TBool result = EFalse; sl@0: RImplInfoPtrArray aImplInfoArray; sl@0: TEComResolverParams resolverParams; sl@0: resolverParams.SetDataType(aDataType); sl@0: resolverParams.SetGenericMatch(ETrue); // Allow wildcard matching sl@0: sl@0: REComSession::ListImplementationsL( sl@0: aInterfaceUid, sl@0: resolverParams, sl@0: aImplInfoArray); sl@0: sl@0: if(aImplInfoArray.Count() > 0) sl@0: { sl@0: result = ETrue; sl@0: } sl@0: sl@0: aImplInfoArray.ResetAndDestroy(); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: // sl@0: // sl@0: //Test functions sl@0: // sl@0: // sl@0: #ifdef __ECOM_SERVER_TESTABILITY__ sl@0: /** sl@0: @SYMTestCaseID SYSLIB-ECOM-CIT-0187 sl@0: @SYMTestCaseDesc The SSA is disabled, the ECOM will do a full discovery with the sl@0: simulated Domain Manager. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Check the plugins and the state of ECOM using client API sl@0: GetCurrentStartupStateL and ListImplementationsL. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ967 sl@0: */ sl@0: LOCAL_C void TestEcomSsaDisabledL() sl@0: { sl@0: // Set up for heap leak checking sl@0: __UHEAP_MARK; sl@0: sl@0: // and leaking thread handles sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: TInt state = EStartupStateUndefined; sl@0: sl@0: // Test Starts... sl@0: sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: TUid ifUid = {0x10009DC0}; sl@0: sl@0: DisableSsa(TheTest, TheFs); sl@0: sl@0: //Open the ecom session which in turn should start the ecom server. sl@0: //Next, wait to make sure that all the plugins are discovered. sl@0: //Finally, get rid of the ecom session. sl@0: REComSession& ecomSession = REComSession::OpenL(); sl@0: CleanupClosePushL(ecomSession); sl@0: User::After(KOneSecond*10); //delay for 10 sec to ensure all plugins are discovered sl@0: CleanupStack::PopAndDestroy(&ecomSession); sl@0: sl@0: //check that current state is EStartupStateUndefined sl@0: TRAPD(err, state = GetCurrentStartupStateL()); sl@0: TEST2(err, KErrNone); sl@0: TEST2(state, EStartupStateNonCritical); sl@0: TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnZ())); sl@0: TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnC())); sl@0: sl@0: REComSession::FinalClose(); sl@0: sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: sl@0: TEST(startProcessHandleCount == endProcessHandleCount); sl@0: TEST(startThreadHandleCount == endThreadHandleCount); sl@0: sl@0: // Test Ends... sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: #endif //__ECOM_SERVER_TESTABILITY__ sl@0: sl@0: #ifdef __ECOM_SERVER_TESTABILITY__ sl@0: // Type definition for pointer to member function. sl@0: // Used in calling t_ServerStartupMgr test functions. sl@0: typedef void (*ClassFuncPtrL) (void); sl@0: sl@0: /** sl@0: Wrapper function to call all test functions sl@0: @param testFunc pointer to test function sl@0: @param aTestDesc test function name sl@0: */ sl@0: LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc) sl@0: { sl@0: TheTest.Next(aTestDesc); sl@0: sl@0: __UHEAP_MARK; sl@0: // find out the number of open handles sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: testFuncL(); sl@0: sl@0: // check that no handles have leaked sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: sl@0: TEST(startProcessHandleCount == endProcessHandleCount); sl@0: TEST(startThreadHandleCount == endThreadHandleCount); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: #endif //__ECOM_SERVER_TESTABILITY__ sl@0: sl@0: LOCAL_C void DoTestsL() sl@0: { sl@0: #ifdef __ECOM_SERVER_TESTABILITY__ sl@0: DoBasicTestL(&TestEcomSsaDisabledL, _L("TestEcomSsaDisabledL")); sl@0: #endif //__ECOM_SERVER_TESTABILITY__ sl@0: sl@0: //We are not going to run OOM tests for several reasons: sl@0: //1- These tests are already done as part of the CEcomServer and sl@0: //CServerStartupMgr OOM tests sl@0: //2- EcomServer is running on another process sl@0: //3- We need to kill the EcomServer and start it again. sl@0: sl@0: //For similar reasons to why we do not run OOM tests we should also sl@0: //not test Ecom startup behaviour in this component test executable. sl@0: //We will need to implement a new test executable for each test. sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: TheTest.Printf(_L("\n")); sl@0: TheTest.Title(); sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-ECOM-CIT-0187 Ecom Ssa Tests ")); sl@0: sl@0: TEST2(TheFs.Connect(), KErrNone); sl@0: sl@0: // get clean-up stack sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: sl@0: TRAPD(err, ::KillEComServerL()); sl@0: TEST2(err, KErrNone); sl@0: sl@0: DisableEcomTestBehaviour(TheTest, TheFs); sl@0: sl@0: SetupFiles(); //Add plugins to C: drive sl@0: sl@0: TRAP(err,DoTestsL()); sl@0: TEST2(err, KErrNone); sl@0: sl@0: CleanupFiles(); //Cleanup after test. Remove the plugins from C: drive sl@0: sl@0: ResetSsa(TheTest, TheFs); sl@0: sl@0: //Make sure that following tests start a fresh version of EComServer sl@0: TRAP(err, ::KillEComServerL()); sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: //delete scheduler; sl@0: delete cleanup; sl@0: sl@0: TheFs.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: User::Heap().Check(); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: