os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomSsaDisabledTest/t_EcomSsaDisabled.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <e32test.h>
sl@0
    17
#include <f32file.h>
sl@0
    18
#include <ecom/ecom.h>
sl@0
    19
#include <startup.hrh>
sl@0
    20
#include "EComSessionAux.h"
sl@0
    21
#include "EcomTestUtils.h"
sl@0
    22
#include "EcomTestIniFileUtils.h"
sl@0
    23
#include "EcomTestCompTestabilityUtils.h"
sl@0
    24
sl@0
    25
static RFs TheFs;
sl@0
    26
static RTest TheTest(_L("T_EcomSsaDisabled"));
sl@0
    27
sl@0
    28
_LIT(KEComExampleDllOnZ,	"Z:\\RAMOnly\\EComExample3.dll");
sl@0
    29
_LIT(KEComExampleDllOnC,	"C:\\sys\\bin\\EComExample3.dll");
sl@0
    30
_LIT(KEComPluginRscOnZ,		"Z:\\RAMOnly\\EComExample3.rsc");
sl@0
    31
_LIT(KEComPluginRscOnC,		"C:\\resource\\plugins\\EComExample3.rsc");
sl@0
    32
sl@0
    33
#ifdef __ECOM_SERVER_TESTABILITY__
sl@0
    34
sl@0
    35
_LIT8(KImplementationDataOnZ,	"RomOnly");
sl@0
    36
_LIT8(KImplementationDataOnC,	"RamOnly");
sl@0
    37
sl@0
    38
const TInt KOneSecond = 1000000;
sl@0
    39
sl@0
    40
#endif
sl@0
    41
sl@0
    42
//
sl@0
    43
//
sl@0
    44
//Test macroes and functions
sl@0
    45
//
sl@0
    46
//
sl@0
    47
#ifdef __ECOM_SERVER_TESTABILITY__
sl@0
    48
static void Check(TInt aValue, TInt aLine)
sl@0
    49
	{
sl@0
    50
	if(!aValue)
sl@0
    51
		{
sl@0
    52
		TheTest(EFalse, aLine);
sl@0
    53
		}
sl@0
    54
	}
sl@0
    55
#define TEST(arg) ::Check((arg), __LINE__)
sl@0
    56
#endif
sl@0
    57
sl@0
    58
sl@0
    59
static  void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0
    60
	{
sl@0
    61
	if(aValue != aExpected)
sl@0
    62
		{
sl@0
    63
		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
    64
		TheTest(EFalse, aLine);
sl@0
    65
		}
sl@0
    66
	}
sl@0
    67
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
sl@0
    68
sl@0
    69
//
sl@0
    70
//
sl@0
    71
//Helper functions
sl@0
    72
//
sl@0
    73
//
sl@0
    74
sl@0
    75
/**
sl@0
    76
* Add plugins to C: drive so they can be discovered during NonStatic discovery
sl@0
    77
* state.
sl@0
    78
*/
sl@0
    79
static void SetupFiles()
sl@0
    80
	{
sl@0
    81
	TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExampleDllOnZ, KEComExampleDllOnC));
sl@0
    82
	TEST2(err, KErrNone);
sl@0
    83
sl@0
    84
	TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginRscOnZ, KEComPluginRscOnC));
sl@0
    85
	TEST2(err, KErrNone);
sl@0
    86
	}
sl@0
    87
sl@0
    88
/**
sl@0
    89
* Remove the plugins from C: drive so we can leave a clean environment for
sl@0
    90
* the next test.
sl@0
    91
*/
sl@0
    92
static void CleanupFiles()
sl@0
    93
	{
sl@0
    94
	TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComExampleDllOnC));
sl@0
    95
	TEST2(err, KErrNone);
sl@0
    96
sl@0
    97
	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginRscOnC));
sl@0
    98
	TEST2(err, KErrNone);
sl@0
    99
	}
sl@0
   100
sl@0
   101
static void KillEComServerL()
sl@0
   102
	{
sl@0
   103
	//Need to ensure that the EComServer process is killed before even starting this test by using
sl@0
   104
   	//the EComTestUtils library
sl@0
   105
   	_LIT(KEComServerProcessName,"ecomserver");
sl@0
   106
   	TRAPD(error, EComTestUtils::KillProcessL(KEComServerProcessName));
sl@0
   107
   	error=error;
sl@0
   108
	}
sl@0
   109
sl@0
   110
/**
sl@0
   111
* Test if the requested plugin is discovered
sl@0
   112
*@param			aInterfaceUid A UID specifying the required interface.
sl@0
   113
*@param			aResolutionParameters A descriptor specifying any additional
sl@0
   114
*				implementation characteristics to be fulfilled.
sl@0
   115
*@return		return TRUE if plugin exists
sl@0
   116
*/
sl@0
   117
TBool TestForPlugin(TUid aInterfaceUid,
sl@0
   118
					const TDesC8& aDataType)
sl@0
   119
	{
sl@0
   120
	TBool result = EFalse;
sl@0
   121
	RImplInfoPtrArray aImplInfoArray;
sl@0
   122
	TEComResolverParams resolverParams;
sl@0
   123
	resolverParams.SetDataType(aDataType);
sl@0
   124
	resolverParams.SetGenericMatch(ETrue);	// Allow wildcard matching
sl@0
   125
sl@0
   126
	REComSession::ListImplementationsL(
sl@0
   127
			aInterfaceUid,
sl@0
   128
			resolverParams,
sl@0
   129
			aImplInfoArray);
sl@0
   130
sl@0
   131
	if(aImplInfoArray.Count() > 0)
sl@0
   132
		{
sl@0
   133
		result = ETrue;
sl@0
   134
		}
sl@0
   135
sl@0
   136
	aImplInfoArray.ResetAndDestroy();
sl@0
   137
sl@0
   138
	return result;
sl@0
   139
	}
sl@0
   140
sl@0
   141
//
sl@0
   142
//
sl@0
   143
//Test functions
sl@0
   144
//
sl@0
   145
//
sl@0
   146
#ifdef __ECOM_SERVER_TESTABILITY__
sl@0
   147
/**
sl@0
   148
@SYMTestCaseID		SYSLIB-ECOM-CIT-0187
sl@0
   149
@SYMTestCaseDesc 	The SSA is disabled, the ECOM will do a full discovery with the
sl@0
   150
simulated Domain Manager.
sl@0
   151
@SYMTestPriority 	High
sl@0
   152
@SYMTestActions  	Check the plugins and the state of ECOM using client API
sl@0
   153
GetCurrentStartupStateL and ListImplementationsL.
sl@0
   154
@SYMTestExpectedResults The test must not fail.
sl@0
   155
@SYMPREQ PREQ967
sl@0
   156
*/
sl@0
   157
LOCAL_C void TestEcomSsaDisabledL()
sl@0
   158
	{
sl@0
   159
	// Set up for heap leak checking
sl@0
   160
	__UHEAP_MARK;
sl@0
   161
sl@0
   162
	// and leaking thread handles
sl@0
   163
	TInt startProcessHandleCount;
sl@0
   164
	TInt startThreadHandleCount;
sl@0
   165
	TInt endProcessHandleCount;
sl@0
   166
	TInt endThreadHandleCount;
sl@0
   167
	TInt state = EStartupStateUndefined;
sl@0
   168
sl@0
   169
	// Test Starts...
sl@0
   170
sl@0
   171
	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
sl@0
   172
sl@0
   173
	TUid ifUid = {0x10009DC0};
sl@0
   174
sl@0
   175
	DisableSsa(TheTest, TheFs);
sl@0
   176
sl@0
   177
	//Open the ecom session which in turn should start the ecom server.
sl@0
   178
	//Next, wait to make sure that all the plugins are discovered.
sl@0
   179
	//Finally, get rid of the ecom session.
sl@0
   180
	REComSession& ecomSession = REComSession::OpenL();
sl@0
   181
	CleanupClosePushL(ecomSession);
sl@0
   182
	User::After(KOneSecond*10); //delay for 10 sec to ensure all plugins are discovered
sl@0
   183
	CleanupStack::PopAndDestroy(&ecomSession);
sl@0
   184
sl@0
   185
	//check that current state is EStartupStateUndefined
sl@0
   186
	TRAPD(err, state = GetCurrentStartupStateL());
sl@0
   187
	TEST2(err, KErrNone);
sl@0
   188
	TEST2(state, EStartupStateNonCritical);
sl@0
   189
	TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnZ()));
sl@0
   190
	TEST2(ETrue, TestForPlugin(ifUid, KImplementationDataOnC()));
sl@0
   191
sl@0
   192
	REComSession::FinalClose();
sl@0
   193
sl@0
   194
	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
sl@0
   195
sl@0
   196
	TEST(startProcessHandleCount == endProcessHandleCount);
sl@0
   197
	TEST(startThreadHandleCount  == endThreadHandleCount);
sl@0
   198
sl@0
   199
	// Test Ends...
sl@0
   200
sl@0
   201
	__UHEAP_MARKEND;
sl@0
   202
	}
sl@0
   203
#endif //__ECOM_SERVER_TESTABILITY__
sl@0
   204
sl@0
   205
#ifdef __ECOM_SERVER_TESTABILITY__
sl@0
   206
// Type definition for pointer to member function.
sl@0
   207
// Used in calling t_ServerStartupMgr test functions.
sl@0
   208
typedef void (*ClassFuncPtrL) (void);
sl@0
   209
sl@0
   210
/**
sl@0
   211
Wrapper function to call all test functions
sl@0
   212
@param		testFunc pointer to test function
sl@0
   213
@param		aTestDesc test function name
sl@0
   214
*/
sl@0
   215
LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
sl@0
   216
	{
sl@0
   217
	TheTest.Next(aTestDesc);
sl@0
   218
sl@0
   219
	__UHEAP_MARK;
sl@0
   220
  	// find out the number of open handles
sl@0
   221
	TInt startProcessHandleCount;
sl@0
   222
	TInt startThreadHandleCount;
sl@0
   223
	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
sl@0
   224
sl@0
   225
	testFuncL();
sl@0
   226
sl@0
   227
	// check that no handles have leaked
sl@0
   228
	TInt endProcessHandleCount;
sl@0
   229
	TInt endThreadHandleCount;
sl@0
   230
	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
sl@0
   231
sl@0
   232
	TEST(startProcessHandleCount == endProcessHandleCount);
sl@0
   233
	TEST(startThreadHandleCount  == endThreadHandleCount);
sl@0
   234
sl@0
   235
	__UHEAP_MARKEND;
sl@0
   236
	}
sl@0
   237
#endif //__ECOM_SERVER_TESTABILITY__
sl@0
   238
sl@0
   239
LOCAL_C void DoTestsL()
sl@0
   240
	{
sl@0
   241
#ifdef __ECOM_SERVER_TESTABILITY__
sl@0
   242
	DoBasicTestL(&TestEcomSsaDisabledL, _L("TestEcomSsaDisabledL"));
sl@0
   243
#endif //__ECOM_SERVER_TESTABILITY__
sl@0
   244
sl@0
   245
	//We are not going to run OOM tests for several reasons:
sl@0
   246
	//1- These tests are already done as part of the CEcomServer and
sl@0
   247
	//CServerStartupMgr OOM tests
sl@0
   248
	//2- EcomServer is running on another process
sl@0
   249
	//3- We need to kill the EcomServer and start it again.
sl@0
   250
sl@0
   251
	//For similar reasons to why we do not run OOM tests we should also
sl@0
   252
	//not test Ecom startup behaviour in this component test executable.
sl@0
   253
	//We will need to implement a new test executable for each test.
sl@0
   254
	}
sl@0
   255
sl@0
   256
GLDEF_C TInt E32Main()
sl@0
   257
	{
sl@0
   258
	__UHEAP_MARK;
sl@0
   259
	TheTest.Printf(_L("\n"));
sl@0
   260
	TheTest.Title();
sl@0
   261
	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-ECOM-CIT-0187 Ecom Ssa Tests "));
sl@0
   262
sl@0
   263
	TEST2(TheFs.Connect(), KErrNone);
sl@0
   264
sl@0
   265
	// get clean-up stack
sl@0
   266
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   267
sl@0
   268
	TRAPD(err, ::KillEComServerL());
sl@0
   269
	TEST2(err, KErrNone);
sl@0
   270
sl@0
   271
	DisableEcomTestBehaviour(TheTest, TheFs);
sl@0
   272
sl@0
   273
	SetupFiles(); //Add plugins to C: drive
sl@0
   274
sl@0
   275
	TRAP(err,DoTestsL());
sl@0
   276
	TEST2(err, KErrNone);
sl@0
   277
sl@0
   278
	CleanupFiles(); //Cleanup after test. Remove the plugins from C: drive
sl@0
   279
sl@0
   280
	ResetSsa(TheTest, TheFs);
sl@0
   281
sl@0
   282
	//Make sure that following tests start a fresh version of EComServer
sl@0
   283
	TRAP(err, ::KillEComServerL());
sl@0
   284
sl@0
   285
	TheTest.End();
sl@0
   286
	TheTest.Close();
sl@0
   287
sl@0
   288
	//delete scheduler;
sl@0
   289
	delete cleanup;
sl@0
   290
sl@0
   291
	TheFs.Close();
sl@0
   292
sl@0
   293
	__UHEAP_MARKEND;
sl@0
   294
sl@0
   295
	User::Heap().Check();
sl@0
   296
sl@0
   297
	return KErrNone;
sl@0
   298
	}
sl@0
   299
sl@0
   300