messagingappbase/smsmtm/test/src/t_SmsReplyToStep.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     1 // Copyright (c) 2005-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 <testexecutelog.h>
       
    17 #include "t_SmsReplyToStep.h"
       
    18 #include <smuthdr.h>
       
    19 #include <txtrich.h>
       
    20 #include <msvuids.h>
       
    21 #include <smsuaddr.h>
       
    22 #include <csmsaccount.h>
       
    23 #include "gsmuIEOperations.h"
       
    24 #include <CommsDatTypesV1_1.h>
       
    25 
       
    26 using namespace CommsDat;
       
    27 LOCAL_D RTest test(_L("TestTextE_1_1"));
       
    28 _LIT(KTestMessageDir,"");
       
    29 
       
    30 const TTimeIntervalMicroSeconds32 KWaitForWatchersToStart = 20000000;
       
    31 const TTimeIntervalMicroSeconds32 KWaitForWatchersToStartDisplayInterval = 5000000;
       
    32 
       
    33 _LIT(KMessageData, "This is a simple text message");
       
    34 _LIT(KRecipientOk,		"+44111111111");  // has to be valid number and switched on
       
    35 
       
    36 		
       
    37 void EntryObserver::HandleEntryEventL(TMsvEntryEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
    38 	{
       
    39 	switch (aEvent)
       
    40 		{
       
    41 			case EMsvEntryChanged:
       
    42 				{
       
    43 				break;
       
    44 				}
       
    45 			case EMsvNewChildren:
       
    46 				{	
       
    47 				CActiveScheduler::Stop();
       
    48 				break;
       
    49 				}
       
    50 						
       
    51 		default:
       
    52 				{
       
    53 				break;
       
    54 				}
       
    55 		}
       
    56 	}
       
    57 		
       
    58 CSmsReplyToStep::CSmsReplyToStep()
       
    59 :CTestStep()
       
    60 	{	
       
    61 	}
       
    62 		
       
    63 CSmsReplyToStep::~CSmsReplyToStep()
       
    64 	{
       
    65 	delete iTestUtils;
       
    66 	delete iEntry;
       
    67 	delete iScheduler;
       
    68 	delete iEntryObserver;
       
    69 	delete iSessionObserver;
       
    70 	delete iSession;
       
    71 	delete iWatchers;
       
    72 	delete iOperation;
       
    73 	delete iTestActive;
       
    74 	test.End();
       
    75 	test.Close();
       
    76 	__UHEAP_MARKEND;
       
    77 	}
       
    78 
       
    79 void CSmsReplyToStep::InitialiseReplyToStepL()
       
    80 {
       
    81 	SetTestStepName(KSmsReplyToStep1);
       
    82 	iScheduler = new (ELeave) CActiveScheduler;
       
    83 	CActiveScheduler::Install(iScheduler);	
       
    84 }
       
    85 	
       
    86 void CSmsReplyToStep::InitialiseTestL()
       
    87 	{
       
    88 	INFO_PRINTF1(_L("Initialising the test..."));
       
    89 	iTestUtils = CSmsTestUtils::NewL(test);	
       
    90 	// Notify the system agent that the phone is on.
       
    91 	iTestUtils->NotifySaPhoneOnL();
       
    92 	
       
    93 	// Restore the service settings.
       
    94 	iTestUtils->SetEntryL(iTestUtils->iSmsServiceId);
       
    95 	CSmsAccount* account = CSmsAccount::NewLC();
       
    96 	account->LoadSettingsL(*iTestUtils->iServiceSettings);
       
    97 	
       
    98 	// Remove the default service centres from the service settings
       
    99 	TInt count = iTestUtils->iServiceSettings->ServiceCenterCount();
       
   100 	while( count-- )
       
   101 		{
       
   102 		iTestUtils->iServiceSettings->RemoveServiceCenter(count);
       
   103 		}
       
   104 		
       
   105 	// Add the Vodafone service centre - store the settings.
       
   106 	iTestUtils->iServiceSettings->AddServiceCenterL(_L("Vodafone"), _L("+447785016005"));
       
   107 
       
   108 	// Set delivery options - do matching and make reports visible.	
       
   109 	iTestUtils->iServiceSettings->SetDeliveryReport(ETrue);
       
   110 	iTestUtils->iServiceSettings->SetStatusReportHandling(CSmsSettings::EMoveReportToInboxVisibleAndMatch);
       
   111 
       
   112 	account->SaveSettingsL(*iTestUtils->iServiceSettings);
       
   113 	CleanupStack::PopAndDestroy(account);
       
   114 
       
   115 	// set up an opserver to observe the inbox
       
   116 	iEntryObserver = new (ELeave) EntryObserver();
       
   117 	iSessionObserver = new (ELeave) SessionObserver();
       
   118 	iSession = CMsvSession::OpenSyncL(*iSessionObserver);
       
   119 	TMsvSelectionOrdering ordering;	
       
   120 	iEntry = CMsvEntry::NewL(*iSession, KMsvGlobalInBoxIndexEntryIdValue,ordering);
       
   121 	iEntry->AddObserverL(*iEntryObserver);
       
   122 	
       
   123 	//used for acynchronous calls
       
   124 	iTestActive=new(ELeave) CTestActive;
       
   125 	
       
   126 	INFO_PRINTF1(_L("Successfully initialised test"));
       
   127 	
       
   128 }
       
   129 	
       
   130 void CSmsReplyToStep::InitialiseSimTsyL()
       
   131 	{
       
   132 	
       
   133 	INFO_PRINTF1(_L("Initialising the SimTsy..."));
       
   134 	
       
   135 	_LIT(KDefaultTsyName, "SIM"); 
       
   136 	HBufC* tsyName =KDefaultTsyName().AllocLC();
       
   137 
       
   138 	//Initialize TSY using the System Agent
       
   139 	TInt testState;
       
   140 	TInt testNumber=1;
       
   141 	if(KErrNone != RProperty::Get(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testState))
       
   142 		{
       
   143 		User::LeaveIfError(RProperty::Define(KUidPSSimTsyCategory, KPSSimTsyTestNumber, RProperty::EInt));
       
   144 		}
       
   145 	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
       
   146 	if(KErrNone != RProperty::Get(KUidSystemCategory, KMsvTestUidPhonePwrValue, testState))
       
   147 		{
       
   148 		User::LeaveIfError(RProperty::Define(KUidSystemCategory, KMsvTestUidPhonePwrValue, RProperty::EInt));
       
   149 		}
       
   150 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KMsvTestUidPhonePwrValue, EMsvTestPhoneOn));
       
   151 
       
   152 	User::LeaveIfError(RProperty::Get(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
       
   153 
       
   154 	RTelServer etelServer;
       
   155 	User::LeaveIfError(etelServer.Connect());
       
   156 	CleanupClosePushL(etelServer);
       
   157 	User::LeaveIfError(etelServer.LoadPhoneModule(tsyName->Des()));
       
   158 
       
   159 	// Find the phone corresponding to this TSY and open a number of handles on it
       
   160 	TInt numPhones;
       
   161 	User::LeaveIfError(etelServer.EnumeratePhones(numPhones));	
       
   162 	TBool found=EFalse;
       
   163 	
       
   164 	RMobilePhone iPhone;
       
   165 	while (!found && numPhones--)
       
   166 		{
       
   167 		TName phoneTsy;
       
   168 		User::LeaveIfError(etelServer.GetTsyName(numPhones,phoneTsy));
       
   169 		if (phoneTsy.CompareF(tsyName->Des())==KErrNone)
       
   170 			{
       
   171 			found = ETrue;
       
   172 			RTelServer::TPhoneInfo info;
       
   173 			User::LeaveIfError(etelServer.GetPhoneInfo(numPhones,info));
       
   174 			CleanupClosePushL(iPhone);
       
   175 			User::LeaveIfError(iPhone.Open(etelServer,info.iName));
       
   176 			User::LeaveIfError(iPhone.Initialise());
       
   177 			//Required Pause to Allow SMSStack to Complete its Async Init call to the TSY and finish its StartUp.
       
   178 			TTimeIntervalMicroSeconds32 InitPause=9000000;  
       
   179 			User::After(InitPause);							
       
   180 			
       
   181 			CleanupStack::PopAndDestroy(&iPhone);
       
   182 			}
       
   183 		}
       
   184 	
       
   185 	CleanupStack::PopAndDestroy(&etelServer);	
       
   186 
       
   187 	CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion());
       
   188 	CleanupStack::PushL(dbSession);
       
   189 	CMDBRecordSet<CCDGlobalSettingsRecord> globalSettingsRecord(KCDTIdGlobalSettingsRecord);
       
   190 	TRAPD(err, globalSettingsRecord.LoadL(*dbSession));
       
   191 	if(err != KErrNone)
       
   192 		{
       
   193 		User::Leave(KErrNotFound);				
       
   194 		}
       
   195 	
       
   196 	CCDModemBearerRecord *modemRecord = static_cast<CCDModemBearerRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdModemBearerRecord));		
       
   197 	CleanupStack::PushL(modemRecord);
       
   198 	modemRecord->SetRecordId(((CCDGlobalSettingsRecord*)globalSettingsRecord.iRecords[0])->iModemForPhoneServicesAndSMS);
       
   199 	modemRecord->LoadL(*dbSession);
       
   200 	modemRecord->iTsyName.SetMaxLengthL(tsyName->Des().Length());
       
   201 	modemRecord->iTsyName = tsyName->Des();	
       
   202 	modemRecord->ModifyL(*dbSession);
       
   203 	CleanupStack::PopAndDestroy(3);  //tsyName, dbSession, modemRecord 	
       
   204 	
       
   205 	INFO_PRINTF1(_L("Successfully initialised the Sim Tsy"));
       
   206 	}
       
   207 	
       
   208 void CSmsReplyToStep::StartWatcherL()
       
   209 	{
       
   210 	INFO_PRINTF1(_L("Start the Watcher"));
       
   211 
       
   212 	if( WatchersAlreadyRunningL() )
       
   213 		{
       
   214 		INFO_PRINTF1(_L("Watchers are already running\n"));
       
   215 		return;
       
   216 		}
       
   217 
       
   218 	iWatchers = CTestUtilsWatcherStarter::NewL();
       
   219 
       
   220 	TTimeIntervalMicroSeconds32 wait = KWaitForWatchersToStart;
       
   221 	TBool started = EFalse;
       
   222 	while( !started && wait.Int() > 0 )
       
   223 		{
       
   224 		INFO_PRINTF2(_L("Waiting %d secs for watchers to start..."), wait.Int() / 1000000);
       
   225 		wait = wait.Int() - KWaitForWatchersToStartDisplayInterval.Int();
       
   226 		User::After(KWaitForWatchersToStartDisplayInterval);
       
   227 		started = WatchersAlreadyRunningL();
       
   228 		}
       
   229 
       
   230 	if( !WatchersAlreadyRunningL() )
       
   231 		{
       
   232 		INFO_PRINTF1(_L("WARNING: NBS Watcher has not started yet\n"));
       
   233 		}
       
   234 	}
       
   235 	
       
   236 TBool CSmsReplyToStep::WatchersAlreadyRunningL()
       
   237 	{
       
   238 	RSocketServ server;
       
   239 	RSocket socket;
       
   240 
       
   241 	User::LeaveIfError(server.Connect());
       
   242 	CleanupClosePushL(server);
       
   243 
       
   244 		// test if it's there... 
       
   245 	TProtocolDesc protoInfo;
       
   246 	TProtocolName protocolname;
       
   247 	protocolname.Copy(KSmsDatagram);
       
   248 	User::LeaveIfError(server.FindProtocol(protocolname,protoInfo));
       
   249 
       
   250 	User::LeaveIfError(socket.Open(server,
       
   251 										protoInfo.iAddrFamily,
       
   252 										protoInfo.iSockType, 
       
   253 										protoInfo.iProtocol));
       
   254 	CleanupClosePushL(socket);
       
   255 	
       
   256 
       
   257 	TSmsAddr addr;
       
   258 	addr.SetSmsAddrFamily(ESmsAddrRecvAny);
       
   259 	TInt err = socket.Bind(addr);
       
   260 
       
   261 	CleanupStack::Pop(2, &server);
       
   262 	socket.CancelAll();
       
   263 	socket.Close();
       
   264 	server.Close();
       
   265 	return (err == KErrAlreadyExists);
       
   266 	}
       
   267 
       
   268 void CSmsReplyToStep::SetRecipientsL(CSmsHeader& aHeader)
       
   269 	{
       
   270 	iTestUtils->Printf(_L("--Setting single recipient\n"));
       
   271 	
       
   272 	CSmsNumber* rcpt = CSmsNumber::NewL();
       
   273 	CleanupStack::PushL(rcpt);
       
   274 	rcpt->SetAddressL(KRecipientOk);
       
   275 	aHeader.Recipients().AppendL(rcpt);
       
   276 	CleanupStack::Pop(rcpt);
       
   277 	}
       
   278 	
       
   279 void CSmsReplyToStep::CreateMessageL()
       
   280 	{
       
   281 	INFO_PRINTF1(_L("Creating message..."));
       
   282 	
       
   283 	TMsvEntry entry;
       
   284 	entry.SetVisible(ETrue); 
       
   285 	entry.SetInPreparation(ETrue); 
       
   286 	entry.iServiceId = iTestUtils->iSmsServiceId; 
       
   287 	entry.iType = KUidMsvMessageEntry; 
       
   288 	entry.iMtm = KUidMsgTypeSMS; 
       
   289 	entry.iDate.HomeTime(); 
       
   290 	entry.iSize = 0; 
       
   291 	entry.iDescription.Set(KNullDesC); 
       
   292 	entry.iDetails.Set(KNullDesC); 
       
   293 	entry.SetSendingState(KMsvSendStateScheduled);
       
   294 
       
   295 	// Create the SMS header object...
       
   296 	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *iTestUtils->iRichText);
       
   297 	CleanupStack::PushL(header);
       
   298 	
       
   299 	// Set the body text...
       
   300 	iTestUtils->iRichText->Reset();
       
   301 	iTestUtils->iRichText->InsertL(0, KMessageData);
       
   302 	
       
   303 	// Copy the message settings...
       
   304 	header->SetSmsSettingsL(*iTestUtils->iServiceSettings); 
       
   305 	
       
   306 	// Set the service centre
       
   307 	TInt defaultIndex = iTestUtils->iServiceSettings->DefaultServiceCenter();
       
   308 	header->SetServiceCenterAddressL(iTestUtils->iServiceSettings->GetServiceCenter(defaultIndex).Address());
       
   309 
       
   310 	// Set recipient - ask derived class
       
   311 	SetRecipientsL(*header);
       
   312 	
       
   313 	// Update entry description and details...
       
   314 	CArrayPtrFlat<CSmsNumber>& recipient = header->Recipients();
       
   315 	entry.iDetails.Set(recipient[0]->Address());
       
   316 	entry.iDescription.Set(iTestUtils->iRichText->Read(0, iTestUtils->iServiceSettings->DescriptionLength()));
       
   317 	entry.SetInPreparation(EFalse);
       
   318 	
       
   319 	// Create the entry - set context to the global outbox.
       
   320 	iTestUtils->iMsvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   321 	iTestUtils->iMsvEntry->CreateL(entry);
       
   322 
       
   323 	// Create new store and save header information 
       
   324 	iTestUtils->iMsvEntry->SetEntryL(entry.Id()); 
       
   325 	CMsvStore* store = iTestUtils->iMsvEntry->EditStoreL(); 
       
   326 	CleanupStack::PushL(store); 
       
   327 	header->StoreL(*store);
       
   328 	store->StoreBodyTextL(*iTestUtils->iRichText);
       
   329 	store->CommitL(); 
       
   330 	CleanupStack::PopAndDestroy(2, header); 
       
   331 	
       
   332 	iMessageId = entry.Id();
       
   333 
       
   334 	}
       
   335 	
       
   336 void CSmsReplyToStep::SendMessageL()
       
   337 	{
       
   338 	INFO_PRINTF1(_L("Sending message..."));
       
   339 
       
   340 	delete iOperation;
       
   341 	iOperation = NULL;
       
   342 
       
   343 	CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection();
       
   344 	CleanupStack::PushL(sel);
       
   345 	sel->AppendL(iMessageId);
       
   346 	iTestUtils->DisplayMessageL(iMessageId);
       
   347 	iTestUtils->iMsvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   348 	iOperation = iTestUtils->iMsvEntry->CopyL(*sel, iTestUtils->iSmsServiceId,iTestActive->iStatus);
       
   349 	iTestActive->StartL();
       
   350 	CActiveScheduler::Start();	
       
   351 	CleanupStack::PopAndDestroy(sel);
       
   352 	}
       
   353 
       
   354 TBool CSmsReplyToStep::CheckMessageL()
       
   355 	{
       
   356 
       
   357 	INFO_PRINTF1(_L("Received new message in Inbox - should be status report..."));
       
   358 		
       
   359 	TMsvSelectionOrdering ordering;	
       
   360 	ordering.ShowInvisibleEntries();
       
   361 	CMsvEntry* entry = CMsvEntry::NewL(*iSession, KMsvGlobalInBoxIndexEntryId,ordering);
       
   362 	CleanupStack::PushL(entry);
       
   363 	
       
   364 	CMsvEntrySelection* msvEntrySelection;
       
   365 	msvEntrySelection=entry->ChildrenL();
       
   366 	CleanupStack::PushL(msvEntrySelection);
       
   367 	
       
   368 	// Check how many mesasges there are - should be just 1
       
   369 	TInt count = msvEntrySelection->Count();
       
   370 	INFO_PRINTF3(_L("Number of new messages: %d, should be: %d"), count, 1);
       
   371 
       
   372 	// Restore the message
       
   373 	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *iTestUtils->iRichText);
       
   374 	CleanupStack::PushL(header);
       
   375 	entry->SetEntryL((*msvEntrySelection)[0]);
       
   376 
       
   377 	CMsvStore* store = entry->ReadStoreL();
       
   378 	CleanupStack::PushL(store);	
       
   379 	header->RestoreL(*store);
       
   380 	
       
   381 	if(store->HasBodyTextL())
       
   382 		{
       
   383 		store->RestoreBodyTextL(*iTestUtils->iRichText);	
       
   384 		}
       
   385 		
       
   386 	TBuf<KSmsDescriptionLength> desc;
       
   387 	User::LeaveIfError(TSmsUtilities::GetDescription(header->Message(), desc));
       
   388 	
       
   389 	//Check for a reply address field
       
   390 	CSmsReplyAddressOperations& operations = STATIC_CAST(CSmsReplyAddressOperations&,header->Message().GetOperationsForIEL(CSmsInformationElement::ESmsReplyAddressFormat));
       
   391 	TBool result=operations.ContainsReplyAddressIEL();
       
   392 
       
   393 	CleanupStack::PopAndDestroy(4,entry);	
       
   394 	return result;	
       
   395 	}
       
   396 
       
   397 TVerdict CSmsReplyToStep::doTestStepPreambleL()
       
   398 	{	
       
   399 	__UHEAP_MARK;
       
   400 	SetTestStepResult(EPass);
       
   401 	test.Start(_L("sdf"));
       
   402 	InitialiseTestL();
       
   403 	InitialiseSimTsyL();
       
   404 	StartWatcherL();
       
   405 	iTestUtils->DeleteSmsMessagesL(KMsvGlobalOutBoxIndexEntryId);
       
   406 	iTestUtils->DeleteSmsMessagesL(KMsvGlobalInBoxIndexEntryId);
       
   407 	iTestUtils->DeleteSmsMessagesL(KMsvSentEntryId);
       
   408 	CreateMessageL();
       
   409 	SendMessageL();
       
   410 	//wait for message to be received...
       
   411 	CActiveScheduler::Start();	
       
   412 
       
   413 	return TestStepResult();
       
   414 	}
       
   415 		
       
   416 
       
   417 TVerdict CSmsReplyToStep::doTestStepL()
       
   418 	{		
       
   419 	if(CheckMessageL())
       
   420 		{
       
   421 		SetTestStepResult(EPass);	
       
   422 		}
       
   423 	else
       
   424 		{
       
   425 		SetTestStepResult(EFail);			
       
   426 		}
       
   427 	
       
   428 	return TestStepResult();
       
   429 	}	
       
   430 
       
   431 TVerdict CSmsReplyToStep::doTestStepPostambleL()
       
   432 /**
       
   433  * @return - TVerdict code
       
   434  * Override of base class virtual
       
   435  */
       
   436 	{
       
   437 	return TestStepResult();
       
   438 	}
       
   439 	
       
   440 	
       
   441 
       
   442