buildverification/autosmoketest/messaging/Src/TestMessCreateSMS.cpp
branchRCL_3
changeset 10 4ca382093dae
parent 5 6beaa9cf4752
child 11 493058e57c8c
equal deleted inserted replaced
5:6beaa9cf4752 10:4ca382093dae
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "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 // This contains CTestMessCreateSMS. This class creates the sms message
       
    15 // for GSM or CDMA. For CDMA mtm, it uses utility classes to create
       
    16 // the respective GSM or CDMA sms message
       
    17 // 
       
    18 //
       
    19 
       
    20 
       
    21 #include "TestMessCreateSMS.h"
       
    22 #include "TestMessEditEntryUtil.h"
       
    23 
       
    24 //Usage of macros of Cdma mtm
       
    25 #include "TestMessCreateGsmSmsUtil.h"
       
    26 #if (defined CDMA_API_ENABLED)
       
    27 #include "TestMessCreateCdmaSmsUtil.h"
       
    28 #endif
       
    29 
       
    30 // EPOC includes
       
    31 #include <mtmuids.h>
       
    32 #include <txtrich.h>
       
    33 #include <smut.h>
       
    34 #include <etelmm.h>
       
    35 #include <smutset.h> //For CSmsMessageSettings
       
    36 
       
    37 /*@{*/
       
    38 // Literal constants read from the ini file
       
    39 _LIT(KRecipients,			"recipients");
       
    40 _LIT(KTo,					"to%d");
       
    41 _LIT(KPtSaveDraft,			"SaveInDraft");
       
    42 _LIT(KDefTo,				"smsto");
       
    43 
       
    44 _LIT(KPtMsgBearerGsm,		"GSM");
       
    45 //Usage of macros for Cdma mtm
       
    46 #if (defined CDMA_API_ENABLED)
       
    47 _LIT(KPtMsgBearerType,		"MessageBearerType");
       
    48 _LIT(KPtMsgBearerCdma,		"CDMA");
       
    49 #endif
       
    50 /*@}*/
       
    51 
       
    52 #if (defined CDMA_API_ENABLED)
       
    53 #define KPtDefaultCount		1
       
    54 #endif
       
    55 
       
    56 CTestMessCreateSMS::CTestMessCreateSMS()
       
    57 :	CTestMessBase(EFalse)
       
    58 ,	iSimInDatabase(EFalse)
       
    59 	{
       
    60 	SetTestStepName(_L("CreateSms"));
       
    61 	}
       
    62 
       
    63 /**
       
    64  Creates the SMS message for GSM or CDMA.
       
    65  @return TVerdict
       
    66 */
       
    67 
       
    68 TVerdict CTestMessCreateSMS::doTestStepPreambleL()
       
    69 	{
       
    70 	TVerdict	ret=CTestMessBase::doTestStepPreambleL();
       
    71 	// IMK iSimInDatabase=(GetPhoneSmsNumberL(iSimPhoneNumber)==KErrNone);
       
    72 	iSimInDatabase=false; //IMK (GetPhoneSmsNumberL(iSimPhoneNumber)==KErrNone);
       
    73 	return ret;
       
    74 	}
       
    75 
       
    76 /**
       
    77  Creates the SMS message for GSM or CDMA.
       
    78  @return TVerdict
       
    79 */
       
    80 TVerdict CTestMessCreateSMS::doTestStepL()
       
    81 	{
       
    82 	//	Get scheduling data
       
    83 	TTimeIntervalMinutes	scheduledTime=ReadScheduleTime();
       
    84 
       
    85 	//create the message
       
    86 	TBool					saveDraft = EFalse;
       
    87 	GetBoolFromConfig(ConfigSection(), KPtSaveDraft, saveDraft);
       
    88 
       
    89 	if ( saveDraft )
       
    90 		{
       
    91 		//Create the message in Draft
       
    92 		CreateSmsL(KMsvDraftEntryId, scheduledTime);
       
    93 		}
       
    94 	else
       
    95 		{
       
    96 		//Creates the message in Outbox
       
    97 		CreateSmsL(KMsvGlobalOutBoxIndexEntryId, scheduledTime);
       
    98 		}
       
    99 
       
   100 	return TestStepResult();
       
   101 	}
       
   102 
       
   103 void CTestMessCreateSMS::CreateSmsL(const TMsvId aMsvId, TTimeIntervalMinutes aScheduledTime)
       
   104 	{
       
   105 	//	Get the bearertype (CDMA/GSM)
       
   106 	TPtrC	messageBearerType;
       
   107 	messageBearerType.Set(KPtMsgBearerGsm);
       
   108 #if (defined CDMA_API_ENABLED)
       
   109 	GetStringFromConfig(ConfigSection(), KPtMsgBearerType, messageBearerType);
       
   110 	INFO_PRINTF2(_L("The message bearertype is : %S"), &messageBearerType);
       
   111 #endif
       
   112 
       
   113 	CTestMessCreateSmsUtilBase*	createSmsUtil = NULL;
       
   114 	//	Create the repective util class
       
   115 	if ( messageBearerType.Compare(KPtMsgBearerGsm)==0 )
       
   116 		{
       
   117 		createSmsUtil=new (ELeave) CTestMessCreateGsmSmsUtil(*this);
       
   118 		}
       
   119 #if (defined CDMA_API_ENABLED)
       
   120 	else if ( messageBearerType.Compare(KPtMsgBearerCdma)==0 )
       
   121 		{
       
   122 		createSmsUtil=new (ELeave) CTestMessCreateCdmaSmsUtil(*this);
       
   123 		}
       
   124 #endif
       
   125 	else
       
   126 		{
       
   127 		WARN_PRINTF1(_L("Unknown bearer type using Gsm"));
       
   128 		createSmsUtil=new (ELeave) CTestMessCreateGsmSmsUtil(*this);
       
   129 		}
       
   130 	CleanupStack::PushL(createSmsUtil);
       
   131 
       
   132 //	All references to PrepareAccountL can be removed when DEF054045 is fixed
       
   133 //	createSmsUtil->PrepareAccountL(*iSession);
       
   134 
       
   135 	if(!iBodyAvailable)
       
   136        {
       
   137 		ERR_PRINTF1(_L("No Body"));
       
   138 		SetTestStepResult(EFail);
       
   139 	   }
       
   140 
       
   141 	if ( TestStepResult()==EPass )
       
   142 		{
       
   143 		TInt	err=KErrNone;
       
   144 		RSendAs			sendAsServer;
       
   145 		User::LeaveIfError(sendAsServer.Connect());
       
   146 		CleanupClosePushL(sendAsServer);
       
   147 		AddMtmCapabilitiesL(sendAsServer);
       
   148 
       
   149 		RSendAsMessage	sendAs;
       
   150 		TRAP(err, sendAs.CreateL(sendAsServer, KUidMsgTypeSMS));
       
   151 		PrepareSendAsL(sendAs);
       
   152 
       
   153 		if ( err!=KErrNone )
       
   154 			{
       
   155 			SetTestStepError(err);
       
   156 			}
       
   157 		else
       
   158 			{
       
   159 			INFO_PRINTF1(_L("sendAs.SetBodyTextL"));
       
   160 			sendAs.SetBodyTextL(*iBodyText);
       
   161 
       
   162 #if (!defined CDMA_API_ENABLED)
       
   163 			TInt	recipients=1;
       
   164 			GetIntFromConfig(ConfigSection(), KRecipients, recipients);
       
   165 
       
   166 			TPtrC	to(iSimPhoneNumber.iTelNumber);
       
   167 			TBool	returnValue=ETrue;
       
   168 			for ( TInt recipient=0; (recipient<recipients) && (TestStepResult()==EPass); )
       
   169 				{
       
   170 				++recipient;
       
   171 
       
   172 				if ( iSimInDatabase )
       
   173 					{
       
   174 					returnValue=ETrue;
       
   175 					}
       
   176 				else
       
   177 					{
       
   178 					TBuf<KMaxTestExecuteCommandLength>	tempStore;
       
   179 					tempStore.Format(KTo(), recipient);
       
   180 					returnValue=GetStringFromConfig(ConfigSection(), tempStore, to);
       
   181 					if ( !returnValue )
       
   182 						{
       
   183 						returnValue=GetStringFromConfig(KDef, KDefTo, to);
       
   184 						}
       
   185 					}
       
   186 				if ( !returnValue )
       
   187 					{
       
   188 					ERR_PRINTF1(_L("No To"));
       
   189 					SetTestStepResult(EFail);
       
   190 					}
       
   191 				else
       
   192 					{
       
   193 					INFO_PRINTF2(_L("To = %S"), &to);
       
   194 					sendAs.AddRecipientL(to, RSendAsMessage::ESendAsRecipientTo);
       
   195 					}
       
   196 				}
       
   197 #endif
       
   198 
       
   199 			TRAP(err, sendAs.SaveMessageAndCloseL());
       
   200 			if ( err!=KErrNone )
       
   201 				{
       
   202 				ERR_PRINTF1(_L("Save Message Failiure"));
       
   203 				SetTestStepResult(EFail);
       
   204 				sendAs.Close();
       
   205 				}
       
   206 			else
       
   207 				{
       
   208 				TMsvId				messageId=KMsvNullIndexEntryId;
       
   209 				CMsvEntry*			parent=iSession->GetEntryL(KMsvDraftEntryIdValue);
       
   210 				CleanupStack::PushL(parent);
       
   211 				parent->SetSortTypeL(SelectionOrdering());
       
   212 				CMsvEntrySelection*	selection=parent->ChildrenL();
       
   213 				CleanupStack::PushL(selection);
       
   214 
       
   215 				if ( selection->Count()>0 )
       
   216 					{
       
   217 					messageId=selection->At(0);
       
   218 					}
       
   219 				if ( messageId!=KMsvNullIndexEntryId )
       
   220 					{
       
   221 					SetEntryL(messageId);
       
   222 					TMsvEntry	child=EntryL().Entry();
       
   223 
       
   224 					//Get the message header
       
   225 					CSmsHeader*	smsHeader = createSmsUtil->NewHeaderL(*iBodyText);
       
   226 					CleanupStack::PushL(smsHeader);
       
   227 
       
   228 					//If message is too big lets concatenate.....
       
   229 					ConCatMessageTextL(*smsHeader);
       
   230 
       
   231 					CMsvStore*	store =NULL;
       
   232 					TRAPD(error, store = EntryL().EditStoreL());
       
   233 					if(error != KErrNone)
       
   234 						{
       
   235 						ERR_PRINTF2(_L("Edit Store Failed. Error %d"), error);
       
   236 						SetTestStepError(error);
       
   237 						}
       
   238 					else
       
   239 						{
       
   240 						CleanupStack::PushL(store);
       
   241 						smsHeader->RestoreL(*store);
       
   242 #if (defined CDMA_API_ENABLED)
       
   243 						//Adding the recipients...
       
   244 						CArrayPtrFlat<CSmsNumber>& recips = smsHeader->Recipients();
       
   245 
       
   246 						TInt	recipients=KPtDefaultCount;
       
   247 						GetIntFromConfig(ConfigSection(), KRecipients, recipients);
       
   248 
       
   249 						TBool	returnValue;
       
   250 						for ( TInt recipient=1; recipient<=recipients; recipient++)
       
   251 							{
       
   252 							TBuf<KMaxTestExecuteCommandLength>	tempStore;	
       
   253 
       
   254 							tempStore.Format(KTo(), recipient);	
       
   255 
       
   256 							TPtrC	to;
       
   257 							returnValue=GetStringFromConfig(ConfigSection(), tempStore, to);
       
   258 							if ( !returnValue )
       
   259 								{
       
   260 								returnValue=GetStringFromConfig(KDef, KDefTo, to);
       
   261 								}
       
   262 							if ( !returnValue )
       
   263 								{
       
   264 								ERR_PRINTF1(_L("No To"));
       
   265 								SetTestStepResult(EFail);
       
   266 								}
       
   267 							else
       
   268 								{
       
   269 								INFO_PRINTF2(_L("To = %S"), &to);
       
   270 
       
   271 								//Get the recipient array
       
   272 								CSmsNumber* newRecip = CSmsNumber::NewL();
       
   273 								CleanupStack::PushL(newRecip);
       
   274 
       
   275 								// Check for the email address in recipient
       
   276 								// This is for email over sms feature
       
   277 								if(to.Locate('@') != KErrNotFound)
       
   278 									{
       
   279 									newRecip->SetAddressL(to, EMsvAddressTypeEMail);
       
   280 									}
       
   281 								else
       
   282 									{
       
   283 									newRecip->SetAddressL(to, EMsvAddressTypeISDN);
       
   284 									}
       
   285 
       
   286 								//Append the recipients
       
   287 								recips.AppendL(newRecip);
       
   288 								CleanupStack::Pop(newRecip);
       
   289 								}
       
   290 							}
       
   291 #endif
       
   292 						child.SetSendingState(KMsvSendStateSuspended);
       
   293 						child.SetInPreparation(EFalse);
       
   294 						child.SetVisible(ETrue);
       
   295 
       
   296 						//Get the details
       
   297 						TBuf<KSmsDetailsLength>	details;
       
   298 
       
   299 //Usage of macros of Cdma mtm
       
   300 #if (!defined CDMA_API_ENABLED)
       
   301 						if ( TSmsUtilities::GetDetails(EntryL().Session().FileSession(), smsHeader->Message(), details) == KErrNone )
       
   302 							{
       
   303 							child.iDetails.Set(details);
       
   304 							}
       
   305 #else
       
   306 						//if ( TSmsUtilities::GetDetails(EntryL().Session().FileSession(), smsHeader->Message(), details) == KErrNone )
       
   307 						CArrayPtrFlat<CSmsNumber>& smsNumberArray = smsHeader->Recipients();
       
   308 						if ( smsNumberArray.Count() )
       
   309 							{
       
   310 							details.Copy(smsNumberArray[0]->Address());
       
   311 							}
       
   312 						if ( details.Length() )
       
   313 							{
       
   314 							child.iDetails.Set(details);
       
   315 							}
       
   316 #endif
       
   317 
       
   318 						//Get the description
       
   319 						TBuf<KSmsDescriptionLength>	desc;
       
   320 						if ( TSmsUtilities::GetDescription(smsHeader->Message(), desc) == KErrNone )
       
   321 							{
       
   322 							child.iDescription.Set(desc);
       
   323 							}
       
   324 
       
   325 						//fill up the fields of the message header
       
   326 						PrepareHeaderL(*createSmsUtil, *smsHeader);
       
   327 
       
   328 						//set the scheduled time if any
       
   329 						if ( aScheduledTime!=TTimeIntervalMinutes(0) )
       
   330 							{
       
   331 							child.SetSendingState(KMsvSendStateScheduled);
       
   332 							child.SetScheduled(ETrue);
       
   333 							child.iDate.UniversalTime();
       
   334 							child.iDate+=aScheduledTime;
       
   335 							}
       
   336 
       
   337 						//	Update entry with data set from .ini file
       
   338 						EntryL().ChangeL(child);
       
   339 						smsHeader->StoreL(*store);
       
   340 						store->CommitL();
       
   341 						CleanupStack::PopAndDestroy(store);
       
   342 
       
   343 						CTestMessEditEntryUtil*	editUtil=new (ELeave) CTestMessEditEntryUtil(*this, ETrue, iSimInDatabase, iSimPhoneNumber);
       
   344 						CleanupStack::PushL(editUtil);
       
   345 						editUtil->ProcessEntryL(EntryL().EntryId());
       
   346 						CleanupStack::PopAndDestroy(editUtil);
       
   347 
       
   348 						if ( aMsvId==KMsvGlobalOutBoxIndexEntryId )
       
   349 							{
       
   350 							// Move the selected message to out box
       
   351 							CTestActive*	active=CTestActive::NewLC(*this);
       
   352 							CMsvOperation*	op=parent->MoveL(child.Id(), KMsvGlobalOutBoxIndexEntryIdValue, active->iStatus);
       
   353 							CleanupStack::PushL(op);
       
   354 							active->Activate();
       
   355 							CActiveScheduler::Start();
       
   356 							CleanupStack::PopAndDestroy(2, active);
       
   357 							}
       
   358 						}
       
   359 					CleanupStack::PopAndDestroy(smsHeader);
       
   360 					}
       
   361 				CleanupStack::PopAndDestroy(2, parent);
       
   362 				}
       
   363 			}
       
   364 
       
   365 		CleanupStack::PopAndDestroy(&sendAsServer);
       
   366 		}
       
   367 	CleanupStack::PopAndDestroy(createSmsUtil);
       
   368 	}
       
   369 
       
   370 void CTestMessCreateSMS::AddMtmCapabilitiesL(RSendAs& aSendAs)
       
   371 	{
       
   372 	aSendAs.ResetMessageFilter();
       
   373 	}
       
   374 
       
   375 void CTestMessCreateSMS::PrepareSendAsL(RSendAsMessage& /*aSendAs*/)
       
   376 	{
       
   377 	}
       
   378 
       
   379 void CTestMessCreateSMS::PrepareHeaderL(CTestMessCreateSmsUtilBase& aCreateUtil, CSmsHeader& aSmsHeader)
       
   380 	{
       
   381 	aCreateUtil.PrepareHeaderL(aSmsHeader);
       
   382 	}
       
   383 
       
   384 //Usage of macro for CDMA mtm
       
   385 #if (defined CDMA_API_ENABLED)
       
   386 void CTestMessCreateSMS::ConCatMessageTextL(CSmsHeader& /*aHeader*/)
       
   387 	{
       
   388 	}
       
   389 #else
       
   390 void CTestMessCreateSMS::ConCatMessageTextL(CSmsHeader& aHeader)
       
   391 	//Doxygen compatible comments
       
   392 	/**
       
   393 		This method Concatenates the long message. Checks for the length of 
       
   394 		body, if it is greater than 160 characters sets the concatenation 
       
   395 		option on for the Sms.
       
   396 
       
   397 		@param aHeader
       
   398 		Header for which the concatenation option is set on... 
       
   399 
       
   400 	*/
       
   401 	{
       
   402 	CSmsSettings*	smsSettings = CSmsSettings::NewL();
       
   403 	CleanupStack::PushL(smsSettings);
       
   404 	//if the length of the iBodyText is greater than the sms maximum length
       
   405 	//i.e 160 chars...Set the Concatenation On....
       
   406 	if( aHeader.Message().MessageLengthL() > aHeader.Message().MaxMessageLength() )
       
   407 		{
       
   408 		INFO_PRINTF1(_L("Concatenate Message..."));
       
   409 		INFO_PRINTF1(_L("Message Exceeds max length setting Concatenate On..."));
       
   410 		aHeader.GetSmsSettingsL(*smsSettings);
       
   411 		smsSettings->SetCanConcatenate(ETrue);
       
   412 		aHeader.SetSmsSettingsL(*smsSettings);
       
   413 		}
       
   414 	CleanupStack::PopAndDestroy(smsSettings);
       
   415 	}
       
   416 #endif