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