messagingappbase/smsmtm/clientmtm/test/src/smcmstepforwardemail.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @SYMTestCaseID MSG-SMSCLIENTMTM-0243-9
       
    18  @SYMTestType UT
       
    19  @SYMTestPriority High
       
    20  @SYMPREQ 234, other
       
    21  @SYMTestCaseDesc Creates an Email over SMS with locale UTC offset 0, sets UTC offset to -8, forward the Email over SMS
       
    22  @SYMTestActions  Checks the timestamps of original and forwarded Email over SMS. (also check original test actions of T_SMCM1)
       
    23  @SYMTestExpectedResults The timestamp of the original Email over SMS should be smaller than the timestamp of the forwarded Email over SMS.
       
    24 */
       
    25 
       
    26 #include "smcmstepforwardemail.h"
       
    27 
       
    28 #include <csmsemailfields.h>
       
    29 #include <smuthdr.h> 
       
    30 
       
    31 CSMCMStepForwardEmail::CSMCMStepForwardEmail( )
       
    32 	{
       
    33 	SetTestStepName( KSMCMStepForwardEmail );
       
    34 	}
       
    35 	
       
    36 CSMCMStepForwardEmail::~CSMCMStepForwardEmail( )
       
    37 	{
       
    38 	
       
    39 	}
       
    40 	
       
    41 TVerdict CSMCMStepForwardEmail::doTestStepL( )
       
    42 	{
       
    43 	INFO_PRINTF1( _L( "CSMCMStepReplyEmail::doTestStepL( )" ) );
       
    44 	
       
    45 	ChangeLocale( KUTC0 );
       
    46 	
       
    47 	SetSettingsL( );
       
    48 	
       
    49 	// Easier to have default EPass. Otherwise a passing test may overwrite the
       
    50 	// result of earlier failed tests (unless we use an extra boolean which is set
       
    51 	// to false if a test fails )
       
    52 	TVerdict result = EPass;
       
    53 	SetTestStepResult( result );
       
    54 	 
       
    55  	_LIT( KTestEmailSubject1,	"Fw: a subject" );
       
    56  	_LIT( KTestEmailBody1,		"some body text" );
       
    57  	_LIT( KTestEmailMessage1,	"user@domain1.domain2##a subject#some body text" );
       
    58  	result = DoTestForwardEmailL( KTestEmailMessage1, KTestEmailSubject1, KTestEmailBody1 );
       
    59  	if ( result == EFail )
       
    60  		{
       
    61  		SetTestStepResult( EFail );
       
    62  		}
       
    63  	
       
    64  	// Reset Time to UTC0 for Next Test	
       
    65  	ChangeLocale( KUTC0 );
       
    66  
       
    67  	_LIT( KTestEmailSubject2,	"" );
       
    68  	_LIT( KTestEmailBody2,		"some body text" );
       
    69  	_LIT( KTestEmailMessage2,	"user@domain1.domain2 some body text" );
       
    70  	result = DoTestForwardEmailL( KTestEmailMessage2, KTestEmailSubject2, KTestEmailBody2 );
       
    71  	if ( result == EFail )
       
    72  		{
       
    73  		SetTestStepResult( EFail );
       
    74  		}
       
    75  	
       
    76  	// if locale isn't changed the log file timestamps will be out of order 
       
    77 	// as they are in local time	
       
    78  	ChangeLocale( KUTC0 );
       
    79 
       
    80 	return TestStepResult( );
       
    81 	
       
    82 	}
       
    83 	
       
    84 TVerdict CSMCMStepForwardEmail::DoTestForwardEmailL( const TDesC& aEmailMessageData, 
       
    85 								  					 const TDesC& aSubject, 
       
    86 								  					 const TDesC& aBody )
       
    87 	{
       
    88 	TVerdict result = EPass;
       
    89 	
       
    90 	// Create an email message and then a forward message to it.
       
    91  	TMsvId entryId = CreateEmailSmsMessageL( aEmailMessageData );
       
    92  	iSmsTestUtils->SetEntryL( entryId );
       
    93  	iSmsClientMtm->SwitchCurrentEntryL( entryId ); 
       
    94  	iSmsClientMtm->LoadMessageL( );
       
    95  	// store the original entry (to compare UTC)
       
    96    	TMsvEntry originalEntry = iSmsClientMtm->Entry( ).Entry( );
       
    97 
       
    98 	ChangeLocale ( KUTCMin8 );
       
    99  
       
   100  	TMsvPartList part = 0;
       
   101  	CMsvOperationWait* wait = CMsvOperationWait::NewLC( );
       
   102  	CMsvOperation* op = iSmsClientMtm->ForwardL( KMsvDraftEntryId, part, wait->iStatus );
       
   103  	CleanupStack::PushL( op );
       
   104  	wait->Start( );
       
   105  	CActiveScheduler::Start( );
       
   106  
       
   107  	TPckgBuf< TMsvId > pkg;
       
   108  	pkg.Copy( op->ProgressL( ) );
       
   109  	TMsvId forward = pkg( );
       
   110  
       
   111  	CleanupStack::PopAndDestroy( 2, wait ); // op, wait
       
   112 
       
   113  	
       
   114  	// Switch and load the forward message
       
   115  	iSmsClientMtm->SwitchCurrentEntryL(forward);
       
   116  	iSmsClientMtm->LoadMessageL();
       
   117  	
       
   118  	// Check the forward message...
       
   119  	const CSmsHeader& forwardHeader = iSmsClientMtm->SmsHeader();
       
   120  	
       
   121  	// 1. Email fields...(address should be empty)
       
   122  	const CSmsEmailFields& fields = forwardHeader.EmailFields();
       
   123  	if( fields.HasAddress( ) )
       
   124  		{
       
   125  		result = EFail;
       
   126  		ERR_PRINTF1( _L("CSmsEmailFields Address is not empty" ) );
       
   127  		}
       
   128  	if ( fields.Addresses( ).MdcaCount( ) !=0 )
       
   129  		{
       
   130  		result = EFail;
       
   131  		ERR_PRINTF1( _L("CSmsEmailFields Address is not empty" ) );
       
   132  		}
       
   133  	if ( fields.Subject( ).Compare( aSubject ) != 0 )
       
   134  		{
       
   135  		result = EFail;
       
   136  		ERR_PRINTF1( _L("CSmsEmailFields Subject is not the expected one" ) );
       
   137  		}
       
   138  	
       
   139  	// 2. PID...
       
   140  	CSmsSettings* smsset = CSmsSettings::NewL( );
       
   141  	CleanupStack::PushL( smsset );
       
   142  	forwardHeader.GetSmsSettingsL( *smsset );
       
   143  	if ( smsset->MessageConversion( ) != ESmsConvMail )
       
   144  		{
       
   145  		result = EFail;
       
   146  		ERR_PRINTF1( _L("Message Conversion is not ESmsConvMail" ) );
       
   147  		}
       
   148  	CleanupStack::PopAndDestroy( smsset );
       
   149  	
       
   150  	// 3. Email <-> SMS gateway (ie the recipient)
       
   151  	const CArrayPtrFlat< CSmsNumber >& rcpts = forwardHeader.Recipients( );
       
   152  	if ( rcpts.Count( ) != 1 )
       
   153  		{
       
   154  		result = EFail;
       
   155  		ERR_PRINTF1( _L("SMS Gateway count is wrong" ) );
       
   156  		}
       
   157  	const CSmsNumber& rcpt = *rcpts.At( 0 );
       
   158  	if ( rcpt.Address( ).Compare( KScriptItemRecipientsDef ) != 0 )
       
   159  		{
       
   160  		result = EFail;
       
   161  		ERR_PRINTF1( _L("SMS Gateway address is wrong" ) );
       
   162  		}
       
   163  
       
   164  	// 4. Description - should be the same as the subject or body text.
       
   165  	TMsvEntry forwardEntry = iSmsClientMtm->Entry( ).Entry( );
       
   166  	TInt maxDesLength = iSmsClientMtm->ServiceSettings( ).DescriptionLength( );
       
   167  	if( fields.Subject( ).Length( ) )
       
   168  		{
       
   169  		// Description should be same as subject.
       
   170  		if ( forwardEntry.iDescription.Compare( fields.Subject( ).Left( maxDesLength ) ) != 0)
       
   171  			{
       
   172  			result = EFail;
       
   173  			ERR_PRINTF1( _L("Description does not match subject" ) );
       
   174  			}
       
   175  		}
       
   176  	else
       
   177  		{
       
   178  		// Description should be the same as the body text.
       
   179  		HBufC* body = HBufC::NewLC( iSmsClientMtm->Body( ).DocumentLength( ) );
       
   180  		TPtr bodyPtr( body->Des( ) );
       
   181  		iSmsClientMtm->Body( ).Extract( bodyPtr );
       
   182  
       
   183  		if ( forwardEntry.iDescription.Compare( bodyPtr.Left( maxDesLength ) ) != 0 )
       
   184  			{
       
   185  			result = EFail;
       
   186  			ERR_PRINTF1( _L("Description does not match body text" ) );
       
   187  			}
       
   188  		CleanupStack::PopAndDestroy( body );
       
   189  		}
       
   190  	
       
   191  	// 5. Details - should be the same as the address (ie empty).
       
   192  	if( forwardEntry.iDetails.Compare( KNullDesC( ) ) != 0 )
       
   193  		{
       
   194  		result = EFail;
       
   195  		ERR_PRINTF1( _L("Details do not match address" ) );
       
   196  		}
       
   197 	
       
   198  	// 6. Body data.
       
   199  	if ( !TestForwardBodyL( iSmsClientMtm->Body( ), aBody) )
       
   200 		{
       
   201 		result = EFail;
       
   202 		ERR_PRINTF1( _L("Body does not" ) );
       
   203 		}
       
   204 	
       
   205 	// 7. UTC - UTC time of the original entry should be smaller than forward entry UTC time
       
   206  	if ( originalEntry.iDate >= forwardEntry.iDate )
       
   207 		{
       
   208 		result = EFail;
       
   209 		ERR_PRINTF1( _L("UTC time is wrong" ) );
       
   210 		}
       
   211 	
       
   212 	return result;
       
   213 	}
       
   214 	
       
   215 TBool CSMCMStepForwardEmail::TestForwardBodyL( const CRichText& aBody, const TDesC& aExpected ) const
       
   216 	{
       
   217 	HBufC* body = HBufC::NewLC( aBody.DocumentLength( ) );
       
   218 	TPtr bodyPtr( body->Des( ) );
       
   219 
       
   220 	aBody.Extract( bodyPtr );
       
   221 
       
   222 	const TBool check = ( *body == aExpected );
       
   223 
       
   224 	CleanupStack::PopAndDestroy( body );
       
   225 
       
   226 	return check;
       
   227 	}