messagingfw/msgtestfw/TestActionUtils/src/CMtfTestActionUtilsMessage.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18 */
       
    19 
       
    20 #include "MtfTestActionUtilsUser.h"
       
    21 #include "CMtfTestActionUtilsMessage.h"
       
    22 #include "TestFrameworkActionsUtils.h"
       
    23 
       
    24 
       
    25 #include "txtfmlyr.h"
       
    26 #include "txtrich.h"
       
    27 #include "smuthdr.h" 
       
    28 #include "miuthdr.h"
       
    29 #include "miutmsg.h"
       
    30 
       
    31 #include<btmsgtypeuid.h>
       
    32 #include<irmsgtypeuid.h>
       
    33 
       
    34 #include "obexheader.h"
       
    35 
       
    36 #include<btheader.h>
       
    37 #include<irheader.h>
       
    38 
       
    39 
       
    40 /*
       
    41  Compare the Body text contents of the message with the file contents
       
    42 */
       
    43 TInt CMtfTestActionUtilsMessage::VerifyBodyTextContentsL(CMsvEntry& aEntry, HBufC* aFileName )
       
    44 	{
       
    45 	TInt returnValue = KErrNone;
       
    46 	
       
    47 	// Create a Rich Text object
       
    48 	CPlainText::TTextOrganisation ttOrg = {CPlainText::EOrganiseByLine};
       
    49 
       
    50 	CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
       
    51 	CleanupStack::PushL(paraFormatLayer);
       
    52 	CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
       
    53 	CleanupStack::PushL(charFormatLayer);
       
    54 	CRichText* bodyRichText1 = CRichText::NewL(paraFormatLayer, charFormatLayer);
       
    55 	CleanupStack::PushL(bodyRichText1);
       
    56 	
       
    57 	// Store the file contents into the CRichText object
       
    58 	bodyRichText1->ImportTextFileL(0, aFileName->Des(), ttOrg);
       
    59 	
       
    60 	TInt len1 = bodyRichText1->DocumentLength();
       
    61 	HBufC* buf1 = HBufC::NewL(len1);
       
    62 	CleanupStack::PushL(buf1);
       
    63 	TPtr fileContents = buf1->Des();
       
    64 	bodyRichText1->Extract(fileContents,0,(len1));
       
    65 	
       
    66 	// Get the type of the message 
       
    67 	TUid msgMtmType = aEntry.Entry().iMtm; 
       
    68 
       
    69 
       
    70 	CRichText* bodyRichText = CRichText::NewL(paraFormatLayer, charFormatLayer);
       
    71 	CleanupStack::PushL(bodyRichText);
       
    72 	
       
    73 	// Email message
       
    74 	if((msgMtmType.operator==(KUidMsgTypeSMTP)) || (msgMtmType.operator==(KUidMsgTypePOP3)) || (msgMtmType.operator==(KUidMsgTypeIMAP4)) )
       
    75 		{
       
    76 		CImEmailMessage*	emailMsg = CImEmailMessage::NewLC(aEntry);
       
    77 		CImEmailMessage::TImEmailEntryType tt = CImEmailMessage::EThisMessageOnly;
       
    78 		
       
    79 		emailMsg->GetBodyTextL(aEntry.EntryId(),tt,*bodyRichText,*paraFormatLayer,*charFormatLayer);
       
    80 			
       
    81 		TInt len = bodyRichText->DocumentLength();
       
    82 		HBufC* buf = HBufC::NewL(len);
       
    83 		CleanupStack::PushL(buf);
       
    84 		TPtr bodyContents = buf->Des();
       
    85 		bodyRichText->Extract(bodyContents,0,(len));
       
    86 
       
    87 		returnValue = bodyContents.Compare(fileContents);
       
    88 		CleanupStack::PopAndDestroy(2,emailMsg);
       
    89 		}
       
    90 	else if((msgMtmType.operator==(KUidMsgTypeSMS)))
       
    91 		{
       
    92 		// SMS message	
       
    93 		CMsvStore* store = aEntry.ReadStoreL();
       
    94 		CleanupStack::PushL(store);
       
    95 		
       
    96 		store->RestoreBodyTextL(*bodyRichText);
       
    97 		TInt len = bodyRichText->DocumentLength();
       
    98 		
       
    99 		HBufC* buf = HBufC::NewL(len);
       
   100 		CleanupStack::PushL(buf);
       
   101 		TPtr bodyContents = buf->Des();
       
   102 		bodyRichText->Extract(bodyContents,0,(len));
       
   103 
       
   104 		returnValue = bodyContents.Compare(fileContents);
       
   105 		CleanupStack::PopAndDestroy(2,store);
       
   106 		}
       
   107 	else if((msgMtmType.operator==(KUidMsgTypeIrUID)) ||(msgMtmType.operator==(KUidMsgTypeBt)))
       
   108 		{
       
   109 		returnValue = KErrNotSupported;
       
   110 		}
       
   111 		else
       
   112 		{
       
   113 		returnValue = KErrUnknown;
       
   114 		}
       
   115 	CleanupStack::PopAndDestroy(5,paraFormatLayer);
       
   116 	return returnValue;
       
   117 	}
       
   118 
       
   119 TInt CMtfTestActionUtilsMessage::VerifySmsRecipientsL(CMsvStore& aMsgStore,CDesC16Array&  aRecipientArray)
       
   120 	{
       
   121 	CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
       
   122 	CleanupStack::PushL(paraFormatLayer);
       
   123 	CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
       
   124 	CleanupStack::PushL(charFormatLayer);
       
   125 	CRichText* richText = CRichText::NewL(paraFormatLayer, charFormatLayer);
       
   126 	CleanupStack::PushL(richText);
       
   127 	richText->Reset();
       
   128 	
       
   129 	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *richText);
       
   130 	CleanupStack::PushL(header);
       
   131 	
       
   132 	header->RestoreL(aMsgStore);
       
   133 	
       
   134 	TInt returnValue = KErrNone;
       
   135 	
       
   136 	// Get the recipient addresses set for the SMS message
       
   137 	CArrayPtrFlat<CSmsNumber>& recipientList = header->Recipients();
       
   138 
       
   139 	// Verify the count of the recipient address set
       
   140 	if(aRecipientArray.Count() != recipientList.Count())
       
   141 		{
       
   142 		returnValue = KErrGeneral;
       
   143 		}
       
   144 	else
       
   145 		{
       
   146 		TBool foundFlag = EFalse;
       
   147 		
       
   148 		for(TInt index = 0; index < aRecipientArray.Count(); index++, foundFlag = EFalse)
       
   149 			{
       
   150 			for(TInt indexRcptArray = 0; indexRcptArray < recipientList.Count(); indexRcptArray++)
       
   151 				{
       
   152 				TPtrC address = recipientList.At(indexRcptArray)->Address();
       
   153 				if(aRecipientArray.MdcaPoint(index).Compare(address) == 0)
       
   154 					{
       
   155 					foundFlag = ETrue;
       
   156 					break;
       
   157 					}
       
   158 				}//End of inner For Loop
       
   159 					
       
   160 			if (foundFlag == EFalse)
       
   161 				{
       
   162 				returnValue = KErrNotFound;
       
   163 				break;
       
   164 				}
       
   165 			}// End If
       
   166 		}// End else
       
   167 		
       
   168 	CleanupStack::PopAndDestroy(4,paraFormatLayer);
       
   169 
       
   170 	return returnValue;
       
   171 	}
       
   172 			
       
   173 
       
   174 TInt CMtfTestActionUtilsMessage::VerifyEmailRecipientsL(CMsvStore& aMsgStore,CDesC16Array& aRecipientArray, TImHeaderEncodingInfo::TFieldList aFieldType)
       
   175 	{
       
   176 	CImHeader* header = CImHeader::NewLC();
       
   177 	header->RestoreL(aMsgStore);
       
   178 
       
   179 	TInt returnValue = KErrNone;
       
   180 	CDesCArray* rcptArray = NULL;
       
   181 
       
   182 	switch(aFieldType)
       
   183 		{
       
   184 		case  TImHeaderEncodingInfo::ETo:
       
   185 			rcptArray = &(header->ToRecipients());
       
   186 		break;
       
   187 		case  TImHeaderEncodingInfo::ECc:
       
   188 			rcptArray = &(header->CcRecipients());
       
   189 		break;
       
   190 		case  TImHeaderEncodingInfo::EBcc:
       
   191 			rcptArray = &(header->BccRecipients());
       
   192 		break;	
       
   193 		default:
       
   194 			returnValue = KErrNotSupported;
       
   195 		}
       
   196 	 
       
   197 	if( returnValue == KErrNone)
       
   198 		{
       
   199 		if( aRecipientArray.Count() != rcptArray->Count())
       
   200 			{
       
   201 			returnValue = KErrGeneral;
       
   202 			}
       
   203 		else
       
   204 			{
       
   205 			TInt recipientArrayCount = aRecipientArray.Count();
       
   206 			
       
   207 			TBool foundFlag = EFalse;
       
   208 			for(TInt index = 0; index < recipientArrayCount; index++, foundFlag = EFalse)
       
   209 				{
       
   210 				for(TInt indexRcptArray = 0; indexRcptArray < recipientArrayCount; indexRcptArray++)
       
   211 					{
       
   212 					TPtrC ptr = aRecipientArray.MdcaPoint(index);
       
   213 					TPtrC ptr1 =rcptArray->MdcaPoint(indexRcptArray);
       
   214 					if (ptr.Match(ptr1) == 0)
       
   215 						{
       
   216 						foundFlag = ETrue;
       
   217 						break;
       
   218 						}
       
   219 					}//End of inner For Loop
       
   220 					
       
   221 				if (foundFlag == EFalse)
       
   222 					{
       
   223 					returnValue = KErrNotFound;
       
   224 					break;
       
   225 					}
       
   226 				}//End of FOR loop
       
   227 			}//End Else
       
   228 		}//End If
       
   229 		
       
   230 	CleanupStack::PopAndDestroy(header);
       
   231 	return returnValue;
       
   232 	}		
       
   233 
       
   234 
       
   235 
       
   236 /**
       
   237    The function is called if IR or Bluetooth
       
   238    The recipient address set for the message is verified against
       
   239    the expected valuse
       
   240 */ 
       
   241   																			/*TPtrC8*/
       
   242 TInt CMtfTestActionUtilsMessage::VerifyObexRecipientL (CMsvEntry& aEntry, CMsvStore& aStore,	CDesC16Array&  aRecipientArray)
       
   243 	{
       
   244 	TInt returnValue = KErrNone;
       
   245 	TUid msgMtmType = aEntry.Entry().iMtm;
       
   246 
       
   247 	CObexMtmHeader* header;
       
   248 	    
       
   249 	if(msgMtmType.operator == (KUidMsgTypeBt))
       
   250 		{
       
   251 		header = CBtHeader::NewL();
       
   252 		}
       
   253 	else if(msgMtmType.operator == (KUidMsgTypeIrUID))
       
   254 		{
       
   255 		header = CIrHeader::NewL();
       
   256 		}
       
   257 	else
       
   258 		{
       
   259 		return KErrUnknown;
       
   260 		}
       
   261 	CleanupStack::PushL(header);
       
   262 		
       
   263 	header->RestoreL(aStore);
       
   264 
       
   265 	TPtrC8 tmp = header->Addr();
       
   266 	HBufC*	itemBuff = HBufC::NewLC(tmp.Length());
       
   267 	itemBuff->Des().Copy(tmp);
       
   268 	TPtrC16 msgRecipientAddr = itemBuff->Des();
       
   269 	
       
   270 	if(aRecipientArray.MdcaPoint(0).Compare(msgRecipientAddr) != 0)
       
   271 		{
       
   272 		returnValue = KErrGeneral;
       
   273 		}
       
   274 
       
   275 	CleanupStack::PopAndDestroy(itemBuff);	
       
   276 	CleanupStack::PopAndDestroy(header);
       
   277 	return returnValue;
       
   278 	}
       
   279 	
       
   280 	
       
   281 
       
   282 TInt CMtfTestActionUtilsMessage::VerifyEmailSubjectL (CMsvEntry& aEntry,HBufC*  aSubject)
       
   283 	{
       
   284 	TInt returnValue = KErrNone;
       
   285 	
       
   286 	CMsvStore* store = aEntry.ReadStoreL();
       
   287 	CleanupStack::PushL(store);
       
   288 	
       
   289 	CImHeader* messageHeader = CImHeader::NewLC();
       
   290 	messageHeader->RestoreL(*store);
       
   291 
       
   292 	TPtrC messageSubject = messageHeader->Subject();
       
   293 
       
   294 	if(messageSubject.Compare(*aSubject) != 0)
       
   295 		{
       
   296 		returnValue = KErrGeneral;
       
   297 		}
       
   298 	
       
   299 	CleanupStack::PopAndDestroy(messageHeader);
       
   300 	CleanupStack::PopAndDestroy(store);
       
   301 	
       
   302 	return returnValue;
       
   303 	}
       
   304 
       
   305 
       
   306 TInt CMtfTestActionUtilsMessage::VerifyObexSubjectL (CMsvEntry& aEntry, HBufC* aSubject)
       
   307 	{
       
   308 	TInt returnValue = KErrNone;
       
   309 	TUid msgMtmType = aEntry.Entry().iMtm;
       
   310 
       
   311 	CObexMtmHeader* header;
       
   312     
       
   313 	if(msgMtmType.operator==(KUidMsgTypeBt))
       
   314 		{
       
   315 		header = CBtHeader::NewL();
       
   316 		}
       
   317 	else if(msgMtmType.operator==(KUidMsgTypeIrUID))
       
   318 		{
       
   319 		header = CIrHeader::NewL();
       
   320 		}
       
   321 	else
       
   322 		{
       
   323 		return KErrUnknown;
       
   324 		}
       
   325 	CleanupStack::PushL(header);
       
   326 	
       
   327 	CMsvStore* msgStore = aEntry.ReadStoreL();
       
   328 	
       
   329 	CleanupStack::PushL(msgStore);
       
   330 	
       
   331 	header->RestoreL(*msgStore);
       
   332 
       
   333 	TPtrC messageSubject = header->Subject();
       
   334 
       
   335 	if( messageSubject.Compare(*aSubject) != 0 )
       
   336 		{
       
   337 		returnValue = KErrGeneral;
       
   338 		}
       
   339 		
       
   340 	CleanupStack::PopAndDestroy(msgStore);
       
   341 	CleanupStack::PopAndDestroy(header);
       
   342 		
       
   343 	return returnValue;
       
   344 	}
       
   345 
       
   346 void CMtfTestActionUtilsMessage::FormatBtRecipientAddress(TDesC& aRecipient, TDes& formattedAddr)
       
   347 	{
       
   348 	TPtrC16 ptr16 = aRecipient;
       
   349 	
       
   350 	for(int index = 0; index < 12; index+=4)
       
   351 		{
       
   352 		// do 4 characters to get one out. We're going to force the compiler to do the character endianness.
       
   353 		TUint8 byte1 = TestFrameworkActionsUtils::GetByteFromUnicodeHexTextChar(&ptr16[index]);
       
   354 		TUint8 byte2 = TestFrameworkActionsUtils::GetByteFromUnicodeHexTextChar(&ptr16[index+1]);
       
   355 		TUint8 byte3 = TestFrameworkActionsUtils::GetByteFromUnicodeHexTextChar(&ptr16[index+2]);
       
   356 		TUint8 byte4 = TestFrameworkActionsUtils::GetByteFromUnicodeHexTextChar(&ptr16[index+3]);
       
   357 
       
   358 		byte1 = (TUint8) ( ((byte1 & 0x0F) << 4) | (byte2 & 0x0f) );
       
   359 		byte3 = (TUint8) ( ((byte3 & 0x0F) << 4) | (byte4 & 0x0f) );
       
   360 
       
   361 		// make sure this is put together in network endianness
       
   362 		TUint16 result = (TUint16)( (TUint16)(byte3 << 8) | byte1 );
       
   363 
       
   364 		formattedAddr.Append( result );
       
   365 		}
       
   366 	}