24
|
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 |
#include "EmsTestUtils.h"
|
|
18 |
#include "EMSInformationElement.h"
|
|
19 |
#include "Gsmumsg.h"
|
|
20 |
#include "gsmubuf.h"
|
|
21 |
#include "EMSFormatIE.h"
|
|
22 |
#include "EMSSoundIE.h"
|
|
23 |
#include "EMSAnimationIE.h"
|
|
24 |
#include "EMSPictureIE.h"
|
|
25 |
#include "EMSUserPromptIE.h"
|
|
26 |
#include "EMSObjectDistributionIE.h"
|
|
27 |
#include <fbs.h>
|
|
28 |
|
|
29 |
EXPORT_C TBool EmsTestUtils::CompareEmsIE(const CEmsInformationElement& aLeft, const CEmsInformationElement& aRight)
|
|
30 |
{
|
|
31 |
TBool retVal = EFalse;
|
|
32 |
|
|
33 |
// make sure the types, start position, and length are the same
|
|
34 |
if ((aLeft.Identifier() == aRight.Identifier()) &&
|
|
35 |
(aLeft.StartPosition() == aRight.StartPosition()) &&
|
|
36 |
(aLeft.Length() == aRight.Length()))
|
|
37 |
{
|
|
38 |
switch(aLeft.Identifier())
|
|
39 |
{
|
|
40 |
case CSmsInformationElement::ESmsEnhancedTextFormatting:
|
|
41 |
{
|
|
42 |
const CEmsFormatIE& leftIE = static_cast<const CEmsFormatIE&>(aLeft);
|
|
43 |
const CEmsFormatIE& rightIE = static_cast<const CEmsFormatIE&>(aRight);
|
|
44 |
|
|
45 |
retVal = (leftIE.FormatLength() == rightIE.FormatLength()) &&
|
|
46 |
(leftIE.Bold() == rightIE.Bold()) &&
|
|
47 |
(leftIE.Italic() == rightIE.Italic()) &&
|
|
48 |
(leftIE.Underline() == rightIE.Underline()) &&
|
|
49 |
(leftIE.Strikethrough() == rightIE.Strikethrough()) &&
|
|
50 |
(leftIE.Alignment() == rightIE.Alignment()) &&
|
|
51 |
(leftIE.FontSize() == rightIE.FontSize());
|
|
52 |
break;
|
|
53 |
}
|
|
54 |
|
|
55 |
case CSmsInformationElement::ESmsEnhancedPredefinedSound:
|
|
56 |
{
|
|
57 |
const CEmsPreDefSoundIE& leftIE = static_cast<const CEmsPreDefSoundIE&>(aLeft);
|
|
58 |
const CEmsPreDefSoundIE& rightIE = static_cast<const CEmsPreDefSoundIE&>(aRight);
|
|
59 |
|
|
60 |
retVal = (leftIE.PredefinedSound() == rightIE.PredefinedSound());
|
|
61 |
break;
|
|
62 |
}
|
|
63 |
|
|
64 |
case CSmsInformationElement::ESmsEnhancedUserDefinedSound:
|
|
65 |
{
|
|
66 |
const CEmsSoundIE& leftIE = static_cast<const CEmsSoundIE&>(aLeft);
|
|
67 |
const CEmsSoundIE& rightIE = static_cast<const CEmsSoundIE&>(aRight);
|
|
68 |
|
|
69 |
// returns true if the melodies are identical - ie if the
|
|
70 |
// compare returns 0 and hence the NOT operator
|
|
71 |
retVal = !(leftIE.Melody()->Compare(*rightIE.Melody()));
|
|
72 |
break;
|
|
73 |
}
|
|
74 |
|
|
75 |
case CSmsInformationElement::ESmsEnhancedPredefinedAnimation:
|
|
76 |
{
|
|
77 |
const CEmsPreDefAnimationIE& leftIE = static_cast<const CEmsPreDefAnimationIE&>(aLeft);
|
|
78 |
const CEmsPreDefAnimationIE& rightIE = static_cast<const CEmsPreDefAnimationIE&>(aRight);
|
|
79 |
|
|
80 |
retVal = (leftIE.Animation() == rightIE.Animation());
|
|
81 |
break;
|
|
82 |
}
|
|
83 |
|
|
84 |
case CSmsInformationElement::ESmsEnhancedLargePicture:
|
|
85 |
case CSmsInformationElement::ESmsEnhancedSmallPicture:
|
|
86 |
case CSmsInformationElement::ESmsEnhancedVariablePicture:
|
|
87 |
{
|
|
88 |
// for pictures, we can only compare the size, not the actual
|
|
89 |
// content
|
|
90 |
const CEmsPictureIE& leftIE = static_cast<const CEmsPictureIE&>(aLeft);
|
|
91 |
const CEmsPictureIE& rightIE = static_cast<const CEmsPictureIE&>(aRight);
|
|
92 |
|
|
93 |
retVal = (leftIE.SizeInPixels() == rightIE.SizeInPixels());
|
|
94 |
break;
|
|
95 |
}
|
|
96 |
|
|
97 |
case CSmsInformationElement::ESmsEnhancedUserPromptIndicator:
|
|
98 |
{
|
|
99 |
// for pictures, we can only compare the size, not the actual
|
|
100 |
// content
|
|
101 |
const CEmsUserPrompt& leftIE = static_cast<const CEmsUserPrompt&>(aLeft);
|
|
102 |
const CEmsUserPrompt& rightIE = static_cast<const CEmsUserPrompt&>(aRight);
|
|
103 |
|
|
104 |
retVal = (leftIE.ObjectCount() == rightIE.ObjectCount());
|
|
105 |
break;
|
|
106 |
}
|
|
107 |
|
|
108 |
case CSmsInformationElement::ESmsEnhancedODI:
|
|
109 |
{
|
|
110 |
const CEmsObjectDistribution& leftIE = static_cast<const CEmsObjectDistribution&>(aLeft);
|
|
111 |
const CEmsObjectDistribution& rightIE = static_cast<const CEmsObjectDistribution&>(aRight);
|
|
112 |
|
|
113 |
retVal = (leftIE.ObjectCount() == rightIE.ObjectCount()) && (leftIE.Forwarding() == rightIE.Forwarding());
|
|
114 |
break;
|
|
115 |
}
|
|
116 |
|
|
117 |
case CSmsInformationElement::ESmsEnhancedLargeAnimation:
|
|
118 |
case CSmsInformationElement::ESmsEnhancedSmallAnimation:
|
|
119 |
// for animations, we can't really compare anything
|
|
120 |
retVal = ETrue;
|
|
121 |
break;
|
|
122 |
|
|
123 |
default:
|
|
124 |
// if we come across an unknown ID, we just return false
|
|
125 |
retVal = EFalse;
|
|
126 |
break;
|
|
127 |
}
|
|
128 |
}
|
|
129 |
// if an ODI, start position doesn't have to match
|
|
130 |
else if (aLeft.Identifier() == CSmsInformationElement::ESmsEnhancedODI)
|
|
131 |
{
|
|
132 |
const CEmsObjectDistribution& leftIE = static_cast<const CEmsObjectDistribution&>(aLeft);
|
|
133 |
const CEmsObjectDistribution& rightIE = static_cast<const CEmsObjectDistribution&>(aRight);
|
|
134 |
retVal = (leftIE.ObjectCount() == rightIE.ObjectCount()) && (leftIE.Forwarding() == rightIE.Forwarding()) &&
|
|
135 |
(leftIE.Identifier() == rightIE.Identifier()) && (leftIE.Length() == rightIE.Length());
|
|
136 |
}
|
|
137 |
|
|
138 |
return retVal;
|
|
139 |
}
|
|
140 |
|
|
141 |
|
|
142 |
EXPORT_C TBool EmsTestUtils::CompareEmsMsgL(const CSmsMessage& aLeft, const CSmsMessage& aRight)
|
|
143 |
{
|
|
144 |
|
|
145 |
TBool retVal = ETrue;
|
|
146 |
|
|
147 |
RSafeEmsArray leftAdjusted, rightAdjusted;
|
|
148 |
CleanupClosePushL(leftAdjusted);
|
|
149 |
CleanupClosePushL(rightAdjusted);
|
|
150 |
|
|
151 |
// Produce the adjusted ems objects so we can also compare
|
|
152 |
// segmented formatting objects
|
|
153 |
AdjustedEmsObjectsL(aLeft, leftAdjusted);
|
|
154 |
AdjustedEmsObjectsL(aRight, rightAdjusted);
|
|
155 |
|
|
156 |
// make sure the number of ems objects match
|
|
157 |
if (leftAdjusted.Count() != rightAdjusted.Count())
|
|
158 |
{
|
|
159 |
retVal = EFalse;
|
|
160 |
}
|
|
161 |
else
|
|
162 |
{
|
|
163 |
// for each EMS element in left, make sure we can find another
|
|
164 |
// element in right which matches completely
|
|
165 |
for (TInt i = 0; i < leftAdjusted.Count(); ++i)
|
|
166 |
{
|
|
167 |
TInt j;
|
|
168 |
for (j = 0; j < rightAdjusted.Count(); ++j)
|
|
169 |
{
|
|
170 |
if (CompareEmsIE(*leftAdjusted[i], *rightAdjusted[j]))
|
|
171 |
{
|
|
172 |
break;
|
|
173 |
}
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
// if j == right.Count(), this means we went through the entire
|
|
178 |
// array without finding a match. Hence we return EFalse
|
|
179 |
if (j == rightAdjusted.Count())
|
|
180 |
{
|
|
181 |
retVal = EFalse;
|
|
182 |
break;
|
|
183 |
}
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
// if EMS objects OK, then compare text as well
|
|
188 |
if (retVal)
|
|
189 |
{
|
|
190 |
HBufC* leftText = ExtractSmsTextLC(aLeft);
|
|
191 |
HBufC* rightText = ExtractSmsTextLC(aRight);
|
|
192 |
|
|
193 |
// do a text compare
|
|
194 |
retVal = (TPtr(leftText->Des()) == TPtr(rightText->Des()));
|
|
195 |
|
|
196 |
CleanupStack::PopAndDestroy(rightText);
|
|
197 |
CleanupStack::PopAndDestroy(leftText);
|
|
198 |
}
|
|
199 |
|
|
200 |
// pop the adjusted arrays
|
|
201 |
CleanupStack::PopAndDestroy(&rightAdjusted);
|
|
202 |
CleanupStack::PopAndDestroy(&leftAdjusted);
|
|
203 |
|
|
204 |
return retVal;
|
|
205 |
}
|
|
206 |
|
|
207 |
EXPORT_C const CEmsInformationElement* EmsTestUtils::FindElementL(
|
|
208 |
const CSmsMessage& aMsg, CSmsInformationElement::TSmsInformationElementIdentifier aId)
|
|
209 |
{
|
|
210 |
const RPointerArray<const CEmsInformationElement>& arr =
|
|
211 |
aMsg.GetEMSInformationElementsL();
|
|
212 |
|
|
213 |
TInt cnt = arr.Count();
|
|
214 |
for (TInt i = 0; i < cnt; ++i)
|
|
215 |
{
|
|
216 |
if (arr[i]->Identifier() == aId)
|
|
217 |
return arr[i];
|
|
218 |
}
|
|
219 |
return NULL;
|
|
220 |
}
|
|
221 |
|
|
222 |
EXPORT_C CEmsPictureIE* EmsTestUtils::CreatePictureL(TInt aIndex)
|
|
223 |
{
|
|
224 |
// path of the pictures
|
|
225 |
_LIT(KPicsMBM,"\\Ems\\pics.mbm");
|
|
226 |
|
|
227 |
// Create the picture object
|
|
228 |
CEmsPictureIE* picture = CreateEmsObjFromBitmapL<CEmsPictureIE>(KPicsMBM, aIndex);
|
|
229 |
return picture;
|
|
230 |
}
|
|
231 |
|
|
232 |
EXPORT_C CEmsAnimationIE* EmsTestUtils::CreateAnimationL(TInt aIndex)
|
|
233 |
{
|
|
234 |
// path of the animations
|
|
235 |
_LIT(KAnimsMBM,"\\Ems\\anims.mbm");
|
|
236 |
|
|
237 |
CEmsAnimationIE* anim = CreateEmsObjFromBitmapL<CEmsAnimationIE>(KAnimsMBM, aIndex);
|
|
238 |
return anim;
|
|
239 |
}
|
|
240 |
|
|
241 |
HBufC* EmsTestUtils::ExtractSmsTextLC(const CSmsMessage& aMsg)
|
|
242 |
{
|
|
243 |
const CSmsBufferBase& buffer = aMsg.Buffer();
|
|
244 |
TInt bufLen=buffer.Length();
|
|
245 |
HBufC* textBuf=HBufC::NewL(bufLen);
|
|
246 |
CleanupStack::PushL(textBuf);
|
|
247 |
TPtr textPtr(textBuf->Des());
|
|
248 |
buffer.Extract(textPtr,0,bufLen);
|
|
249 |
return textBuf;
|
|
250 |
}
|
|
251 |
|
|
252 |
void EmsTestUtils::AdjustedEmsObjectsL(
|
|
253 |
const CSmsMessage& aMsg, RPointerArray<CEmsInformationElement>& aAdjusted)
|
|
254 |
{
|
|
255 |
// This will contain all the formatting objects of the message,
|
|
256 |
// but consolidated
|
|
257 |
RPointerArray<CEmsInformationElement> formatObjects(10);
|
|
258 |
|
|
259 |
const RPointerArray<const CEmsInformationElement>& emsObjects =
|
|
260 |
aMsg.GetEMSInformationElementsL();
|
|
261 |
|
|
262 |
// now go through the array in the message, and copy the objects
|
|
263 |
// if they are not format objects. Format objects go in a separate
|
|
264 |
// array for consolidation
|
|
265 |
TInt i;
|
|
266 |
for (i = 0; i < emsObjects.Count(); ++i)
|
|
267 |
{
|
|
268 |
if (emsObjects[i]->Identifier() != CSmsInformationElement::ESmsEnhancedTextFormatting)
|
|
269 |
{
|
|
270 |
aAdjusted.Append(emsObjects[i]->DuplicateL());
|
|
271 |
}
|
|
272 |
else
|
|
273 |
{
|
|
274 |
// otherwise, go through the format list and see if can be appended
|
|
275 |
// to an existing format object
|
|
276 |
const CEmsFormatIE* formatIE = static_cast<const CEmsFormatIE*>(emsObjects[i]);
|
|
277 |
TInt j;
|
|
278 |
for (j = 0; j < formatObjects.Count(); ++j)
|
|
279 |
{
|
|
280 |
// check if the start position of this element equals the
|
|
281 |
// startPos + length of the other format object
|
|
282 |
CEmsFormatIE* other = static_cast<CEmsFormatIE*>(formatObjects[j]);
|
|
283 |
if (formatIE->StartPosition() == other->StartPosition() + other->FormatLength() &&
|
|
284 |
formatIE->Bold() == other->Bold() &&
|
|
285 |
formatIE->Italic() == other->Italic() &&
|
|
286 |
formatIE->Underline() == other->Underline() &&
|
|
287 |
formatIE->Strikethrough() == other->Strikethrough() &&
|
|
288 |
formatIE->Alignment() == other->Alignment() &&
|
|
289 |
formatIE->FontSize() == other->FontSize())
|
|
290 |
{
|
|
291 |
// add the length
|
|
292 |
other->SetFormatLength(other->FormatLength() + formatIE->FormatLength());
|
|
293 |
break;
|
|
294 |
}
|
|
295 |
}
|
|
296 |
|
|
297 |
// if we have gone to the end without appending to another element,
|
|
298 |
// then clone the element and add it to the formatObjects array
|
|
299 |
if (j == formatObjects.Count())
|
|
300 |
{
|
|
301 |
formatObjects.Append(formatIE->DuplicateL());
|
|
302 |
}
|
|
303 |
}
|
|
304 |
}
|
|
305 |
|
|
306 |
// Now, move all elements from the format objects into the adjusted array
|
|
307 |
for (i = 0; i < formatObjects.Count(); ++i)
|
|
308 |
{
|
|
309 |
aAdjusted.Append(formatObjects[i]);
|
|
310 |
}
|
|
311 |
|
|
312 |
// make sure array memory has been deallocated
|
|
313 |
formatObjects.Close();
|
|
314 |
}
|
|
315 |
|
|
316 |
template <class T>
|
|
317 |
T* EmsTestUtils::CreateEmsObjFromBitmapL(const TDesC& aFilename, TInt32 aIndex)
|
|
318 |
{
|
|
319 |
_LIT(KTxtCDrive,"C:");
|
|
320 |
_LIT(KTxtZDrive,"Z:");
|
|
321 |
|
|
322 |
// startup bitmap server
|
|
323 |
FbsStartup();
|
|
324 |
User::LeaveIfError(RFbsSession::Connect());
|
|
325 |
|
|
326 |
// Given a particular filename, assumed to be in C:\ or Z:\, we load
|
|
327 |
// a bitmap from the given index. The bitmap is pushed onto the
|
|
328 |
// cleanup stack
|
|
329 |
CFbsBitmap* bmp;
|
|
330 |
|
|
331 |
TParse mbfn;
|
|
332 |
bmp = new (ELeave) CFbsBitmap();
|
|
333 |
CleanupStack::PushL(bmp);
|
|
334 |
|
|
335 |
// load the indexed bitmap, first in drive C, then drive Z
|
|
336 |
mbfn.Set(aFilename, &KTxtCDrive, NULL);
|
|
337 |
|
|
338 |
// did it fail?
|
|
339 |
if (bmp->Load(mbfn.FullName(), aIndex))
|
|
340 |
{
|
|
341 |
// then try drive Z
|
|
342 |
mbfn.Set(aFilename, &KTxtZDrive, NULL);
|
|
343 |
User::LeaveIfError(bmp->Load(mbfn.FullName(), aIndex));
|
|
344 |
}
|
|
345 |
|
|
346 |
// if it succeeded, then create the appropriate type
|
|
347 |
T* obj = T::NewL(*bmp);
|
|
348 |
CleanupStack::PopAndDestroy(bmp);
|
|
349 |
|
|
350 |
RFbsSession::Disconnect();
|
|
351 |
|
|
352 |
return obj;
|
|
353 |
}
|