messagingfw/msgtestfw/TestActions/SendAs/src/CMtfTestActionSendAsSetBodyText.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2004-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 // __ACTION_INFO_BEGIN__ 
       
    15 // [Action Name]
       
    16 // SendAsSetBodyText
       
    17 // [Action Parameters]
       
    18 // RSendAsMessage			sendAsMessage		<input>	: RSendAsMssage object
       
    19 // TInt						bufferType			<input> : Type of the buffer storing body text contents 
       
    20 // TInt 					index				<input>	: Value of Index
       
    21 // [Action Description]
       
    22 // SendAsSetBodyText Test Action is intended to set the body text 
       
    23 // contents for a message that was created using Send-As API.  
       
    24 // The body text content is read from a file and then stored in a 
       
    25 // CRichText object. The 
       
    26 // The buffer type is taken as the input parameter to the test action 
       
    27 // Buffer type 0 => Set body text using Descriptor
       
    28 // Buffer type 1 => Set body text using CRichText object
       
    29 // [APIs Used]
       
    30 // RSendAsMessage::SetBodyTextL(const TDesC)	
       
    31 // RSendAsMessage::SetBodyTextL(const TDesC)
       
    32 // __ACTION_INFO_END__
       
    33 // 
       
    34 //
       
    35 
       
    36 /**
       
    37  @file 
       
    38  @internalTechnology 
       
    39 */
       
    40 
       
    41 //system include
       
    42 #include <msvapi.h>
       
    43 #include <txtrich.h>
       
    44 
       
    45 // User include
       
    46 #include "CMtfTestActionSendAsSetBodyText.h"
       
    47 #include "CMtfTestCase.h"
       
    48 #include "CMtfTestActionParameters.h"
       
    49 #include "sendas2.h"
       
    50 
       
    51 
       
    52 /**
       
    53   NewL()
       
    54   Constructs a CMtfTestActionSendAsSetBodyText object.
       
    55   Uses two phase construction and leaves nothing on the CleanupStack.   
       
    56   @internalTechnology
       
    57   @param  aTestCase         Test Case to which this Test Action belongs
       
    58   @param  aActionParameters Action parameters, must not be NULL
       
    59   @return Created object of type CMtfTestActionSendAsSetBodyText
       
    60   @pre    None
       
    61   @post   CMtfTestActionSendAsSetBodyText object is created
       
    62 */
       
    63 CMtfTestAction* CMtfTestActionSendAsSetBodyText::
       
    64 		NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    65 	{
       
    66 	CMtfTestActionSendAsSetBodyText* self = 
       
    67 							new (ELeave) CMtfTestActionSendAsSetBodyText(aTestCase);
       
    68 
       
    69 	CleanupStack::PushL(self);
       
    70 	self->ConstructL(aActionParameters);
       
    71 	CleanupStack::Pop(self);
       
    72 	return self;
       
    73 	}
       
    74 	
       
    75 
       
    76 /**
       
    77   CMtfTestActionSendAsSetBodyText constructor
       
    78   Calls the base class' constructor
       
    79   @internalTechnology  
       
    80   @param  aTestCase  Test Case to which this Test Action belongs
       
    81   @pre    None
       
    82   @post   None
       
    83 */ 
       
    84 CMtfTestActionSendAsSetBodyText::CMtfTestActionSendAsSetBodyText(CMtfTestCase& aTestCase)
       
    85 	: CMtfSynchronousTestAction(aTestCase)
       
    86 	{
       
    87 	}
       
    88 
       
    89 /**
       
    90   Function : ~CMtfTestActionSendAsSetBodyText
       
    91   Description : Destructor
       
    92   @internalTechnology
       
    93   @param :
       
    94   @return : 
       
    95   @pre 
       
    96   @post 
       
    97 */
       
    98 CMtfTestActionSendAsSetBodyText::~CMtfTestActionSendAsSetBodyText()
       
    99 	{
       
   100 	}
       
   101 
       
   102 /**
       
   103   ExecuteActionL
       
   104   Obtains the parameters for the test action. Get the Message Id at given index. The Message 
       
   105   Id is stored as output parameters of this Test Action
       
   106   @internalTechnology 
       
   107   @pre    None
       
   108   @post   None
       
   109   @leave  System wide errors
       
   110 */
       
   111 void CMtfTestActionSendAsSetBodyText::ExecuteActionL()
       
   112 	{
       
   113 	if((TestCase().TestStepResult()) == EPass)
       
   114 		{
       
   115 		TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSendAsSetBodyText);
       
   116 	
       
   117 		// Get test action input parameters
       
   118 		RSendAsMessage sendAsMessage = ObtainValueParameterL<RSendAsMessage>(TestCase(),
       
   119 														ActionParameters().Parameter(0));
       
   120 		
       
   121 		// Buffer type to be used for adding the body text 
       
   122 		// 0 => Set body text using Descriptor 
       
   123 		// 1 => Set body text using CRichText object (Default)	
       
   124 		TInt bufferType = ObtainValueParameterL<TInt>(TestCase(),
       
   125 														ActionParameters().Parameter(1),1);
       
   126 	
       
   127 		TInt index = ObtainValueParameterL<TInt>(TestCase(),
       
   128 														ActionParameters().Parameter(2));
       
   129 	
       
   130 		// Get the body text configuration file name												
       
   131 		TPtrC fileName = TestCase().GetConfigurationFileL(CMtfConfigurationType::EMtfDataFile,index);
       
   132 
       
   133 		// Create a Rich text object to store the Body text contents
       
   134 		CPlainText::TTextOrganisation ttOrg = {CPlainText::EOrganiseByLine};
       
   135 
       
   136 		CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
       
   137 		CleanupStack::PushL(paraFormatLayer);
       
   138 		CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
       
   139 		CleanupStack::PushL(charFormatLayer);
       
   140 		CRichText* bodyCRichText = CRichText::NewL(paraFormatLayer, charFormatLayer);
       
   141 		CleanupStack::PushL(bodyCRichText);
       
   142 
       
   143 		HBufC* bodyTextFileName = fileName.Alloc();
       
   144 		CleanupStack::PushL(bodyTextFileName);
       
   145 
       
   146 		// Read the body text contents into the Rich text object
       
   147 		bodyCRichText->ImportTextFileL(0, bodyTextFileName->Des(), ttOrg);	
       
   148 	
       
   149 		TInt err = KErrNone;
       
   150 		// Set body text using descriptor
       
   151 		if( bufferType  == 0 )
       
   152 			{
       
   153 			// Create a heap buffer and copy the file contents
       
   154 			TInt len1 = bodyCRichText->DocumentLength();
       
   155 			HBufC* buf1 = HBufC::NewL(len1);
       
   156 			CleanupStack::PushL(buf1);
       
   157 			
       
   158 			TPtr fileContents = buf1->Des();
       
   159 			bodyCRichText->Extract(fileContents,0,(len1));
       
   160 			
       
   161 			// Set the body text to the message
       
   162 			TRAP(err, sendAsMessage.SetBodyTextL(fileContents));
       
   163 			
       
   164 			if(err == KErrNone)
       
   165 				{
       
   166 				TestCase().INFO_PRINTF1(_L("SetBodyTextL using Descriptor was successful"));
       
   167 				}
       
   168 			else
       
   169 				{
       
   170 				TestCase().ERR_PRINTF2(_L("SetBodyTextL using Descriptor failed with error: %d"), err);
       
   171 				TestCase().SetTestStepResult(EFail);
       
   172 				}
       
   173 				
       
   174 			// destroy the temporary storage of the text
       
   175 			CleanupStack::PopAndDestroy(buf1);
       
   176 			}
       
   177 		else if (bufferType  == 1)
       
   178 			{
       
   179 			// Set body text using CRichText
       
   180 			TRAP(err, sendAsMessage.SetBodyTextL(*bodyCRichText));
       
   181 			
       
   182 			if(err == KErrNone)
       
   183 				{
       
   184 				TestCase().INFO_PRINTF1(_L("SetBodyTextL using Rich Text was successful"));
       
   185 				}
       
   186 			else
       
   187 				{
       
   188 				TestCase().ERR_PRINTF2(_L("SetBodyTextL using Rich Text failed with error: %d"), err);
       
   189 				TestCase().SetTestStepResult(EFail);
       
   190 				}
       
   191 			}
       
   192 	 	else
       
   193 			{
       
   194 			err = KErrArgument;
       
   195 			TestCase().ERR_PRINTF2(_L("Incorrent input parameter: Buffer type value should be either 0 or 1. The value provided is  %d"),bufferType );
       
   196 			TestCase().SetTestStepResult(EFail);
       
   197 			}
       
   198 		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(3));
       
   199 			
       
   200 		CleanupStack::PopAndDestroy(4);	//bodyTextFileName, bodyCRichText, charFormatLayer, paraFormatLayer
       
   201 		TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendAsSetBodyText);
       
   202 		}
       
   203 	TestCase().ActionCompletedL(*this);
       
   204 	}
       
   205