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