messagingfw/scheduledsendmtm/test/unit/src/t_schsendutils.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1999-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 "t_schsendutils.h"
       
    17 #include <msvstd.h>
       
    18 #include <msvids.h>
       
    19 #include <msvuids.h>
       
    20 #include <msvschedulesettings.h>
       
    21 #include <csch_cli.h>
       
    22 #include <msvschedulepackage.h>
       
    23 #include <msvoffpeaktime.h>
       
    24 
       
    25 EXPORT_C CSchSendTestUtils::CSchSendTestUtils(RTest& aTest)
       
    26 : CMsvTestUtils(aTest)
       
    27 	{
       
    28 	}
       
    29 
       
    30 EXPORT_C void CSchSendTestUtils::InstallMtmGroupsL()
       
    31 	{
       
    32 	}
       
    33 
       
    34 EXPORT_C void CSchSendTestUtils::CreateServerMtmRegsL()
       
    35 	{
       
    36 //CreateServerMtmRegL(KPigeonMtmUid, _L("Pig"), KUidMsvMtmServerDLL, KUidMsvMtmClientDLL, TMsvTestDllInfo(KUidMsvMtmUiDLL,2), TMsvTestDllInfo(KUidMsvMtmUiDLL,1), KPigeonMtmUid, KDataComponentFileName);
       
    37 	}
       
    38 
       
    39 EXPORT_C void CSchSendTestUtils::ConstructL()
       
    40 	{
       
    41 	CMsvTestUtils::ConstructL(ETuNone);
       
    42 	CleanScheduleFolderL();
       
    43 	CreateAllTestDirectories();
       
    44 	GoClientSideL();
       
    45 
       
    46 	InstallMtmGroupL(_L("c:\\system\\mtm\\pigmtmu.dat"));
       
    47 
       
    48 	iSelection = new(ELeave) CMsvEntrySelection;
       
    49 	iSchTestActive = CScheduleTestActive::NewL(*this);
       
    50 	}
       
    51 
       
    52 EXPORT_C CSchSendTestUtils::~CSchSendTestUtils()
       
    53 	{
       
    54 	delete iSchTestActive;
       
    55 	delete iSelection;
       
    56 	}
       
    57 
       
    58 EXPORT_C void CSchSendTestUtils::Panic(TInt aPanic)
       
    59 	{
       
    60 	User::Panic(_L("SchSend Test"), aPanic);
       
    61 	}
       
    62 
       
    63 EXPORT_C void CSchSendTestUtils::StartL()
       
    64 	{
       
    65 	TRAPD(err, RunAutoL());
       
    66 
       
    67 	if (err)
       
    68 		{
       
    69 		if (iCurrentTest)
       
    70 			{
       
    71 			TestFinish(iCurrentTest, err);
       
    72 			}
       
    73 
       
    74 		TestHarnessFailed(err);
       
    75 		}
       
    76 	else
       
    77 		{
       
    78 		TestHarnessCompleted();
       
    79 		}
       
    80 	}
       
    81 
       
    82 //Returns approximate difference (rounded down?) in minutes
       
    83 EXPORT_C TInt CSchSendTestUtils::DiffInMins(TTime d1, TTime d2)
       
    84 	{
       
    85 	iRTest<<d1<<d2;
       
    86 	TInt64 diffUs64 = d1.Int64() - d2.Int64();
       
    87 	TInt64 diffMins64 = diffUs64 / (1000000 * 60);
       
    88 	TInt diffMins32 = I64INT(diffMins64);
       
    89 	return diffMins32;
       
    90 	}
       
    91 
       
    92 //Returns approximate difference (rounded down?) in seconds
       
    93 EXPORT_C TInt CSchSendTestUtils::DiffInSecs(TTime d1, TTime d2)
       
    94 	{
       
    95 	iRTest<<d1<<d2;
       
    96 	TInt64 diffUs64 = d1.Int64() - d2.Int64();
       
    97 	TInt64 diffSecs64 = diffUs64 / (1000000);
       
    98 	TInt diffSecs32 = I64INT(diffSecs64);
       
    99 	return diffSecs32;
       
   100 	}
       
   101 
       
   102 EXPORT_C void CSchSendTestUtils::ChangeMessageTimeL(TMsvId aMessage, TTime aTime)
       
   103 	{
       
   104 	iMsvEntry->SetEntryL(aMessage);
       
   105 	TMsvEntry entry = iMsvEntry->Entry();
       
   106 	iRTest<<entry.iDate<<aTime;
       
   107 	entry.iDate = aTime;
       
   108 
       
   109 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   110 	wait->Start();
       
   111 	CMsvOperation*  opert = iMsvEntry->ChangeL(entry, wait->iStatus);
       
   112 	CleanupStack::PushL(opert);
       
   113 	CActiveScheduler::Start(); // operation complete
       
   114 	entry = iMsvEntry->Entry();
       
   115 	iRTest<<entry.iDate;
       
   116 
       
   117 	TMsvLocalOperationProgress details;
       
   118 	TPckgC<TMsvLocalOperationProgress> package(details);	
       
   119 	package.Set(opert->ProgressL());
       
   120 
       
   121 	if(wait->iStatus.Int()!=KErrNone)
       
   122 		User::Leave(wait->iStatus.Int());
       
   123 
       
   124 	//TInt err = package().iError;
       
   125 	//if(err != KErrNone);
       
   126 	//	User::Leave(package().iError);
       
   127 
       
   128 	CleanupStack::PopAndDestroy(2);//opert, wait
       
   129 	}
       
   130 
       
   131 EXPORT_C void CSchSendTestUtils::AssertL(TBool b)
       
   132 	{
       
   133 	if(!b)
       
   134 		{
       
   135 		User::Leave(KErrAbort);
       
   136 		}
       
   137 	}
       
   138 
       
   139 EXPORT_C TMsvId CSchSendTestUtils::CreateMessageLC(TMsvEntry& aEntry, TMsvId aDestFolder, TTime aSendTime, TBool aOffPeak)
       
   140 	{
       
   141 	//Make a TMsvEntry
       
   142 	iMsvEntry->SetEntryL(aDestFolder);
       
   143 	aEntry.iType = KUidMsvMessageEntry;
       
   144 	aEntry.iMtm = KSchSendTestMtmUid;
       
   145 	
       
   146 	aEntry.iServiceId = KMsvLocalServiceIndexEntryId;
       
   147 
       
   148 	aEntry.iDate = aSendTime;
       
   149 	aEntry.SetOffPeak(aOffPeak);
       
   150 
       
   151 	//Create the entry in the server
       
   152 
       
   153 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   154 	wait->Start();
       
   155 	CMsvOperation*  opert = iMsvEntry->CreateL(aEntry, wait->iStatus);
       
   156 	CleanupStack::PushL(opert);
       
   157 	CActiveScheduler::Start(); // operation complete
       
   158 
       
   159 	//Find out the ID of the entry we made
       
   160 	TMsvLocalOperationProgress details;
       
   161 	TPckgC<TMsvLocalOperationProgress> package(details);	
       
   162 	package.Set(opert->ProgressL());
       
   163 
       
   164 	if(wait->iStatus.Int()!=KErrNone)
       
   165 		User::Leave(wait->iStatus.Int());
       
   166 
       
   167 	if(package().iError!=KErrNone)
       
   168 		User::Leave(package().iError);
       
   169 	
       
   170 	*(TMsvId*)&aEntry = package().iId;
       
   171 	TMsvId testMsvId = aEntry.Id();
       
   172 
       
   173 	CleanupStack::PopAndDestroy(2);//opert, wait
       
   174 	iMsvSession->CleanupEntryPushL(testMsvId);
       
   175 
       
   176 	return testMsvId;
       
   177 	}
       
   178 
       
   179 EXPORT_C void CSchSendTestUtils::DisplayAllSchedulesL(TInt& rSchCount, TInt& rSchSize)
       
   180 	{
       
   181 	Printf(_L("Displaying all Schedules:\n"));
       
   182 	rSchCount = 0;
       
   183 	rSchSize = 0;
       
   184 
       
   185 	TParse parse;
       
   186 	TFileName fileName(_L("\\system\\schedules\\")); 
       
   187 	_LIT(KCDrive, "C:");
       
   188 	parse.Set(fileName, &KCDrive, NULL);
       
   189 
       
   190 	CDir* entryList;
       
   191 	TPtrC drive(parse.DriveAndPath());
       
   192 	TInt err = iFs.GetDir(drive, KEntryAttNormal, ESortNone, entryList);
       
   193 	
       
   194 	if (err)
       
   195 		{
       
   196 		Printf(_L("\tiFs.GetDir(%S) returned %d\n"), &drive, err);
       
   197 		return;
       
   198 		}
       
   199 
       
   200 	CleanupStack::PushL(entryList);
       
   201 	
       
   202 	TInt count = entryList->Count();
       
   203 
       
   204 	while (count--)
       
   205 		{
       
   206 		TEntry entry((*entryList)[count]);
       
   207 		rSchSize += entry.iSize;
       
   208 		}
       
   209 
       
   210 	Printf(_L("\tFiles in %S have total size %d\n"), &drive, rSchSize);
       
   211 
       
   212 	CleanupStack::PopAndDestroy(entryList);
       
   213 
       
   214 	RScheduler sch;
       
   215 	err = sch.Connect();
       
   216 
       
   217 	if (err)
       
   218 		{
       
   219 		Printf(_L("\tRScheduler::Connect() returned %d\n"), err);
       
   220 		return;
       
   221 		}
       
   222 	
       
   223 	CleanupClosePushL(sch);
       
   224 
       
   225 	IMPORT_C TInt GetScheduleL(const TInt aScheduleHandle, TScheduleState& aState, 
       
   226 			CArrayFixFlat<TScheduleEntryInfo>& aEntries, CArrayFixFlat<TTaskInfo>& aTasks, TTime& aDueTime);
       
   227 
       
   228 	CArrayFixFlat<TSchedulerItemRef>* schRefArray = new (ELeave) CArrayFixFlat<TSchedulerItemRef>(10);
       
   229 	CleanupStack::PushL(schRefArray);
       
   230 
       
   231 	CArrayFixFlat<TScheduleEntryInfo>* schEntries = new (ELeave) CArrayFixFlat<TScheduleEntryInfo>(10);
       
   232 	CleanupStack::PushL(schEntries);
       
   233 
       
   234 	CArrayFixFlat<TTaskInfo>* schTasks = new (ELeave) CArrayFixFlat<TTaskInfo>(10);
       
   235 	CleanupStack::PushL(schTasks);
       
   236 
       
   237 	err = sch.GetScheduleRefsL(*schRefArray, EAllSchedules);
       
   238 
       
   239 	if (!err)
       
   240 		{
       
   241 		TScheduleState schState;
       
   242 		TTime schDueTime;
       
   243 		count = schRefArray->Count();
       
   244 		rSchCount = count;
       
   245 		Printf(_L("\t%d schedules in the task scheduler\n"), count);
       
   246 
       
   247 		while (count--)
       
   248 			{
       
   249 			err = sch.GetScheduleL((*schRefArray)[count].iHandle, schState, *schEntries, *schTasks, schDueTime);
       
   250 
       
   251 			if (!err)
       
   252 				{
       
   253 				TInt taskCount = schTasks->Count();
       
   254 				Printf(_L("\tSchedule %d (\"%S\") has %d tasks\n"), (*schRefArray)[count].iHandle, &(*schRefArray)[count].iName, taskCount);
       
   255 
       
   256 				while (taskCount--)
       
   257 					{
       
   258 					TTaskInfo taskInfo((*schTasks)[taskCount]);
       
   259 					TInt size;
       
   260 					err = sch.GetTaskDataSize(taskInfo.iTaskId, size);
       
   261 
       
   262 					if (!err)
       
   263 						{
       
   264 						HBufC* hBuf = HBufC::NewLC(size);
       
   265 						TPtr ptr(hBuf->Des());
       
   266 						TSchedulerItemRef schRef;
       
   267 
       
   268 						err = sch.GetTaskInfoL(taskInfo.iTaskId, taskInfo, ptr, schRef, schDueTime);
       
   269 
       
   270 						if (!err)
       
   271 							{
       
   272 							TPckgBuf<TMsvSchedulePackage> mtmBuf;
       
   273 							mtmBuf.Copy(*hBuf);
       
   274 							Printf(_L("\t\tTask %d: msvId %d, commandId %d, pollProgress %d\n"), taskInfo.iTaskId, mtmBuf().iId, mtmBuf().iCommandId, mtmBuf().iPollProgress.Int());
       
   275 							}
       
   276 						else
       
   277 							{
       
   278 							Printf(_L("\t\tRScheduler::GetTaskInfoL(%d) returned %d\n"), taskInfo.iTaskId, err);
       
   279 							}
       
   280 
       
   281 						CleanupStack::PopAndDestroy(hBuf);
       
   282 						}
       
   283 					else
       
   284 						{
       
   285 						Printf(_L("\t\tRScheduler::GetTaskDataSize(%d) returned %d\n"), taskInfo.iTaskId, err);
       
   286 						}
       
   287 					}
       
   288 				}
       
   289 			else
       
   290 				{
       
   291 				Printf(_L("\tRScheduler::GetScheduleL(%d (\"%S\")) returned %d\n"), (*schRefArray)[count].iHandle, &(*schRefArray)[count].iName, err);
       
   292 				}
       
   293 			}
       
   294 		}
       
   295 	else
       
   296 		{
       
   297 		Printf(_L("RScheduler::GetScheduleRefsL() returned %d"), err);
       
   298 		}
       
   299 
       
   300 	CleanupStack::PopAndDestroy(3); //schRefArray, schEntries, schTasks
       
   301 	CleanupStack::PopAndDestroy(); //sch
       
   302 	}
       
   303 
       
   304 EXPORT_C void CSchSendTestUtils::CleanScheduleFolderL()
       
   305 	{
       
   306 	CFileMan* fileMan = CFileMan::NewL(iFs); 
       
   307 	CleanupStack::PushL(fileMan);
       
   308 	TParse parse;
       
   309 	TFileName fileName(_L("\\system\\schedules\\")); 
       
   310 	TBuf<4> drive=_L("C:");
       
   311 	parse.Set(fileName, &drive, NULL);
       
   312 	TInt error = fileMan->RmDir(parse.DriveAndPath()); 
       
   313 	error = iFs.RmDir(parse.DriveAndPath());
       
   314 	
       
   315 	if (!(error==KErrNotFound||error==KErrNone))
       
   316 		{
       
   317         TPtrC driveAndPath = parse.DriveAndPath();
       
   318 		Printf(_L("Directory %S cannot be removed. Error=%d"), &driveAndPath, error);
       
   319 		Printf(_L("Please ensure directory is not in use.\n"));
       
   320 		User::Leave(error);
       
   321 		}
       
   322 
       
   323 	iFs.MkDirAll(parse.DriveAndPath());
       
   324 
       
   325 	CleanupStack::PopAndDestroy(fileMan);
       
   326 	}
       
   327 
       
   328 EXPORT_C TBool CSchSendTestUtils::CompareRoundedTimes(const TTime& aLeft, const TTime& aRight) const
       
   329 	{
       
   330 	TBool ret = (aLeft == aRight);
       
   331 	ret = ret || (RoundUpToMinute(aLeft) == RoundUpToMinute(aRight));
       
   332 	ret = ret || (RoundDownToMinute(aLeft) == RoundDownToMinute(aRight));
       
   333 	return ret;
       
   334 	}
       
   335 
       
   336 
       
   337 EXPORT_C TTime CSchSendTestUtils::RoundUpToMinute(const TTime& aTime) const
       
   338 	{
       
   339 	TTime ret(aTime);
       
   340 	TDateTime dt(ret.DateTime());
       
   341 
       
   342 	if (dt.Second() != 0 || dt.MicroSecond() != 0)
       
   343 		{
       
   344 		dt.SetSecond(0);
       
   345 		dt.SetMicroSecond(0);
       
   346 		ret = dt;
       
   347 		ret += (TTimeIntervalMinutes) 1;
       
   348 		}
       
   349 
       
   350 	return ret;
       
   351 	}
       
   352 
       
   353 EXPORT_C TTime CSchSendTestUtils::RoundDownToMinute(const TTime& aTime) const
       
   354 	{
       
   355 	TTime ret(aTime);
       
   356 	TDateTime dt(ret.DateTime());
       
   357 
       
   358 	if (dt.Second() != 0 || dt.MicroSecond() != 0)
       
   359 		{
       
   360 		dt.SetSecond(0);
       
   361 		dt.SetMicroSecond(0);
       
   362 		ret = dt;
       
   363 		}
       
   364 
       
   365 	return ret;
       
   366 	}
       
   367 
       
   368 //
       
   369 //
       
   370 //
       
   371 
       
   372 CScheduleTestActive::CScheduleTestActive(CSchSendTestUtils& aTest, TInt aPriority)
       
   373 : CActive(aPriority), iTest(aTest), iSession(*aTest.iMsvSession)
       
   374 	{
       
   375 	CActiveScheduler::Add(this);
       
   376 	}
       
   377 
       
   378 EXPORT_C CScheduleTestActive* CScheduleTestActive::NewL(CSchSendTestUtils& aTest, TInt aPriority)
       
   379 	{
       
   380 	CScheduleTestActive* self = new (ELeave) CScheduleTestActive(aTest, aPriority);
       
   381 	CleanupStack::PushL(self);
       
   382 	self->iSession.AddObserverL(*self);
       
   383 	CleanupStack::Pop(self);
       
   384 	return self;
       
   385 	}
       
   386 
       
   387 EXPORT_C CScheduleTestActive::~CScheduleTestActive()
       
   388 	{
       
   389 	Cancel();
       
   390 	iSession.RemoveObserver(*this);
       
   391 	delete iSelection;
       
   392 	delete iOperation;
       
   393 	}
       
   394 
       
   395 //Set aStopAtRunL to true to stop the active scheduler. 
       
   396 //False will make us wait for someone else to stop it
       
   397 EXPORT_C const TSchSendTestProgress& CScheduleTestActive::TransferCommandSyncL(TSchSendTestOperation aCommand, const CMsvEntrySelection& aSelection, TBool aStopAtRunL)
       
   398 	{
       
   399 	return TransferCommandSyncL(aCommand, aSelection, _L8("aaaa"), aStopAtRunL);
       
   400 	}
       
   401 
       
   402 EXPORT_C const TSchSendTestProgress& CScheduleTestActive::TransferCommandSyncL(TSchSendTestOperation aCommand, const CMsvEntrySelection& aSelection, const TDesC8& aParameter, TBool aStopAtRunL)
       
   403 	{
       
   404 	iTest.Printf(_L("TransferCommandSyncL Command %d Count %d StopAtRunL %d\n"), aCommand, aSelection.Count(), aStopAtRunL);
       
   405 
       
   406 	if (IsActive())
       
   407 		User::Leave(KErrInUse);
       
   408 
       
   409 	delete iSelection;
       
   410 	iSelection = NULL;
       
   411 	iSelection = aSelection.CopyL();
       
   412 	iCommand = aCommand;
       
   413 	iStopAtRunL = aStopAtRunL;
       
   414 	iStatus = KRequestPending;
       
   415 	SetActive();
       
   416 
       
   417 	delete iOperation;
       
   418 	iOperation = NULL;
       
   419 	iOperation = iSession.TransferCommandL (*iSelection, 
       
   420 				aCommand,
       
   421 				aParameter, 
       
   422 				iStatus);
       
   423 
       
   424 	CActiveScheduler::Start(); // will not return from this until the command is transferred
       
   425 
       
   426 	iProgress.iError = iStatus.Int();
       
   427 	if(iStatus.Int()!=KErrNone)
       
   428 		User::Leave(iStatus.Int());
       
   429 
       
   430 	TPckgC<TSchSendTestProgress> pkg(iProgress);
       
   431 	pkg.Set(iOperation->ProgressL());
       
   432 	iProgress = pkg();
       
   433 	return iProgress;
       
   434 	}
       
   435 
       
   436 
       
   437 TInt CScheduleTestActive::RunError(TInt aError)
       
   438 	{
       
   439 	if (iProgress.iError == KErrNone)
       
   440 		iProgress.iError = aError;
       
   441 
       
   442 	CActiveScheduler::Stop();
       
   443 	return KErrNone;
       
   444 	}
       
   445 
       
   446 void CScheduleTestActive::RunL()
       
   447 	{
       
   448 	iTest.Printf(_L("CScheduleTestActive::RunL() iStatus %d\n"), iStatus.Int());
       
   449 	User::LeaveIfError(iStatus.Int());
       
   450 
       
   451 	if(iStopAtRunL) 
       
   452 		{
       
   453 		CActiveScheduler::Stop();
       
   454 		return;
       
   455 		}
       
   456 
       
   457 	switch (iCommand)
       
   458 		{
       
   459 		case EScheduleAllL:
       
   460 		case EReScheduleAllL:
       
   461 			{
       
   462 			TInt count = iSelection->Count();
       
   463 			TBool stopped = EFalse;
       
   464 			while (!stopped && count--)
       
   465 				{
       
   466 				CMsvEntry* entry = iSession.GetEntryL(iSelection->At(count));
       
   467 				CleanupStack::PushL(entry);
       
   468 				const TInt state = entry->Entry().SendingState();
       
   469 				switch(state)
       
   470 					{
       
   471 					case KMsvSendStateScheduled:
       
   472 					case KMsvSendStateResend:
       
   473 						break;
       
   474 					default: // The message sent or failed
       
   475 						stopped = ETrue;
       
   476 						CActiveScheduler::Stop();
       
   477 						break;
       
   478 					}
       
   479 				CleanupStack::PopAndDestroy(entry);
       
   480 				}
       
   481 		
       
   482 			break;
       
   483 			}
       
   484 		default:
       
   485 			CActiveScheduler::Stop(); //Added by AA 9/6/2000. Is this correct?
       
   486 			break;
       
   487 		}
       
   488 	}
       
   489 
       
   490 void CScheduleTestActive::HandleSessionEventL(TMsvSessionEvent eventType, TAny* p1, TAny*, TAny*)
       
   491 	{
       
   492 	if (iStopAtRunL) return;
       
   493 	if (eventType != EMsvEntriesCreated) return;
       
   494 
       
   495 	CMsvEntrySelection* entries = STATIC_CAST(CMsvEntrySelection*, p1);
       
   496 
       
   497 	CMsvEntry* cEntry = iSession.GetEntryL((*entries)[0]);
       
   498 	CleanupStack::PushL(cEntry);
       
   499 
       
   500 	TMsvEntry entry(cEntry->Entry());
       
   501 	
       
   502 	if(entry.iDetails == KSchSendTestDetails)
       
   503 		{
       
   504 		iTest.Printf(_L("Scheduled message has been sent\n"));
       
   505 
       
   506 		//We found the right message!
       
   507 		CActiveScheduler::Stop();
       
   508 
       
   509 		//Delete the new message
       
   510 		CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   511 		wait->Start();
       
   512 		cEntry->SetEntryL(entry.Parent());
       
   513 		CMsvOperation* op = cEntry->DeleteL(entry.Id(), wait->iStatus);
       
   514 		CActiveScheduler::Start();
       
   515 		delete op;
       
   516 		CleanupStack::PopAndDestroy(wait);
       
   517 		}
       
   518 
       
   519 	CleanupStack::PopAndDestroy(cEntry);
       
   520 	}
       
   521 
       
   522 
       
   523 //
       
   524 //
       
   525 //
       
   526 
       
   527 
       
   528 //
       
   529 //
       
   530 //
       
   531 
       
   532 EXPORT_C CSchSendTestTimer* CSchSendTestTimer::NewL(TInt aPriority)
       
   533     {
       
   534     CSchSendTestTimer* self = new (ELeave) CSchSendTestTimer(aPriority);
       
   535     CleanupStack::PushL(self);
       
   536     self->ConstructL();		// Inherited from CTimer.
       
   537     CleanupStack::Pop();
       
   538     return self;
       
   539     }
       
   540 
       
   541 CSchSendTestTimer::CSchSendTestTimer(TInt aPriority)
       
   542 : CTimer(aPriority)
       
   543 	{
       
   544     CActiveScheduler::Add(this);
       
   545 	}
       
   546 
       
   547 void CSchSendTestTimer::RunL()
       
   548     {
       
   549     CActiveScheduler::Stop();
       
   550     }
       
   551 
       
   552 EXPORT_C RTest& operator<<(RTest& aTest, TTime t)
       
   553 	{
       
   554 	TBuf<100> buf;
       
   555 	t.FormatL(buf, _L("%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%.%*C4%:3%+B\n"));
       
   556 	aTest.Printf(buf);
       
   557 	return aTest;
       
   558 	}
       
   559 
       
   560 EXPORT_C TBool operator==(const CMsvSendErrorActions& one, const CMsvSendErrorActions& two)
       
   561 	{
       
   562 	TMsvSendErrorAction action1 = one.Default();
       
   563 	TMsvSendErrorAction action2 = two.Default();
       
   564 	if(!(action1==action2)) return EFalse;
       
   565 
       
   566 	const CArrayFixFlat<TMsvSendErrorAction>& actionArray1 = one.Errors();
       
   567 	const CArrayFixFlat<TMsvSendErrorAction>& actionArray2 = two.Errors();
       
   568 
       
   569 	if(actionArray1.Count()!=actionArray2.Count()) return EFalse;
       
   570 	for(int i = 0; i < actionArray1.Count(); i++)
       
   571 		if(!(actionArray1[i]==actionArray2[i])) return EFalse;
       
   572 
       
   573 	return ETrue;
       
   574 
       
   575 	}
       
   576 
       
   577 EXPORT_C TBool operator==(const TMsvSchedulePackage& a1, const TMsvSchedulePackage& a2)
       
   578 	{
       
   579 	if (a1.iId				!= a2.iId) return EFalse;
       
   580 	if (a1.iCommandId		!= a2.iCommandId) return EFalse;
       
   581 	if (a1.iPollProgress	!= a2.iPollProgress) return EFalse;
       
   582 	if (a1.iParameter		!= a2.iParameter) return EFalse;
       
   583 	return ETrue;
       
   584 	}
       
   585 
       
   586 
       
   587 EXPORT_C TBool operator==(const TMsvSendErrorAction& a1, const TMsvSendErrorAction& a2)
       
   588 	{
       
   589 	if(a1.iAction			!= a2.iAction) return EFalse;
       
   590 	if(a1.iRetrySpacing		!= a2.iRetrySpacing) return EFalse;
       
   591 	if(a1.iError			!= a2.iError) return EFalse;
       
   592 	if(a1.MaxRetries()		!= a2.MaxRetries()) return EFalse;
       
   593 	if(a1.iRetries			!= a2.iRetries) return EFalse;
       
   594 	return ETrue;
       
   595 	}
       
   596 
       
   597 EXPORT_C TBool operator==(const TMsvOffPeakTime& time1, const TMsvOffPeakTime& time2)
       
   598 	{
       
   599 	if(time1.Day()!=time2.Day()) return EFalse;
       
   600 	if(time1.Hour()!=time2.Hour()) return EFalse;
       
   601 	if(time1.Minute()!=time2.Minute()) return EFalse;
       
   602 	if(time1.ValidityPeriod()!=time2.ValidityPeriod()) return EFalse;
       
   603 	return ETrue;
       
   604 	}
       
   605 
       
   606 EXPORT_C TBool StartsAt(const TMsvOffPeakTime& time1, const TTime& time2)
       
   607 	{
       
   608 	TDateTime dateTime2 = time2.DateTime();
       
   609 
       
   610 	if(time1.Day() != time2.DayNoInWeek()) return EFalse;
       
   611 	if(time1.Hour() != dateTime2.Hour()) return EFalse;
       
   612 	if(time1.Minute() != dateTime2.Minute()) return EFalse;
       
   613 	return ETrue;
       
   614 	}
       
   615 
       
   616 EXPORT_C TBool operator==(const CMsvScheduleSettings& aSettings1, const CMsvScheduleSettings& aSettings2)
       
   617 	{
       
   618 	if(aSettings1.Priority()!=aSettings2.Priority()) return EFalse;
       
   619 	if(aSettings1.ValidityPeriod()!=aSettings2.ValidityPeriod()) return EFalse;
       
   620 	if(aSettings1.IntervalType()!=aSettings2.IntervalType()) return EFalse;
       
   621 	if(aSettings1.LongInterval()!=aSettings2.LongInterval()) return EFalse;
       
   622 	if(aSettings1.ShortInterval()!=aSettings2.ShortInterval()) return EFalse;
       
   623 	if(aSettings1.VariableIntervals().Count()!=aSettings2.VariableIntervals().Count()) return EFalse;
       
   624 	for(int i = 0; i < aSettings1.VariableIntervals().Count(); i++)
       
   625 		{
       
   626 		if(aSettings1.VariableIntervals()[i]!=aSettings2.VariableIntervals()[i])
       
   627 			return EFalse;
       
   628 		}
       
   629 	if(aSettings1.Latency()!=aSettings2.Latency()) return EFalse;
       
   630 	return ETrue;
       
   631 	}
       
   632 
       
   633 
       
   634 //
       
   635 
       
   636 EXPORT_C CSchSendTestWaitForState* CSchSendTestWaitForState::NewL(CSchSendTestUtils& aTest)
       
   637 	{
       
   638 	CSchSendTestWaitForState* self = new (ELeave) CSchSendTestWaitForState(aTest);
       
   639 	CleanupStack::PushL(self);
       
   640 	User::LeaveIfError(self->iTimer.CreateLocal());
       
   641 	aTest.iMsvSession->AddObserverL(*self);
       
   642 	CleanupStack::Pop(self);
       
   643 	return self;
       
   644 	}
       
   645 
       
   646 EXPORT_C CSchSendTestWaitForState::~CSchSendTestWaitForState()
       
   647 	{
       
   648 	Reset();
       
   649 	iTimer.Close();
       
   650 	iTest.iMsvSession->RemoveObserver(*this);
       
   651 	}
       
   652 
       
   653 void CSchSendTestWaitForState::DoStartL(const CMsvEntrySelection& aSelection, TTimeIntervalMicroSeconds32 aAfter, TBool aWaitForever)
       
   654 	{
       
   655 	iTest(iSendingStates.Count() != 0);
       
   656 
       
   657 	iAfter = aAfter;
       
   658 	iWaitForever = aWaitForever;
       
   659 
       
   660 	delete iSelection;
       
   661 	iSelection = NULL;
       
   662 	iSelection = aSelection.CopyL();
       
   663 
       
   664 	iTimer.After(iStatus, iAfter);
       
   665 	SetActive();
       
   666 
       
   667 	CActiveScheduler::Start();
       
   668 	}
       
   669 
       
   670 EXPORT_C void CSchSendTestWaitForState::StartL(const CMsvEntrySelection& aSelection)
       
   671 	{
       
   672 	DoStartL(aSelection, KSchSendTestWaitForStateDefault, ETrue);
       
   673 	}
       
   674 
       
   675 EXPORT_C void CSchSendTestWaitForState::StartL(const CMsvEntrySelection& aSelection, TTimeIntervalMicroSeconds32 aAfter)
       
   676 	{
       
   677 	DoStartL(aSelection, aAfter, EFalse);
       
   678 	}
       
   679 
       
   680 
       
   681 CSchSendTestWaitForState::CSchSendTestWaitForState(CSchSendTestUtils& aTest)
       
   682 : CActive(CActive::EPriorityStandard), iTest(aTest), iAfter(KSchSendTestWaitForStateDefault)
       
   683 	{
       
   684 	CActiveScheduler::Add(this);
       
   685 	}
       
   686 
       
   687 void CSchSendTestWaitForState::RunL()
       
   688 	{
       
   689 	User::LeaveIfError(iStatus.Int());
       
   690 
       
   691 	TInt count = iSelection->Count();
       
   692 	TBool stop = ETrue;
       
   693 	while (count--)
       
   694 		{
       
   695 		const TMsvId id = (*iSelection)[count];
       
   696 		stop = stop && CheckStateL(id);
       
   697 		}
       
   698 
       
   699 	if (stop || !iWaitForever)
       
   700 		{
       
   701 		if (!stop)
       
   702 			iStatus = KErrGeneral;
       
   703 
       
   704 		CActiveScheduler::Stop();
       
   705 		}
       
   706 	}
       
   707 
       
   708 TBool CSchSendTestWaitForState::CheckStateL(TMsvId aId)
       
   709 	{
       
   710 	iTest.SetEntryL(aId);
       
   711 	iTest.SetEntryL(iTest.Entry().Parent());
       
   712 	iTest.SetEntryL(aId);
       
   713 
       
   714 	const TInt sendingState = iTest.Entry().SendingState();
       
   715 	TInt count = iSendingStates.Count();
       
   716 	while (count--)
       
   717 		{
       
   718 		if (sendingState == iSendingStates[count])
       
   719 			return ETrue;
       
   720 		}
       
   721 
       
   722 	return EFalse;
       
   723 	}
       
   724 
       
   725 TInt CSchSendTestWaitForState::RunError(TInt aError)
       
   726 	{
       
   727 	if (iStatus.Int() == KErrNone)
       
   728 		iStatus = aError;
       
   729 
       
   730 	CActiveScheduler::Stop();
       
   731 	return KErrNone;
       
   732 	}
       
   733 
       
   734 void CSchSendTestWaitForState::DoCancel()
       
   735 	{
       
   736 	iTimer.Cancel();
       
   737 	}
       
   738 
       
   739 EXPORT_C void CSchSendTestWaitForState::Reset()
       
   740 	{
       
   741 	Cancel();
       
   742 	delete iSelection;
       
   743 	iSelection = NULL;
       
   744 	iSendingStates.Reset();
       
   745 	}
       
   746 
       
   747 void CSchSendTestWaitForState::HandleSessionEventL(TMsvSessionEvent aEvent, TAny*, TAny*, TAny*)
       
   748 	{
       
   749 	iTest.Printf(_L("CSchSendTestWaitForState::HandleSessionEventL [Event=%d IsActive=%d Count=%d]\n"), aEvent, IsActive(), iSelection->Count());
       
   750 	if ((aEvent != EMsvEntriesChanged && aEvent != EMsvEntriesCreated) || !IsActive() || iSelection->Count() == 0)
       
   751 		return;
       
   752 
       
   753 	TInt count = iSelection->Count();
       
   754 
       
   755 	while (count--)
       
   756 		{
       
   757 		const TMsvId id = iSelection->At(count);
       
   758 		if (CheckStateL(id))
       
   759 			iSelection->Delete(count);
       
   760 		}
       
   761 
       
   762 	if (iSelection->Count() == 0)
       
   763 		{
       
   764 		Cancel();
       
   765 		TRequestStatus* status = &iStatus;
       
   766 		User::RequestComplete(status, KErrNone);
       
   767 		SetActive();
       
   768 		}
       
   769 	}