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 "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "T_DataWsGraphicMsgBuf.h" |
|
19 |
|
20 /*@{*/ |
|
21 //Parameters |
|
22 _LIT(KExpected, "expected"); |
|
23 _LIT(KInputTypeId, "inputTypeId"); |
|
24 _LIT(KInputText, "inputText"); |
|
25 _LIT(KInputUseText8, "inputUseText8"); |
|
26 _LIT(KInputMsgLen, "inputMsgLen"); |
|
27 _LIT(KInputMsgPosition, "inputMsgPosition"); |
|
28 _LIT(KInputFormat, "inputFormat"); |
|
29 |
|
30 //Commands |
|
31 _LIT(KCmdnew, "new"); |
|
32 _LIT(KCmdClose, "Close"); |
|
33 _LIT(KCmdCleanupClosePushL, "CleanupClosePushL"); |
|
34 _LIT(KCmdAppend, "Append"); |
|
35 _LIT(KCmdRemove, "Remove"); |
|
36 _LIT(KCmdCount, "Count"); |
|
37 _LIT(KCmdTypeId, "TypeId"); |
|
38 _LIT(KCmdData, "Data"); |
|
39 _LIT(KCmdGetFixedMsg, "GetFixedMsg"); |
|
40 _LIT(KCmdPckg, "Pckg"); |
|
41 /*@}*/ |
|
42 |
|
43 ////////////////////////////////////////////////////////////////////// |
|
44 // Construction/Destruction |
|
45 ////////////////////////////////////////////////////////////////////// |
|
46 |
|
47 CT_DataWsGraphicMsgBuf* CT_DataWsGraphicMsgBuf::NewL() |
|
48 { |
|
49 CT_DataWsGraphicMsgBuf* ret=new (ELeave) CT_DataWsGraphicMsgBuf(); |
|
50 CleanupStack::PushL(ret); |
|
51 ret->ConstructL(); |
|
52 CleanupStack::Pop(ret); |
|
53 return ret; |
|
54 } |
|
55 |
|
56 CT_DataWsGraphicMsgBuf::CT_DataWsGraphicMsgBuf() |
|
57 : CDataWrapperBase() |
|
58 , iWsGraphicMsgBuf(NULL) |
|
59 { |
|
60 } |
|
61 |
|
62 void CT_DataWsGraphicMsgBuf::ConstructL() |
|
63 { |
|
64 } |
|
65 |
|
66 CT_DataWsGraphicMsgBuf::~CT_DataWsGraphicMsgBuf() |
|
67 { |
|
68 DestroyData(); |
|
69 } |
|
70 |
|
71 void CT_DataWsGraphicMsgBuf::SetObjectL(TAny* aAny) |
|
72 { |
|
73 DestroyData(); |
|
74 iWsGraphicMsgBuf = static_cast<RWsGraphicMsgBuf*> (aAny); |
|
75 } |
|
76 |
|
77 void CT_DataWsGraphicMsgBuf::DisownObjectL() |
|
78 { |
|
79 iWsGraphicMsgBuf = NULL; |
|
80 } |
|
81 |
|
82 void CT_DataWsGraphicMsgBuf::DestroyData() |
|
83 { |
|
84 delete iWsGraphicMsgBuf; |
|
85 iWsGraphicMsgBuf=NULL; |
|
86 } |
|
87 |
|
88 |
|
89 /** |
|
90 * Process a command read from the ini file |
|
91 * |
|
92 * @param aCommand the command to process |
|
93 * @param aSection the entry in the ini file requiring the command to be processed |
|
94 * @param aAsyncErrorIndex index of command. used for async calls |
|
95 * |
|
96 * @return ETrue if the command is processed |
|
97 */ |
|
98 TBool CT_DataWsGraphicMsgBuf::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
99 { |
|
100 TBool ret = ETrue; |
|
101 |
|
102 if ( aCommand==KCmdnew ) |
|
103 { |
|
104 DoCmdnew(); |
|
105 } |
|
106 else if ( aCommand==KCmdClose ) |
|
107 { |
|
108 DoCmdClose(); |
|
109 } |
|
110 else if ( aCommand==KCmdCleanupClosePushL ) |
|
111 { |
|
112 DoCmdCleanupClosePushL(); |
|
113 } |
|
114 else if ( aCommand==KCmdAppend ) |
|
115 { |
|
116 DoCmdAppendL(aSection); |
|
117 } |
|
118 else if ( aCommand==KCmdRemove ) |
|
119 { |
|
120 DoCmdRemove(aSection); |
|
121 } |
|
122 else if ( aCommand==KCmdCount ) |
|
123 { |
|
124 DoCmdCount(aSection); |
|
125 } |
|
126 else if ( aCommand==KCmdTypeId ) |
|
127 { |
|
128 DoCmdTypeId(aSection); |
|
129 } |
|
130 else if ( aCommand==KCmdData ) |
|
131 { |
|
132 DoCmdDataL(aSection); |
|
133 } |
|
134 else if( aCommand==KCmdGetFixedMsg) |
|
135 { |
|
136 DoCmdGetFixedMsg(aSection); |
|
137 } |
|
138 else if ( aCommand==KCmdPckg ) |
|
139 { |
|
140 DoCmdPckg(); |
|
141 } |
|
142 else |
|
143 { |
|
144 ret=EFalse; |
|
145 } |
|
146 |
|
147 return ret; |
|
148 } |
|
149 |
|
150 |
|
151 void CT_DataWsGraphicMsgBuf::DoCmdnew() |
|
152 { |
|
153 DestroyData(); |
|
154 |
|
155 TRAPD(err, iWsGraphicMsgBuf = new (ELeave) RWsGraphicMsgBuf()); |
|
156 if(err != KErrNone) |
|
157 { |
|
158 ERR_PRINTF2(_L("**** RWsGraphicMsgBuf Constructor failed with error %d"), err); |
|
159 SetError(err); |
|
160 } |
|
161 |
|
162 INFO_PRINTF1(_L("RWsGraphicMsgBuf::RWsGraphicMsgBuf")); |
|
163 } |
|
164 |
|
165 void CT_DataWsGraphicMsgBuf::DoCmdClose() |
|
166 { |
|
167 iWsGraphicMsgBuf->Close(); |
|
168 INFO_PRINTF1(_L("RWsGraphicMsgBuf::Close")); |
|
169 } |
|
170 |
|
171 void CT_DataWsGraphicMsgBuf::DoCmdCleanupClosePushL() |
|
172 { |
|
173 iWsGraphicMsgBuf->CleanupClosePushL(); |
|
174 CleanupStack::PopAndDestroy(iWsGraphicMsgBuf); |
|
175 INFO_PRINTF1(_L("RWsGraphicMsgBuf::CleanupClosePushL")); |
|
176 } |
|
177 |
|
178 void CT_DataWsGraphicMsgBuf::DoCmdAppendL(const TDesC& aSection) |
|
179 { |
|
180 TInt err=KErrNone; |
|
181 TInt inputTypeId=0; |
|
182 if( GetIntFromConfig(aSection, KInputTypeId(), inputTypeId)) |
|
183 { |
|
184 TUid uid = TUid::Uid(inputTypeId); |
|
185 TPtrC inputStr; |
|
186 if( !GetStringFromConfig(aSection, KInputText(), inputStr) ) |
|
187 { |
|
188 ERR_PRINTF2(_L("Missing parameter %S"), &KInputText()); |
|
189 SetBlockResult(EFail); |
|
190 } |
|
191 else |
|
192 { |
|
193 TBool useBuf8=EFalse; |
|
194 GetBoolFromConfig(aSection, KInputUseText8(), useBuf8); |
|
195 if ( useBuf8 ) |
|
196 { |
|
197 TInt inputMsgLen=0; |
|
198 HBufC8* tempStr = HBufC8::NewLC(inputStr.Length()); |
|
199 tempStr->Des().Copy(inputStr); |
|
200 if( GetIntFromConfig(aSection, KInputMsgLen(), inputMsgLen)) |
|
201 { |
|
202 // Test iWsGraphicMsgBuf->Append(TUid aTypeId, TInt aLen, TPtr8 &aPtr); |
|
203 TPtr8 tempInputStr(tempStr->Des()); |
|
204 err = iWsGraphicMsgBuf->Append(uid, inputMsgLen, tempInputStr); |
|
205 INFO_PRINTF1(_L("RWsGraphicMsgBuf::Append (TPtr8)")); |
|
206 } |
|
207 else |
|
208 { |
|
209 // Test iWsGraphicMsgBuf->Append(TUid aTypeId, const TDesC8 &aData); |
|
210 err = iWsGraphicMsgBuf->Append(uid, *tempStr); |
|
211 INFO_PRINTF1(_L("RWsGraphicMsgBuf::Append (TDesC8)")); |
|
212 } |
|
213 CleanupStack::PopAndDestroy(tempStr); |
|
214 } |
|
215 else |
|
216 { |
|
217 // Test iWsGraphicMsgBuf->Append(TUid aTypeId, const TDesC16 &aData); |
|
218 err = iWsGraphicMsgBuf->Append(uid, inputStr); |
|
219 INFO_PRINTF1(_L("RWsGraphicMsgBuf::Append (TDesC16)")); |
|
220 } |
|
221 } |
|
222 } |
|
223 else |
|
224 { |
|
225 TWsGraphicFrameRate frameRate; |
|
226 err = iWsGraphicMsgBuf->Append(frameRate); |
|
227 INFO_PRINTF1(_L("RWsGraphicMsgBuf::Append (TWsGraphicMsgFixedBase)")); |
|
228 } |
|
229 |
|
230 if(err != KErrNone) |
|
231 { |
|
232 ERR_PRINTF2(_L("**** Append failed with error %d"), err); |
|
233 SetError(err); |
|
234 } |
|
235 } |
|
236 |
|
237 void CT_DataWsGraphicMsgBuf::DoCmdRemove(const TDesC& aSection) |
|
238 { |
|
239 TInt inputMsgPosition=0; |
|
240 if( GetIntFromConfig(aSection, KInputMsgPosition(), inputMsgPosition)) |
|
241 { |
|
242 iWsGraphicMsgBuf->Remove(inputMsgPosition); |
|
243 INFO_PRINTF1(_L("RWsGraphicMsgBuf::Remove")); |
|
244 } |
|
245 else |
|
246 { |
|
247 ERR_PRINTF2(_L("Missing parameter %S"), &KInputMsgPosition()); |
|
248 SetBlockResult(EFail); |
|
249 } |
|
250 } |
|
251 |
|
252 void CT_DataWsGraphicMsgBuf::DoCmdCount(const TDesC& aSection) |
|
253 { |
|
254 TInt actual = iWsGraphicMsgBuf->Count(); |
|
255 INFO_PRINTF2(_L("RWsGraphicMsgBuf::Count = %d"), actual); |
|
256 |
|
257 TInt expected = 0; |
|
258 if( GetIntFromConfig(aSection, KExpected(), expected)) |
|
259 { |
|
260 if( actual != expected ) |
|
261 { |
|
262 ERR_PRINTF1(_L("Count is not as expected!")); |
|
263 SetBlockResult(EFail); |
|
264 } |
|
265 } |
|
266 else |
|
267 { |
|
268 ERR_PRINTF2(_L("Missing parameter %S"), &KExpected()); |
|
269 SetBlockResult(EFail); |
|
270 } |
|
271 } |
|
272 |
|
273 void CT_DataWsGraphicMsgBuf::DoCmdTypeId(const TDesC& aSection) |
|
274 { |
|
275 TInt inputMsgPosition=0; |
|
276 if( GetIntFromConfig(aSection, KInputMsgPosition(), inputMsgPosition)) |
|
277 { |
|
278 TUid actual = iWsGraphicMsgBuf->TypeId(inputMsgPosition); |
|
279 INFO_PRINTF2(_L("RWsGraphicMsgBuf::TypeId = %d"), actual.iUid); |
|
280 |
|
281 TInt expected = 0; |
|
282 if( GetIntFromConfig(aSection, KExpected(), expected)) |
|
283 { |
|
284 TUid expectedUid = TUid::Uid(expected); |
|
285 |
|
286 if( actual != expectedUid ) |
|
287 { |
|
288 ERR_PRINTF1(_L("TypeId is not as expected!")); |
|
289 SetBlockResult(EFail); |
|
290 } |
|
291 } |
|
292 else |
|
293 { |
|
294 ERR_PRINTF2(_L("Missing parameter %S"), &KExpected()); |
|
295 SetBlockResult(EFail); |
|
296 } |
|
297 } |
|
298 else |
|
299 { |
|
300 ERR_PRINTF2(_L("Missing parameter %S"), &KInputMsgPosition()); |
|
301 SetBlockResult(EFail); |
|
302 } |
|
303 } |
|
304 |
|
305 void CT_DataWsGraphicMsgBuf::DoCmdDataL(const TDesC& aSection) |
|
306 { |
|
307 TInt inputMsgPosition=0; |
|
308 if( !GetIntFromConfig(aSection, KInputMsgPosition(), inputMsgPosition) ) |
|
309 { |
|
310 ERR_PRINTF2(_L("Missing parameter %S"), &KInputMsgPosition()); |
|
311 SetBlockResult(EFail); |
|
312 } |
|
313 else |
|
314 { |
|
315 TPtrC format; |
|
316 if( GetStringFromConfig(aSection, KInputFormat(), format) ) |
|
317 { |
|
318 // Test modifiable Data |
|
319 TPtr8 actual=iWsGraphicMsgBuf->Data(inputMsgPosition); |
|
320 HBufC* buffer=HBufC::NewLC(actual.Length()); |
|
321 TPtr bufferPtr=buffer->Des(); |
|
322 |
|
323 bufferPtr.Copy(actual); |
|
324 INFO_PRINTF1(_L("RWsGraphicMsgBuf::Data =")); |
|
325 INFO_PRINTF1(bufferPtr); |
|
326 bufferPtr.Format(format, &bufferPtr); |
|
327 actual.Copy(bufferPtr); |
|
328 CleanupStack::PopAndDestroy(buffer); |
|
329 } |
|
330 else |
|
331 { |
|
332 // Test non-modifiable Data |
|
333 const RWsGraphicMsgBuf* wsGraphicMsgBuf=iWsGraphicMsgBuf; |
|
334 TPtrC8 actual=wsGraphicMsgBuf->Data(inputMsgPosition); |
|
335 HBufC* buffer=HBufC::NewLC(actual.Length()); |
|
336 TPtr bufferPtr=buffer->Des(); |
|
337 |
|
338 bufferPtr.Copy(actual); |
|
339 INFO_PRINTF1(_L("RWsGraphicMsgBuf::Data =")); |
|
340 INFO_PRINTF1(bufferPtr); |
|
341 TPtrC expected; |
|
342 if( !GetStringFromConfig(aSection, KExpected(), expected) ) |
|
343 { |
|
344 ERR_PRINTF2(_L("Missing parameter %S"), &KInputMsgPosition()); |
|
345 SetBlockResult(EFail); |
|
346 } |
|
347 else |
|
348 { |
|
349 if( bufferPtr!=expected ) |
|
350 { |
|
351 ERR_PRINTF1(_L("Data is not as expected!")); |
|
352 SetBlockResult(EFail); |
|
353 } |
|
354 } |
|
355 CleanupStack::PopAndDestroy(buffer); |
|
356 } |
|
357 } |
|
358 } |
|
359 |
|
360 void CT_DataWsGraphicMsgBuf::DoCmdGetFixedMsg(const TDesC& aSection) |
|
361 { |
|
362 TInt inputMsgPosition=0; |
|
363 if( GetIntFromConfig(aSection, KInputMsgPosition(), inputMsgPosition)) |
|
364 { |
|
365 TWsGraphicFrameRate frameRate; |
|
366 iWsGraphicMsgBuf->GetFixedMsg(frameRate, inputMsgPosition); |
|
367 INFO_PRINTF1(_L("RWsGraphicMsgBuf::GetFixedMsg")); |
|
368 } |
|
369 else |
|
370 { |
|
371 ERR_PRINTF2(_L("Missing parameter %S"), &KInputMsgPosition()); |
|
372 SetBlockResult(EFail); |
|
373 } |
|
374 } |
|
375 |
|
376 void CT_DataWsGraphicMsgBuf::DoCmdPckg() |
|
377 { |
|
378 TBuf8<KMaxTestExecuteCommandLength> msg; |
|
379 msg = iWsGraphicMsgBuf->Pckg(); |
|
380 INFO_PRINTF1(_L("RWsGraphicMsgBuf::Pckg")); |
|
381 } |
|