buildverification/smoketest/messaging/Src/TestMessEditEntryUtil.cpp
branchRCL_3
changeset 20 493058e57c8c
parent 0 9736f095102e
equal deleted inserted replaced
19:4ca382093dae 20:493058e57c8c
       
     1 // Copyright (c) 2003-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 // This contains CTestMessEditEntryUtil. A utility to edit an entry
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 #include "TestMessEditEntryUtil.h"
       
    20 
       
    21 // EPOC includes
       
    22 
       
    23 #include <smut.h>
       
    24 #include <miutmsg.h>
       
    25 #include <mtclreg.h>
       
    26 
       
    27 /**
       
    28  * @name Constant Literals used.
       
    29  */
       
    30 /*@{*/
       
    31 _LIT(KToRecipients,			"toRecipients");
       
    32 _LIT(KTo,					"to%d");
       
    33 _LIT(KDef,					"default");
       
    34 _LIT(KDefTo,				"emailto");
       
    35 
       
    36 // Literal constants used
       
    37 _LIT(KCharacterSetType,		"characterSetType");
       
    38 _LIT(KPtEditBody,			"EditBody");
       
    39 _LIT(KPtEditRecipients,		"EditRecipients");
       
    40 _LIT(KPtRecipient,			"recipient%d");
       
    41 /*@}*/
       
    42 
       
    43 CTestMessEditEntryUtil::CTestMessEditEntryUtil(CTestMessBase& aTestStep, TBool aSimChecked, TBool aSimInDatabase, RMobilePhone::TMobileAddress aSimPhoneNumber)
       
    44 :	CTestMessStoreProcessUtil(aTestStep, EFalse)
       
    45 ,	iSimChecked(aSimChecked)
       
    46 ,	iSimInDatabase(aSimInDatabase)
       
    47 ,	iSimPhoneNumber(aSimPhoneNumber)
       
    48 	{
       
    49 	}
       
    50 
       
    51 /**
       
    52  * Edits the ImHeaders of the Entry
       
    53  * @param  CImHeader& aHeader - Im Header to edit
       
    54  * @return None
       
    55  * @panic None
       
    56  * @leave KErrNoMemory
       
    57  *  
       
    58 */
       
    59 void CTestMessEditEntryUtil::ProcessImHeaderL(CImHeader& aHeader)
       
    60 	{
       
    61 	// Edit the CImHeader information
       
    62 	TInt	recipients;
       
    63 	if ( !iTestStep.GetIntFromConfig(iTestStep.ConfigSection(), KToRecipients, recipients) )
       
    64 		{
       
    65 		recipients=0;
       
    66 		}
       
    67 
       
    68 	for ( TInt recipient=1; recipient<=recipients; recipient++)
       
    69 		{
       
    70 		TBuf<KMaxTestExecuteCommandLength>	tempStore;
       
    71 		tempStore.Format(KTo(), recipient);
       
    72 
       
    73 		TPtrC	to;
       
    74 		TInt	returnValue=iTestStep.GetStringFromConfig(iTestStep.ConfigSection(), tempStore, to);
       
    75 		if ( !returnValue )
       
    76 			{
       
    77 			returnValue=iTestStep.GetStringFromConfig(KDef, KDefTo, to);
       
    78 			}
       
    79 		if ( !returnValue )
       
    80 			{
       
    81 			iTestStep.ERR_PRINTF1(_L("No To"));
       
    82 			iTestStep.SetTestStepResult(EFail);
       
    83 			}
       
    84 		else
       
    85 			{
       
    86 			iTestStep.INFO_PRINTF2(_L("To = %S"), &to);
       
    87 			aHeader.ToRecipients().AppendL(to);
       
    88 			}
       
    89 		}
       
    90 	}
       
    91 
       
    92 /**
       
    93  * Edits the ImMimeHeaders of the message entry
       
    94  * @param  CImMimeHeader& aHeader - Mime Header to edit
       
    95  * @return None
       
    96  * @panic None
       
    97  * @leave KErrNoMemory
       
    98  *  
       
    99 */
       
   100 void CTestMessEditEntryUtil::ProcessImMimeHeaderL(CImMimeHeader& aHeader)
       
   101 	{
       
   102 	// Update the character set info
       
   103 	TPtrC	charSetType;
       
   104 	if ( iTestStep.GetStringFromConfig(iTestStep.ConfigSection(), KCharacterSetType, charSetType) )
       
   105 		{
       
   106 		TUint	charSetVal;
       
   107 		if ( ValidCharacterSetInfo(charSetType, charSetVal) )
       
   108 			{
       
   109 			aHeader.SetMimeCharset(charSetVal);
       
   110 			}
       
   111 		}
       
   112 	}
       
   113 
       
   114 /**
       
   115  * Edits the ImIAPPreferences of the entry
       
   116  * @param  CImIAPPreferences& aPreferences - IAP Preferences to edit
       
   117  * @return None
       
   118  * @panic None
       
   119  * @leave KErrNoMemory
       
   120  *  
       
   121 */
       
   122 void CTestMessEditEntryUtil::ProcessInternetAccessPreferencesL(CImIAPPreferences& /*aPreferences*/)
       
   123 	{
       
   124 	}
       
   125 
       
   126 /**
       
   127  Edits the CSmsHeader of the entry
       
   128  @param  CSmsHeader& aHeader - Sms Header to edit
       
   129  @return None
       
   130  @panic None
       
   131  @leave KErrNoMemory
       
   132 */
       
   133 void CTestMessEditEntryUtil::ProcessSmsHeaderStreamL(CSmsHeader& aSmsHeader)
       
   134 	{
       
   135 	// Get the number of recipients 
       
   136 	TInt	recipients = 0;
       
   137 	if ( !iTestStep.GetIntFromConfig(iTestStep.ConfigSection(), KPtEditRecipients, recipients) )
       
   138 		{
       
   139 		recipients=0;
       
   140 		iTestStep.INFO_PRINTF1(_L("No Recipients edited/added"));
       
   141 		}
       
   142 	iTestStep.INFO_PRINTF2(_L("The number of recipients : %d"), recipients);
       
   143 
       
   144 	if ( !iSimChecked )
       
   145 		{
       
   146 		//IMK iSimInDatabase=(iTestStep.GetPhoneSmsNumberL(iSimPhoneNumber)==KErrNone);
       
   147 		iSimInDatabase=0;
       
   148 		}
       
   149 	TPtrC	to(iSimPhoneNumber.iTelNumber);
       
   150 	TInt	returnValue=ETrue;
       
   151 	for ( TInt recipient=0; (recipient<recipients) && (iTestStep.TestStepResult()==EPass); )
       
   152 		{
       
   153 		++recipient;
       
   154 		if ( iSimInDatabase )
       
   155 			{
       
   156 			returnValue=ETrue;
       
   157 			}
       
   158 		else
       
   159 			{
       
   160 			TBuf<KMaxTestExecuteCommandLength>	tempStore;
       
   161 			tempStore.Format(KPtRecipient(), recipient);
       
   162 
       
   163 			//Get the recipient address
       
   164 			returnValue=iTestStep.GetStringFromConfig(iTestStep.ConfigSection(), tempStore, to);
       
   165 			if ( !returnValue )
       
   166 				{
       
   167 				returnValue=iTestStep.GetStringFromConfig(KDef, KDefTo, to);
       
   168 				}
       
   169 			}
       
   170 		if ( !returnValue )
       
   171 			{
       
   172 			iTestStep.ERR_PRINTF1(_L("Recipient number is not Provided"));
       
   173 			iTestStep.SetTestStepResult(EFail);
       
   174 			}
       
   175 		else
       
   176 			{
       
   177 			//Append the recipient address in recipient list
       
   178 			CSmsNumber*	smsNumber = CSmsNumber::NewL();
       
   179 			CleanupStack::PushL(smsNumber);
       
   180 			iTestStep.INFO_PRINTF2(_L("To = %S"), &to);
       
   181 			smsNumber->SetAddressL(to);
       
   182 			aSmsHeader.Recipients().AppendL(smsNumber);
       
   183 			//No need to destory CSmsNumber. CSmsHeader destroys it
       
   184 			CleanupStack::Pop(smsNumber);
       
   185 			}
       
   186 		}
       
   187 	}
       
   188 
       
   189 
       
   190 /**
       
   191  Edits the CRichText of the entry
       
   192  @param  CRichText& aBodyText - Text to edit
       
   193  @return None
       
   194  @panic None
       
   195  @leave KErrNoMemory
       
   196 */
       
   197 void CTestMessEditEntryUtil::ProcessRichTextBodyL(CRichText& aBodyText)
       
   198 	{
       
   199 	TPtrC	ptrBody;
       
   200 	//Get the body text file
       
   201 	TBool	returnValue=iTestStep.GetStringFromConfig(iTestStep.ConfigSection(), KPtEditBody, ptrBody);
       
   202 	if ( !returnValue )
       
   203 		{
       
   204 		iTestStep.INFO_PRINTF1(_L("Body is not edited"));
       
   205 		}
       
   206 	else
       
   207 		{
       
   208 		iTestStep.INFO_PRINTF2(_L("Body = %S"), &ptrBody);
       
   209 
       
   210 		// open the file
       
   211 		RFs rfs;
       
   212 		rfs.Connect();
       
   213 		RFile	file;
       
   214 
       
   215 		//Append the body text of the entry
       
   216 		TInt anError = file.Open(rfs, ptrBody, EFileShareAny);
       
   217 		if(anError == KErrNone)
       
   218 			{
       
   219 			TBool		reading=ETrue;
       
   220 			TInt		pos = aBodyText.LdDocumentLength();
       
   221 			TBuf8<1>	charIn;
       
   222 			while (reading)
       
   223 				{
       
   224 				file.Read(charIn, 1);
       
   225 				if(charIn.Length())
       
   226 					switch ( charIn[0] )
       
   227 						{
       
   228 					case '\r':
       
   229 						aBodyText.InsertL(pos++, CEditableText::ELineBreak);
       
   230 					case '\n':
       
   231 						break;
       
   232 					default:
       
   233 						aBodyText.InsertL(pos++, TChar(charIn[0]));
       
   234 						}
       
   235 				else
       
   236 					{
       
   237 					reading = FALSE;	// stop at the end of the file
       
   238 					}
       
   239 				}
       
   240 			file.Close();
       
   241 			rfs.Close();
       
   242 			}
       
   243 		else
       
   244 			{
       
   245 			iTestStep.ERR_PRINTF2(_L("Cannot open file = %S"), &ptrBody);
       
   246 			iTestStep.SetTestStepResult(EFail);
       
   247 			}
       
   248 		}	
       
   249 	}