messagingfw/msgtest/testutils/sms/src/SmsTestUtils.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 "smstestutils.h"
       
    17 #include <e32test.h>
       
    18 #include <f32fsys.h>
       
    19 #include <s32file.h>
       
    20 #include <e32uid.h>
       
    21 #include <txtrich.h>
       
    22 #include <txtfmlyr.h>
       
    23 #include <msvids.h>
       
    24 #include <msvuids.h>
       
    25 #include <e32std.h>
       
    26 #include <smuthdr.h>
       
    27 #include <msvsysagentaction.h>
       
    28 #include <smscmds.h>
       
    29 #include <smsclnt.h>
       
    30 #include <smutset.h>
       
    31 #include <msgtestscripts.h>
       
    32 #include <biouids.h>
       
    33 #include <msvschedulesettings.h>
       
    34 #include <commsdattypesv1_1.h>
       
    35 #include <commsdat.h>
       
    36 #include <etelmm.h>
       
    37 #include <logsmspdudata.h>
       
    38 
       
    39 using namespace CommsDat;
       
    40 
       
    41 #include "EmsMsgTestUtils.h"
       
    42 #include "emstestutils.h"
       
    43 #include <csmsaccount.h>
       
    44 #include <msvoffpeaktime.h>
       
    45 
       
    46 #include "CAsyncWaiter.h"
       
    47 
       
    48 #include <mmsvattachmentmanager.h>
       
    49 #include <cmsvattachment.h>
       
    50 
       
    51 #include <e32property.h>
       
    52 
       
    53 // Constants
       
    54 //
       
    55 const TInt KUidNetworkBarsCmtValue=0x100052DB;
       
    56 const TInt KUidCmtPowerValue=0x100052D9;
       
    57 
       
    58 /**
       
    59 	@enum	TSANetworkBarsCmt
       
    60 	Enum defining the system agent network commands
       
    61 	@since	6.1
       
    62 */
       
    63 enum TSANetworkBarsCmt
       
    64 	{
       
    65 	ENBars_0,		//<
       
    66 	ENBars_1,		//<
       
    67 	ENBars_2,		//<
       
    68 	ENBars_3,		//<
       
    69 	ENBars_4,		//<
       
    70 	ECmtPowerOn,	//< Specifies that the power is on
       
    71 	ECmtPowerOff	//< Specifies that the power is off
       
    72 	};
       
    73 
       
    74 /**
       
    75 	@enum	TSACmtPower
       
    76 	Enum defining the system agent commands for power
       
    77 	@since	6.1
       
    78 */
       
    79 enum TSACmtPower
       
    80 	{	
       
    81 	ECmtOn,		//< Specifies that the power is on
       
    82 	ECmtOff		//< Specifies that the power is off
       
    83 	};
       
    84 
       
    85 
       
    86 
       
    87 EXPORT_C CSmsTestUtils::~CSmsTestUtils()
       
    88 	{
       
    89 	Reset();
       
    90 	delete iServiceSettings;
       
    91 	delete iRichText;
       
    92 	delete iCharFormat;
       
    93 	delete iParaFormat;
       
    94 
       
    95 	iRTest.Printf(_L("Waiting 3 seconds for the msg server to close...\n"));
       
    96 	User::After(3000000);
       
    97 	}
       
    98 
       
    99 EXPORT_C void CSmsTestUtils::AddSystemAgentConditionsL()
       
   100 	{
       
   101 	CMsvSysAgentActions* actions = new (ELeave) CMsvSysAgentActions();
       
   102 	CleanupStack::PushL(actions);
       
   103 
       
   104 	CMsvScheduleSettings* schSettings = CMsvScheduleSettings::NewL();
       
   105 	CleanupStack::PushL(schSettings);
       
   106 
       
   107 	CMsvOffPeakTimes* offPeakTimes = new (ELeave) CMsvOffPeakTimes();
       
   108 	CleanupStack::PushL(offPeakTimes);
       
   109 
       
   110 	CMsvSendErrorActions* errorActions = CMsvSendErrorActions::NewL();
       
   111 	CleanupStack::PushL(errorActions);
       
   112 
       
   113 	CSmsAccount* account = CSmsAccount::NewLC();
       
   114 	account->LoadSettingsL(*schSettings, *offPeakTimes, *errorActions, *actions);
       
   115 
       
   116 	actions->iDefault.iAction = ESendActionRetryImmediately;
       
   117 	actions->iDefault.iRetries = ESendRetriesFixed;
       
   118 	actions->iDefault.iRetrySpacing = ESendRetrySpacingStatic;
       
   119 	actions->iDefault.SetMaxRetries(1);
       
   120 
       
   121 	TMsvSysAgentConditionAction condAction;
       
   122 
       
   123 	condAction.iUseDefaultSysAgentAction = ETrue;
       
   124 
       
   125 	condAction.iCondition.iVariable = KMsvTestUidPhonePwr;
       
   126 	condAction.iCondition.iState = EMsvTestPhoneOn;
       
   127 	condAction.iCondition.iType = TMsvCondition::EMsvSchSendEquals;
       
   128 
       
   129 	actions->AppendL(condAction);
       
   130 
       
   131 	condAction.iCondition.iVariable = KMsvTestUidSIMStatus;
       
   132 	condAction.iCondition.iState = EMsvTestSimOk;
       
   133 	condAction.iCondition.iType = TMsvCondition::EMsvSchSendEquals;
       
   134 	
       
   135 	actions->AppendL(condAction);
       
   136 
       
   137 	condAction.iCondition.iVariable = KMsvTestUidNetworkStatus;
       
   138 	condAction.iCondition.iState = EMsvTestNetworkAvailable;
       
   139 	condAction.iCondition.iType = TMsvCondition::EMsvSchSendEquals;
       
   140 	
       
   141 	actions->AppendL(condAction);
       
   142 
       
   143 //	TMsvSendErrorAction action;
       
   144 //	TBool condMet = actions->ConditionsMetL(action);
       
   145 
       
   146 	account->SaveSettingsL(*schSettings, *offPeakTimes, *errorActions, *actions);
       
   147 	CleanupStack::PopAndDestroy(4, account);    	
       
   148 	}
       
   149 
       
   150 /**
       
   151 	@fn				NotifySaPhoneOnL()
       
   152 	Intended Usage	:	To notify the system agent that the phone is on.
       
   153 	@since			6.1
       
   154 	@pre 			None
       
   155 	@post			System agent has been notified.
       
   156  */
       
   157 EXPORT_C void CSmsTestUtils::NotifySaPhoneOnL()
       
   158 	{
       
   159 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KMsvTestUidPhonePwrValue, EMsvTestPhoneOn));
       
   160 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidCmtPowerValue, ECmtOn));
       
   161 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidNetworkBarsCmtValue, ECmtPowerOn));
       
   162 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, 0x100052E7, 8));
       
   163 	}
       
   164 
       
   165 /**
       
   166 	@fn				NotifySaPhoneOffL()
       
   167 	Intended Usage	:	To notify the system agent that the phone is off.
       
   168 	@since			6.2
       
   169 	@pre 			None
       
   170 	@post			System agent has been notified.
       
   171  */
       
   172 EXPORT_C void CSmsTestUtils::NotifySaPhoneOffL()
       
   173 	{
       
   174 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KMsvTestUidPhonePwrValue, EMsvTestPhoneOff));
       
   175 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidCmtPowerValue, ECmtOff));
       
   176 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidNetworkBarsCmtValue, ECmtPowerOff));
       
   177 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, 0x100052E7, 8));
       
   178 	}
       
   179 
       
   180 EXPORT_C void CSmsTestUtils::WaitForInitializeL()
       
   181 /**
       
   182 	Initialize the phone for the tsy. This will prevent message sends from completing with KErrNotReady
       
   183 */
       
   184 	{
       
   185 
       
   186 	TName tsy;
       
   187 	
       
   188 	CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion());
       
   189 	CleanupStack::PushL(dbSession);
       
   190 	
       
   191 	CMDBRecordSet<CCDGlobalSettingsRecord> globalSettingsRecord(KCDTIdGlobalSettingsRecord);
       
   192 	TRAPD(err, globalSettingsRecord.LoadL(*dbSession));
       
   193 	if(err != KErrNone)
       
   194 		{
       
   195 		User::Leave(KErrNotFound);				
       
   196 		}
       
   197 		
       
   198 	CCDModemBearerRecord *modemRecord = static_cast<CCDModemBearerRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdModemBearerRecord));		
       
   199 	CleanupStack::PushL(modemRecord);	
       
   200 	modemRecord->SetRecordId(((CCDGlobalSettingsRecord*)globalSettingsRecord.iRecords[0])->iModemForPhoneServicesAndSMS); 
       
   201 	modemRecord->LoadL(*dbSession);
       
   202 	tsy = modemRecord->iTsyName;	
       
   203 	CleanupStack::PopAndDestroy(2); //dbSession, modemRecord
       
   204 
       
   205 	RTelServer server;
       
   206 	User::LeaveIfError(server.Connect());
       
   207 	CleanupClosePushL(server);
       
   208 	User::LeaveIfError(server.LoadPhoneModule(tsy));
       
   209 
       
   210 	// Find the phone corresponding to this TSY and open a number of handles on it
       
   211 	TInt numPhones;
       
   212 	User::LeaveIfError(server.EnumeratePhones(numPhones));
       
   213 	RPhone phone;
       
   214 
       
   215 	while (numPhones--)
       
   216 		{
       
   217 		TName phoneTsy;
       
   218 		User::LeaveIfError(server.GetTsyName(numPhones,phoneTsy));
       
   219 		if (phoneTsy.CompareF(tsy)==KErrNone)
       
   220 			{
       
   221 			RTelServer::TPhoneInfo info;
       
   222 			User::LeaveIfError(server.GetPhoneInfo(numPhones,info));
       
   223 			User::LeaveIfError(phone.Open(server,info.iName));
       
   224 			CleanupClosePushL(phone);
       
   225 			const TInt err = phone.Initialise();
       
   226 			User::LeaveIfError(err);
       
   227 			CleanupStack::PopAndDestroy(&phone);
       
   228 			break;
       
   229 			}
       
   230 		}
       
   231 
       
   232 	CleanupStack::PopAndDestroy(&server);
       
   233 	}
       
   234 
       
   235 EXPORT_C CSmsTestUtils* CSmsTestUtils::NewL(RTest& aRTest, TUint aCreationFlags)
       
   236 	{
       
   237 	CSmsTestUtils* self = NewLC(aRTest, aCreationFlags);
       
   238 	CleanupStack::Pop();
       
   239 	return self;
       
   240 	}
       
   241 
       
   242 EXPORT_C CSmsTestUtils* CSmsTestUtils::NewLC(RTest& aRTest, TUint aCreationFlags)
       
   243 	{
       
   244 	CSmsTestUtils* self = new(ELeave) CSmsTestUtils(aRTest);
       
   245 	CleanupStack::PushL(self);
       
   246 	self->ConstructL(aCreationFlags);
       
   247 	return self;
       
   248 	}
       
   249 
       
   250 void CSmsTestUtils::Reset()
       
   251 	{
       
   252 	if (iSmsClientMtm)
       
   253 		{
       
   254 		delete iSmsClientMtm;
       
   255 		iSmsClientMtm=NULL;
       
   256 //		iMsvEntry=NULL;
       
   257 		}
       
   258 
       
   259 	CMsvTestUtils::Reset();
       
   260 	}
       
   261 
       
   262 //
       
   263 // Register a Sms Mtm server DLL
       
   264 //
       
   265 EXPORT_C void CSmsTestUtils::CreateSmsServerMtmRegL()
       
   266 	{
       
   267 	CreateServerMtmRegL(KUidMsgTypeSMS, _L("SMS"), KSmsServerMtmFileName(), KSmsClientMtmFileName(), TMsvTestDllInfo(KSmsUiMtmFileFileName,2), TMsvTestDllInfo(KSmsUiMtmFileFileName,1), KUidMsgTypeSMS, KSmsDataComponentFileName);
       
   268 	}
       
   269 
       
   270 EXPORT_C TMsvId CSmsTestUtils::CreateSmsServiceL()
       
   271 	{
       
   272 	// create service in root
       
   273 	TInt err = KErrNone;
       
   274 	iSmsServiceId = 0;
       
   275 	TRAP(err, ServiceIdL(KUidMsgTypeSMS, iSmsServiceId));
       
   276 
       
   277 	if (err)
       
   278 		{
       
   279 		if (!iServiceSettings)
       
   280 			{
       
   281 			iServiceSettings = CSmsSettings::NewL();
       
   282 			}
       
   283 	
       
   284 		CSmsAccount* account = CSmsAccount::NewLC();
       
   285 		account->InitialiseDefaultSettingsL(*iServiceSettings);
       
   286 		ServiceIdL(KUidMsgTypeSMS, iSmsServiceId);
       
   287 			
       
   288 		iServiceSettings->SetValidityPeriod(ESmsVPWeek);	// week
       
   289 		iServiceSettings->SetValidityPeriodFormat(TSmsFirstOctet::ESmsVPFInteger); //relative
       
   290 		iServiceSettings->AddServiceCenterL(_L("Vodafone"), _L("+4477850016005"));
       
   291 		iServiceSettings->AddServiceCenterL(_L("Sonera"), _L("+358405202000"));
       
   292 		iServiceSettings->SetDefaultServiceCenter(1);
       
   293 		iServiceSettings->SetReplyQuoted(EFalse);
       
   294 		iServiceSettings->SetRejectDuplicate(ETrue);
       
   295 		iServiceSettings->SetDelivery(ESmsDeliveryImmediately);
       
   296 		iServiceSettings->SetDeliveryReport(ETrue);
       
   297 		iServiceSettings->SetReplyPath(EFalse);
       
   298 		iServiceSettings->SetMessageConversion(ESmsConvPIDNone);
       
   299 		iServiceSettings->SetCanConcatenate(ETrue);
       
   300 
       
   301 		account->SaveSettingsL(*iServiceSettings);
       
   302 		
       
   303 		CMsvScheduleSettings* schSettings = CMsvScheduleSettings::NewL();
       
   304 		CleanupStack::PushL(schSettings);
       
   305 
       
   306 		CMsvOffPeakTimes* offPeakTimes = new (ELeave) CMsvOffPeakTimes();
       
   307 		CleanupStack::PushL(offPeakTimes);
       
   308 
       
   309 		CMsvSendErrorActions* errorActions = CMsvSendErrorActions::NewL();
       
   310 		CleanupStack::PushL(errorActions);
       
   311 
       
   312 		CMsvSysAgentActions* sysAgentActions = new (ELeave) CMsvSysAgentActions();
       
   313 		CleanupStack::PushL(sysAgentActions);
       
   314 		
       
   315 		account->LoadSettingsL(*schSettings, *offPeakTimes, *errorActions, *sysAgentActions);
       
   316 
       
   317 		schSettings->SetLongInterval(30);
       
   318 		schSettings->SetShortInterval(10);
       
   319 
       
   320 		account->SaveSettingsL(*schSettings, *offPeakTimes, *errorActions, *sysAgentActions);
       
   321 
       
   322 		CleanupStack::PopAndDestroy(5, account);    	
       
   323 		}
       
   324 	else
       
   325 		{
       
   326 		User::Leave(KErrAlreadyExists);
       
   327 		}
       
   328 
       
   329 	return iSmsServiceId;
       
   330 	}
       
   331 
       
   332 
       
   333 EXPORT_C void CSmsTestUtils::InstallSmsMtmGroupL()
       
   334 	{
       
   335 	InstallMtmGroupL(KSmsDataComponentFileName);
       
   336 	}
       
   337 
       
   338 EXPORT_C void CSmsTestUtils::InstantiateSmsClientMtmL()
       
   339 	{
       
   340 	__ASSERT_ALWAYS(iSmsServiceId, Panic(KSmsTestUtilsPanicSmsServiceIdNotSet));
       
   341 	delete iSmsClientMtm;
       
   342 	iSmsClientMtm = NULL;
       
   343 	iSmsClientMtm = (CSmsClientMtm*) InstantiateClientMtmL(KUidMsgTypeSMS, iSmsServiceId);
       
   344 	}
       
   345 
       
   346 EXPORT_C CSmsTestUtils::CSmsTestUtils(RTest& aRTest)
       
   347 : CMsvTestUtils(aRTest), iSmsServiceId(KMsvNullIndexEntryId), iSmokeTest(EFalse)
       
   348 	{
       
   349 	}
       
   350 
       
   351 EXPORT_C void CSmsTestUtils::ConstructL(TUint aFlags)
       
   352 	{
       
   353 	CMsvTestUtils::ConstructL(aFlags);
       
   354 
       
   355 
       
   356 	iParaFormat = CParaFormatLayer::NewL();
       
   357 	iCharFormat = CCharFormatLayer::NewL();
       
   358 	iRichText = CRichText::NewL(iParaFormat, iCharFormat);
       
   359 	}
       
   360 
       
   361 EXPORT_C void CSmsTestUtils::SaveBodyToFileL(TMsvId aId)
       
   362 	{
       
   363 	SetEntryL(aId);
       
   364 
       
   365 	CMsvStore* store = ReadStoreL();
       
   366 	CleanupStack::PushL(store);
       
   367 		
       
   368 	iRichText->Reset();
       
   369 	store->RestoreBodyTextL(*iRichText);
       
   370 
       
   371 	CleanupStack::PopAndDestroy(store);
       
   372 
       
   373 	const TInt length = iRichText->DocumentLength();
       
   374 		
       
   375 	HBufC* buf = HBufC::NewLC(length);
       
   376 	HBufC8* buf8 = HBufC8::NewLC(length);
       
   377 
       
   378 	TPtr bufPtr(buf->Des());
       
   379 
       
   380 	iRichText->Extract(bufPtr);
       
   381 	buf8->Des().Copy(*buf);
       
   382 	TFileName path;
       
   383 
       
   384 
       
   385 	TInt bioType = Entry().iBioType;
       
   386 	path.AppendNum((TUint)Entry().Id());
       
   387 	path.Append(_L("-"));
       
   388 	path.AppendNum(bioType);
       
   389 	path.Append(_L(".body"));
       
   390 	
       
   391 	// Remove any attachments with the same name
       
   392 	if (iClientServer == EClientSide)
       
   393 		{
       
   394 		store = iMsvEntry->EditStoreL();
       
   395 		}
       
   396 	else if (iClientServer == EServerSide)
       
   397 		{
       
   398 		store = iServerEntry->EditStoreL();
       
   399 		}
       
   400 	else
       
   401 		{
       
   402 		User::Leave(KErrNotSupported);
       
   403 		}
       
   404 	CleanupStack::PushL(store);
       
   405 	
       
   406 	CAsyncWaiter* waiter = CAsyncWaiter::NewL();
       
   407 	CleanupStack::PushL(waiter);
       
   408 	MMsvAttachmentManager& manager = store->AttachmentManagerL();
       
   409 	for(TInt ii=0; ii<manager.AttachmentCount(); ++ii )
       
   410 		{
       
   411 		
       
   412 
       
   413 		CMsvAttachment* attachment = manager.GetAttachmentInfoL(ii);
       
   414 		CleanupStack::PushL(attachment);
       
   415 		if( attachment->AttachmentName().CompareF(path) == 0 )
       
   416 			{
       
   417 			CTestActive* testActive = new (ELeave) CTestActive();
       
   418 			CleanupStack::PushL(testActive);
       
   419 			
       
   420 			// found a matching attachment, remove it
       
   421 			manager.RemoveAttachmentL(ii, waiter->iStatus);
       
   422 			waiter->StartAndWait();
       
   423 			User::LeaveIfError(waiter->Result());			
       
   424 			}
       
   425 		CleanupStack::PopAndDestroy(attachment);
       
   426 		
       
   427 		}
       
   428 	
       
   429 	// create a new attachment file
       
   430 	CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
       
   431 	CleanupStack::PushL(attachment);
       
   432 	attachment->SetSize(buf->Length());
       
   433 	attachment->SetAttachmentNameL(path);
       
   434 	RFile file;
       
   435 	manager.CreateAttachmentL(path, file, attachment, waiter->iStatus);
       
   436 	CleanupStack::Pop(attachment); // ownership passed
       
   437 	waiter->StartAndWait();
       
   438 	User::LeaveIfError(waiter->Result());		
       
   439 
       
   440 	CleanupClosePushL(file);
       
   441 
       
   442 	file.Write(*buf8);
       
   443 	file.Flush();
       
   444 
       
   445 	CleanupStack::PopAndDestroy(5, buf); // file, waiter, store, buf8, buf
       
   446 	}
       
   447 
       
   448 
       
   449 
       
   450 void CSmsTestUtils::DisplayChildDetailsL(const TMsvEntry& aEntry)
       
   451 	{
       
   452 	iRTest.Printf(KMsvTestUtilsNewLine);
       
   453 	DisplayChildL(aEntry);
       
   454 	iRTest.Printf(KMsvTestUtilsNewLine);
       
   455 
       
   456 	if ((aEntry.iMtm != KUidMsgTypeSMS && aEntry.iMtm != KUidBIOMessageTypeMtm) || aEntry.iType != KUidMsvMessageEntry)
       
   457 		return;
       
   458 
       
   459 	CMsvEntry* cEntry = iMsvSession->GetEntryL(aEntry.Id());
       
   460 	CleanupStack::PushL(cEntry);
       
   461 
       
   462 	CSmsHeader* header = DoGetHeaderLC(*cEntry);
       
   463 
       
   464 	TBuf<256> temp;
       
   465 	temp.Append(_L("\tType: SMS "));
       
   466 
       
   467 	switch (header->Type())
       
   468 		{
       
   469 		case CSmsPDU::ESmsDeliver:
       
   470 			temp.Append(_L("Deliver\n"));
       
   471 			break;
       
   472 		case CSmsPDU::ESmsSubmit:
       
   473 			temp.Append(_L("Submit\n"));
       
   474 			break;
       
   475 		case CSmsPDU::ESmsDeliverReport:
       
   476 			temp.Append(_L("Deliver Report\n"));
       
   477 			break;
       
   478 		case CSmsPDU::ESmsSubmitReport:
       
   479 			temp.Append(_L("Submit Report\n"));
       
   480 			break;
       
   481 		default:
       
   482 			temp.Append(_L("Other\n"));
       
   483 			break;
       
   484 		}
       
   485 
       
   486 	iRTest.Printf(temp);
       
   487 	temp.Zero();
       
   488 
       
   489 	iRTest.Printf(_L("\tBio Type UID: %d\n"), aEntry.iBioType);
       
   490 	iRTest.Printf(_L("\tSending State: %d\n"), aEntry.SendingState());
       
   491 
       
   492 	if (header->Type() == CSmsPDU::ESmsDeliver)
       
   493 		{
       
   494  		CSmsDeliver& pdu = header->Deliver();
       
   495 
       
   496 		TBool found = EFalse;
       
   497 		TInt destination, originator, is16Bit;
       
   498 		destination = originator = is16Bit = 0;
       
   499 		if (pdu.UserDataPresent())
       
   500 			{
       
   501 			const CSmsUserData& userData = pdu.UserData();
       
   502 			TInt count = userData.NumInformationElements();
       
   503 			iRTest.Printf(_L("\tPdu contains %d information elements\n"), count);
       
   504 			while (!found && count--)
       
   505 				{
       
   506 				CSmsInformationElement& nextIE=userData.InformationElement(count);
       
   507 				switch(nextIE.Identifier())
       
   508 					{
       
   509 					case CSmsInformationElement::ESmsIEIApplicationPortAddressing8Bit:
       
   510 					case CSmsInformationElement::ESmsIEIApplicationPortAddressing16Bit:
       
   511 						{
       
   512 						pdu.ApplicationPortAddressing(destination, originator, &is16Bit);
       
   513 						found = ETrue;
       
   514 						break;
       
   515 						}
       
   516 					default:
       
   517 						break;
       
   518 					}
       
   519 				}
       
   520 			}
       
   521 		if (found)
       
   522 			iRTest.Printf(_L("\tApplication Port Addressing: Dest %d, Origin %d, is16Bit %d\n"), destination, originator, is16Bit);
       
   523 		else
       
   524 			iRTest.Printf(_L("\tApplication Port Addressing: Not Found\n"));
       
   525 		}
       
   526 
       
   527 	CleanupStack::PopAndDestroy(header);
       
   528 	CleanupStack::PopAndDestroy(cEntry);
       
   529 
       
   530 	iRTest.Printf(_L("\n'S'ave or any other key...\n"));
       
   531 	TChar key = iRTest.Getch();
       
   532 
       
   533 	if (key == 's' || key == 'S')
       
   534 		{
       
   535 		TRAPD(err, SaveBodyToFileL(aEntry.Id()));
       
   536 
       
   537 		if (!err)
       
   538 			iRTest.Printf(_L("\nMessage body saved OK\n"));
       
   539 		else
       
   540 			iRTest.Printf(_L("\nSave ERROR %d\n"), err);
       
   541 
       
   542 		iRTest.Getch();
       
   543 		}
       
   544 	}
       
   545 
       
   546 EXPORT_C void CSmsTestUtils::DisplayMessagesL(const CMsvEntrySelection& aSelection)
       
   547 	{
       
   548 	TInt count = aSelection.Count();
       
   549 	
       
   550 	for (TInt i = 0; i < count; i++)
       
   551 		{
       
   552 		DisplayMessageL(aSelection[i]);
       
   553 		}
       
   554 	}
       
   555 
       
   556 EXPORT_C void CSmsTestUtils::DisplayMessageL(TMsvId aId)
       
   557 	{
       
   558 	SetEntryL(aId);
       
   559 	CSmsHeader* header = GetHeaderLC(aId);
       
   560 
       
   561 	HBufC* buf = HBufC::NewLC(100 + Entry().iDetails.Length() + Entry().iDescription.Length());
       
   562 	TPtr temp(buf->Des());
       
   563 
       
   564 	temp.AppendNum((TInt) aId);
       
   565 	temp.Append(_L(" Type: "));
       
   566 
       
   567 	switch (header->Type())
       
   568 		{
       
   569 		case CSmsPDU::ESmsDeliver:
       
   570 			temp.Append(_L("Deliver"));
       
   571 			break;
       
   572 		case CSmsPDU::ESmsSubmit:
       
   573 			temp.Append(_L("Submit "));
       
   574 			break;
       
   575 		case CSmsPDU::ESmsSubmitReport:
       
   576 			temp.Append(_L("SubRprt"));
       
   577 			break;
       
   578 		case CSmsPDU::ESmsDeliverReport:
       
   579 			temp.Append(_L("DelRprt"));
       
   580 			break;
       
   581 		default:
       
   582 			temp.Append(_L("Other  "));
       
   583 			break;
       
   584 		}
       
   585 
       
   586 	temp.Append(_L(" Rcpts: "));
       
   587 	temp.AppendNum(header->Recipients().Count());
       
   588 	temp.Append(_L(" Det: \""));
       
   589 	temp.Append(Entry().iDetails);
       
   590 	temp.Append(_L("\" Desc: \""));
       
   591 	temp.Append(Entry().iDescription);
       
   592 	temp.Append(_L("\"\n"));
       
   593 	Printf(*buf);
       
   594 
       
   595 	CleanupStack::PopAndDestroy(buf);
       
   596 	CleanupStack::PopAndDestroy(header);	
       
   597 	}
       
   598 
       
   599 EXPORT_C TBool CSmsTestUtils::ReadScriptL(const TDesC& aFile, TMsvId aDestFolder, CMsvEntrySelection& aSelection, const TTime& aDate)
       
   600 	{
       
   601 	TParse fileOut;
       
   602 
       
   603 	User::LeaveIfError(ResolveFile(KSmsComponent, aFile, fileOut));
       
   604 
       
   605 	return DoReadScriptL(fileOut.FullName(), aDestFolder, aSelection, aDate);
       
   606 	}
       
   607 
       
   608 TBool CSmsTestUtils::DoReadScriptL(const TDesC& aFile, TMsvId aDestFolder, CMsvEntrySelection& aSelection, const TTime& aDate)
       
   609 	{
       
   610 	CScriptFile* scriptFile = CScriptFile::NewLC(*this, KSmsComponent, aFile);
       
   611 	TBool retVal = CreateMessagesL(aDestFolder, *scriptFile, aSelection, aDate);
       
   612 	CleanupStack::PopAndDestroy(scriptFile);
       
   613 	return retVal;
       
   614 	}
       
   615 
       
   616 TBool CSmsTestUtils::CreateMessagesL(TMsvId aDestFolder, CScriptFile& rFile, CMsvEntrySelection& rSelection, const TTime& aDate)
       
   617 	{
       
   618 	CArrayPtrFlat<CScriptSection>& sections = rFile.Sections();
       
   619 
       
   620 	TBool retVal = EFalse;
       
   621 
       
   622 	if (!sections.Count())
       
   623 		return EFalse;
       
   624 
       
   625 	const TInt secCount = sections.Count();
       
   626 	TInt count = secCount;
       
   627 	TInt all = KErrNotFound;
       
   628 	CScriptSection* section = NULL;
       
   629 
       
   630 	while (count--)
       
   631 		{
       
   632 		section = sections[count];
       
   633 		if (section->SectionName().CompareF(_L("All")) == 0)
       
   634 			{
       
   635 			all = count;
       
   636 			break;
       
   637 			}
       
   638 		}
       
   639 
       
   640 	count = secCount;
       
   641 
       
   642 	for(TInt item = 0; item < count; item++)
       
   643 		{
       
   644 		section = sections[item];
       
   645 
       
   646 		if (item == all)
       
   647 			{
       
   648 			continue;
       
   649 			}
       
   650 
       
   651 		TPtrC typePtr(section->ItemValue(KScriptItemMessageType, KScriptItemSubmit));  //  CJCW
       
   652 		TPtrC classPtr(section->ItemValue(KScriptItemMessageClass, KScriptItemClassDefault));  //  CJCW
       
   653 		TPtrC scPtr(section->ItemValue(KScriptItemSC, KScriptItemSCDef));
       
   654 		TPtrC rcptsPtr(section->ItemValue(KScriptItemRecipients, KScriptItemRecipientsDef));
       
   655 		TInt bioId(section->ItemValue(KScriptItemBioUid, KScriptItemBioUidDef));
       
   656 		TInt encoding(section->ItemValue(KScriptItemEncoding, KScriptItemEncodingDef));
       
   657 		TPtrC drPtr(section->ItemValue(KScriptItemDeliveryReport, KScriptItemDeliveryReportDef));
       
   658 		TPtrC bearerPtr(section->ItemValue(KScriptItemBearer, KScriptItemBearerDef));
       
   659 		TPtrC msgPtr(section->ItemValue(KScriptItemMessage, KNullDesC));
       
   660 		TPtrC filePtr(section->ItemValue(KScriptItemFile, KNullDesC));
       
   661 
       
   662 		TBioMsgIdType bearer = EBioMsgIdNbs;
       
   663 
       
   664 		if (bearerPtr.CompareF(_L("wap")) == 0)
       
   665 			{
       
   666 			bearer = EBioMsgIdWap;
       
   667 			}
       
   668 		else if (bearerPtr.CompareF(_L("wapsecure")) == 0)
       
   669 			{
       
   670 			bearer = EBioMsgIdWapSecure;
       
   671 			}
       
   672 
       
   673 		TSmsDataCodingScheme::TSmsAlphabet alpha = TSmsDataCodingScheme::ESmsAlphabet7Bit;
       
   674 
       
   675 		switch (encoding)
       
   676 			{
       
   677 			case 7:
       
   678 				alpha = TSmsDataCodingScheme::ESmsAlphabet7Bit;
       
   679 				break;
       
   680 			case 8:
       
   681 				alpha = TSmsDataCodingScheme::ESmsAlphabet8Bit;
       
   682 				break;
       
   683 			case 16:
       
   684 				alpha = TSmsDataCodingScheme::ESmsAlphabetUCS2;
       
   685 				break;
       
   686 			default:
       
   687 				alpha = TSmsDataCodingScheme::ESmsAlphabet7Bit;
       
   688 				break;
       
   689 			}
       
   690 
       
   691 		TBool changeDR = ETrue;
       
   692 		TBool deliveryReport = EFalse;
       
   693 
       
   694 		if (drPtr.CompareF(_L("NO")) == 0)
       
   695 			{
       
   696 			deliveryReport = EFalse;
       
   697 			}
       
   698 		else if (drPtr.CompareF(_L("YES")) == 0)
       
   699 			{
       
   700 			deliveryReport = ETrue;
       
   701 			}
       
   702 		else
       
   703 			{
       
   704 			changeDR = EFalse;
       
   705 			}
       
   706 
       
   707 		if (filePtr.Length())
       
   708 			{
       
   709 			HBufC8* tempMsg = NULL;
       
   710 			TRAPD(resErr, tempMsg = ReadFileLC(filePtr));
       
   711 
       
   712 			if (resErr)
       
   713 				{
       
   714 				TParse fileOut;
       
   715 				resErr = ResolveFile(KSmsComponent, filePtr, fileOut);
       
   716 
       
   717 				if (resErr)
       
   718 					{
       
   719 					Printf(_L("Cannot resolve file %S\n"), &filePtr);
       
   720 					User::Leave(resErr);
       
   721 					}
       
   722 
       
   723 				tempMsg = ReadFileLC(fileOut.FullName());
       
   724 				}
       
   725 
       
   726 			HBufC* msgVal = HBufC::NewLC(tempMsg->Length());
       
   727 			msgVal->Des().Copy(*tempMsg);
       
   728 			section->ReplaceItemL(KScriptItemMessage, *msgVal);
       
   729 			CleanupStack::PopAndDestroy(2); //tempMsg, msgVal
       
   730 			msgPtr.Set(section->ItemValue(KScriptItemMessage, KNullDesC));
       
   731 			}
       
   732 
       
   733 		if (msgPtr.Length())
       
   734 			{
       
   735 			//Replace LF with CRLF for vCards and vCals only
       
   736 			if (bioId == KVCardBioUid.iUid || bioId == KVCalBioUid.iUid || msgPtr.Left(5) == _L("//SCK"))
       
   737 				{
       
   738 				CScriptSectionItem* sectionItem = section->Item(KScriptItemMessage);
       
   739 
       
   740 				__ASSERT_ALWAYS(sectionItem, Panic(KErrNotFound));
       
   741 
       
   742 				CScriptFile::ReplaceL(KScriptCRLF, KScriptLF, sectionItem->iValue);
       
   743 				CScriptFile::ReplaceL(KScriptLF, KScriptCRLF, sectionItem->iValue);
       
   744 				TInt valLen = sectionItem->Value().Length();
       
   745 				sectionItem->iValue = sectionItem->iValue->ReAllocL(valLen + 2);
       
   746 				sectionItem->iValue->Des().Append(KScriptCRLF);
       
   747 				}
       
   748 
       
   749 			TLex input(rcptsPtr);
       
   750 			TPtrC rcpt;
       
   751 			TInt curRcpt = 0;
       
   752 			TMsvEntry entry;
       
   753 			
       
   754 			while (CScriptFile::GetNextWord(input, '|', rcpt) == KErrNone)
       
   755 				{
       
   756 				if (rcpt.CompareF(KDefault1) == 0 || rcpt.CompareF(KDefault2) == 0)
       
   757 					{
       
   758 					CScriptSection* defaults = section->Defaults();
       
   759 					if (defaults != NULL)
       
   760 						{
       
   761 						rcpt.Set(defaults->ItemValue(KScriptItemRecipients, KScriptItemRecipientsDef));
       
   762 						}
       
   763 					}
       
   764 
       
   765 				retVal = ETrue;
       
   766 
       
   767 				if (!curRcpt)
       
   768 					{
       
   769 					entry = TMsvEntry();
       
   770 					entry.iBioType = bioId;
       
   771 					entry.SetSendingState(KMsvSendStateUponRequest);
       
   772 
       
   773 					CSmsPDU::TSmsPDUType type=CSmsPDU::ESmsSubmit;
       
   774 					if (typePtr.CompareF(KScriptItemSubmit) == 0)  //  CJCW
       
   775 						type=CSmsPDU::ESmsSubmit;
       
   776 					else if (typePtr.CompareF(KScriptItemDeliver) == 0)
       
   777 						type=CSmsPDU::ESmsDeliver;
       
   778 					else if (typePtr.CompareF(KScriptItemStatusReport) == 0)
       
   779 						type=CSmsPDU::ESmsStatusReport;
       
   780 					else if (typePtr.CompareF(KScriptItemSubmit) == 0)
       
   781 						type=CSmsPDU::ESmsCommand;
       
   782 					else
       
   783 						User::Leave(KErrNotSupported);
       
   784 
       
   785 					CSmsHeader* header = CSmsHeader::NewL(type, *iRichText);  //  CJCW
       
   786 					CleanupStack::PushL(header);
       
   787 
       
   788 					iRichText->Reset();
       
   789 					if (msgPtr.Length())
       
   790 						{
       
   791 						if (type==CSmsPDU::ESmsStatusReport)
       
   792 							{
       
   793 							CSmsStatusReport& statusreport=header->StatusReport();
       
   794 							statusreport.SetParameterIndicatorPresent(ETrue);
       
   795 							statusreport.SetDataCodingSchemePresent(ETrue);
       
   796 							statusreport.SetUserDataPresent(ETrue);
       
   797 							}
       
   798 						iRichText->InsertL(0, msgPtr);
       
   799 						}
       
   800 
       
   801 					__ASSERT_ALWAYS(iServiceSettings, Panic(KSmsTestUtilsPanicSettingsNotConstructed));
       
   802 
       
   803 					header->SetSmsSettingsL(*iServiceSettings);
       
   804 
       
   805 					if (type==CSmsPDU::ESmsSubmit || type==CSmsPDU::ESmsDeliver)
       
   806 						{
       
   807 						CSmsPDU& pdu=header->Message().SmsPDU();
       
   808 						if (classPtr.CompareF(KScriptItemClassDefault)==0)
       
   809 							pdu.SetClass(EFalse,TSmsDataCodingScheme::ESmsClass0);
       
   810 						else if (classPtr.CompareF(KScriptItemClass0)==0)
       
   811 							pdu.SetClass(ETrue,TSmsDataCodingScheme::ESmsClass0);
       
   812 						else if (classPtr.CompareF(KScriptItemClass1)==0)
       
   813 							pdu.SetClass(ETrue,TSmsDataCodingScheme::ESmsClass1);
       
   814 						else if (classPtr.CompareF(KScriptItemClass2)==0)
       
   815 							pdu.SetClass(ETrue,TSmsDataCodingScheme::ESmsClass2);
       
   816 						else if (classPtr.CompareF(KScriptItemClass3)==0)
       
   817 							pdu.SetClass(ETrue,TSmsDataCodingScheme::ESmsClass3);
       
   818 						}
       
   819 
       
   820 					if (changeDR)
       
   821 						{
       
   822 						switch (header->Type())
       
   823 							{
       
   824 							case CSmsPDU::ESmsSubmit:
       
   825 								{
       
   826 								header->Submit().SetStatusReportRequest(deliveryReport);
       
   827 								break;
       
   828 								}
       
   829 							case CSmsPDU::ESmsCommand:
       
   830 								{
       
   831 								header->Command().SetStatusReportRequest(deliveryReport);
       
   832 								break;
       
   833 								}
       
   834 							default:
       
   835 								User::Leave(KErrNotSupported);
       
   836 							};
       
   837 						}
       
   838 
       
   839 					header->SetBioMsgIdType(bearer);
       
   840 
       
   841 					if (scPtr.CompareF(KScriptItemSCUseDefault) == 0)
       
   842 						{
       
   843 						header->Message().SetServiceCenterAddressL(TPtrC());
       
   844 						}
       
   845 					else
       
   846 						{
       
   847 						header->Message().SetServiceCenterAddressL(scPtr);
       
   848 						}
       
   849 
       
   850 					// Extract the EMS objects
       
   851 					CEmsExtractor* ems = CEmsExtractor::NewLC(*section);
       
   852 					ems->AddToMessageL(header->Message());
       
   853 					CleanupStack::PopAndDestroy(ems);
       
   854 
       
   855 					CSmsPDU& pdu=header->Message().SmsPDU();
       
   856 					if (pdu.DataCodingSchemePresent())
       
   857 						pdu.SetAlphabet(alpha);
       
   858 					
       
   859 					TMsvId destfolder=aDestFolder;
       
   860 					if (destfolder==KMsvNullIndexEntryId)
       
   861 						destfolder=(type==CSmsPDU::ESmsSubmit) || (type==CSmsPDU::ESmsCommand)? KMsvGlobalOutBoxIndexEntryId: KMsvGlobalInBoxIndexEntryId;
       
   862 
       
   863 					CreateMessageL(destfolder, entry, *header, *iRichText, aDate);
       
   864 					CleanupStack::PopAndDestroy(); //header
       
   865 
       
   866 					AddRecipientL(entry.Id(), rcpt);
       
   867 
       
   868 					rSelection.AppendL(entry.Id());
       
   869 					}
       
   870 				else
       
   871 					{
       
   872 					AddRecipientL(entry.Id(), rcpt);
       
   873 					}
       
   874 
       
   875 				curRcpt++;
       
   876 				}
       
   877 			}
       
   878 		}
       
   879 
       
   880 	return retVal;
       
   881 	}
       
   882 
       
   883 EXPORT_C TMsvId CSmsTestUtils::CreateDummyMessageToSendL()
       
   884 	{
       
   885 	TMsvEntry entry;
       
   886 	entry.SetSendingState(KMsvSendStateUponRequest);
       
   887 	entry.iDate.HomeTime();
       
   888 
       
   889 	iRichText->Reset();
       
   890 	iRichText->InsertL(0,_L("This is a send test.\näöå\n Cheers, Mico\n"));
       
   891 
       
   892 	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsSubmit,*iRichText);
       
   893 	CleanupStack::PushL(header);
       
   894 
       
   895 	header->SetSmsSettingsL(*iServiceSettings);
       
   896 	
       
   897 	CSmsNumber* recipient=CSmsNumber::NewL();
       
   898 	CleanupStack::PushL(recipient);
       
   899 	recipient->SetAddressL(KScriptItemRecipientsDef);
       
   900 	recipient->SetNameL(_L("Anthony"));
       
   901 	header->Recipients().AppendL(recipient);
       
   902 	CleanupStack::Pop(); //recipients
       
   903 
       
   904 	CSmsNumber* recipient2=CSmsNumber::NewL();
       
   905 	CleanupStack::PushL(recipient2);
       
   906 	recipient2->SetAddressL(KScriptItemRecipients2Def);
       
   907 	recipient2->SetNameL(_L("Julia"));
       
   908 	header->Recipients().AppendL(recipient2);
       
   909 	CleanupStack::Pop(); //recipients
       
   910 
       
   911 	TTime now;
       
   912 	now.HomeTime();
       
   913 
       
   914 	CreateMessageL(KMsvGlobalOutBoxIndexEntryId, entry, *header, *iRichText, now);
       
   915 //	Printf(_L("Test Create Message (%d) To Send\n"), entry.Id());
       
   916 
       
   917 	CleanupStack::PopAndDestroy(1); //header
       
   918 
       
   919 	return entry.Id();
       
   920 	}
       
   921 
       
   922 EXPORT_C TMsvId CSmsTestUtils::CreateDummyMessageToReceiveL()
       
   923 	{
       
   924 	TMsvEntry entry;
       
   925 	entry.iType=KUidMsvMessageEntry;
       
   926 	entry.SetSendingState(KMsvSendStateNotApplicable);
       
   927 
       
   928 	iRichText->Reset();
       
   929 	iRichText->InsertL(0,_L("Hiphei"));
       
   930 
       
   931 	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *iRichText);
       
   932 	CleanupStack::PushL(header);
       
   933 
       
   934 	header->SetFromAddressL(KScriptItemRecipientsDef);
       
   935 	header->Message().SetServiceCenterAddressL(KScriptItemSCDef);
       
   936 
       
   937 	TTime now;
       
   938 	now.HomeTime();
       
   939 
       
   940 	CreateMessageL(KMsvGlobalInBoxIndexEntryId, entry, *header, *iRichText, now);
       
   941 	entry.SetReadOnly(ETrue);
       
   942 	ChangeEntryL(entry);
       
   943 
       
   944 //	Printf(_L("Create Message (%d) To Receive\n"), entry.Id());
       
   945 
       
   946 	CleanupStack::PopAndDestroy(1); //header
       
   947 	return entry.Id();
       
   948 	}
       
   949 
       
   950 EXPORT_C void CSmsTestUtils::CreateMessageL(TMsvId aDestFolder, TMsvEntry& aEntry, CSmsHeader& aHeader, CRichText& aBody, const TTime& aDate)
       
   951 	{
       
   952 	TSmsUtilities::PopulateMsgEntry(aEntry, aHeader.Message(), iSmsServiceId);
       
   953 	TBuf<KSmsDescriptionLength> desc;
       
   954 
       
   955 	TSmsUtilities::GetDescription(aHeader.Message(), desc);
       
   956 	aEntry.iDescription.Set(desc);
       
   957 
       
   958 	aEntry.iDate = aDate;
       
   959 
       
   960 	SetEntryL(aDestFolder);
       
   961 
       
   962 	CreateEntryL(aEntry);
       
   963 
       
   964 	if (iClientServer == EClientSide)
       
   965 		iMsvSession->CleanupEntryPushL(aEntry.Id());
       
   966 
       
   967 	SetEntryL(aEntry.Id());
       
   968 
       
   969 	CMsvStore* store = EditStoreL();
       
   970 	CleanupStack::PushL(store);
       
   971 
       
   972 	aHeader.StoreL(*store);
       
   973 
       
   974 	store->StoreBodyTextL(aBody);
       
   975 
       
   976 	store->CommitL();
       
   977 
       
   978 	aEntry.iSize = store->SizeL();
       
   979 	ChangeEntryL(aEntry);
       
   980 
       
   981 	CleanupStack::PopAndDestroy(store);
       
   982 
       
   983 	if (iClientServer == EClientSide)
       
   984 		iMsvSession->CleanupEntryPop();
       
   985 	}
       
   986 
       
   987 EXPORT_C void CSmsTestUtils::AddRecipientL(TMsvId aId, const TDesC& aNumber)
       
   988 	{
       
   989 	CSmsHeader* header = GetHeaderLC(aId);
       
   990 
       
   991 	SetEntryL(aId);
       
   992 	CMsvStore* store = EditStoreL();
       
   993 	CleanupStack::PushL(store);
       
   994 
       
   995 	CSmsNumber* rcpt = CSmsNumber::NewL();
       
   996 	CleanupStack::PushL(rcpt);
       
   997 	rcpt->SetAddressL(aNumber);
       
   998 
       
   999 	TBuf<KSmsDetailsLength> details;
       
  1000 
       
  1001 	if (TSmsUtilities::GetDetails(iFs, aNumber, details) == KErrNone)
       
  1002 		{
       
  1003 		rcpt->SetNameL(details);
       
  1004 		TMsvEntry entry(Entry());
       
  1005 		entry.iDetails.Set(details);
       
  1006 		ChangeEntryL(entry);
       
  1007 		}
       
  1008 
       
  1009 	header->Recipients().AppendL(rcpt);
       
  1010 	CleanupStack::Pop(); //rcpt;
       
  1011 
       
  1012 	header->StoreL(*store);
       
  1013 
       
  1014 	store->CommitL();
       
  1015 
       
  1016 	CleanupStack::PopAndDestroy(store);
       
  1017 	CleanupStack::PopAndDestroy(header);
       
  1018 	}
       
  1019 
       
  1020 EXPORT_C void CSmsTestUtils::Panic(TSmsTestUtilsPanic aPanic)
       
  1021 	{
       
  1022 	Panic((TInt) aPanic);
       
  1023 	}
       
  1024 
       
  1025 EXPORT_C void CSmsTestUtils::Panic(TInt aPanic)
       
  1026 	{
       
  1027 	User::Panic(SMSTEST_PANIC, aPanic);
       
  1028 	}
       
  1029 
       
  1030 EXPORT_C void CSmsTestUtils::InstantiateSmsServerMtmL()
       
  1031 	{
       
  1032 	InstantiateServerMtmL(KUidMsgTypeSMS, iSmsServiceId);
       
  1033 	}
       
  1034 
       
  1035 EXPORT_C void CSmsTestUtils::DeleteSmsServiceL()
       
  1036 	{
       
  1037 	DeleteServiceL(KUidMsgTypeSMS);
       
  1038 	}
       
  1039 
       
  1040 EXPORT_C TMsvId CSmsTestUtils::FindExistingSmsServiceL()
       
  1041 	{
       
  1042 	TMsvId firstId = 0;
       
  1043 	ServiceIdL(KUidMsgTypeSMS, firstId);
       
  1044 	return firstId;
       
  1045 	}
       
  1046 
       
  1047 EXPORT_C void CSmsTestUtils::FindExistingServicesL()
       
  1048 	{
       
  1049 	iSmsServiceId = 0;
       
  1050 	TRAPD(err, iSmsServiceId = FindExistingSmsServiceL());
       
  1051 
       
  1052 	if (err)
       
  1053 		Printf(_L("No existing SMS services found!\n"));
       
  1054 	}
       
  1055 
       
  1056 EXPORT_C void CSmsTestUtils::DeleteSmsMessagesL(TMsvId aFolder)
       
  1057 	{
       
  1058 	SetEntryL(aFolder);
       
  1059 	CMsvEntrySelection* sel = ChildrenWithMtmLC(KUidMsgTypeSMS);
       
  1060 
       
  1061 	TInt count = sel->Count();
       
  1062 
       
  1063 	while (count--)
       
  1064 		{
       
  1065 		DeleteEntryL(sel->At(count));
       
  1066 		}
       
  1067 
       
  1068 	CleanupStack::PopAndDestroy(); //sel
       
  1069 	}
       
  1070 
       
  1071 EXPORT_C TBool CSmsTestUtils::AreMessagesSameTextL(TMsvId aSentId, TMsvId aRecvId, TBool aPrintIfMismatch)
       
  1072 	{
       
  1073 	__ASSERT_ALWAYS(aSentId != aRecvId, Panic(KSmsTestUtilsPanicCannotCompareSameIds));
       
  1074 
       
  1075 	CSmsHeader* sentHeader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *iRichText);
       
  1076 	CleanupStack::PushL(sentHeader);
       
  1077 	CSmsHeader* rcvdHeader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *iRichText);
       
  1078 	CleanupStack::PushL(rcvdHeader);
       
  1079 	
       
  1080 	// extract the sent message
       
  1081 	SetEntryL(aSentId);
       
  1082 	CMsvStore* store = ReadStoreL();
       
  1083 	CleanupStack::PushL(store);
       
  1084 	sentHeader->RestoreL(*store);
       
  1085 	CleanupStack::PopAndDestroy(); //store
       
  1086 
       
  1087 	// do the same for the rx message
       
  1088 	SetEntryL(aRecvId);
       
  1089 	store = ReadStoreL();
       
  1090 	CleanupStack::PushL(store);
       
  1091 	rcvdHeader->RestoreL(*store);
       
  1092 	CleanupStack::PopAndDestroy(); //store
       
  1093 
       
  1094 	// compare the text and the EMS objects
       
  1095 	TBool retVal = EmsTestUtils::CompareEmsMsgL(sentHeader->Message(), rcvdHeader->Message());
       
  1096 	if (!retVal && aPrintIfMismatch)
       
  1097 		{
       
  1098 		Printf(_L("Message mismatch...\n"));
       
  1099 		}
       
  1100 
       
  1101 	CleanupStack::PopAndDestroy(rcvdHeader);
       
  1102 	CleanupStack::PopAndDestroy(sentHeader);
       
  1103 
       
  1104 	return retVal;
       
  1105 	}
       
  1106 
       
  1107 void CSmsTestUtils::DisplayLogEventData(const CLogEvent& aEvent)
       
  1108 	{
       
  1109 	if (aEvent.EventType() == KLogShortMessageEventTypeUid)
       
  1110 		{
       
  1111 		TLogSmsPduData data;
       
  1112 		TPckg<TLogSmsPduData> packeddata(data);
       
  1113 		packeddata.Copy(aEvent.Data());
       
  1114 
       
  1115 		TBuf<256> output;
       
  1116 		output.Append(_L("\t"));
       
  1117 
       
  1118 		switch (data.iType)
       
  1119 			{
       
  1120 			case CSmsPDU::ESmsSubmit:
       
  1121 				output.Append(_L("Submit"));
       
  1122 				break;
       
  1123 			case CSmsPDU::ESmsDeliver:
       
  1124 				output.Append(_L("Deliver"));
       
  1125 				break;
       
  1126 			case CSmsPDU::ESmsStatusReport:
       
  1127 				output.Append(_L("Status Report"));
       
  1128 				break;
       
  1129 			case CSmsPDU::ESmsSubmitReport:
       
  1130 				output.Append(_L("Submit Report"));
       
  1131 				break;
       
  1132 			case CSmsPDU::ESmsDeliverReport:
       
  1133 				output.Append(_L("Deliver Report"));
       
  1134 				break;
       
  1135 			default:
       
  1136 				output.Append(_L("Command"));
       
  1137 				break;
       
  1138 			}
       
  1139 
       
  1140 		output.Append(_L(" Tot %d Sent %d Deliver %d Fail %d Recvd %d\n"));
       
  1141 		Printf(output, data.iTotal, data.iSent, data.iDelivered, data.iFailed, data.iReceived);
       
  1142 		}
       
  1143 	}
       
  1144 
       
  1145 EXPORT_C void CSmsTestUtils::SetCommDbServiceCenterFromScriptL(const TDesC& aScriptFile)
       
  1146 	{
       
  1147 	//Update the service settings with the Service Centre address read from the script
       
  1148 	Printf(_L("Setting Comm DB Service Center from Script\n"));
       
  1149 	
       
  1150 	TTime now;
       
  1151 	now.HomeTime();
       
  1152 
       
  1153 	CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection();
       
  1154 	CleanupStack::PushL(sel);
       
  1155 
       
  1156 	ReadScriptL(aScriptFile, KMsvGlobalOutBoxIndexEntryId, *sel, now);
       
  1157 
       
  1158 	Printf(_L("\t%d msgs read from %S\n"), sel->Count(), &aScriptFile);
       
  1159 
       
  1160 	if (!sel->Count())
       
  1161 		User::Leave(KErrNotFound);
       
  1162 
       
  1163 	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *iRichText);
       
  1164 	CleanupStack::PushL(header);
       
  1165 
       
  1166 	SetEntryL(sel->At(0));
       
  1167 	CMsvStore* store = ReadStoreL();
       
  1168 	CleanupStack::PushL(store);
       
  1169 	header->RestoreL(*store);
       
  1170 	CleanupStack::PopAndDestroy(store);
       
  1171 
       
  1172 	CSmsAccount* account = CSmsAccount::NewLC();
       
  1173 	account->LoadSettingsL(*iServiceSettings);
       
  1174 	
       
  1175 	iServiceSettings->SetCommDbAction(CSmsSettings::EStoreToCommDb);
       
  1176 
       
  1177 	TInt count = iServiceSettings->ServiceCenterCount();
       
  1178 	while (count--)
       
  1179 		{
       
  1180 		iServiceSettings->RemoveServiceCenter(count);
       
  1181 		}
       
  1182 
       
  1183 	TPtrC sc(header->Message().ServiceCenterAddress());
       
  1184 	Printf(_L("\tUsing service center %S\n"), &sc);
       
  1185 	iServiceSettings->AddServiceCenterL(_L("Unknown"), sc);
       
  1186 
       
  1187 	account->SaveSettingsL(*iServiceSettings);
       
  1188 	CleanupStack::PopAndDestroy(account);    		
       
  1189 
       
  1190 	count = sel->Count();
       
  1191 	while (count--)
       
  1192 		{
       
  1193 		TMsvId id = sel->At(count);
       
  1194 		SetEntryL(id);
       
  1195 		SetEntryL(Entry().Parent());
       
  1196 		DeleteEntryL(id);
       
  1197 		}
       
  1198 
       
  1199 	CleanupStack::PopAndDestroy(header);
       
  1200 	CleanupStack::PopAndDestroy(sel);
       
  1201 	Printf(_L("\tComplete: Setting Comm DB Service Center from Script\n"));
       
  1202 	}
       
  1203 
       
  1204 EXPORT_C TBool CSmsTestUtils::SendingCompleteL(const CMsvEntrySelection& aSelection, TInt& rError)
       
  1205 	{
       
  1206 	TBool sent = ETrue;
       
  1207 	const TInt msgCount = aSelection.Count();
       
  1208 	TInt err = KErrNone;
       
  1209 
       
  1210 	for (TInt msg = 0; msg < msgCount; msg++)
       
  1211 		{
       
  1212 		TRAP(err, SetEntryL(aSelection[msg]));
       
  1213 
       
  1214 		if (err == KErrNone)
       
  1215 			{
       
  1216 			TMsvEntry entry = Entry();
       
  1217 			
       
  1218 			TRAP(err, SetEntryL(KMsvGlobalOutBoxIndexEntryId)); //ignore error
       
  1219 
       
  1220 			switch (entry.SendingState())
       
  1221 				{
       
  1222 				case KMsvSendStateSending:
       
  1223 				case KMsvSendStateResend:
       
  1224 				case KMsvSendStateScheduled:
       
  1225 				case KMsvSendStateWaiting:
       
  1226 					sent = EFalse;
       
  1227 					break;
       
  1228 				case KMsvSendStateFailed:
       
  1229 					if (entry.iError)
       
  1230 						rError = entry.iError;
       
  1231 					else
       
  1232 						rError = KErrGeneral;
       
  1233 					break;
       
  1234 				default:
       
  1235 					break;
       
  1236 					//nothing
       
  1237 				}
       
  1238 			}
       
  1239 		}
       
  1240 
       
  1241 	return sent;
       
  1242 	}
       
  1243 
       
  1244 EXPORT_C void CSmsTestUtils::DisplaySendingStatesL(const CMsvEntrySelection& aSelection)
       
  1245 	{
       
  1246 	TInt err = KErrNone;
       
  1247 	TInt msgCount = aSelection.Count();
       
  1248 
       
  1249 	for (TInt msg = 0; msg < msgCount; msg++)
       
  1250 		{
       
  1251 		TRAP(err, SetEntryL(aSelection[msg]));
       
  1252 
       
  1253 		if (!err)
       
  1254 			{
       
  1255 			TMsvEntry entry = Entry();
       
  1256 			TRAP(err, SetEntryL(KMsvGlobalOutBoxIndexEntryId)); //ignore error
       
  1257 
       
  1258 				TBuf<0x100> output;
       
  1259 				TBuf<0x50>  nowBuf;
       
  1260 
       
  1261 				switch (entry.SendingState())
       
  1262 					{
       
  1263 					case KMsvSendStateSending:
       
  1264 						output.AppendFormat(_L("Message %d Sending with error %d\n"), entry.Id(), entry.iError);
       
  1265 						break;
       
  1266 					case KMsvSendStateResend:
       
  1267 						output.AppendFormat(_L("Message %d Resend with error %d at:\n"), entry.Id(), entry.iError);
       
  1268 						err = AppendScheduleTimeL(entry.Id(), output);
       
  1269 						if (err)
       
  1270 							{
       
  1271 							entry.iDate.FormatL(nowBuf, _L("%-B%:0%J%:1%T%:2%S%:3%+B"));
       
  1272 							output.Append(nowBuf);
       
  1273 							output.Append(_L("\n"));
       
  1274 							}
       
  1275 						break;
       
  1276 					case KMsvSendStateScheduled:
       
  1277 						output.AppendFormat(_L("Message %d Scheduled with error %d at:\n"), entry.Id(), entry.iError);
       
  1278 						err = AppendScheduleTimeL(entry.Id(), output);
       
  1279 						break;
       
  1280 					case KMsvSendStateFailed:
       
  1281 						output.AppendFormat(_L("Message %d Failed with error %d\n"), entry.Id(), entry.iError);
       
  1282 						break;
       
  1283 					case KMsvSendStateWaiting:
       
  1284 						output.AppendFormat(_L("Message %d Waiting with error %d\n"), entry.Id(), entry.iError);
       
  1285 						break;
       
  1286 					case KMsvSendStateSent:
       
  1287 						output.AppendFormat(_L("Message %d Sent\n"), entry.Id());
       
  1288 						break;
       
  1289 					case KMsvSendStateSuspended:
       
  1290 						output.AppendFormat(_L("Message %d Suspended\n"), entry.Id());
       
  1291 						break;
       
  1292 					default:
       
  1293 						output.AppendFormat(_L("Message %d Other Sending State with error %d and failed %d\n"), entry.Id(), entry.iError, entry.Failed());
       
  1294 						break;
       
  1295 						//nothing
       
  1296 					} //end switch
       
  1297 				Printf(output);
       
  1298 			} //end if
       
  1299 		} //end for
       
  1300 	}
       
  1301 
       
  1302 CSmsHeader* CSmsTestUtils::DoGetHeaderLC(CMsvEntry& aEntry)
       
  1303 	{
       
  1304 	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *iRichText);
       
  1305 	CleanupStack::PushL(header);
       
  1306 
       
  1307 	CMsvStore* store = aEntry.ReadStoreL();
       
  1308 	CleanupStack::PushL(store);
       
  1309 
       
  1310 	header->RestoreL(*store);
       
  1311 	iRichText->Reset();
       
  1312 	store->RestoreBodyTextL(*iRichText);
       
  1313 
       
  1314 	CleanupStack::PopAndDestroy(store);
       
  1315 
       
  1316 	return header;
       
  1317 	}
       
  1318 
       
  1319 EXPORT_C CSmsHeader* CSmsTestUtils::GetHeaderLC(TMsvId aId)
       
  1320 	{
       
  1321 	iMsvEntry->SetEntryL(aId);
       
  1322 	return DoGetHeaderLC(*iMsvEntry);
       
  1323 	}