messagingfw/msgtest/testutils/sms/src/EmsMsgTestUtils.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 1999-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 #include "EmsMsgTestUtils.h"
       
    17 #include <msgtestscripts.h>
       
    18 #include <emsformatie.h>
       
    19 #include <emsanimationie.h>
       
    20 #include <emssoundie.h>
       
    21 #include <emsuserpromptie.h>
       
    22 #include <gsmumsg.h>
       
    23 #include "emstestutils.h"
       
    24 
       
    25 
       
    26 CEmsExtractor* CEmsExtractor::NewL(CScriptSection& aSection)
       
    27 	{
       
    28 	CEmsExtractor* retVal = NewLC(aSection);
       
    29 	CleanupStack::Pop(retVal);
       
    30 
       
    31 	return retVal;
       
    32 	}
       
    33 CEmsExtractor* CEmsExtractor::NewLC(CScriptSection& aSection)
       
    34 	{
       
    35 	CEmsExtractor* retVal = new (ELeave) CEmsExtractor;
       
    36 	CleanupStack::PushL(retVal);
       
    37 	retVal->ConstructL(aSection);
       
    38 
       
    39 	return retVal;
       
    40 	}
       
    41 
       
    42 void CEmsExtractor::ConstructL(CScriptSection& aSection)
       
    43 	{
       
    44 	// create the vector of parsers
       
    45 	iParsers.Append(new (ELeave) EmsFormatParser);
       
    46 	iParsers.Append(new (ELeave) EmsUserSoundParser);
       
    47 	iParsers.Append(new (ELeave) EmsPredefSoundParser);
       
    48 	iParsers.Append(new (ELeave) EmsPicParser);
       
    49 	iParsers.Append(new (ELeave) EmsAnimParser);
       
    50 	iParsers.Append(new (ELeave) EmsPredefAnimParser);
       
    51 	iParsers.Append(new (ELeave) EmsUserPromptParser);
       
    52 
       
    53 	// For each of the different types of parsers, attempt
       
    54 	// to extract the object information from the section
       
    55 	for (TInt i = 0; i < iParsers.Count(); ++i)
       
    56 		{
       
    57 		iParsers[i]->ParseL(aSection, iEmsArray);
       
    58 		}
       
    59 	}
       
    60 	
       
    61 CEmsExtractor::~CEmsExtractor()
       
    62 	{ 
       
    63 	iEmsArray.ResetAndDestroy(); 
       
    64 	iParsers.ResetAndDestroy();
       
    65 	}
       
    66 
       
    67 void CEmsExtractor::AddToMessageL(CSmsMessage& msg) const
       
    68 	{
       
    69 	for (TInt i = 0; i < iEmsArray.Count(); ++i)
       
    70 		{
       
    71 		msg.AddEMSInformationElementL(*iEmsArray[i]);
       
    72 		}
       
    73 	}
       
    74 
       
    75 void EmsParser::ParseL(CScriptSection& aSection, 
       
    76 					   RPointerArray<CEmsInformationElement>& aEmsArray) const
       
    77 	{
       
    78 	// Get the value for the specific tag
       
    79 	TPtrC tagPtr(aSection.ItemValue(iTagName, KNullDesC));
       
    80 
       
    81 	// Only proceed if our string is non-empty
       
    82 	if (tagPtr.Length() > 0)
       
    83 		{
       
    84 		// Firstly, wrap the characters in a TLex object
       
    85 		TLex input(tagPtr);
       
    86 
       
    87 		// Now, extract the number of objects we are expecting
       
    88 		TInt num = ExtractIntegerL(input);
       
    89 
       
    90 		// Loop around 'n' times getting the start position and then calling
       
    91 		// the specific processing function
       
    92 		for (TInt i = 0; i < num; ++i)
       
    93 			{
       
    94 			TInt startPos = ExtractIntegerL(input);
       
    95 
       
    96 			// call the virtual function to append a new ems object into the
       
    97 			// array
       
    98 			aEmsArray.Append(GetElementL(input, startPos));
       
    99 			}
       
   100 		}
       
   101 	}
       
   102 
       
   103 TInt EmsParser::ExtractIntegerL(TLex& aInput)
       
   104 	{
       
   105 	aInput.Mark();
       
   106 
       
   107 	// Now, get the value
       
   108 	TInt retVal;
       
   109 	User::LeaveIfError(aInput.Val(retVal));
       
   110 
       
   111 	// Skip any whitespaces
       
   112 	aInput.SkipSpace();
       
   113 
       
   114 	return retVal;
       
   115 	}
       
   116 
       
   117 
       
   118 CEmsInformationElement* EmsFormatParser::GetElementL(TLex& aInput, TInt aStartPos) const
       
   119 	{
       
   120 	// Firstly, extract all the necessary parameters
       
   121 	TInt formatLength = ExtractIntegerL(aInput);
       
   122 	TInt formatValue = ExtractIntegerL(aInput);
       
   123 
       
   124 	// now, create the formatting object
       
   125 	CEmsFormatIE* object = CEmsFormatIE::NewL();
       
   126 	object->SetStartPosition(aStartPos);
       
   127 	object->SetFormatLength(formatLength);
       
   128 	object->SetAlignment(STATIC_CAST(CEmsFormatIE::TAlignment, formatValue & 0x03));
       
   129 	object->SetFontSize(STATIC_CAST(CEmsFormatIE::TFontSize, (formatValue & 0x0C) >> 2));
       
   130 	object->SetBold(formatValue & 0x10);
       
   131 	object->SetItalic(formatValue & 0x20);
       
   132 	object->SetUnderline(formatValue & 0x40);
       
   133 	object->SetStrikethrough(formatValue & 0x80);
       
   134 
       
   135 	// Return this object
       
   136 	return object;
       
   137 	}
       
   138 
       
   139 CEmsInformationElement* EmsUserSoundParser::GetElementL(TLex& aInput, TInt aStartPos) const
       
   140 	{
       
   141 	TPtrC soundAlpha;
       
   142 
       
   143 	// Extract the sound but leave there is none.
       
   144 	User::LeaveIfError(CScriptFile::GetNextWord(aInput, ' ', soundAlpha));
       
   145 
       
   146 	TInt length = soundAlpha.Length();
       
   147 
       
   148 	// Otherwise, create a new HBuf with the sound length
       
   149 	HBufC8* sound = HBufC8::NewLC(soundAlpha.Length());
       
   150 	TPtr8 ptr(sound->Des());
       
   151 
       
   152 	// Go through the soundAlpha and extract the sound bytes
       
   153 	// (removing offset of 'a')
       
   154 	for (TInt i = 0; i < length; ++i)
       
   155 		{
       
   156 		ptr.Append(STATIC_CAST(TUint8, soundAlpha[i]) - 'a');
       
   157 		}
       
   158 
       
   159 	// Create the sound object
       
   160 	CEmsSoundIE* object = CEmsSoundIE::NewL(*sound);
       
   161 	object->SetStartPosition(aStartPos);
       
   162 	CleanupStack::PopAndDestroy(sound);
       
   163 
       
   164 	return object;
       
   165 	}
       
   166 
       
   167 CEmsInformationElement* EmsPredefSoundParser::GetElementL(TLex& aInput, TInt aStartPos) const
       
   168 	{
       
   169 	TInt sndValue = ExtractIntegerL(aInput);
       
   170 
       
   171 	CEmsPreDefSoundIE* object = CEmsPreDefSoundIE::NewL(
       
   172 		STATIC_CAST(CEmsPreDefSoundIE::TPredefinedSound, sndValue));
       
   173 	object->SetStartPosition(aStartPos);
       
   174 
       
   175 	return object;
       
   176 	}
       
   177 
       
   178 CEmsInformationElement* EmsPicParser::GetElementL(TLex& aInput, TInt aStartPos) const
       
   179 	{
       
   180 	TInt picValue = ExtractIntegerL(aInput);
       
   181 
       
   182 	// construct a picture from the index which was input
       
   183 	CEmsPictureIE* object = EmsTestUtils::CreatePictureL(picValue);
       
   184 	object->SetStartPosition(aStartPos);
       
   185 
       
   186 	return object;
       
   187 	}
       
   188 
       
   189 CEmsInformationElement* EmsAnimParser::GetElementL(TLex& aInput, TInt aStartPos) const
       
   190 	{
       
   191 	TInt animValue = ExtractIntegerL(aInput);
       
   192 
       
   193 	// construct a picture from the index which was input
       
   194 	CEmsAnimationIE* object = EmsTestUtils::CreateAnimationL(animValue);
       
   195 	object->SetStartPosition(aStartPos);
       
   196 
       
   197 	return object;
       
   198 	}
       
   199 
       
   200 CEmsInformationElement* EmsPredefAnimParser::GetElementL(TLex& aInput, TInt aStartPos) const
       
   201 	{
       
   202 	TInt animValue = ExtractIntegerL(aInput);
       
   203 
       
   204 	CEmsPreDefAnimationIE* object = CEmsPreDefAnimationIE::NewL(
       
   205 		STATIC_CAST(CEmsPreDefAnimationIE::TAnimType, animValue));
       
   206 	object->SetStartPosition(aStartPos);
       
   207 
       
   208 	return object;
       
   209 	}
       
   210 
       
   211 CEmsInformationElement* EmsUserPromptParser::GetElementL(TLex& aInput, TInt aStartPos) const
       
   212 	{	
       
   213 	TInt objCount = ExtractIntegerL(aInput);
       
   214 
       
   215 	CEmsUserPrompt* object = CEmsUserPrompt::NewL(objCount);
       
   216 	object->SetStartPosition(aStartPos);
       
   217 	return object;
       
   218 	}
       
   219