os/kernelhwsrv/kerneltest/e32test/power/t_domain.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-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 the License "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
// e32test\power\t_domain.cpp
sl@0
    15
// Overview:
sl@0
    16
// Domain manager tests
sl@0
    17
// API Information:
sl@0
    18
// RDmDomain, RDmDomainManager CDmDomain, CDmDomainManager
sl@0
    19
// Details:
sl@0
    20
// - Test a variety of domain transitions, check the expected number of
sl@0
    21
// notifications and the first expected ordinal. Verify results are
sl@0
    22
// as expected.
sl@0
    23
// - Test system standby, check the expected number of notifications and 
sl@0
    24
// the first expected ordinal. Use a timer to request a wakeup event.
sl@0
    25
// Verify results are as expected.
sl@0
    26
// - Test domain related simple error situations, verify results are
sl@0
    27
// as expected.
sl@0
    28
// - Perform platform security tests: launch a separate process with no 
sl@0
    29
// capabilities, verify that results are as expected.
sl@0
    30
// - Test domain transitions by connecting to two domain hierarchies 
sl@0
    31
// simultaneously, add some test and power hierarchy members, verify
sl@0
    32
// the expected target state, notifications and leaf nodes. Verify results.
sl@0
    33
// - Verify that the same hierarchy can not be connected to more than once.
sl@0
    34
// - Request a positive transition and request that the test domain use 
sl@0
    35
// ETraverseParentsFirst. Verify results are as expected and verify 
sl@0
    36
// domains are in the correct state.
sl@0
    37
// - Request a negative transition and request that the test domain use 
sl@0
    38
// ETraverseChildrenFirst. Verify results are as expected.
sl@0
    39
// - Request a positive transition with zero acknowledgements. Verify 
sl@0
    40
// results are as expected.
sl@0
    41
// - Request a positive transition with error acknowledgements. Verify 
sl@0
    42
// results are as expected.
sl@0
    43
// - Perform a variety of negative tests and verify results are as expected.
sl@0
    44
// - Perform various tests on domain transitions with activated observer.
sl@0
    45
// Verify results are as expected.
sl@0
    46
// Platforms/Drives/Compatibility:
sl@0
    47
// All.
sl@0
    48
// Assumptions/Requirement/Pre-requisites:
sl@0
    49
// Failures and causes:
sl@0
    50
// Base Port information:
sl@0
    51
// 
sl@0
    52
//
sl@0
    53
sl@0
    54
#include <e32test.h>
sl@0
    55
#include <domainmember.h>
sl@0
    56
#include <domainmanager.h>
sl@0
    57
#include <domainobserver.h>
sl@0
    58
#include "domainpolicytest.h"
sl@0
    59
#include <e32debug.h>
sl@0
    60
#include <f32file.h>
sl@0
    61
#include <e32ldr.h>
sl@0
    62
#include <e32ldr_private.h>
sl@0
    63
sl@0
    64
LOCAL_D RTest test(_L(" T_DOMAIN "));
sl@0
    65
_LIT(KThreadName, "t_domain_panic_thread");
sl@0
    66
sl@0
    67
#ifdef _DEBUG
sl@0
    68
#define __PRINT(x) {RDebug::Print x;}
sl@0
    69
#else
sl@0
    70
#define __PRINT(x) 
sl@0
    71
#endif
sl@0
    72
sl@0
    73
class CDmTestMember;
sl@0
    74
sl@0
    75
// interface for test domain memebers.
sl@0
    76
// Any test memeber should derive from this interface 
sl@0
    77
class MDmDomainMember
sl@0
    78
	{
sl@0
    79
public:
sl@0
    80
	virtual TDmHierarchyId HierarchyId() = 0;
sl@0
    81
	virtual TDmDomainId	DomainId() = 0;
sl@0
    82
	virtual TDmDomainState State() = 0;
sl@0
    83
	virtual TInt Status() = 0;
sl@0
    84
	virtual TUint32 Ordinal() = 0;
sl@0
    85
	virtual TInt Notifications() = 0;
sl@0
    86
	};
sl@0
    87
sl@0
    88
class MDmTest
sl@0
    89
	{
sl@0
    90
public:
sl@0
    91
	virtual void Perform() = 0;
sl@0
    92
	virtual void Release() = 0;
sl@0
    93
	virtual TInt TransitionNotification(MDmDomainMember& aDomainMember) = 0;
sl@0
    94
	virtual void TransitionRequestComplete() = 0;
sl@0
    95
	};
sl@0
    96
sl@0
    97
// for the test hierarchy, we generate an ordinal for each domain
sl@0
    98
// each byte of which describes the exact location of the domain in the hierarchy
sl@0
    99
#define ORDINAL_FROM_DOMAINID0(id) (id)
sl@0
   100
#define ORDINAL_FROM_DOMAINID1(parent, id) ((parent << 8) | (id))
sl@0
   101
#define ORDINAL_FROM_DOMAINID2(grandparent, parent, id) ((grandparent << 16) | (parent << 8) | id)
sl@0
   102
#define ORDINAL_FROM_DOMAINID3(greatgrandparent, grandparent, parent, id) ((greatgrandparent << 24) | (grandparent << 16) | (parent << 8) | id)
sl@0
   103
#define PARENT_ORDINAL(id) (id >> 8)
sl@0
   104
sl@0
   105
#define ORDINAL_LEVEL(ordinal)			\
sl@0
   106
	((ordinal & 0xFF00) == 0) ? 1 :			\
sl@0
   107
	((ordinal & 0xFF0000) == 0) ? 2 :		\
sl@0
   108
	((ordinal & 0xFF000000) == 0) ? 3 : 4;
sl@0
   109
sl@0
   110
sl@0
   111
// get the least significant domain id character (for debugging purposes)
sl@0
   112
TBool GetDomainChar(TDmDomainId aDomainId, TChar& aChar)
sl@0
   113
	{
sl@0
   114
	TBool found = ETrue;
sl@0
   115
	switch(aDomainId)
sl@0
   116
		{
sl@0
   117
		
sl@0
   118
		case KDmIdTestA:	aChar = 'A'; break;
sl@0
   119
		case KDmIdTestB:	aChar = 'B'; break;
sl@0
   120
		case KDmIdTestC:	aChar = 'C'; break;
sl@0
   121
		case KDmIdTestAA:	aChar = 'A'; break;
sl@0
   122
		case KDmIdTestAB:	aChar = 'B'; break;
sl@0
   123
		case KDmIdTestBA:	aChar = 'A'; break;
sl@0
   124
		case KDmIdTestCA:	aChar = 'A'; break;
sl@0
   125
		case KDmIdTestABA:	aChar = 'A'; break;
sl@0
   126
		case KDmIdTestABB:	aChar = 'B'; break;
sl@0
   127
		case KDmIdTestCAA:	aChar = 'A'; break;
sl@0
   128
		// domain char not found 
sl@0
   129
		case KDmIdNone:
sl@0
   130
		case KDmIdRoot:		
sl@0
   131
		default:			
sl@0
   132
			found = EFalse;
sl@0
   133
		}
sl@0
   134
	return found;
sl@0
   135
	}
sl@0
   136
sl@0
   137
// prints the 4-character domain string into the passed descriptor (for debugging purposes)
sl@0
   138
// e.g. "CAA" for KDmIdTestCAA
sl@0
   139
void GetDomainDesc(TUint32 aOrdinal, TDes& aDes)
sl@0
   140
	{
sl@0
   141
	if (aOrdinal == KDmIdRoot)
sl@0
   142
		{
sl@0
   143
		aDes.Append(_L("root"));
sl@0
   144
		return;
sl@0
   145
		}
sl@0
   146
sl@0
   147
	TUint32 val =  aOrdinal;
sl@0
   148
sl@0
   149
	for (TInt n=0; n<4; n++)
sl@0
   150
		{
sl@0
   151
		TDmDomainId domainId = (TDmDomainId) (val >> 24);
sl@0
   152
		TChar ch;
sl@0
   153
		TBool found = GetDomainChar(domainId, ch);
sl@0
   154
		if (found)
sl@0
   155
			aDes.Append(ch);
sl@0
   156
		val = val << 8;
sl@0
   157
		}
sl@0
   158
sl@0
   159
	}
sl@0
   160
sl@0
   161
sl@0
   162
class CDmTestMember : public CActive, public MDmDomainMember
sl@0
   163
	{
sl@0
   164
public:	
sl@0
   165
	// from CActive
sl@0
   166
	void RunL();
sl@0
   167
	// from MDmDomainMember
sl@0
   168
	inline TDmHierarchyId HierarchyId() {return iHierarchy;};
sl@0
   169
	inline TDmDomainId	DomainId() {return iId;};
sl@0
   170
	inline TDmDomainState State() {return iState;};
sl@0
   171
	inline TInt Status() {return iStatus.Int();};
sl@0
   172
	inline TUint32 Ordinal() {return iOrdinal;};
sl@0
   173
	inline TInt Notifications() {return iNotifications;};
sl@0
   174
sl@0
   175
	CDmTestMember(TDmHierarchyId aHierarchy, TDmDomainId aId, TUint32 aOrdinal, MDmTest*);
sl@0
   176
	~CDmTestMember();
sl@0
   177
	void Acknowledge();
sl@0
   178
sl@0
   179
protected:
sl@0
   180
	// from CActive
sl@0
   181
	virtual void DoCancel();
sl@0
   182
sl@0
   183
sl@0
   184
public:
sl@0
   185
	TDmHierarchyId iHierarchy;
sl@0
   186
	TDmDomainId	iId;
sl@0
   187
	TDmDomainState iState;
sl@0
   188
	TUint32		iOrdinal;
sl@0
   189
	MDmTest*	iTest;	
sl@0
   190
	TInt		iNotifications;
sl@0
   191
	RDmDomain	iDomain;
sl@0
   192
	};
sl@0
   193
sl@0
   194
sl@0
   195
sl@0
   196
CDmTestMember::CDmTestMember(TDmHierarchyId aHierarchy, TDmDomainId aId, TUint32 aOrdinal, MDmTest* aTest) : CActive(CActive::EPriorityStandard), 
sl@0
   197
	iHierarchy(aHierarchy), iId(aId), iOrdinal(aOrdinal), iTest(aTest)
sl@0
   198
	{
sl@0
   199
	TInt r;
sl@0
   200
sl@0
   201
	if (iHierarchy == KDmHierarchyIdPower)
sl@0
   202
		 r = iDomain.Connect(iId);
sl@0
   203
	else
sl@0
   204
		 r = iDomain.Connect(iHierarchy, iId);
sl@0
   205
sl@0
   206
	test(r == KErrNone);
sl@0
   207
sl@0
   208
	CActiveScheduler::Add(this);
sl@0
   209
sl@0
   210
	iDomain.RequestTransitionNotification(CActive::iStatus);
sl@0
   211
	CActive::SetActive();
sl@0
   212
	}
sl@0
   213
sl@0
   214
CDmTestMember::~CDmTestMember()
sl@0
   215
	{
sl@0
   216
	CActive::Cancel();
sl@0
   217
	iDomain.Close();
sl@0
   218
	}
sl@0
   219
sl@0
   220
void CDmTestMember::Acknowledge()
sl@0
   221
	{
sl@0
   222
	iDomain.AcknowledgeLastState();
sl@0
   223
	}
sl@0
   224
sl@0
   225
void CDmTestMember::RunL()
sl@0
   226
	{
sl@0
   227
sl@0
   228
	iNotifications++;
sl@0
   229
sl@0
   230
	iState = iDomain.GetState();
sl@0
   231
sl@0
   232
	TInt ackError = iTest->TransitionNotification(*this);
sl@0
   233
	if (ackError == KErrNone)
sl@0
   234
		iDomain.AcknowledgeLastState();
sl@0
   235
	else if (ackError == KErrAbort)	// don't acknowledge
sl@0
   236
		;
sl@0
   237
	else
sl@0
   238
		iDomain.AcknowledgeLastState(ackError);
sl@0
   239
sl@0
   240
	
sl@0
   241
	// request another notification (even if we didn't acknowledge the last one)
sl@0
   242
	iDomain.RequestTransitionNotification(CActive::iStatus);
sl@0
   243
	CActive::SetActive();
sl@0
   244
	}
sl@0
   245
sl@0
   246
void CDmTestMember::DoCancel()
sl@0
   247
	{
sl@0
   248
	iDomain.CancelTransitionNotification();
sl@0
   249
	}
sl@0
   250
sl@0
   251
sl@0
   252
// CDomainMemberAo
sl@0
   253
class CDomainMemberAo : public CDmDomain, public MDmDomainMember
sl@0
   254
	{
sl@0
   255
public:	
sl@0
   256
	static CDomainMemberAo* NewL(TDmHierarchyId aHierarchy, TDmDomainId aId, TUint32 aOrdinal, MDmTest*);
sl@0
   257
	~CDomainMemberAo();
sl@0
   258
sl@0
   259
	// from CActive
sl@0
   260
	void RunL();
sl@0
   261
sl@0
   262
	// from MDmDomainMember
sl@0
   263
	inline TDmHierarchyId HierarchyId() {return iHierarchy;};
sl@0
   264
	inline TDmDomainId	DomainId() {return iId;};
sl@0
   265
	inline TDmDomainState State() {return iState;};
sl@0
   266
	inline TInt Status() {return iStatus.Int();};
sl@0
   267
	inline TUint32 Ordinal() {return iOrdinal;};
sl@0
   268
	inline TInt Notifications() {return iNotifications;};
sl@0
   269
sl@0
   270
private:
sl@0
   271
	CDomainMemberAo(TDmHierarchyId aHierarchy, TDmDomainId aId, TUint32 aOrdinal, MDmTest*);
sl@0
   272
sl@0
   273
public:
sl@0
   274
	TDmHierarchyId iHierarchy;
sl@0
   275
	TDmDomainId	iId;
sl@0
   276
	TDmDomainState iState;
sl@0
   277
	TUint32		iOrdinal;
sl@0
   278
	MDmTest*	iTest;	
sl@0
   279
	TInt		iNotifications;
sl@0
   280
	};
sl@0
   281
sl@0
   282
CDomainMemberAo* CDomainMemberAo::NewL(TDmHierarchyId aHierarchy, TDmDomainId aId, TUint32 aOrdinal, MDmTest* aTest)
sl@0
   283
	{
sl@0
   284
	CDomainMemberAo* self=new (ELeave) CDomainMemberAo(aHierarchy, aId, aOrdinal, aTest);
sl@0
   285
	CleanupStack::PushL(self);
sl@0
   286
	self->ConstructL();
sl@0
   287
sl@0
   288
	self->RequestTransitionNotification();
sl@0
   289
sl@0
   290
	CleanupStack::Pop();
sl@0
   291
	return self;
sl@0
   292
	}
sl@0
   293
sl@0
   294
CDomainMemberAo::CDomainMemberAo(TDmHierarchyId aHierarchy, TDmDomainId aId, TUint32 aOrdinal, MDmTest* aTest) : 
sl@0
   295
	CDmDomain(aHierarchy, aId), 
sl@0
   296
	iHierarchy(aHierarchy), iId(aId), iOrdinal(aOrdinal), iTest(aTest)
sl@0
   297
	{
sl@0
   298
	}
sl@0
   299
sl@0
   300
CDomainMemberAo::~CDomainMemberAo()
sl@0
   301
	{
sl@0
   302
	Cancel();
sl@0
   303
	}
sl@0
   304
sl@0
   305
void CDomainMemberAo::RunL()
sl@0
   306
	{
sl@0
   307
	iNotifications++;
sl@0
   308
sl@0
   309
	iState = GetState();
sl@0
   310
sl@0
   311
	TInt ackError = iTest->TransitionNotification(*this);
sl@0
   312
	if (ackError == KErrNone)
sl@0
   313
		AcknowledgeLastState(ackError);
sl@0
   314
	else if (ackError == KErrAbort)	// don't acknowledge
sl@0
   315
		;
sl@0
   316
	else
sl@0
   317
		AcknowledgeLastState(ackError); 
sl@0
   318
	if (ackError != KErrAbort)	
sl@0
   319
		AcknowledgeLastState(ackError);
sl@0
   320
sl@0
   321
	
sl@0
   322
	// request another notification (even if we didn't acknowledge the last one)
sl@0
   323
	RequestTransitionNotification();
sl@0
   324
	}
sl@0
   325
sl@0
   326
sl@0
   327
// CDomainManagerAo
sl@0
   328
class CDomainManagerAo : public CDmDomainManager
sl@0
   329
	{
sl@0
   330
public:	
sl@0
   331
	~CDomainManagerAo();
sl@0
   332
	static CDomainManagerAo* NewL(TDmHierarchyId aHierarchy, MDmTest& aTest);
sl@0
   333
sl@0
   334
	// from CActive
sl@0
   335
	void RunL();
sl@0
   336
sl@0
   337
private:
sl@0
   338
	CDomainManagerAo(TDmHierarchyId aHierarchy, MDmTest& aTest);
sl@0
   339
sl@0
   340
private:
sl@0
   341
	MDmTest& iTest;
sl@0
   342
	};
sl@0
   343
sl@0
   344
sl@0
   345
CDomainManagerAo* CDomainManagerAo::NewL(TDmHierarchyId aHierarchy, MDmTest& aTest)
sl@0
   346
	{
sl@0
   347
	CDomainManagerAo* self=new (ELeave) CDomainManagerAo(aHierarchy, aTest);
sl@0
   348
	CleanupStack::PushL(self);
sl@0
   349
sl@0
   350
	self->ConstructL();
sl@0
   351
	CleanupStack::Pop();
sl@0
   352
	return self;
sl@0
   353
	}
sl@0
   354
sl@0
   355
CDomainManagerAo::CDomainManagerAo(TDmHierarchyId aHierarchy, MDmTest& aTest) : 
sl@0
   356
	CDmDomainManager(aHierarchy), iTest(aTest)
sl@0
   357
	{
sl@0
   358
	}
sl@0
   359
sl@0
   360
CDomainManagerAo::~CDomainManagerAo()
sl@0
   361
	{
sl@0
   362
	}
sl@0
   363
sl@0
   364
void CDomainManagerAo::RunL()
sl@0
   365
	{
sl@0
   366
	iTest.TransitionRequestComplete();
sl@0
   367
	}
sl@0
   368
sl@0
   369
sl@0
   370
class CDmTest1 : public CActive, public MDmTest
sl@0
   371
	{
sl@0
   372
public: // from CActive
sl@0
   373
	void RunL();
sl@0
   374
sl@0
   375
	// from MDmTest
sl@0
   376
	void Perform();
sl@0
   377
	void Release();
sl@0
   378
	TInt TransitionNotification(MDmDomainMember& aDomainMember);
sl@0
   379
	void TransitionRequestComplete() {};
sl@0
   380
sl@0
   381
	CDmTest1 (TDmDomainId aId, TDmDomainState aState) : CActive(CActive::EPriorityStandard), iDomainId(aId), iState((TPowerState) aState) {}
sl@0
   382
sl@0
   383
protected:
sl@0
   384
	// from CActive
sl@0
   385
	virtual void DoCancel();
sl@0
   386
sl@0
   387
private:
sl@0
   388
	enum { KMembersMax = 16 };
sl@0
   389
	CDmTestMember*		iMembers[KMembersMax]; 
sl@0
   390
	RDmDomainManager	iManager;
sl@0
   391
	TDmDomainId			iDomainId;
sl@0
   392
	TPowerState			iState;
sl@0
   393
	TBool				iAcknowledge;
sl@0
   394
	TInt				iMembersCount;
sl@0
   395
	TInt				iCount;
sl@0
   396
	TUint32				iOrdinal;
sl@0
   397
	};
sl@0
   398
sl@0
   399
void CDmTest1::Perform()
sl@0
   400
	{
sl@0
   401
	//
sl@0
   402
	// Test domain transitions
sl@0
   403
	//
sl@0
   404
sl@0
   405
	test.Next(_L("Test 1"));
sl@0
   406
	test.Printf(_L("Domain id = 0x%x Target State = 0x%x\n"), iDomainId, iState);
sl@0
   407
	iMembers[0] = new CDmTestMember(KDmHierarchyIdPower, KDmIdRoot, 0, this);
sl@0
   408
	test(iMembers[0] != NULL);
sl@0
   409
	iMembers[1] = new CDmTestMember(KDmHierarchyIdPower, KDmIdRoot, 0, this);
sl@0
   410
	test(iMembers[1] != NULL);
sl@0
   411
	iMembers[2] = new CDmTestMember(KDmHierarchyIdPower, KDmIdApps, 1, this);
sl@0
   412
	test(iMembers[2] != NULL);
sl@0
   413
	iMembers[3] = new CDmTestMember(KDmHierarchyIdPower, KDmIdApps, 1, this);
sl@0
   414
	test(iMembers[3] != NULL);
sl@0
   415
	iMembers[4] = new CDmTestMember(KDmHierarchyIdPower, KDmIdUiApps, 1, this);
sl@0
   416
	test(iMembers[4] != NULL);
sl@0
   417
	iMembers[5] = new CDmTestMember(KDmHierarchyIdPower, KDmIdUiApps, 1, this);
sl@0
   418
	test(iMembers[5] != NULL);
sl@0
   419
	
sl@0
   420
	// expected number of notifications
sl@0
   421
	iMembersCount = (iDomainId == KDmIdRoot) ? 6 : 2;
sl@0
   422
	// first expected ordinal
sl@0
   423
	iOrdinal = (iState == EPwActive) ? 0 : 1;
sl@0
   424
sl@0
   425
	TInt r = iManager.Connect();
sl@0
   426
	test(r == KErrNone);
sl@0
   427
sl@0
   428
	CActiveScheduler::Add(this);
sl@0
   429
sl@0
   430
	iManager.RequestDomainTransition(iDomainId, iState, CActive::iStatus);
sl@0
   431
	CActive::SetActive();
sl@0
   432
sl@0
   433
	CActiveScheduler::Start();
sl@0
   434
	}
sl@0
   435
sl@0
   436
TInt CDmTest1::TransitionNotification(MDmDomainMember& aDomainMember)
sl@0
   437
	{
sl@0
   438
	++iCount;
sl@0
   439
	if (aDomainMember.State() == EPwActive)
sl@0
   440
		{
sl@0
   441
		if(aDomainMember.Ordinal() < iOrdinal)
sl@0
   442
			{
sl@0
   443
			// Making the test to fail in RunL function inorder to complete the cleanup from domain manager.
sl@0
   444
			test.Printf(_L("Making test to fail as Ordinal Mismatch Expected : %d, Returned : %d"), aDomainMember.Ordinal(), iOrdinal);
sl@0
   445
			iCount--;
sl@0
   446
			}
sl@0
   447
		}
sl@0
   448
	else
sl@0
   449
		{
sl@0
   450
		if(aDomainMember.Ordinal() > iOrdinal)
sl@0
   451
			{
sl@0
   452
			//Making the test to fail in RunL function inorder to complete the cleanup from domain manager.
sl@0
   453
			test.Printf(_L("Making test to fail as Ordinal Mismatch Expected : %d, Returned : %d"), aDomainMember.Ordinal(), iOrdinal);
sl@0
   454
			iCount--;
sl@0
   455
			}
sl@0
   456
		}
sl@0
   457
	iOrdinal = aDomainMember.Ordinal();
sl@0
   458
sl@0
   459
	// acknowledge one from two
sl@0
   460
	iAcknowledge = !iAcknowledge;
sl@0
   461
	return iAcknowledge?KErrNone:KErrGeneral;
sl@0
   462
	}
sl@0
   463
sl@0
   464
void CDmTest1::RunL()
sl@0
   465
	{
sl@0
   466
	CActiveScheduler::Stop();
sl@0
   467
sl@0
   468
	iManager.Close();
sl@0
   469
sl@0
   470
	CDmTestMember** mp;
sl@0
   471
	for (mp = iMembers; *mp; ++mp)
sl@0
   472
		delete *mp;
sl@0
   473
	test(iCount == iMembersCount);
sl@0
   474
	}
sl@0
   475
sl@0
   476
void CDmTest1::DoCancel()
sl@0
   477
	{
sl@0
   478
	test(0);
sl@0
   479
	}
sl@0
   480
sl@0
   481
void CDmTest1::Release()
sl@0
   482
	{
sl@0
   483
	delete this;
sl@0
   484
	}
sl@0
   485
sl@0
   486
class CDmTest2Timer : public CTimer
sl@0
   487
	{
sl@0
   488
public: // fomr CTimer
sl@0
   489
   void RunL();
sl@0
   490
public:
sl@0
   491
	CDmTest2Timer() : CTimer(0) 
sl@0
   492
		{
sl@0
   493
		TRAPD(r,
sl@0
   494
			ConstructL());
sl@0
   495
		test(r == KErrNone);
sl@0
   496
		CActiveScheduler::Add(this);
sl@0
   497
		}
sl@0
   498
	};
sl@0
   499
sl@0
   500
void CDmTest2Timer::RunL()
sl@0
   501
	{
sl@0
   502
	test.Printf(_L("Tick count after CDmTest2Timer::RunL() = %d\n"), User::NTickCount());
sl@0
   503
sl@0
   504
	// kick the timer again in case power down hasn't happened yet
sl@0
   505
	TTime wakeup;
sl@0
   506
	wakeup.HomeTime();
sl@0
   507
	wakeup += TTimeIntervalSeconds(3);
sl@0
   508
	At(wakeup);
sl@0
   509
	}
sl@0
   510
sl@0
   511
class CDmTest2 : public CActive, public MDmTest
sl@0
   512
	{
sl@0
   513
public: // from CActive
sl@0
   514
	void RunL();
sl@0
   515
sl@0
   516
	// from MDmTest
sl@0
   517
	void Perform();
sl@0
   518
	void Release();
sl@0
   519
	TInt TransitionNotification(MDmDomainMember& aDomainMember);
sl@0
   520
	void TransitionRequestComplete() {};
sl@0
   521
	CDmTest2 (TDmDomainState aState) : CActive(CActive::EPriorityStandard), iState((TPowerState) aState) {}
sl@0
   522
sl@0
   523
protected:
sl@0
   524
	// from CActive
sl@0
   525
	virtual void DoCancel();
sl@0
   526
sl@0
   527
private:
sl@0
   528
	enum { KMembersMax = 16 };
sl@0
   529
	CDmTestMember*		iMembers[KMembersMax]; 
sl@0
   530
	RDmDomainManager	iManager;
sl@0
   531
	TPowerState			iState;
sl@0
   532
	TBool				iAcknowledge;
sl@0
   533
	TInt				iMembersCount;
sl@0
   534
	TInt				iCount;
sl@0
   535
	TUint32				iOrdinal;
sl@0
   536
	CDmTest2Timer*		iTimer;
sl@0
   537
	};
sl@0
   538
sl@0
   539
sl@0
   540
void CDmTest2::Perform()
sl@0
   541
	{
sl@0
   542
	//
sl@0
   543
	// Test system standby
sl@0
   544
	//
sl@0
   545
sl@0
   546
	test.Next(_L("Test 2"));
sl@0
   547
	test.Printf(_L("Target State = 0x%x\n"), iState);
sl@0
   548
	iMembers[0] = new CDmTestMember(KDmHierarchyIdPower, KDmIdRoot, 0, this);
sl@0
   549
	test(iMembers[0] != NULL);
sl@0
   550
	iMembers[1] = new CDmTestMember(KDmHierarchyIdPower, KDmIdRoot, 0, this);
sl@0
   551
	test(iMembers[1] != NULL);
sl@0
   552
	iMembers[2] = new CDmTestMember(KDmHierarchyIdPower, KDmIdApps, 1, this);
sl@0
   553
	test(iMembers[2] != NULL);
sl@0
   554
	iMembers[3] = new CDmTestMember(KDmHierarchyIdPower, KDmIdApps, 1, this);
sl@0
   555
	test(iMembers[3] != NULL);
sl@0
   556
	iMembers[4] = new CDmTestMember(KDmHierarchyIdPower, KDmIdUiApps, 1, this);
sl@0
   557
	test(iMembers[4] != NULL);
sl@0
   558
	iMembers[5] = new CDmTestMember(KDmHierarchyIdPower, KDmIdUiApps, 1, this);
sl@0
   559
	test(iMembers[5] != NULL);
sl@0
   560
	
sl@0
   561
	// expected number of notifications
sl@0
   562
	iMembersCount = 12;
sl@0
   563
	// first expected ordinal
sl@0
   564
	iOrdinal = (iState == EPwActive) ? 0 : 1;
sl@0
   565
sl@0
   566
	TInt r = iManager.Connect();
sl@0
   567
	test(r == KErrNone);
sl@0
   568
sl@0
   569
	CActiveScheduler::Add(this);
sl@0
   570
sl@0
   571
	// Use an absolute timer to request a wakeup event
sl@0
   572
	iTimer = new CDmTest2Timer();
sl@0
   573
	TTime wakeup;
sl@0
   574
	wakeup.HomeTime();
sl@0
   575
	wakeup += TTimeIntervalSeconds(5);
sl@0
   576
	test.Printf(_L("Tick count before timer = %d\n"), User::NTickCount());
sl@0
   577
	iTimer->At(wakeup);
sl@0
   578
	
sl@0
   579
	iManager.RequestSystemTransition(iState, CActive::iStatus);
sl@0
   580
	CActive::SetActive();
sl@0
   581
sl@0
   582
	CActiveScheduler::Start();
sl@0
   583
	}
sl@0
   584
sl@0
   585
TInt CDmTest2::TransitionNotification(MDmDomainMember& aDomainMember)
sl@0
   586
	{
sl@0
   587
	++iCount;
sl@0
   588
	if (aDomainMember.State() == EPwActive)
sl@0
   589
		{
sl@0
   590
		if(aDomainMember.Ordinal() < iOrdinal)
sl@0
   591
			{
sl@0
   592
			// Making the test to fail in RunL function inorder to complete the cleanup from domain manager.
sl@0
   593
			test.Printf(_L("Making test to fail as Ordinal Mismatch Expected : %d, Returned : %d, State : %d"), 
sl@0
   594
																		aDomainMember.Ordinal(), iOrdinal, aDomainMember.State());
sl@0
   595
			iCount--;
sl@0
   596
			}
sl@0
   597
		}
sl@0
   598
	else
sl@0
   599
		{
sl@0
   600
		if(aDomainMember.Ordinal() > iOrdinal)
sl@0
   601
			{
sl@0
   602
			// Making the test to fail in RunL function inorder to complete the cleanup from domain manager.
sl@0
   603
			test.Printf(_L("Making test to fail as Ordinal Mismatch Expected : %d, Returned : %d, State: %d"), 
sl@0
   604
																		aDomainMember.Ordinal(), iOrdinal, aDomainMember.State());
sl@0
   605
			iCount--;
sl@0
   606
			}
sl@0
   607
		}
sl@0
   608
	iOrdinal = aDomainMember.Ordinal();
sl@0
   609
sl@0
   610
	// acknowledge one from two
sl@0
   611
	iAcknowledge = !iAcknowledge;
sl@0
   612
	return iAcknowledge?KErrNone:KErrAbort;
sl@0
   613
	}
sl@0
   614
sl@0
   615
void CDmTest2::RunL()
sl@0
   616
	{
sl@0
   617
	test.Printf(_L("Tick count after CDmTest2::RunL() = %d\n"), User::NTickCount());
sl@0
   618
sl@0
   619
	iTimer->Cancel();	
sl@0
   620
	CActiveScheduler::Stop();
sl@0
   621
sl@0
   622
	iManager.Close();
sl@0
   623
sl@0
   624
	CDmTestMember** mp;
sl@0
   625
	for (mp = iMembers; *mp; ++mp)
sl@0
   626
		delete *mp;
sl@0
   627
	test(CActive::iStatus == KErrTimedOut);
sl@0
   628
	test(iCount == iMembersCount);
sl@0
   629
	}
sl@0
   630
sl@0
   631
void CDmTest2::DoCancel()
sl@0
   632
	{
sl@0
   633
	test(0);
sl@0
   634
	}
sl@0
   635
sl@0
   636
void CDmTest2::Release()
sl@0
   637
	{
sl@0
   638
	if (iTimer)
sl@0
   639
		{
sl@0
   640
		iTimer->Cancel();
sl@0
   641
		delete iTimer;
sl@0
   642
		}
sl@0
   643
	delete this;
sl@0
   644
	}
sl@0
   645
sl@0
   646
class CDmTest3 : public MDmTest
sl@0
   647
	{
sl@0
   648
public: 
sl@0
   649
	// from MDmTest
sl@0
   650
	void Perform();
sl@0
   651
	void Release();
sl@0
   652
	TInt TransitionNotification(MDmDomainMember& aDomainMember);
sl@0
   653
	void TransitionRequestComplete() {};
sl@0
   654
	};
sl@0
   655
sl@0
   656
void CDmTest3::Perform()
sl@0
   657
	{
sl@0
   658
	//
sl@0
   659
	// Test simple error situation
sl@0
   660
	//
sl@0
   661
	RDmDomainManager manager;
sl@0
   662
	TInt r = manager.Connect();
sl@0
   663
	test(r == KErrNone);
sl@0
   664
sl@0
   665
	RDmDomainManager manager1;
sl@0
   666
	r = manager1.Connect();
sl@0
   667
	test(r == KErrInUse);
sl@0
   668
sl@0
   669
	RDmDomain domain;
sl@0
   670
	r = domain.Connect(KDmIdNone);
sl@0
   671
	test(r == KDmErrBadDomainId);
sl@0
   672
	CDmTestMember*		testMember;
sl@0
   673
	testMember = new CDmTestMember(KDmHierarchyIdPower, KDmIdApps, 1, this);
sl@0
   674
	test (testMember != NULL);
sl@0
   675
sl@0
   676
	TRequestStatus status;
sl@0
   677
	manager.RequestDomainTransition(KDmIdApps, EPwStandby, status);
sl@0
   678
	test(status.Int() == KRequestPending);
sl@0
   679
sl@0
   680
	TRequestStatus status1;
sl@0
   681
	manager.RequestDomainTransition(KDmIdApps, EPwActive, status1);
sl@0
   682
	User::WaitForRequest(status1);
sl@0
   683
	test(status1.Int() == KDmErrBadSequence);
sl@0
   684
	User::WaitForRequest(status);
sl@0
   685
	test(status.Int() == KErrTimedOut);
sl@0
   686
sl@0
   687
	// Since this test doesn't start the active scheduler, a domain member's RunL() will 
sl@0
   688
	// not get called so we need to re-request a domain transition notification manually
sl@0
   689
	User::WaitForRequest(testMember->iStatus);
sl@0
   690
	test(testMember->iStatus.Int() == KErrNone);
sl@0
   691
	testMember->iDomain.RequestTransitionNotification(testMember->iStatus);
sl@0
   692
sl@0
   693
	manager.RequestDomainTransition(KDmIdApps, EPwActive, status);
sl@0
   694
	test(status.Int() == KRequestPending);
sl@0
   695
	manager.CancelTransition();
sl@0
   696
	test(status.Int() == KErrCancel);
sl@0
   697
	manager.CancelTransition();
sl@0
   698
	User::WaitForRequest(status);
sl@0
   699
	test(status.Int() == KErrCancel);
sl@0
   700
sl@0
   701
	testMember->iDomain.CancelTransitionNotification();
sl@0
   702
sl@0
   703
	delete testMember;
sl@0
   704
	
sl@0
   705
	domain.Close();
sl@0
   706
	manager.Close();
sl@0
   707
	}
sl@0
   708
sl@0
   709
TInt CDmTest3::TransitionNotification(MDmDomainMember& /*aDomainMember*/)
sl@0
   710
	{
sl@0
   711
	test(0);
sl@0
   712
	return KErrAbort;	// don't acknowledge
sl@0
   713
	}
sl@0
   714
sl@0
   715
void CDmTest3::Release()
sl@0
   716
	{
sl@0
   717
	delete this;
sl@0
   718
	}
sl@0
   719
sl@0
   720
class CDmTest4 : public MDmTest
sl@0
   721
	{
sl@0
   722
public: 
sl@0
   723
	// from MDmTest
sl@0
   724
	void Perform();
sl@0
   725
	void Release();
sl@0
   726
	TInt TransitionNotification(MDmDomainMember& aDomainMember);
sl@0
   727
	void TransitionRequestComplete() {};
sl@0
   728
private:
sl@0
   729
	void ExecSlave(TUint arg);
sl@0
   730
	};
sl@0
   731
sl@0
   732
_LIT(KSecuritySlavePath, "t_domain_slave.exe");
sl@0
   733
sl@0
   734
void CDmTest4::ExecSlave(TUint aArg)
sl@0
   735
	{
sl@0
   736
	RProcess proc;
sl@0
   737
	TInt r = proc.Create(KSecuritySlavePath, TPtrC((TUint16*) &aArg, sizeof(aArg)/sizeof(TUint16)));
sl@0
   738
	test(r == KErrNone);
sl@0
   739
	TRequestStatus status;
sl@0
   740
	proc.Logon(status);
sl@0
   741
	proc.Resume();
sl@0
   742
	User::WaitForRequest(status);
sl@0
   743
sl@0
   744
    RDebug::Printf("CDmTest4::ExecSlave(%d) ExitType %d", aArg, proc.ExitType() );
sl@0
   745
    RDebug::Printf("CDmTest4::ExecSlave(%d) ExitReason %d", aArg, proc.ExitReason() );
sl@0
   746
	test(proc.ExitType() == EExitKill);
sl@0
   747
//	test(proc.ExitReason() == KErrPermissionDenied);
sl@0
   748
sl@0
   749
	CLOSE_AND_WAIT(proc);
sl@0
   750
	}
sl@0
   751
sl@0
   752
//! @SYMTestCaseID PBASE-T_DOMAIN-4
sl@0
   753
//! @SYMTestType CT
sl@0
   754
//! @SYMTestCaseDesc Dmain manager security tests
sl@0
   755
//! @SYMREQ 3722
sl@0
   756
//! @SYMTestActions Launches a separate process with no capabilities
sl@0
   757
//! @SYMTestExpectedResults  DM APIs should fail with KErrPermissionDenied
sl@0
   758
//! @SYMTestPriority High
sl@0
   759
//! @SYMTestStatus Defined
sl@0
   760
void CDmTest4::Perform()
sl@0
   761
	{
sl@0
   762
	//
sl@0
   763
	// Security tests
sl@0
   764
	//
sl@0
   765
sl@0
   766
	ExecSlave(0);
sl@0
   767
sl@0
   768
    ExecSlave(1);
sl@0
   769
sl@0
   770
	}
sl@0
   771
sl@0
   772
TInt CDmTest4::TransitionNotification(MDmDomainMember& /*aDomainMember*/)
sl@0
   773
	{
sl@0
   774
	test(0);
sl@0
   775
	return KErrNone;
sl@0
   776
	}
sl@0
   777
sl@0
   778
void CDmTest4::Release()
sl@0
   779
	{
sl@0
   780
	delete this;
sl@0
   781
	}
sl@0
   782
sl@0
   783
// Test hierarchy tests
sl@0
   784
class CDmTestStartupMember : public CDmTestMember
sl@0
   785
	{
sl@0
   786
public:
sl@0
   787
	CDmTestStartupMember(TDmHierarchyId aHierarchy, TDmDomainId aId, TUint32 aOrdinal, MDmTest*);
sl@0
   788
sl@0
   789
public:
sl@0
   790
private:
sl@0
   791
	};
sl@0
   792
sl@0
   793
CDmTestStartupMember::CDmTestStartupMember(TDmHierarchyId aHierarchy, TDmDomainId aId, TUint32 aOrdinal, MDmTest* aTest) 
sl@0
   794
	: CDmTestMember(aHierarchy, aId, aOrdinal, aTest)
sl@0
   795
	{
sl@0
   796
	}
sl@0
   797
sl@0
   798
// Simultaneously testing of test domain defined in DomainPolicy99.dll
sl@0
   799
// and the power domain defined in DomainPolicy.dll
sl@0
   800
class CDmTest5 : public CActive, public MDmTest
sl@0
   801
	{
sl@0
   802
public: 
sl@0
   803
	// from CActive
sl@0
   804
	void RunL();
sl@0
   805
	// from MDmTest
sl@0
   806
	void Perform();
sl@0
   807
	void Release();
sl@0
   808
	TInt TransitionNotification(MDmDomainMember& aDomainMember);
sl@0
   809
	void TransitionRequestComplete();
sl@0
   810
	CDmTest5(TDmDomainId aPowerId, TDmDomainId aTestId, TDmDomainState aPowerState, TDmDomainState aTestState) : 
sl@0
   811
		CActive(CActive::EPriorityStandard), 
sl@0
   812
		iPowerDomainId(aPowerId), iTestDomainId(aTestId), iPowerState(aPowerState), iTestState(aTestState) {}
sl@0
   813
protected:
sl@0
   814
	// from CActive
sl@0
   815
	virtual void DoCancel();
sl@0
   816
sl@0
   817
private:
sl@0
   818
	enum { KMembersMax = 16 };
sl@0
   819
	enum TAckMode{ KAckAlways, KAckNever, KAckError, KAckOddDomainsOnly };
sl@0
   820
sl@0
   821
	CDmTestMember*		iTestMembers[KMembersMax]; 
sl@0
   822
	CDomainMemberAo*	iPowerMembers[KMembersMax]; 
sl@0
   823
sl@0
   824
	RDmDomainManager	iTestDomainManager;
sl@0
   825
	
sl@0
   826
	TDmDomainId			iPowerDomainId;
sl@0
   827
	TDmDomainId			iTestDomainId;
sl@0
   828
sl@0
   829
	TDmDomainState		iPowerState;
sl@0
   830
	TDmDomainState		iTestState;
sl@0
   831
sl@0
   832
	// level number for iTestDomainId. E.g 1 for KDmIdRoot, 2 for KDmIdTestA, etc.
sl@0
   833
	TInt				iTestDomainLevel;	
sl@0
   834
sl@0
   835
	TDmTraverseDirection iTraverseDirection;
sl@0
   836
sl@0
   837
	TAckMode			iAckMode;
sl@0
   838
sl@0
   839
public:
sl@0
   840
	TInt				iTestNotifications;
sl@0
   841
	TInt				iPowerNotifications;
sl@0
   842
	TInt				iTestNotificationsExpected;
sl@0
   843
	TInt				iPowerNotificationsExpected;
sl@0
   844
sl@0
   845
	TInt				iTransitionsCompleted;
sl@0
   846
	TInt				iTransitionsExpected;
sl@0
   847
	};
sl@0
   848
sl@0
   849
sl@0
   850
sl@0
   851
//! @SYMTestCaseID PBASE-T_DOMAIN-5
sl@0
   852
//! @SYMTestType CT
sl@0
   853
//! @SYMTestCaseDesc Connects to two domain hierarchies simulteneously and perform various tests
sl@0
   854
//! @SYMREQ 3704,3705,3706,3707,3708,3709,3710,3711,3720,3721,3724,3725,3726,3727
sl@0
   855
//! @SYMTestActions Open two hiearchies simultaneously and perform various actions.
sl@0
   856
//! @SYMTestExpectedResults  All tests should pass
sl@0
   857
//! @SYMTestPriority High
sl@0
   858
//! @SYMTestStatus Defined
sl@0
   859
void CDmTest5::Perform()
sl@0
   860
	{
sl@0
   861
sl@0
   862
 	__UHEAP_MARK;
sl@0
   863
sl@0
   864
	//
sl@0
   865
	// Test domain transitions
sl@0
   866
	//
sl@0
   867
	CActiveScheduler::Add(this);
sl@0
   868
sl@0
   869
	TInt r = RDmDomainManager::AddDomainHierarchy(KDmHierarchyIdTest);
sl@0
   870
sl@0
   871
    RDebug::Printf("RDmDomainManager::AddDomainHierarchy returns %d", r );
sl@0
   872
sl@0
   873
	test(r == KErrNone);
sl@0
   874
sl@0
   875
	CDomainManagerAo* powerDomainManager = NULL;
sl@0
   876
	TRAP(r, powerDomainManager = CDomainManagerAo::NewL(KDmHierarchyIdPower, *this));
sl@0
   877
	test (powerDomainManager != NULL);
sl@0
   878
sl@0
   879
	r = CDomainManagerAo::AddDomainHierarchy(KDmHierarchyIdPower);
sl@0
   880
	test(r == KErrNone);
sl@0
   881
sl@0
   882
	//*************************************************
sl@0
   883
	//	Test 5a - connect to two domain hierarchies simultaneously
sl@0
   884
	//*************************************************
sl@0
   885
	test.Next(_L("Test 5a - connect to two domain hierarchies simultaneously"));
sl@0
   886
sl@0
   887
	test.Printf(_L("Domain id = 0x%x, Target State = 0x%x\n"), iTestDomainId, iTestState);
sl@0
   888
sl@0
   889
	TInt testMemberCount = 0;
sl@0
   890
sl@0
   891
	// Add some test hierarchy members - these use the RDmDomain API
sl@0
   892
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdRoot, ORDINAL_FROM_DOMAINID0(KDmIdRoot), this);
sl@0
   893
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   894
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdRoot, ORDINAL_FROM_DOMAINID0(KDmIdRoot), this);
sl@0
   895
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   896
	
sl@0
   897
	// row 1
sl@0
   898
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdTestA, ORDINAL_FROM_DOMAINID1(KDmIdRoot, KDmIdTestA), this);
sl@0
   899
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   900
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdTestB, ORDINAL_FROM_DOMAINID1(KDmIdRoot, KDmIdTestB), this);
sl@0
   901
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   902
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdTestC, ORDINAL_FROM_DOMAINID1(KDmIdRoot, KDmIdTestC), this);
sl@0
   903
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   904
	
sl@0
   905
	// row2
sl@0
   906
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdTestAA, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestA, KDmIdTestAA), this);
sl@0
   907
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   908
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdTestAB, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestA, KDmIdTestAB), this);
sl@0
   909
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   910
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdTestBA, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestB, KDmIdTestBA), this);
sl@0
   911
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   912
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdTestCA, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestC, KDmIdTestCA), this);
sl@0
   913
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   914
	
sl@0
   915
	// row 3
sl@0
   916
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdTestABA, ORDINAL_FROM_DOMAINID3(KDmIdRoot, KDmIdTestA, KDmIdTestAB, KDmIdTestABA), this);
sl@0
   917
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   918
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdTestABB, ORDINAL_FROM_DOMAINID3(KDmIdRoot, KDmIdTestA, KDmIdTestAB, KDmIdTestABB), this);
sl@0
   919
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   920
	iTestMembers[testMemberCount] = new CDmTestMember(KDmHierarchyIdTest, KDmIdTestCAA, ORDINAL_FROM_DOMAINID3(KDmIdRoot, KDmIdTestC, KDmIdTestCA, KDmIdTestCAA), this);
sl@0
   921
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
   922
sl@0
   923
	// add some power hierarchy members - these use the CDmDomain AO API
sl@0
   924
	TInt powerMemberCount = 0;
sl@0
   925
	TRAP(r, iPowerMembers[powerMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdPower, KDmIdRoot, KDmIdRoot, this));
sl@0
   926
	test(iTestMembers[powerMemberCount++] != NULL);
sl@0
   927
	TRAP(r, iPowerMembers[powerMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdPower, KDmIdApps, KDmIdApps, this));
sl@0
   928
	test(iTestMembers[powerMemberCount++] != NULL);
sl@0
   929
	TRAP(r, iPowerMembers[powerMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdPower, KDmIdUiApps, KDmIdUiApps, this));
sl@0
   930
	test(iTestMembers[powerMemberCount++] != NULL);
sl@0
   931
sl@0
   932
sl@0
   933
	RArray<const TTransitionFailure> testFailures;
sl@0
   934
	TInt testFailureCount;
sl@0
   935
	RArray<const TTransitionFailure> powerFailures;
sl@0
   936
	TInt powerFailureCount;
sl@0
   937
sl@0
   938
sl@0
   939
sl@0
   940
	// calculate the expected number of notifications
sl@0
   941
	TInt expectedTestNotifications = 0;
sl@0
   942
	TInt leafNodes = 0;
sl@0
   943
	
sl@0
   944
sl@0
   945
	// work out the domain level, the number of leaf nodes and the expected number of 
sl@0
   946
	// notifications for the domain that is being transitioned
sl@0
   947
	switch(iTestDomainId)
sl@0
   948
		{
sl@0
   949
		case KDmIdRoot		:	iTestDomainLevel = 1; leafNodes = 5; expectedTestNotifications = testMemberCount; break;
sl@0
   950
		case KDmIdTestA		:	iTestDomainLevel = 2; leafNodes = 3; expectedTestNotifications = 5; break;
sl@0
   951
		case KDmIdTestB		:	iTestDomainLevel = 2; leafNodes = 1; expectedTestNotifications = 2; break;
sl@0
   952
		case KDmIdTestC		:	iTestDomainLevel = 2; leafNodes = 1; expectedTestNotifications = 3; break;
sl@0
   953
sl@0
   954
		case KDmIdTestAA	:	iTestDomainLevel = 3; leafNodes = 1; expectedTestNotifications = 1; break;
sl@0
   955
		case KDmIdTestAB	:	iTestDomainLevel = 3; leafNodes = 2; expectedTestNotifications = 3; break;
sl@0
   956
		case KDmIdTestBA	:	iTestDomainLevel = 3; leafNodes = 1; expectedTestNotifications = 1; break;
sl@0
   957
		case KDmIdTestCA	:	iTestDomainLevel = 3; leafNodes = 1; expectedTestNotifications = 2; break;
sl@0
   958
sl@0
   959
		case KDmIdTestABA	:	iTestDomainLevel = 4; leafNodes = 1; expectedTestNotifications = 1; break;
sl@0
   960
		case KDmIdTestABB	:	iTestDomainLevel = 4; leafNodes = 1; expectedTestNotifications = 1; break;
sl@0
   961
		case KDmIdTestCAA	:	iTestDomainLevel = 4; leafNodes = 1; expectedTestNotifications = 1; break;
sl@0
   962
		default:
sl@0
   963
			test(0);
sl@0
   964
		}
sl@0
   965
	test.Printf(_L("Test Domain id = 0x%x, Level = %d, Target State = 0x%x, expected notifications = %d, leafNodes = %d\n"), 
sl@0
   966
		iTestDomainId, iTestDomainLevel, iTestState, expectedTestNotifications, leafNodes);
sl@0
   967
sl@0
   968
	TInt expectedPowerNotifications = 0;
sl@0
   969
	switch(iPowerDomainId)
sl@0
   970
		{
sl@0
   971
		case KDmIdRoot		:	expectedPowerNotifications = powerMemberCount; break;
sl@0
   972
		case KDmIdApps		:	expectedPowerNotifications = 1; break;
sl@0
   973
		case KDmIdUiApps	:	expectedPowerNotifications = 1; break;
sl@0
   974
		default:
sl@0
   975
			test(0);
sl@0
   976
		}
sl@0
   977
sl@0
   978
sl@0
   979
sl@0
   980
	// connect to the test hierarchy
sl@0
   981
	r = iTestDomainManager.Connect(KDmHierarchyIdTest);
sl@0
   982
	test(r == KErrNone);
sl@0
   983
sl@0
   984
	// verify that we can't connect to the same hierarchy more than once
sl@0
   985
	RDmDomainManager	domainManager;
sl@0
   986
	r = domainManager.Connect(KDmHierarchyIdTest);
sl@0
   987
	test(r == KErrInUse);
sl@0
   988
sl@0
   989
sl@0
   990
sl@0
   991
	//*************************************************
sl@0
   992
	// Test 5b - request a positive transition
sl@0
   993
	// issue a positive  transition (i.e. transition state increases)
sl@0
   994
	// and request that the test domain use ETraverseParentsFirst
sl@0
   995
	//*************************************************
sl@0
   996
	test.Next(_L("Test 5b - request a positive transition"));
sl@0
   997
	iAckMode = KAckAlways;
sl@0
   998
sl@0
   999
	iTransitionsCompleted = iTestNotifications = iPowerNotifications = 0;
sl@0
  1000
	iPowerNotificationsExpected = 0;
sl@0
  1001
	iTestNotificationsExpected = expectedTestNotifications;
sl@0
  1002
	iTransitionsExpected = 1;
sl@0
  1003
sl@0
  1004
	// DON'T request any domain transition on the power hierarchy
sl@0
  1005
	// powerDomainManager->RequestDomainTransition(iPowerDomainId, EPwActive);
sl@0
  1006
	// request a domain transition on the test hierarchy
sl@0
  1007
	iTraverseDirection = ETraverseParentsFirst;
sl@0
  1008
	if (iTestDomainId == KDmIdRoot)
sl@0
  1009
		iTestDomainManager.RequestSystemTransition(iTestState, ETraverseDefault, CActive::iStatus);
sl@0
  1010
	else
sl@0
  1011
		iTestDomainManager.RequestDomainTransition(iTestDomainId, iTestState, ETraverseDefault, CActive::iStatus);
sl@0
  1012
	CActive::SetActive();
sl@0
  1013
sl@0
  1014
	CActiveScheduler::Start();
sl@0
  1015
	test(powerDomainManager->iStatus == KErrNone);
sl@0
  1016
	test(iStatus == KErrNone);
sl@0
  1017
	test(iTestNotifications == iTestNotificationsExpected);
sl@0
  1018
	test(iPowerNotifications == iPowerNotificationsExpected);
sl@0
  1019
sl@0
  1020
	//*************************************************
sl@0
  1021
	// Test 5c- verify domains are in correct state
sl@0
  1022
	//*************************************************
sl@0
  1023
	test.Next(_L("Test 5c- verify domains are in correct state"));
sl@0
  1024
	RDmDomain domainMember;
sl@0
  1025
	r = domainMember.Connect(KDmHierarchyIdTest, iTestDomainId);
sl@0
  1026
	test (r == KErrNone);
sl@0
  1027
	TDmDomainState state = domainMember.GetState();
sl@0
  1028
	domainMember.Close();
sl@0
  1029
	test (state == iTestState);
sl@0
  1030
sl@0
  1031
	// if the transition request is not on the root, verify that that 
sl@0
  1032
	// the root domain and the transition domain are in different states
sl@0
  1033
	if (iTestDomainId != KDmIdRoot && iTestState != EStartupCriticalStatic)
sl@0
  1034
		{
sl@0
  1035
		r = domainMember.Connect(KDmHierarchyIdTest, KDmIdRoot);
sl@0
  1036
		test (r == KErrNone);
sl@0
  1037
		TDmDomainState state = domainMember.GetState();
sl@0
  1038
		domainMember.Close();
sl@0
  1039
		test (state != iTestState);
sl@0
  1040
		}
sl@0
  1041
sl@0
  1042
sl@0
  1043
	//*************************************************
sl@0
  1044
	// Test 5d- request a negative transition
sl@0
  1045
	// issue a negative transition (i.e. transition state decreases)
sl@0
  1046
	// and request that the test domain use ETraverseChildrenFirst
sl@0
  1047
	//*************************************************
sl@0
  1048
	test.Next(_L("Test 5d- request a negative transition"));
sl@0
  1049
	iAckMode = KAckAlways;
sl@0
  1050
	iTestState--;	// EStartupCriticalStatic;
sl@0
  1051
	iPowerState--;	// EPwStandby
sl@0
  1052
sl@0
  1053
	iTransitionsCompleted = iTestNotifications = iPowerNotifications = 0;
sl@0
  1054
	iPowerNotificationsExpected = expectedPowerNotifications;
sl@0
  1055
	iTestNotificationsExpected = expectedTestNotifications;
sl@0
  1056
	iTransitionsExpected = 2;
sl@0
  1057
sl@0
  1058
	// DO request a domain transition on the power hierarchy
sl@0
  1059
	powerDomainManager->RequestDomainTransition(iPowerDomainId, iPowerState, ETraverseDefault);
sl@0
  1060
sl@0
  1061
	// request a domain transition on the test hierarchy
sl@0
  1062
	iTraverseDirection = ETraverseChildrenFirst;
sl@0
  1063
	iTestDomainManager.RequestDomainTransition(iTestDomainId, iTestState, iTraverseDirection, CActive::iStatus);
sl@0
  1064
	CActive::SetActive();
sl@0
  1065
sl@0
  1066
	// wait for all test & power transitions to complete
sl@0
  1067
	CActiveScheduler::Start();
sl@0
  1068
	test(powerDomainManager->iStatus == KErrNone);
sl@0
  1069
	test(iStatus == KErrNone);
sl@0
  1070
	test(iTestNotifications == iTestNotificationsExpected);
sl@0
  1071
	test(iPowerNotifications == iPowerNotificationsExpected);
sl@0
  1072
	
sl@0
  1073
sl@0
  1074
	//*************************************************
sl@0
  1075
	// Test 5e- request a positive transition, with zero acknowledgements
sl@0
  1076
	// issue a positive transition with no members acknowledging the transition
sl@0
  1077
	//*************************************************
sl@0
  1078
	test.Next(_L("Test 5e- request a positive transition, with zero acknowledgements"));
sl@0
  1079
	iAckMode = KAckNever;
sl@0
  1080
	iTestState++;		// EStartupCriticalDynamic;
sl@0
  1081
	iPowerState++;		// EPwActive
sl@0
  1082
sl@0
  1083
	// power hierarchy should continue on failure, so we all power domains should transition
sl@0
  1084
	// test hierarchy should stop on failure, so should get notifications from all leaf nodes
sl@0
  1085
	iTransitionsCompleted = iTestNotifications = iPowerNotifications = 0;
sl@0
  1086
	iPowerNotificationsExpected = expectedPowerNotifications;
sl@0
  1087
	iTestNotificationsExpected = leafNodes;	// 5 leaf nodes for root domain
sl@0
  1088
	iTransitionsExpected = 2;
sl@0
  1089
sl@0
  1090
	// DO request a domain transition on the power hierarchy
sl@0
  1091
	powerDomainManager->RequestDomainTransition(iPowerDomainId, iPowerState, ETraverseDefault);
sl@0
  1092
sl@0
  1093
	// request a domain transition on the test hierarchy
sl@0
  1094
	iTraverseDirection = ETraverseChildrenFirst;
sl@0
  1095
	iTestDomainManager.RequestDomainTransition(iTestDomainId, iTestState, iTraverseDirection, CActive::iStatus);
sl@0
  1096
	CActive::SetActive();
sl@0
  1097
sl@0
  1098
	// wait for all test & power transitions to complete
sl@0
  1099
	CActiveScheduler::Start();
sl@0
  1100
	test(powerDomainManager->iStatus == KErrTimedOut);
sl@0
  1101
	test(iStatus == KErrTimedOut);
sl@0
  1102
	test(iTestNotifications == iTestNotificationsExpected);
sl@0
  1103
	test(iPowerNotifications == iPowerNotificationsExpected);
sl@0
  1104
	
sl@0
  1105
	// get the failures on the test hierarchy
sl@0
  1106
	testFailureCount = iTestDomainManager.GetTransitionFailureCount();
sl@0
  1107
	test (testFailureCount == 1);
sl@0
  1108
sl@0
  1109
	r = iTestDomainManager.GetTransitionFailures(testFailures);
sl@0
  1110
	test(r == KErrNone);
sl@0
  1111
	test(testFailureCount == testFailures.Count());
sl@0
  1112
sl@0
  1113
	test.Printf(_L("Test failures = %d\n"), testFailureCount);
sl@0
  1114
	TInt i;
sl@0
  1115
	for (i=0; i<testFailureCount; i++)
sl@0
  1116
		{
sl@0
  1117
		test.Printf(_L("%d: iDomainId %d, iError %d\n"), 
sl@0
  1118
			i, testFailures[i].iDomainId, testFailures[i].iError);
sl@0
  1119
		test(testFailures[i].iError == KErrTimedOut);
sl@0
  1120
		}
sl@0
  1121
sl@0
  1122
	// get the failures on the power hierarchy
sl@0
  1123
	powerFailureCount = powerDomainManager->GetTransitionFailureCount();
sl@0
  1124
	test (powerFailureCount == expectedPowerNotifications);
sl@0
  1125
sl@0
  1126
	r = powerDomainManager->GetTransitionFailures(powerFailures);
sl@0
  1127
	test(r == KErrNone);
sl@0
  1128
	test(powerFailureCount == powerFailures.Count());
sl@0
  1129
sl@0
  1130
	test.Printf(_L("Power failures = %d\n"), powerFailureCount);
sl@0
  1131
	for (i=0; i<powerFailureCount; i++)
sl@0
  1132
		{
sl@0
  1133
		test.Printf(_L("%d: iDomainId %d, iError %d\n"), 
sl@0
  1134
			i, powerFailures[i].iDomainId, powerFailures[i].iError);
sl@0
  1135
		test(powerFailures[i].iError == KErrTimedOut);
sl@0
  1136
		}
sl@0
  1137
sl@0
  1138
	
sl@0
  1139
	//*************************************************
sl@0
  1140
	// Test 5f- request a positive transition, with error acknowledgements
sl@0
  1141
	// issue a positive transition with all members nack'ing the transition
sl@0
  1142
	//*************************************************
sl@0
  1143
	test.Next(_L("Test 5f- request a positive transition, with error acknowledgements"));
sl@0
  1144
	iAckMode = KAckError;
sl@0
  1145
	iTestState++;		
sl@0
  1146
	iPowerState++;		
sl@0
  1147
sl@0
  1148
	// power hierarchy should continue on failure, so all power domains should transition
sl@0
  1149
	// test hierarchy should stop on failure, so should get notifications from 
sl@0
  1150
	// anything from 1 to all the leaf nodes
sl@0
  1151
	iTransitionsCompleted = iTestNotifications = iPowerNotifications = 0;
sl@0
  1152
	iPowerNotificationsExpected = expectedPowerNotifications;
sl@0
  1153
	iTestNotificationsExpected = leafNodes;	// 5 leaf nodes for root domain
sl@0
  1154
	iTransitionsExpected = 2;
sl@0
  1155
sl@0
  1156
	// DO request a domain transition on the power hierarchy
sl@0
  1157
	powerDomainManager->RequestDomainTransition(iPowerDomainId, iPowerState, ETraverseDefault);
sl@0
  1158
sl@0
  1159
	// request a domain transition on the test hierarchy
sl@0
  1160
	iTraverseDirection = ETraverseChildrenFirst;
sl@0
  1161
	iTestDomainManager.RequestDomainTransition(iTestDomainId, iTestState, iTraverseDirection, CActive::iStatus);
sl@0
  1162
	CActive::SetActive();
sl@0
  1163
sl@0
  1164
	// wait for all test & power transitions to complete
sl@0
  1165
	CActiveScheduler::Start();
sl@0
  1166
	test(powerDomainManager->iStatus == KErrGeneral);
sl@0
  1167
	test(iStatus == KErrGeneral);
sl@0
  1168
	test(iTestNotifications <= iTestNotificationsExpected);
sl@0
  1169
	test(iPowerNotifications == iPowerNotificationsExpected);
sl@0
  1170
	
sl@0
  1171
	// get the failures on the test hierarchy
sl@0
  1172
	testFailureCount = iTestDomainManager.GetTransitionFailureCount();
sl@0
  1173
	test (testFailureCount == 1);
sl@0
  1174
sl@0
  1175
	r = iTestDomainManager.GetTransitionFailures(testFailures);
sl@0
  1176
	test(r == KErrNone);
sl@0
  1177
	test(testFailureCount == testFailures.Count());
sl@0
  1178
sl@0
  1179
	test.Printf(_L("Test failures = %d\n"), testFailureCount);
sl@0
  1180
	for (i=0; i<testFailureCount; i++)
sl@0
  1181
		{
sl@0
  1182
		test.Printf(_L("%d: iDomainId %d, iError %d\n"), 
sl@0
  1183
			i, testFailures[i].iDomainId, testFailures[i].iError);
sl@0
  1184
		test(testFailures[i].iError == KErrGeneral);
sl@0
  1185
		}
sl@0
  1186
sl@0
  1187
	// get the failures on the power hierarchy
sl@0
  1188
	powerFailureCount = powerDomainManager->GetTransitionFailureCount();
sl@0
  1189
	test (powerFailureCount == expectedPowerNotifications);
sl@0
  1190
sl@0
  1191
	r = powerDomainManager->GetTransitionFailures(powerFailures);
sl@0
  1192
	test(r == KErrNone);
sl@0
  1193
	test(powerFailureCount == powerFailures.Count());
sl@0
  1194
sl@0
  1195
	test.Printf(_L("Power failures = %d\n"), powerFailureCount);
sl@0
  1196
	for (i=0; i<powerFailureCount; i++)
sl@0
  1197
		{
sl@0
  1198
		test.Printf(_L("%d: iDomainId %d, iError %d\n"), 
sl@0
  1199
			i, powerFailures[i].iDomainId, powerFailures[i].iError);
sl@0
  1200
		test(powerFailures[i].iError == KErrGeneral);
sl@0
  1201
		}
sl@0
  1202
sl@0
  1203
	
sl@0
  1204
	// cleanup
sl@0
  1205
sl@0
  1206
	testFailures.Reset();
sl@0
  1207
	powerFailures.Reset();
sl@0
  1208
sl@0
  1209
	iTestDomainManager.Close();
sl@0
  1210
	delete powerDomainManager;
sl@0
  1211
	powerDomainManager = NULL;
sl@0
  1212
sl@0
  1213
	CDmTestMember** mt;
sl@0
  1214
	for (mt = iTestMembers; *mt; ++mt)
sl@0
  1215
		delete *mt;
sl@0
  1216
sl@0
  1217
	CDomainMemberAo** mp;
sl@0
  1218
	for (mp = iPowerMembers; *mp; ++mp)
sl@0
  1219
		delete *mp;
sl@0
  1220
sl@0
  1221
sl@0
  1222
	// restore the domain hierarchies to their initial state so as not to 
sl@0
  1223
	// upset any subsequent tests which rely on this
sl@0
  1224
	{
sl@0
  1225
	RDmDomainManager manager;
sl@0
  1226
	TInt r = manager.Connect();
sl@0
  1227
	test (r == KErrNone);
sl@0
  1228
	TRequestStatus status;
sl@0
  1229
	manager.RequestDomainTransition(KDmIdRoot, EPwActive, status);
sl@0
  1230
	test(status.Int() == KRequestPending);
sl@0
  1231
	User::WaitForRequest(status);
sl@0
  1232
	test(status.Int() == KErrNone);
sl@0
  1233
	manager.Close();
sl@0
  1234
	
sl@0
  1235
	r = manager.Connect(KDmHierarchyIdTest);
sl@0
  1236
	test (r == KErrNone);
sl@0
  1237
	manager.RequestDomainTransition(KDmIdRoot, EStartupCriticalStatic, ETraverseDefault, status);
sl@0
  1238
	test(status.Int() == KRequestPending);
sl@0
  1239
	User::WaitForRequest(status);
sl@0
  1240
	test(status.Int() == KErrNone);
sl@0
  1241
	manager.Close();
sl@0
  1242
	}
sl@0
  1243
sl@0
  1244
 	__UHEAP_MARKEND;
sl@0
  1245
	}
sl@0
  1246
sl@0
  1247
// This handles a transition notification from either a power domain member or 
sl@0
  1248
// a test domain member.
sl@0
  1249
// Verifies that the domain state is as expected.
sl@0
  1250
// Updates the number of notifications for each hierarchy and verifies that all parent 
sl@0
  1251
// domains have transitioned already (for parent-to-child transitions) or that all child 
sl@0
  1252
// domains have been transitioned already (for child-to-parent transitions).
sl@0
  1253
sl@0
  1254
TInt CDmTest5::TransitionNotification(MDmDomainMember& aDomainMember)
sl@0
  1255
	{
sl@0
  1256
	if (aDomainMember.HierarchyId() == KDmHierarchyIdPower)
sl@0
  1257
		iPowerNotifications++;
sl@0
  1258
	else
sl@0
  1259
		iTestNotifications++;
sl@0
  1260
sl@0
  1261
	if (aDomainMember.HierarchyId() == KDmHierarchyIdPower)
sl@0
  1262
		{
sl@0
  1263
		__PRINT((_L("CDmTest5::TransitionNotification(), Hierarchy = %d, iOrdinal = 0x%08X, state = 0x%x, status = %d\n"), 
sl@0
  1264
			aDomainMember.HierarchyId(), aDomainMember.Ordinal(), aDomainMember.State(), aDomainMember.Status()));
sl@0
  1265
		test(aDomainMember.State() == iPowerState);
sl@0
  1266
		}
sl@0
  1267
	else if (aDomainMember.HierarchyId() == KDmHierarchyIdTest)
sl@0
  1268
		{
sl@0
  1269
		TBuf16<4> buf;
sl@0
  1270
		GetDomainDesc(aDomainMember.Ordinal(), buf);
sl@0
  1271
sl@0
  1272
		__PRINT((_L("CDmTest5::TransitionNotification(), Hierarchy = %d, domain = %S, iOrdinal = 0x%08X, state = 0x%x, status = %d\n"), 
sl@0
  1273
			aDomainMember.HierarchyId(), &buf, aDomainMember.Ordinal(), aDomainMember.State(), aDomainMember.Status()));
sl@0
  1274
		test(aDomainMember.State() == iTestState);
sl@0
  1275
		}
sl@0
  1276
	else
sl@0
  1277
		{
sl@0
  1278
		test(0);
sl@0
  1279
		}
sl@0
  1280
sl@0
  1281
	// if we're going from parent to child, 
sl@0
  1282
	// check that each parent domain has received a notification already
sl@0
  1283
	// if not, check that each child domain has received a notification already
sl@0
  1284
sl@0
  1285
	CDmTestMember** mp;
sl@0
  1286
sl@0
  1287
	if (aDomainMember.HierarchyId() == KDmHierarchyIdTest && iAckMode == KAckAlways)
sl@0
  1288
		{
sl@0
  1289
sl@0
  1290
		if (iTraverseDirection == ETraverseParentsFirst)
sl@0
  1291
			{
sl@0
  1292
			TUint ordThis = aDomainMember.Ordinal();
sl@0
  1293
			TUint ordParent = PARENT_ORDINAL(ordThis);
sl@0
  1294
sl@0
  1295
			TInt levelParent = ORDINAL_LEVEL(ordParent);
sl@0
  1296
sl@0
  1297
			TBuf16<4> buf;
sl@0
  1298
			GetDomainDesc(ordParent, buf);
sl@0
  1299
			if (levelParent >= iTestDomainLevel)
sl@0
  1300
				{
sl@0
  1301
				__PRINT((_L("Searching for parent domain = %S, ordinal = %08X \n"), &buf, ordParent));
sl@0
  1302
				for (mp = iTestMembers; *mp; ++mp)
sl@0
  1303
					{
sl@0
  1304
					if ((*mp)->Ordinal() == ordParent)
sl@0
  1305
						{
sl@0
  1306
						TBuf16<4> buf;
sl@0
  1307
						GetDomainDesc((*mp)->Ordinal(), buf);
sl@0
  1308
						__PRINT((_L("Found parent (%S). notification = %d\n"), &buf, (*mp)->Notifications()));
sl@0
  1309
						test ((*mp)->Notifications() == aDomainMember.Notifications());
sl@0
  1310
						break;
sl@0
  1311
						}
sl@0
  1312
					}
sl@0
  1313
				}
sl@0
  1314
			}
sl@0
  1315
		else
sl@0
  1316
			{
sl@0
  1317
			__PRINT((_L("Searching for children\n")));
sl@0
  1318
			for (mp = iTestMembers; *mp; ++mp)
sl@0
  1319
				{
sl@0
  1320
sl@0
  1321
				TUint ordParent = PARENT_ORDINAL((*mp)->Ordinal());
sl@0
  1322
				if (ordParent == aDomainMember.Ordinal())
sl@0
  1323
					{
sl@0
  1324
					TBuf16<4> buf;
sl@0
  1325
					GetDomainDesc((*mp)->Ordinal(), buf);
sl@0
  1326
					__PRINT((_L("Found child (%S). notification = %d\n"), &buf, (*mp)->Notifications()));
sl@0
  1327
					test ((*mp)->Notifications() == aDomainMember.Notifications());
sl@0
  1328
					}
sl@0
  1329
				}
sl@0
  1330
			}
sl@0
  1331
		}
sl@0
  1332
sl@0
  1333
	TInt ackError;
sl@0
  1334
	switch (iAckMode)
sl@0
  1335
		{
sl@0
  1336
		case KAckNever:
sl@0
  1337
			ackError = KErrAbort;
sl@0
  1338
			break;
sl@0
  1339
		case KAckError:		// return an error to the DM
sl@0
  1340
			ackError = KErrGeneral;
sl@0
  1341
			break;
sl@0
  1342
		case KAckOddDomainsOnly:
sl@0
  1343
			ackError = (aDomainMember.DomainId() & 1)?KErrNone:KErrAbort;
sl@0
  1344
			break;
sl@0
  1345
		case KAckAlways:
sl@0
  1346
		default:
sl@0
  1347
			ackError = KErrNone;
sl@0
  1348
			break;
sl@0
  1349
		}
sl@0
  1350
	return ackError;
sl@0
  1351
	}
sl@0
  1352
sl@0
  1353
void CDmTest5::RunL()
sl@0
  1354
	{
sl@0
  1355
	iTransitionsCompleted++;
sl@0
  1356
sl@0
  1357
	__PRINT((_L("CDmTest5::RunL(), error = %d, iTestNotifications %d, iPowerNotifications %d\n"), 
sl@0
  1358
		iStatus.Int(), iTestNotifications , iPowerNotifications));
sl@0
  1359
sl@0
  1360
	if (iTransitionsCompleted == iTransitionsExpected)
sl@0
  1361
		CActiveScheduler::Stop();
sl@0
  1362
	}
sl@0
  1363
sl@0
  1364
void CDmTest5::TransitionRequestComplete()
sl@0
  1365
	{
sl@0
  1366
	iTransitionsCompleted++;
sl@0
  1367
sl@0
  1368
	__PRINT((_L("CDmTest5::TransitionRequestComplete(), error = %d, iTestNotifications %d, iPowerNotifications %d\n"), 
sl@0
  1369
		iStatus.Int(), iTestNotifications , iPowerNotifications));
sl@0
  1370
	
sl@0
  1371
	if (iTransitionsCompleted == iTransitionsExpected)
sl@0
  1372
		CActiveScheduler::Stop();
sl@0
  1373
	}
sl@0
  1374
sl@0
  1375
void CDmTest5::DoCancel()
sl@0
  1376
	{
sl@0
  1377
	test(0);
sl@0
  1378
	}
sl@0
  1379
sl@0
  1380
void CDmTest5::Release()
sl@0
  1381
	{
sl@0
  1382
	delete this;
sl@0
  1383
	}
sl@0
  1384
sl@0
  1385
const TInt KMembersMax = 16;
sl@0
  1386
sl@0
  1387
// Negative testing 
sl@0
  1388
class CDmTest6 : public CActive, public MDmTest
sl@0
  1389
	{
sl@0
  1390
public:
sl@0
  1391
	enum 
sl@0
  1392
	{
sl@0
  1393
	ENegTestTransitionNoConnect,
sl@0
  1394
	ENegTestGetStateNoConnect,
sl@0
  1395
	ENegTestTransitionInvalidMode
sl@0
  1396
	};
sl@0
  1397
sl@0
  1398
	class TData 
sl@0
  1399
		{
sl@0
  1400
	public:
sl@0
  1401
		inline TData(TInt aTest) : iTest(aTest){};
sl@0
  1402
		TInt iTest;
sl@0
  1403
		};
sl@0
  1404
sl@0
  1405
public: 
sl@0
  1406
	// from CActive
sl@0
  1407
	void RunL();
sl@0
  1408
 
sl@0
  1409
	// from MDmTest
sl@0
  1410
	void Perform();
sl@0
  1411
	void Release();
sl@0
  1412
	TInt TransitionNotification(MDmDomainMember& aDomainMember);
sl@0
  1413
	void TransitionRequestComplete();
sl@0
  1414
sl@0
  1415
sl@0
  1416
	CDmTest6() : CActive(CActive::EPriorityStandard) {}
sl@0
  1417
sl@0
  1418
protected:
sl@0
  1419
	// from CActive
sl@0
  1420
	virtual void DoCancel();
sl@0
  1421
sl@0
  1422
private:
sl@0
  1423
	static TInt PanicThreadFunc(TAny* aData);
sl@0
  1424
	void PanicTest(TInt aTestNumber);
sl@0
  1425
sl@0
  1426
sl@0
  1427
	CDomainMemberAo*	iTestMembers[KMembersMax]; 
sl@0
  1428
	CDomainManagerAo*	iTestDomainManager;
sl@0
  1429
	
sl@0
  1430
	TDmDomainId			iTestDomainId;
sl@0
  1431
	TDmDomainState		iTestState;
sl@0
  1432
sl@0
  1433
public:
sl@0
  1434
	TInt				iTestNotifications;
sl@0
  1435
	TInt				iTestNotificationsExpected;
sl@0
  1436
sl@0
  1437
	TInt				iTransitionsCompleted;
sl@0
  1438
	TInt				iTransitionsExpected;
sl@0
  1439
	};
sl@0
  1440
sl@0
  1441
TInt CDmTest6::PanicThreadFunc(TAny* aData)
sl@0
  1442
	{
sl@0
  1443
	const TData* data = (const TData*)aData;
sl@0
  1444
	switch (data->iTest)
sl@0
  1445
		{
sl@0
  1446
		case ENegTestTransitionNoConnect:
sl@0
  1447
			{
sl@0
  1448
			// request a transition notification without connecting first (should panic)
sl@0
  1449
			RDmDomain domainMember;
sl@0
  1450
			TRequestStatus status;
sl@0
  1451
			User::SetJustInTime(EFalse);
sl@0
  1452
			domainMember.RequestTransitionNotification(status);
sl@0
  1453
			}
sl@0
  1454
			break;
sl@0
  1455
		case ENegTestGetStateNoConnect:
sl@0
  1456
			{
sl@0
  1457
			// Get the domain state without connecting (should panic)
sl@0
  1458
			RDmDomain domainMember;
sl@0
  1459
			User::SetJustInTime(EFalse);
sl@0
  1460
			domainMember.GetState();
sl@0
  1461
			}
sl@0
  1462
			break;
sl@0
  1463
		case ENegTestTransitionInvalidMode:
sl@0
  1464
			{
sl@0
  1465
			RDmDomainManager manager;
sl@0
  1466
			TRequestStatus status;
sl@0
  1467
			TInt r = manager.Connect(KDmHierarchyIdTest);
sl@0
  1468
			test(r == KErrNone);
sl@0
  1469
sl@0
  1470
			User::SetJustInTime(EFalse);
sl@0
  1471
			manager.RequestDomainTransition(KDmIdRoot, 0, TDmTraverseDirection(-1), status);
sl@0
  1472
			}
sl@0
  1473
			break;
sl@0
  1474
		default:
sl@0
  1475
			break;
sl@0
  1476
		}
sl@0
  1477
	return KErrNone;
sl@0
  1478
	}
sl@0
  1479
sl@0
  1480
void CDmTest6::PanicTest(TInt aTestNumber)
sl@0
  1481
	{
sl@0
  1482
	test.Printf(_L("panic test number %d\n"), aTestNumber);
sl@0
  1483
sl@0
  1484
	TBool jit = User::JustInTime();
sl@0
  1485
sl@0
  1486
	TData data(aTestNumber);
sl@0
  1487
sl@0
  1488
	TInt KHeapSize=0x2000;
sl@0
  1489
sl@0
  1490
	RThread thread;
sl@0
  1491
	TInt ret = thread.Create(KThreadName, PanicThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, &data);
sl@0
  1492
	test(KErrNone == ret);
sl@0
  1493
	TRequestStatus stat;
sl@0
  1494
	thread.Logon(stat);
sl@0
  1495
	thread.Resume();
sl@0
  1496
	User::WaitForRequest(stat);
sl@0
  1497
sl@0
  1498
	User::SetJustInTime(jit);
sl@0
  1499
sl@0
  1500
	// The thread must panic
sl@0
  1501
	test(thread.ExitType() == EExitPanic);
sl@0
  1502
	TInt exitReason = thread.ExitReason();
sl@0
  1503
	test.Printf(_L("panic test exit reason = %d\n"), exitReason);
sl@0
  1504
sl@0
  1505
	switch(aTestNumber)
sl@0
  1506
		{
sl@0
  1507
		case ENegTestTransitionNoConnect:
sl@0
  1508
			test (exitReason == EBadHandle);
sl@0
  1509
			break;
sl@0
  1510
		case ENegTestGetStateNoConnect:
sl@0
  1511
			test (exitReason == EBadHandle);
sl@0
  1512
			break;
sl@0
  1513
		case ENegTestTransitionInvalidMode:
sl@0
  1514
			break;
sl@0
  1515
		default:
sl@0
  1516
			break;
sl@0
  1517
		}
sl@0
  1518
sl@0
  1519
	CLOSE_AND_WAIT(thread);
sl@0
  1520
	}
sl@0
  1521
sl@0
  1522
sl@0
  1523
//! @SYMTestCaseID PBASE-T_DOMAIN-6
sl@0
  1524
//! @SYMTestType CT
sl@0
  1525
//! @SYMTestCaseDesc Negative testing
sl@0
  1526
//! @SYMPREQ 810
sl@0
  1527
//! @SYMTestActions Various negative tests
sl@0
  1528
//! @SYMTestExpectedResults  All tests should pass
sl@0
  1529
//! @SYMTestPriority High
sl@0
  1530
//! @SYMTestStatus Defined
sl@0
  1531
void CDmTest6::Perform()
sl@0
  1532
	{
sl@0
  1533
sl@0
  1534
 	__UHEAP_MARK;
sl@0
  1535
sl@0
  1536
	CActiveScheduler::Add(this);
sl@0
  1537
sl@0
  1538
	CDomainManagerAo* iTestDomainManager = NULL;
sl@0
  1539
	TRAP_IGNORE(iTestDomainManager = CDomainManagerAo::NewL(KDmHierarchyIdTest, *this));
sl@0
  1540
	test (iTestDomainManager != NULL);
sl@0
  1541
sl@0
  1542
	TInt r = CDomainManagerAo::AddDomainHierarchy(KDmHierarchyIdTest);
sl@0
  1543
	test(r == KErrNone);
sl@0
  1544
sl@0
  1545
	//*************************************************
sl@0
  1546
	// Test 6a - Connect to the same hierarchy twice
sl@0
  1547
	//*************************************************
sl@0
  1548
	test.Next(_L("Test 6a - Connect to the same hierarchy twice"));
sl@0
  1549
sl@0
  1550
	// verify that we can't connect to the same hierarchy more than once
sl@0
  1551
	CDomainManagerAo* testDomainManager = NULL;
sl@0
  1552
	TRAP(r, testDomainManager = CDomainManagerAo::NewL(KDmHierarchyIdTest, *this));
sl@0
  1553
	test(r == KErrInUse);
sl@0
  1554
	test (testDomainManager == NULL);
sl@0
  1555
sl@0
  1556
sl@0
  1557
	TInt testMemberCount = 0;
sl@0
  1558
sl@0
  1559
	// Add some test hierarchy members
sl@0
  1560
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdRoot, ORDINAL_FROM_DOMAINID0(KDmIdRoot), this));
sl@0
  1561
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1562
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdRoot, ORDINAL_FROM_DOMAINID0(KDmIdRoot), this));
sl@0
  1563
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1564
	
sl@0
  1565
	// row 1
sl@0
  1566
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestA, ORDINAL_FROM_DOMAINID1(KDmIdRoot, KDmIdTestA), this));
sl@0
  1567
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1568
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestB, ORDINAL_FROM_DOMAINID1(KDmIdRoot, KDmIdTestB), this));
sl@0
  1569
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1570
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestC, ORDINAL_FROM_DOMAINID1(KDmIdRoot, KDmIdTestC), this));
sl@0
  1571
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1572
	
sl@0
  1573
	// row2
sl@0
  1574
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestAA, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestA, KDmIdTestAA), this));
sl@0
  1575
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1576
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestAB, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestA, KDmIdTestAB), this));
sl@0
  1577
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1578
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestBA, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestB, KDmIdTestBA), this));
sl@0
  1579
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1580
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestCA, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestC, KDmIdTestCA), this));
sl@0
  1581
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1582
	
sl@0
  1583
	// row 3
sl@0
  1584
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestABA, ORDINAL_FROM_DOMAINID3(KDmIdRoot, KDmIdTestA, KDmIdTestAB, KDmIdTestABA), this));
sl@0
  1585
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1586
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestABB, ORDINAL_FROM_DOMAINID3(KDmIdRoot, KDmIdTestA, KDmIdTestAB, KDmIdTestABB), this));
sl@0
  1587
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1588
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestCAA, ORDINAL_FROM_DOMAINID3(KDmIdRoot, KDmIdTestC, KDmIdTestCA, KDmIdTestCAA), this));
sl@0
  1589
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1590
sl@0
  1591
sl@0
  1592
	//*************************************************
sl@0
  1593
	// Test 6b change to current state
sl@0
  1594
	//*************************************************
sl@0
  1595
	test.Next(_L("Test 6b change to current state"));
sl@0
  1596
	iTestState =  EStartupCriticalStatic;
sl@0
  1597
	iTestDomainId = KDmIdRoot;
sl@0
  1598
sl@0
  1599
	iTransitionsCompleted = iTestNotifications = 0;
sl@0
  1600
	iTestNotificationsExpected = testMemberCount;
sl@0
  1601
	iTransitionsExpected = 1;
sl@0
  1602
sl@0
  1603
	// request a domain transition
sl@0
  1604
	iTestDomainManager->RequestDomainTransition(iTestDomainId, iTestState, ETraverseDefault);
sl@0
  1605
sl@0
  1606
	// wait for test transitions to complete
sl@0
  1607
	CActiveScheduler::Start();
sl@0
  1608
	test(iStatus == KErrNone);
sl@0
  1609
	test(iTestNotifications == iTestNotificationsExpected);
sl@0
  1610
	
sl@0
  1611
sl@0
  1612
	// cancel a member notification request 
sl@0
  1613
	//*************************************************
sl@0
  1614
	// Test 6c cancel a member notification request
sl@0
  1615
	//*************************************************
sl@0
  1616
	test.Next(_L("Test 6c cancel a member notification request"));
sl@0
  1617
	RDmDomain domainMember;
sl@0
  1618
	TRequestStatus status;
sl@0
  1619
	domainMember.Connect(KDmHierarchyIdTest, iTestDomainId);
sl@0
  1620
	domainMember.RequestTransitionNotification(status);
sl@0
  1621
	domainMember.CancelTransitionNotification();
sl@0
  1622
	User::WaitForRequest(status);
sl@0
  1623
	domainMember.Close();
sl@0
  1624
sl@0
  1625
	//*************************************************
sl@0
  1626
	// Test 6d cancel a member notification request without having first requested a notification
sl@0
  1627
	//*************************************************
sl@0
  1628
	test.Next(_L("Test 6d cancel a member notification request without having first requested a notification"));
sl@0
  1629
	domainMember.Connect(KDmHierarchyIdTest, iTestDomainId);
sl@0
  1630
	domainMember.CancelTransitionNotification();
sl@0
  1631
	domainMember.Close();
sl@0
  1632
sl@0
  1633
	//*************************************************
sl@0
  1634
	// Test 6e domain controller adds invalid hierarchy
sl@0
  1635
	//*************************************************
sl@0
  1636
	test.Next(_L("Test 6e domain controller connects to invalid hierarchy"));
sl@0
  1637
	r = RDmDomainManager::AddDomainHierarchy(TDmHierarchyId(-1));
sl@0
  1638
	test(r == KErrBadHierarchyId);
sl@0
  1639
sl@0
  1640
	//*************************************************
sl@0
  1641
	// Test 6f domain member connects to invalid hierarchy
sl@0
  1642
	//*************************************************
sl@0
  1643
	test.Next(_L("Test 6f domain member connects to invalid hierarchy"));
sl@0
  1644
	r = domainMember.Connect(TDmHierarchyId(-1), TDmDomainId(KDmIdRoot));
sl@0
  1645
	test (r == KErrBadHierarchyId);
sl@0
  1646
sl@0
  1647
	//*************************************************
sl@0
  1648
	// Test 6g domain member connects to valid hierarchy but invalid domain
sl@0
  1649
	//*************************************************
sl@0
  1650
	test.Next(_L("Test 6g domain member connects to valid hierarchy but invalid domain"));
sl@0
  1651
	r = domainMember.Connect(KDmHierarchyIdTest, TDmDomainId(-1));
sl@0
  1652
	test (r == KDmErrBadDomainId);
sl@0
  1653
sl@0
  1654
	delete iTestDomainManager;
sl@0
  1655
	iTestDomainManager = NULL;
sl@0
  1656
sl@0
  1657
	// Panic tests
sl@0
  1658
sl@0
  1659
	//*************************************************
sl@0
  1660
	// Test 6h request a transition notification without connecting first
sl@0
  1661
	//*************************************************
sl@0
  1662
	test.Next(_L("Test 6h request a transition notification without connecting first"));
sl@0
  1663
	PanicTest(ENegTestTransitionNoConnect);
sl@0
  1664
sl@0
  1665
	//*************************************************
sl@0
  1666
	// Test 6i Get the domain state without connecting
sl@0
  1667
	//*************************************************
sl@0
  1668
	test.Next(_L("Test 6i Get the domain state without connecting"));
sl@0
  1669
	PanicTest(ENegTestGetStateNoConnect);
sl@0
  1670
sl@0
  1671
	//*************************************************
sl@0
  1672
	// Test 6j request a transition notification with an invalid transition mode
sl@0
  1673
	//*************************************************
sl@0
  1674
	test.Next(_L("Test 6j request a transition notification with an invalid transition mode"));
sl@0
  1675
	PanicTest(ENegTestTransitionInvalidMode);
sl@0
  1676
sl@0
  1677
sl@0
  1678
	// cleanup
sl@0
  1679
sl@0
  1680
	CDomainMemberAo** mt;
sl@0
  1681
	for (mt = iTestMembers; *mt; ++mt)
sl@0
  1682
		delete *mt;
sl@0
  1683
sl@0
  1684
 	__UHEAP_MARKEND;
sl@0
  1685
	}
sl@0
  1686
sl@0
  1687
// This handles a transition notification from a test domain member.
sl@0
  1688
TInt CDmTest6::TransitionNotification(MDmDomainMember& aDomainMember)
sl@0
  1689
	{
sl@0
  1690
	TInt status = aDomainMember.Status();
sl@0
  1691
		
sl@0
  1692
	iTestNotifications++;
sl@0
  1693
sl@0
  1694
	test (aDomainMember.HierarchyId() == KDmHierarchyIdTest);
sl@0
  1695
sl@0
  1696
	TBuf16<4> buf;
sl@0
  1697
	GetDomainDesc(aDomainMember.Ordinal(), buf);
sl@0
  1698
sl@0
  1699
	test.Printf(_L("CDmTest6::TransitionNotification(), Hierarchy = %d, domain = %S, iOrdinal = 0x%08X, state = 0x%x, status = %d\n"), 
sl@0
  1700
		aDomainMember.HierarchyId(), &buf, aDomainMember.Ordinal(), aDomainMember.State(), status);
sl@0
  1701
sl@0
  1702
sl@0
  1703
	return KErrNone;
sl@0
  1704
	}
sl@0
  1705
sl@0
  1706
void CDmTest6::RunL()
sl@0
  1707
	{
sl@0
  1708
	iTransitionsCompleted++;
sl@0
  1709
sl@0
  1710
	TInt error = iStatus.Int();
sl@0
  1711
sl@0
  1712
	test.Printf(_L("CDmTest6::RunL(), error = %d, iTestNotifications %d\n"), 
sl@0
  1713
		error, iTestNotifications);
sl@0
  1714
sl@0
  1715
	if (iTransitionsCompleted == iTransitionsExpected)
sl@0
  1716
		CActiveScheduler::Stop();
sl@0
  1717
	}
sl@0
  1718
sl@0
  1719
void CDmTest6::TransitionRequestComplete()
sl@0
  1720
	{
sl@0
  1721
	iTransitionsCompleted++;
sl@0
  1722
sl@0
  1723
	TInt error = iStatus.Int();
sl@0
  1724
	
sl@0
  1725
	test.Printf(_L("CDmTest6::TransitionRequestComplete(), error = %d, iTestNotifications %d\n"), 
sl@0
  1726
		error, iTestNotifications);
sl@0
  1727
	
sl@0
  1728
	if (iTransitionsCompleted == iTransitionsExpected)
sl@0
  1729
		CActiveScheduler::Stop();
sl@0
  1730
	}
sl@0
  1731
sl@0
  1732
void CDmTest6::DoCancel()
sl@0
  1733
	{
sl@0
  1734
	test(0);
sl@0
  1735
	}
sl@0
  1736
sl@0
  1737
void CDmTest6::Release()
sl@0
  1738
	{
sl@0
  1739
	delete this;
sl@0
  1740
	}
sl@0
  1741
sl@0
  1742
// Transition progress Observer testing
sl@0
  1743
class CDmTest7 : public CActive, public MDmTest, public MHierarchyObserver
sl@0
  1744
	{
sl@0
  1745
public: 
sl@0
  1746
	// from CActive
sl@0
  1747
	void RunL();
sl@0
  1748
 
sl@0
  1749
	// from MDmTest
sl@0
  1750
	void Perform();
sl@0
  1751
	void Release();
sl@0
  1752
	TInt TransitionNotification(MDmDomainMember& aDomainMember);
sl@0
  1753
	void TransitionRequestComplete();
sl@0
  1754
sl@0
  1755
	// from MHierarchyObserver
sl@0
  1756
	virtual void TransProgEvent(TDmDomainId aDomainId, TDmDomainState aState);
sl@0
  1757
	virtual void TransFailEvent(TDmDomainId aDomainId, TDmDomainState aState, TInt aError);
sl@0
  1758
	virtual void TransReqEvent(TDmDomainId aDomainId, TDmDomainState aState);
sl@0
  1759
sl@0
  1760
sl@0
  1761
sl@0
  1762
	CDmTest7(TDmDomainId aDomainId) : CActive(CActive::EPriorityStandard), iObservedDomainId(aDomainId) {}
sl@0
  1763
sl@0
  1764
protected:
sl@0
  1765
	// from CActive
sl@0
  1766
	virtual void DoCancel();
sl@0
  1767
sl@0
  1768
private:
sl@0
  1769
	void TestForCompletion();
sl@0
  1770
sl@0
  1771
sl@0
  1772
private:
sl@0
  1773
sl@0
  1774
	enum { KMembersMax = 16 };
sl@0
  1775
sl@0
  1776
	CDomainMemberAo*	iTestMembers[KMembersMax]; 
sl@0
  1777
	CDomainManagerAo*	iTestDomainManager;
sl@0
  1778
	
sl@0
  1779
	TDmDomainId			iTestDomainId;
sl@0
  1780
	TDmDomainState		iTestState;
sl@0
  1781
	TDmDomainId			iObservedDomainId;
sl@0
  1782
sl@0
  1783
public:
sl@0
  1784
	TInt				iTestNotifications;
sl@0
  1785
	TInt				iTestNotificationsExpected;
sl@0
  1786
sl@0
  1787
	TInt				iTransitionsCompleted;
sl@0
  1788
	TInt				iTransitionsExpected;
sl@0
  1789
sl@0
  1790
	TInt				iTransProgEvents;
sl@0
  1791
	TInt				iTransFailEvents;
sl@0
  1792
	TInt				iTransReqEvents;
sl@0
  1793
sl@0
  1794
	TInt				iTransProgEventsExpected;
sl@0
  1795
	TInt				iTransFailEventsExpected;
sl@0
  1796
	TInt				iTransReqEventsExpected;
sl@0
  1797
	};
sl@0
  1798
sl@0
  1799
//! @SYMTestCaseID PBASE-T_DOMAIN-7
sl@0
  1800
//! @SYMTestType CT
sl@0
  1801
//! @SYMTestCaseDesc Transition progress Observer testing
sl@0
  1802
//! @SYMREQ REQ3723
sl@0
  1803
//! @SYMTestActions Various negative tests
sl@0
  1804
//! @SYMTestExpectedResults  All tests should pass
sl@0
  1805
//! @SYMTestPriority High
sl@0
  1806
//! @SYMTestStatus Defined
sl@0
  1807
void CDmTest7::Perform()
sl@0
  1808
	{
sl@0
  1809
sl@0
  1810
 	__UHEAP_MARK;
sl@0
  1811
sl@0
  1812
	//
sl@0
  1813
	// Test domain transitions with activated observer
sl@0
  1814
	//
sl@0
  1815
	CActiveScheduler::Add(this);
sl@0
  1816
sl@0
  1817
	TInt r = RDmDomainManager::AddDomainHierarchy(KDmHierarchyIdTest);
sl@0
  1818
	test(r == KErrNone);
sl@0
  1819
sl@0
  1820
	CDomainManagerAo* iTestDomainManager = NULL;
sl@0
  1821
	TRAP_IGNORE(iTestDomainManager = CDomainManagerAo::NewL(KDmHierarchyIdTest, *this));
sl@0
  1822
	test (iTestDomainManager != NULL);
sl@0
  1823
sl@0
  1824
	r = CDomainManagerAo::AddDomainHierarchy(KDmHierarchyIdTest);
sl@0
  1825
	test(r == KErrNone);
sl@0
  1826
sl@0
  1827
	//*************************************************
sl@0
  1828
	// Test 7a - Testing observer notifications
sl@0
  1829
	//*************************************************
sl@0
  1830
	
sl@0
  1831
	test.Next(_L("Test 7a - Testing observer notifications"));
sl@0
  1832
sl@0
  1833
	TInt testMemberCount = 0;
sl@0
  1834
sl@0
  1835
	// Add some test hierarchy members
sl@0
  1836
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdRoot, ORDINAL_FROM_DOMAINID0(KDmIdRoot), this));
sl@0
  1837
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1838
	
sl@0
  1839
	// row 1
sl@0
  1840
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestA, ORDINAL_FROM_DOMAINID1(KDmIdRoot, KDmIdTestA), this));
sl@0
  1841
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1842
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestB, ORDINAL_FROM_DOMAINID1(KDmIdRoot, KDmIdTestB), this));
sl@0
  1843
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1844
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestC, ORDINAL_FROM_DOMAINID1(KDmIdRoot, KDmIdTestC), this));
sl@0
  1845
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1846
	
sl@0
  1847
	// row2
sl@0
  1848
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestAA, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestA, KDmIdTestAA), this));
sl@0
  1849
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1850
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestAB, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestA, KDmIdTestAB), this));
sl@0
  1851
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1852
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestBA, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestB, KDmIdTestBA), this));
sl@0
  1853
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1854
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestCA, ORDINAL_FROM_DOMAINID2(KDmIdRoot, KDmIdTestC, KDmIdTestCA), this));
sl@0
  1855
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1856
	
sl@0
  1857
	// row 3
sl@0
  1858
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestABA, ORDINAL_FROM_DOMAINID3(KDmIdRoot, KDmIdTestA, KDmIdTestAB, KDmIdTestABA), this));
sl@0
  1859
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1860
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestABB, ORDINAL_FROM_DOMAINID3(KDmIdRoot, KDmIdTestA, KDmIdTestAB, KDmIdTestABB), this));
sl@0
  1861
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1862
	TRAP(r, iTestMembers[testMemberCount] = CDomainMemberAo::NewL(KDmHierarchyIdTest, KDmIdTestCAA, ORDINAL_FROM_DOMAINID3(KDmIdRoot, KDmIdTestC, KDmIdTestCA, KDmIdTestCAA), this));
sl@0
  1863
	test(iTestMembers[testMemberCount++] != NULL);
sl@0
  1864
sl@0
  1865
	// create an observer
sl@0
  1866
	CHierarchyObserver* observer = NULL;
sl@0
  1867
	TRAP(r, observer = CHierarchyObserver::NewL(*this, KDmHierarchyIdTest));
sl@0
  1868
	test (r == KErrNone);
sl@0
  1869
	test(observer != NULL);
sl@0
  1870
	observer->StartObserver(iObservedDomainId, EDmNotifyAll);
sl@0
  1871
	
sl@0
  1872
	// request a state change
sl@0
  1873
	iTestState =  EStartupCriticalDynamic;
sl@0
  1874
	iTestDomainId = KDmIdRoot;
sl@0
  1875
	iTransitionsCompleted = iTestNotifications = 0;
sl@0
  1876
	iTestNotificationsExpected = testMemberCount;
sl@0
  1877
	iTransitionsExpected = 1;
sl@0
  1878
sl@0
  1879
	iTransProgEvents = iTransFailEvents = iTransReqEvents = 0;
sl@0
  1880
	
sl@0
  1881
	iTransReqEventsExpected = iTransProgEventsExpected = observer->ObserverDomainCount();
sl@0
  1882
	iTransFailEventsExpected = 0;
sl@0
  1883
sl@0
  1884
sl@0
  1885
	iTestDomainManager->RequestDomainTransition(iTestDomainId, iTestState, ETraverseDefault);
sl@0
  1886
sl@0
  1887
	// wait for test transitions to complete
sl@0
  1888
	CActiveScheduler::Start();
sl@0
  1889
	test(iStatus == KErrNone);
sl@0
  1890
	test(iTestNotifications == iTestNotificationsExpected);
sl@0
  1891
	test (iTransProgEvents == iTransProgEventsExpected);
sl@0
  1892
	test (iTransFailEvents == iTransFailEventsExpected);
sl@0
  1893
	test (iTransReqEvents == iTransReqEventsExpected);
sl@0
  1894
sl@0
  1895
sl@0
  1896
	// cleanup
sl@0
  1897
	delete observer; 
sl@0
  1898
	observer = NULL;
sl@0
  1899
sl@0
  1900
	//*************************************************
sl@0
  1901
	// Test 7b - start & stop the observer
sl@0
  1902
	//*************************************************
sl@0
  1903
	test.Next(_L("Test 7b - start & stop the observer"));
sl@0
  1904
sl@0
  1905
	// create an observer, start it stop and then start it again
sl@0
  1906
	TRAP(r, observer = CHierarchyObserver::NewL(*this, KDmHierarchyIdTest));
sl@0
  1907
	test (r == KErrNone);
sl@0
  1908
	test(observer != NULL);
sl@0
  1909
	observer->StartObserver(iObservedDomainId, EDmNotifyAll);
sl@0
  1910
	observer->StopObserver();
sl@0
  1911
	observer->StartObserver(iObservedDomainId, EDmNotifyAll);
sl@0
  1912
sl@0
  1913
	// request a state change
sl@0
  1914
	iTestState++;
sl@0
  1915
	iTestDomainId = KDmIdRoot;
sl@0
  1916
	iTransitionsCompleted = iTestNotifications = 0;
sl@0
  1917
	iTestNotificationsExpected = testMemberCount;
sl@0
  1918
	iTransitionsExpected = 1;
sl@0
  1919
sl@0
  1920
	iTransProgEvents = iTransFailEvents = iTransReqEvents = 0;
sl@0
  1921
	
sl@0
  1922
	iTransProgEventsExpected = iTransReqEventsExpected = observer->ObserverDomainCount();
sl@0
  1923
	iTransFailEventsExpected = 0;
sl@0
  1924
sl@0
  1925
	iTestDomainManager->RequestDomainTransition(iTestDomainId, iTestState, ETraverseDefault);
sl@0
  1926
sl@0
  1927
	// wait for test transitions to complete
sl@0
  1928
	CActiveScheduler::Start();
sl@0
  1929
	test(iStatus == KErrNone);
sl@0
  1930
	test(iTestNotifications == iTestNotificationsExpected);
sl@0
  1931
	test (iTransProgEvents == iTransProgEventsExpected);
sl@0
  1932
	test (iTransFailEvents == iTransFailEventsExpected);
sl@0
  1933
	test (iTransReqEvents == iTransReqEventsExpected);
sl@0
  1934
sl@0
  1935
	// stop the observer & request another state change
sl@0
  1936
	observer->StopObserver();
sl@0
  1937
	iTestState++;
sl@0
  1938
	iTestDomainId = KDmIdRoot;
sl@0
  1939
	iTransitionsCompleted = iTestNotifications = 0;
sl@0
  1940
	iTestNotificationsExpected = testMemberCount;
sl@0
  1941
	iTransitionsExpected = 1;
sl@0
  1942
sl@0
  1943
	iTransProgEvents = iTransFailEvents = iTransReqEvents = 0;
sl@0
  1944
	
sl@0
  1945
	iTransProgEventsExpected = 0;
sl@0
  1946
	iTransFailEventsExpected = 0;
sl@0
  1947
	iTransReqEventsExpected = 0;
sl@0
  1948
sl@0
  1949
	iTestDomainManager->RequestDomainTransition(iTestDomainId, iTestState, ETraverseDefault);
sl@0
  1950
	// wait for test transitions to complete
sl@0
  1951
	CActiveScheduler::Start();
sl@0
  1952
	test(iStatus == KErrNone);
sl@0
  1953
	test(iTestNotifications == iTestNotificationsExpected);
sl@0
  1954
	test (iTransProgEvents == iTransProgEventsExpected);
sl@0
  1955
	test (iTransFailEvents == iTransFailEventsExpected);
sl@0
  1956
	test (iTransReqEvents == iTransReqEventsExpected);
sl@0
  1957
sl@0
  1958
	// Start the observer again on a different domain and only ask for transition requests
sl@0
  1959
	// Then request another state change
sl@0
  1960
	observer->StartObserver((iObservedDomainId == KDmIdRoot)?KDmIdTestCA:KDmIdRoot, EDmNotifyTransRequest);
sl@0
  1961
	iTestState++;
sl@0
  1962
	iTestDomainId = KDmIdRoot;
sl@0
  1963
	iTransitionsCompleted = iTestNotifications = 0;
sl@0
  1964
	iTestNotificationsExpected = testMemberCount;
sl@0
  1965
	iTransitionsExpected = 1;
sl@0
  1966
sl@0
  1967
	iTransProgEvents = iTransFailEvents = iTransReqEvents = 0;
sl@0
  1968
	
sl@0
  1969
	iTransReqEventsExpected = observer->ObserverDomainCount();
sl@0
  1970
	iTransProgEventsExpected = 0;
sl@0
  1971
	iTransFailEventsExpected = 0;
sl@0
  1972
sl@0
  1973
sl@0
  1974
	iTestDomainManager->RequestDomainTransition(iTestDomainId, iTestState, ETraverseDefault);
sl@0
  1975
	// wait for test transitions to complete
sl@0
  1976
	CActiveScheduler::Start();
sl@0
  1977
	test(iStatus == KErrNone);
sl@0
  1978
	test(iTestNotifications == iTestNotificationsExpected);
sl@0
  1979
	test (iTransProgEvents == iTransProgEventsExpected);
sl@0
  1980
	test (iTransFailEvents == iTransFailEventsExpected);
sl@0
  1981
	test (iTransReqEvents == iTransReqEventsExpected);
sl@0
  1982
sl@0
  1983
	delete observer; 
sl@0
  1984
	observer = NULL;
sl@0
  1985
sl@0
  1986
	//*************************************************
sl@0
  1987
	// Test 7c - invalid arguments testing for observer
sl@0
  1988
	//*************************************************
sl@0
  1989
	test.Next(_L("Test 7c - Invalid arguments testing for observer"));
sl@0
  1990
	
sl@0
  1991
	const TDmHierarchyId	KDmHierarchyIdInvalid = 110;
sl@0
  1992
	
sl@0
  1993
	test.Printf(_L("Test 7c.1 - create observer with invalid hierarchy Id\n"));
sl@0
  1994
	
sl@0
  1995
	// create an observer
sl@0
  1996
	TRAP(r, observer = CHierarchyObserver::NewL(*this, KDmHierarchyIdInvalid));
sl@0
  1997
	test (r == KErrBadHierarchyId);
sl@0
  1998
	
sl@0
  1999
	
sl@0
  2000
	test.Printf(_L("Test 7c.2 - Starting the observer with wrong domain Id\n"));
sl@0
  2001
	TRAP(r, observer = CHierarchyObserver::NewL(*this, KDmHierarchyIdTest));
sl@0
  2002
	test (r == KErrNone);
sl@0
  2003
	test(observer != NULL);
sl@0
  2004
sl@0
  2005
	//Wrong domain Id
sl@0
  2006
	const TDmDomainId	KDmIdInvalid	= 0x0f;
sl@0
  2007
	r= observer->StartObserver(KDmIdInvalid, EDmNotifyAll);
sl@0
  2008
	test(r==KDmErrBadDomainId);
sl@0
  2009
sl@0
  2010
	test.Printf(_L("Test 7c.3 - Trying to create second observer on the same hierarchy\n"));
sl@0
  2011
	TRAP(r, CHierarchyObserver::NewL(*this, KDmHierarchyIdTest));
sl@0
  2012
	test (r == KDmErrBadSequence);
sl@0
  2013
sl@0
  2014
	
sl@0
  2015
	
sl@0
  2016
	//*************************************************
sl@0
  2017
	// Test 7d - Wrong sequence of API calls for observer
sl@0
  2018
	//*************************************************
sl@0
  2019
	test.Next(_L("Test 7d - Observer wrong sequence of calls"));
sl@0
  2020
	
sl@0
  2021
	test.Printf(_L("Test 7d.1 - Stopping Observer before starting it\n"));
sl@0
  2022
	r = observer->StopObserver();
sl@0
  2023
	test(r==KDmErrBadSequence);
sl@0
  2024
	
sl@0
  2025
	test.Printf(_L("Test 7d.2 - Starting Observer twice\n"));
sl@0
  2026
	r= observer->StartObserver(KDmIdRoot, EDmNotifyAll);
sl@0
  2027
	test(r==KErrNone);
sl@0
  2028
sl@0
  2029
	r= observer->StartObserver(KDmIdRoot, EDmNotifyAll);
sl@0
  2030
	test(r==KDmErrBadSequence);
sl@0
  2031
sl@0
  2032
	
sl@0
  2033
	delete observer;
sl@0
  2034
sl@0
  2035
	/***************************************/
sl@0
  2036
sl@0
  2037
	delete iTestDomainManager;
sl@0
  2038
	iTestDomainManager = NULL;
sl@0
  2039
sl@0
  2040
	CDomainMemberAo** mt;
sl@0
  2041
	for (mt = iTestMembers; *mt; ++mt)
sl@0
  2042
		delete *mt;
sl@0
  2043
sl@0
  2044
sl@0
  2045
	// restore the domain hierarchies to their initial state so as not to 
sl@0
  2046
	// upset any subsequent tests which rely on this
sl@0
  2047
	{
sl@0
  2048
	RDmDomainManager manager;
sl@0
  2049
	TRequestStatus status;
sl@0
  2050
	TInt r = manager.Connect(KDmHierarchyIdTest);
sl@0
  2051
	test (r == KErrNone);
sl@0
  2052
	manager.RequestDomainTransition(KDmIdRoot, EStartupCriticalStatic, ETraverseDefault, status);
sl@0
  2053
	test(status.Int() == KRequestPending);
sl@0
  2054
	User::WaitForRequest(status);
sl@0
  2055
	test(status.Int() == KErrNone);
sl@0
  2056
	manager.Close();
sl@0
  2057
	}
sl@0
  2058
sl@0
  2059
 	__UHEAP_MARKEND;
sl@0
  2060
	}
sl@0
  2061
sl@0
  2062
// This handles a transition notification from a test domain member.
sl@0
  2063
TInt CDmTest7::TransitionNotification(MDmDomainMember& aDomainMember)
sl@0
  2064
	{
sl@0
  2065
		
sl@0
  2066
	iTestNotifications++;
sl@0
  2067
sl@0
  2068
	test (aDomainMember.HierarchyId() == KDmHierarchyIdTest);
sl@0
  2069
sl@0
  2070
	TBuf16<4> buf;
sl@0
  2071
	GetDomainDesc(aDomainMember.Ordinal(), buf);
sl@0
  2072
sl@0
  2073
	__PRINT((_L("CDmTest7::TransitionNotification(), Hierarchy = %d, domain = %S, iOrdinal = 0x%08X, state = 0x%x, status = %d\n"), 
sl@0
  2074
		aDomainMember.HierarchyId(), &buf, aDomainMember.Ordinal(), aDomainMember.State(), aDomainMember.Status()));
sl@0
  2075
sl@0
  2076
	return KErrNone;
sl@0
  2077
	}
sl@0
  2078
sl@0
  2079
void CDmTest7::RunL()
sl@0
  2080
	{
sl@0
  2081
	iTransitionsCompleted++;
sl@0
  2082
sl@0
  2083
	__PRINT((_L("CDmTest7::RunL(), error = %d, iTestNotifications %d\n"), 
sl@0
  2084
		iStatus.Int(), iTestNotifications));
sl@0
  2085
sl@0
  2086
	TestForCompletion();
sl@0
  2087
	}
sl@0
  2088
sl@0
  2089
void CDmTest7::TransitionRequestComplete()
sl@0
  2090
	{
sl@0
  2091
	iTransitionsCompleted++;
sl@0
  2092
sl@0
  2093
	__PRINT((_L("CDmTest7::TransitionRequestComplete(), error = %d, iTestNotifications %d\n"), 
sl@0
  2094
		iStatus.Int(), iTestNotifications));
sl@0
  2095
	
sl@0
  2096
	TestForCompletion();
sl@0
  2097
	}
sl@0
  2098
sl@0
  2099
void CDmTest7::DoCancel()
sl@0
  2100
	{
sl@0
  2101
	test(0);
sl@0
  2102
	}
sl@0
  2103
sl@0
  2104
void CDmTest7::Release()
sl@0
  2105
	{
sl@0
  2106
	delete this;
sl@0
  2107
	}
sl@0
  2108
sl@0
  2109
void CDmTest7::TestForCompletion()
sl@0
  2110
	{
sl@0
  2111
sl@0
  2112
	if (iTransitionsCompleted == iTransitionsExpected &&
sl@0
  2113
		iTransProgEvents == iTransProgEventsExpected && 
sl@0
  2114
		iTransFailEvents == iTransFailEventsExpected &&
sl@0
  2115
		iTransReqEvents == iTransReqEventsExpected)
sl@0
  2116
		{
sl@0
  2117
		CActiveScheduler::Stop();
sl@0
  2118
		}
sl@0
  2119
	}
sl@0
  2120
sl@0
  2121
#ifdef _DEBUG
sl@0
  2122
void CDmTest7::TransProgEvent(TDmDomainId aDomainId, TDmDomainState aState)
sl@0
  2123
#else
sl@0
  2124
void CDmTest7::TransProgEvent(TDmDomainId /*aDomainId*/, TDmDomainState /*aState*/)
sl@0
  2125
#endif
sl@0
  2126
	{
sl@0
  2127
	iTransProgEvents++;
sl@0
  2128
	__PRINT((_L("CDmTest7::TransProgEvent(), aDomainId = %d, aState %d, iTransProgEvents %d\n"), 
sl@0
  2129
		aDomainId, aState, iTransProgEvents));
sl@0
  2130
	TestForCompletion();
sl@0
  2131
	}
sl@0
  2132
sl@0
  2133
#ifdef _DEBUG
sl@0
  2134
void CDmTest7::TransFailEvent(TDmDomainId aDomainId, TDmDomainState aState, TInt aError)
sl@0
  2135
#else
sl@0
  2136
void CDmTest7::TransFailEvent(TDmDomainId /*aDomainId*/, TDmDomainState /*aState*/, TInt /*aError*/)
sl@0
  2137
#endif
sl@0
  2138
sl@0
  2139
	{
sl@0
  2140
	iTransFailEvents++;
sl@0
  2141
	__PRINT((_L("CDmTest7::TransFailEvent(), aDomainId = %d, aState %d aError %d, iTransFailEvents %d\n"), 
sl@0
  2142
		aDomainId, aState, iTransFailEvents, aError));
sl@0
  2143
	TestForCompletion();
sl@0
  2144
	}
sl@0
  2145
sl@0
  2146
#ifdef _DEBUG
sl@0
  2147
void CDmTest7::TransReqEvent(TDmDomainId aDomainId, TDmDomainState aState)
sl@0
  2148
#else
sl@0
  2149
void CDmTest7::TransReqEvent(TDmDomainId /*aDomainId*/, TDmDomainState /*aState*/)
sl@0
  2150
#endif
sl@0
  2151
	{
sl@0
  2152
	iTransReqEvents++;
sl@0
  2153
	__PRINT((_L("CDmTest7::TransReqEvent(), aDomainId = %d, aState %d, iTransReqEvents %d\n"), 
sl@0
  2154
		aDomainId, aState, iTransReqEvents));
sl@0
  2155
	TestForCompletion();
sl@0
  2156
	}
sl@0
  2157
sl@0
  2158
GLDEF_C TInt E32Main()
sl@0
  2159
	{
sl@0
  2160
	CTrapCleanup* trapHandler=CTrapCleanup::New();
sl@0
  2161
	test(trapHandler!=NULL);
sl@0
  2162
sl@0
  2163
	CActiveScheduler* scheduler = new CActiveScheduler();
sl@0
  2164
	test(scheduler != NULL);
sl@0
  2165
	CActiveScheduler::Install(scheduler);
sl@0
  2166
sl@0
  2167
	// Turn off evil lazy dll unloading
sl@0
  2168
	RLoader l;
sl@0
  2169
	test(l.Connect()==KErrNone);
sl@0
  2170
	test(l.CancelLazyDllUnload()==KErrNone);
sl@0
  2171
	l.Close();
sl@0
  2172
sl@0
  2173
	//
sl@0
  2174
	// Perform the number of iterations specifed by the command line argument.
sl@0
  2175
	//
sl@0
  2176
	// If no arguments - perform two iterations
sl@0
  2177
	//
sl@0
  2178
//  TInt iter = 2;
sl@0
  2179
    TInt iter = 1;
sl@0
  2180
sl@0
  2181
	TInt len = User::CommandLineLength();
sl@0
  2182
	if (len)
sl@0
  2183
		{
sl@0
  2184
		// Copy the command line in a buffer
sl@0
  2185
		HBufC* hb = HBufC::NewMax(len);
sl@0
  2186
		test(hb != NULL);
sl@0
  2187
		TPtr cmd((TUint16*) hb->Ptr(), len);
sl@0
  2188
		User::CommandLine(cmd);
sl@0
  2189
		// Extract the number of iterations
sl@0
  2190
		TLex l(cmd);
sl@0
  2191
		TInt i;
sl@0
  2192
		TInt r = l.Val(i);
sl@0
  2193
		if (r == KErrNone)
sl@0
  2194
			iter = i;
sl@0
  2195
		else
sl@0
  2196
			// strange command - silently ignore
sl@0
  2197
			{} 
sl@0
  2198
		delete hb;
sl@0
  2199
		}
sl@0
  2200
sl@0
  2201
	test.Title();
sl@0
  2202
	test.Start(_L("Testing"));
sl@0
  2203
sl@0
  2204
	test.Printf(_L("Go for %d iterations\n"), iter);
sl@0
  2205
sl@0
  2206
	// Remember the number of open handles. Just for a sanity check ....
sl@0
  2207
	TInt start_thc, start_phc;
sl@0
  2208
	RThread().HandleCount(start_phc, start_thc);
sl@0
  2209
sl@0
  2210
	while (iter--)
sl@0
  2211
		{
sl@0
  2212
		MDmTest* tests[] = 
sl@0
  2213
			{
sl@0
  2214
sl@0
  2215
			new CDmTest1(KDmIdRoot, EPwStandby),
sl@0
  2216
			new CDmTest1(KDmIdRoot, EPwOff),
sl@0
  2217
			new CDmTest1(KDmIdRoot, EPwActive),
sl@0
  2218
			new CDmTest1(KDmIdApps, EPwStandby),
sl@0
  2219
			new CDmTest1(KDmIdApps, EPwOff),
sl@0
  2220
			new CDmTest1(KDmIdApps, EPwActive),
sl@0
  2221
			new CDmTest1(KDmIdUiApps, EPwStandby),
sl@0
  2222
			new CDmTest1(KDmIdUiApps, EPwOff),
sl@0
  2223
			new CDmTest1(KDmIdUiApps, EPwActive),
sl@0
  2224
			new CDmTest2(EPwStandby),
sl@0
  2225
			new CDmTest3(),
sl@0
  2226
	
sl@0
  2227
			// platform security tests
sl@0
  2228
			new CDmTest4(),
sl@0
  2229
sl@0
  2230
			// PREQ810 tests :
sl@0
  2231
			// note that we use a fictitious power state to prevent any 
sl@0
  2232
			new CDmTest5(KDmIdRoot, KDmIdRoot, EPwActive+10, EStartupCriticalDynamic),
sl@0
  2233
			new CDmTest5(KDmIdUiApps, KDmIdTestAB, EPwActive+10, EStartupCriticalDynamic),
sl@0
  2234
sl@0
  2235
        // negative tests
sl@0
  2236
			new CDmTest6(),
sl@0
  2237
sl@0
  2238
sl@0
  2239
			// observer tests
sl@0
  2240
     		new CDmTest7(KDmIdTestA),
sl@0
  2241
			new CDmTest7(KDmIdRoot),
sl@0
  2242
			
sl@0
  2243
			};
sl@0
  2244
sl@0
  2245
		for (unsigned int i = 0; i < sizeof(tests)/sizeof(*tests); ++i)
sl@0
  2246
			{
sl@0
  2247
			test(tests[i] != NULL);
sl@0
  2248
			tests[i]->Perform();
sl@0
  2249
			tests[i]->Release();
sl@0
  2250
			}
sl@0
  2251
sl@0
  2252
		}
sl@0
  2253
sl@0
  2254
	test.End();
sl@0
  2255
sl@0
  2256
	// Sanity check for open handles and for pending requests ...
sl@0
  2257
	TInt end_thc, end_phc;
sl@0
  2258
	RThread().HandleCount(end_phc, end_thc);
sl@0
  2259
	test(start_thc == end_thc);
sl@0
  2260
	test(start_phc == end_phc);
sl@0
  2261
	test(RThread().RequestCount() >= 0);
sl@0
  2262
sl@0
  2263
	delete scheduler;
sl@0
  2264
	delete trapHandler;
sl@0
  2265
sl@0
  2266
	return KErrNone;
sl@0
  2267
	}