common/tools/ats/smoketest/messaging/Src/TestMessStoreProcessUtil.cpp
changeset 117 483f966c6335
child 872 17498133d9ad
equal deleted inserted replaced
113:7f0174848f99 117:483f966c6335
       
     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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This contains CTestMessStoreProcessUtil. Base class process what is in the message store
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  @file TestMessStoreProcessUtil.cpp
       
    22 */
       
    23 
       
    24 #include "TestMessStoreProcessUtil.h"
       
    25 
       
    26 //	EPOC include
       
    27 #include <txtrich.h>
       
    28 
       
    29 /**
       
    30  * @name Constant Literals used.
       
    31  */
       
    32 /*@{*/
       
    33 /// Literal constants used for the character set
       
    34 _LIT(KChineseGB2312,		"ChineseGB2312");
       
    35 _LIT(KChineseHz,			"ChineseHz");
       
    36 _LIT(KChineseBig5,			"ChineseBig5");
       
    37 /*@}*/
       
    38 
       
    39 CTestMessStoreProcessUtil::CTestMessStoreProcessUtil(CTestMessBase& aTestStep, TBool aReadOnly)
       
    40 :	CBase()
       
    41 ,	iTestStep(aTestStep)
       
    42 ,	iReadOnly(aReadOnly)
       
    43 	{
       
    44 	}
       
    45 
       
    46 /**
       
    47  * Process the message entry
       
    48  * @param  TMsvId aMsvId - Id of message to edit
       
    49  * @return TInt - return TErrNone if all worked
       
    50  *  
       
    51 */
       
    52 TInt CTestMessStoreProcessUtil::ProcessEntryL(TMsvId aMsvId)
       
    53 	{
       
    54 	TInt		ret=KErrNone;
       
    55 	CMsvEntry*	msvEntry=iTestStep.Session().GetEntryL(aMsvId);
       
    56 	CleanupStack::PushL(msvEntry);
       
    57 
       
    58 	if ( msvEntry->HasStoreL() )
       
    59 		{
       
    60 		CMsvStore*	store=NULL;
       
    61 		if ( iReadOnly )
       
    62 			{
       
    63 			store=msvEntry->ReadStoreL();
       
    64 			}
       
    65 		else
       
    66 			{
       
    67 			store=msvEntry->EditStoreL();
       
    68 			}
       
    69 		CleanupStack::PushL(store);
       
    70 
       
    71 		RArray<TUid>	ids;
       
    72 		ids.Append(KUidMsgFileIMailHeader);
       
    73 		ids.Append(KUidMsgFileMimeHeader);
       
    74 		ids.Append(KUidMsgFileInternetAccessPreferences);
       
    75 		ids.Append(KUidMsvSMSHeaderStream);
       
    76 		ids.Append(KUidMsvDefaultServices);
       
    77 		ids.Append(KMsvEntryRichTextBody);
       
    78 		for ( TUint uidIndex=ids.Count(); uidIndex>0; )
       
    79 			{
       
    80 			TUid	uid=ids[--uidIndex];
       
    81 
       
    82 			if ( store->IsPresentL(uid) )
       
    83 				{
       
    84 				if ( uid==KUidMsgFileIMailHeader )
       
    85 					{
       
    86 					// Process the CImHeader info
       
    87 					ProcessImHeaderL(*store);
       
    88 					}
       
    89 				else if ( uid==KUidMsgFileMimeHeader )
       
    90 					{
       
    91 					// Process the CImMimeHeader info
       
    92 					ProcessImMimeHeaderL(*store);
       
    93 					}
       
    94 				else if ( uid==KUidMsgFileInternetAccessPreferences )
       
    95 					{
       
    96 					}
       
    97 				else if ( uid==KUidMsvSMSHeaderStream )
       
    98 					{
       
    99 					// Process the CSmsHeader info
       
   100 					ProcessSmsHeaderStreamL(*store);
       
   101 					}
       
   102 				else if ( uid==KUidMsvDefaultServices )
       
   103 					{
       
   104 					}
       
   105 				else if ( uid==KMsvEntryRichTextBody )
       
   106 					{
       
   107 					// Process the CRichText info
       
   108 					ProcessRichTextBodyL(*store);
       
   109 					}
       
   110 				else
       
   111 					{
       
   112 					iTestStep.INFO_PRINTF2(_L("Cannot process %x"), uid.iUid);
       
   113 					}
       
   114 				}
       
   115 			}
       
   116 
       
   117 		// Commit to the store
       
   118 		if ( !iReadOnly )
       
   119 			{
       
   120 			store->CommitL();
       
   121 			}
       
   122 		CleanupStack::PopAndDestroy(store);
       
   123 		}
       
   124 
       
   125 	CleanupStack::PopAndDestroy(msvEntry);
       
   126 
       
   127 	return ret;
       
   128 	}
       
   129 
       
   130 // Process the CImHeader information
       
   131 void CTestMessStoreProcessUtil::ProcessImHeaderL(CMsvStore& aStore)
       
   132 	{
       
   133 	CImHeader*	header=CImHeader::NewLC();
       
   134 	TRAPD(err, header->RestoreL(aStore));
       
   135 
       
   136 	if ( err==KErrNone )
       
   137 		{
       
   138 		ProcessImHeaderL(*header);
       
   139 		if ( !iReadOnly )
       
   140 			{
       
   141 			header->StoreL(aStore);
       
   142 			}
       
   143 		}
       
   144 
       
   145 	CleanupStack::PopAndDestroy(header);
       
   146 	}
       
   147 
       
   148 // Process the CImMimeHeader information
       
   149 void CTestMessStoreProcessUtil::ProcessImMimeHeaderL(CMsvStore& aStore)
       
   150 	{
       
   151 	CImMimeHeader*	header=CImMimeHeader::NewLC();
       
   152 	TRAPD(err, header->RestoreL(aStore));
       
   153 
       
   154 	if ( err==KErrNone )
       
   155 		{
       
   156 		ProcessImMimeHeaderL(*header);
       
   157 		if ( !iReadOnly )
       
   158 			{
       
   159 			header->StoreL(aStore);
       
   160 			}
       
   161 		}
       
   162 
       
   163 	CleanupStack::PopAndDestroy(header);
       
   164 	}
       
   165 
       
   166 
       
   167 // Process the CSmsHeader information
       
   168 void CTestMessStoreProcessUtil::ProcessSmsHeaderStreamL(CMsvStore& aStore)
       
   169 	{
       
   170 	CParaFormatLayer*	paraFormatLayer=CParaFormatLayer::NewL();
       
   171 	CleanupStack::PushL(paraFormatLayer);
       
   172 
       
   173 	CCharFormatLayer*	charFormatLayer=CCharFormatLayer::NewL(); 
       
   174 	CleanupStack::PushL(charFormatLayer);
       
   175 
       
   176 	CRichText*			bodyText=CRichText::NewL(paraFormatLayer, charFormatLayer);
       
   177 	CleanupStack::PushL(bodyText);
       
   178 
       
   179 	CSmsHeader*			header = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *bodyText);
       
   180 	CleanupStack::PushL(header);
       
   181 
       
   182 	TRAPD(err, header->RestoreL(aStore));
       
   183 	if ( err == KErrNone )
       
   184 		{
       
   185 		ProcessSmsHeaderStreamL(*header);
       
   186 		if ( !iReadOnly )
       
   187 			{
       
   188 			header->StoreL(aStore);
       
   189 			}
       
   190 		}
       
   191 
       
   192 	CleanupStack::PopAndDestroy(4, paraFormatLayer);
       
   193 	}
       
   194 
       
   195 
       
   196 // Process the CRichText information
       
   197 void CTestMessStoreProcessUtil::ProcessRichTextBodyL(CMsvStore& aStore)
       
   198 	{
       
   199 	CParaFormatLayer*	paraFormatLayer=CParaFormatLayer::NewL();
       
   200 	CleanupStack::PushL(paraFormatLayer);
       
   201 
       
   202 	CCharFormatLayer*	charFormatLayer=CCharFormatLayer::NewL(); 
       
   203 	CleanupStack::PushL(charFormatLayer);
       
   204 
       
   205 	CRichText*			bodyText=CRichText::NewL(paraFormatLayer, charFormatLayer);
       
   206 	CleanupStack::PushL(bodyText);
       
   207 
       
   208 	TRAPD(err, aStore.RestoreBodyTextL(*bodyText));
       
   209 	if ( err == KErrNone )
       
   210 		{
       
   211 		ProcessRichTextBodyL(*bodyText);
       
   212 		if ( !iReadOnly )
       
   213 			{
       
   214 			aStore.StoreBodyTextL(*bodyText);
       
   215 			}
       
   216 		}
       
   217 
       
   218 	CleanupStack::PopAndDestroy(3, paraFormatLayer);
       
   219 	}
       
   220 
       
   221 /**
       
   222  * Saves the new character set to the message 
       
   223  * @param  TPtrC aCharacterSetType - New Character set type to be stored for the received message
       
   224  * @param  TUint &aCharSetVal - character set value
       
   225  * @return TBool 
       
   226  * @panic None
       
   227  * @leave None
       
   228  *
       
   229 */
       
   230 TBool CTestMessStoreProcessUtil::ValidCharacterSetInfo(const TPtrC& aCharacterSetType, TUint &aCharSetVal)
       
   231 	{
       
   232 	TBool	hasSet = ETrue;
       
   233 
       
   234 	if ( aCharacterSetType.Compare(KChineseGB2312) == 0 )
       
   235 		{
       
   236 		iTestStep.INFO_PRINTF1(_L("Character set set to Chinese GB2312"));
       
   237 		aCharSetVal =  KCharacterSetIdentifierGb2312;
       
   238 		}
       
   239 	else if (aCharacterSetType.Compare(KChineseHz) == 0)
       
   240 		{
       
   241 		iTestStep.INFO_PRINTF1(_L("Character set set to Chinese Hz"));
       
   242 		aCharSetVal = KCharacterSetIdentifierHz;
       
   243 		}
       
   244 	else if ( aCharacterSetType.Compare(KChineseBig5) == 0 )
       
   245 		{
       
   246 		iTestStep.INFO_PRINTF1(_L("Character set set to Chinese Big5"));
       
   247 		aCharSetVal = KCharacterSetIdentifierBig5;
       
   248 		}
       
   249 	else
       
   250 		{
       
   251 		// To be updated later
       
   252 		hasSet= EFalse;
       
   253 		iTestStep.ERR_PRINTF2(_L("Character not supported in test code: %S"), &aCharacterSetType);
       
   254 		iTestStep.SetTestStepResult(EFail);
       
   255 		}
       
   256 
       
   257 	return hasSet;
       
   258 	}