os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomSsaEnabledTest/t_EcomSsaEnabled.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomSsaEnabledTest/t_EcomSsaEnabled.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,349 @@
     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_EcomSsaEnabled"));
    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 +#endif
    1.42 +
    1.43 +//
    1.44 +//
    1.45 +//Test macroes and functions
    1.46 +//
    1.47 +//
    1.48 +#ifdef __ECOM_SERVER_TESTABILITY__
    1.49 +
    1.50 +static void Check(TInt aValue, TInt aLine)
    1.51 +	{
    1.52 +	if(!aValue)
    1.53 +		{
    1.54 +		TheTest(EFalse, aLine);
    1.55 +		}
    1.56 +	}
    1.57 +#define TEST(arg) ::Check((arg), __LINE__)
    1.58 +
    1.59 +#endif
    1.60 +
    1.61 +static  void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.62 +	{
    1.63 +	if(aValue != aExpected)
    1.64 +		{
    1.65 +		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.66 +		TheTest(EFalse, aLine);
    1.67 +		}
    1.68 +	}
    1.69 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    1.70 +
    1.71 +//
    1.72 +//
    1.73 +//Helper functions
    1.74 +//
    1.75 +//
    1.76 +
    1.77 +/**
    1.78 +* Add plugins to C: drive so they can be discovered during NonStatic discovery
    1.79 +* state.
    1.80 +*/
    1.81 +static void SetupFiles()
    1.82 +	{
    1.83 +	TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExampleDllOnZ, KEComExampleDllOnC));
    1.84 +	TEST2(err, KErrNone);
    1.85 +
    1.86 +	TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginRscOnZ, KEComPluginRscOnC));
    1.87 +	TEST2(err, KErrNone);
    1.88 +	}
    1.89 +
    1.90 +/**
    1.91 +* Remove the plugins from C: drive so we can leave a clean environment for
    1.92 +* the next test.
    1.93 +*/
    1.94 +static void CleanupFiles()
    1.95 +	{
    1.96 +	TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComExampleDllOnC));
    1.97 +	TEST2(err, KErrNone);
    1.98 +
    1.99 +	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginRscOnC));
   1.100 +	TEST2(err, KErrNone);
   1.101 +	}
   1.102 +
   1.103 +static void KillEComServerL()
   1.104 +	{
   1.105 +	//Need to ensure that the EComServer process is killed before even starting this test by using
   1.106 +   	//the EComTestUtils library
   1.107 +   	_LIT(KEComServerProcessName,"ecomserver");
   1.108 +   	TRAPD(error, EComTestUtils::KillProcessL(KEComServerProcessName));
   1.109 +   	error=error;
   1.110 +	}
   1.111 +
   1.112 +#ifdef __ECOM_SERVER_TESTABILITY__
   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 +static 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 +#endif
   1.144 +
   1.145 +//
   1.146 +//
   1.147 +//Test functions
   1.148 +//
   1.149 +//
   1.150 +#ifdef __ECOM_SERVER_TESTABILITY__
   1.151 +/**
   1.152 +Wrapper function to call change and process startup state test functions
   1.153 +and check the current startup state is matched with the expected startup state.
   1.154 +@param		aState A startup state to be set in ECOM
   1.155 +@param		aExpectedState An expected startup state in ECOM
   1.156 +*/
   1.157 +LOCAL_C void ChangeAndProcessStartupState(TInt aState, TInt aExpectedState)
   1.158 +{
   1.159 +
   1.160 +	TInt state = EStartupStateUndefined;
   1.161 +	TRAPD(err, ChangeStartupStateL(aState));
   1.162 +	TEST2(err, KErrNone);
   1.163 +	TRAP(err, ProcessCurrentStartupStateL());
   1.164 +	TEST2(err, KErrNone);
   1.165 +	TRAP(err, state = GetCurrentStartupStateL());
   1.166 +	TEST2(err, KErrNone);
   1.167 +	TEST2(state, aExpectedState);
   1.168 +}
   1.169 +
   1.170 +/**
   1.171 +@SYMTestCaseID		SYSLIB-ECOM-CIT-0188
   1.172 +@SYMTestCaseDesc 	The SSA is enabled, the ECOM will do a staged discovery with the
   1.173 +simulated Domain Manager.
   1.174 +@SYMTestPriority 	High
   1.175 +@SYMTestActions  	Check the plugins and the state of ECOM are correct at each state
   1.176 + using client API GetCurrentStartupStateL and ListImplementationsL.
   1.177 +@SYMTestExpectedResults The test must not fail.
   1.178 +@SYMPREQ PREQ967
   1.179 +*/
   1.180 +LOCAL_C void TestEcomSsaEnabledL()
   1.181 +	{
   1.182 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CIT-0188 "));
   1.183 +	// Set up for heap leak checking
   1.184 +	__UHEAP_MARK;
   1.185 +
   1.186 +	// and leaking thread handles
   1.187 +	TInt startProcessHandleCount;
   1.188 +	TInt startThreadHandleCount;
   1.189 +	TInt endProcessHandleCount;
   1.190 +	TInt endThreadHandleCount;
   1.191 +	// Test Starts...
   1.192 +
   1.193 +	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
   1.194 +
   1.195 +	TUid ifUid = {0x10009DC0};
   1.196 +
   1.197 +	EnableSsa(TheTest, TheFs);
   1.198 +
   1.199 +	//Change the state to a user defined state then
   1.200 +	//check that current state is still EStartupStateUndefined
   1.201 +	ChangeAndProcessStartupState(EStartupStateUndefined+1,EStartupStateUndefined);
   1.202 +
   1.203 +	//Change the state to a user defined state then
   1.204 +	//check that current state is still EStartupStateUndefined
   1.205 +	ChangeAndProcessStartupState(EStartupStateCriticalStatic-1,EStartupStateUndefined );
   1.206 +
   1.207 +	//Change the state to EStartupStateCriticalStatic then
   1.208 +	//check that current state is EStartupStateCriticalStatic
   1.209 +	//check that a plugin from RO drive is discovered
   1.210 +	ChangeAndProcessStartupState(EStartupStateCriticalStatic,EStartupStateCriticalStatic );
   1.211 +	TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnZ()));
   1.212 +
   1.213 +	//Change the state to a user defined state then
   1.214 +	//check that current state is still EStartupStateCriticalStatic
   1.215 +	ChangeAndProcessStartupState(EStartupStateCriticalStatic+1,EStartupStateCriticalStatic);
   1.216 +
   1.217 +	//Change the state to a user defined state then
   1.218 +	//check that current state is still EStartupStateCriticalStatic
   1.219 +	ChangeAndProcessStartupState(EStartupStateCriticalDynamic-1,EStartupStateCriticalStatic);
   1.220 +
   1.221 +	//Change the state to EStartupStateCriticalDynamic then
   1.222 +	//check that current state is EStartupStateCriticalDynamic
   1.223 +	ChangeAndProcessStartupState(EStartupStateCriticalDynamic, EStartupStateCriticalDynamic);
   1.224 +
   1.225 +	//Change the state to a user defined state then
   1.226 +	//check that current state is still EStartupStateCriticalDynamic
   1.227 +	ChangeAndProcessStartupState(EStartupStateCriticalDynamic+1, EStartupStateCriticalDynamic);
   1.228 +
   1.229 +	//Change the state to a user defined state then
   1.230 +	//check that current state is still EStartupStateCriticalDynamic
   1.231 +	ChangeAndProcessStartupState(EStartupStateNonCritical-1,EStartupStateCriticalDynamic);
   1.232 +
   1.233 +	//Change the state to EStartupStateNonCritical then
   1.234 +	//check that current state is EStartupStateNonCritical
   1.235 +	//check that a plugin from RO drive is discovered
   1.236 +	ChangeAndProcessStartupState(EStartupStateNonCritical,EStartupStateNonCritical );
   1.237 +	TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnC()));
   1.238 +
   1.239 +	//Change the state to a user defined state then
   1.240 +	//check that current state is still EStartupStateNonCritical
   1.241 +	ChangeAndProcessStartupState(EStartupStateNonCritical+1, EStartupStateNonCritical);
   1.242 +
   1.243 +	REComSession::FinalClose();
   1.244 +
   1.245 +	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   1.246 +
   1.247 +	TEST(startProcessHandleCount == endProcessHandleCount);
   1.248 +	TEST(startThreadHandleCount  == endThreadHandleCount);
   1.249 +
   1.250 +	// Test Ends...
   1.251 +
   1.252 +	__UHEAP_MARKEND;
   1.253 +	}
   1.254 +#endif //__ECOM_SERVER_TESTABILITY__
   1.255 +
   1.256 +#ifdef __ECOM_SERVER_TESTABILITY__
   1.257 +// Type definition for pointer to member function.
   1.258 +// Used in calling T_EcomSsaEnabled test functions.
   1.259 +typedef void (*ClassFuncPtrL) (void);
   1.260 +
   1.261 +/**
   1.262 +Wrapper function to call all test functions
   1.263 +@param		testFunc pointer to test function
   1.264 +@param		aTestDesc test function name
   1.265 +*/
   1.266 +LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
   1.267 +	{
   1.268 +	TheTest.Next(aTestDesc);
   1.269 +
   1.270 +	__UHEAP_MARK;
   1.271 +  	// find out the number of open handles
   1.272 +	TInt startProcessHandleCount;
   1.273 +	TInt startThreadHandleCount;
   1.274 +	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
   1.275 +
   1.276 +	testFuncL();
   1.277 +
   1.278 +	// check that no handles have leaked
   1.279 +	TInt endProcessHandleCount;
   1.280 +	TInt endThreadHandleCount;
   1.281 +	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   1.282 +
   1.283 +	TEST(startProcessHandleCount == endProcessHandleCount);
   1.284 +	TEST(startThreadHandleCount  == endThreadHandleCount);
   1.285 +
   1.286 +	__UHEAP_MARKEND;
   1.287 +	}
   1.288 +#endif //__ECOM_SERVER_TESTABILITY__
   1.289 +
   1.290 +LOCAL_C void DoTestsL()
   1.291 +	{
   1.292 +#ifdef __ECOM_SERVER_TESTABILITY__
   1.293 +	DoBasicTestL(&TestEcomSsaEnabledL, _L("TestEcomSsaEnabledL"));
   1.294 +#endif //__ECOM_SERVER_TESTABILITY__
   1.295 +
   1.296 +	//We are not going to run OOM tests for several reasons:
   1.297 +	//1- These tests are already done as part of the CEcomServer and
   1.298 +	//CServerStartupMgr OOM tests
   1.299 +	//2- EcomServer is running on another process
   1.300 +	//3- We need to kill the EcomServer and start it again.
   1.301 +
   1.302 +	//For similar reasons to why we do not run OOM tests we should also
   1.303 +	//not test Ecom startup behaviour in this component test executable.
   1.304 +	//We will need to implement a new test executable for each test.
   1.305 +	}
   1.306 +
   1.307 +GLDEF_C TInt E32Main()
   1.308 +	{
   1.309 +	__UHEAP_MARK;
   1.310 +	TheTest.Printf(_L("\n"));
   1.311 +	TheTest.Title();
   1.312 +	TheTest.Start(_L("Ecom Ssa Tests"));
   1.313 +
   1.314 +	TEST2(TheFs.Connect(), KErrNone);
   1.315 +
   1.316 +	// get clean-up stack
   1.317 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.318 +
   1.319 +	TRAPD(err, ::KillEComServerL());
   1.320 +	TEST2(err, KErrNone);
   1.321 +
   1.322 +	EnableEcomTestBehaviour(TheTest, TheFs);
   1.323 +
   1.324 +	SetupFiles(); //Add plugins to C: drive
   1.325 +
   1.326 +	TRAP(err,DoTestsL());
   1.327 +	TEST2(err, KErrNone);
   1.328 +
   1.329 +	CleanupFiles(); //Cleanup after test. Remove the plugins from C: drive
   1.330 +
   1.331 +	DisableEcomTestBehaviour(TheTest, TheFs);
   1.332 +
   1.333 +	ResetSsa(TheTest, TheFs);
   1.334 +
   1.335 +	//Make sure that following tests start a fresh version of EComServer
   1.336 +	TRAP(err, ::KillEComServerL());
   1.337 +
   1.338 +	TheTest.End();
   1.339 +	TheTest.Close();
   1.340 +
   1.341 +	//delete scheduler;
   1.342 +	delete cleanup;
   1.343 +
   1.344 +	TheFs.Close();
   1.345 +
   1.346 +	__UHEAP_MARKEND;
   1.347 +
   1.348 +	User::Heap().Check();
   1.349 +
   1.350 +	return KErrNone;
   1.351 +	}
   1.352 +