messagingfw/msgtest/integration/email/src/sms.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
child 58 6c34d0baa0b1
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     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 "sms.h"
       
    17 
       
    18 //
       
    19 CSmsBaseUtils::CSmsBaseUtils()
       
    20 	:iSession(NULL), iEntry(NULL), iOrder(KMsvGroupByType|KMsvGroupByStandardFolders,EMsvSortById,ETrue)
       
    21 	{
       
    22 	}
       
    23 
       
    24 
       
    25 CSmsBaseUtils::~CSmsBaseUtils()
       
    26 	{
       
    27 	delete iEntry;
       
    28 	iEntry=NULL;
       
    29 	delete iSession;
       
    30 	iSession=NULL;
       
    31 	}
       
    32 
       
    33 
       
    34 void CSmsBaseUtils::StartL()
       
    35 	{
       
    36 	iSession=CMsvSession::OpenSyncL(*this);
       
    37 	}
       
    38 
       
    39 
       
    40 CMsvEntry& CSmsBaseUtils::EntryL()
       
    41 	{
       
    42 	if ( iEntry == NULL )
       
    43 		{
       
    44 		User::Leave(KErrGeneral);
       
    45 		}
       
    46 	return *iEntry;
       
    47 	}
       
    48 
       
    49 
       
    50 void CSmsBaseUtils::SetEntryL(TMsvId aId)
       
    51 	{
       
    52 	delete iEntry;
       
    53 	iEntry=NULL;
       
    54 	iEntry=iSession->GetEntryL(aId);
       
    55 	}
       
    56 
       
    57 
       
    58 void CSmsBaseUtils::SetDefaultServiceL(TUid aMtm,TMsvId aService) const
       
    59 	{
       
    60 	CMsvEntry* rootEntry=iSession->GetEntryL(KMsvRootIndexEntryIdValue);
       
    61 	CleanupStack::PushL(rootEntry);
       
    62 	CMsvStore* store = rootEntry->EditStoreL();
       
    63 	CleanupStack::PushL(store);
       
    64 	CMsvDefaultServices* services = new(ELeave)CMsvDefaultServices;
       
    65 	CleanupStack::PushL(services);
       
    66 	services->RestoreL(*store);
       
    67 
       
    68 	TMsvDefaultService	defaultService;
       
    69 	defaultService.iMtm=aMtm;
       
    70 	defaultService.iService=aService;
       
    71 	services->ChangeDefaultServiceL(defaultService);
       
    72 	services->StoreL(*store);
       
    73 	store->CommitL();
       
    74 
       
    75 	CleanupStack::PopAndDestroy(3, rootEntry);
       
    76 	}
       
    77 
       
    78 
       
    79 TInt CSmsBaseUtils::DefaultServiceL(TUid aMtm,TMsvId& aService) const
       
    80 	{
       
    81 	CMsvEntry*				rootEntry=iSession->GetEntryL(KMsvRootIndexEntryIdValue);
       
    82 	CleanupStack::PushL(rootEntry);
       
    83 	CMsvStore*				store=rootEntry->ReadStoreL();
       
    84 	CleanupStack::PushL(store);
       
    85 	CMsvDefaultServices*	services=new(ELeave)CMsvDefaultServices;
       
    86 	CleanupStack::PushL(services);
       
    87 	services->RestoreL(*store);
       
    88 
       
    89 	TInt					ret=services->DefaultService(aMtm, aService);
       
    90 
       
    91 	CleanupStack::PopAndDestroy(3, rootEntry);
       
    92 
       
    93 	return ret;
       
    94 	}
       
    95 
       
    96 
       
    97 //
       
    98 void CSmsTestUtils::StartL()
       
    99 	{
       
   100 	_LIT(KSmsAccountName,	"Short Message");
       
   101 	
       
   102 	CSmsBaseUtils::StartL();
       
   103 
       
   104 	CSmsSettings* smsSettings = CSmsSettings::NewL();
       
   105 	CleanupStack::PushL(smsSettings);
       
   106 	SetEntryL(KMsvRootIndexEntryId);
       
   107 
       
   108 	EntryL().SetSortTypeL(SelectionOrdering());
       
   109 	CMsvEntrySelection*	selection=EntryL().ChildrenWithTypeL(KUidMsvServiceEntry);
       
   110 	CleanupStack::PushL(selection);
       
   111 	TInt   count=selection->Count();
       
   112 	TBool  found=EFalse;
       
   113 	TPtrC  accountName(KSmsAccountName);
       
   114 	TMsvId idSms=0;
       
   115 	for (TInt i=count; i>0 && !found; )
       
   116 		{
       
   117 		SetEntryL(selection->At(--i));
       
   118 		if	(EntryL().Entry().iMtm == KUidMsgTypeSMS && EntryL().Entry().iType == KUidMsvServiceEntry)
       
   119 			{
       
   120 			idSms=EntryL().EntryId();
       
   121 			found=ETrue;
       
   122 			}
       
   123 		}
       
   124 
       
   125 	if (!found)
       
   126 		{
       
   127 		TMsvEntry entry;
       
   128 		entry.iMtm = KUidMsgTypeSMS;
       
   129 		entry.iType = KUidMsvServiceEntry;
       
   130 		entry.SetReadOnly(EFalse);
       
   131 		entry.SetVisible(EFalse);
       
   132 		entry.SetOperation(ETrue);
       
   133 		entry.iDetails.Set(accountName);
       
   134 	
       
   135 		SetEntryL(KMsvRootIndexEntryId);
       
   136 		EntryL().CreateL(entry);
       
   137 		idSms=entry.Id();
       
   138 
       
   139 		smsSettings->SetValidityPeriod(ESmsVPWeek);
       
   140 		smsSettings->SetValidityPeriodFormat(TSmsFirstOctet::ESmsVPFInteger);
       
   141 		smsSettings->SetReplyQuoted(EFalse);
       
   142 		smsSettings->SetRejectDuplicate(ETrue);
       
   143 		smsSettings->SetDelivery(ESmsDeliveryImmediately);
       
   144 		smsSettings->SetDeliveryReport(ETrue);
       
   145 		smsSettings->SetReplyPath(EFalse);
       
   146 		smsSettings->SetMessageConversion(ESmsConvPIDNone);
       
   147 		smsSettings->SetCanConcatenate(ETrue);
       
   148 
       
   149 		SetEntryL(idSms);
       
   150 		
       
   151 		CMsvStore*	msvstore=EntryL().EditStoreL();
       
   152 		CleanupStack::PushL(msvstore);
       
   153 		smsSettings->StoreL(*msvstore);
       
   154 		msvstore->CommitL();
       
   155 		CleanupStack::PopAndDestroy(msvstore);
       
   156 		}
       
   157 
       
   158 		SetEntryL(idSms);
       
   159 		
       
   160  		CMsvStore*	smsStore = EntryL().EditStoreL();
       
   161 		CleanupStack::PushL(smsStore);
       
   162 
       
   163 		smsSettings->RestoreL(*smsStore);
       
   164 
       
   165 		TPtrC	ptrSCName;
       
   166 		TPtrC	ptrSCNumber;
       
   167 
       
   168 		smsSettings->AddSCAddressL(ptrSCName, ptrSCNumber);
       
   169 		
       
   170 		smsSettings->StoreL(*smsStore);
       
   171 		smsStore->CommitL();
       
   172 
       
   173 		CleanupStack::PopAndDestroy(smsStore);
       
   174 
       
   175 		SetDefaultServiceL(KUidMsgTypeSMS, idSms);
       
   176 		CleanupStack::PopAndDestroy(2);
       
   177 	}
       
   178 
       
   179 
       
   180 //
       
   181 CSmsBaseClientTest* CSmsBaseClientTest::NewL(CSmsTestUtils& aSmsUtils,RTest& aTest)
       
   182 	{
       
   183 	CSmsBaseClientTest* self = new (ELeave) CSmsBaseClientTest(aSmsUtils,aTest);
       
   184 	CleanupStack::PushL(self);
       
   185 	self->ConstructL();
       
   186 	CleanupStack::Pop(self);
       
   187 	return self;
       
   188 	}
       
   189 
       
   190 CSmsBaseClientTest* CSmsBaseClientTest::NewL(CSmsTestUtils* aSmsUtils, RTest& aTest)
       
   191 	{
       
   192 	CSmsBaseClientTest* self = new (ELeave) CSmsBaseClientTest(aSmsUtils, aTest);
       
   193 	CleanupStack::PushL(self);
       
   194 	self->ConstructL();
       
   195 	CleanupStack::Pop(self);
       
   196 	return self;
       
   197 	}
       
   198 
       
   199 CSmsBaseClientTest::~CSmsBaseClientTest()
       
   200 	{
       
   201 	Cancel();
       
   202 	delete iCurrentSelection;
       
   203 	delete iOperation;
       
   204 	delete iOwnedSmsUtils;
       
   205 	}
       
   206 
       
   207 void CSmsBaseClientTest::DoCancel()
       
   208 	{
       
   209 	if (iOperation)
       
   210 		{
       
   211 		iOperation->Cancel();
       
   212 		}
       
   213 	}
       
   214 
       
   215 void CSmsBaseClientTest::SetCurrentOperation(CMsvOperation* aOperation)
       
   216 	{
       
   217 	delete iOperation;
       
   218 	iOperation = aOperation;
       
   219 	}
       
   220 
       
   221 
       
   222 CMsvOperation& CSmsBaseClientTest::CurrentOperation()
       
   223 	{
       
   224 	return *iOperation;
       
   225 	}
       
   226 
       
   227 void CSmsBaseClientTest::ConstructL()
       
   228 	{
       
   229 	CBaseTestHarness::ConstructL();
       
   230 	iCurrentSelection = new (ELeave) CMsvEntrySelection;
       
   231 	}
       
   232 
       
   233 CSmsBaseClientTest::CSmsBaseClientTest(CSmsTestUtils& aSmsUtils, RTest& aTest) 
       
   234 : CBaseTestHarness(aTest), 
       
   235   iSmsUtils(aSmsUtils)
       
   236 	{
       
   237 	iOperation = NULL;
       
   238 	}
       
   239 
       
   240 CSmsBaseClientTest::CSmsBaseClientTest(CSmsTestUtils* aSmsUtils, RTest& aTest) 
       
   241 : CBaseTestHarness(aTest), 
       
   242   iSmsUtils(*aSmsUtils),
       
   243   iOwnedSmsUtils(aSmsUtils)
       
   244 	{
       
   245 	iOperation = NULL;
       
   246 	}
       
   247 
       
   248 CSmsTestUtils& CSmsBaseClientTest::SmsTestUtils()
       
   249 	{
       
   250 	return iSmsUtils;
       
   251 	}
       
   252 
       
   253 
       
   254 //
       
   255 CSmsBaseClientSectionParser* CSmsBaseClientSectionParser::NewL(CSmsBaseClientTest& aSmsTest, CTestScript& aScript, const TDesC& aNewSectionName)
       
   256 	{
       
   257 	CSmsBaseClientSectionParser* self = new (ELeave) CSmsBaseClientSectionParser(aSmsTest, aScript);
       
   258 	CleanupStack::PushL(self);
       
   259 	self->ConstructL(aNewSectionName);
       
   260 	CleanupStack::Pop(self);
       
   261 	return self;
       
   262 	}
       
   263 
       
   264 void CSmsBaseClientSectionParser::LogCommentL(const TDesC& /*aComment*/)
       
   265 	{
       
   266 //	iEmailTest.EmailTestUtils().WriteComment(aComment);
       
   267 	}
       
   268 
       
   269 void CSmsBaseClientSectionParser::ConstructL(const TDesC& aNewSectionName)
       
   270 	{
       
   271 	CBaseSectionParser::ConstructL(aNewSectionName);
       
   272 	TTestDebugInfo debugInfo = iSmsTest.GetDebugInfo();
       
   273 	debugInfo.SetTestHarnessName(iSection->SectionPosition());
       
   274 	iSmsTest.SetDebugInfo(debugInfo);
       
   275 	iCommandParsers->AppendL(CNewSmsTestCommandParser::NewL(iScript,iSmsTest));
       
   276 	iCommandParsers->AppendL(CSmsBaseUtilitiesParser::NewL(iSmsTest));
       
   277 	}
       
   278 
       
   279 CSmsBaseClientSectionParser::CSmsBaseClientSectionParser(CSmsBaseClientTest& aSmsTest, CTestScript& aScript) : CBaseSectionParser(aScript), iSmsTest(aSmsTest)
       
   280 	{
       
   281 	}
       
   282 
       
   283 
       
   284 //
       
   285 CNewSmsBaseTestCommandParser* CNewSmsBaseTestCommandParser::NewL(CTestScript& aScript, CMainTestHarness& aMainTest, TBool aKeepLogFile)
       
   286 	{
       
   287 	CNewSmsBaseTestCommandParser* self = new (ELeave) CNewSmsBaseTestCommandParser(aScript, aMainTest, aKeepLogFile);
       
   288 	CleanupStack::PushL(self);
       
   289 	self->ConstructL();
       
   290 	CleanupStack::Pop(self);
       
   291 	return self;
       
   292 	}
       
   293 
       
   294 void CNewSmsBaseTestCommandParser::ProcessL()
       
   295 	{
       
   296 	// Create sms stuff
       
   297 	CSmsTestUtils* smsUtils = new(ELeave) CSmsTestUtils();
       
   298 	CleanupStack::PushL(smsUtils);
       
   299 	
       
   300 	// Create an Sms test, give it the test utilities
       
   301 	CSmsBaseClientTest* smsTest = CSmsBaseClientTest::NewL(smsUtils,iMainTest.TestConsole());
       
   302 	CleanupStack::Pop(smsUtils); // smsTest has taken ownership
       
   303 	CleanupStack::PushL(smsTest);
       
   304 
       
   305 	// Attach the Sms test to the main test
       
   306 	iMainTest.AddStateL(smsTest, iDebugInfo);
       
   307 	CleanupStack::Pop(smsTest); // SmsTest is now owned by the iMainTest
       
   308 
       
   309 	// Check that there is one argument, the Sms test section name
       
   310 	CheckNumberOfArgumentsL(1);
       
   311 
       
   312 	// Create an Sms section parser
       
   313 	CSmsBaseClientSectionParser* sectionParser = CSmsBaseClientSectionParser::NewL(*smsTest, iScript, (*iArgumentList)[0]);
       
   314 	CleanupStack::PushL(sectionParser);
       
   315 	sectionParser->ParseL();
       
   316 	CleanupStack::PopAndDestroy(sectionParser);
       
   317 	}
       
   318 
       
   319 void CNewSmsBaseTestCommandParser::ConstructL()
       
   320 	{
       
   321 	CBaseCommandParser::ConstructL();
       
   322 	AddCommandL(CCommandSmsBaseClientTest);
       
   323 	}
       
   324 
       
   325 CNewSmsBaseTestCommandParser::CNewSmsBaseTestCommandParser(CTestScript& aScript, CMainTestHarness& aMainTest, TBool aKeepLogFile) : iMainTest(aMainTest), iScript(aScript), iKeepLogFile(aKeepLogFile)
       
   326 	{
       
   327 	}
       
   328 
       
   329 
       
   330 //
       
   331 CSmsClientTest* CSmsClientTest::NewL(CSmsTestUtils& aSmsUtils, RTest& aTest)
       
   332 	{
       
   333 	CSmsClientTest* self = new (ELeave) CSmsClientTest(aSmsUtils, aTest);
       
   334 	CleanupStack::PushL(self);
       
   335 	self->ConstructL();
       
   336 	CleanupStack::Pop(self);
       
   337 	return self;
       
   338 	}
       
   339 
       
   340 CSmsClientTest::~CSmsClientTest()
       
   341 	{
       
   342 	}
       
   343 
       
   344 void CSmsClientTest::ConstructL()
       
   345 	{
       
   346 	CSmsBaseClientTest::ConstructL();
       
   347 	}
       
   348 
       
   349 CSmsClientTest::CSmsClientTest(CSmsTestUtils& aSmsUtils, RTest& aTest) : CSmsBaseClientTest(aSmsUtils, aTest)
       
   350 	{
       
   351 	}
       
   352 
       
   353 
       
   354 //
       
   355 CSmsClientSectionParser* CSmsClientSectionParser::NewL(CSmsClientTest& aSmsTest, CTestScript& aScript, const TDesC& aNewSectionName)
       
   356 	{
       
   357 	CSmsClientSectionParser* self = new (ELeave) CSmsClientSectionParser(aSmsTest, aScript);
       
   358 	CleanupStack::PushL(self);
       
   359 	self->ConstructL(aNewSectionName);
       
   360 	CleanupStack::Pop(self);
       
   361 	return self;
       
   362 	}
       
   363 
       
   364 void CSmsClientSectionParser::ConstructL(const TDesC& aNewSectionName)
       
   365 	{
       
   366 	CSmsBaseClientSectionParser::ConstructL(aNewSectionName);
       
   367 	}
       
   368 
       
   369 CSmsClientSectionParser::CSmsClientSectionParser(CSmsClientTest& aSmsTest, CTestScript& aScript) : CSmsBaseClientSectionParser(aSmsTest, aScript), iSmsTest(aSmsTest)
       
   370 	{
       
   371 	}
       
   372 
       
   373 
       
   374 
       
   375 //
       
   376 CNewSmsTestCommandParser* CNewSmsTestCommandParser::NewL(CTestScript& aScript, CSmsBaseClientTest& aSmsTest)
       
   377 	{
       
   378 	CNewSmsTestCommandParser* self = new (ELeave) CNewSmsTestCommandParser(aScript, aSmsTest);
       
   379 	CleanupStack::PushL(self);
       
   380 	self->ConstructL();
       
   381 	CleanupStack::Pop(self);
       
   382 	return self;
       
   383 	};
       
   384 
       
   385 void CNewSmsTestCommandParser::ProcessL()
       
   386 	{
       
   387 	// Create an sms test, give it the test utilities
       
   388 	CSmsClientTest* smsTest = CSmsClientTest::NewL(iSmsTest.SmsTestUtils(), iSmsTest.TestConsole());
       
   389 	CleanupStack::PushL(smsTest);
       
   390 
       
   391 	// Attach the sms test to the main test
       
   392 	iSmsTest.AddStateL(smsTest, iDebugInfo);
       
   393 	CleanupStack::Pop(smsTest); // smsTest is now owned by the iMainTest
       
   394 
       
   395 	// Check that there is one argument, the sms test section name
       
   396 	CheckNumberOfArgumentsL(1);
       
   397 
       
   398 	// Create an sms section parser
       
   399 	CSmsClientSectionParser* sectionParser = CSmsClientSectionParser::NewL(*smsTest, iScript, (*iArgumentList)[0]);
       
   400 	CleanupStack::PushL(sectionParser);
       
   401 	sectionParser->ParseL();
       
   402 	CleanupStack::PopAndDestroy(sectionParser);
       
   403 	}
       
   404 
       
   405 void CNewSmsTestCommandParser::ConstructL()
       
   406 	{
       
   407 	CBaseCommandParser::ConstructL();
       
   408 	AddCommandL(CCommandSmsClientTest);
       
   409 	}
       
   410 
       
   411 CNewSmsTestCommandParser::CNewSmsTestCommandParser(CTestScript& aScript, CSmsBaseClientTest& aSmsTest) : iSmsTest(aSmsTest), iScript(aScript)
       
   412 	{
       
   413 	}
       
   414 
       
   415 
       
   416 
       
   417 //
       
   418 CSmsBaseUtilitiesParser* CSmsBaseUtilitiesParser::NewL(CSmsBaseClientTest& aSmsTest)
       
   419 	{
       
   420 	CSmsBaseUtilitiesParser* self = new (ELeave) CSmsBaseUtilitiesParser(aSmsTest);
       
   421 	CleanupStack::PushL(self);
       
   422 	self->ConstructL();
       
   423 	CleanupStack::Pop(self);
       
   424 	return self;
       
   425 	}
       
   426 
       
   427 void CSmsBaseUtilitiesParser::ProcessL()
       
   428 	{
       
   429 	TInt howMany;
       
   430 
       
   431 	if ((*iCurrentCommand) == KCommandSmsBegin)
       
   432 		{
       
   433 		iSmsTest.AddStateL(new(ELeave) CSmsBegin(iSmsTest.SmsTestUtils()),iDebugInfo);
       
   434 		}
       
   435 	else if ((*iCurrentCommand) == KCommandSmsCreateMessage)
       
   436 		{
       
   437 		if (iArgumentList->Count() == 4) // If optional howmany is specified
       
   438 			{
       
   439 			TPtrC param = (*iArgumentList)[3];
       
   440 			TLex lex(param);
       
   441 			if (lex.Val(howMany)!=KErrNone)
       
   442 				howMany=1;
       
   443 			}
       
   444 		else
       
   445 			{
       
   446 			howMany = 1;
       
   447 			CheckNumberOfArgumentsL(3);
       
   448 			}
       
   449 		RFs fs;
       
   450 		fs.Connect();
       
   451 		TParse fileName;
       
   452 		ResolveFile(fs, (*iArgumentList)[0], (*iArgumentList)[1], fileName);
       
   453 		fs.Close();
       
   454 		TMsvId folder;
       
   455 		TPtrC folderName = (*iArgumentList)[2];
       
   456 		if (folderName == _L("inbox"))
       
   457 			folder = KMsvGlobalInBoxIndexEntryId;
       
   458 		else if (folderName == _L("outbox"))
       
   459 			folder = KMsvGlobalOutBoxIndexEntryId;
       
   460 		else if (folderName == _L("sent"))
       
   461 			folder = KMsvSentEntryId;
       
   462 		else 
       
   463 			folder = KMsvDraftEntryId;
       
   464 		iSmsTest.AddStateL(new (ELeave) CCreateSmsMessage(folder, iSmsTest.iCurrentServiceId, fileName.FullName(), iSmsTest.SmsTestUtils(),howMany), iDebugInfo);
       
   465 		}
       
   466 	else if ((*iCurrentCommand) == KCommandSmsEnd)
       
   467 		{
       
   468 		iSmsTest.AddStateL(new(ELeave) CSmsEnd(iSmsTest.SmsTestUtils()),iDebugInfo);
       
   469 		}
       
   470 	else
       
   471 		{
       
   472 		User::Leave(KErrNotFound);
       
   473 		}
       
   474 	}
       
   475 
       
   476 void CSmsBaseUtilitiesParser::ConstructL()
       
   477 	{
       
   478 	CBaseCommandParser::ConstructL();
       
   479 	AddCommandL(KCommandSmsBegin);
       
   480 	AddCommandL(KCommandSmsCreateMessage);
       
   481 	AddCommandL(KCommandSmsEnd);
       
   482 	}
       
   483 
       
   484 CSmsBaseUtilitiesParser::CSmsBaseUtilitiesParser(CSmsBaseClientTest& aSmsTest) : iSmsTest(aSmsTest)
       
   485 	{
       
   486 	}
       
   487 
       
   488 
       
   489 //
       
   490 void CSmsBegin::StartL(TRequestStatus& aStatus)
       
   491 	{
       
   492 	iSmsUtils.StartL();
       
   493 	TRequestStatus* status = &aStatus;
       
   494 	User::RequestComplete(status, KErrNone);
       
   495 	}
       
   496 
       
   497 CSmsBegin::CSmsBegin(CSmsTestUtils& aSmsUtils) : iSmsUtils(aSmsUtils)
       
   498 	{}
       
   499 
       
   500 
       
   501 //
       
   502 void CSmsEnd::StartL(TRequestStatus& aStatus)
       
   503 	{
       
   504 //	iSmsUtils.StartL();
       
   505 	TRequestStatus* status = &aStatus;
       
   506 	User::RequestComplete(status, KErrNone);
       
   507 	}
       
   508 
       
   509 CSmsEnd::CSmsEnd(CSmsTestUtils& aSmsUtils) : iSmsUtils(aSmsUtils)
       
   510 	{}
       
   511 
       
   512 
       
   513 //
       
   514 CCreateSmsMessage::CCreateSmsMessage(TMsvId aFolderId, const TMsvId& aServiceId, const TDesC& aFileName, CSmsTestUtils& aSmsUtils,TInt aHowMany) : CActive(EPriorityNormal), iCurrentFolderId(aFolderId), iServiceId(aServiceId), iSmsUtils(aSmsUtils), iHowMany(aHowMany)
       
   515 	{
       
   516 	CActiveScheduler::Add(this);
       
   517 	iFileName = aFileName;
       
   518 	}
       
   519 
       
   520 void CCreateSmsMessage::StartL(TRequestStatus& aStatus)
       
   521 	{
       
   522 	delete iTimer;
       
   523 	iTimer = 0;
       
   524 	iTimer = CTestTimer::NewL();
       
   525 	iReportStatus = &aStatus;
       
   526 	iTimer->AfterReq(5000000, iStatus);
       
   527 	aStatus = KRequestPending;
       
   528 	iState = ECreateSmsWait1;
       
   529 	SetActive();
       
   530 	}
       
   531 
       
   532 void CCreateSmsMessage::RunL()
       
   533 	{
       
   534 	TInt i;
       
   535 	switch (iState)
       
   536 		{
       
   537 		case ECreateSmsWait1:
       
   538 			for (i=0; i<iHowMany; i++)
       
   539 				 CreateMessageL();
       
   540 			iTimer->AfterReq(5000000, iStatus);
       
   541 
       
   542 			iState = ECreateSmsWait2;
       
   543 			SetActive();
       
   544 			break;
       
   545 
       
   546 		case ECreateSmsWait2:
       
   547 			// We should be safely back on the client side so we can continue.
       
   548 			User::RequestComplete(iReportStatus, iStatus.Int());
       
   549 			break;
       
   550 		};
       
   551 	}
       
   552 
       
   553 void CCreateSmsMessage::CreateMessageL()
       
   554 	{
       
   555 	CParaFormatLayer*	paraFormatLayer=CParaFormatLayer::NewL();
       
   556 	CleanupStack::PushL(paraFormatLayer);
       
   557 
       
   558 	CCharFormatLayer*	charFormatLayer=CCharFormatLayer::NewL();
       
   559 	CleanupStack::PushL(charFormatLayer);
       
   560 
       
   561 	CRichText*			bodyText=CRichText::NewL(paraFormatLayer, charFormatLayer, CEditableText::EFlatStorage, 256);
       
   562 	CleanupStack::PushL(bodyText);
       
   563 
       
   564 
       
   565 		CSendAs* sendAs=CSendAs::NewL(*this);
       
   566 		CleanupStack::PushL(sendAs);
       
   567 
       
   568 		sendAs->SetMtmL(KUidMsgTypeSMS);
       
   569 
       
   570 	    if (sendAs->AvailableServices().Count() < 1)
       
   571 		    {
       
   572 			User::Leave(KErrNotFound);
       
   573 			}
       
   574 		sendAs->SetService(0);
       
   575 
       
   576 		sendAs->CreateMessageL(iCurrentFolderId);
       
   577 
       
   578 		TRAPD(err, sendAs->SaveMessageL(ETrue));
       
   579 		if (err != KErrNone)
       
   580 			{
       
   581 			sendAs->AbandonMessage();
       
   582 			}
       
   583 		else
       
   584 			{
       
   585 			TMsvId	messageId=sendAs->MessageId();
       
   586 			iSmsUtils.SetEntryL(messageId);
       
   587 
       
   588 			//Get the new message
       
   589 			CSmsHeader* smsHeader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *bodyText);
       
   590 			CleanupStack::PushL(smsHeader);
       
   591 			CMsvStore*	store = iSmsUtils.EntryL().EditStoreL();
       
   592 			CleanupStack::PushL(store);
       
   593 
       
   594 			smsHeader->RestoreL(*store);
       
   595 
       
   596 			TMsvEntry	entry=iSmsUtils.EntryL().Entry();
       
   597 
       
   598 			entry.SetSendingState(KMsvSendStateSuspended);
       
   599 
       
   600 			TBuf<KSmsDetailsLength>	details;	
       
   601 			if ( TSmsUtilities::GetDetails(iSmsUtils.EntryL().Session().FileSession(), smsHeader->Message(), details) == KErrNone )
       
   602 				{
       
   603 				entry.iDetails.Set(details);
       
   604 				}
       
   605 				
       
   606 			TBuf<KSmsDescriptionLength>	desc;
       
   607 			if ( TSmsUtilities::GetDescription(smsHeader->Message(), desc) == KErrNone )
       
   608 				{
       
   609 				entry.iDescription.Set(desc);
       
   610 				}
       
   611 			entry.SetInPreparation(EFalse);
       
   612 
       
   613 			//	Update entry with data set from .ini file
       
   614 			iSmsUtils.EntryL().ChangeL(entry);
       
   615 			smsHeader->StoreL(*store);
       
   616 
       
   617 			CleanupStack::PopAndDestroy(2, smsHeader);
       
   618 		}
       
   619 		CleanupStack::PopAndDestroy(sendAs);
       
   620 	CleanupStack::PopAndDestroy(3); // bodyText, paraFormatLayer, charFormatLayer
       
   621 	}
       
   622 
       
   623 void CCreateSmsMessage::DoCancel()
       
   624 	{
       
   625 	}
       
   626 
       
   627 CCreateSmsMessage::~CCreateSmsMessage()
       
   628 	{
       
   629 	if (iTimer)
       
   630 		{
       
   631 		iTimer->Cancel();
       
   632 		}
       
   633 	delete iTimer;
       
   634 	}
       
   635 
       
   636