messagingfw/scheduledsendmtm/test/unit/src/t_schsend.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_schsend.h"
       
    17 
       
    18 #include <msvschedulesend.h>
       
    19 #include <bautils.h>
       
    20 #include <smss.rsg>
       
    21 #include <msvschedulesettings.h>
       
    22 #include <msvsysagentaction.h>
       
    23 #include <barsc.h>
       
    24 #include <msvoffpeaktime.h>
       
    25 #include <csmsaccount.h>
       
    26 
       
    27 RTest& operator<<(RTest& aTest, TTime t);
       
    28 
       
    29 CTrapCleanup* theCleanup;
       
    30 //_LIT(KSmsResourceFile, "z:\\System\\Data\\SMSS.RSC");
       
    31 
       
    32 //Horrible hack because nmake thinks &myFun is illegal but GCC needs the & sign
       
    33 
       
    34 #ifdef __WINS__
       
    35 #define PFUN
       
    36 #else
       
    37 #define PFUN &
       
    38 #endif
       
    39 
       
    40 void doMainL(RTest& aTest)
       
    41 	{
       
    42 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
    43 	CleanupStack::PushL(scheduler);
       
    44 	CActiveScheduler::Install( scheduler );
       
    45 
       
    46 	CSchSendTest* schSendTest = CSchSendTest::NewL(aTest);
       
    47 	CleanupStack::PushL(schSendTest);
       
    48 
       
    49 	schSendTest->StartL();
       
    50 
       
    51 	CleanupStack::PopAndDestroy(2); //schSendTest, iScheduler
       
    52 
       
    53 	aTest.Printf(_L("\nWaiting 3 seconds before closing...\n"));
       
    54 	User::After(3000000);
       
    55 	}
       
    56 
       
    57 GLDEF_C TInt E32Main()
       
    58 	{
       
    59 	RTest test(_L("Scheduled Sending Test Harness"));
       
    60 	__UHEAP_MARK;
       
    61 	test.Title();
       
    62 	test.Start(_L("Scheduled Sending Test Harness"));
       
    63 	theCleanup = CTrapCleanup::New();
       
    64 	test(theCleanup !=NULL);
       
    65 	TRAPD(error,doMainL(test));
       
    66 	test(error==KErrNone);
       
    67 	delete theCleanup;
       
    68 	test.Printf(_L("Completed with return code %d"),error);
       
    69 	test.End();
       
    70 	test.Close();
       
    71 	__UHEAP_MARKEND;
       
    72 	return KErrNone;
       
    73 	}
       
    74 
       
    75 CSchSendTest* CSchSendTest::NewL(RTest& aTest)
       
    76 	{
       
    77 	CSchSendTest* self = new (ELeave) CSchSendTest(aTest);
       
    78 	CleanupStack::PushL(self);
       
    79 	self->ConstructL();
       
    80 	CleanupStack::Pop(); //self
       
    81 	return self;
       
    82 	}
       
    83 
       
    84 CSchSendTest::CSchSendTest(RTest& aTest)
       
    85 : CSchSendTestUtils(aTest)
       
    86 	{
       
    87 	}
       
    88 
       
    89 void CSchSendTest::TestPackageL()
       
    90 	{
       
    91 	TMsvSchedulePackage pkg;
       
    92 	pkg.iCommandId = 100000;
       
    93 	pkg.iId = 123456;
       
    94 
       
    95 	TestPackageL(pkg);
       
    96 
       
    97 	pkg.iCommandId = 20000;
       
    98 	pkg.iPollProgress = 1000000;
       
    99 
       
   100 	TestPackageL(pkg);
       
   101 
       
   102 	pkg.iParameter.Append(_L8("Hello"));
       
   103 
       
   104 	TestPackageL(pkg);
       
   105 
       
   106 	pkg.iParameter.Fill('a');
       
   107 
       
   108 	TestPackageL(pkg);
       
   109 	}
       
   110 
       
   111 void CSchSendTest::TestPackageL(const TMsvSchedulePackage& aPackage)
       
   112 	{
       
   113 	TTaskInfo info;
       
   114 	TMsvSchedulePackage pkg;
       
   115 	HBufC* buf = NULL;
       
   116 
       
   117 	aPackage.PackLC(info, buf);
       
   118 	pkg.UnpackL(info, *buf);
       
   119 	AssertL(aPackage == pkg);
       
   120 	CleanupStack::PopAndDestroy(buf);
       
   121 	}
       
   122 
       
   123 void CSchSendTest::RunAutoL()
       
   124 	{
       
   125 	// Two groups of tests
       
   126 	TestSendErrorActionsL();
       
   127 	TestOffPeakTimesL();
       
   128 
       
   129 	// Individual tests
       
   130 
       
   131 	AssertL(DoTest(PFUN CSchSendTest::TestPackageL, _L("Schedule Package")));
       
   132 	AssertL(DoTest(PFUN TestSysAgentActionsL, _L("Sys Agent Actions")));
       
   133 	AssertL(DoTest(PFUN TestScheduleSettingsL, _L("Schedule Settings")));
       
   134 	AssertL(DoTest(PFUN TestSchedulingMessagesL, _L("Scheduling Messages")));
       
   135 	AssertL(DoTest(PFUN TestSchedulingOldMessagesL, _L("Scheduling Old Messages")));
       
   136 	AssertL(DoTest(PFUN TestSchedulingMessagesTwiceL, _L("Scheduling Messages Twice")));
       
   137 	AssertL(DoTest(PFUN TestReschedulingMessagesL, _L("ReScheduling Messages")));
       
   138 	AssertL(DoTest(PFUN TestReschedulingNonScheduledMessagesL, _L("ReScheduling Non Scheduled Messages")));
       
   139 	AssertL(DoTest(PFUN TestDeletingMessagesL, _L("Deleting Messages")));
       
   140 	AssertL(DoTest(PFUN TestDeletingNonScheduledMessagesL, _L("Deleting Non Scheduled Messages")));
       
   141 
       
   142 	AssertL(DoTest(PFUN TestSchedulingOffPeakMessagesL, _L("Off Peak Messages")));
       
   143 
       
   144 	//AssertL(DoTest(PFUN TestCheckScheduleL, _L("CheckScheduleL")));
       
   145 
       
   146 	AssertL(HeapTest(PFUN TestSysAgentActionsL, _L("Sys Agent Actions")));
       
   147 	AssertL(HeapTest(PFUN TestSchedulingMessagesL, _L("Scheduling Messages")));
       
   148 	AssertL(HeapTest(PFUN TestSchedulingOffPeakMessagesL, _L("Off Peak Messages")));
       
   149 	AssertL(HeapTest(PFUN TestSchedulingOldMessagesL, _L("Scheduling Old Messages")));
       
   150 	AssertL(HeapTest(PFUN TestSchedulingMessagesTwiceL, _L("Scheduling Messages Twice")));
       
   151 	AssertL(HeapTest(PFUN TestReschedulingMessagesL, _L("ReScheduling Messages")));
       
   152 	AssertL(HeapTest(PFUN TestReschedulingNonScheduledMessagesL, _L("ReScheduling Non Scheduled Messages")));
       
   153 	AssertL(HeapTest(PFUN TestDeletingMessagesL, _L("Deleting Messages")));
       
   154 	AssertL(HeapTest(PFUN TestDeletingNonScheduledMessagesL, _L("Deleting Non Scheduled Messages")));
       
   155 
       
   156 	}
       
   157 
       
   158 
       
   159 void CSchSendTest::TestSendErrorActionsL()
       
   160 	{
       
   161 /*
       
   162 	Public functions of TMsvSendErrorAction:
       
   163 
       
   164 	Tested	Function
       
   165 	-------	---------------------------------------------------------------------
       
   166 	Yes		TMsvSendErrorAction();
       
   167 	Yes		void InternalizeL(RReadStream& aReadStream);
       
   168 	Yes		void ExternalizeL(RWriRTestream& aWriRTestream) const;
       
   169 	Yes		void Reset();
       
   170 	Yes		void SetMaxRetries(const TInt16 aMaxRetries);
       
   171 	Yes		TInt16 MaxRetries() const;
       
   172 
       
   173 	Public functions of CMsvSendErrorActions:
       
   174 
       
   175 	Tested	Function
       
   176 	-------	---------------------------------------------------------------------
       
   177 	Yes		static CMsvSendErrorActions* NewL();
       
   178 	Yes		void AddSendErrorActionL(const TMsvSendErrorAction& aAction);
       
   179 	Yes		const TInt RemoveSendErrorAction(const TInt aError);
       
   180 	Yes		const TInt GetSendErrorAction(const TInt aError, TMsvSendErrorAction& aAction) const;
       
   181 	Yes		void StoreL(CMsvStore& aStore) const;
       
   182 	Yes		void RestoreL(CMsvStore& aStore);
       
   183 			void RestoreFromResourceL(TResourceReader& aReader);
       
   184 	Yes		void SetErrorsL(const CArrayFixFlat<TMsvSendErrorAction>& aActions);
       
   185 	// but broken
       
   186 	Yes		const CArrayFixFlat<TMsvSendErrorAction>& Errors() const;
       
   187 	Yes		const TMsvSendErrorAction& Default() const;
       
   188 	Yes		void SetDefault(const TMsvSendErrorAction& aAction);
       
   189  
       
   190 */
       
   191 
       
   192 	AssertL(DoTest(PFUN TestSendErrorActions1L, _L("TestSendErrorActions1")));
       
   193 	AssertL(DoTest(PFUN TestDefaultL, _L("TestDefault")));
       
   194 	AssertL(DoTest(PFUN TestSendErrorActions3L, _L("TestSendErrorActions3")));
       
   195 	AssertL(DoTest(PFUN TestErrorsL, _L("TestErrors")));
       
   196 	AssertL(DoTest(PFUN TestStoringL, _L("TestStoring")));
       
   197 	AssertL(DoTest(PFUN TestRemovingL, _L("TestRemoving")));
       
   198 	//AssertL(DoTest(PFUN TestSendErrorActions4L, _L("TestSendErrorActions4")));
       
   199 
       
   200 	}
       
   201 
       
   202 void CSchSendTest::TestOffPeakTimesL()
       
   203 	{
       
   204 /*
       
   205 	Public functions of TMsvOffPeakTime:
       
   206 
       
   207 	Tested	Function
       
   208 	-------	---------------------------------------------------------------------
       
   209 	Yes		TMsvOffPeakTime();
       
   210 	Yes		TMsvOffPeakTime(const TDay aDay, const TInt aHour, const TInt aMinute, const TTimeIntervalMinutes aValidityPeriod);
       
   211 	Yes		void ExternalizeL (RWriRTestream &) const;
       
   212     Yes		void InternalizeL (RReadStream &);
       
   213 	Yes		void Reset();
       
   214 	Yes		const TDay Day() const;
       
   215 	Yes		void SetDay(const TDay aDay);
       
   216 	Yes		const TInt Hour() const;
       
   217 	Yes		void SetHour(const TInt aHour);
       
   218 	Yes		const TInt Minute() const;
       
   219 	Yes		void SetMinute(const TInt aMinute);
       
   220 	Yes		const TTimeIntervalMinutes ValidityPeriod() const;
       
   221 	Yes		void SetValidityPeriod(const TTimeIntervalMinutes aValidityPeriod);
       
   222 	Yes		const TTime NextTimeInclusive(const TTime& aFromTime) const;
       
   223 
       
   224 	
       
   225 	Public functions of CMsvOffPeakTimes:
       
   226 
       
   227 	Tested	Function
       
   228 	-------	---------------------------------------------------------------------
       
   229 	Yes		CMsvOffPeakTimes();
       
   230 	Yes		void StoreL(CMsvStore& aStore) const;
       
   231 	Yes		void RestoreL(CMsvStore& aStore);
       
   232 			const TInt GetNextOffPeakTime(const TTime& aFromTime, TMsvOffPeakTime& aNext, TTime& aNextTime) const;
       
   233 	// This last one tested by TestReschedulingMessagesL()
       
   234 */
       
   235 
       
   236 	AssertL(DoTest(PFUN TestOffPeakTimes1L, _L("TestOffPeakTimes1L")));
       
   237 	AssertL(DoTest(PFUN TestOffPeakTimes3L, _L("TestOffPeakTimes3L")));
       
   238 
       
   239 	}
       
   240 
       
   241 void CSchSendTest::TestSendErrorActions1L()
       
   242 	{
       
   243 // --- Testing TMsvSendErrorAction ---
       
   244 
       
   245 	iRTest.Next(_L("TestSendErrorActions1L()"));
       
   246 
       
   247 	TMsvSendErrorAction action1, action2;
       
   248 
       
   249 	action1.iAction			= ESendActionRetryLater;
       
   250 	action1.iRetries		= ESendRetriesFixed;
       
   251 	action1.iRetrySpacing	= ESendRetrySpacingStatic;
       
   252 	action1.iError			= KErrNotFound;
       
   253 	action1.SetMaxRetries(10);
       
   254 	
       
   255 	action2 = action1;
       
   256 
       
   257 	AssertL(action1==action2);
       
   258 
       
   259 	action1.SetMaxRetries(1);
       
   260 	AssertL(action1.MaxRetries() == 1);
       
   261 
       
   262 	action1.SetMaxRetries(200);
       
   263 	AssertL(action1.MaxRetries() == 200);
       
   264 
       
   265 	action1.Reset();
       
   266 	TMsvSendErrorAction action3;
       
   267 
       
   268 	AssertL(action1==action3);
       
   269 	}
       
   270 
       
   271 
       
   272 void CSchSendTest::TestSendErrorActions3L()
       
   273 	{
       
   274 	TMsvSendErrorAction action1, action2;
       
   275 	action1.iAction			= ESendActionRetryLater;
       
   276 	action1.iRetries		= ESendRetriesFixed;
       
   277 	action1.iRetrySpacing	= ESendRetrySpacingStatic;
       
   278 	action1.iError			= KErrNotFound;
       
   279 	action1.SetMaxRetries(10);
       
   280 	action1.Reset();
       
   281 	AssertL(action1==action2);
       
   282 	}
       
   283 
       
   284 void CSchSendTest::TestDefaultL()
       
   285 	{
       
   286 
       
   287 	CMsvSendErrorActions* actions = CMsvSendErrorActions::NewL();
       
   288 	CleanupStack::PushL(actions);
       
   289 
       
   290 	TMsvSendErrorAction action1, action2;
       
   291 
       
   292 	action1.iAction			= ESendActionRetryLater;
       
   293 	action1.iRetries		= ESendRetriesFixed;
       
   294 	action1.iRetrySpacing	= ESendRetrySpacingStatic;
       
   295 	action1.iError			= KErrNotFound;
       
   296 	action1.SetMaxRetries(10);
       
   297 	
       
   298 	actions->SetDefault(action1);
       
   299 	action2 = actions->Default();
       
   300 
       
   301 	AssertL(action2 == action1);
       
   302 
       
   303 	CleanupStack::PopAndDestroy(); // actions
       
   304 	
       
   305 	}
       
   306 
       
   307 void CSchSendTest::TestSendErrorActions5L()
       
   308 	{
       
   309 
       
   310 	CMsvSendErrorActions* actions = CMsvSendErrorActions::NewL();
       
   311 	CleanupStack::PushL(actions);
       
   312 
       
   313 	TMsvSendErrorAction action1, action2, action3;
       
   314 
       
   315 	action1.iError = KErrGeneral;
       
   316 	action2.iError = KErrNotSupported;
       
   317 
       
   318 	actions->AddSendErrorActionL(action1);
       
   319 	actions->AddSendErrorActionL(action2);
       
   320 
       
   321 	TInt error = actions->GetSendErrorAction(KErrNotSupported, action3);
       
   322 
       
   323 	AssertL(error == KErrNone);
       
   324 	AssertL(action3 == action2);
       
   325 	
       
   326 	error = actions->GetSendErrorAction(KErrGeneral, action3);
       
   327 	
       
   328 	AssertL(action3 == action1);
       
   329 	
       
   330 	error = actions->GetSendErrorAction(KErrNotFound, action3);
       
   331 	AssertL(error == KErrNotFound);
       
   332 
       
   333 	CleanupStack::PopAndDestroy(); // actions
       
   334 	}
       
   335 
       
   336 void CSchSendTest::TestErrorsL()
       
   337 	{
       
   338 	CMsvSendErrorActions* actions = CMsvSendErrorActions::NewL();
       
   339 	CleanupStack::PushL(actions);
       
   340 
       
   341 	CArrayFixFlat<TMsvSendErrorAction>* actionArray1 = new (ELeave) CArrayFixFlat<TMsvSendErrorAction>(20);
       
   342 	CleanupStack::PushL(actionArray1);
       
   343 	TMsvSendErrorAction test1, test2;
       
   344 	test1.iError = KErrAbort;
       
   345 	test2.iError = KErrTooBig;
       
   346 
       
   347 	TInt offSet = _FOFF(TMsvSendErrorAction, iError);
       
   348 	TKeyArrayFix key(offSet, ECmpTInt);
       
   349 
       
   350 	actionArray1->InsertIsqL(test1, key);
       
   351 	actionArray1->InsertIsqL(test2, key);
       
   352 
       
   353 	actions->SetErrorsL(*actionArray1);
       
   354 	const CArrayFixFlat<TMsvSendErrorAction>& actionArray2 = actions->Errors();
       
   355 
       
   356 	AssertL(actionArray1->Count()==actionArray2.Count());
       
   357 	for(int i = 0; i < actionArray1->Count(); i++)
       
   358 		{
       
   359 		// VC can't find my operator== if I do this the obvious one-line way
       
   360 		TMsvSendErrorAction one = (*actionArray1)[i];
       
   361 		TMsvSendErrorAction two = actionArray2[i];
       
   362 		AssertL(one==two);
       
   363 		}
       
   364 	CleanupStack::PopAndDestroy(2); // actions, actionArray1
       
   365 	}
       
   366 
       
   367 void CSchSendTest::TestStoringL()
       
   368 	{
       
   369 	CMsvSendErrorActions* actions = CMsvSendErrorActions::NewL();
       
   370 	CleanupStack::PushL(actions);
       
   371 
       
   372 	CMsvSendErrorActions* actions2 = CMsvSendErrorActions::NewL();
       
   373 	CleanupStack::PushL(actions2);
       
   374 
       
   375 	// access sms account settings
       
   376 	CSmsAccount* account = CSmsAccount::NewLC();
       
   377 
       
   378 	CMsvScheduleSettings* scheduleSettings = CMsvScheduleSettings::NewL();
       
   379 	CleanupStack::PushL(scheduleSettings);
       
   380 	CMsvOffPeakTimes* offPeakTimes = new(ELeave) CMsvOffPeakTimes;
       
   381 	CleanupStack::PushL(offPeakTimes);
       
   382 	CMsvSendErrorActions* errorActions = CMsvSendErrorActions::NewL();
       
   383 	CleanupStack::PushL(errorActions);
       
   384 	CMsvSysAgentActions* sysAgentActions = new (ELeave) CMsvSysAgentActions();
       
   385 	CleanupStack::PushL(sysAgentActions);
       
   386 
       
   387 	// read existing settings
       
   388 	TRAPD(ignor, account->LoadSettingsL(*scheduleSettings, *offPeakTimes, *errorActions, *sysAgentActions));
       
   389 
       
   390 	// write
       
   391 	account->SaveSettingsL(*scheduleSettings, *offPeakTimes, *actions, *sysAgentActions);
       
   392 
       
   393 	// read 
       
   394 	account->LoadSettingsL(*scheduleSettings, *offPeakTimes, *actions2, *sysAgentActions);
       
   395 
       
   396 	// restore settings	
       
   397 	account->SaveSettingsL(*scheduleSettings, *offPeakTimes, *errorActions, *sysAgentActions);
       
   398 	CleanupStack::PopAndDestroy(4, scheduleSettings); // sysAgentActions, errorActions, offPeakTimes, scheduleSettings 
       
   399 
       
   400 	AssertL(*actions==*actions2);
       
   401 	
       
   402 	CleanupStack::PopAndDestroy(3); //actions, actions2, entry/account
       
   403 	}
       
   404 
       
   405 void CSchSendTest::TestRemovingL()
       
   406 	{
       
   407 	TMsvSendErrorAction a1, a2, a3;
       
   408 	a1.iError = -3;
       
   409 	a2.iError = -4;
       
   410 	a3.iError = -5;
       
   411 	CMsvSendErrorActions* actions1 = CMsvSendErrorActions::NewL();
       
   412 	CleanupStack::PushL(actions1);
       
   413 	CMsvSendErrorActions* actions2 = CMsvSendErrorActions::NewL();
       
   414 	CleanupStack::PushL(actions2);
       
   415 
       
   416 	actions1->AddSendErrorActionL(a1);
       
   417 	actions1->AddSendErrorActionL(a2);
       
   418 	actions1->AddSendErrorActionL(a3);
       
   419 
       
   420 	actions2->AddSendErrorActionL(a1);
       
   421 	actions2->AddSendErrorActionL(a3);
       
   422 
       
   423 	actions1->RemoveSendErrorAction(-4);
       
   424 
       
   425 	AssertL(*actions1==*actions2);
       
   426 
       
   427 	CleanupStack::PopAndDestroy(2); //actions1 and 2
       
   428 	}
       
   429 
       
   430 /*void CSchSendTest::TestSendErrorActions4L()
       
   431 	{
       
   432 // --- Reading CMsvSendErrorActions from a resource file ---
       
   433 
       
   434 	iRTest.Next(_L("TestSendErrorActions4L"));
       
   435 
       
   436 	CMsvSendErrorActions* actions = CMsvSendErrorActions::NewL();
       
   437 	CleanupStack::PushL(actions);
       
   438 
       
   439 	TFileName fileName;
       
   440 	TParse parse;
       
   441     parse.Set(KSmsResourceFile, &fileName, 0);
       
   442 	fileName=parse.FullName();
       
   443 	BaflUtils::NearestLanguageFile(iFs, fileName);
       
   444 	RResourceFile iResourceFile;
       
   445 	iResourceFile.OpenL(iFs, fileName);
       
   446 
       
   447 	TResourceReader reader;
       
   448 	HBufC8* rBuf = iResourceFile.AllocReadLC(ERROR_ACTIONS);
       
   449 	reader.SetBuffer(rBuf);
       
   450 
       
   451 	actions->RestoreFromResourceL(reader);
       
   452 
       
   453 	iResourceFile.Close();
       
   454 	CleanupStack::PopAndDestroy(2); //actions, rBuf
       
   455 	} */
       
   456 
       
   457 
       
   458 
       
   459 void CSchSendTest::TestOffPeakTimes1L()
       
   460 	{
       
   461 	iRTest.Next(_L("TestOffPeakTimes1L"));
       
   462 
       
   463 
       
   464 	//Make an off peak time
       
   465 	TInt hour = 10;
       
   466 	TInt min = 10;
       
   467 	TDay day = EMonday;
       
   468 	TTimeIntervalMinutes valPrd = 5*60;
       
   469 
       
   470 	TMsvOffPeakTime offPeak;
       
   471 	offPeak.SetHour(hour);
       
   472 	offPeak.SetMinute(min);
       
   473 	offPeak.SetDay(day);
       
   474 //	offPeak.SetValidityPeriod(-1);  PASSED OK
       
   475 	offPeak.SetValidityPeriod(valPrd);
       
   476 
       
   477 	//Check that it worked
       
   478 	AssertL(offPeak.Hour() == hour);
       
   479 	AssertL(offPeak.Minute() == min);
       
   480 	AssertL(offPeak.Day() == day);
       
   481 	AssertL(offPeak.ValidityPeriod() == valPrd);
       
   482 
       
   483 	
       
   484 	TTime now;
       
   485 	now.HomeTime();
       
   486 	TTime nextTime = now;
       
   487 	nextTime = offPeak.NextTimeInclusive(now);
       
   488 
       
   489 	TBuf<30> dateString;
       
   490 	now.FormatL(dateString,(_L("%D%M%Y%/0%1%/1%2%/2%3%/3  %-B%:0%J%:1%T%:2%S%.%*C4%:3%+B")));
       
   491     Printf(_L("Now: "));
       
   492 	Printf(dateString);
       
   493 	Printf(_L("\n"));
       
   494 
       
   495 	nextTime.FormatL(dateString,(_L("%D%M%Y%/0%1%/1%2%/2%3%/3  %-B%:0%J%:1%T%:2%S%.%*C4%:3%+B")));
       
   496     Printf(_L("Next Time: "));
       
   497 	Printf(dateString);
       
   498 	Printf(_L("\n"));
       
   499 
       
   500 	AssertL(StartsAt(offPeak, nextTime));
       
   501 
       
   502 	TTime fourHoursAgo = now - (TTimeIntervalHours) 4;
       
   503 	TDateTime dtFourHoursAgo = fourHoursAgo.DateTime();
       
   504 
       
   505 	hour = dtFourHoursAgo.Hour();
       
   506 	min  = dtFourHoursAgo.Minute();
       
   507 	day = fourHoursAgo.DayNoInWeek();
       
   508 	valPrd = 8*60;  // valid for eight hours
       
   509 	
       
   510 	TMsvOffPeakTime nowIsOffPeak(day, hour, min, valPrd);
       
   511 	nextTime = nowIsOffPeak.NextTimeInclusive(now);
       
   512 
       
   513     Printf(_L("Now: "));
       
   514 	iRTest<<now;
       
   515     Printf(_L("\nFour Hours Ago: "));
       
   516 	iRTest<<fourHoursAgo;
       
   517 	Printf(_L("\nNext Time: "));
       
   518 	iRTest<<nextTime;
       
   519 
       
   520 	AssertL(nextTime < now);
       
   521 	AssertL(StartsAt(nowIsOffPeak, fourHoursAgo));
       
   522 	}
       
   523 
       
   524 
       
   525 void CSchSendTest::TestOffPeakTimes3L()
       
   526 	{
       
   527 	iRTest.Next(_L("TestOffPeakTimes3L"));
       
   528 
       
   529 	CMsvOffPeakTimes* offPeakTimes1 = new (ELeave) CMsvOffPeakTimes();
       
   530 	CleanupStack::PushL(offPeakTimes1);
       
   531 	CMsvOffPeakTimes* offPeakTimes2 = new (ELeave) CMsvOffPeakTimes();
       
   532 	CleanupStack::PushL(offPeakTimes2);
       
   533 
       
   534 	TMsvOffPeakTime offPeak1, offPeak2;
       
   535 
       
   536 	offPeakTimes1->AppendL(offPeak1);
       
   537 
       
   538 	offPeak2.SetDay(EWednesday);
       
   539 	offPeak2.SetHour(20);
       
   540 	offPeak2.SetMinute(30);
       
   541 	offPeak2.SetValidityPeriod(10);
       
   542 
       
   543 	offPeakTimes1->AppendL(offPeak2);
       
   544 
       
   545 	// access sms account settings
       
   546 	CSmsAccount* account = CSmsAccount::NewLC();
       
   547 
       
   548 	CMsvScheduleSettings* scheduleSettings = CMsvScheduleSettings::NewL();
       
   549 	CleanupStack::PushL(scheduleSettings);
       
   550 	CMsvOffPeakTimes* offPeakTimes = new(ELeave) CMsvOffPeakTimes;
       
   551 	CleanupStack::PushL(offPeakTimes);
       
   552 	CMsvSendErrorActions* errorActions = CMsvSendErrorActions::NewL();
       
   553 	CleanupStack::PushL(errorActions);
       
   554 	CMsvSysAgentActions* sysAgentActions = new (ELeave) CMsvSysAgentActions();
       
   555 	CleanupStack::PushL(sysAgentActions);
       
   556 
       
   557 	// read existing settings
       
   558 	TRAPD(ignor, account->LoadSettingsL(*scheduleSettings, *offPeakTimes, *errorActions, *sysAgentActions));
       
   559 
       
   560 	// write
       
   561 	account->SaveSettingsL(*scheduleSettings, *offPeakTimes1, *errorActions, *sysAgentActions);
       
   562 
       
   563 	// read 
       
   564 	account->LoadSettingsL(*scheduleSettings, *offPeakTimes2, *errorActions, *sysAgentActions);
       
   565 
       
   566 	// restore settings	
       
   567 	account->SaveSettingsL(*scheduleSettings, *offPeakTimes, *errorActions, *sysAgentActions);
       
   568 	CleanupStack::PopAndDestroy(4, scheduleSettings);
       
   569 
       
   570 	AssertL(offPeakTimes1->Count()==offPeakTimes2->Count());
       
   571 	for(int i = 0; i < offPeakTimes1->Count(); i++)
       
   572 		AssertL((*offPeakTimes1)[i]==(*offPeakTimes2)[i]);
       
   573 
       
   574 	CleanupStack::PopAndDestroy(3, offPeakTimes1); // offPeakTimes1, offPeakTimes2, entry/account
       
   575 	}
       
   576 
       
   577 
       
   578 
       
   579 
       
   580 void CSchSendTest::TestScheduleSettingsL()
       
   581 	{
       
   582 /*
       
   583 	Public functions of CMsvScheduleSettings:
       
   584 
       
   585 	Tested	Function
       
   586 	-------	---------------------------------------------------------------------
       
   587 	Yes		void StoreL(CMsvStore&) const;
       
   588 	Yes		void RestoreL(CMsvStore&);
       
   589 	Yes		void Reset();
       
   590 	Yes		void SetSendExe(const TDesC&);
       
   591 	Yes		const TDesC& SendExe() const;
       
   592 	Yes		void SetPriority(const TInt);
       
   593 	Yes		const TInt Priority() const;
       
   594 	Yes		void SetValidityPeriod(const TTimeIntervalMinutes&);
       
   595 	Yes		const TTimeIntervalMinutes& ValidityPeriod() const;
       
   596 	Yes		void SetIntervalType(const TIntervalType);
       
   597 	Yes		const TIntervalType IntervalType() const;
       
   598 	Yes		void SetLongInterval(const TTimeIntervalSeconds&);
       
   599 	Yes		const TTimeIntervalSeconds& LongInterval() const;
       
   600 	Yes		void SetShortInterval(const TTimeIntervalSeconds&);
       
   601 	Yes		const TTimeIntervalSeconds& ShortInterval() const;
       
   602 	Yes		const CArrayFixFlat<TTimeIntervalSeconds>& VariableIntervals() const;
       
   603 	Yes		void SetVariableIntervalsL(const CArrayFixFlat<TTimeIntervalSeconds>&);
       
   604 	Yes		const TTimeIntervalSeconds& Latency() const;
       
   605 	Yes		void SetLatency(const TTimeIntervalSeconds&);
       
   606 */
       
   607 	iRTest.Next(_L("Schedule Settings Test - CMsvScheduleSettings"));
       
   608 	
       
   609 	CMsvScheduleSettings* settings1 = CMsvScheduleSettings::NewL();
       
   610 	CleanupStack::PushL(settings1);
       
   611 
       
   612 	CMsvScheduleSettings* settings2 = CMsvScheduleSettings::NewL();
       
   613 	CleanupStack::PushL(settings2);
       
   614 
       
   615 	settings1->SetIntervalType(EDaily);
       
   616 	settings1->SetLatency(6);
       
   617 	settings1->SetLongInterval(6);
       
   618 	settings1->SetShortInterval(6);
       
   619 	settings1->SetValidityPeriod(6);
       
   620 	settings1->SetPriority(1);
       
   621 	CArrayFixFlat<TTimeIntervalSeconds>* times = new (ELeave) CArrayFixFlat<TTimeIntervalSeconds>(20);
       
   622 	CleanupStack::PushL(times);
       
   623 	times->AppendL(6);
       
   624 	times->AppendL(6);
       
   625 	times->AppendL(6);
       
   626 	settings1->SetVariableIntervalsL(*times);
       
   627 
       
   628 	// access sms account settings
       
   629 	CSmsAccount* account = CSmsAccount::NewLC();
       
   630 
       
   631 	CMsvScheduleSettings* scheduleSettings = CMsvScheduleSettings::NewL();
       
   632 	CleanupStack::PushL(scheduleSettings);
       
   633 	CMsvOffPeakTimes* offPeakTimes = new(ELeave) CMsvOffPeakTimes;
       
   634 	CleanupStack::PushL(offPeakTimes);
       
   635 	CMsvSendErrorActions* errorActions = CMsvSendErrorActions::NewL();
       
   636 	CleanupStack::PushL(errorActions);
       
   637 	CMsvSysAgentActions* sysAgentActions = new (ELeave) CMsvSysAgentActions();
       
   638 	CleanupStack::PushL(sysAgentActions);
       
   639 
       
   640 	// read existing settings
       
   641 	TRAPD(ignor, account->LoadSettingsL(*scheduleSettings, *offPeakTimes, *errorActions, *sysAgentActions));
       
   642 
       
   643 	// write
       
   644 	account->SaveSettingsL(*settings1, *offPeakTimes, *errorActions, *sysAgentActions);
       
   645 
       
   646 	// read 
       
   647 	account->LoadSettingsL(*settings2, *offPeakTimes, *errorActions, *sysAgentActions);
       
   648 
       
   649 	// restore settings	
       
   650 	account->SaveSettingsL(*scheduleSettings, *offPeakTimes, *errorActions, *sysAgentActions);
       
   651 	CleanupStack::PopAndDestroy(4, scheduleSettings);
       
   652 
       
   653 // 	Not doing anything?
       
   654 //	CMsvScheduleSettings* aDefaultSettings = CMsvScheduleSettings::NewL();
       
   655 //	CleanupStack::PushL(aDefaultSettings);
       
   656 //	aSettings2->Reset();
       
   657 
       
   658 //	AssertL(*aDefaultSettings==*aSettings2);
       
   659 
       
   660 	CleanupStack::PopAndDestroy(4, settings1); // settings1, settings2, times, entry/account
       
   661 	}
       
   662 
       
   663 void CSchSendTest::TestSysAgentActionsL()
       
   664 	{
       
   665 	CMsvSysAgentActions* actions = new (ELeave) CMsvSysAgentActions();
       
   666 	CleanupStack::PushL(actions);
       
   667 	CleanupStack::PopAndDestroy(actions);
       
   668 	}
       
   669 
       
   670 void CSchSendTest::TestSchedulingMessagesL()
       
   671 	{
       
   672 
       
   673 	//make a message and schedule it in 1 second
       
   674 	TMsvEntry entry;
       
   675 	TTime t;
       
   676 	t.HomeTime();
       
   677 //	t += TTimeIntervalSeconds(2);
       
   678 	TMsvId testMessage = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t);	
       
   679 
       
   680 	iRTest.Printf(_L("Message created at "));
       
   681 	iRTest << t;
       
   682 	
       
   683 	iSelection->ResizeL(0);
       
   684 	iSelection->AppendL(testMessage);
       
   685 
       
   686 	iMsvEntry->SetEntryL(testMessage);
       
   687 	AssertL(iMsvEntry->Entry().SendingState() == 0);
       
   688 	TTime t2 = TestL(EScheduleAllL, *iSelection).iTime;
       
   689 	
       
   690 	iRTest.Printf(_L("Message scheduled at "));
       
   691 	iRTest << t2;
       
   692 	//Test that the time is still the same
       
   693 	
       
   694 	//check that it worked
       
   695 	
       
   696 	iMsvEntry->SetEntryL(testMessage);
       
   697 	iRTest.Printf(_L("Message iDate "));
       
   698 	iRTest << iMsvEntry->Entry().iDate;
       
   699 
       
   700 	AssertL(CompareRoundedTimes(iMsvEntry->Entry().iDate, t2));
       
   701 
       
   702 	const TInt sendState = iMsvEntry->Entry().SendingState();
       
   703 	AssertL(sendState == KMsvSendStateSent);
       
   704 
       
   705 	CleanupStack::PopAndDestroy();//testMessage
       
   706 	}
       
   707 
       
   708 void CSchSendTest::TestSchedulingOldMessagesL()
       
   709 	{
       
   710 	//Make a message and schedule it yesterday
       
   711 	TMsvEntry entry;
       
   712 	TTime t;
       
   713 	t.HomeTime();
       
   714 	t -= TTimeIntervalDays(1);
       
   715 	TMsvId testMessage = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t);
       
   716 	
       
   717 
       
   718 	iSelection->ResizeL(0);
       
   719 	iSelection->AppendL(testMessage);
       
   720 	
       
   721 	
       
   722 	TTime t2(TestL(EScheduleAllL, *iSelection, ETrue).iTime);
       
   723 
       
   724 	//did it get scheduled?
       
   725 
       
   726 	iMsvEntry->SetEntryL(testMessage);
       
   727 	AssertL(iMsvEntry->Entry().SendingState() == KMsvSendStateScheduled);
       
   728 
       
   729 	TTime now;
       
   730 	now.HomeTime();
       
   731 
       
   732 	//should be scheduled in the future 
       
   733 
       
   734 	iRTest << t2 << now;
       
   735 	AssertL(t2 > now);
       
   736 
       
   737 	ChangeMessageTimeL(testMessage, t);
       
   738 
       
   739 	CleanupStack::PopAndDestroy();//testMessage
       
   740 	}
       
   741 
       
   742 void CSchSendTest::TestSchedulingOffPeakMessagesL()
       
   743 	{
       
   744 	
       
   745 	//make a message and schedule it for off-peak
       
   746 	TMsvEntry entry;
       
   747 	TTime t;
       
   748 	t.HomeTime();
       
   749 	t += TTimeIntervalSeconds(1);
       
   750 	iRTest.Printf(_L("Trying to schedule at"));
       
   751 	iRTest<<t;
       
   752 	TMsvId testMessage = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t, ETrue);
       
   753 
       
   754 	iSelection->ResizeL(0);
       
   755 	iSelection->AppendL(testMessage);
       
   756 	
       
   757 	iSchTestActive->TransferCommandSyncL(ESetNowOffPeak, *iSelection, ETrue);
       
   758 
       
   759 	ChangeMessageTimeL(testMessage, t);
       
   760 	TTime t2 = TestL(EScheduleAllL, *iSelection, ETrue).iTime;
       
   761 	ChangeMessageTimeL(testMessage, t);
       
   762 
       
   763 	iMsvEntry->SetEntryL(testMessage);
       
   764 	TMsvEntry resultingEntry = iMsvEntry->Entry();
       
   765 	AssertL(resultingEntry.SendingState() == KMsvSendStateScheduled);
       
   766 
       
   767 	TTime now;
       
   768 	now.HomeTime();
       
   769 
       
   770 	AssertL(DiffInMins(t2, now) < 5);   // About now
       
   771 
       
   772 	iSchTestActive->TransferCommandSyncL(ESetNowNotOffPeak, *iSelection, ETrue);
       
   773 	
       
   774 	t2 = TestL(EScheduleAllL, *iSelection, ETrue).iTime;
       
   775 
       
   776 
       
   777 	AssertL(DiffInMins(t2, now) > (60 * 22)); // Tomorrow sometime
       
   778 
       
   779 	iSchTestActive->TransferCommandSyncL(ESetFirstOffPeakBest, *iSelection, ETrue);
       
   780 	
       
   781 	t2 = TestL(EScheduleAllL, *iSelection, ETrue).iTime;
       
   782 
       
   783 	AssertL(DiffInMins(t2, now) > (60 * 22)); // Tomorrow sometime
       
   784 
       
   785 	iSchTestActive->TransferCommandSyncL(ESetLastOffPeakBest, *iSelection, ETrue);
       
   786 	t2 = TestL(EScheduleAllL, *iSelection, ETrue).iTime;
       
   787 
       
   788 	AssertL(DiffInMins(t2, now) > (60 * 22)); // Tomorrow sometime
       
   789 
       
   790 	//Tidy up after ourselves!
       
   791 	iSchTestActive->TransferCommandSyncL(EDeleteScheduleL, *iSelection, ETrue);
       
   792 	
       
   793 	CleanupStack::PopAndDestroy();//testMessage
       
   794 	}
       
   795 
       
   796 
       
   797 void CSchSendTest::TestReschedulingMessagesL()
       
   798 	{
       
   799 	//Make a message and schedule it in 1 second
       
   800 	TMsvEntry entry;
       
   801 	TTime t;
       
   802 	t.HomeTime();
       
   803 	t += TTimeIntervalSeconds(4);
       
   804 	TMsvId testMessage = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t);
       
   805 	
       
   806 
       
   807 	iSelection->ResizeL(0);
       
   808 	iSelection->AppendL(testMessage);
       
   809 
       
   810 	iSchTestActive->TransferCommandSyncL(EScheduleAllL, *iSelection, ETrue);
       
   811 	
       
   812 	//Set the retry time
       
   813 	iSchTestActive->TransferCommandSyncL(ESetRetryImmediately, *iSelection, ETrue);
       
   814 
       
   815 	//Reschedule the message
       
   816 
       
   817 	TTime t2 = TestL(EReScheduleAllL, *iSelection, ETrue).iTime;
       
   818 
       
   819 	//Still scheduled?
       
   820 
       
   821 	iMsvEntry->SetEntryL(testMessage);
       
   822 	AssertL(iMsvEntry->Entry().SendingState() == KMsvSendStateResend);
       
   823 
       
   824 	//Check the time is in KShortInterval seconds from t
       
   825 
       
   826 	TTime test = t + TTimeIntervalSeconds(KShortInterval);
       
   827 	iRTest.Printf(_L("KShortInterval seconds different "));
       
   828 	iRTest<<t2<< test;
       
   829 	AssertL(DiffInSecs(test, t2) < 10);
       
   830 
       
   831 	//Resend several times. Each time AssertL that the time is correct.
       
   832 
       
   833 	iSchTestActive->TransferCommandSyncL(ESetRetryLater, *iSelection, ETrue);
       
   834 	t2 = TestL(EReScheduleAllL, *iSelection, ETrue).iTime;
       
   835 
       
   836 	test = t + TTimeIntervalSeconds(KLongInterval);
       
   837 	iRTest.Printf(_L("KLongInterval seconds different"));
       
   838 	iRTest<< t2 << test;
       
   839 	AssertL(DiffInSecs(test,t2)< 5);
       
   840 
       
   841 	iSchTestActive->TransferCommandSyncL(ESetNoRetry, *iSelection, ETrue);
       
   842 	iSchTestActive->TransferCommandSyncL(EReScheduleAllL, *iSelection, ETrue);
       
   843 
       
   844 	iSchTestActive->TransferCommandSyncL(ESetRetryVariable, *iSelection, ETrue);
       
   845 	t2 = TestL(EReScheduleAllL, *iSelection, ETrue).iTime;
       
   846 
       
   847 	test = t + TTimeIntervalSeconds(KFirstInterval);
       
   848 	iRTest.Printf(_L("KFirstInterval seconds different"));
       
   849 	iRTest<< t2 << test;
       
   850 	AssertL(DiffInSecs(test, t2) < 5);
       
   851 
       
   852 	t2 = TestL(EReScheduleAllL, *iSelection, ETrue).iTime;
       
   853 
       
   854 	test = t + TTimeIntervalSeconds(KSecondInterval);
       
   855 	iRTest.Printf(_L("KSecondInterval seconds different"));
       
   856 	iRTest<<t2<< test;
       
   857 	AssertL(DiffInSecs(test, t2) < 5);
       
   858 
       
   859 	t2 = TestL(EReScheduleAllL, *iSelection, ETrue).iTime;
       
   860 
       
   861 	test = t + TTimeIntervalSeconds(KThirdInterval);
       
   862 	iRTest.Printf(_L("KThirdInterval seconds different"));
       
   863 	iRTest<<t2<< test;
       
   864 	AssertL(DiffInSecs(test, t2) < 5);
       
   865 
       
   866 	//Tidy up.
       
   867 
       
   868 	iSchTestActive->TransferCommandSyncL(EDeleteScheduleL, *iSelection, ETrue);
       
   869 
       
   870 	CleanupStack::PopAndDestroy();//testMessage
       
   871 	}
       
   872 
       
   873 void CSchSendTest::TestReschedulingNonScheduledMessagesL()
       
   874 	{
       
   875 	//Make a message and schedule it in 1 second
       
   876 	TMsvEntry entry;
       
   877 	TTime t;
       
   878 	t.HomeTime();
       
   879 	t += TTimeIntervalSeconds(1);
       
   880 	TMsvId testMessage = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t);
       
   881 	
       
   882 	iSelection->Reset();
       
   883 	iSelection->AppendL(testMessage);
       
   884 	
       
   885 	//Reschedule the message
       
   886 
       
   887 	iSchTestActive->TransferCommandSyncL(EReScheduleAllL, *iSelection, ETrue);
       
   888 
       
   889 	//Are we scheduled now?
       
   890 	
       
   891 	iMsvEntry->SetEntryL(testMessage);
       
   892 	AssertL(iMsvEntry->Entry().SendingState() == KMsvSendStateResend);
       
   893 
       
   894 	//Tidy up.
       
   895 	iSchTestActive->TransferCommandSyncL(EDeleteScheduleL, *iSelection, ETrue);
       
   896 
       
   897 	CleanupStack::PopAndDestroy();//testMessage
       
   898 	}
       
   899 
       
   900 void CSchSendTest::TestSchedulingMessagesTwiceL()
       
   901 	{
       
   902 	//make a message
       
   903 	TMsvEntry entry;
       
   904 	TTime t;
       
   905 	t.HomeTime();
       
   906 	t += TTimeIntervalSeconds(1);
       
   907 	TMsvId testMessage = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t);
       
   908 	
       
   909 
       
   910 	//schedule it for real soon now
       
   911 	iSelection->Reset();
       
   912 	iSelection->AppendL(testMessage);
       
   913 	
       
   914 	iSchTestActive->TransferCommandSyncL(EScheduleAllL, *iSelection, ETrue);
       
   915 
       
   916 	//schedule it for tomorrow too
       
   917 	t += TTimeIntervalDays(1);
       
   918 	ChangeMessageTimeL(testMessage, t);
       
   919 	
       
   920 	//TTime t2 = TestL(EScheduleAllL, *iSelection, ETrue));
       
   921 	
       
   922 	//assert message scheduled.
       
   923 
       
   924 	iMsvEntry->SetEntryL(testMessage);
       
   925 	AssertL(iMsvEntry->Entry().SendingState() == KMsvSendStateScheduled);
       
   926 
       
   927 	//look for the message
       
   928 
       
   929 	TTime now;
       
   930 	now.HomeTime();
       
   931 
       
   932 	//check its time is tomorrow
       
   933 //	AssertL(DiffInMins(t2,now) > (23*60)); 
       
   934 
       
   935 	//Get rid of it
       
   936 	iSchTestActive->TransferCommandSyncL(EDeleteScheduleL, *iSelection, ETrue);
       
   937 
       
   938 	CleanupStack::PopAndDestroy();//testMessage
       
   939 	}
       
   940 
       
   941 
       
   942 void CSchSendTest::TestDeletingMessagesL()
       
   943 	{
       
   944 	//make a message and schedule it for tomorrow
       
   945 	TMsvEntry entry;
       
   946 	TTime t;
       
   947 	t.HomeTime();
       
   948 	t += TTimeIntervalDays(1);
       
   949 	iSelection->Reset();
       
   950 
       
   951 	TMsvId testMessage1 = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t);
       
   952 	iSelection->AppendL(testMessage1);
       
   953 	TMsvId testMessage2 = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t);
       
   954 	iSelection->AppendL(testMessage2);
       
   955 	TMsvId testMessage3 = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t);
       
   956 	iSelection->AppendL(testMessage3);
       
   957 
       
   958 	TInt schCountOld, schCountNew;
       
   959 	TInt schSize;
       
   960 	DisplayAllSchedulesL(schCountOld, schSize);
       
   961 
       
   962 	iSchTestActive->TransferCommandSyncL(EScheduleAllL, *iSelection, ETrue);
       
   963 	
       
   964 	//delete the schedule
       
   965 
       
   966 	iSchTestActive->TransferCommandSyncL(EDeleteScheduleL, *iSelection, ETrue);
       
   967 
       
   968 	DisplayAllSchedulesL(schCountNew, schSize);
       
   969 
       
   970 //	AssertL (schCountNew <= schCountOld);
       
   971 
       
   972 	//deleted message should now be suspended
       
   973 	
       
   974 	iMsvEntry->SetEntryL(testMessage1);
       
   975 	AssertL (iMsvEntry->Entry().SendingState()==KMsvSendStateSuspended);	
       
   976 	iMsvEntry->SetEntryL(testMessage2);
       
   977 	AssertL (iMsvEntry->Entry().SendingState()==KMsvSendStateSuspended);	
       
   978 	iMsvEntry->SetEntryL(testMessage3);
       
   979 	AssertL (iMsvEntry->Entry().SendingState()==KMsvSendStateSuspended);	
       
   980 
       
   981 	CleanupStack::PopAndDestroy(3);//testMessages
       
   982 	}
       
   983 
       
   984 void CSchSendTest::TestDeletingNonScheduledMessagesL()
       
   985 	{
       
   986 	//make a message but don't schedule it
       
   987  	TMsvEntry entry;
       
   988 	TTime t;
       
   989 	t.HomeTime();
       
   990 	t += TTimeIntervalDays(1);
       
   991 	TMsvId testMessage = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t);
       
   992 
       
   993 	//delete the message from the scheduler
       
   994 	iSelection->ResizeL(0);
       
   995 	iSelection->AppendL(testMessage);
       
   996 
       
   997 	iSchTestActive->TransferCommandSyncL(EDeleteScheduleL, *iSelection, ETrue);
       
   998 	
       
   999 	//deleted message should now be suspended
       
  1000 	
       
  1001 	iMsvEntry->SetEntryL(testMessage);
       
  1002 	AssertL (iMsvEntry->Entry().SendingState()==KMsvSendStateSuspended);
       
  1003 
       
  1004 	CleanupStack::PopAndDestroy();//testMessage
       
  1005 	}
       
  1006 
       
  1007 void CSchSendTest::TestCheckScheduleL()
       
  1008 	{
       
  1009 	//make a message and schedule it at T1
       
  1010  	TMsvEntry entry;
       
  1011 	TTime t1;
       
  1012 	t1.HomeTime();
       
  1013 	t1 += TTimeIntervalHours(1);
       
  1014 	TMsvId testMessage = CreateMessageLC(entry, KMsvGlobalInBoxIndexEntryId, t1);
       
  1015 	
       
  1016 	iSchTestActive->TransferCommandSyncL(EScheduleAllL, *iSelection, ETrue);
       
  1017 
       
  1018 	//change the date in the message to T2
       
  1019 
       
  1020 	TTime t2 = t1 + TTimeIntervalHours(1);
       
  1021 	ChangeMessageTimeL(testMessage, t2);
       
  1022 
       
  1023 	//check the schedule
       
  1024 	iSchTestActive->TransferCommandSyncL(ECheckScheduleL, *iSelection, ETrue);
       
  1025 
       
  1026 	//the date should now be T1
       
  1027 
       
  1028 	iMsvEntry->SetEntryL(testMessage);
       
  1029 	//TMsvEntry newEntry = iMsvEntry->Entry();
       
  1030 
       
  1031 	//AssertL(newEntry.iDate == t1);  // not implemented yet
       
  1032 
       
  1033 	CleanupStack::PopAndDestroy();//testMessage
       
  1034 	}
       
  1035 
       
  1036 // leaves unless the test leaves with KErrNoMemory for every memory failure
       
  1037 const TSchSendTestProgress& CSchSendTest::TestL(TSchSendTestOperation aOp,
       
  1038 						 CMsvEntrySelection& aSel,
       
  1039 						 TBool aBool /*= EFalse*/)
       
  1040 	{
       
  1041 	TInt error = KErrNone;
       
  1042 	if (iHeapTest) 
       
  1043 		{
       
  1044 		iSchTestActive->TransferCommandSyncL(ESetIncrementalHeapFailure, *iSelection, ETrue);
       
  1045 		do
       
  1046 			{
       
  1047 	
       
  1048 			TRAP(error, 
       
  1049 				iSchTestActive->TransferCommandSyncL(aOp, aSel, aBool);
       
  1050 			);
       
  1051 	
       
  1052 			} while(error == KErrNoMemory);
       
  1053 
       
  1054 		iSchTestActive->TransferCommandSyncL(ENoIncrementalHeapFailure, *iSelection, ETrue);
       
  1055 
       
  1056 		User::LeaveIfError(error);
       
  1057 		return iSchTestActive->Progress();
       
  1058 		} 
       
  1059 	else 
       
  1060 		{
       
  1061 		return iSchTestActive->TransferCommandSyncL(aOp, aSel, aBool);
       
  1062 		}
       
  1063 	}
       
  1064 
       
  1065 // Returns true if the test does not leave
       
  1066 // Also if the test leaves with KErrNone, but that would be pathological.
       
  1067 
       
  1068 // Logs the test start/finish messages
       
  1069 TBool CSchSendTest::DoTest(void (CSchSendTest::*aTest)(), TPtrC aText)
       
  1070 	{
       
  1071 	TestStart(++iCurrentTest, aText);
       
  1072 	TRAPD(err, (this->*aTest)());
       
  1073 	TestFinish(iCurrentTest, err);
       
  1074 	return (err == KErrNone);
       
  1075 	}
       
  1076 
       
  1077 TBool CSchSendTest::HeapTest(void (CSchSendTest::*aTest)(), TPtrC aText)
       
  1078 	{
       
  1079 	TestStart(++iCurrentTest, aText);
       
  1080 //	WriteComment(aText);
       
  1081 	iHeapTest = ETrue;
       
  1082 	TRAPD(err, (this->*aTest)());
       
  1083 	TestFinish(iCurrentTest, err);
       
  1084 	iHeapTest = EFalse;
       
  1085 	return (err == KErrNone);
       
  1086 	}
       
  1087