|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 @test |
|
20 @internalComponent |
|
21 |
|
22 This contains CT_DataBitmapUtil |
|
23 */ |
|
24 |
|
25 // User includes |
|
26 #include "T_DataBitmapUtil.h" |
|
27 #include "T_GraphicsUtil.h" |
|
28 |
|
29 /*@{*/ |
|
30 /// Parameters |
|
31 _LIT(KBitmap, "bitmap"); |
|
32 _LIT(KPointX, "point_x"); |
|
33 _LIT(KPointY, "point_y"); |
|
34 _LIT(KOtherBitmapUtil, "other_bitmap_util"); |
|
35 _LIT(KColor, "color"); |
|
36 _LIT(KColorMask, "colormask"); |
|
37 |
|
38 /// Commands |
|
39 _LIT(KCmdNew, "new"); |
|
40 _LIT(KCmdBegin, "Begin"); |
|
41 _LIT(KCmdEnd, "End"); |
|
42 _LIT(KCmdSetPixel, "SetPixel"); |
|
43 _LIT(KCmdGetPixel, "GetPixel"); |
|
44 _LIT(KCmdSetPos, "SetPos"); |
|
45 _LIT(KCmdDecXPos, "DecXPos"); |
|
46 _LIT(KCmdDecYPos, "DecYPos"); |
|
47 _LIT(KCmdIncXPos, "IncXPos"); |
|
48 _LIT(KCmdIncYPos, "IncYPos"); |
|
49 _LIT(KCleanup, "~"); |
|
50 /*@}*/ |
|
51 |
|
52 /** |
|
53 * Two phase constructor |
|
54 */ |
|
55 CT_DataBitmapUtil* CT_DataBitmapUtil::NewL() |
|
56 { |
|
57 CT_DataBitmapUtil* ret = new (ELeave) CT_DataBitmapUtil(); |
|
58 return ret; |
|
59 } |
|
60 |
|
61 /** |
|
62 * Protected constructor. First phase construction |
|
63 */ |
|
64 CT_DataBitmapUtil::CT_DataBitmapUtil() |
|
65 : CDataWrapperBase() |
|
66 , iBitmapUtil(NULL) |
|
67 { |
|
68 } |
|
69 |
|
70 /** |
|
71 * Protected desctructor |
|
72 */ |
|
73 CT_DataBitmapUtil::~CT_DataBitmapUtil() |
|
74 { |
|
75 DestroyData(); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Contains cleanup implementation |
|
80 */ |
|
81 void CT_DataBitmapUtil::DestroyData() |
|
82 { |
|
83 delete iBitmapUtil; |
|
84 iBitmapUtil = NULL; |
|
85 } |
|
86 |
|
87 TAny* CT_DataBitmapUtil::GetObject() |
|
88 { |
|
89 return iBitmapUtil; |
|
90 } |
|
91 |
|
92 void CT_DataBitmapUtil::SetObjectL(TAny* aObject) |
|
93 { |
|
94 DestroyData(); |
|
95 iBitmapUtil = static_cast<TBitmapUtil*> (aObject); |
|
96 } |
|
97 |
|
98 void CT_DataBitmapUtil::DisownObjectL() |
|
99 { |
|
100 iBitmapUtil = NULL; |
|
101 } |
|
102 |
|
103 /** |
|
104 * Process a command read from the ini file |
|
105 * |
|
106 * @param aDataWrapper test step requiring command to be processed |
|
107 * @param aCommand the command to process |
|
108 * @param aSection the entry in the ini file requiring the command to be processed |
|
109 * |
|
110 * @return ETrue if the command is processed |
|
111 */ |
|
112 TBool CT_DataBitmapUtil::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
113 { |
|
114 TBool retVal = ETrue; |
|
115 |
|
116 if (aCommand == KCmdNew) |
|
117 { |
|
118 DoCmdNewL(aSection); |
|
119 } |
|
120 else if (aCommand == KCmdBegin) |
|
121 { |
|
122 DoCmdBeginL(aSection); |
|
123 } |
|
124 else if (aCommand == KCmdEnd) |
|
125 { |
|
126 DoCmdEnd(); |
|
127 } |
|
128 else if (aCommand == KCmdSetPixel) |
|
129 { |
|
130 DoCmdSetPixelL(aSection); |
|
131 } |
|
132 else if (aCommand == KCmdGetPixel) |
|
133 { |
|
134 DoCmdGetPixel(aSection); |
|
135 } |
|
136 else if (aCommand == KCmdSetPos) |
|
137 { |
|
138 DoCmdSetPos(aSection); |
|
139 } |
|
140 else if (aCommand == KCmdDecXPos) |
|
141 { |
|
142 DoCmdDecXPos(); |
|
143 } |
|
144 else if (aCommand == KCmdDecYPos) |
|
145 { |
|
146 DoCmdDecYPos(); |
|
147 } |
|
148 else if (aCommand == KCmdIncXPos) |
|
149 { |
|
150 DoCmdIncXPos(); |
|
151 } |
|
152 else if (aCommand == KCmdIncYPos) |
|
153 { |
|
154 DoCmdIncYPos(); |
|
155 } |
|
156 else if (aCommand == KCleanup) |
|
157 { |
|
158 DestroyData(); |
|
159 } |
|
160 else |
|
161 { |
|
162 retVal=EFalse; |
|
163 } |
|
164 |
|
165 return retVal; |
|
166 } |
|
167 |
|
168 |
|
169 |
|
170 /** Creates a TBitmapUtil instance */ |
|
171 void CT_DataBitmapUtil::DoCmdNewL(const TDesC& aSection) |
|
172 { |
|
173 INFO_PRINTF1(_L("Creates a TBitmapUtil instance")); |
|
174 |
|
175 // get fbsBitmap passed as a parameter |
|
176 CFbsBitmap* fbsBitmap=NULL; |
|
177 CT_GraphicsUtil::GetFbsBitmapL(*this, aSection, KBitmap(), fbsBitmap); |
|
178 |
|
179 // cleanup if already created |
|
180 delete iBitmapUtil; |
|
181 iBitmapUtil = NULL; |
|
182 |
|
183 // call new operator |
|
184 TRAPD(err, iBitmapUtil = new (ELeave) TBitmapUtil(fbsBitmap)); |
|
185 |
|
186 // check error code |
|
187 if (err != KErrNone) |
|
188 { |
|
189 ERR_PRINTF2(_L("Error creation instance: %d"), err); |
|
190 SetError(err); |
|
191 } |
|
192 } |
|
193 |
|
194 |
|
195 /** Calls TBitmapUtil::Begin() */ |
|
196 void CT_DataBitmapUtil::DoCmdBeginL(const TDesC& aSection) |
|
197 { |
|
198 INFO_PRINTF1(_L("Calls TBitmapUtil::Begin()")); |
|
199 TBool dataOk=ETrue; |
|
200 |
|
201 // get position x-coordinate from parameters |
|
202 TInt pointX; |
|
203 if(!GetIntFromConfig(aSection, KPointX(), pointX)) |
|
204 { |
|
205 ERR_PRINTF2(_L("No %S"), &KPointX()); |
|
206 SetBlockResult(EFail); |
|
207 dataOk=EFalse; |
|
208 } |
|
209 |
|
210 // get position y-coordinate from parameters |
|
211 TInt pointY; |
|
212 if(!GetIntFromConfig(aSection, KPointY(), pointY)) |
|
213 { |
|
214 ERR_PRINTF2(_L("No %S"), &KPointY()); |
|
215 SetBlockResult(EFail); |
|
216 dataOk=EFalse; |
|
217 } |
|
218 |
|
219 if ( dataOk ) |
|
220 { |
|
221 // call Begin() |
|
222 // get bitmapUtil passed as a parameter |
|
223 CT_DataBitmapUtil* bitmapUtilDataObject = CT_DataBitmapUtil::GetBitmapUtilDataObjectFromParameterL(*this, KOtherBitmapUtil(), aSection); |
|
224 |
|
225 if (bitmapUtilDataObject == NULL) |
|
226 { |
|
227 iBitmapUtil->Begin(TPoint(pointX, pointY)); |
|
228 } |
|
229 else |
|
230 { |
|
231 TBitmapUtil* otherBitmapUtil = static_cast<TBitmapUtil*>(bitmapUtilDataObject->GetObject()); |
|
232 |
|
233 // call Begin() |
|
234 iBitmapUtil->Begin(TPoint(pointX, pointY), *otherBitmapUtil); |
|
235 } |
|
236 } |
|
237 } |
|
238 |
|
239 |
|
240 /** Calls TBitmapUtil::End() */ |
|
241 void CT_DataBitmapUtil::DoCmdEnd() |
|
242 { |
|
243 INFO_PRINTF1(_L("Calls TBitmapUtil::End()")); |
|
244 |
|
245 // call End() |
|
246 iBitmapUtil->End(); |
|
247 } |
|
248 |
|
249 |
|
250 /** Calls TBitmapUtil::SetPixel() */ |
|
251 void CT_DataBitmapUtil::DoCmdSetPixelL(const TDesC& aSection) |
|
252 { |
|
253 INFO_PRINTF1(_L("Calls TBitmapUtil::SetPixel()")); |
|
254 |
|
255 // get bitmapUtil passed as a parameter |
|
256 CT_DataBitmapUtil* bitmapUtilDataObject = CT_DataBitmapUtil::GetBitmapUtilDataObjectFromParameterL(*this, KOtherBitmapUtil(), aSection); |
|
257 |
|
258 if (bitmapUtilDataObject == NULL) |
|
259 { |
|
260 // get color from parameters |
|
261 TInt color; |
|
262 if(!GetIntFromConfig(aSection, KColor(), color)) |
|
263 { |
|
264 ERR_PRINTF2(_L("No %S"), &KColor()); |
|
265 SetBlockResult(EFail); |
|
266 } |
|
267 else |
|
268 { |
|
269 // call SetPixel() |
|
270 iBitmapUtil->SetPixel(TUint32(color)); |
|
271 } |
|
272 } |
|
273 else |
|
274 { |
|
275 TBitmapUtil* otherBitmapUtil = static_cast<TBitmapUtil*>(bitmapUtilDataObject->GetObject()); |
|
276 |
|
277 // call SetPixel() |
|
278 iBitmapUtil->SetPixel(*otherBitmapUtil); |
|
279 } |
|
280 } |
|
281 |
|
282 |
|
283 /** Calls TBitmapUtil::GetPixel() */ |
|
284 void CT_DataBitmapUtil::DoCmdGetPixel(const TDesC& aSection) |
|
285 { |
|
286 // call GetPixel() |
|
287 TUint32 color = iBitmapUtil->GetPixel(); |
|
288 INFO_PRINTF2(_L("Calls TBitmapUtil::GetPixel() %d"), color); |
|
289 |
|
290 TInt colorMask; |
|
291 if ( GetHexFromConfig(aSection, KColorMask(), colorMask) ) |
|
292 { |
|
293 color &= colorMask; |
|
294 INFO_PRINTF2(_L("Color after masking %d"), color); |
|
295 } |
|
296 |
|
297 // get expected color from parameters |
|
298 TInt expectedColor; |
|
299 if(GetIntFromConfig(aSection, KColor(), expectedColor)) |
|
300 { |
|
301 // check that the value is as expected |
|
302 if (color != (TUint32)expectedColor ) |
|
303 { |
|
304 ERR_PRINTF3(_L("The value is not as expected! expected: %d, actual: %d"), expectedColor, color); |
|
305 SetBlockResult(EFail); |
|
306 } |
|
307 } |
|
308 } |
|
309 |
|
310 /** Calls TBitmapUtil::SetPos() */ |
|
311 void CT_DataBitmapUtil::DoCmdSetPos(const TDesC& aSection) |
|
312 { |
|
313 INFO_PRINTF1(_L("Calls TBitmapUtil::SetPos()")); |
|
314 TBool dataOk=ETrue; |
|
315 |
|
316 // get position x-coordinate from parameters |
|
317 TInt pointX; |
|
318 if(!GetIntFromConfig(aSection, KPointX(), pointX)) |
|
319 { |
|
320 ERR_PRINTF2(_L("No %S"), &KPointX()); |
|
321 SetBlockResult(EFail); |
|
322 dataOk=EFalse; |
|
323 } |
|
324 |
|
325 // get position y-coordinate from parameters |
|
326 TInt pointY; |
|
327 if(!GetIntFromConfig(aSection, KPointY(), pointY)) |
|
328 { |
|
329 ERR_PRINTF2(_L("No %S"), &KPointY()); |
|
330 SetBlockResult(EFail); |
|
331 dataOk=EFalse; |
|
332 } |
|
333 |
|
334 if ( dataOk ) |
|
335 { |
|
336 // call SetPos() |
|
337 iBitmapUtil->SetPos(TPoint(pointX, pointY)); |
|
338 } |
|
339 } |
|
340 |
|
341 |
|
342 /** Calls TBitmapUtil::DecXPos() */ |
|
343 void CT_DataBitmapUtil::DoCmdDecXPos() |
|
344 { |
|
345 INFO_PRINTF1(_L("Calls TBitmapUtil::DecXPos()")); |
|
346 |
|
347 // call DecXPos() |
|
348 iBitmapUtil->DecXPos(); |
|
349 } |
|
350 |
|
351 |
|
352 /** Calls TBitmapUtil::DecYPos() */ |
|
353 void CT_DataBitmapUtil::DoCmdDecYPos() |
|
354 { |
|
355 INFO_PRINTF1(_L("Calls TBitmapUtil::DecYPos()")); |
|
356 |
|
357 // call DecYPos() |
|
358 iBitmapUtil->DecYPos(); |
|
359 } |
|
360 |
|
361 |
|
362 /** Calls TBitmapUtil::IncXPos() */ |
|
363 void CT_DataBitmapUtil::DoCmdIncXPos() |
|
364 { |
|
365 INFO_PRINTF1(_L("Calls TBitmapUtil::IncXPos()")); |
|
366 |
|
367 // call IncXPos() |
|
368 iBitmapUtil->IncXPos(); |
|
369 } |
|
370 |
|
371 |
|
372 /** Calls TBitmapUtil::IncYPos() */ |
|
373 void CT_DataBitmapUtil::DoCmdIncYPos() |
|
374 { |
|
375 INFO_PRINTF1(_L("Calls TBitmapUtil::IncYPos()")); |
|
376 |
|
377 // call IncYPos() |
|
378 iBitmapUtil->IncYPos(); |
|
379 } |
|
380 |
|
381 |
|
382 |
|
383 ///////////////////////////////// UTIL METHODS ////////////////////////////////////// |
|
384 |
|
385 |
|
386 /** |
|
387 * Utility method that fetches CT_DataBitmapUtil pointer by command parameter name from INI-file. |
|
388 */ |
|
389 CT_DataBitmapUtil* CT_DataBitmapUtil::GetBitmapUtilDataObjectFromParameterL(CDataWrapper& aDataWrapper, const TDesC& aParameterName, const TDesC& aSection) |
|
390 { |
|
391 // get AlgStyleData object from parameters |
|
392 CT_DataBitmapUtil* ret=NULL; |
|
393 |
|
394 TPtrC bitmapUtilDataObjectName; |
|
395 // get BitmapUtilData object from parameters |
|
396 if ( aDataWrapper.GetStringFromConfig(aSection, aParameterName, bitmapUtilDataObjectName) ) |
|
397 { |
|
398 // check that the data object was found |
|
399 ret=static_cast<CT_DataBitmapUtil*>(aDataWrapper.GetDataWrapperL(bitmapUtilDataObjectName)); |
|
400 } |
|
401 |
|
402 return ret; |
|
403 } |