os/ossrv/lowlevellibsandfws/pluginfw/Framework/ResolverTest/ResolverUnitTests.inl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1997-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
// The implementation of the CResolver unit test classes.
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "ResolverStateAccessor.h"
sl@0
    19
sl@0
    20
const TUid KCExampleInterfaceUid			= {0x10009DC0};
sl@0
    21
const TUid KCExampleInterfaceImp			= {0x10009DC1};
sl@0
    22
sl@0
    23
// ______________________________________________________________________________
sl@0
    24
//
sl@0
    25
_LIT(KDefaultResolverCreateAndDestroyUnitTest,"CDefaultResolver_CreateAndDestroy_UnitTest");
sl@0
    26
sl@0
    27
CDefaultResolver_CreateAndDestroy_UnitTest* CDefaultResolver_CreateAndDestroy_UnitTest::NewL(CDataLogger& aDataLogger,
sl@0
    28
											MUnitTestObserver& aObserver)
sl@0
    29
	{
sl@0
    30
	CDefaultResolver_CreateAndDestroy_UnitTest* self = 
sl@0
    31
					new(ELeave) CDefaultResolver_CreateAndDestroy_UnitTest(aDataLogger,
sl@0
    32
																aObserver);
sl@0
    33
	CleanupStack::PushL(self);
sl@0
    34
	self->ConstructL();
sl@0
    35
	CleanupStack::Pop();
sl@0
    36
	return self; 
sl@0
    37
	}
sl@0
    38
sl@0
    39
inline TInt CDefaultResolver_CreateAndDestroy_UnitTest::RunError(TInt aError)
sl@0
    40
	{
sl@0
    41
	// The RunL left so chain to the base first and then cleanup
sl@0
    42
	TInt error = CUnitTest::RunError(aError);	// Chain to base
sl@0
    43
	delete iUTContext;
sl@0
    44
	iUTContext = NULL;
sl@0
    45
	delete iStateAccessor;
sl@0
    46
	iStateAccessor = NULL;
sl@0
    47
	/* delete any validators used */
sl@0
    48
	delete iCtorValidator;
sl@0
    49
	iCtorValidator = NULL;
sl@0
    50
	delete iDtorValidator;
sl@0
    51
	iDtorValidator = NULL;
sl@0
    52
	return error;
sl@0
    53
	}
sl@0
    54
sl@0
    55
inline CDefaultResolver_CreateAndDestroy_UnitTest::~CDefaultResolver_CreateAndDestroy_UnitTest()
sl@0
    56
	{
sl@0
    57
	// Simply delete our test class instance
sl@0
    58
	delete iUTContext;
sl@0
    59
	delete iStateAccessor;
sl@0
    60
sl@0
    61
	// delete any validators used
sl@0
    62
	delete iCtorValidator;
sl@0
    63
	delete iDtorValidator;
sl@0
    64
	}
sl@0
    65
sl@0
    66
inline CDefaultResolver_CreateAndDestroy_UnitTest::CDefaultResolver_CreateAndDestroy_UnitTest(CDataLogger& aDataLogger,
sl@0
    67
																	MUnitTestObserver& aObserver)
sl@0
    68
: CUnitTest(KDefaultResolverCreateAndDestroyUnitTest, aDataLogger, aObserver)
sl@0
    69
	{
sl@0
    70
	//Do nothing
sl@0
    71
	}
sl@0
    72
sl@0
    73
// Now the Individual transitions need to be added.
sl@0
    74
inline void CDefaultResolver_CreateAndDestroy_UnitTest::ConstructL()
sl@0
    75
	{
sl@0
    76
	// Perform the base class initialization
sl@0
    77
	UnitTestConstructL();
sl@0
    78
sl@0
    79
	// Create the Unit test state accessor
sl@0
    80
	iStateAccessor = new(ELeave) TDefaultResolver_StateAccessor;
sl@0
    81
	// Construct the Unit test context.
sl@0
    82
	iUTContext = new(ELeave) CDefaultResolver_UnitTestContext(iDataLogger, 
sl@0
    83
															  *iStateAccessor, 
sl@0
    84
															  *this);
sl@0
    85
sl@0
    86
	User::LeaveIfError(iUTContext->iFs.Connect());
sl@0
    87
sl@0
    88
	// Add the Transitions in the order they are to run
sl@0
    89
	// C'tor first, D'tor last...
sl@0
    90
	iCtorValidator = new(ELeave) TDefaultResolver_Ctor_TransitionValidator(*iUTContext);
sl@0
    91
	iDtorValidator = new(ELeave) TDefaultResolver_Dtor_TransitionValidator(*iUTContext);
sl@0
    92
sl@0
    93
	AddTransitionL(new(ELeave)CDefaultResolver_NewL_Transition(*iUTContext,*iCtorValidator));
sl@0
    94
	AddTransitionL(new(ELeave)CDefaultResolver_Dtor_Transition(*iUTContext,*iDtorValidator));
sl@0
    95
	}
sl@0
    96
sl@0
    97
void CDefaultResolver_CreateAndDestroy_UnitTest::PrepareUnitTestL()
sl@0
    98
	{
sl@0
    99
	iUTContext->iRegistry = CRegistryData::NewL(iUTContext->iFs);
sl@0
   100
	}
sl@0
   101
sl@0
   102
// ______________________________________________________________________________
sl@0
   103
//
sl@0
   104
_LIT(KDefaultResolverIdentifyImplementationUnitTest,"CDefaultResolver_IdentifyImplementation_UnitTest");
sl@0
   105
sl@0
   106
CDefaultResolver_IdentifyImplementation_UnitTest* CDefaultResolver_IdentifyImplementation_UnitTest::NewL(CDataLogger& aDataLogger,
sl@0
   107
											MUnitTestObserver& aObserver)
sl@0
   108
	{
sl@0
   109
	CDefaultResolver_IdentifyImplementation_UnitTest* self = 
sl@0
   110
					new(ELeave) CDefaultResolver_IdentifyImplementation_UnitTest(aDataLogger,
sl@0
   111
																aObserver);
sl@0
   112
	CleanupStack::PushL(self);
sl@0
   113
	self->ConstructL();
sl@0
   114
	CleanupStack::Pop();
sl@0
   115
	return self; 
sl@0
   116
	}
sl@0
   117
sl@0
   118
inline TInt CDefaultResolver_IdentifyImplementation_UnitTest::RunError(TInt aError)
sl@0
   119
	{
sl@0
   120
	// The RunL left so chain to the base first and then cleanup
sl@0
   121
	TInt error = CUnitTest::RunError(aError);	// Chain to base
sl@0
   122
sl@0
   123
	// Delete all the iImplementationData (which we created)
sl@0
   124
	while(iUTContext->iImplementationData.Count())
sl@0
   125
		{
sl@0
   126
		CImplementationInformation* impInfo = iUTContext->iImplementationData[0];
sl@0
   127
		iUTContext->iImplementationData.Remove(0);
sl@0
   128
		delete impInfo;
sl@0
   129
		}
sl@0
   130
sl@0
   131
	delete iUTContext;
sl@0
   132
	delete iStateAccessor;
sl@0
   133
	// delete any validators used
sl@0
   134
	delete iCtorValidator;
sl@0
   135
	delete iDefaultValidator;
sl@0
   136
	delete iMatchValidator;
sl@0
   137
	delete iIdentifyImplementationValidator;
sl@0
   138
	delete iDtorValidator;
sl@0
   139
sl@0
   140
	return error;
sl@0
   141
	}
sl@0
   142
sl@0
   143
inline CDefaultResolver_IdentifyImplementation_UnitTest::~CDefaultResolver_IdentifyImplementation_UnitTest()
sl@0
   144
	{
sl@0
   145
	if(iUTContext)
sl@0
   146
		{
sl@0
   147
		// Delete all the iImplementationData (which we created)
sl@0
   148
		while(iUTContext->iImplementationData.Count())
sl@0
   149
			{
sl@0
   150
			CImplementationInformation* impInfo = iUTContext->iImplementationData[0];
sl@0
   151
			iUTContext->iImplementationData.Remove(0);
sl@0
   152
			delete impInfo;
sl@0
   153
			}
sl@0
   154
		delete iUTContext;
sl@0
   155
		}
sl@0
   156
sl@0
   157
	delete iStateAccessor;
sl@0
   158
	// delete any validators used
sl@0
   159
	delete iCtorValidator;
sl@0
   160
	delete iDefaultValidator;
sl@0
   161
	delete iMatchValidator;
sl@0
   162
	delete iIdentifyImplementationValidator;
sl@0
   163
	delete iDtorValidator;
sl@0
   164
	}
sl@0
   165
sl@0
   166
inline CDefaultResolver_IdentifyImplementation_UnitTest::CDefaultResolver_IdentifyImplementation_UnitTest(CDataLogger& aDataLogger,
sl@0
   167
																	MUnitTestObserver& aObserver)
sl@0
   168
: CUnitTest(KDefaultResolverIdentifyImplementationUnitTest, aDataLogger, aObserver)
sl@0
   169
	{
sl@0
   170
	//Do nothing
sl@0
   171
	}
sl@0
   172
sl@0
   173
// Now the Individual transitions need to be added.
sl@0
   174
inline void CDefaultResolver_IdentifyImplementation_UnitTest::ConstructL()
sl@0
   175
	{
sl@0
   176
	// Perform the base class initialization
sl@0
   177
	UnitTestConstructL();
sl@0
   178
sl@0
   179
	// Create the Unit test state accessor
sl@0
   180
	iStateAccessor = new(ELeave) TDefaultResolver_StateAccessor;
sl@0
   181
sl@0
   182
	// Construct the Unit test context.
sl@0
   183
	iUTContext = new(ELeave) CDefaultResolver_UnitTestContext(iDataLogger, *iStateAccessor, *this);
sl@0
   184
	User::LeaveIfError(iUTContext->iFs.Connect());
sl@0
   185
	iUTContext->iRegistry = CRegistryData::NewL(iUTContext->iFs);
sl@0
   186
sl@0
   187
	// Set up the match type and implementation type for use in the Match transition
sl@0
   188
	_LIT8(KResolveImplementationType, "DataType2||DataType1");
sl@0
   189
	_LIT8(KResolveMatchType, "DataType1");
sl@0
   190
sl@0
   191
	iUTContext->iImplementationType = HBufC8::NewMaxL(KResolveImplementationType().Length());
sl@0
   192
	TPtr8 impType = iUTContext->iImplementationType->Des();
sl@0
   193
	impType = KResolveImplementationType;
sl@0
   194
sl@0
   195
	iUTContext->iMatchType = HBufC8::NewMaxL(KResolveMatchType().Length());
sl@0
   196
	TPtr8 matchType = iUTContext->iMatchType->Des();
sl@0
   197
	matchType = KResolveMatchType;
sl@0
   198
sl@0
   199
	iUTContext->iExpectedMatchResult = ETrue; // Based on iMatchType and iImplementationType
sl@0
   200
sl@0
   201
	iUTContext->iInterfaceUid.iUid = KCExampleInterfaceUid.iUid;
sl@0
   202
sl@0
   203
	TUid impUid;
sl@0
   204
	impUid.iUid = KCExampleInterfaceImp.iUid;
sl@0
   205
	HBufC8* implType = HBufC8::NewMaxL(KResolveImplementationType().Length());
sl@0
   206
	TPtr8 impPtr = implType->Des();
sl@0
   207
	impPtr = KResolveImplementationType;
sl@0
   208
	TDriveUnit drive(EDriveC);
sl@0
   209
	CImplementationInformation* impData = 
sl@0
   210
		CImplementationInformation::NewL(impUid, 0, NULL, implType, NULL, drive, EFalse, EFalse);
sl@0
   211
	CleanupStack::PushL(impData);
sl@0
   212
	User::LeaveIfError(iUTContext->iImplementationData.Append(impData));
sl@0
   213
	CleanupStack::Pop(impData);
sl@0
   214
sl@0
   215
	iUTContext->iAdditionalParameters.SetDataType(*iUTContext->iMatchType);
sl@0
   216
sl@0
   217
	// Add the Transitions in the order they are to run
sl@0
   218
	// C'tor first, D'tor last...
sl@0
   219
	iCtorValidator = new(ELeave) TDefaultResolver_Ctor_TransitionValidator(*iUTContext);
sl@0
   220
	iIdentifyImplementationValidator = new(ELeave) TDefaultResolver_IdentifyImplementationL_TransitionValidator(*iUTContext);
sl@0
   221
	iDefaultValidator = new(ELeave) TDefaultResolver_Default_TransitionValidator(*iUTContext);
sl@0
   222
	iMatchValidator = new(ELeave) TDefaultResolver_Match_TransitionValidator(*iUTContext);
sl@0
   223
	iDtorValidator = new(ELeave) TDefaultResolver_Dtor_TransitionValidator(*iUTContext);
sl@0
   224
sl@0
   225
	AddTransitionL(new(ELeave)CDefaultResolver_NewL_Transition(*iUTContext,*iCtorValidator));
sl@0
   226
	AddTransitionL(new(ELeave)CDefaultResolver_Match_Transition(*iUTContext,*iMatchValidator));
sl@0
   227
	AddTransitionL(new(ELeave)CDefaultResolver_Resolve_Transition(*iUTContext,*iDefaultValidator));
sl@0
   228
	AddTransitionL(new(ELeave)CDefaultResolver_IdentifyImplementationL_Transition(*iUTContext,*iIdentifyImplementationValidator));
sl@0
   229
	AddTransitionL(new(ELeave)CDefaultResolver_Dtor_Transition(*iUTContext,*iDtorValidator));
sl@0
   230
sl@0
   231
	// Add the permissible error codes for failures
sl@0
   232
	AddLeaveErrorCodeL(KEComErrNoInterfaceIdentified);
sl@0
   233
	}
sl@0
   234