messagingfw/msgtest/integration/sms/src/T_smut.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
child 58 6c34d0baa0b1
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2000-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 "T_smcm.h"
       
    17 #include <commsdattypesv1_1.h>
       
    18 #include <commsdat.h>
       
    19 #include <etelmm.h>
       
    20 #include <smutset.h>
       
    21 
       
    22 using namespace CommsDat;
       
    23 
       
    24 	#include <csmsaccount.h>
       
    25 
       
    26 CSmutTest::CSmutTest(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest)
       
    27 : CSmsTestBase(aSmsTest, aScriptFile, aNextTest)
       
    28 	{
       
    29 	}
       
    30 
       
    31 void CSmutTest::RunAutoL()
       
    32 	{
       
    33 	// Testing settings (CSmsSettings)
       
    34 	iSmsTest.TestStart(++iNextTest, _L("CSmsSettings"));  
       
    35 	TestSettingsL();
       
    36 	iSmsTest.TestFinish(iNextTest);
       
    37 
       
    38 	// Testing number class (CSmsNumber)
       
    39 	iSmsTest.TestStart(++iNextTest, _L("CSmsNumber"));  
       
    40 	TestNumberL();
       
    41 	iSmsTest.TestFinish(iNextTest);
       
    42 
       
    43 	// Testing with header (CSmsHeader)
       
    44 	iSmsTest.TestStart(++iNextTest, _L("CSmsHeader"));
       
    45 	TestHeaderL();
       
    46 	iSmsTest.TestFinish(iNextTest);
       
    47 
       
    48 	// Testing with utility class (TSmsUtilities)
       
    49 	iSmsTest.TestStart(++iNextTest, _L("TSmsUtilities"));
       
    50 	TestSmsUtilitiesL();
       
    51 	iSmsTest.TestFinish(iNextTest);
       
    52 
       
    53 	}
       
    54 
       
    55 CSmutTest::~CSmutTest()
       
    56 	{
       
    57 	delete iSmsHeader;
       
    58 	delete iRichText;
       
    59 	delete iParaLayer;
       
    60 	delete iCharLayer;
       
    61 	}
       
    62 
       
    63 void CSmutTest::ConstructL()
       
    64 	{
       
    65 	SetTestNameL(KSmsUtilitiesTestName);
       
    66 	iSmsTest.SetLogToFile();
       
    67 
       
    68 	iSelection = new (ELeave) CMsvEntrySelection();
       
    69 	iTimer = CTestTimer::NewL();
       
    70 
       
    71 	iParaLayer =CParaFormatLayer::NewL();
       
    72 	iCharLayer = CCharFormatLayer::NewL();
       
    73 	iRichText = CRichText::NewL(iParaLayer, iCharLayer, CEditableText::EFlatStorage,256);
       
    74 	CActiveScheduler::Add(this);
       
    75 	}
       
    76 
       
    77 CSmutTest* CSmutTest::NewLC(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest)
       
    78 	{
       
    79 	CSmutTest* self = new (ELeave) CSmutTest(aSmsTest, aScriptFile, aNextTest);
       
    80 	CleanupStack::PushL(self);
       
    81 
       
    82 	self->ConstructL();
       
    83 
       
    84 	return self;
       
    85 	}
       
    86 
       
    87 void CSmutTest::ShowMenuL()
       
    88 	{
       
    89 	iSmsTest.ResetMenu();
       
    90 
       
    91 	iSmsTest.AppendToMenuL(_L("Start"));
       
    92 
       
    93 	TInt result = iSmsTest.DisplayMenu(_L("SMS Client MTM Test"));
       
    94 
       
    95 	if (result <= 0)
       
    96 		return;
       
    97 
       
    98 	switch (result)
       
    99 		{
       
   100 		case 1:
       
   101 			RunAutoL();
       
   102 			break;
       
   103 		default:
       
   104 			User::Leave(KErrArgument);
       
   105 			break;
       
   106 		}
       
   107 
       
   108 	if (!iSmsTest.RunAuto())
       
   109 		{
       
   110 		iSmsTest.Printf(_L("Press any key to continue...\n"));
       
   111 		iSmsTest.Test().Getch();
       
   112 		}
       
   113 
       
   114 	ShowMenuL();
       
   115 	}
       
   116 
       
   117 void CSmutTest::TestSettingsL()
       
   118 	{
       
   119 	iSmsTest.Printf(_L("Testing Create Settings...\n"));
       
   120 
       
   121 	iSmsTest.SetEntryL(iSmsTest.iSmsServiceId);
       
   122 
       
   123 // First we test all the features of the class CSmsSettings
       
   124 // We give them different values and compare if it works
       
   125 
       
   126 	CSmsSettings* settings = CSmsSettings::NewL();
       
   127 	CleanupStack::PushL(settings);
       
   128 	iSmsTest(CompareSettings(*settings, *settings));
       
   129 	TestSettingsMembersL(*settings);
       
   130 	TestMessageSettingsMembersL(*settings);
       
   131 
       
   132 // Lets copy the values to a different instance
       
   133 	CSmsSettings* smsSettings=CSmsSettings::NewL();
       
   134 	CleanupStack::PushL(smsSettings);
       
   135 	smsSettings->CopyL(*settings);
       
   136 	iSmsTest(CompareSettings(*smsSettings, *settings));
       
   137 	CleanupStack::PopAndDestroy(smsSettings);
       
   138 	smsSettings = NULL;
       
   139 	iSmsTest.Printf(_L("Test CSmsSettings::CopyL() passed\n"));
       
   140 
       
   141 //	Lets create a sms service in the file system with these values
       
   142 	StoreSettingsL(*settings);
       
   143 
       
   144 	iSmsTest.Printf(_L("Stored CSmsSettings against the service\n"));
       
   145 
       
   146 // Lets read the service and see it the values are still ok
       
   147 	CSmsSettings* set1=CSmsSettings::NewL();
       
   148 	CleanupStack::PushL(set1);
       
   149 
       
   150 	RestoreSettingsL(*set1);
       
   151 
       
   152 	iSmsTest.Printf(_L("Restored CSmsSettings\n"));
       
   153 
       
   154 	iSmsTest(CompareSettings(*set1, *settings));
       
   155 
       
   156 	CleanupStack::PopAndDestroy(set1);
       
   157 
       
   158 // Lets make the previous test again; Lets give a settings instance some
       
   159 // values, store it, restore it and see that the values are still the same
       
   160 	CSmsSettings* set2=CSmsSettings::NewL();
       
   161 	CleanupStack::PushL(set2);
       
   162 	set2->AddServiceCenterL(_L("Radiolinja0"),_L("+358508771010"));
       
   163 	set2->AddServiceCenterL(_L("Radiolinja1"),_L("+358508771010"));
       
   164 	set2->AddServiceCenterL(_L("Radiolinja2"),_L("+358508771010"));
       
   165 	set2->AddServiceCenterL(_L("Radiolinja3"),_L("+358508771010"));
       
   166 	set2->AddServiceCenterL(_L("Radiolinja4"),_L("+358508771010"));
       
   167 	set2->SetDefaultServiceCenter(1);
       
   168 	iSmsTest(set2->DefaultServiceCenter()==1);
       
   169 // Validity Period	
       
   170 	set2->SetValidityPeriod(ESmsVPSixHours);
       
   171 	iSmsTest(set2->ValidityPeriod().Int()==ESmsVPSixHours);
       
   172 // Reply Quoted
       
   173 	set2->SetReplyQuoted(EFalse);
       
   174 	iSmsTest(!set2->ReplyQuoted());
       
   175 // Reject Duplicate 
       
   176 	set2->SetRejectDuplicate(ETrue);
       
   177 	iSmsTest(set2->RejectDuplicate());
       
   178 // Delivery Method
       
   179 	set2->SetDelivery(ESmsDeliveryUponRequest);
       
   180 	iSmsTest(set2->Delivery()==ESmsDeliveryUponRequest);
       
   181 // Delivery Report
       
   182 	set2->SetDeliveryReport(ETrue);
       
   183 	iSmsTest(set2->DeliveryReport());
       
   184 // Reply Path
       
   185 	set2->SetReplyPath(EFalse);
       
   186 	iSmsTest(!set2->ReplyPath());
       
   187 // Message Conversion
       
   188 	set2->SetMessageConversion(ESmsConvPIDNone);
       
   189 	iSmsTest(set2->MessageConversion()==ESmsConvPIDNone);
       
   190 // Can Concatenate
       
   191 	set2->SetCanConcatenate(ETrue);
       
   192 	iSmsTest(set2->CanConcatenate());
       
   193 // Character Set
       
   194 	set2->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet8Bit);
       
   195 	iSmsTest(set2->CharacterSet()==TSmsDataCodingScheme::ESmsAlphabet8Bit);
       
   196 // Validity period format
       
   197 	set2->SetValidityPeriodFormat(TSmsFirstOctet::ESmsVPFSemiOctet);
       
   198 	iSmsTest(set2->ValidityPeriodFormat()==TSmsFirstOctet::ESmsVPFSemiOctet);
       
   199 // Status Report Handling
       
   200 	set2->SetStatusReportHandling(CSmsSettings::EMoveReportToInboxVisible);
       
   201 	iSmsTest(set2->StatusReportHandling()==CSmsSettings::EMoveReportToInboxVisible);
       
   202 // Special Message Handling
       
   203 	set2->SetSpecialMessageHandling(CSmsSettings::EMoveReportToInboxVisible);
       
   204 	iSmsTest(set2->SpecialMessageHandling()==CSmsSettings::EMoveReportToInboxVisible);
       
   205 
       
   206 	StoreSettingsL(*set2);
       
   207 
       
   208 	iSmsTest.Printf(_L("Stored CSmsSettings 2\n"));
       
   209 
       
   210 
       
   211 	CSmsSettings* set3=CSmsSettings::NewL();
       
   212 	CleanupStack::PushL(set3);
       
   213 
       
   214 	RestoreSettingsL(*set3);
       
   215 
       
   216 	iSmsTest.Printf(_L("Restored CSmsSettings 2\n"));
       
   217 
       
   218 	iSmsTest(CompareSettings(*set2, *set3));
       
   219 
       
   220 	CleanupStack::PopAndDestroy(set3);
       
   221 	CleanupStack::PopAndDestroy(set2);
       
   222 
       
   223 	iSmsTest.iServiceSettings->CopyL(*settings);  // Lets copy the current setting to the service settings
       
   224 
       
   225 	iSmsTest(CompareSettings(*iSmsTest.iServiceSettings, *settings));
       
   226 
       
   227 	iSmsTest.Printf(_L("CSmsSettings::CopyL() 2\n"));
       
   228 
       
   229 	CleanupStack::PopAndDestroy(settings);
       
   230 
       
   231 	iSmsTest.Printf(_L("Test Create Settings Passed\n"));
       
   232 
       
   233 	TestSettingsStoreToCommDbL();
       
   234 
       
   235 	iSmsTest.Printf(_L("TestSettingsStoreToCommDbL Passed\n"));
       
   236 
       
   237 	TestSettingsRestoreDefectL();
       
   238 
       
   239 	iSmsTest.Printf(_L("TestSettingsRestoreDefectL Passed\n"));
       
   240 	}
       
   241 
       
   242 void CSmutTest::TestSettingsMembersL(CSmsSettings& aSettings)
       
   243 	{
       
   244 // Status Report Handling (what should be done to report messages)
       
   245 	aSettings.SetStatusReportHandling(CSmsSettings::EMoveReportToInboxInvisible);
       
   246 	iSmsTest(aSettings.StatusReportHandling()==CSmsSettings::EMoveReportToInboxInvisible);
       
   247 	aSettings.SetStatusReportHandling(CSmsSettings::EMoveReportToInboxVisible);
       
   248 	iSmsTest(aSettings.StatusReportHandling()==CSmsSettings::EMoveReportToInboxVisible);
       
   249 	aSettings.SetStatusReportHandling(CSmsSettings::EDiscardReport);
       
   250 	iSmsTest(aSettings.StatusReportHandling()==CSmsSettings::EDiscardReport);
       
   251 	iSmsTest.Printf(_L("Test Status Report Handling Passed\n"));
       
   252 
       
   253 // SC handling
       
   254 	aSettings.AddServiceCenterL(_L("Radiolinja0"),_L("+358508771010"));
       
   255 	aSettings.AddServiceCenterL(_L("Radiolinja1"),_L("+358508771010"));
       
   256 	aSettings.AddServiceCenterL(_L("Radiolinja2"),_L("+358508771010"));
       
   257 	aSettings.AddServiceCenterL(_L("Radiolinja3"),_L("+358508771010"));
       
   258 	aSettings.AddServiceCenterL(_L("Radiolinja4"),_L("+358508771010"));
       
   259 	iSmsTest(aSettings.GetServiceCenter(0).Name()==_L("Radiolinja0"));
       
   260 	aSettings.RemoveServiceCenter(aSettings.ServiceCenterCount()-3);
       
   261 	aSettings.RemoveServiceCenter(aSettings.ServiceCenterCount()-2);
       
   262 	iSmsTest(aSettings.GetServiceCenter(1).Name()==_L("Radiolinja1"));
       
   263 	iSmsTest(aSettings.GetServiceCenter(2).Name()==_L("Radiolinja4"));
       
   264 	iSmsTest(aSettings.GetServiceCenter(2).Address()==_L("+358508771010"));
       
   265 	aSettings.RemoveServiceCenter(aSettings.ServiceCenterCount()-1);
       
   266 	aSettings.RemoveServiceCenter(aSettings.ServiceCenterCount()-1);
       
   267 	aSettings.RemoveServiceCenter(aSettings.ServiceCenterCount()-1);
       
   268 //	aSettings.RemoveServiceCenter(aSettings.ServiceCenterCount()-1); // this would be -1
       
   269 	aSettings.AddServiceCenterL(_L("Radiolinja0"),_L("+358508771010"));
       
   270 	aSettings.AddServiceCenterL(_L("Radiolinja1"),_L("+358508771010"));
       
   271 	aSettings.AddServiceCenterL(_L("Radiolinja2"),_L("+358508771010"));
       
   272 	aSettings.SetDefaultServiceCenter(1);
       
   273 	iSmsTest(aSettings.DefaultServiceCenter()==1);
       
   274 	aSettings.SetDefaultServiceCenter(2);
       
   275 	iSmsTest(aSettings.DefaultServiceCenter()==2);
       
   276 	iSmsTest.Printf(_L("Test Default SC Passed\n"));
       
   277 
       
   278 
       
   279 // Special Message Handling (what should be done to special messages)
       
   280 	aSettings.SetSpecialMessageHandling(CSmsSettings::EMoveReportToInboxInvisible);
       
   281 	iSmsTest(aSettings.SpecialMessageHandling()==CSmsSettings::EMoveReportToInboxInvisible);
       
   282 	aSettings.SetSpecialMessageHandling(CSmsSettings::EMoveReportToInboxVisible);
       
   283 	iSmsTest(aSettings.SpecialMessageHandling()==CSmsSettings::EMoveReportToInboxVisible);
       
   284 	aSettings.SetSpecialMessageHandling(CSmsSettings::EDiscardReport);
       
   285 	iSmsTest(aSettings.SpecialMessageHandling()==CSmsSettings::EDiscardReport);
       
   286 	iSmsTest.Printf(_L("Test Special Message Handling Passed\n"));
       
   287 
       
   288 //CommDbAction
       
   289 	aSettings.SetCommDbAction(CSmsSettings::ENone);
       
   290 	iSmsTest(aSettings.CommDbAction() == CSmsSettings::ENone);
       
   291 	aSettings.SetCommDbAction(CSmsSettings::EStoreToCommDb);
       
   292 	iSmsTest(aSettings.CommDbAction() == CSmsSettings::EStoreToCommDb);
       
   293 	iSmsTest.Printf(_L("Test CommDb Action Passed\n"));
       
   294 
       
   295 //SmsBearerAction
       
   296 	aSettings.SetSmsBearerAction(CSmsSettings::ENone);
       
   297 	iSmsTest(aSettings.SmsBearerAction() == CSmsSettings::ENone);
       
   298 	aSettings.SetSmsBearerAction(CSmsSettings::EStoreToCommDb);
       
   299 	iSmsTest(aSettings.SmsBearerAction() == CSmsSettings::EStoreToCommDb);
       
   300 	iSmsTest.Printf(_L("Test SMS Bearer Action Passed\n"));
       
   301 
       
   302 //SmsBearer
       
   303 	aSettings.SetSmsBearer(CSmsSettings::ESmsBearerPacketOnly);
       
   304 	iSmsTest(aSettings.SmsBearer() == CSmsSettings::ESmsBearerPacketOnly);
       
   305 	aSettings.SetSmsBearer(CSmsSettings::ESmsBearerPacketOnly);
       
   306 	iSmsTest(aSettings.SmsBearer() == CSmsSettings::ESmsBearerPacketOnly);
       
   307 	aSettings.SetSmsBearer(CSmsSettings::ESmsBearerCircuitOnly);
       
   308 	iSmsTest(aSettings.SmsBearer() == CSmsSettings::ESmsBearerCircuitOnly);
       
   309 	aSettings.SetSmsBearer(CSmsSettings::ESmsBearerPacketPreferred);
       
   310 	iSmsTest(aSettings.SmsBearer() == CSmsSettings::ESmsBearerPacketPreferred);
       
   311 	aSettings.SetSmsBearer(CSmsSettings::ESmsBearerCircuitPreferred);
       
   312 	iSmsTest(aSettings.SmsBearer() == CSmsSettings::ESmsBearerCircuitPreferred);
       
   313 	iSmsTest.Printf(_L("Test SMS Bearer Passed\n"));
       
   314 
       
   315 // Reply Quoted
       
   316 	aSettings.SetReplyQuoted(EFalse);
       
   317 	iSmsTest(!aSettings.ReplyQuoted());
       
   318 	aSettings.SetReplyQuoted(ETrue);
       
   319 	iSmsTest(aSettings.ReplyQuoted());
       
   320 	iSmsTest.Printf(_L("Test Reply Quoted Passed\n"));
       
   321 
       
   322 // Delivery Method
       
   323 	aSettings.SetDelivery(ESmsDeliveryUponRequest);
       
   324 	iSmsTest(aSettings.Delivery()==ESmsDeliveryUponRequest);
       
   325 	aSettings.SetDelivery(ESmsDeliveryScheduled);
       
   326 	iSmsTest(aSettings.Delivery()==ESmsDeliveryScheduled);
       
   327 	aSettings.SetDelivery(ESmsDeliveryImmediately);
       
   328 	iSmsTest(aSettings.Delivery()==ESmsDeliveryImmediately);
       
   329 	iSmsTest.Printf(_L("Test Delivery Passed\n"));
       
   330 	}
       
   331 
       
   332 void CSmutTest::TestMessageSettingsMembersL(CSmsMessageSettings& aSettings)
       
   333 	{
       
   334 
       
   335 // Reject Duplicate 
       
   336 	aSettings.SetRejectDuplicate(ETrue);
       
   337 	iSmsTest(aSettings.RejectDuplicate());
       
   338 	aSettings.SetRejectDuplicate(EFalse);
       
   339 	iSmsTest(!aSettings.RejectDuplicate());
       
   340 	iSmsTest.Printf(_L("Test Reject Duplicate Passed\n"));
       
   341 
       
   342 // Delivery Report
       
   343 	aSettings.SetDeliveryReport(ETrue);
       
   344 	iSmsTest(aSettings.DeliveryReport());
       
   345 	aSettings.SetDeliveryReport(EFalse);
       
   346 	iSmsTest(!aSettings.DeliveryReport());
       
   347 	iSmsTest.Printf(_L("Test Delivery Report Passed\n"));
       
   348 
       
   349 // Reply Path
       
   350 	aSettings.SetReplyPath(EFalse);
       
   351 	iSmsTest(aSettings.ReplyPath()==EFalse);
       
   352 	aSettings.SetReplyPath(ETrue);
       
   353 	iSmsTest(aSettings.ReplyPath());
       
   354 	iSmsTest.Printf(_L("Test Reply Path Passed\n"));
       
   355 
       
   356 // Validity period format
       
   357 	aSettings.SetValidityPeriodFormat(TSmsFirstOctet::ESmsVPFNone);
       
   358 	iSmsTest(aSettings.ValidityPeriodFormat()==TSmsFirstOctet::ESmsVPFNone);
       
   359 	aSettings.SetValidityPeriodFormat(TSmsFirstOctet::ESmsVPFEnhanced);
       
   360 	iSmsTest(aSettings.ValidityPeriodFormat()==TSmsFirstOctet::ESmsVPFEnhanced);
       
   361 	aSettings.SetValidityPeriodFormat(TSmsFirstOctet::ESmsVPFInteger);
       
   362 	iSmsTest(aSettings.ValidityPeriodFormat()==TSmsFirstOctet::ESmsVPFInteger);
       
   363 	aSettings.SetValidityPeriodFormat(TSmsFirstOctet::ESmsVPFSemiOctet);
       
   364 	iSmsTest(aSettings.ValidityPeriodFormat()==TSmsFirstOctet::ESmsVPFSemiOctet);
       
   365 	iSmsTest.Printf(_L("Test Validity Period Format Passed\n"));
       
   366 
       
   367 // Message Conversion (following conversions are supported)
       
   368 	aSettings.SetMessageConversion(ESmsConvFax);
       
   369 	iSmsTest(aSettings.MessageConversion()==ESmsConvFax);
       
   370 	aSettings.SetMessageConversion(ESmsConvX400);
       
   371 	iSmsTest(aSettings.MessageConversion()==ESmsConvX400);
       
   372 	aSettings.SetMessageConversion(ESmsConvPaging);
       
   373 	iSmsTest(aSettings.MessageConversion()==ESmsConvPaging);
       
   374 	aSettings.SetMessageConversion(ESmsConvMail);
       
   375 	iSmsTest(aSettings.MessageConversion()==ESmsConvMail);
       
   376 	aSettings.SetMessageConversion(ESmsConvErmes);
       
   377 	iSmsTest(aSettings.MessageConversion()==ESmsConvErmes);
       
   378 	aSettings.SetMessageConversion(ESmsConvSpeech);
       
   379 	iSmsTest(aSettings.MessageConversion()==ESmsConvSpeech);
       
   380 	aSettings.SetMessageConversion(ESmsConvPIDNone);
       
   381 	iSmsTest(aSettings.MessageConversion()==ESmsConvPIDNone);
       
   382 	iSmsTest.Printf(_L("Test Message Conversion Passed\n"));
       
   383 
       
   384 // Validity Period	
       
   385 	aSettings.SetValidityPeriod(ESmsVPHour);
       
   386 	iSmsTest(aSettings.ValidityPeriod().Int()==ESmsVPHour);
       
   387 	aSettings.SetValidityPeriod(ESmsVPSixHours);
       
   388 	iSmsTest(aSettings.ValidityPeriod().Int()==ESmsVPSixHours);
       
   389 	aSettings.SetValidityPeriod(ESmsVP24Hours);
       
   390 	iSmsTest(aSettings.ValidityPeriod().Int()==ESmsVP24Hours);
       
   391 	aSettings.SetValidityPeriod(ESmsVPMaximum);
       
   392 	iSmsTest(aSettings.ValidityPeriod().Int()==ESmsVPMaximum);
       
   393 	aSettings.SetValidityPeriod(ESmsVPWeek);
       
   394 	iSmsTest(aSettings.ValidityPeriod().Int()==ESmsVPWeek);
       
   395 	iSmsTest.Printf(_L("Test Validity Period Passed\n"));
       
   396 
       
   397 // Can Concatenate (write messages with more than 160 characters)
       
   398 	aSettings.SetCanConcatenate(ETrue);
       
   399 	iSmsTest(aSettings.CanConcatenate());
       
   400 	aSettings.SetCanConcatenate(EFalse);
       
   401 	iSmsTest(aSettings.CanConcatenate()==EFalse);
       
   402 	iSmsTest.Printf(_L("Test Can Concatenate Passed\n"));
       
   403 
       
   404 // Character Set (following character sets are supported)
       
   405 	aSettings.SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet7Bit);
       
   406 	iSmsTest(aSettings.CharacterSet()==TSmsDataCodingScheme::ESmsAlphabet7Bit);
       
   407 	aSettings.SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabetUCS2);
       
   408 	iSmsTest(aSettings.CharacterSet()==TSmsDataCodingScheme::ESmsAlphabetUCS2);
       
   409 	aSettings.SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet8Bit);
       
   410 	iSmsTest(aSettings.CharacterSet()==TSmsDataCodingScheme::ESmsAlphabet8Bit);
       
   411 	iSmsTest.Printf(_L("Test Character Set Passed\n"));
       
   412 	}
       
   413 
       
   414 TBool CSmutTest::CompareSettings(const CSmsSettings& aLeft, const CSmsSettings& aRight, TBool aTestSC)
       
   415 	{
       
   416 	TCompare compare(CompareMessageSettings(aLeft, aRight));
       
   417 
       
   418 	compare(aLeft.CommDbAction() == aRight.CommDbAction());
       
   419 	compare(aLeft.SmsBearerAction() == aRight.SmsBearerAction());
       
   420 	compare(aLeft.SmsBearer() == aRight.SmsBearer());
       
   421 	compare(aLeft.Delivery() == aRight.Delivery());
       
   422 	compare(CompareBools(aLeft.ReplyQuoted(), aRight.ReplyQuoted()));
       
   423 	compare(aLeft.SpecialMessageHandling() == aRight.SpecialMessageHandling());
       
   424 	compare(aLeft.StatusReportHandling() == aRight.StatusReportHandling());
       
   425 
       
   426 	if (aTestSC)
       
   427 		{
       
   428 		compare(aLeft.DefaultServiceCenter() == aRight.DefaultServiceCenter());
       
   429 		compare(aLeft.ServiceCenterCount() == aRight.ServiceCenterCount());
       
   430 
       
   431 		TInt count = aLeft.ServiceCenterCount();
       
   432 
       
   433 		while (count--)
       
   434 			{
       
   435 			compare(CompareServiceCenters(aLeft.GetServiceCenter(count), aRight.GetServiceCenter(count)));
       
   436 			}
       
   437 		}		
       
   438 
       
   439 	return compare;
       
   440 	}
       
   441 
       
   442 TBool CSmutTest::CompareMessageSettings(const CSmsMessageSettings& aLeft, const CSmsMessageSettings& aRight)
       
   443 	{
       
   444 	TCompare compare(CompareBools(aLeft.CanConcatenate(), aRight.CanConcatenate()));
       
   445 	compare(aLeft.CharacterSet() == aRight.CharacterSet());
       
   446 	compare(CompareBools(aLeft.DeliveryReport(), aRight.DeliveryReport()));
       
   447 	compare(aLeft.MessageConversion() == aRight.MessageConversion());
       
   448 	compare(CompareBools(aLeft.RejectDuplicate(), aRight.RejectDuplicate()));
       
   449 	compare(CompareBools(aLeft.ReplyPath(), aRight.ReplyPath()));
       
   450 	compare(aLeft.ValidityPeriod() == aRight.ValidityPeriod());
       
   451 	compare(aLeft.ValidityPeriodFormat() == aRight.ValidityPeriodFormat());
       
   452 	return compare;
       
   453 	}
       
   454 
       
   455 void CSmutTest::TestSettingsRestoreDefectL()
       
   456 	{
       
   457 	//Test fix for defects EDNAALR-4KTKTD (CSmsSettings::RestoreL() should leave if stream not present)
       
   458 	//and EDNAALR-4KTKLP (CSmsSettings::InternalizeL() causes memory leak)
       
   459 
       
   460 	CSmsSettings* settings = CSmsSettings::NewL();
       
   461 	CleanupStack::PushL(settings);
       
   462 
       
   463 	//Test defect fix for EDNAALR-4KTKTD (CSmsSettings::RestoreL() should leave if stream not present)
       
   464 	const TMsvId id = iSmsTest.CreateDummyMessageToSendL();
       
   465 	Session().CleanupEntryPushL(id);
       
   466 	iSmsTest.SetEntryL(id);
       
   467 
       
   468 	iSmsTest.Printf(_L("TestSettingsRestoreDefectL Created dummy message\n"));
       
   469 
       
   470 	TRAPD(err, RestoreSettingsL(*settings));
       
   471 
       
   472 	iSmsTest.Printf(_L("TestSettingsRestoreDefectL RestoreL 1 with error %d\n"), err);
       
   473 	iSmsTest.Printf(_L("Expected %d\n"), KErrNotFound);
       
   474 	iSmsTest(err == KErrNotFound);
       
   475 
       
   476 	//Test defect fix for EDNAALR-4KTKLP (CSmsSettings::InternalizeL() causes memory leak)
       
   477 //	iSmsTest.SetEntryL(id);
       
   478 	StoreSettingsL(*settings);
       
   479 
       
   480 	iSmsTest.Printf(_L("TestSettingsRestoreDefectL StoreL 1\n"));
       
   481 
       
   482 	settings->AddServiceCenterL(_L("Unknown"), _L("447785016005"));
       
   483 
       
   484 	RestoreSettingsL(*settings);
       
   485 
       
   486 	CleanupStack::PopAndDestroy(); //id
       
   487 	CleanupStack::PopAndDestroy(settings);
       
   488 	iSmsTest.Printf(_L("TestSettingsRestoreDefectL RestoreL 2\n"));
       
   489 	}
       
   490 
       
   491 void CSmutTest::TestSettingsStoreToCommDbL()
       
   492 	{
       
   493 	iSmsTest.Test().Next(_L("Storing CSmsSettings to CommDb\n"));
       
   494 	iSmsTest.Printf(_L("Test Store Settings to CommDb\n"));
       
   495 
       
   496 	CSmsSettings* settings1 = CSmsSettings::NewL();
       
   497 	CleanupStack::PushL(settings1);
       
   498 
       
   499 	CSmsSettings* settings2 = CSmsSettings::NewL();
       
   500 	CleanupStack::PushL(settings2);
       
   501 
       
   502 	iSmsTest(CompareSettings(*settings1, *settings2));
       
   503 
       
   504 	settings1->SetCommDbAction(CSmsSettings::EStoreToCommDb);
       
   505 	settings1->AddServiceCenterL(_L("Vodafone"), _L("+447785016005"));
       
   506 	settings1->SetDeliveryReport(ETrue);
       
   507 	settings1->SetValidityPeriod(1000);
       
   508 
       
   509 	iSmsTest.SetEntryL(iSmsTest.iSmsServiceId);
       
   510 
       
   511 	StoreSettingsL(*settings1);
       
   512 	iSmsTest.Printf(_L("\tNew Settings...\n"));
       
   513 	iSmsTest(CompareSettingsAndCommDbL(*settings1));
       
   514 
       
   515 	settings1->GetServiceCenter(settings1->DefaultServiceCenter()).SetAddressL(_L("+3854354433"));
       
   516 
       
   517 	StoreSettingsL(*settings1);
       
   518 	iSmsTest.Printf(_L("\tSC Address Changed...\n"));
       
   519 	iSmsTest(CompareSettingsAndCommDbL(*settings1));
       
   520 	
       
   521 	settings1->SetDeliveryReport(EFalse);
       
   522 
       
   523 	StoreSettingsL(*settings1);
       
   524 	iSmsTest.Printf(_L("\tDelivery Report Changed...\n"));
       
   525 	iSmsTest(CompareSettingsAndCommDbL(*settings1));
       
   526 
       
   527 	settings1->SetValidityPeriod(2000);
       
   528 
       
   529 	StoreSettingsL(*settings1);
       
   530 	iSmsTest.Printf(_L("\tValidity Period Changed...\n"));
       
   531 	iSmsTest(CompareSettingsAndCommDbL(*settings1));
       
   532 
       
   533 	settings1->GetServiceCenter(settings1->DefaultServiceCenter()).SetAddressL(_L("+48996655888"));
       
   534 	settings1->SetDeliveryReport(ETrue);
       
   535 	settings1->SetValidityPeriod(3000);
       
   536 
       
   537 	StoreSettingsL(*settings1);
       
   538 	iSmsTest.Printf(_L("\tAll Settings Changed...\n"));
       
   539 	iSmsTest(CompareSettingsAndCommDbL(*settings1));
       
   540 
       
   541 	settings1->AddServiceCenterL(_L("Radio"), _L("+385669988"));
       
   542 	settings1->SetDefaultServiceCenter(settings1->ServiceCenterCount()-1);
       
   543 
       
   544 	StoreSettingsL(*settings1);
       
   545 	iSmsTest.Printf(_L("\tDefaultSC Changed...\n"));
       
   546 	iSmsTest(CompareSettingsAndCommDbL(*settings1));
       
   547 
       
   548 	settings1->SetCommDbAction(CSmsSettings::ENone);
       
   549 	settings1->GetServiceCenter(settings1->DefaultServiceCenter()).SetAddressL(_L("+123456789"));
       
   550 	settings1->SetDeliveryReport(EFalse);
       
   551 	settings1->SetValidityPeriod(4000);
       
   552 
       
   553 	iSmsTest.Printf(_L("\tTesting Setting Different from CommDb...\n"));
       
   554 	iSmsTest(!CompareSettingsAndCommDbL(*settings1));
       
   555 
       
   556 	TInt count = settings1->ServiceCenterCount();
       
   557 
       
   558 	while (count--)
       
   559 		{
       
   560 		settings1->RemoveServiceCenter(count);
       
   561 		}
       
   562 
       
   563 	iSmsTest.Printf(_L("\tTesting Setting Different from CommDb...\n"));
       
   564 	iSmsTest(!CompareSettingsAndCommDbL(*settings1));
       
   565 
       
   566 	iSmsTest.Printf(_L("\tRestore settings from store...\n"));
       
   567 	RestoreSettingsL(*settings2);
       
   568 	iSmsTest(CompareSettingsAndCommDbL(*settings2));
       
   569 
       
   570 //Test SMS Bearer
       
   571 
       
   572 	iSmsTest.Printf(_L("\tTest Store SMS Bearer...\n"));
       
   573 
       
   574 //Test 1
       
   575 
       
   576 	settings1->SetSmsBearerAction(CSmsSettings::EStoreToCommDb);
       
   577 	settings1->SetSmsBearer(CSmsSettings::ESmsBearerPacketOnly);
       
   578 
       
   579 	StoreSettingsL(*settings1);
       
   580 	iSmsTest(CompareSettingsAndSmsBearerL(*settings1));
       
   581 	
       
   582 //Test 2
       
   583 
       
   584 	settings1->SetSmsBearer(CSmsSettings::ESmsBearerCircuitOnly);
       
   585 	iSmsTest(!CompareSettingsAndSmsBearerL(*settings1));
       
   586 
       
   587 //Test 3
       
   588 
       
   589 	StoreSettingsL(*settings1);
       
   590 	iSmsTest(CompareSettingsAndSmsBearerL(*settings1));
       
   591 
       
   592 	RestoreSettingsL(*settings2);
       
   593 	iSmsTest(CompareSettingsAndSmsBearerL(*settings2));
       
   594 
       
   595 //Test 4
       
   596 
       
   597 	settings1->SetSmsBearerAction(CSmsSettings::ENone);
       
   598 	StoreSettingsL(*settings1);
       
   599 	iSmsTest(CompareSettingsAndSmsBearerL(*settings1));
       
   600 
       
   601 //Test 5
       
   602 
       
   603 	settings1->SetSmsBearer(CSmsSettings::ESmsBearerCircuitPreferred);
       
   604 	iSmsTest(!CompareSettingsAndSmsBearerL(*settings1));
       
   605 	StoreSettingsL(*settings1);
       
   606 	iSmsTest(!CompareSettingsAndSmsBearerL(*settings1));
       
   607 
       
   608 	CleanupStack::PopAndDestroy(2); //settings1, settings2
       
   609 	}
       
   610 
       
   611 TBool CSmutTest::CompareSettingsAndCommDbL(const CSmsSettings& aSettings) const
       
   612 	{
       
   613 	TCompare compare = ETrue;
       
   614 
       
   615 	TBuf<256> scAddress;
       
   616 	CMDBSession* iDBSession = CMDBSession::NewL(CMDBSession::LatestVersion());
       
   617 	CMDBRecordSet<CCDGlobalSettingsRecord> globalSettingsRecord(KCDTIdGlobalSettingsRecord);
       
   618 	TRAPD(err, globalSettingsRecord.LoadL(*iDBSession));
       
   619 	if(err != KErrNone)
       
   620 		{
       
   621 		User::Leave(KErrNotFound);				
       
   622 		}
       
   623 	
       
   624 	CCDModemBearerRecord *modemBearerRecord = static_cast<CCDModemBearerRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdModemBearerRecord));
       
   625 	CleanupStack::PushL(modemBearerRecord);
       
   626 	modemBearerRecord->SetRecordId(((CCDGlobalSettingsRecord*)globalSettingsRecord.iRecords[0])->iModemForPhoneServicesAndSMS); 
       
   627 	modemBearerRecord->LoadL(*iDBSession);
       
   628 	scAddress = modemBearerRecord->iMessageCentreNumber;
       
   629 
       
   630 	if (aSettings.DefaultServiceCenter() < 0 || !aSettings.ServiceCenterCount())
       
   631 		{
       
   632 		compare(!scAddress.Length());
       
   633 		}
       
   634 	else
       
   635 		{
       
   636 		compare(scAddress == aSettings.GetServiceCenter(aSettings.DefaultServiceCenter()).Address());
       
   637 		}
       
   638 
       
   639 	TUint32 valPeriod = 0;
       
   640 	valPeriod = modemBearerRecord->iMessageValidityPeriod;
       
   641 	compare(valPeriod == (TUint32) aSettings.ValidityPeriod().Int());
       
   642 
       
   643 	TBool delReport = EFalse;
       
   644 	delReport = modemBearerRecord->iMessageDeliveryReport;
       
   645 	compare(delReport ? aSettings.DeliveryReport() : !aSettings.DeliveryReport());
       
   646 	CleanupStack::PopAndDestroy(modemBearerRecord);	
       
   647 	delete iDBSession;	
       
   648 	iDBSession = NULL;
       
   649 	return compare;
       
   650 	}
       
   651 
       
   652 TBool CSmutTest::CompareSettingsAndSmsBearerL(const CSmsSettings& aSettings) const
       
   653 	{
       
   654 	TUint32 smsBearer;
       
   655 	CMDBSession* iDBSession = CMDBSession::NewL(CMDBSession::LatestVersion());
       
   656 	CMDBRecordSet<CCDGlobalSettingsRecord> globalSettingsRecord(KCDTIdGlobalSettingsRecord);
       
   657 	TRAPD(err, globalSettingsRecord.LoadL(*iDBSession));
       
   658 	if(err != KErrNone)
       
   659 		{
       
   660 		User::Leave(KErrNotFound);				
       
   661 		}
       
   662 	smsBearer = ((CCDGlobalSettingsRecord*)globalSettingsRecord.iRecords[0])->iSMSBearer;	
       
   663 	delete iDBSession;	
       
   664 	iDBSession = NULL;
       
   665 	TCompare compare(smsBearer == (TUint32) aSettings.SmsBearer());
       
   666 	return compare;
       
   667 	}
       
   668 
       
   669 void CSmutTest::StoreNumberL(const CSmsNumber& aNumber, TUid aStreamId)
       
   670 	{
       
   671 	CMsvStore* store = iSmsTest.EditStoreL(); // lets edit the entry
       
   672 	CleanupStack::PushL(store);
       
   673 
       
   674 	RMsvWriteStream out;
       
   675 	out.AssignLC(*store, aStreamId);		// file stream id ok?
       
   676 	aNumber.ExternalizeL(out);				// lets extrenalise the instance
       
   677 	out.CommitL();
       
   678 	store->CommitL();
       
   679 
       
   680 	CleanupStack::PopAndDestroy(2);			// out, store
       
   681 	}
       
   682 
       
   683 void CSmutTest::RestoreNumberL(CSmsNumber& rNumber, TUid aStreamId)
       
   684 	{
       
   685 	CMsvStore* store = iSmsTest.ReadStoreL(); // prepare the store for reading
       
   686 	CleanupStack::PushL(store);
       
   687 
       
   688 	RMsvReadStream in;
       
   689 	in.OpenLC(*store, aStreamId);		// lets open the store for 
       
   690 	rNumber.InternalizeL(in);				// internalising the address/name
       
   691 
       
   692 	CleanupStack::PopAndDestroy(2);			// in, store
       
   693 	}
       
   694 
       
   695 void CSmutTest::StoreHeaderL(const CSmsHeader& aHeader)
       
   696 	{
       
   697 	CMsvStore* store = iSmsTest.EditStoreL();
       
   698 	CleanupStack::PushL(store);
       
   699 
       
   700 	aHeader.StoreL(*store);
       
   701 	store->CommitL();
       
   702 
       
   703 	CleanupStack::PopAndDestroy(store);
       
   704 	}
       
   705 
       
   706 void CSmutTest::RestoreHeaderL(CSmsHeader& aHeader)
       
   707 	{
       
   708 	CMsvStore* store = iSmsTest.ReadStoreL();
       
   709 	CleanupStack::PushL(store);
       
   710 
       
   711 	aHeader.RestoreL(*store);
       
   712 
       
   713 	CleanupStack::PopAndDestroy(store);
       
   714 	}
       
   715 
       
   716 void CSmutTest::StoreSettingsL(const CSmsSettings& aSettings)
       
   717 	{
       
   718 	
       
   719 	CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   720 	smsAccount->SaveSettingsL(aSettings);
       
   721 	CleanupStack::PopAndDestroy(smsAccount);
       
   722 	
       
   723 	}
       
   724 
       
   725 void CSmutTest::RestoreSettingsL(CSmsSettings& aSettings)
       
   726 	{
       
   727 
       
   728 	CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   729 	smsAccount->LoadSettingsL(aSettings);
       
   730 	CleanupStack::PopAndDestroy(smsAccount);
       
   731 
       
   732 	}
       
   733 
       
   734 TBool CSmutTest::CompareServiceCenters(const CSmsServiceCenter& aLeft, const CSmsServiceCenter& aRight)
       
   735 	{
       
   736 	TCompare compare(aLeft.Name() == aRight.Name());
       
   737 	compare(aLeft.Address() == aRight.Address());
       
   738 
       
   739 	return compare;
       
   740 	}
       
   741 
       
   742 TBool CSmutTest::CompareNumbers(const CSmsNumber& aLeft, const CSmsNumber& aRight)
       
   743 	{
       
   744 	TCompare compare(aLeft.Name() == aRight.Name());
       
   745 	compare(aLeft.Address() == aRight.Address());
       
   746 	compare(aLeft.LogId() == aRight.LogId());
       
   747 
       
   748 	return compare;
       
   749 	}
       
   750 
       
   751 void CSmutTest::TestNumberL()
       
   752 	{
       
   753 	iSmsTest.Test().Next(_L("Testing CSmsNumber"));
       
   754 	iSmsTest.Printf(_L("Preparing test CSmsNumber"));
       
   755 
       
   756 	TMsvId id=iSmsTest.CreateDummyMessageToSendL();
       
   757 	Session().CleanupEntryPushL(id);
       
   758 	iSmsTest.SetEntryL(id);
       
   759 
       
   760 	CSmsNumber* number0=CSmsNumber::NewL();  
       
   761 	CleanupStack::PushL(number0);
       
   762 
       
   763 	CSmsNumber* number=CSmsNumber::NewL();  // create the instance
       
   764 	CleanupStack::PushL(number);
       
   765 
       
   766 	// Testing the features of CSmsNumber
       
   767 	// The max length for a name is 256 characters
       
   768 	// The max length for a number is 20 characters
       
   769 
       
   770 
       
   771 // Lets take an ordinary number, test it, then store and restore it
       
   772 // and see if the values are still ok.
       
   773 
       
   774 	number->SetNameL(_L("Radiolinja1"));	// set the name
       
   775 	number->SetAddressL(_L("+358508771010")); // set the address
       
   776 
       
   777 	iSmsTest(number->Name()==_L("Radiolinja1")); // name ok?
       
   778 	iSmsTest(number->Address()==_L("+358508771010")); // number ok?
       
   779 
       
   780 	StoreNumberL(*number);
       
   781 	RestoreNumberL(*number0);
       
   782 	iSmsTest(CompareNumbers(*number0, *number));
       
   783 	
       
   784 // Lets try the max length of the telephone address, store and
       
   785 // restore it and see if it works
       
   786 
       
   787 	number->SetNameL(_L("Whatsthemaximumlengthforthis?Whatsthemaximumlengthforthis?Whatsthemaximumlengthforthis?"));
       
   788 	number->SetAddressL(_L("+0123456789012345678"));
       
   789 	iSmsTest(number->Name()==_L("Whatsthemaximumlengthforthis?Whatsthemaximumlengthforthis?Whatsthemaximumlengthforthis?"));
       
   790 	iSmsTest(number->Address()==_L("+0123456789012345678"));
       
   791 
       
   792 	StoreNumberL(*number);
       
   793 	RestoreNumberL(*number0);
       
   794 	iSmsTest(CompareNumbers(*number, *number0));
       
   795 
       
   796 // Lets use special Scandinavian letters both in the name and
       
   797 // address, store and restore and see if they are ok
       
   798 	number->SetNameL(_L("ÖÄÅåöä"));
       
   799 	number->SetAddressL(_L("åäöÅÄÖ"));
       
   800 	iSmsTest(number->Name()==_L("ÖÄÅåöä"));
       
   801 	iSmsTest(number->Address()==_L("åäöÅÄÖ"));
       
   802 
       
   803 	StoreNumberL(*number);
       
   804 	RestoreNumberL(*number0);
       
   805 	iSmsTest(CompareNumbers(*number, *number0));
       
   806 
       
   807 //  Lets try if both the number and the name can be empty,
       
   808 //	store and restore it and see if they still match
       
   809 	number->SetNameL(_L(""));
       
   810 	number->SetAddressL(_L(""));
       
   811 	iSmsTest(number->Name()==_L(""));
       
   812 	iSmsTest(number->Address()==_L(""));
       
   813 
       
   814 	StoreNumberL(*number);
       
   815 	RestoreNumberL(*number0);
       
   816 	iSmsTest(CompareNumbers(*number, *number0));
       
   817 
       
   818 //  Lets try [alt+255] as both the name and number, store and	
       
   819 //  restore it and see if it works
       
   820 	number->SetNameL(_L(" ")); //alt+255
       
   821 	number->SetAddressL(_L(" "));
       
   822 	iSmsTest(number->Name()==_L(" "));
       
   823 	iSmsTest(number->Address()==_L(" "));
       
   824 
       
   825 	StoreNumberL(*number);
       
   826 	RestoreNumberL(*number0);
       
   827 	iSmsTest(CompareNumbers(*number, *number0));
       
   828 
       
   829 	CleanupStack::PopAndDestroy(2); //number, number0
       
   830 
       
   831 	//Test for defect EDNMOHN-4LDDK8
       
   832 	number=CSmsNumber::NewL();  // create the instance
       
   833 	CleanupStack::PushL(number);
       
   834 
       
   835 	StoreNumberL(*number);
       
   836 	RestoreNumberL(*number);
       
   837 
       
   838 	number->SetAddressL(_L("+4477676545"));
       
   839 	//End Test for defect  EDNMOHN-4LDDK8
       
   840 
       
   841 	CleanupStack::PopAndDestroy(2); //number, id
       
   842 	}
       
   843 
       
   844 void CSmutTest::TestHeaderL()
       
   845 	{
       
   846 
       
   847 // Testing class CSmsHeader
       
   848 	iSmsTest.Test().Next(_L("Testing CSmsHeader"));
       
   849 	
       
   850 // A CSmsHeader can be of 6 different types
       
   851 // First we test constructing ESmsDeliver
       
   852 	delete iSmsHeader; // deleting the previous one
       
   853 	iSmsHeader = NULL;
       
   854 	iSmsHeader=CSmsHeader::NewL(CSmsPDU::ESmsDeliver,*iRichText); // constructing
       
   855 	iSmsTest(iSmsHeader->Type()==CSmsPDU::ESmsDeliver);	// type ok?
       
   856 
       
   857 	CSmsDeliver& deliver = iSmsHeader->Deliver();  // lets get the CSmsPDU of the CSmsHeader
       
   858 	const CSmsDeliver& deliver2 = iSmsHeader->Deliver();
       
   859 
       
   860 	iSmsTest(deliver.Type() == CSmsPDU::ESmsDeliver); // Are the types ok?
       
   861 	iSmsTest(deliver2.Type() == CSmsPDU::ESmsDeliver);
       
   862 
       
   863 // Type ESmsCommand
       
   864 	delete iSmsHeader; // deleting previous
       
   865 	iSmsHeader=CSmsHeader::NewL(CSmsPDU::ESmsCommand,*iRichText);
       
   866 	iSmsTest(iSmsHeader->Type()==CSmsPDU::ESmsCommand);
       
   867 
       
   868 	CSmsCommand& command=iSmsHeader->Command();
       
   869 	const CSmsCommand& command2=iSmsHeader->Command();
       
   870 
       
   871 	iSmsTest(command.Type() == CSmsPDU::ESmsCommand);
       
   872 	iSmsTest(command2.Type() == CSmsPDU::ESmsCommand);
       
   873 
       
   874 // Type ESmsStatusReport
       
   875 	delete iSmsHeader; // deleting the previous one
       
   876 	iSmsHeader=CSmsHeader::NewL(CSmsPDU::ESmsStatusReport,*iRichText);
       
   877 	iSmsTest(iSmsHeader->Type()==CSmsPDU::ESmsStatusReport);
       
   878 
       
   879 	CSmsStatusReport& statusreport=iSmsHeader->StatusReport();
       
   880 	const CSmsStatusReport& statusreport2=iSmsHeader->StatusReport();
       
   881 
       
   882 	iSmsTest(statusreport.Type() == CSmsPDU::ESmsStatusReport);
       
   883 	iSmsTest(statusreport2.Type() == CSmsPDU::ESmsStatusReport);
       
   884 
       
   885 // Type ESmsSubmit
       
   886 	delete iSmsHeader; // deleting the previous one
       
   887 	iSmsHeader=CSmsHeader::NewL(CSmsPDU::ESmsSubmit,*iRichText);
       
   888 	iSmsTest(iSmsHeader->Type()==CSmsPDU::ESmsSubmit);
       
   889 
       
   890 	CSmsSubmit& submit=iSmsHeader->Submit();
       
   891 	const CSmsSubmit& submit2=iSmsHeader->Submit();
       
   892 
       
   893 	iSmsTest(submit.Type() == CSmsPDU::ESmsSubmit);
       
   894 	iSmsTest(submit2.Type() == CSmsPDU::ESmsSubmit);
       
   895 
       
   896 // Lets access the CSmsMessage of our header
       
   897 	CSmsMessage& message=iSmsHeader->Message();
       
   898 	const CSmsMessage& message2=iSmsHeader->Message();
       
   899 
       
   900 	iSmsTest(message.Type() == CSmsPDU::ESmsSubmit);
       
   901 	iSmsTest(message2.Type() == CSmsPDU::ESmsSubmit);
       
   902 
       
   903 // Lets test the features of CSmsHeader with different values
       
   904 	iSmsHeader->SetReplyPathProvided(ETrue);
       
   905 	iSmsTest(iSmsHeader->ReplyPathProvided());
       
   906 	iSmsHeader->SetReplyPathProvided(EFalse);
       
   907 	iSmsTest(!iSmsHeader->ReplyPathProvided());
       
   908 
       
   909 	iSmsHeader->SetBioMsgIdType(EBioMsgIdUnknown);
       
   910 	iSmsTest(iSmsHeader->BioMsgIdType()==EBioMsgIdUnknown);
       
   911 	iSmsHeader->SetBioMsgIdType(EBioMsgIdIana);
       
   912 	iSmsTest(iSmsHeader->BioMsgIdType()==EBioMsgIdIana);
       
   913 	iSmsHeader->SetBioMsgIdType(EBioMsgIdNbs);
       
   914 	iSmsTest(iSmsHeader->BioMsgIdType()==EBioMsgIdNbs);
       
   915 	iSmsHeader->SetBioMsgIdType(EBioMsgIdWap);
       
   916 	iSmsTest(iSmsHeader->BioMsgIdType()==EBioMsgIdWap);
       
   917 	iSmsHeader->SetBioMsgIdType(EBioMsgIdWapSecure);
       
   918 	iSmsTest(iSmsHeader->BioMsgIdType()==EBioMsgIdWapSecure);
       
   919 
       
   920 // Lets set the service center number
       
   921 	iSmsHeader->SetServiceCenterAddressL(_L("+350508771010"));
       
   922 	iSmsTest(iSmsHeader->ServiceCenterAddress()==_L("+350508771010"));
       
   923 
       
   924 // Lets set one recipient for the message
       
   925 	CArrayPtrFlat<CSmsNumber>& recipients = iSmsHeader->Recipients();
       
   926 	CSmsNumber* number=CSmsNumber::NewL();
       
   927 	CleanupStack::PushL(number);
       
   928 	number->SetAddressL(_L("+358503367709"));
       
   929 	recipients.AppendL(number);
       
   930 	CleanupStack::Pop();
       
   931 
       
   932 // Setting settings of the message
       
   933 	CSmsSettings* smsset = CSmsSettings::NewL();
       
   934 	CleanupStack::PushL(smsset);
       
   935 	smsset->AddServiceCenterL(_L("Hippo"), _L("+358508771010"));
       
   936 	smsset->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet7Bit);
       
   937 	smsset->SetDelivery(ESmsDeliveryImmediately);
       
   938 	smsset->SetDeliveryReport(EFalse);
       
   939 	smsset->SetMessageConversion(ESmsConvPIDNone);
       
   940 	smsset->SetRejectDuplicate(ETrue);
       
   941 	smsset->SetReplyPath(EFalse);
       
   942 	smsset->SetValidityPeriod(ESmsVP24Hours);
       
   943 	smsset->SetValidityPeriodFormat(TSmsFirstOctet::ESmsVPFSemiOctet);
       
   944 // And copying them to the CSmsHeader
       
   945 	iSmsHeader->SetSmsSettingsL(*smsset);
       
   946 	CleanupStack::PopAndDestroy(smsset);
       
   947 
       
   948 	CSmsSettings* smsset2 = CSmsSettings::NewL();
       
   949 	CleanupStack::PushL(smsset2);
       
   950 // Lets get the same setting from the CSmsHeader
       
   951 	iSmsHeader->GetSmsSettingsL(*smsset2);
       
   952 // And compare that they are ok!
       
   953 	iSmsTest(smsset2->CharacterSet()==TSmsDataCodingScheme::ESmsAlphabet7Bit);
       
   954 	iSmsTest(!smsset2->DeliveryReport());
       
   955 	iSmsTest(smsset2->MessageConversion()==ESmsConvPIDNone);
       
   956 	iSmsTest(smsset2->RejectDuplicate());
       
   957 	iSmsTest(!smsset2->ReplyPath());
       
   958 	iSmsTest(smsset2->ValidityPeriod().Int()==ESmsVP24Hours);
       
   959 	iSmsTest(smsset2->ValidityPeriodFormat()==TSmsFirstOctet::ESmsVPFSemiOctet);
       
   960 	CleanupStack::PopAndDestroy(smsset2);
       
   961 
       
   962 //Test Set/FromAddress()
       
   963 	iSmsHeader->SetFromAddressL(_L("+358503367709"));
       
   964 	iSmsTest(iSmsHeader->FromAddress()==_L("+358503367709"));
       
   965 
       
   966 //Lets store and restore the CSmsHeader and test that the values are right
       
   967 	TMsvId id = iSmsTest.CreateDummyMessageToSendL();
       
   968 	Session().CleanupEntryPushL(id);
       
   969 	iSmsTest.SetEntryL(id);
       
   970 
       
   971 	StoreHeaderL(*iSmsHeader);
       
   972 
       
   973 	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsSubmit,*iRichText);
       
   974 	CleanupStack::PushL(header);
       
   975 
       
   976 	RestoreHeaderL(*header);
       
   977 
       
   978 //Values ok?
       
   979 	iSmsTest(iSmsHeader->Type()==header->Type());
       
   980 	iSmsTest(!header->ReplyPathProvided());
       
   981 	iSmsTest(header->ServiceCenterAddress()==_L("+350508771010"));
       
   982 	iSmsTest(iSmsHeader->Recipients().Count()==header->Recipients().Count());
       
   983 	iSmsTest(iSmsHeader->BioMsgIdType()==header->BioMsgIdType());
       
   984 	iSmsTest(iSmsHeader->FromAddress()==header->FromAddress());
       
   985 
       
   986 // Lets get the setting of the message
       
   987 	CSmsSettings* smsset3 = CSmsSettings::NewL();
       
   988 	CleanupStack::PushL(smsset3);
       
   989 	header->GetSmsSettingsL(*smsset3);
       
   990 
       
   991 // And compare that they are the original values
       
   992 	iSmsTest(smsset3->CharacterSet()==TSmsDataCodingScheme::ESmsAlphabet7Bit);
       
   993 	iSmsTest(!smsset3->DeliveryReport());
       
   994 	iSmsTest(smsset3->MessageConversion()==ESmsConvPIDNone);
       
   995 	iSmsTest(smsset3->RejectDuplicate());
       
   996 	iSmsTest(!smsset3->ReplyPath());
       
   997 	iSmsTest(smsset3->ValidityPeriod().Int()==ESmsVP24Hours);
       
   998 	iSmsTest(smsset3->ValidityPeriodFormat()==TSmsFirstOctet::ESmsVPFSemiOctet);
       
   999 
       
  1000 	CleanupStack::PopAndDestroy(); // smsset3
       
  1001 	CleanupStack::PopAndDestroy(); // header
       
  1002 	CleanupStack::PopAndDestroy(); // id
       
  1003 	}
       
  1004 
       
  1005 _LIT(KGetDescriptionTestMessage, "Finland to win the ice hockey world champs");
       
  1006 
       
  1007 void CSmutTest::TestSmsUtilitiesL()
       
  1008 	{
       
  1009 	iSmsTest.Test().Next(_L("Testing TSmsUtilities"));
       
  1010 
       
  1011 	iRichText->Reset();
       
  1012 	iRichText->InsertL(0, KGetDescriptionTestMessage);
       
  1013 	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsSubmit,*iRichText);
       
  1014 	CleanupStack::PushL(header);
       
  1015 
       
  1016 	TestSmsUtilities1L(*header);
       
  1017 	TestSmsUtilities2L(*header);
       
  1018 	TestSmsUtilities3L(*header);
       
  1019 
       
  1020 	CleanupStack::PopAndDestroy(); //header
       
  1021 	}
       
  1022 
       
  1023 void CSmutTest::TestSmsUtilities1L(CSmsHeader& aHeader)
       
  1024 	{
       
  1025 	iSmsTest.Printf(_L("Testing TSmsUtilities::GetDescription()"));
       
  1026 
       
  1027 //Test GetDescription()
       
  1028 
       
  1029 	TPtrC buf(KGetDescriptionTestMessage);
       
  1030 	TBuf<KSmsDescriptionLength> desc;
       
  1031 	TSmsUtilities::GetDescription(aHeader.Message(), desc);
       
  1032 	iSmsTest(desc.Length());
       
  1033 	iSmsTest(desc == buf.Left( Min(buf.Length(), desc.Length()) ) ); //this won't work if buf contains CEditableText::EParagraphDelimiter
       
  1034 
       
  1035 //Test Special Message Indication
       
  1036 
       
  1037 	CSmsPDU& pdu = aHeader.Message().SmsPDU();
       
  1038 	CSmsUserData& userData = pdu.UserData();
       
  1039 	TBuf8<2> msgInd;
       
  1040 	msgInd.Copy(_L("AA"));
       
  1041 
       
  1042 	iSmsTest.Printf(_L("\tAdding 1st information element (Fax) to UD\n"));
       
  1043 	msgInd[0] = TSmsUtilities::EFaxMessageWaiting;
       
  1044 	msgInd[1] = 0x00000001; //1 message
       
  1045 	userData.AddInformationElementL(CSmsInformationElement::ESmsIEISpecialSMSMessageIndication, msgInd);
       
  1046 	TSmsUtilities::GetDescription(aHeader.Message(), desc);
       
  1047 	iSmsTest.Printf(_L("\tGetDescription() returned: %S\n"), &desc);
       
  1048 	iSmsTest(desc.Length());
       
  1049 
       
  1050 	//Add another information element
       
  1051 	msgInd[0] = TSmsUtilities::EEmailMessageWaiting;
       
  1052 	msgInd[1] = 0x00000001; //1 message
       
  1053 
       
  1054 	iSmsTest.Printf(_L("\tAdding 2nd information element (Email) to UD\n"));
       
  1055 	userData.AddInformationElementL(CSmsInformationElement::ESmsIEISpecialSMSMessageIndication, msgInd);
       
  1056 	TSmsUtilities::GetDescription(aHeader.Message(), desc);
       
  1057 	iSmsTest.Printf(_L("\tGetDescription() returned: %S\n"), &desc);
       
  1058 	iSmsTest(desc.Length());
       
  1059 
       
  1060 	iSmsTest.Printf(_L("Passed\n"));
       
  1061 	}
       
  1062 
       
  1063 _LIT(KGetDetailsResult, "\t\tNum In: \"%S\" Name Out: \"%S\"\n");
       
  1064 
       
  1065 void CSmutTest::TestSmsUtilities2L(CSmsHeader& aHeader)
       
  1066 	{
       
  1067 //Test GetDetails
       
  1068 
       
  1069 	iSmsTest.Printf(_L("Test TSmsUtilities::GetDetails()\n"));
       
  1070 
       
  1071 	_LIT(KMikkoTel, "+358503367709");
       
  1072 	_LIT(KMikkoFirst, "Mikko");
       
  1073 	_LIT(KMikkoLast, "Rintala");
       
  1074 	_LIT(KMikkoEmail, "mikko@nokia.com");
       
  1075 
       
  1076 //	_LIT(KAnthonyTel, " + 4 "); //is valid
       
  1077 	_LIT(KAnthonyTel, "+ 7 "); //is valid
       
  1078 	_LIT(KAnthonyFirst, "Anthony");
       
  1079 	_LIT(KAnthonyLast, "Alexander");
       
  1080 	_LIT(KAnthonyEmail, "test@symbian.com");
       
  1081 
       
  1082 	_LIT(KHarriTel, "+8"); //is valid
       
  1083 	_LIT(KHarriFirst, "HarriHarriHarriHarriHarriHarriHarri");
       
  1084 	_LIT(KHarriLast, "RäisänenRäisänenRäisänenRäisänenRäisänen");
       
  1085 	_LIT(KHarriEmail, "harri@nokia.com");
       
  1086 
       
  1087 	_LIT(KDupTel, "+44207435676");
       
  1088 	_LIT(KDupFirst1, "Keval");
       
  1089 	_LIT(KDupLast1, "Pindoria");
       
  1090 	_LIT(KDupFirst2, "Jackie");
       
  1091 	_LIT(KDupLast2, "Chan");
       
  1092 	
       
  1093 	_LIT(KBadTel1, "This is a bad Telephone");
       
  1094 	_LIT(KBadTel2, " 5  ");
       
  1095 	_LIT(KBadTel3, "5+");
       
  1096 	_LIT(KBadTel4, "*5565434556");
       
  1097 
       
  1098 	_LIT(KBadFirst, "BadFirstName");
       
  1099 	_LIT(KBadLast, "BadLastName");
       
  1100 
       
  1101 	_LIT(KNoNameTel, "+449005434");
       
  1102 
       
  1103 	_LIT(KDummy, "+44444");
       
  1104 
       
  1105 	TRAPD(err, iSmsTest.DeleteContactsFileL());
       
  1106 	iSmsTest(err == KErrNotFound || err == KErrNone);
       
  1107 
       
  1108 	iSmsTest.Printf(_L("\tTesting without contacts\n"));
       
  1109 
       
  1110 	//Simple test
       
  1111 	TPtrC testTel(KMikkoTel);
       
  1112 	TBuf<KSmsDetailsLength> details;
       
  1113 
       
  1114 	aHeader.Message().SetToFromAddressL(testTel);
       
  1115 	TSmsUtilities::GetDetails(iSmsTest.FileSession(), aHeader.Message(), details);
       
  1116 	iSmsTest.Printf(KGetDetailsResult, &testTel, &details);
       
  1117 	iSmsTest(testTel.FindF(details) != KErrNotFound);
       
  1118 
       
  1119 	TestInvalidTelOrContact(testTel, details);
       
  1120 
       
  1121 	testTel.Set(KAnthonyTel);
       
  1122 	aHeader.Message().SetToFromAddressL(testTel);
       
  1123 	err = TSmsUtilities::GetDetails(iSmsTest.FileSession(), aHeader.Message(), details);
       
  1124 	iSmsTest.Printf(KGetDetailsResult, &testTel, &details);
       
  1125 	iSmsTest(testTel.FindF(details) != KErrNotFound);
       
  1126 	iSmsTest(err == KErrNone);
       
  1127 
       
  1128 	TestInvalidTelOrContact(testTel, details);
       
  1129 
       
  1130 	//Add contacts
       
  1131 
       
  1132 	iSmsTest.Printf(_L("\tAdding Contacts\n"));
       
  1133 
       
  1134 		//Adding good telephone numbers
       
  1135 
       
  1136 		TContactItemId contId = iSmsTest.CreateContactL(KAnthonyFirst, KAnthonyLast, KAnthonyTel, KAnthonyEmail);
       
  1137 		iSmsTest(contId != KNullContactId);
       
  1138 
       
  1139 		contId = iSmsTest.CreateContactL(KMikkoFirst, KMikkoLast, KMikkoTel, KMikkoEmail);
       
  1140 		iSmsTest(contId != KNullContactId);
       
  1141 
       
  1142 		contId = iSmsTest.CreateContactL(KHarriFirst, KHarriLast, KHarriTel, KHarriEmail);
       
  1143 		iSmsTest(contId != KNullContactId);
       
  1144 
       
  1145 		//Adding a duplicate telephone
       
  1146 
       
  1147 		contId = iSmsTest.CreateContactL(KDupFirst1, KDupLast1, KDupTel, KNullDesC);
       
  1148 		iSmsTest(contId != KNullContactId);
       
  1149 
       
  1150 		contId = iSmsTest.CreateContactL(KDupFirst2, KDupLast2, KDupTel, KNullDesC);
       
  1151 		iSmsTest(contId != KNullContactId);
       
  1152 
       
  1153 		//Adding bad telephone numbers
       
  1154 
       
  1155 		contId = iSmsTest.CreateContactL(KBadFirst, KBadLast, KBadTel1, KNullDesC);
       
  1156 		iSmsTest(contId != KNullContactId);
       
  1157 
       
  1158 		contId = iSmsTest.CreateContactL(KBadFirst, KBadLast, KBadTel2, KNullDesC);
       
  1159 		iSmsTest(contId != KNullContactId);
       
  1160 
       
  1161 		contId = iSmsTest.CreateContactL(KBadFirst, KBadLast, KBadTel3, KNullDesC);
       
  1162 		iSmsTest(contId != KNullContactId);
       
  1163 
       
  1164 		contId = iSmsTest.CreateContactL(KBadFirst, KBadLast, KBadTel4, KNullDesC);
       
  1165 		iSmsTest(contId != KNullContactId);
       
  1166 
       
  1167 		//Adding no name contact
       
  1168 
       
  1169 		contId = iSmsTest.CreateContactL(KNullDesC, KNullDesC, KNoNameTel, KNullDesC);
       
  1170 		iSmsTest(contId != KNullContactId);
       
  1171 
       
  1172 	iSmsTest.Printf(_L("\tTesting with valid telephone numbers\n"));
       
  1173 
       
  1174 		TestValidTel(KAnthonyTel, KAnthonyFirst, KAnthonyLast, KNullDesC, details);
       
  1175 		TestValidTel(KMikkoTel, KMikkoFirst, KMikkoLast, KNullDesC, details);
       
  1176 		TestValidTel(KHarriTel, _L("Räisänen"), KNullDesC, _L("Harri"), details);
       
  1177 
       
  1178 	iSmsTest.Printf(_L("\tTesting with invalid telephone numbers\n"));
       
  1179 
       
  1180 		TestInvalidTelOrContact(KBadTel1, details);
       
  1181 		TestInvalidTelOrContact(KBadTel2, details);
       
  1182 		TestInvalidTelOrContact(KBadTel3, details);
       
  1183 		TestInvalidTelOrContact(KBadTel4, details);
       
  1184 
       
  1185 	iSmsTest.Printf(_L("\tTesting with duplicate telephone numbers\n"));
       
  1186 
       
  1187 //		TestInvalidTelOrContact(KDupTel, details); //Fails because of CntModel defect EDNAALR-4Q2L4D
       
  1188 
       
  1189 	iSmsTest.Printf(_L("\tTesting No Names telephone number\n"));
       
  1190 
       
  1191 		TestInvalidTelOrContact(KNoNameTel, details);
       
  1192 		TestInvalidTelOrContact(KDummy, details);
       
  1193 
       
  1194 	iSmsTest.Printf(_L("Passed\n"));
       
  1195 	}
       
  1196 
       
  1197 void CSmutTest::TestValidTel(const TDesC& aTel, const TDesC& aExpect1, const TDesC& aExpect2, const TDesC& aNotExpect, TDes& rDetails)
       
  1198 	{
       
  1199 	TInt err = TSmsUtilities::GetDetails(iSmsTest.FileSession(), aTel, rDetails);
       
  1200 	iSmsTest.Printf(KGetDetailsResult, &aTel, &rDetails);
       
  1201 
       
  1202 	if (aExpect1.Length())
       
  1203 		iSmsTest(rDetails.FindF(aExpect1) != KErrNotFound);
       
  1204 
       
  1205 	if (aExpect2.Length())
       
  1206 		iSmsTest(rDetails.FindF(aExpect2) != KErrNotFound);
       
  1207 
       
  1208 	if (aNotExpect.Length())
       
  1209 		iSmsTest(rDetails.FindF(aNotExpect) == KErrNotFound);
       
  1210 
       
  1211 	iSmsTest(err == KErrNone);
       
  1212 	}
       
  1213 
       
  1214 void CSmutTest::TestInvalidTelOrContact(const TDesC& aTel, TDes& rDetails)
       
  1215 	{
       
  1216 	TInt err = TSmsUtilities::GetDetails(iSmsTest.FileSession(), aTel, rDetails);
       
  1217 	iSmsTest.Printf(KGetDetailsResult, &aTel, &rDetails);
       
  1218 	iSmsTest(aTel.FindF(rDetails) != KErrNotFound);
       
  1219 	iSmsTest(err == KErrNone);
       
  1220 	}
       
  1221 
       
  1222 void CSmutTest::TestSmsUtilities3L(CSmsHeader& aHeader)
       
  1223 	{
       
  1224 	iSmsTest.Printf(_L("Test TSmsUtilities::ServiceIdL()\n"));
       
  1225 
       
  1226 	TMsvId id2 = KMsvNullIndexEntryId;
       
  1227 // First tested function is ServiceIdL()
       
  1228 	TSmsUtilities::ServiceIdL(*iSmsTest.iMsvEntry, id2);
       
  1229 	iSmsTest(id2 == iSmsTest.iSmsServiceId);
       
  1230 	iSmsTest.Printf(_L("\tPassed\n"));
       
  1231 
       
  1232 	iSmsTest.Printf(_L("Test TSmsUtilities::PopulateMsgEntry()\n"));
       
  1233 	TMsvEntry entry;
       
  1234 	TSmsUtilities::PopulateMsgEntry(entry,aHeader.Message(), iSmsTest.iSmsServiceId);
       
  1235 //To Do: More tests
       
  1236 	iSmsTest.Printf(_L("\tPassed\n"));
       
  1237 	}