email/pop3andsmtpmtm/popservermtm/test/src/T_mtmcmd.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2000-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 "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 //
       
    15 
       
    16 #include "emailtestutils.h"
       
    17 #include "miutlog.h"
       
    18 #include "miutmsg.h"
       
    19 #include <txtrich.h>
       
    20 #include "T_mtmcmd.h"
       
    21 
       
    22 
       
    23 _LIT(K_CHANGE_COMMAND, "Change");
       
    24 _LIT(K_COPY_FROM_LOCAL_COMMAND, "Copy from local");
       
    25 _LIT(K_COPY_TO_LOCAL_COMMAND, "Copy to local");
       
    26 _LIT(K_COPY_WITHIN_SERVICE_COMMAND, "Copy within service");
       
    27 _LIT(K_DELETE_ALL_COMMAND, "Delete all");
       
    28 _LIT(K_MOVE_FROM_LOCAL_COMMAND, "Move from local");
       
    29 _LIT(K_MOVE_TO_LOCAL_COMMAND, "Move to local");
       
    30 _LIT(K_MOVE_WITHIN_SERVICE_COMMAND, "Move within service");
       
    31 _LIT(K_START_COMMAND, "Start command");
       
    32 _LIT(K_TEST_ON_ALL, " (run on all messages)");
       
    33 _LIT(K_TEST_COMPLETED, "Completed - ");
       
    34 _LIT(K_TEST_STARTED, "Started - ");
       
    35 _LIT(K_TEST_FAILED, "Failed - ");
       
    36 _LIT(K_TEST_COMPLETED_OKAY, "Test Completed OK");
       
    37 _LIT(K_TEST_ON_SINGLE, " (run on single message)");
       
    38 _LIT(K_TEST_ON_SECOND, " (run on second message)");
       
    39 _LIT(K_TEST_ON_SECOND_CHILDREN, " (run on children of second message)");
       
    40 _LIT(K_TOP_POPULATE_COMMAND, "Populate using TOP");
       
    41 
       
    42 // Generic Server MTM Test Harness
       
    43 
       
    44 //
       
    45 
       
    46 CMtmTestHarness* CMtmTestHarness::NewL(CBaseServerMtm& aServerMtm, CTestUtils& aTestUtils)
       
    47 	{
       
    48 	CMtmTestHarness* self = new (ELeave) CMtmTestHarness(aServerMtm, aTestUtils);
       
    49 	CleanupStack::PushL(self);
       
    50 	self->ConstructL();
       
    51 	CleanupStack::Pop(); // self
       
    52 	return self;
       
    53 	}
       
    54 
       
    55 // Test harness set up
       
    56 void CMtmTestHarness::Reset()
       
    57 	{
       
    58 	Cancel();
       
    59 
       
    60 	TInt index = iCommandList->Count();
       
    61 	while (index != 0)
       
    62 		{
       
    63 		index--;
       
    64 		delete (*iCommandList)[index];
       
    65 		}
       
    66 
       
    67 	iCommandList->Reset();
       
    68 	iCurrentCommand = 0;
       
    69 	iCommandIndex = 0;
       
    70 	}
       
    71 
       
    72 void CMtmTestHarness::AddCommandL(CMtmTestCommand* aCommand)
       
    73 	{
       
    74 	iCommandList->AppendL(aCommand);
       
    75 	}
       
    76 
       
    77 // Run the test harness
       
    78 void CMtmTestHarness::StartL(const TDesC& aTestName, TRequestStatus& aStatus)
       
    79 	{
       
    80 	iFailed = EFalse;
       
    81 	iCommandIndex = 0;
       
    82 	iCurrentCommand = 0;
       
    83 	iStatus = KRequestPending;
       
    84 	iReportStatus = &aStatus;
       
    85 	*iReportStatus = KRequestPending;
       
    86 
       
    87 	iTestUtils.WriteComment(aTestName);
       
    88 
       
    89 	if (iCommandIndex < iCommandList->Count())
       
    90 		{
       
    91 		RunCurrentCommandL();
       
    92 		}
       
    93 	else
       
    94 		{
       
    95 		SetActive();
       
    96 		TRequestStatus* status = &iStatus;
       
    97 		User::RequestComplete(status, KErrNone);
       
    98 		}
       
    99 	}
       
   100 
       
   101 TInt CMtmTestHarness::StartL(const TDesC& aTestName)
       
   102 	{
       
   103 	CTestActive* waiter = new (ELeave) CTestActive;
       
   104 	CleanupStack::PushL(waiter);
       
   105 	waiter->StartL();
       
   106 	StartL(aTestName, waiter->iStatus);
       
   107 	CActiveScheduler::Start();
       
   108 	TInt status = waiter->iStatus.Int();
       
   109 	CleanupStack::PopAndDestroy(); // waiter
       
   110 	return status;
       
   111 	}
       
   112 
       
   113 // Status information
       
   114 const TDesC8& CMtmTestHarness::Progress()
       
   115 	{
       
   116 	return iServerMtm.Progress();
       
   117 	}
       
   118 
       
   119 CBaseServerMtm&	CMtmTestHarness::ServerMtm()
       
   120 	{
       
   121 	return iServerMtm;
       
   122 	}
       
   123 
       
   124 // Constructor & destructor
       
   125 CMtmTestHarness::CMtmTestHarness(CBaseServerMtm& aServerMtm, CTestUtils& aTestUtils) : CActive(EPriorityNormal), iServerMtm(aServerMtm), iTestUtils(aTestUtils)
       
   126 	{}
       
   127 
       
   128 CMtmTestHarness::~CMtmTestHarness()
       
   129 	{
       
   130 	Reset();
       
   131 	delete iCommandList;
       
   132 	}
       
   133 
       
   134 void CMtmTestHarness::ConstructL()
       
   135 	{
       
   136 	CActiveScheduler::Add(this);
       
   137 	iCommandList = new (ELeave) CArrayFixFlat<CMtmTestCommand*>(6);
       
   138 	Reset();
       
   139 	}
       
   140 
       
   141 void CMtmTestHarness::DoCancel()
       
   142 	{
       
   143 	if (iCurrentCommand)
       
   144 		{
       
   145 		iCurrentCommand->Cancel();
       
   146 		}
       
   147 	}
       
   148 
       
   149 TInt CMtmTestHarness::RunError(TInt aError)
       
   150 	{
       
   151 	if (iReportStatus)
       
   152 		User::RequestComplete(iReportStatus,aError);
       
   153 	return KErrNone;
       
   154 	}
       
   155 
       
   156 void CMtmTestHarness::RunL()
       
   157 	{
       
   158 	if (iCurrentCommand)
       
   159 		{
       
   160 		TBool failed = EFalse;
       
   161 		MCommandTester* tester = iCurrentCommand->Tester();
       
   162 		if (tester)
       
   163 			{
       
   164 			if (!(tester->EndL()))
       
   165 				{
       
   166 				HBufC* logString = HBufC::NewLC(((TDesC&)K_TEST_FAILED).Size() + iCurrentCommand->DetailsL().Size());
       
   167 				*logString = (TDesC&)K_TEST_FAILED;
       
   168 				logString->Des().Append(iCurrentCommand->DetailsL());
       
   169 				iTestUtils.WriteComment(logString->Des());
       
   170 				CleanupStack::PopAndDestroy(); // logString
       
   171 
       
   172 
       
   173 				// log 'FAILED + the info string from the tester'
       
   174 				HBufC* failureInfo = tester->TextInfoL();
       
   175 				if (failureInfo)
       
   176 					{
       
   177 					CleanupStack::PushL(failureInfo);
       
   178 					iTestUtils.WriteComment(failureInfo->Des());
       
   179 					CleanupStack::PopAndDestroy(); // failureInfo
       
   180 					}
       
   181 
       
   182 				iFailed = ETrue;
       
   183 				failed = ETrue;
       
   184 				}
       
   185 			}
       
   186 
       
   187 		if (!failed)
       
   188 			{
       
   189 			HBufC* logString = HBufC::NewLC(((TDesC&)K_TEST_COMPLETED).Size() + iCurrentCommand->DetailsL().Size());
       
   190 			*logString = (TDesC&)K_TEST_COMPLETED;
       
   191 			logString->Des().Append(iCurrentCommand->DetailsL());
       
   192 			iTestUtils.WriteComment(logString->Des());
       
   193 			CleanupStack::PopAndDestroy(); // logString
       
   194 			}
       
   195 		}
       
   196 
       
   197 	// Run the next command if there is one.
       
   198 	iCommandError = KErrNone;
       
   199  	iCommandIndex++;
       
   200 	if ((iCommandIndex < iCommandList->Count())
       
   201 		&& (iStatus == KErrNone))
       
   202 		{
       
   203 		// Check for any Command Errors
       
   204 		TRAPD(err, RunCurrentCommandL());
       
   205 		if (err != KErrNone)
       
   206 			{
       
   207 			// Store the Command Error & Leave
       
   208 			iCommandError = err;
       
   209 			User::Leave(err);
       
   210 			}
       
   211 		}
       
   212 	else
       
   213 	// otherwise complete the report status.
       
   214 		{
       
   215 		iTestUtils.WriteComment(K_TEST_COMPLETED_OKAY);
       
   216 		User::RequestComplete(iReportStatus, iStatus.Int());
       
   217 		Reset();
       
   218 		}
       
   219 	}
       
   220 
       
   221 void CMtmTestHarness::RunCurrentCommandL()
       
   222 	{
       
   223 	iStatus = KRequestPending;
       
   224 	SetActive();
       
   225 	iCurrentCommand = (*iCommandList)[iCommandIndex];
       
   226 	MCommandTester* tester = iCurrentCommand->Tester();
       
   227 
       
   228 	if (tester)
       
   229 		tester->InitialiseL();
       
   230 
       
   231 	iCurrentCommand->ExecuteCommandL(iStatus);
       
   232 
       
   233 	if (tester)
       
   234 		tester->StartL();
       
   235 
       
   236 	HBufC* logString = HBufC::NewLC(((TDesC&)K_TEST_STARTED).Size() + iCurrentCommand->DetailsL().Size());
       
   237 	*logString = (TDesC&)K_TEST_STARTED;
       
   238 	logString->Des().Append(iCurrentCommand->DetailsL());
       
   239 	iTestUtils.WriteComment(logString->Des());
       
   240 	CleanupStack::PopAndDestroy(); // logString
       
   241 	}
       
   242 
       
   243 //
       
   244 
       
   245 // Run this command
       
   246 void CMtmTestCommand::DoCancel()
       
   247 	{
       
   248 	iServerMtm.Cancel();
       
   249 	}
       
   250 
       
   251 TInt CMtmTestCommand::RunError(TInt aError)
       
   252 	{
       
   253 	if (iReportStatus)
       
   254 		User::RequestComplete(iReportStatus,aError);
       
   255 	return KErrNone;
       
   256 	}
       
   257 
       
   258 void CMtmTestCommand::RunL()
       
   259 	{
       
   260 	TPop3Progress temp;	
       
   261 	TPckgC<TPop3Progress> paramPack(temp);
       
   262 	const TDesC8& progBuf = iServerMtm.Progress();	
       
   263 	paramPack.Set(progBuf);
       
   264 	TPop3Progress progress=paramPack();	
       
   265 
       
   266 	TInt err=iStatus.Int();
       
   267 	if (!err && progress.iErrorCode )
       
   268 		err=progress.iErrorCode; //pass the error
       
   269 	User::RequestComplete(iReportStatus, err);
       
   270 	}
       
   271 
       
   272 CMtmTestCommand::~CMtmTestCommand()
       
   273 	{
       
   274 	delete iSelection;
       
   275 	delete iTester;
       
   276 	delete iDetails;
       
   277 	}
       
   278 
       
   279 void CMtmTestCommand::CopySelectionL(const CMsvEntrySelection* aSelection)
       
   280 	{
       
   281 	delete iSelection;
       
   282 	iSelection = 0;
       
   283 	if (aSelection)
       
   284 		iSelection = aSelection->CopyL();
       
   285 	}
       
   286 
       
   287 CMtmTestCommand::CMtmTestCommand(CBaseServerMtm& aServerMtm) : CActive(EPriorityNormal),iServerMtm(aServerMtm)
       
   288 	{
       
   289 	CActiveScheduler::Add(this);
       
   290 	}
       
   291 
       
   292 void CMtmTestCommand::Queue(TRequestStatus& aReportStatus)
       
   293 	{
       
   294 	iReportStatus = &aReportStatus;
       
   295 	iStatus = KRequestPending;
       
   296 	SetActive();
       
   297 	}
       
   298 
       
   299 void CMtmTestCommand::SetCommandTester(MCommandTester* aTester)
       
   300 	{
       
   301 	delete iTester;
       
   302 	iTester = 0;
       
   303 	iTester = aTester;
       
   304 	}
       
   305 
       
   306 MCommandTester* CMtmTestCommand::Tester()
       
   307 	{
       
   308 	return iTester;
       
   309 	}
       
   310 
       
   311 TPtrC CMtmTestCommand::DetailsL()
       
   312 	{
       
   313 	delete iDetails;
       
   314 	iDetails = NULL;
       
   315 	iDetails = CommandDetailsL();
       
   316 	if (iDetails == NULL)
       
   317 		{
       
   318 		iDetails = HBufC::NewL(0);
       
   319 		}
       
   320 
       
   321 	return TPtrC(iDetails->Des());
       
   322 	}
       
   323 
       
   324 
       
   325 //
       
   326 
       
   327 void CMtmTestChange::ExecuteCommandL(TRequestStatus& aStatus)
       
   328 	{
       
   329 	Queue(aStatus);
       
   330 	iServerMtm.ChangeL(iNewEntry, iStatus);
       
   331 	}
       
   332 
       
   333 HBufC* CMtmTestChange::CommandDetailsL()
       
   334 	{
       
   335 	HBufC* details = HBufC::NewL(((TDesC&)K_CHANGE_COMMAND).Size());
       
   336 	*details = (TDesC&)K_CHANGE_COMMAND;
       
   337 	return details;
       
   338 	}
       
   339 
       
   340 CMtmTestChange* CMtmTestChange::NewL(CBaseServerMtm& aServerMtm, TMsvEntry aNewEntry)
       
   341 	{
       
   342 	CMtmTestChange* self = new (ELeave) CMtmTestChange(aServerMtm, aNewEntry);
       
   343 	return self;
       
   344 	}
       
   345 
       
   346 CMtmTestChange::CMtmTestChange(CBaseServerMtm& aServerMtm, TMsvEntry aNewEntry) : CMtmTestCommand(aServerMtm),iNewEntry(aNewEntry)
       
   347 	{}
       
   348 
       
   349 //
       
   350 
       
   351 void CMtmTestDeleteAll::ExecuteCommandL(TRequestStatus& aStatus)
       
   352 	{
       
   353 	Queue(aStatus);
       
   354 	iServerMtm.DeleteAllL(*iSelection, iStatus);
       
   355 	}
       
   356 
       
   357 HBufC* CMtmTestDeleteAll::CommandDetailsL()
       
   358 	{
       
   359 	HBufC* details = HBufC::NewL(((TDesC&)K_DELETE_ALL_COMMAND).Size());
       
   360 	*details = (TDesC&)K_DELETE_ALL_COMMAND;
       
   361 	return details;
       
   362 	}
       
   363 
       
   364 CMtmTestDeleteAll* CMtmTestDeleteAll::NewL(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* aSelection)
       
   365 	{
       
   366 	CMtmTestDeleteAll* self = new (ELeave) CMtmTestDeleteAll(aServerMtm, aSelection);
       
   367 	CleanupStack::PushL(self);
       
   368 	self->CopySelectionL(aSelection);
       
   369 	CleanupStack::Pop(); // self
       
   370 	return self;
       
   371 	}
       
   372 
       
   373 CMtmTestDeleteAll::CMtmTestDeleteAll(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* /*aSelection*/) : CMtmTestCommand(aServerMtm)
       
   374 	{}
       
   375 
       
   376 //
       
   377 
       
   378 void CMtmTestCopyToLocal::ExecuteCommandL(TRequestStatus& aStatus)
       
   379 	{
       
   380 	Queue(aStatus);
       
   381 	iServerMtm.CopyToLocalL(*iSelection, iDest, iStatus);
       
   382 	}
       
   383 
       
   384 HBufC* CMtmTestCopyToLocal::CommandDetailsL()
       
   385 	{
       
   386 	HBufC* details = HBufC::NewL(((TDesC&)K_COPY_TO_LOCAL_COMMAND).Size());
       
   387 	*details = (TDesC&)K_COPY_TO_LOCAL_COMMAND;
       
   388 	return details;
       
   389 	}
       
   390 
       
   391 CMtmTestCopyToLocal* CMtmTestCopyToLocal::NewL(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* aSelection, TMsvId aDest)
       
   392 	{
       
   393 	CMtmTestCopyToLocal* self = new (ELeave) CMtmTestCopyToLocal(aServerMtm, aSelection, aDest);
       
   394 	CleanupStack::PushL(self);
       
   395 	self->CopySelectionL(aSelection);
       
   396 	CleanupStack::Pop(); // self
       
   397 	return self;
       
   398 	}
       
   399 
       
   400 CMtmTestCopyToLocal::CMtmTestCopyToLocal(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* /*aSelection*/, TMsvId aDest) : CMtmTestCommand(aServerMtm), iDest(aDest)
       
   401 	{}
       
   402 
       
   403 //
       
   404 
       
   405 void CMtmTestCopyFromLocal::ExecuteCommandL(TRequestStatus& aStatus)
       
   406 	{
       
   407 	Queue(aStatus);
       
   408 	iServerMtm.CopyFromLocalL(*iSelection, iDest, iStatus);
       
   409 	}
       
   410 
       
   411 HBufC* CMtmTestCopyFromLocal::CommandDetailsL()
       
   412 	{
       
   413 	HBufC* details = HBufC::NewL(((TDesC&)K_COPY_FROM_LOCAL_COMMAND).Size());
       
   414 	*details = (TDesC&)K_COPY_FROM_LOCAL_COMMAND;
       
   415 	return details;
       
   416 	}
       
   417 
       
   418 CMtmTestCopyFromLocal* CMtmTestCopyFromLocal::NewL(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* aSelection, TMsvId aDest)
       
   419 	{
       
   420 	CMtmTestCopyFromLocal* self = new (ELeave) CMtmTestCopyFromLocal(aServerMtm, aSelection, aDest);
       
   421 	CleanupStack::PushL(self);
       
   422 	self->CopySelectionL(aSelection);
       
   423 	CleanupStack::Pop(); // self
       
   424 	return self;
       
   425 	}
       
   426 
       
   427 CMtmTestCopyFromLocal::CMtmTestCopyFromLocal(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* /*aSelection*/, TMsvId aDest) : CMtmTestCommand(aServerMtm), iDest(aDest)
       
   428 	{}
       
   429 
       
   430 //
       
   431 
       
   432 void CMtmTestTopPopulate::ExecuteCommandL(TRequestStatus& aStatus)
       
   433 	{
       
   434 	Queue(aStatus);
       
   435 	TInt command = KPOP3MTMPopulate;
       
   436 	TImPop3PopulateOptions pop3GetMailInfo;	
       
   437 	pop3GetMailInfo.SetPopulationLimit(64);
       
   438 	TPckgC<TImPop3PopulateOptions> paramPack(pop3GetMailInfo);
       
   439 	
       
   440 	iServerMtm.StartCommandL(*iSelection,command,paramPack,iStatus);
       
   441 	}
       
   442 
       
   443 HBufC* CMtmTestTopPopulate::CommandDetailsL()
       
   444 	{
       
   445 	HBufC* details = HBufC::NewL(((TDesC&)K_TOP_POPULATE_COMMAND).Size());
       
   446 	*details = (TDesC&)K_TOP_POPULATE_COMMAND;
       
   447 	return details;
       
   448 	}
       
   449 
       
   450 CMtmTestTopPopulate* CMtmTestTopPopulate::NewL(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* aSelection, TMsvId aDest)
       
   451 	{
       
   452 	CMtmTestTopPopulate* self = new (ELeave) CMtmTestTopPopulate(aServerMtm, aSelection, aDest);
       
   453 	CleanupStack::PushL(self);
       
   454 	self->CopySelectionL(aSelection);
       
   455 	CleanupStack::Pop(self); // self
       
   456 	return self;
       
   457 	}
       
   458 
       
   459 CMtmTestTopPopulate::CMtmTestTopPopulate(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* /*aSelection*/, TMsvId aDest) : CMtmTestCommand(aServerMtm), iDest(aDest)
       
   460 	{}
       
   461 
       
   462 //
       
   463 
       
   464 void CMtmTestCopyWithinService::ExecuteCommandL(TRequestStatus& aStatus)
       
   465 	{
       
   466 	Queue(aStatus);
       
   467 	iServerMtm.CopyWithinServiceL(*iSelection, iDest, iStatus);
       
   468 	}
       
   469 
       
   470 HBufC* CMtmTestCopyWithinService::CommandDetailsL()
       
   471 	{
       
   472 	HBufC* details = HBufC::NewL(((TDesC&)K_COPY_WITHIN_SERVICE_COMMAND).Size());
       
   473 	*details = (TDesC&)K_COPY_WITHIN_SERVICE_COMMAND;
       
   474 	return details;
       
   475 	}
       
   476 
       
   477 CMtmTestCopyWithinService* CMtmTestCopyWithinService::NewL(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* aSelection, TMsvId aDest)
       
   478 	{
       
   479 	CMtmTestCopyWithinService* self = new (ELeave) CMtmTestCopyWithinService(aServerMtm, aSelection, aDest);
       
   480 	CleanupStack::PushL(self);
       
   481 	self->CopySelectionL(aSelection);
       
   482 	CleanupStack::Pop(); // self
       
   483 	return self;
       
   484 	}
       
   485 
       
   486 CMtmTestCopyWithinService::CMtmTestCopyWithinService(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* /*aSelection*/, TMsvId aDest) : CMtmTestCommand(aServerMtm), iDest(aDest)
       
   487 	{}
       
   488 
       
   489 //
       
   490 
       
   491 void CMtmTestMoveToLocal::ExecuteCommandL(TRequestStatus& aStatus)
       
   492 	{
       
   493 	Queue(aStatus);
       
   494 	iServerMtm.MoveToLocalL(*iSelection, iDest, iStatus);
       
   495 	}
       
   496 
       
   497 HBufC* CMtmTestMoveToLocal::CommandDetailsL()
       
   498 	{
       
   499 	HBufC* details = HBufC::NewL(((TDesC&)K_MOVE_TO_LOCAL_COMMAND).Size());
       
   500 	*details = (TDesC&)K_MOVE_TO_LOCAL_COMMAND;
       
   501 	return details;
       
   502 	}
       
   503 
       
   504 CMtmTestMoveToLocal* CMtmTestMoveToLocal::NewL(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* aSelection, TMsvId aDest)
       
   505 	{
       
   506 	CMtmTestMoveToLocal* self = new (ELeave) CMtmTestMoveToLocal(aServerMtm, aSelection, aDest);
       
   507 	CleanupStack::PushL(self);
       
   508 	self->CopySelectionL(aSelection);
       
   509 	CleanupStack::Pop(); // self
       
   510 	return self;
       
   511 	}
       
   512 
       
   513 CMtmTestMoveToLocal::CMtmTestMoveToLocal(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* /*aSelection*/, TMsvId aDest) : CMtmTestCommand(aServerMtm), iDest(aDest)
       
   514 	{}
       
   515 
       
   516 //
       
   517 
       
   518 void CMtmTestMoveFromLocal::ExecuteCommandL(TRequestStatus& aStatus)
       
   519 	{
       
   520 	Queue(aStatus);
       
   521 	iServerMtm.MoveFromLocalL(*iSelection, iDest, iStatus);
       
   522 	}
       
   523 
       
   524 HBufC* CMtmTestMoveFromLocal::CommandDetailsL()
       
   525 	{
       
   526 	HBufC* details = HBufC::NewL(((TDesC&)K_MOVE_FROM_LOCAL_COMMAND).Size());
       
   527 	*details = (TDesC&)K_MOVE_FROM_LOCAL_COMMAND;
       
   528 	return details;
       
   529 	}
       
   530 
       
   531 CMtmTestMoveFromLocal* CMtmTestMoveFromLocal::NewL(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* aSelection, TMsvId aDest)
       
   532 	{
       
   533 	CMtmTestMoveFromLocal* self = new (ELeave) CMtmTestMoveFromLocal(aServerMtm, aSelection, aDest);
       
   534 	CleanupStack::PushL(self);
       
   535 	self->CopySelectionL(aSelection);
       
   536 	CleanupStack::Pop(); // self
       
   537 	return self;
       
   538 	}
       
   539 
       
   540 CMtmTestMoveFromLocal::CMtmTestMoveFromLocal(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* /*aSelection*/, TMsvId aDest) : CMtmTestCommand(aServerMtm), iDest(aDest)
       
   541 	{}
       
   542 
       
   543 //
       
   544 
       
   545 void CMtmTestMoveWithinService::ExecuteCommandL(TRequestStatus& aStatus)
       
   546 	{
       
   547 	Queue(aStatus);
       
   548 	iServerMtm.MoveWithinServiceL(*iSelection, iDest, iStatus);
       
   549 	}
       
   550 
       
   551 HBufC* CMtmTestMoveWithinService::CommandDetailsL()
       
   552 	{
       
   553 	HBufC* details = HBufC::NewL(((TDesC&)K_MOVE_WITHIN_SERVICE_COMMAND).Size());
       
   554 	*details = (TDesC&)K_MOVE_WITHIN_SERVICE_COMMAND;
       
   555 	return details;
       
   556 	}
       
   557 
       
   558 CMtmTestMoveWithinService* CMtmTestMoveWithinService::NewL(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* aSelection, TMsvId aDest)
       
   559 	{
       
   560 	CMtmTestMoveWithinService* self = new (ELeave) CMtmTestMoveWithinService(aServerMtm, aSelection, aDest);
       
   561 	CleanupStack::PushL(self);
       
   562 	self->CopySelectionL(aSelection);
       
   563 	CleanupStack::Pop(); // self
       
   564 	return self;
       
   565 	}
       
   566 
       
   567 CMtmTestMoveWithinService::CMtmTestMoveWithinService(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* /*aSelection*/, TMsvId aDest) : CMtmTestCommand(aServerMtm), iDest(aDest)
       
   568 	{}
       
   569 
       
   570 //
       
   571 
       
   572 void CMtmTestStartCommand::ExecuteCommandL(TRequestStatus& aStatus)
       
   573 	{
       
   574 	Queue(aStatus);
       
   575 	iServerMtm.StartCommandL(*iSelection, iCommandId, iParameter->Des(), iStatus);
       
   576 	}
       
   577 
       
   578 HBufC* CMtmTestStartCommand::CommandDetailsL()
       
   579 	{
       
   580 	HBufC* details = HBufC::NewL(((TDesC&)K_START_COMMAND).Size());
       
   581 	*details = (TDesC&)K_START_COMMAND;
       
   582 	return details;
       
   583 	}
       
   584 
       
   585 CMtmTestStartCommand* CMtmTestStartCommand::NewL(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* aSelection, TInt aCommandId, TDesC8& aParameter)
       
   586 	{
       
   587 	CMtmTestStartCommand* self = new (ELeave) CMtmTestStartCommand(aServerMtm, aSelection, aCommandId, aParameter);
       
   588 	CleanupStack::PushL(self);
       
   589 	self->CopySelectionL(aSelection);
       
   590 	self->iParameter = HBufC8::NewL(aParameter.Size());
       
   591 	*(self->iParameter) = aParameter;
       
   592 	CleanupStack::Pop(); // self
       
   593 	return self;
       
   594 	}
       
   595 
       
   596 CMtmTestStartCommand::~CMtmTestStartCommand()
       
   597 	{
       
   598 	delete iParameter;
       
   599 	}
       
   600 
       
   601 CMtmTestStartCommand::CMtmTestStartCommand(CBaseServerMtm& aServerMtm, const CMsvEntrySelection* /*aSelection*/, TInt aCommandId, TDesC8& /*aParamter*/) : CMtmTestCommand(aServerMtm), iCommandId(aCommandId)
       
   602 	{}
       
   603 
       
   604 //
       
   605 
       
   606 // Runs a command on all messages directly under a given message entry.
       
   607 // This command object takes ownership of the given command.
       
   608 // The given command should have all of it's parameters set before
       
   609 // this command is created, with the exception of it's selection
       
   610 // parameter.
       
   611 
       
   612 void CMtmTestCommandOnAllMessages::ExecuteCommandL(TRequestStatus& aStatus)
       
   613 	{
       
   614 	// Get the selection of messages.
       
   615 	User::LeaveIfError(iServerEntry.SetEntry(iRootId));
       
   616 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   617 	CleanupStack::PushL(selection);
       
   618 	User::LeaveIfError(iServerEntry.GetChildren(*selection));
       
   619 
       
   620 	// Set the entry selection of the child command.
       
   621 	iRealCommand->CopySelectionL(selection);
       
   622 	CleanupStack::PopAndDestroy(); // selection
       
   623 
       
   624 	// Run the child command.
       
   625 	Queue(aStatus);
       
   626 	iRealCommand->ExecuteCommandL(iStatus);
       
   627 	}
       
   628 
       
   629 HBufC* CMtmTestCommandOnAllMessages::CommandDetailsL()
       
   630 	{
       
   631 	HBufC* details = HBufC::NewL(((TDesC&)K_TEST_ON_ALL).Size() + iRealCommand->DetailsL().Size());
       
   632 	*details = iRealCommand->DetailsL();
       
   633 	details->Des().Append((TDesC&)K_TEST_ON_ALL);
       
   634 	return details;
       
   635 	}
       
   636 
       
   637 CMtmTestCommandOnAllMessages* CMtmTestCommandOnAllMessages::NewL(CBaseServerMtm& aServerMtm, CMtmTestCommand* aCommand, TMsvId aRootId, CMsvServerEntry& aEntry)
       
   638 	{
       
   639 	CMtmTestCommandOnAllMessages* self = new (ELeave) CMtmTestCommandOnAllMessages(aServerMtm, aCommand, aRootId, aEntry);
       
   640 	return self;
       
   641 	}
       
   642 
       
   643 CMtmTestCommandOnAllMessages::~CMtmTestCommandOnAllMessages()
       
   644 	{
       
   645 	iRealCommand->Cancel();
       
   646 	delete iRealCommand;
       
   647 	}
       
   648 
       
   649 CMtmTestCommandOnAllMessages::CMtmTestCommandOnAllMessages(CBaseServerMtm& aServerMtm, CMtmTestCommand* aCommand, TMsvId aRootId, CMsvServerEntry& aEntry) : CMtmTestCommand(aServerMtm), iRealCommand(aCommand), iRootId(aRootId), iServerEntry(aEntry)
       
   650 	{
       
   651 	}
       
   652 
       
   653 //
       
   654 
       
   655 // Runs a command on the second message directly under a given message entry.
       
   656 // This command object takes ownership of the given command.
       
   657 // The given command should have all of it's parameters set before
       
   658 // this command is created, with the exception of it's selection
       
   659 // parameter.
       
   660 
       
   661 void CMtmTestCommandOnSecondMessage::ExecuteCommandL(TRequestStatus& aStatus)
       
   662 	{
       
   663 	// Get the selection of messages.
       
   664 	User::LeaveIfError(iServerEntry.SetEntry(iRootId));
       
   665 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   666 	CleanupStack::PushL(selection);
       
   667 	User::LeaveIfError(iServerEntry.GetChildren(*selection));
       
   668 	CMsvEntrySelection* secondSelection = new (ELeave) CMsvEntrySelection;
       
   669 	CleanupStack::PushL(secondSelection);
       
   670 	secondSelection->AppendL((*selection)[1]);
       
   671 
       
   672 	// Set the entry selection of the child command.
       
   673 	iRealCommand->CopySelectionL(secondSelection);
       
   674 	CleanupStack::PopAndDestroy(2); // secondSelection, selection
       
   675 
       
   676 	// Run the child command.
       
   677 	Queue(aStatus);
       
   678 	iRealCommand->ExecuteCommandL(iStatus);
       
   679 	}
       
   680 
       
   681 HBufC* CMtmTestCommandOnSecondMessage::CommandDetailsL()
       
   682 	{
       
   683 	HBufC* details = HBufC::NewL(((TDesC&)K_TEST_ON_SECOND).Size() + iRealCommand->DetailsL().Size());
       
   684 	*details = iRealCommand->DetailsL();
       
   685 	details->Des().Append((TDesC&)K_TEST_ON_SECOND);
       
   686 	return details;
       
   687 	}
       
   688 
       
   689 CMtmTestCommandOnSecondMessage* CMtmTestCommandOnSecondMessage::NewL(CBaseServerMtm& aServerMtm, CMtmTestCommand* aCommand, TMsvId aRootId, CMsvServerEntry& aEntry)
       
   690 	{
       
   691 	CMtmTestCommandOnSecondMessage* self = new (ELeave) CMtmTestCommandOnSecondMessage(aServerMtm, aCommand, aRootId, aEntry);
       
   692 	return self;
       
   693 	}
       
   694 
       
   695 CMtmTestCommandOnSecondMessage::~CMtmTestCommandOnSecondMessage()
       
   696 	{
       
   697 	iRealCommand->Cancel();
       
   698 	delete iRealCommand;
       
   699 	}
       
   700 
       
   701 CMtmTestCommandOnSecondMessage::CMtmTestCommandOnSecondMessage(CBaseServerMtm& aServerMtm, CMtmTestCommand* aCommand, TMsvId aRootId, CMsvServerEntry& aEntry) : CMtmTestCommand(aServerMtm), iRealCommand(aCommand), iRootId(aRootId), iServerEntry(aEntry)
       
   702 	{
       
   703 	}
       
   704 
       
   705 //
       
   706 
       
   707 // Runs a command on the children of the second message directly under a given message entry.
       
   708 // This command object takes ownership of the given command.
       
   709 // The given command should have all of it's parameters set before
       
   710 // this command is created, with the exception of it's selection
       
   711 // parameter.
       
   712 
       
   713 void CMtmTestCommandOnChildrenOf2ndMsg::ExecuteCommandL(TRequestStatus& aStatus)
       
   714 	{
       
   715 	// Get the selection of messages.
       
   716 	User::LeaveIfError(iServerEntry.SetEntry(iRootId));
       
   717 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   718 	CleanupStack::PushL(selection);
       
   719 	User::LeaveIfError(iServerEntry.GetChildren(*selection));
       
   720 	CMsvEntrySelection* secondSelection = new (ELeave) CMsvEntrySelection;
       
   721 	CleanupStack::PushL(secondSelection);
       
   722 
       
   723 	// Get the selection of children of the second message
       
   724 	User::LeaveIfError(iServerEntry.SetEntry((*selection)[1]));	
       
   725 	User::LeaveIfError(iServerEntry.GetChildren(*secondSelection));
       
   726 
       
   727 	// Set the entry selection of the child command.
       
   728 	iRealCommand->CopySelectionL(secondSelection);
       
   729 	CleanupStack::PopAndDestroy(2); // secondSelection, selection
       
   730 
       
   731 	// Run the child command.
       
   732 	Queue(aStatus);
       
   733 	iRealCommand->ExecuteCommandL(iStatus);
       
   734 	}
       
   735 
       
   736 HBufC* CMtmTestCommandOnChildrenOf2ndMsg::CommandDetailsL()
       
   737 	{
       
   738 	HBufC* details = HBufC::NewL(((TDesC&)K_TEST_ON_SECOND_CHILDREN).Size() + iRealCommand->DetailsL().Size());
       
   739 	*details = iRealCommand->DetailsL();
       
   740 	details->Des().Append((TDesC&)K_TEST_ON_SECOND_CHILDREN);
       
   741 	return details;
       
   742 	}
       
   743 
       
   744 CMtmTestCommandOnChildrenOf2ndMsg* CMtmTestCommandOnChildrenOf2ndMsg::NewL(CBaseServerMtm& aServerMtm, CMtmTestCommand* aCommand, TMsvId aRootId, CMsvServerEntry& aEntry)
       
   745 	{
       
   746 	CMtmTestCommandOnChildrenOf2ndMsg* self = new (ELeave) CMtmTestCommandOnChildrenOf2ndMsg(aServerMtm, aCommand, aRootId, aEntry);
       
   747 	return self;
       
   748 	}
       
   749 
       
   750 CMtmTestCommandOnChildrenOf2ndMsg::~CMtmTestCommandOnChildrenOf2ndMsg()
       
   751 	{
       
   752 	iRealCommand->Cancel();
       
   753 	delete iRealCommand;
       
   754 	}
       
   755 
       
   756 CMtmTestCommandOnChildrenOf2ndMsg::CMtmTestCommandOnChildrenOf2ndMsg(CBaseServerMtm& aServerMtm, CMtmTestCommand* aCommand, TMsvId aRootId, CMsvServerEntry& aEntry) : CMtmTestCommand(aServerMtm), iRealCommand(aCommand), iRootId(aRootId), iServerEntry(aEntry)
       
   757 	{
       
   758 	}
       
   759 
       
   760 //
       
   761 
       
   762 //
       
   763 
       
   764 // Runs a command on the specified messages directly under a given message entry.
       
   765 // The messages must exist, e.g. remote mailbox must be populated or this object leaves.
       
   766 // This command object takes ownership of the given command.
       
   767 // The given command should have all of it's parameters set before
       
   768 // this command is created, with the exception of it's selection
       
   769 // parameter.
       
   770 
       
   771 void CMtmTestCommandOnSpecifiedMessages::ExecuteCommandL(TRequestStatus& aStatus)
       
   772 	{
       
   773 	// Get the selection of messages.
       
   774 	if (!iSpecifiedEntries || iSpecifiedEntries->Count()==0)
       
   775 		User::Leave(KErrNotFound);
       
   776 
       
   777 	// Set the entry selection of the child command.
       
   778 	iRealCommand->CopySelectionL(iSpecifiedEntries);
       
   779 
       
   780 	// Run the child command.
       
   781 	Queue(aStatus);
       
   782 	iRealCommand->ExecuteCommandL(iStatus);
       
   783 	}
       
   784 
       
   785 HBufC* CMtmTestCommandOnSpecifiedMessages::CommandDetailsL()
       
   786 	{
       
   787 	HBufC* details = HBufC::NewL(((TDesC&)K_TEST_ON_ALL).Size() + iRealCommand->DetailsL().Size());
       
   788 	*details = iRealCommand->DetailsL();
       
   789 	details->Des().Append((TDesC&)K_TEST_ON_ALL);
       
   790 	return details;
       
   791 	}
       
   792 
       
   793 CMtmTestCommandOnSpecifiedMessages* CMtmTestCommandOnSpecifiedMessages::NewL(CBaseServerMtm& aServerMtm, CMtmTestCommand* aCommand, TMsvId aRootId, CMsvServerEntry& aEntry, CMsvEntrySelection* aSpecifiedEntries)
       
   794 	{
       
   795 	CMtmTestCommandOnSpecifiedMessages* self = new (ELeave) CMtmTestCommandOnSpecifiedMessages(aServerMtm, aCommand, aRootId, aEntry,aSpecifiedEntries);
       
   796 	return self;
       
   797 	}
       
   798 
       
   799 CMtmTestCommandOnSpecifiedMessages::~CMtmTestCommandOnSpecifiedMessages()
       
   800 	{
       
   801 	iRealCommand->Cancel();
       
   802 	delete iRealCommand;
       
   803 	delete iSpecifiedEntries;
       
   804 	}
       
   805 
       
   806 CMtmTestCommandOnSpecifiedMessages::CMtmTestCommandOnSpecifiedMessages(CBaseServerMtm& aServerMtm, CMtmTestCommand* aCommand, TMsvId aRootId, CMsvServerEntry& aEntry, CMsvEntrySelection* aSpecifiedEntries) 
       
   807 : CMtmTestCommand(aServerMtm), iRealCommand(aCommand), iRootId(aRootId), iServerEntry(aEntry), iSpecifiedEntries(aSpecifiedEntries)
       
   808 	{
       
   809 	}
       
   810 
       
   811 
       
   812 //
       
   813 
       
   814 // Runs a command on the specified message directly under a given message entry.
       
   815 // (NB specified as a positive integer value NOT TMsvId !!!)
       
   816 // This command object takes ownership of the given command.
       
   817 // The given command should have all of it's parameters set before
       
   818 // this command is created, with the exception of it's selection
       
   819 // parameter.
       
   820 
       
   821 void CMtmTestCommandOnSingleMessage::ExecuteCommandL(TRequestStatus& aStatus)
       
   822 	{
       
   823 	// Get the selection of messages.
       
   824 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   825 	CleanupStack::PushL(selection);
       
   826 	selection->AppendL( iSpecifiedEntry );
       
   827 	iRealCommand->CopySelectionL(selection);
       
   828 	CleanupStack::PopAndDestroy(selection); // selection
       
   829 
       
   830 	// Run the child command.
       
   831 	Queue(aStatus);
       
   832 	iRealCommand->ExecuteCommandL(iStatus);
       
   833 	}
       
   834 
       
   835 HBufC* CMtmTestCommandOnSingleMessage::CommandDetailsL()
       
   836 	{
       
   837 	HBufC* details = HBufC::NewL(((TDesC&)K_TEST_ON_SINGLE).Size() + iRealCommand->DetailsL().Size());
       
   838 	*details = iRealCommand->DetailsL();
       
   839 	details->Des().Append((TDesC&)K_TEST_ON_SINGLE);
       
   840 	return details;
       
   841 	}
       
   842 
       
   843 CMtmTestCommandOnSingleMessage* CMtmTestCommandOnSingleMessage::NewL(CBaseServerMtm& aServerMtm, CMtmTestCommand* aCommand, TMsvId aRootId, CMsvServerEntry& aEntry, TMsvId aSpecifiedEntry)
       
   844 	{
       
   845 	CMtmTestCommandOnSingleMessage* self = new (ELeave) CMtmTestCommandOnSingleMessage(aServerMtm, aCommand, aRootId, aEntry,aSpecifiedEntry);
       
   846 	return self;
       
   847 	}
       
   848 
       
   849 CMtmTestCommandOnSingleMessage::~CMtmTestCommandOnSingleMessage()
       
   850 	{
       
   851 	iRealCommand->Cancel();
       
   852 	delete iRealCommand;
       
   853 	}
       
   854 
       
   855 CMtmTestCommandOnSingleMessage::CMtmTestCommandOnSingleMessage(CBaseServerMtm& aServerMtm, CMtmTestCommand* aCommand, TMsvId aRootId, CMsvServerEntry& aEntry, TMsvId aSpecifiedEntry) 
       
   856 : CMtmTestCommand(aServerMtm), iRealCommand(aCommand), iRootId(aRootId), iServerEntry(aEntry), iSpecifiedEntry(aSpecifiedEntry)
       
   857 	{
       
   858 	}
       
   859 
       
   860 
       
   861