messagingappbase/smsmtm/clientmtm/test/Unittef/src/csmsheaderbodySqlstorerestore.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) 2006-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 // file  CTestHeaderStoreReStore.cpp
       
    15 // This contains Ut for Sms header migration.
       
    16 // 
       
    17 
       
    18 #include "csmsheaderbodySqlstorerestore.h"
       
    19 #include <smuthdr.h>
       
    20 #include <txtrich.h>
       
    21 #include <msvuids.h>
       
    22 #include <smsuaddr.h>
       
    23 #include <csmsaccount.h>
       
    24 #include <Smut.h>
       
    25 #include <sqldb.h>
       
    26 #include <csmsemailfields.h>
       
    27 
       
    28 
       
    29 #define MY_ASSERT_TRUE(a)  \
       
    30 		INFO_PRINTF1(KFunction);   \
       
    31 		ASSERT_TRUE(a);
       
    32 #define MY_ASSERT_FALSE(a)  \
       
    33 		INFO_PRINTF1(KFunction);   \
       
    34 		ASSERT_FALSE(a);
       
    35 #define MY_ASSERT_EQUALS(a,b)  \
       
    36 		INFO_PRINTF1(KFunction);   \
       
    37 		ASSERT_EQUALS(a,b);
       
    38 
       
    39 
       
    40 
       
    41 _LIT(KDbFileName, "\\messaging.db");
       
    42 
       
    43 
       
    44 const TTimeIntervalMicroSeconds32 KWaitForWatchersToStart = 20000000;
       
    45 const TTimeIntervalMicroSeconds32 KWaitForWatchersToStartDisplayInterval = 5000000;
       
    46 
       
    47 _LIT(KMessageData, "This is a simple text message");
       
    48 _LIT(KRecipientOk,		"+44111111111");  // has to be valid number and switched on
       
    49 _LIT(KRecipientOk1,		"+44111111115");  // has to be valid number and switched on
       
    50 _LIT(KRecipientOk3,		"+44111111119");  // has to be valid number and switched on
       
    51 _LIT(KRecipientName,		"XYx"); 
       
    52 _LIT(KRecipientName1,		"Sukanta"); 
       
    53 _LIT(KRealAddress,		"XYZ@nokia.com"); 
       
    54 _LIT(KRealAddress1,		"Abc123@nokia.com"); 
       
    55 _LIT(KRealAddress11,		""); 
       
    56 _LIT(KSubject, "Subject subject");
       
    57 _LIT(KRecipientEmpty, "");
       
    58 
       
    59 
       
    60 RTest test(_L("TestStoreReStore1"));
       
    61 
       
    62 CTestHeaderStoreReStore::CTestHeaderStoreReStore()
       
    63 	{
       
    64 	}
       
    65 
       
    66 CTestHeaderStoreReStore::~CTestHeaderStoreReStore()
       
    67 	{
       
    68 	}
       
    69 
       
    70 
       
    71 void CTestHeaderStoreReStore::SetupL()
       
    72 	{
       
    73 	_LIT(KFunction, "SetupL");
       
    74 	INFO_PRINTF1(KFunction);
       
    75 	
       
    76 	TParse parse;
       
    77 	TPtrC drive = TDriveUnit(EDriveC).Name();
       
    78 	parse.Set(KDbFileName, &drive, NULL);
       
    79 	TFileName dbFile = parse.FullName();
       
    80 	RSqlDatabase::Delete(dbFile);
       
    81 
       
    82 	InitialiseTestL();
       
    83 	}
       
    84 
       
    85 void CTestHeaderStoreReStore::TearDownL()
       
    86 	{
       
    87 	_LIT(KFunction, "TearDownL");
       
    88 	INFO_PRINTF1(KFunction);
       
    89 	
       
    90 	delete iTestUtils;
       
    91 	iTestUtils = NULL;
       
    92 	
       
    93 	delete iTestActive;
       
    94 	iTestActive = NULL;
       
    95 	
       
    96 	delete iEntryObserver;
       
    97 	iEntryObserver = NULL;
       
    98 	
       
    99 	delete iSessionObserver;
       
   100 	iSessionObserver = NULL;
       
   101 	
       
   102 	delete iSession;
       
   103 	iSession = NULL;
       
   104 	
       
   105 	delete iheader;
       
   106 	iheader = NULL;
       
   107 	
       
   108 	delete iReciveheader;
       
   109 	iReciveheader = NULL;
       
   110 	}
       
   111 
       
   112 
       
   113 void EntryObserver::HandleEntryEventL(TMsvEntryEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   114 	{
       
   115 	switch (aEvent)
       
   116 		{
       
   117 			case EMsvEntryChanged:
       
   118 				{
       
   119 				break;
       
   120 				}
       
   121 			case EMsvNewChildren:
       
   122 				{	
       
   123 				CActiveScheduler::Stop();
       
   124 				break;
       
   125 				}
       
   126 						
       
   127 		default:
       
   128 				{
       
   129 				break;
       
   130 				}
       
   131 		}
       
   132 	}
       
   133 	
       
   134 void CTestHeaderStoreReStore::InitialiseTestL()
       
   135 	{
       
   136 	INFO_PRINTF1(_L("Initialising the test..."));
       
   137 	iTestUtils = CSmsTestUtils::NewL(test);	
       
   138 	// Notify the system agent that the phone is on.
       
   139 	iTestUtils->NotifySaPhoneOnL();
       
   140 	
       
   141 	// Restore the service settings.
       
   142 	iTestUtils->SetEntryL(iTestUtils->iSmsServiceId);
       
   143 	CSmsAccount* account = CSmsAccount::NewLC();
       
   144 	account->LoadSettingsL(*iTestUtils->iServiceSettings);
       
   145 	
       
   146 	// Remove the default service centres from the service settings
       
   147 	TInt count = iTestUtils->iServiceSettings->ServiceCenterCount();
       
   148 	while( count-- )
       
   149 		{
       
   150 		iTestUtils->iServiceSettings->RemoveServiceCenter(count);
       
   151 		}
       
   152 		
       
   153 	// Add the Vodafone service centre - store the settings.
       
   154 	iTestUtils->iServiceSettings->AddServiceCenterL(_L("Vodafone"), _L("+447785016005"));
       
   155 
       
   156 	// Set delivery options - do matching and make reports visible.	
       
   157 	iTestUtils->iServiceSettings->SetDeliveryReport(ETrue);
       
   158 	iTestUtils->iServiceSettings->SetStatusReportHandling(CSmsSettings::EMoveReportToInboxVisibleAndMatch);
       
   159 
       
   160 	account->SaveSettingsL(*iTestUtils->iServiceSettings);
       
   161 	CleanupStack::PopAndDestroy(account);
       
   162 
       
   163 	// set up an opserver to observe the inbox
       
   164 	iEntryObserver = new (ELeave) EntryObserver();
       
   165 	iSessionObserver = new (ELeave) SessionObserver();
       
   166 	iSession = CMsvSession::OpenSyncL(*iSessionObserver);
       
   167 	TMsvSelectionOrdering ordering;	
       
   168 	iEntry = CMsvEntry::NewL(*iSession, KMsvGlobalInBoxIndexEntryIdValue,ordering);
       
   169 	iEntry->AddObserverL(*iEntryObserver);
       
   170 	
       
   171 	//used for acynchronous calls
       
   172 	iTestActive=new(ELeave) CTestActive;
       
   173 	
       
   174 	INFO_PRINTF1(_L("Successfully initialised test"));
       
   175 	
       
   176 }
       
   177 
       
   178 void CTestHeaderStoreReStore::SetRecipientsL(CSmsHeader& aHeader)
       
   179 	{
       
   180 	iTestUtils->Printf(_L("--Setting single recipient\n"));
       
   181 	
       
   182 	CSmsNumber* rcpt = CSmsNumber::NewL();
       
   183 	CleanupStack::PushL(rcpt);
       
   184 	rcpt->SetAddressL(KRecipientOk);
       
   185 	rcpt->SetNameL(KRecipientName);
       
   186 	aHeader.Recipients().AppendL(rcpt);
       
   187 	CleanupStack::Pop(rcpt);
       
   188 	}
       
   189 	
       
   190 void CTestHeaderStoreReStore::SetEmptyRecipientsL(CSmsHeader& aHeader)
       
   191 	{
       
   192 	iTestUtils->Printf(_L("--Setting single recipient\n"));
       
   193 	
       
   194 	CSmsNumber* rcpt = CSmsNumber::NewL();
       
   195 	CleanupStack::PushL(rcpt);
       
   196 	rcpt->SetAddressL(KRecipientEmpty);
       
   197 	aHeader.Recipients().AppendL(rcpt);
       
   198 	CleanupStack::Pop(rcpt);
       
   199 	}
       
   200 
       
   201 void CTestHeaderStoreReStore::TestStoreHeaderL()
       
   202 	{
       
   203 	
       
   204 	_LIT(KFunction, ":Test For Store SMS Header ");
       
   205 	INFO_PRINTF1(KFunction);
       
   206 
       
   207 	
       
   208 	TMsvEntry entry;
       
   209 	entry.SetVisible(ETrue); 
       
   210 	entry.SetInPreparation(ETrue); 
       
   211 	entry.iServiceId = iTestUtils->iSmsServiceId; 
       
   212 	entry.iType = KUidMsvMessageEntry; 
       
   213 	entry.iMtm = KUidMsgTypeSMS; 
       
   214 	entry.iDate.HomeTime(); 
       
   215 	entry.iSize = 0; 
       
   216 	entry.iDescription.Set(KNullDesC); 
       
   217 	entry.iDetails.Set(KNullDesC); 
       
   218 	entry.SetSendingState(KMsvSendStateScheduled);
       
   219 	
       
   220 
       
   221 	// Create the SMS header object...
       
   222 	iheader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *iTestUtils->iRichText);
       
   223 		
       
   224 	// Set the body text...
       
   225 	iTestUtils->iRichText->Reset();
       
   226 	iTestUtils->iRichText->InsertL(0, KMessageData);
       
   227 	
       
   228 	// Copy the message settings...
       
   229 	iheader->SetSmsSettingsL(*iTestUtils->iServiceSettings); 
       
   230 	
       
   231 	// Set the service centre
       
   232 	TInt defaultIndex = iTestUtils->iServiceSettings->DefaultServiceCenter();
       
   233 	iheader->SetServiceCenterAddressL(iTestUtils->iServiceSettings->GetServiceCenter(defaultIndex).Address());
       
   234 
       
   235 	// Set recipient - ask derived class
       
   236 	SetRecipientsL(*iheader);
       
   237 	
       
   238 	CSmsNumber* rcpt1 = CSmsNumber::NewL();
       
   239 	rcpt1->SetStatus((CMsvRecipient::TRecipientStatus)1);
       
   240 	rcpt1->SetError(2);
       
   241 	rcpt1->SetRetries(3);
       
   242 	TTime date;
       
   243 	date.UniversalTime();
       
   244 	rcpt1->SetTimeValue(date.Int64());
       
   245 	
       
   246 	rcpt1->SetAddressL(KRecipientOk1);
       
   247 	rcpt1->SetNameL(KRecipientName);
       
   248 	iheader->Recipients().AppendL(rcpt1);
       
   249 
       
   250 	CSmsNumber* rcpt2 = CSmsNumber::NewL();
       
   251 	rcpt2->SetAddressL(KRecipientOk3);
       
   252 	rcpt2->SetNameL(KRecipientName);
       
   253 	iheader->Recipients().AppendL(rcpt2);
       
   254 
       
   255 	CSmsNumber* rcpt3 = CSmsNumber::NewL();
       
   256 	rcpt3->SetAddressL(KRecipientOk3);
       
   257 	rcpt3->SetNameL(KRecipientName1);
       
   258 	iheader->Recipients().AppendL(rcpt3);
       
   259 
       
   260 	_LIT(KFunction1, ":Test For Store Email over SMS Header ");
       
   261 	INFO_PRINTF1(KFunction1);
       
   262 
       
   263 	
       
   264 	CSmsEmailFields* emailFields = NULL;
       
   265     emailFields = CSmsEmailFields::NewL( iheader->EmailFields() );
       
   266     emailFields->AddAddressL(KRealAddress);
       
   267     emailFields->AddAddressL(KRealAddress1);
       
   268     emailFields->SetSubjectL(KSubject);
       
   269     iheader->SetEmailFieldsL( *emailFields );
       
   270  
       
   271 	iTestUtils->Printf(_L("--Setting single recipient Done \n"));
       
   272 	
       
   273 	// Create the entry - set context to the global outbox.
       
   274 	iTestUtils->iMsvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   275 	iTestUtils->iMsvEntry->CreateL(entry);
       
   276 
       
   277 	// Create new store and save header information 
       
   278 	iTestUtils->iMsvEntry->SetEntryL(entry.Id()); 
       
   279 	CMsvStore* store = iTestUtils->iMsvEntry->EditStoreL();
       
   280 	CleanupStack::PushL(store); 
       
   281 	iheader->StoreL(*store);
       
   282 	store->CommitL();
       
   283 	CleanupStack::PopAndDestroy(1); //store 
       
   284 	
       
   285 	INFO_PRINTF1(_L("Successfully Message header Stored"));
       
   286 	
       
   287 	TestReStoreHeaderL();
       
   288 	}
       
   289 
       
   290 void CTestHeaderStoreReStore::TestReStoreHeaderL()
       
   291 	{
       
   292 
       
   293 	_LIT(KFunction, ":Test For ReStore SMS Header ");
       
   294 	INFO_PRINTF1(KFunction);
       
   295 
       
   296 			
       
   297 	TMsvSelectionOrdering ordering;	
       
   298 	ordering.ShowInvisibleEntries();
       
   299 	CMsvEntry* entry = CMsvEntry::NewL(*iSession, KMsvGlobalOutBoxIndexEntryId,ordering);
       
   300 	CleanupStack::PushL(entry);
       
   301 	
       
   302 	CMsvEntrySelection* msvEntrySelection;
       
   303 	msvEntrySelection=entry->ChildrenL();
       
   304 	CleanupStack::PushL(msvEntrySelection);
       
   305 	
       
   306 	// Check how many mesasges there are - should be just 1
       
   307 	TInt count = msvEntrySelection->Count();
       
   308 	INFO_PRINTF3(_L("Number of new messages: %d, should be: %d"), count, 1);
       
   309 	ASSERT_TRUE(count == 1);
       
   310 
       
   311 
       
   312 	// Restore the message
       
   313 	iReciveheader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *iTestUtils->iRichText);
       
   314 	entry->SetEntryL((*msvEntrySelection)[0]);
       
   315 
       
   316 	CMsvStore* store = entry->ReadStoreL();
       
   317 	CleanupStack::PushL(store);	
       
   318 	iTestUtils->Printf(_L("--Restore \n"));
       
   319 	iReceiveheader->RestoreL(*store);
       
   320 	
       
   321 	//Check for a recipient count
       
   322 	
       
   323 	TInt cc= iReceiveheader->Recipients().Count();
       
   324 	ASSERT_EQUALS(cc,4);
       
   325 	
       
   326 	_LIT(KFunction1, ":Test For ReStore Email over SMS Header ");
       
   327 	INFO_PRINTF1(KFunction1);
       
   328 
       
   329 	CSmsEmailFields* emailFields = NULL;
       
   330     emailFields = CSmsEmailFields::NewL(iReceiveheader->EmailFields());
       
   331 	
       
   332 	const MDesCArray& addresses = emailFields->Addresses();
       
   333 	count = addresses.MdcaCount();
       
   334 	ASSERT_EQUALS(count,2);
       
   335 	
       
   336 	for( TInt i=0; i < count; ++i )
       
   337 		{
       
   338 		addresses.MdcaPoint(i);		
       
   339 		}
       
   340 	
       
   341 	CleanupStack::PopAndDestroy(3,entry);	
       
   342 	INFO_PRINTF1(_L("Successfully Message header ReStored"));
       
   343 
       
   344 	}
       
   345 	
       
   346 
       
   347 void CTestHeaderStoreReStore::TestStoreReStoreSMSHeaderL()
       
   348 	{
       
   349 	
       
   350 	_LIT(KFunction, ":Test For Store SMS Header ");
       
   351 	INFO_PRINTF1(KFunction);
       
   352 
       
   353 	
       
   354 	TMsvEntry entry;
       
   355 	entry.SetVisible(ETrue); 
       
   356 	entry.SetInPreparation(ETrue); 
       
   357 	entry.iServiceId = iTestUtils->iSmsServiceId; 
       
   358 	entry.iType = KUidMsvMessageEntry; 
       
   359 	entry.iMtm = KUidMsgTypeSMS; 
       
   360 	entry.iDate.HomeTime(); 
       
   361 	entry.iSize = 0; 
       
   362 	entry.iDescription.Set(KNullDesC); 
       
   363 	entry.iDetails.Set(KNullDesC); 
       
   364 	entry.SetSendingState(KMsvSendStateScheduled);
       
   365 	
       
   366 
       
   367 	// Create the SMS header object...
       
   368 	iheader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *iTestUtils->iRichText);
       
   369 		
       
   370 	// Set the body text...
       
   371 	iTestUtils->iRichText->Reset();
       
   372 	iTestUtils->iRichText->InsertL(0, KMessageData);
       
   373 	
       
   374 	// Copy the message settings...
       
   375 	iheader->SetSmsSettingsL(*iTestUtils->iServiceSettings); 
       
   376 	
       
   377 	// Set the service centre
       
   378 	TInt defaultIndex = iTestUtils->iServiceSettings->DefaultServiceCenter();
       
   379 	iheader->SetServiceCenterAddressL(iTestUtils->iServiceSettings->GetServiceCenter(defaultIndex).Address());
       
   380 
       
   381 
       
   382 	_LIT(KFunction1, ":Test For Store Email over SMS Header ");
       
   383 	INFO_PRINTF1(KFunction1);
       
   384 
       
   385 	
       
   386  
       
   387 	iTestUtils->Printf(_L("--Setting single recipient Done \n"));
       
   388 	
       
   389 	// Create the entry - set context to the global outbox.
       
   390 	iTestUtils->iMsvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   391 	iTestUtils->iMsvEntry->CreateL(entry);
       
   392 
       
   393 	// Create new store and save header information 
       
   394 	iTestUtils->iMsvEntry->SetEntryL(entry.Id()); 
       
   395 	CMsvStore* store = iTestUtils->iMsvEntry->EditStoreL();
       
   396 	CleanupStack::PushL(store); 
       
   397 	
       
   398 	iheader->StoreL(*store);
       
   399 	
       
   400 	store->CommitL();
       
   401 	CleanupStack::PopAndDestroy(1);//Store 
       
   402 	
       
   403 	INFO_PRINTF1(_L("Successfully Message header Stored"));
       
   404 	
       
   405 	TestReStoreSMSHeaderL();
       
   406 	}
       
   407 
       
   408 void CTestHeaderStoreReStore::TestReStoreSMSHeaderL()
       
   409 	{
       
   410 
       
   411 	_LIT(KFunction, ":Test For ReStore SMS Header ");
       
   412 	INFO_PRINTF1(KFunction);
       
   413 
       
   414 			
       
   415 	TMsvSelectionOrdering ordering;	
       
   416 	ordering.ShowInvisibleEntries();
       
   417 	CMsvEntry* entry = CMsvEntry::NewL(*iSession, KMsvGlobalOutBoxIndexEntryId,ordering);
       
   418 	CleanupStack::PushL(entry);
       
   419 	
       
   420 	CMsvEntrySelection* msvEntrySelection;
       
   421 	msvEntrySelection=entry->ChildrenL();
       
   422 	CleanupStack::PushL(msvEntrySelection);
       
   423 	
       
   424 	// Check how many mesasges there are - should be just 1
       
   425 	TInt count = msvEntrySelection->Count();
       
   426 	INFO_PRINTF3(_L("Number of new messages: %d, should be: %d"), count, 1);
       
   427 	ASSERT_TRUE(count == 1);
       
   428 
       
   429 
       
   430 	// Restore the message
       
   431 	iReceiveheader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *iTestUtils->iRichText);
       
   432 	entry->SetEntryL((*msvEntrySelection)[0]);
       
   433 
       
   434 	CMsvStore* store = entry->ReadStoreL();
       
   435 	CleanupStack::PushL(store);	
       
   436 	iTestUtils->Printf(_L("--Restore \n"));
       
   437 	iReceiveheader->RestoreL(*store);
       
   438 	
       
   439 	
       
   440 	_LIT(KFunction1, ":Test For ReStore Email over SMS Header ");
       
   441 	INFO_PRINTF1(KFunction1);
       
   442 
       
   443 	CleanupStack::PopAndDestroy(3,entry);	
       
   444 	INFO_PRINTF1(_L("Successfully Message header ReStored"));
       
   445 	}
       
   446 
       
   447 
       
   448 void CTestHeaderStoreReStore::TestStoreReStoreEOSSMSHeaderL()
       
   449 	{
       
   450 	
       
   451 	_LIT(KFunction, ":Test For Store SMS Header ");
       
   452 	INFO_PRINTF1(KFunction);
       
   453 
       
   454 	
       
   455 	TMsvEntry entry;
       
   456 	entry.SetVisible(ETrue); 
       
   457 	entry.SetInPreparation(ETrue); 
       
   458 	entry.iServiceId = iTestUtils->iSmsServiceId; 
       
   459 	entry.iType = KUidMsvMessageEntry; 
       
   460 	entry.iMtm = KUidMsgTypeSMS; 
       
   461 	entry.iDate.HomeTime(); 
       
   462 	entry.iSize = 0; 
       
   463 	entry.iDescription.Set(KNullDesC); 
       
   464 	entry.iDetails.Set(KNullDesC); 
       
   465 	entry.SetSendingState(KMsvSendStateScheduled);
       
   466 	
       
   467 
       
   468 	// Create the SMS header object...
       
   469 	iheader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *iTestUtils->iRichText);
       
   470 	
       
   471 	// Set the body text...
       
   472 	iTestUtils->iRichText->Reset();
       
   473 	iTestUtils->iRichText->InsertL(0, KMessageData);
       
   474 	
       
   475 	// Copy the message settings...
       
   476 	iheader->SetSmsSettingsL(*iTestUtils->iServiceSettings); 
       
   477 	
       
   478 	// Set the service centre
       
   479 	TInt defaultIndex = iTestUtils->iServiceSettings->DefaultServiceCenter();
       
   480 	iheader->SetServiceCenterAddressL(iTestUtils->iServiceSettings->GetServiceCenter(defaultIndex).Address());
       
   481 
       
   482 	// Set recipient - ask derived class
       
   483 
       
   484 	_LIT(KFunction1, ":Test For Store Email over SMS Header ");
       
   485 	INFO_PRINTF1(KFunction1);
       
   486 
       
   487 	
       
   488 	CSmsEmailFields* emailFields = NULL;
       
   489     emailFields = CSmsEmailFields::NewL( iheader->EmailFields() );
       
   490     emailFields->AddAddressL(KRealAddress11);
       
   491     iheader->SetEmailFieldsL( *emailFields );
       
   492  
       
   493 	iTestUtils->Printf(_L("--Setting single recipient Done \n"));
       
   494 	
       
   495 	// Create the entry - set context to the global outbox.
       
   496 	iTestUtils->iMsvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   497 	iTestUtils->iMsvEntry->CreateL(entry);
       
   498 
       
   499 	// Create new store and save header information 
       
   500 	iTestUtils->iMsvEntry->SetEntryL(entry.Id()); 
       
   501 	CMsvStore* store = iTestUtils->iMsvEntry->EditStoreL();
       
   502 	CleanupStack::PushL(store); 
       
   503 	iheader->StoreL(*store);
       
   504 
       
   505 	store->CommitL();
       
   506 	CleanupStack::PopAndDestroy(1);//Store 
       
   507 	
       
   508 	INFO_PRINTF1(_L("Successfully Message header Stored"));
       
   509 	
       
   510 	TestReStoreEOSHeaderL();
       
   511 	}
       
   512 
       
   513 void CTestHeaderStoreReStore::TestReStoreEOSHeaderL()
       
   514 	{
       
   515 
       
   516 	_LIT(KFunction, ":Test For ReStore SMS Header ");
       
   517 	INFO_PRINTF1(KFunction);
       
   518 
       
   519 			
       
   520 	TMsvSelectionOrdering ordering;	
       
   521 	ordering.ShowInvisibleEntries();
       
   522 	CMsvEntry* entry = CMsvEntry::NewL(*iSession, KMsvGlobalOutBoxIndexEntryId,ordering);
       
   523 	CleanupStack::PushL(entry);
       
   524 	
       
   525 	CMsvEntrySelection* msvEntrySelection;
       
   526 	msvEntrySelection=entry->ChildrenL();
       
   527 	CleanupStack::PushL(msvEntrySelection);
       
   528 	
       
   529 	// Check how many mesasges there are - should be just 1
       
   530 	TInt count = msvEntrySelection->Count();
       
   531 	INFO_PRINTF3(_L("Number of new messages: %d, should be: %d"), count, 1);
       
   532 	ASSERT_TRUE(count == 1);
       
   533 
       
   534 
       
   535 	// Restore the message
       
   536 	iReciveheader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *iTestUtils->iRichText);
       
   537 	entry->SetEntryL((*msvEntrySelection)[0]);
       
   538 
       
   539 	CMsvStore* store = entry->ReadStoreL();
       
   540 	CleanupStack::PushL(store);	
       
   541 	iTestUtils->Printf(_L("--Restore \n"));
       
   542 	iReciveheader->RestoreL(*store);
       
   543 	
       
   544 	CleanupStack::PopAndDestroy(3,entry);	
       
   545 	INFO_PRINTF1(_L("Successfully Message header ReStored"));
       
   546 
       
   547 	}
       
   548 
       
   549 void CTestHeaderStoreReStore::TestStoreReStoreEmptyEOSSMSHeaderL()
       
   550 	{
       
   551 	
       
   552 	_LIT(KFunction, ":Test For Store SMS Header ");
       
   553 	INFO_PRINTF1(KFunction);
       
   554 
       
   555 	
       
   556 	TMsvEntry entry;
       
   557 	entry.SetVisible(ETrue); 
       
   558 	entry.SetInPreparation(ETrue); 
       
   559 	entry.iServiceId = iTestUtils->iSmsServiceId; 
       
   560 	entry.iType = KUidMsvMessageEntry; 
       
   561 	entry.iMtm = KUidMsgTypeSMS; 
       
   562 	entry.iDate.HomeTime(); 
       
   563 	entry.iSize = 0; 
       
   564 	entry.iDescription.Set(KNullDesC); 
       
   565 	entry.iDetails.Set(KNullDesC); 
       
   566 	entry.SetSendingState(KMsvSendStateScheduled);
       
   567 	
       
   568 
       
   569 	// Create the SMS header object...
       
   570 	iheader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *iTestUtils->iRichText);
       
   571 	
       
   572 	// Set the body text...
       
   573 	iTestUtils->iRichText->Reset();
       
   574 	iTestUtils->iRichText->InsertL(0, KMessageData);
       
   575 	
       
   576 	// Copy the message settings...
       
   577 	iheader->SetSmsSettingsL(*iTestUtils->iServiceSettings); 
       
   578 	
       
   579 	// Set the service centre
       
   580 	TInt defaultIndex = iTestUtils->iServiceSettings->DefaultServiceCenter();
       
   581 	iheader->SetServiceCenterAddressL(iTestUtils->iServiceSettings->GetServiceCenter(defaultIndex).Address());
       
   582 
       
   583 	_LIT(KFunction1, ":Test For Store Email over SMS Header ");
       
   584 	INFO_PRINTF1(KFunction1);
       
   585 
       
   586 	
       
   587 	CSmsEmailFields* emailFields = NULL;
       
   588     emailFields = CSmsEmailFields::NewL( iheader->EmailFields() );
       
   589     iheader->SetEmailFieldsL( *emailFields );
       
   590  
       
   591 	iTestUtils->Printf(_L("--Setting single recipient Done \n"));
       
   592 	
       
   593 	// Create the entry - set context to the global outbox.
       
   594 	iTestUtils->iMsvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   595 	iTestUtils->iMsvEntry->CreateL(entry);
       
   596 
       
   597 	// Create new store and save header information 
       
   598 	iTestUtils->iMsvEntry->SetEntryL(entry.Id()); 
       
   599 	CMsvStore* store = iTestUtils->iMsvEntry->EditStoreL();
       
   600 	CleanupStack::PushL(store); 
       
   601 	iheader->StoreL(*store);
       
   602 
       
   603 	store->CommitL();
       
   604 	CleanupStack::PopAndDestroy(1);//store
       
   605 	
       
   606 	INFO_PRINTF1(_L("Successfully Message header Stored"));
       
   607 	
       
   608 	TestReStoreEmptyEOSHeaderL();
       
   609 	}
       
   610 
       
   611 void CTestHeaderStoreReStore::TestReStoreEmptyEOSHeaderL()
       
   612 	{
       
   613 
       
   614 	_LIT(KFunction, ":Test For ReStore SMS Header ");
       
   615 	INFO_PRINTF1(KFunction);
       
   616 
       
   617 			
       
   618 	TMsvSelectionOrdering ordering;	
       
   619 	ordering.ShowInvisibleEntries();
       
   620 	CMsvEntry* entry = CMsvEntry::NewL(*iSession, KMsvGlobalOutBoxIndexEntryId,ordering);
       
   621 	CleanupStack::PushL(entry);
       
   622 	
       
   623 	CMsvEntrySelection* msvEntrySelection;
       
   624 	msvEntrySelection=entry->ChildrenL();
       
   625 	CleanupStack::PushL(msvEntrySelection);
       
   626 	
       
   627 	// Check how many mesasges there are - should be just 1
       
   628 	TInt count = msvEntrySelection->Count();
       
   629 	INFO_PRINTF3(_L("Number of new messages: %d, should be: %d"), count, 1);
       
   630 	ASSERT_TRUE(count == 1);
       
   631 
       
   632 
       
   633 	// Restore the message
       
   634 	iReceiveheader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *iTestUtils->iRichText);
       
   635 	entry->SetEntryL((*msvEntrySelection)[0]);
       
   636 
       
   637 	CMsvStore* store = entry->ReadStoreL();
       
   638 	CleanupStack::PushL(store);	
       
   639 	iTestUtils->Printf(_L("--Restore \n"));
       
   640 	iReceiveheader->RestoreL(*store);
       
   641 	
       
   642 	CleanupStack::PopAndDestroy(3,entry);	
       
   643 	INFO_PRINTF1(_L("Successfully Message header ReStored"));
       
   644 
       
   645 	}
       
   646 
       
   647 void CTestHeaderStoreReStore::TestMultipuleEOSRecipientSMSHeaderL()
       
   648 	{
       
   649 	
       
   650 	_LIT(KFunction, ":Test For Store SMS Header ");
       
   651 	INFO_PRINTF1(KFunction);
       
   652 
       
   653 	TMsvEntry entry;
       
   654 	entry.SetVisible(ETrue); 
       
   655 	entry.SetInPreparation(ETrue); 
       
   656 	entry.iServiceId = iTestUtils->iSmsServiceId; 
       
   657 	entry.iType = KUidMsvMessageEntry; 
       
   658 	entry.iMtm = KUidMsgTypeSMS; 
       
   659 	entry.iDate.HomeTime(); 
       
   660 	entry.iSize = 0; 
       
   661 	entry.iDescription.Set(KNullDesC); 
       
   662 	entry.iDetails.Set(KNullDesC); 
       
   663 	entry.SetSendingState(KMsvSendStateScheduled);
       
   664 	
       
   665 
       
   666 	// Create the SMS header object...
       
   667 	iheader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *iTestUtils->iRichText);
       
   668 	
       
   669 	// Set the body text...
       
   670 	iTestUtils->iRichText->Reset();
       
   671 	iTestUtils->iRichText->InsertL(0, KMessageData);
       
   672 	
       
   673 	// Copy the message settings...
       
   674 	iheader->SetSmsSettingsL(*iTestUtils->iServiceSettings); 
       
   675 	
       
   676 	// Set the service centre
       
   677 	TInt defaultIndex = iTestUtils->iServiceSettings->DefaultServiceCenter();
       
   678 	iheader->SetServiceCenterAddressL(iTestUtils->iServiceSettings->GetServiceCenter(defaultIndex).Address());
       
   679 
       
   680 	// Set recipient - ask derived class
       
   681 
       
   682 	_LIT(KFunction1, ":Test For Store Email over SMS Header ");
       
   683 	INFO_PRINTF1(KFunction1);
       
   684 
       
   685 	
       
   686 	CSmsEmailFields* emailFields = NULL;
       
   687     emailFields = CSmsEmailFields::NewL( iheader->EmailFields() );
       
   688     emailFields->AddAddressL(KRealAddress);
       
   689             
       
   690     iheader->SetEmailFieldsL( *emailFields );
       
   691  
       
   692 	iTestUtils->Printf(_L("--Setting single recipient Done \n"));
       
   693 	
       
   694 	// Create the entry - set context to the global outbox.
       
   695 	iTestUtils->iMsvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   696 	iTestUtils->iMsvEntry->CreateL(entry);
       
   697 
       
   698 	// Create new store and save header information 
       
   699 	iTestUtils->iMsvEntry->SetEntryL(entry.Id()); 
       
   700 	CMsvStore* store = iTestUtils->iMsvEntry->EditStoreL();
       
   701 	CleanupStack::PushL(store); 
       
   702 	iheader->StoreL(*store);
       
   703 	store->CommitL();
       
   704 	CleanupStack::PopAndDestroy(1);//store
       
   705 	
       
   706 	INFO_PRINTF1(_L("Successfully Message header Stored"));
       
   707 	
       
   708 	TestReStoreMultipuleEOSRecipientSMSHeaderL();
       
   709 	}
       
   710 
       
   711 void CTestHeaderStoreReStore::TestReStoreMultipuleEOSRecipientSMSHeaderL()
       
   712 	{
       
   713 
       
   714 	_LIT(KFunction, ":Test For ReStore SMS Header ");
       
   715 	INFO_PRINTF1(KFunction);
       
   716 
       
   717 			
       
   718 	TMsvSelectionOrdering ordering;	
       
   719 	ordering.ShowInvisibleEntries();
       
   720 	CMsvEntry* entry = CMsvEntry::NewL(*iSession, KMsvGlobalOutBoxIndexEntryId,ordering);
       
   721 	CleanupStack::PushL(entry);
       
   722 	
       
   723 	CMsvEntrySelection* msvEntrySelection;
       
   724 	msvEntrySelection=entry->ChildrenL();
       
   725 	CleanupStack::PushL(msvEntrySelection);
       
   726 	
       
   727 	// Check how many mesasges there are - should be just 1
       
   728 	TInt count = msvEntrySelection->Count();
       
   729 	INFO_PRINTF3(_L("Number of new messages: %d, should be: %d"), count, 1);
       
   730 	ASSERT_TRUE(count == 1);
       
   731 
       
   732 
       
   733 	// Restore the message
       
   734 	iReceiveheader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *iTestUtils->iRichText);
       
   735 	entry->SetEntryL((*msvEntrySelection)[0]);
       
   736 
       
   737 	CMsvStore* store = entry->ReadStoreL();
       
   738 	CleanupStack::PushL(store);	
       
   739 	iTestUtils->Printf(_L("--Restore \n"));
       
   740 	iReceiveheader->RestoreL(*store);
       
   741 	
       
   742 
       
   743 	CleanupStack::PopAndDestroy(3,entry);	
       
   744 	INFO_PRINTF1(_L("Successfully Message header ReStored"));
       
   745 
       
   746 	}
       
   747 
       
   748 
       
   749 void CTestHeaderStoreReStore::TestEmptyEOSSubjectSMSHeaderL()
       
   750 	{
       
   751 	
       
   752 	_LIT(KFunction, ":Test For Store SMS Header ");
       
   753 	INFO_PRINTF1(KFunction);
       
   754 
       
   755 	TMsvEntry entry;
       
   756 	entry.SetVisible(ETrue); 
       
   757 	entry.SetInPreparation(ETrue); 
       
   758 	entry.iServiceId = iTestUtils->iSmsServiceId; 
       
   759 	entry.iType = KUidMsvMessageEntry; 
       
   760 	entry.iMtm = KUidMsgTypeSMS; 
       
   761 	entry.iDate.HomeTime(); 
       
   762 	entry.iSize = 0; 
       
   763 	entry.iDescription.Set(KNullDesC); 
       
   764 	entry.iDetails.Set(KNullDesC); 
       
   765 	entry.SetSendingState(KMsvSendStateScheduled);
       
   766 	
       
   767 
       
   768 	// Create the SMS header object...
       
   769 	iheader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *iTestUtils->iRichText);
       
   770 	//CleanupStack::PushL(iheader);
       
   771 	
       
   772 	// Set the body text...
       
   773 	iTestUtils->iRichText->Reset();
       
   774 	iTestUtils->iRichText->InsertL(0, KMessageData);
       
   775 	
       
   776 	// Copy the message settings...
       
   777 	iheader->SetSmsSettingsL(*iTestUtils->iServiceSettings); 
       
   778 	
       
   779 	// Set the service centre
       
   780 	TInt defaultIndex = iTestUtils->iServiceSettings->DefaultServiceCenter();
       
   781 	iheader->SetServiceCenterAddressL(iTestUtils->iServiceSettings->GetServiceCenter(defaultIndex).Address());
       
   782 
       
   783 
       
   784 	_LIT(KFunction1, ":Test For Store Email over SMS Header ");
       
   785 	INFO_PRINTF1(KFunction1);
       
   786 
       
   787 	
       
   788 	CSmsEmailFields* emailFields = NULL;
       
   789     emailFields = CSmsEmailFields::NewL( iheader->EmailFields() );
       
   790     emailFields->SetSubjectL(KSubject);
       
   791         
       
   792     iheader->SetEmailFieldsL( *emailFields );
       
   793  
       
   794 	iTestUtils->Printf(_L("--Setting single recipient Done \n"));
       
   795 	
       
   796 	// Create the entry - set context to the global outbox.
       
   797 	iTestUtils->iMsvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   798 	iTestUtils->iMsvEntry->CreateL(entry);
       
   799 
       
   800 	// Create new store and save header information 
       
   801 	iTestUtils->iMsvEntry->SetEntryL(entry.Id()); 
       
   802 	CMsvStore* store = iTestUtils->iMsvEntry->EditStoreL();
       
   803 	CleanupStack::PushL(store); 
       
   804 	iheader->StoreL(*store);
       
   805 	store->CommitL();
       
   806 	CleanupStack::PopAndDestroy(1);//store
       
   807 	
       
   808 	INFO_PRINTF1(_L("Successfully Message header Stored"));
       
   809 	
       
   810 	TestReStoreEmptySubjectSMSHeaderL();
       
   811 	}
       
   812 
       
   813 void CTestHeaderStoreReStore::TestReStoreEmptySubjectSMSHeaderL()
       
   814 	{
       
   815 
       
   816 	_LIT(KFunction, ":Test For ReStore SMS Header ");
       
   817 	INFO_PRINTF1(KFunction);
       
   818 
       
   819 			
       
   820 	TMsvSelectionOrdering ordering;	
       
   821 	ordering.ShowInvisibleEntries();
       
   822 	CMsvEntry* entry = CMsvEntry::NewL(*iSession, KMsvGlobalOutBoxIndexEntryId,ordering);
       
   823 	CleanupStack::PushL(entry);
       
   824 	
       
   825 	CMsvEntrySelection* msvEntrySelection;
       
   826 	msvEntrySelection=entry->ChildrenL();
       
   827 	CleanupStack::PushL(msvEntrySelection);
       
   828 	
       
   829 	// Check how many mesasges there are - should be just 1
       
   830 	TInt count = msvEntrySelection->Count();
       
   831 	INFO_PRINTF3(_L("Number of new messages: %d, should be: %d"), count, 1);
       
   832 	ASSERT_TRUE(count == 1);
       
   833 
       
   834 
       
   835 	// Restore the message
       
   836 	iReceiveheader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *iTestUtils->iRichText);
       
   837 	
       
   838 	entry->SetEntryL((*msvEntrySelection)[0]);
       
   839 
       
   840 	CMsvStore* store = entry->ReadStoreL();
       
   841 	CleanupStack::PushL(store);	
       
   842 	iTestUtils->Printf(_L("--Restore \n"));
       
   843 	iReceiveheader->RestoreL(*store);
       
   844 	
       
   845 	CleanupStack::PopAndDestroy(3,entry);	
       
   846 	INFO_PRINTF1(_L("Successfully Message header ReStored"));
       
   847 
       
   848 	}
       
   849 
       
   850 
       
   851 CTestSuite* CTestHeaderStoreReStore::CreateSuiteL(const TDesC& aName)
       
   852 	{
       
   853 	SUB_SUITE;
       
   854 	ADD_ASYNC_TEST_STEP(TestStoreHeaderL);
       
   855 	ADD_ASYNC_TEST_STEP(TestStoreReStoreSMSHeaderL);
       
   856 	ADD_ASYNC_TEST_STEP(TestStoreReStoreEOSSMSHeaderL);
       
   857 	ADD_ASYNC_TEST_STEP(TestStoreReStoreEmptyEOSSMSHeaderL);
       
   858 	ADD_ASYNC_TEST_STEP(TestMultipuleEOSRecipientSMSHeaderL);
       
   859 	ADD_ASYNC_TEST_STEP(TestEmptyEOSSubjectSMSHeaderL);
       
   860 	END_SUITE;
       
   861 	}