author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 24 Nov 2009 08:56:33 +0200 | |
changeset 33 | 50974a8b132e |
parent 19 | 989d2f495d90 |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2006-2007 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 "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: ?Description |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
20 |
||
21 |
// INCLUDE FILES |
|
22 |
#include <e32svr.h> |
|
23 |
#include <StifParser.h> |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
24 |
#include <StifTestInterface.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
25 |
#include <liwservicehandler.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
26 |
#include <liwbufferextension.h> |
19 | 27 |
|
28 |
||
29 |
#include "tmediaprovidertest.h" |
|
30 |
#include "txmlconvertor.h" |
|
31 |
||
32 |
#include <f32file.h> |
|
33 |
#include <e32des16.h> |
|
34 |
#include <e32base.h> |
|
35 |
||
36 |
#include "tprovidertestobserver.h" |
|
37 |
#include "txmlconvertor.h" |
|
38 |
_LIT8(KErrorCode,"ErrorCode"); |
|
39 |
||
40 |
||
41 |
||
42 |
||
43 |
void CProviderTest::Delete() |
|
44 |
{ |
|
45 |
||
46 |
} |
|
47 |
||
48 |
// ----------------------------------------------------------------------------- |
|
49 |
// Csapi_getheader:RunMethodL |
|
50 |
// Run specified method. Contains also table of test mothods and their names. |
|
51 |
// ----------------------------------------------------------------------------- |
|
52 |
// |
|
53 |
TInt CProviderTest::RunMethodL( |
|
54 |
CStifItemParser& aItem ) |
|
55 |
{ |
|
56 |
||
57 |
static TStifFunctionInfo const KFunctions[] = |
|
58 |
{ |
|
59 |
||
60 |
ENTRY( "CheckInputArgumentType", CProviderTest::CheckInputArgumentType ), |
|
61 |
}; |
|
62 |
||
63 |
const TInt count = sizeof( KFunctions ) / |
|
64 |
sizeof( TStifFunctionInfo ); |
|
65 |
||
66 |
return RunInternalL( KFunctions, count, aItem ); |
|
67 |
||
68 |
} |
|
69 |
||
70 |
||
71 |
||
72 |
||
73 |
// ----------------------------------------------------------------------------- |
|
74 |
// CAppManagerTest:CheckInputArgumentType |
|
75 |
// |
|
76 |
// ----------------------------------------------------------------------------- |
|
77 |
// |
|
78 |
TInt CProviderTest::CheckInputArgumentType( CStifItemParser& aItem ) |
|
79 |
{ |
|
80 |
||
81 |
__UHEAP_MARK; |
|
82 |
TPtrC16 serice16; |
|
83 |
TPtrC16 Interface16; |
|
84 |
TPtrC16 command16; |
|
85 |
TInt servicecmdpptions; |
|
86 |
TPtrC16 callback; |
|
87 |
||
88 |
TInt expected; |
|
89 |
TInt err; |
|
90 |
CProviderObserver* callbackobj = NULL; |
|
91 |
||
92 |
TInt result =KErrNone ;// KErrGeneral; // 0 means pass and -1 means Fail |
|
93 |
||
94 |
aItem.GetNextString(serice16); |
|
95 |
aItem.GetNextString(Interface16); |
|
96 |
aItem.GetNextString(command16); |
|
97 |
aItem.GetNextInt(servicecmdpptions); |
|
98 |
aItem.GetNextString(callback); |
|
99 |
||
100 |
||
101 |
||
102 |
||
103 |
iLog->Log(_L("read varibale ")); |
|
104 |
||
105 |
/*-------------------------------------------------------------------------------------------*/ |
|
106 |
||
107 |
||
108 |
CLiwServiceHandler* iServiceHandler = CLiwServiceHandler::NewL(); |
|
109 |
CleanupStack::PushL(iServiceHandler);//1 |
|
110 |
||
111 |
if ( iServiceHandler ) |
|
112 |
iLog->Log(_L("Got Service Handler ")); |
|
113 |
else |
|
114 |
iLog->Log(_L("Didn't get service handler")); |
|
115 |
||
116 |
||
117 |
//Take the Interface name and provider from cfg file |
|
118 |
TBuf8<30> interface8; |
|
119 |
TBuf8<30> service8; |
|
120 |
interface8.Copy(Interface16); |
|
121 |
service8.Copy(serice16); |
|
122 |
||
123 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1,interface8,service8); |
|
124 |
iLog->Log(_L("Create criterai Item")); |
|
125 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
126 |
CleanupStack::PushL(crit);//2 |
|
127 |
||
128 |
||
129 |
RCriteriaArray critArray; |
|
130 |
iLog->Log(_L("Append in Crit")); |
|
131 |
critArray.AppendL(crit); |
|
132 |
CleanupClosePushL(critArray);//3 |
|
133 |
||
134 |
iServiceHandler->AttachL(critArray); |
|
135 |
||
136 |
||
137 |
iLog->Log(_L("Creating Output")); |
|
138 |
CLiwGenericParamList* output = CLiwGenericParamList::NewL(); |
|
139 |
CleanupStack::PushL(output);//4 |
|
140 |
CLiwGenericParamList* input = CLiwGenericParamList::NewL(); |
|
141 |
CleanupStack::PushL(input);//5 |
|
142 |
||
143 |
iLog->Log(_L("call Service cmd L")); |
|
144 |
iServiceHandler->ExecuteServiceCmdL(*crit, *input, *output); |
|
145 |
||
146 |
iLog->Log(_L("Service cmdl is over")); |
|
147 |
||
148 |
// Create the Instance of SAPI class and the Input Param and output Param |
|
149 |
TInt pos = 0; |
|
150 |
MLiwInterface* Interface = NULL; |
|
151 |
output->FindFirst(pos,interface8 ); |
|
152 |
if(pos != KErrNotFound) |
|
153 |
{ |
|
154 |
Interface = (*output)[pos].Value().AsInterface(); |
|
155 |
} |
|
156 |
output->Reset(); |
|
157 |
||
158 |
CleanupClosePushL(*Interface);//6 |
|
159 |
iLog->Log(_L("got Interface")); |
|
160 |
input->Reset(); |
|
161 |
||
162 |
||
163 |
if (FillInputParmaeterList( aItem, input) == KErrNone ) |
|
164 |
{ |
|
165 |
//Call Service |
|
166 |
PrintInputParameterList(input); |
|
167 |
TBuf8<30> command8; |
|
168 |
command8.Copy(command16); |
|
169 |
||
170 |
if(callback.CompareF(_L("NULL"))==0) |
|
171 |
{ |
|
172 |
//without call back |
|
173 |
Interface->ExecuteCmdL(command8,*input,*output,servicecmdpptions, NULL); |
|
174 |
||
175 |
} |
|
176 |
else |
|
177 |
||
178 |
{ |
|
179 |
//need to change the observer |
|
180 |
callbackobj = CProviderObserver::NewL(); |
|
181 |
if(callback.CompareF(_L("LeavingCallBack"))==0) |
|
182 |
{ |
|
183 |
callbackobj->needtoleave = ETrue; |
|
184 |
} |
|
185 |
||
186 |
||
187 |
||
188 |
//CleanupStack::PushL( callbackobj); |
|
189 |
Interface->ExecuteCmdL(command8,*input,*output,servicecmdpptions, callbackobj); |
|
190 |
//CleanupStack::PopAndDestroy( ); |
|
191 |
} |
|
192 |
||
193 |
aItem.GetNextInt(expected); |
|
194 |
const TLiwGenericParam* p= NULL; |
|
195 |
p = output->FindFirst(pos, KErrorCode); // Finding Error Code |
|
196 |
if(p) |
|
197 |
{ |
|
198 |
err = p->Value().AsTInt32(); |
|
199 |
||
200 |
if(err == 0 ) |
|
201 |
{ |
|
202 |
// Requested Accepted by the provider |
|
203 |
if( (callback != NULL) && (KLiwOptASyncronous == servicecmdpptions) ) |
|
204 |
{ |
|
205 |
// need to wait for callback |
|
206 |
CActiveSchedulerWait* wait = new CActiveSchedulerWait(); |
|
207 |
CleanupStack::PushL( wait); |
|
208 |
callbackobj->SetWait( wait ); |
|
209 |
wait->Start(); |
|
210 |
CleanupStack::PopAndDestroy();//Active Wait Scheduler |
|
211 |
} |
|
212 |
||
213 |
} |
|
214 |
||
215 |
input->Reset(); |
|
216 |
output->Reset(); |
|
217 |
iLog->Log(_L("Got Error Code ")); |
|
218 |
||
219 |
if(expected != err) |
|
220 |
{ |
|
221 |
result = KErrGeneral; |
|
222 |
} |
|
223 |
} |
|
224 |
else |
|
225 |
result = KErrGeneral; |
|
226 |
} |
|
227 |
else |
|
228 |
{ |
|
229 |
//Input Parameter List is not properly entered in Cfg file |
|
230 |
PrintInputParameterList(input); |
|
231 |
result = KErrGeneral; |
|
232 |
} |
|
233 |
||
234 |
output->Reset(); |
|
235 |
input->Reset(); |
|
236 |
delete callbackobj; |
|
237 |
CleanupStack::PopAndDestroy( ); |
|
238 |
CleanupStack::PopAndDestroy( ); |
|
239 |
CleanupStack::PopAndDestroy( ); |
|
240 |
CleanupStack::PopAndDestroy( ); |
|
241 |
CleanupStack::PopAndDestroy( ); |
|
242 |
CleanupStack::PopAndDestroy( ); |
|
243 |
||
244 |
__UHEAP_MARKEND; |
|
245 |
return result; |
|
246 |
||
247 |
||
248 |
} |
|
249 |
||
250 |
||
251 |
||
252 |
||
253 |
||
254 |
||
255 |
TInt CProviderTest::FillInputParmaeterList( CStifItemParser& aItem , CLiwGenericParamList* input ) |
|
256 |
||
257 |
{ |
|
258 |
||
259 |
TInt intValue; |
|
260 |
TPtrC16 value16; |
|
261 |
TBuf8<40> value8; |
|
262 |
TLiwVariant value; |
|
263 |
TLiwGenericParam valueParam; |
|
264 |
TBuf8<40> next8 ; |
|
265 |
TPtrC next16; |
|
266 |
TPtrC16 dataType; |
|
267 |
||
268 |
aItem.GetNextString(next16); |
|
269 |
while( next16.CompareF(_L("Finish"))!= 0) |
|
270 |
{ |
|
271 |
aItem.GetNextString(dataType); |
|
272 |
||
273 |
//Convert variable name into 8 bit key |
|
274 |
if(next16.CompareF(_L("NULL"))== 0) |
|
275 |
next8.Copy(KNullDesC8); // For postion based |
|
276 |
else |
|
277 |
next8.Copy(next16); |
|
278 |
||
279 |
if(dataType.CompareF(_L("Int") )== 0) |
|
280 |
{ |
|
281 |
//Value should be Integer |
|
282 |
aItem.GetNextInt(intValue); |
|
283 |
value.SetL((TInt32)intValue); |
|
284 |
valueParam.SetNameAndValueL(next8, value); |
|
285 |
input->AppendL(valueParam); |
|
286 |
value.Reset(); |
|
287 |
valueParam.Reset(); |
|
288 |
} |
|
289 |
||
290 |
else if ( dataType.CompareF(_L("String") ) == 0) |
|
291 |
{ |
|
292 |
//Value should be 8 bit |
|
293 |
aItem.GetNextString(value16); |
|
294 |
value8.Copy(value16); |
|
295 |
value.SetL(value8); |
|
296 |
valueParam.SetNameAndValueL(next8, value); |
|
297 |
input->AppendL(valueParam); |
|
298 |
value.Reset(); |
|
299 |
valueParam.Reset(); |
|
300 |
} |
|
301 |
else if ( dataType.CompareF(_L("UnicodeString") ) == 0) |
|
302 |
{ |
|
303 |
//Value should be 16 bit string |
|
304 |
aItem.GetNextString(value16); |
|
305 |
value.SetL(value16); |
|
306 |
valueParam.SetNameAndValueL(next8, value); |
|
307 |
input->AppendL(valueParam); |
|
308 |
value.Reset(); |
|
309 |
valueParam.Reset(); |
|
310 |
} |
|
311 |
else if ( dataType.CompareF(_L("Map")) == 0) |
|
312 |
{ |
|
313 |
//Value should be map |
|
314 |
CLiwDefaultMap *map = CLiwDefaultMap::NewL(); |
|
315 |
value.SetL(map); |
|
316 |
valueParam.SetNameAndValueL(next8, value); |
|
317 |
input->AppendL(valueParam); |
|
318 |
map->DecRef(); |
|
319 |
value.Reset(); |
|
320 |
valueParam.Reset(); |
|
321 |
||
322 |
if( FillMap(aItem,map) !=KErrNone) |
|
323 |
return KErrGeneral; |
|
324 |
||
325 |
} |
|
326 |
else if ( dataType.CompareF(_L("List")) == 0) |
|
327 |
{ |
|
328 |
//Value should be map |
|
329 |
CLiwDefaultList *list = CLiwDefaultList::NewL(); |
|
330 |
value.SetL(list); |
|
331 |
valueParam.SetNameAndValueL(next8, value); |
|
332 |
input->AppendL(valueParam); |
|
333 |
list->DecRef(); |
|
334 |
value.Reset(); |
|
335 |
valueParam.Reset(); |
|
336 |
||
337 |
if( FillList(aItem,list) !=KErrNone) |
|
338 |
return KErrGeneral; |
|
339 |
} |
|
340 |
else |
|
341 |
{ |
|
342 |
return KErrGeneral; |
|
343 |
} |
|
344 |
aItem.GetNextString(next16); |
|
345 |
}//While loop |
|
346 |
||
347 |
||
348 |
return KErrNone; |
|
349 |
||
350 |
} |
|
351 |
||
352 |
||
353 |
||
354 |
||
355 |
||
356 |
TInt CProviderTest::FillMap( CStifItemParser& aItem , CLiwDefaultMap* aMap ) |
|
357 |
||
358 |
{ |
|
359 |
||
360 |
TInt intValue; |
|
361 |
TPtrC16 value16; |
|
362 |
TBuf8<40> value8; |
|
363 |
TLiwVariant value; |
|
364 |
TBuf8<40> next8 ; |
|
365 |
TPtrC next16; |
|
366 |
TPtrC16 dataType; |
|
367 |
||
368 |
aItem.GetNextString(next16); |
|
369 |
while( next16.CompareF(_L("End"))!= 0) |
|
370 |
{ |
|
371 |
aItem.GetNextString(dataType); |
|
372 |
//Convert variable name into 8 bit key |
|
373 |
next8.Copy(next16); |
|
374 |
||
375 |
if(dataType.CompareF(_L("Int") )== 0) |
|
376 |
{ |
|
377 |
//Value should be Integer |
|
378 |
aItem.GetNextInt(intValue); |
|
379 |
value.SetL((TInt32)intValue); |
|
380 |
aMap->InsertL(next8,value); |
|
381 |
value.Reset(); |
|
382 |
} |
|
383 |
||
384 |
else if ( dataType.CompareF(_L("String") ) == 0) |
|
385 |
{ |
|
386 |
//Value should be 8 bit |
|
387 |
aItem.GetNextString(value16); |
|
388 |
value8.Copy(value16); |
|
389 |
value.SetL(value8); |
|
390 |
aMap->InsertL(next8,value); |
|
391 |
value.Reset(); |
|
392 |
} |
|
393 |
else if ( dataType.CompareF(_L("UnicodeString") ) == 0) |
|
394 |
{ |
|
395 |
//Value should be 16 bit string |
|
396 |
aItem.GetNextString(value16); |
|
397 |
value.SetL(value16); |
|
398 |
aMap->InsertL(next8,value); |
|
399 |
value.Reset(); |
|
400 |
} |
|
401 |
else if ( dataType.CompareF(_L("Map")) == 0) |
|
402 |
{ |
|
403 |
//Value should be map |
|
404 |
CLiwDefaultMap *map = CLiwDefaultMap::NewL(); |
|
405 |
value.SetL(map); |
|
406 |
aMap->InsertL(next8,value); |
|
407 |
map->DecRef(); |
|
408 |
value.Reset(); |
|
409 |
||
410 |
if( FillMap(aItem,map) !=KErrNone) |
|
411 |
return KErrGeneral; |
|
412 |
||
413 |
} |
|
414 |
else if ( dataType.CompareF(_L("List")) == 0) |
|
415 |
{ |
|
416 |
//Value should be map |
|
417 |
CLiwDefaultList *list = CLiwDefaultList::NewL(); |
|
418 |
value.SetL(list); |
|
419 |
aMap->InsertL(next8,value); |
|
420 |
list->DecRef(); |
|
421 |
value.Reset(); |
|
422 |
||
423 |
if( FillList(aItem,list) !=KErrNone) |
|
424 |
return KErrGeneral; |
|
425 |
} |
|
426 |
else |
|
427 |
{ |
|
428 |
return KErrGeneral; |
|
429 |
} |
|
430 |
aItem.GetNextString(next16); |
|
431 |
}//While loop |
|
432 |
||
433 |
||
434 |
return KErrNone; |
|
435 |
||
436 |
} |
|
437 |
||
438 |
||
439 |
||
440 |
TInt CProviderTest::FillList( CStifItemParser& aItem , CLiwDefaultList* aList ) |
|
441 |
||
442 |
{ |
|
443 |
||
444 |
TInt intValue; |
|
445 |
TPtrC16 value16; |
|
446 |
TBuf8<40> value8; |
|
447 |
TLiwVariant value; |
|
448 |
TBuf8<40> next8 ; |
|
449 |
TPtrC next16; |
|
450 |
TPtrC16 dataType; |
|
451 |
||
452 |
aItem.GetNextString(dataType); |
|
453 |
while( dataType.CompareF(_L("End"))!= 0) |
|
454 |
{ |
|
455 |
//aItem.GetNextString(dataType); |
|
456 |
||
457 |
if(dataType.CompareF(_L("Int") )== 0) |
|
458 |
{ |
|
459 |
//Value should be Integer |
|
460 |
aItem.GetNextInt(intValue); |
|
461 |
value.SetL((TInt32)intValue); |
|
462 |
aList->AppendL(value); |
|
463 |
value.Reset(); |
|
464 |
} |
|
465 |
||
466 |
else if ( dataType.CompareF(_L("String") ) == 0) |
|
467 |
{ |
|
468 |
//Value should be 8 bit |
|
469 |
aItem.GetNextString(value16); |
|
470 |
value8.Copy(value16); |
|
471 |
value.SetL(value8); |
|
472 |
aList->AppendL(value); |
|
473 |
value.Reset(); |
|
474 |
} |
|
475 |
else if ( dataType.CompareF(_L("UnicodeString") ) == 0) |
|
476 |
{ |
|
477 |
//Value should be 16 bit string |
|
478 |
aItem.GetNextString(value16); |
|
479 |
value.SetL(value16); |
|
480 |
aList->AppendL(value); |
|
481 |
value.Reset(); |
|
482 |
} |
|
483 |
else if ( dataType.CompareF(_L("Map")) == 0) |
|
484 |
{ |
|
485 |
//Value should be map |
|
486 |
CLiwDefaultMap *map = CLiwDefaultMap::NewL(); |
|
487 |
value.SetL(map); |
|
488 |
aList->AppendL(value); |
|
489 |
map->DecRef(); |
|
490 |
value.Reset(); |
|
491 |
||
492 |
if( FillMap(aItem,map) !=KErrNone) |
|
493 |
return KErrGeneral; |
|
494 |
||
495 |
} |
|
496 |
else if ( dataType.CompareF(_L("List")) == 0) |
|
497 |
{ |
|
498 |
//Value should be List |
|
499 |
CLiwDefaultList *list = CLiwDefaultList::NewL(); |
|
500 |
value.SetL(list); |
|
501 |
aList->AppendL(value); |
|
502 |
list->DecRef(); |
|
503 |
value.Reset(); |
|
504 |
||
505 |
if( FillList(aItem,list) !=KErrNone) |
|
506 |
return KErrGeneral; |
|
507 |
||
508 |
} |
|
509 |
else |
|
510 |
{ |
|
511 |
return KErrGeneral; |
|
512 |
} |
|
513 |
aItem.GetNextString(dataType); |
|
514 |
}//While loop |
|
515 |
||
516 |
||
517 |
return KErrNone; |
|
518 |
||
519 |
} |
|
520 |
||
521 |
||
522 |
void CProviderTest::PrintInputParameterList( CLiwGenericParamList* input ) |
|
523 |
{ |
|
524 |
||
525 |
// Show the Input List |
|
526 |
RFs fs; |
|
527 |
RFile file; |
|
528 |
User::LeaveIfError(fs.Connect()); |
|
529 |
||
530 |
CleanupClosePushL(fs);//1 |
|
531 |
TInt errfile=0; |
|
532 |
TEntry entry; |
|
533 |
||
534 |
||
535 |
||
536 |
if( fs.Entry(_L("c:\\Data\\Provider\\"),entry) != KErrNone) |
|
537 |
{ |
|
538 |
TInt ret = fs.MkDir(_L("c:\\Data\\Provider\\")); |
|
539 |
} |
|
540 |
||
541 |
TBuf<100> flname(_L("c:\\Data\\Provider\\InputList.xml")); |
|
542 |
||
543 |
errfile =file.Replace(fs,flname, EFileWrite | EFileStreamText); |
|
544 |
CleanupClosePushL(file);//2 |
|
545 |
||
546 |
||
547 |
/*------------------------------------------------------------------------------*/ |
|
548 |
//Generate Xml file |
|
549 |
TPtrC filebuf; |
|
550 |
||
551 |
||
552 |
CXmlConvertor* convertor = CXmlConvertor::NewL(); |
|
553 |
CleanupStack::PushL(convertor); |
|
554 |
convertor->BuildOutputTreeL(*input,filebuf); |
|
555 |
||
556 |
HBufC8* heapBuffer = HBufC8::NewL(filebuf.Length()); |
|
557 |
TPtr8 filebuf8(heapBuffer->Des()); |
|
558 |
filebuf8.Copy(filebuf); |
|
559 |
||
560 |
file.Write(filebuf8); |
|
561 |
||
562 |
delete heapBuffer; |
|
563 |
CleanupStack::PopAndDestroy(); |
|
564 |
||
565 |
/*------------------------------------------------------------------------------*/ |
|
566 |
||
567 |
||
568 |
CleanupStack::PopAndDestroy();//File 1 |
|
569 |
CleanupStack::PopAndDestroy();//File Session 2 |
|
570 |
} |
|
571 |
||
572 |
||
573 |
||
574 |
||
575 |
||
576 |
//Output parameter processing |
|
577 |
||
578 |
// ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
579 |
// None |
|
580 |
||
581 |
// End of File |