os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomSsaDisabledTest/t_EcomSsaDisabled.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomSsaDisabledTest/t_EcomSsaDisabled.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,300 @@
     1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <e32test.h>
    1.20 +#include <f32file.h>
    1.21 +#include <ecom/ecom.h>
    1.22 +#include <startup.hrh>
    1.23 +#include "EComSessionAux.h"
    1.24 +#include "EcomTestUtils.h"
    1.25 +#include "EcomTestIniFileUtils.h"
    1.26 +#include "EcomTestCompTestabilityUtils.h"
    1.27 +
    1.28 +static RFs TheFs;
    1.29 +static RTest TheTest(_L("T_EcomSsaDisabled"));
    1.30 +
    1.31 +_LIT(KEComExampleDllOnZ,	"Z:\\RAMOnly\\EComExample3.dll");
    1.32 +_LIT(KEComExampleDllOnC,	"C:\\sys\\bin\\EComExample3.dll");
    1.33 +_LIT(KEComPluginRscOnZ,		"Z:\\RAMOnly\\EComExample3.rsc");
    1.34 +_LIT(KEComPluginRscOnC,		"C:\\resource\\plugins\\EComExample3.rsc");
    1.35 +
    1.36 +#ifdef __ECOM_SERVER_TESTABILITY__
    1.37 +
    1.38 +_LIT8(KImplementationDataOnZ,	"RomOnly");
    1.39 +_LIT8(KImplementationDataOnC,	"RamOnly");
    1.40 +
    1.41 +const TInt KOneSecond = 1000000;
    1.42 +
    1.43 +#endif
    1.44 +
    1.45 +//
    1.46 +//
    1.47 +//Test macroes and functions
    1.48 +//
    1.49 +//
    1.50 +#ifdef __ECOM_SERVER_TESTABILITY__
    1.51 +static void Check(TInt aValue, TInt aLine)
    1.52 +	{
    1.53 +	if(!aValue)
    1.54 +		{
    1.55 +		TheTest(EFalse, aLine);
    1.56 +		}
    1.57 +	}
    1.58 +#define TEST(arg) ::Check((arg), __LINE__)
    1.59 +#endif
    1.60 +
    1.61 +
    1.62 +static  void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.63 +	{
    1.64 +	if(aValue != aExpected)
    1.65 +		{
    1.66 +		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.67 +		TheTest(EFalse, aLine);
    1.68 +		}
    1.69 +	}
    1.70 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    1.71 +
    1.72 +//
    1.73 +//
    1.74 +//Helper functions
    1.75 +//
    1.76 +//
    1.77 +
    1.78 +/**
    1.79 +* Add plugins to C: drive so they can be discovered during NonStatic discovery
    1.80 +* state.
    1.81 +*/
    1.82 +static void SetupFiles()
    1.83 +	{
    1.84 +	TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExampleDllOnZ, KEComExampleDllOnC));
    1.85 +	TEST2(err, KErrNone);
    1.86 +
    1.87 +	TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginRscOnZ, KEComPluginRscOnC));
    1.88 +	TEST2(err, KErrNone);
    1.89 +	}
    1.90 +
    1.91 +/**
    1.92 +* Remove the plugins from C: drive so we can leave a clean environment for
    1.93 +* the next test.
    1.94 +*/
    1.95 +static void CleanupFiles()
    1.96 +	{
    1.97 +	TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComExampleDllOnC));
    1.98 +	TEST2(err, KErrNone);
    1.99 +
   1.100 +	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginRscOnC));
   1.101 +	TEST2(err, KErrNone);
   1.102 +	}
   1.103 +
   1.104 +static void KillEComServerL()
   1.105 +	{
   1.106 +	//Need to ensure that the EComServer process is killed before even starting this test by using
   1.107 +   	//the EComTestUtils library
   1.108 +   	_LIT(KEComServerProcessName,"ecomserver");
   1.109 +   	TRAPD(error, EComTestUtils::KillProcessL(KEComServerProcessName));
   1.110 +   	error=error;
   1.111 +	}
   1.112 +
   1.113 +/**
   1.114 +* Test if the requested plugin is discovered
   1.115 +*@param			aInterfaceUid A UID specifying the required interface.
   1.116 +*@param			aResolutionParameters A descriptor specifying any additional
   1.117 +*				implementation characteristics to be fulfilled.
   1.118 +*@return		return TRUE if plugin exists
   1.119 +*/
   1.120 +TBool TestForPlugin(TUid aInterfaceUid,
   1.121 +					const TDesC8& aDataType)
   1.122 +	{
   1.123 +	TBool result = EFalse;
   1.124 +	RImplInfoPtrArray aImplInfoArray;
   1.125 +	TEComResolverParams resolverParams;
   1.126 +	resolverParams.SetDataType(aDataType);
   1.127 +	resolverParams.SetGenericMatch(ETrue);	// Allow wildcard matching
   1.128 +
   1.129 +	REComSession::ListImplementationsL(
   1.130 +			aInterfaceUid,
   1.131 +			resolverParams,
   1.132 +			aImplInfoArray);
   1.133 +
   1.134 +	if(aImplInfoArray.Count() > 0)
   1.135 +		{
   1.136 +		result = ETrue;
   1.137 +		}
   1.138 +
   1.139 +	aImplInfoArray.ResetAndDestroy();
   1.140 +
   1.141 +	return result;
   1.142 +	}
   1.143 +
   1.144 +//
   1.145 +//
   1.146 +//Test functions
   1.147 +//
   1.148 +//
   1.149 +#ifdef __ECOM_SERVER_TESTABILITY__
   1.150 +/**
   1.151 +@SYMTestCaseID		SYSLIB-ECOM-CIT-0187
   1.152 +@SYMTestCaseDesc 	The SSA is disabled, the ECOM will do a full discovery with the
   1.153 +simulated Domain Manager.
   1.154 +@SYMTestPriority 	High
   1.155 +@SYMTestActions  	Check the plugins and the state of ECOM using client API
   1.156 +GetCurrentStartupStateL and ListImplementationsL.
   1.157 +@SYMTestExpectedResults The test must not fail.
   1.158 +@SYMPREQ PREQ967
   1.159 +*/
   1.160 +LOCAL_C void TestEcomSsaDisabledL()
   1.161 +	{
   1.162 +	// Set up for heap leak checking
   1.163 +	__UHEAP_MARK;
   1.164 +
   1.165 +	// and leaking thread handles
   1.166 +	TInt startProcessHandleCount;
   1.167 +	TInt startThreadHandleCount;
   1.168 +	TInt endProcessHandleCount;
   1.169 +	TInt endThreadHandleCount;
   1.170 +	TInt state = EStartupStateUndefined;
   1.171 +
   1.172 +	// Test Starts...
   1.173 +
   1.174 +	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
   1.175 +
   1.176 +	TUid ifUid = {0x10009DC0};
   1.177 +
   1.178 +	DisableSsa(TheTest, TheFs);
   1.179 +
   1.180 +	//Open the ecom session which in turn should start the ecom server.
   1.181 +	//Next, wait to make sure that all the plugins are discovered.
   1.182 +	//Finally, get rid of the ecom session.
   1.183 +	REComSession& ecomSession = REComSession::OpenL();
   1.184 +	CleanupClosePushL(ecomSession);
   1.185 +	User::After(KOneSecond*10); //delay for 10 sec to ensure all plugins are discovered
   1.186 +	CleanupStack::PopAndDestroy(&ecomSession);
   1.187 +
   1.188 +	//check that current state is EStartupStateUndefined
   1.189 +	TRAPD(err, state = GetCurrentStartupStateL());
   1.190 +	TEST2(err, KErrNone);
   1.191 +	TEST2(state, EStartupStateNonCritical);
   1.192 +	TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnZ()));
   1.193 +	TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnC()));
   1.194 +
   1.195 +	REComSession::FinalClose();
   1.196 +
   1.197 +	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   1.198 +
   1.199 +	TEST(startProcessHandleCount == endProcessHandleCount);
   1.200 +	TEST(startThreadHandleCount  == endThreadHandleCount);
   1.201 +
   1.202 +	// Test Ends...
   1.203 +
   1.204 +	__UHEAP_MARKEND;
   1.205 +	}
   1.206 +#endif //__ECOM_SERVER_TESTABILITY__
   1.207 +
   1.208 +#ifdef __ECOM_SERVER_TESTABILITY__
   1.209 +// Type definition for pointer to member function.
   1.210 +// Used in calling t_ServerStartupMgr test functions.
   1.211 +typedef void (*ClassFuncPtrL) (void);
   1.212 +
   1.213 +/**
   1.214 +Wrapper function to call all test functions
   1.215 +@param		testFunc pointer to test function
   1.216 +@param		aTestDesc test function name
   1.217 +*/
   1.218 +LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
   1.219 +	{
   1.220 +	TheTest.Next(aTestDesc);
   1.221 +
   1.222 +	__UHEAP_MARK;
   1.223 +  	// find out the number of open handles
   1.224 +	TInt startProcessHandleCount;
   1.225 +	TInt startThreadHandleCount;
   1.226 +	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
   1.227 +
   1.228 +	testFuncL();
   1.229 +
   1.230 +	// check that no handles have leaked
   1.231 +	TInt endProcessHandleCount;
   1.232 +	TInt endThreadHandleCount;
   1.233 +	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   1.234 +
   1.235 +	TEST(startProcessHandleCount == endProcessHandleCount);
   1.236 +	TEST(startThreadHandleCount  == endThreadHandleCount);
   1.237 +
   1.238 +	__UHEAP_MARKEND;
   1.239 +	}
   1.240 +#endif //__ECOM_SERVER_TESTABILITY__
   1.241 +
   1.242 +LOCAL_C void DoTestsL()
   1.243 +	{
   1.244 +#ifdef __ECOM_SERVER_TESTABILITY__
   1.245 +	DoBasicTestL(&TestEcomSsaDisabledL, _L("TestEcomSsaDisabledL"));
   1.246 +#endif //__ECOM_SERVER_TESTABILITY__
   1.247 +
   1.248 +	//We are not going to run OOM tests for several reasons:
   1.249 +	//1- These tests are already done as part of the CEcomServer and
   1.250 +	//CServerStartupMgr OOM tests
   1.251 +	//2- EcomServer is running on another process
   1.252 +	//3- We need to kill the EcomServer and start it again.
   1.253 +
   1.254 +	//For similar reasons to why we do not run OOM tests we should also
   1.255 +	//not test Ecom startup behaviour in this component test executable.
   1.256 +	//We will need to implement a new test executable for each test.
   1.257 +	}
   1.258 +
   1.259 +GLDEF_C TInt E32Main()
   1.260 +	{
   1.261 +	__UHEAP_MARK;
   1.262 +	TheTest.Printf(_L("\n"));
   1.263 +	TheTest.Title();
   1.264 +	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-ECOM-CIT-0187 Ecom Ssa Tests "));
   1.265 +
   1.266 +	TEST2(TheFs.Connect(), KErrNone);
   1.267 +
   1.268 +	// get clean-up stack
   1.269 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.270 +
   1.271 +	TRAPD(err, ::KillEComServerL());
   1.272 +	TEST2(err, KErrNone);
   1.273 +
   1.274 +	DisableEcomTestBehaviour(TheTest, TheFs);
   1.275 +
   1.276 +	SetupFiles(); //Add plugins to C: drive
   1.277 +
   1.278 +	TRAP(err,DoTestsL());
   1.279 +	TEST2(err, KErrNone);
   1.280 +
   1.281 +	CleanupFiles(); //Cleanup after test. Remove the plugins from C: drive
   1.282 +
   1.283 +	ResetSsa(TheTest, TheFs);
   1.284 +
   1.285 +	//Make sure that following tests start a fresh version of EComServer
   1.286 +	TRAP(err, ::KillEComServerL());
   1.287 +
   1.288 +	TheTest.End();
   1.289 +	TheTest.Close();
   1.290 +
   1.291 +	//delete scheduler;
   1.292 +	delete cleanup;
   1.293 +
   1.294 +	TheFs.Close();
   1.295 +
   1.296 +	__UHEAP_MARKEND;
   1.297 +
   1.298 +	User::Heap().Check();
   1.299 +
   1.300 +	return KErrNone;
   1.301 +	}
   1.302 +
   1.303 +