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 "tprovidertest_vpbk.h" |
|
30 |
#include "txmlconvertor.h" |
|
31 |
||
32 |
#include <f32file.h> |
|
33 |
#include <e32des16.h> |
|
34 |
#include <e32base.h> |
|
35 |
||
36 |
#include "tprovidertest_vpbk_observer.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 |
||
182 |
if(callback.CompareF(_L("LeavingCallBack"))==0) |
|
183 |
{ |
|
184 |
callbackobj->needtoleave = ETrue; |
|
185 |
} |
|
186 |
||
187 |
||
188 |
||
189 |
//CleanupStack::PushL( callbackobj); |
|
190 |
Interface->ExecuteCmdL(command8,*input,*output,servicecmdpptions, callbackobj); |
|
191 |
//CleanupStack::PopAndDestroy( ); |
|
192 |
} |
|
193 |
||
194 |
aItem.GetNextInt(expected); |
|
195 |
const TLiwGenericParam* p= NULL; |
|
196 |
p = output->FindFirst(pos, KErrorCode); // Finding Error Code |
|
197 |
if(p) |
|
198 |
{ |
|
199 |
err = p->Value().AsTInt32(); |
|
200 |
||
201 |
if(err == 0 ) |
|
202 |
{ |
|
203 |
// Requested Accepted by the provider |
|
204 |
if( (callback != NULL) && (KLiwOptASyncronous == servicecmdpptions) ) |
|
205 |
{ |
|
206 |
// need to wait for callback |
|
207 |
CActiveSchedulerWait* wait = new CActiveSchedulerWait(); |
|
208 |
CleanupStack::PushL( wait); |
|
209 |
callbackobj->SetWait( wait ); |
|
210 |
wait->Start(); |
|
211 |
||
212 |
err = callbackobj->iErrorReturn; |
|
213 |
CleanupStack::PopAndDestroy();//Active Wait Scheduler |
|
214 |
} |
|
215 |
||
216 |
} |
|
217 |
||
218 |
||
219 |
iLog->Log(_L("Got Error Code ")); |
|
220 |
||
221 |
if(expected != err) |
|
222 |
{ |
|
223 |
result = KErrGeneral; |
|
224 |
} |
|
225 |
} |
|
226 |
else |
|
227 |
result = KErrGeneral; |
|
228 |
} |
|
229 |
else |
|
230 |
{ |
|
231 |
//Input Parameter List is not properly entered in Cfg file |
|
232 |
PrintInputParameterList(input); |
|
233 |
result = KErrGeneral; |
|
234 |
} |
|
235 |
||
236 |
output->Reset(); |
|
237 |
input->Reset(); |
|
238 |
delete callbackobj; |
|
239 |
CleanupStack::PopAndDestroy( ); |
|
240 |
CleanupStack::PopAndDestroy( ); |
|
241 |
CleanupStack::PopAndDestroy( ); |
|
242 |
CleanupStack::PopAndDestroy( ); |
|
243 |
CleanupStack::PopAndDestroy( ); |
|
244 |
CleanupStack::PopAndDestroy( ); |
|
245 |
||
246 |
//__UHEAP_MARKEND; |
|
247 |
return result; |
|
248 |
||
249 |
||
250 |
} |
|
251 |
||
252 |
||
253 |
TInt CProviderTest::FillInputParmaeterList( CStifItemParser& aItem , CLiwGenericParamList* input ) |
|
254 |
||
255 |
{ |
|
256 |
||
257 |
TInt intValue; |
|
258 |
TPtrC16 value16; |
|
259 |
TBuf8<40> value8; |
|
260 |
TLiwVariant value; |
|
261 |
TLiwGenericParam valueParam; |
|
262 |
TBuf8<40> next8 ; |
|
263 |
TPtrC next16; |
|
264 |
TPtrC16 dataType; |
|
265 |
||
266 |
aItem.GetNextString(next16); |
|
267 |
while( next16.CompareF(_L("Finish"))!= 0) |
|
268 |
{ |
|
269 |
aItem.GetNextString(dataType); |
|
270 |
||
271 |
//Convert variable name into 8 bit key |
|
272 |
if(next16.CompareF(_L("NULL"))== 0) |
|
273 |
next8.Copy(KNullDesC8); // For postion based |
|
274 |
else |
|
275 |
next8.Copy(next16); |
|
276 |
||
277 |
if(dataType.CompareF(_L("Int") )== 0) |
|
278 |
{ |
|
279 |
//Value should be Integer |
|
280 |
aItem.GetNextInt(intValue); |
|
281 |
value.SetL((TInt32)intValue); |
|
282 |
valueParam.SetNameAndValueL(next8, value); |
|
283 |
input->AppendL(valueParam); |
|
284 |
} |
|
285 |
||
286 |
else if ( dataType.CompareF(_L("String") ) == 0) |
|
287 |
{ |
|
288 |
//Value should be 8 bit |
|
289 |
aItem.GetNextString(value16); |
|
290 |
value8.Copy(value16); |
|
291 |
value.SetL(value8); |
|
292 |
valueParam.SetNameAndValueL(next8, value); |
|
293 |
input->AppendL(valueParam); |
|
294 |
} |
|
295 |
else if ( dataType.CompareF(_L("UnicodeString") ) == 0) |
|
296 |
{ |
|
297 |
//Value should be 16 bit string |
|
298 |
aItem.GetNextString(value16); |
|
299 |
value.SetL(value16); |
|
300 |
valueParam.SetNameAndValueL(next8, value); |
|
301 |
input->AppendL(valueParam); |
|
302 |
} |
|
303 |
else if ( dataType.CompareF(_L("Map")) == 0) |
|
304 |
{ |
|
305 |
//Value should be map |
|
306 |
CLiwDefaultMap *map = CLiwDefaultMap::NewL(); |
|
307 |
value.SetL(map); |
|
308 |
valueParam.SetNameAndValueL(next8, value); |
|
309 |
input->AppendL(valueParam); |
|
310 |
map->DecRef(); |
|
311 |
||
312 |
if( FillMap(aItem,map) !=KErrNone) |
|
313 |
return KErrGeneral; |
|
314 |
||
315 |
} |
|
316 |
else if ( dataType.CompareF(_L("List")) == 0) |
|
317 |
{ |
|
318 |
//Value should be map |
|
319 |
CLiwDefaultList *list = CLiwDefaultList::NewL(); |
|
320 |
value.SetL(list); |
|
321 |
valueParam.SetNameAndValueL(next8, value); |
|
322 |
input->AppendL(valueParam); |
|
323 |
list->DecRef(); |
|
324 |
||
325 |
if( FillList(aItem,list) !=KErrNone) |
|
326 |
return KErrGeneral; |
|
327 |
} |
|
328 |
else |
|
329 |
{ |
|
330 |
return KErrGeneral; |
|
331 |
} |
|
332 |
valueParam.Reset(); |
|
333 |
value.Reset(); |
|
334 |
aItem.GetNextString(next16); |
|
335 |
}//While loop |
|
336 |
||
337 |
||
338 |
return KErrNone; |
|
339 |
||
340 |
} |
|
341 |
||
342 |
||
343 |
||
344 |
||
345 |
||
346 |
TInt CProviderTest::FillMap( CStifItemParser& aItem , CLiwDefaultMap* aMap ) |
|
347 |
||
348 |
{ |
|
349 |
||
350 |
TInt intValue; |
|
351 |
TPtrC16 value16; |
|
352 |
TBuf8<40> value8; |
|
353 |
TLiwVariant value; |
|
354 |
TBuf8<40> next8 ; |
|
355 |
TPtrC next16; |
|
356 |
TPtrC16 dataType; |
|
357 |
||
358 |
aItem.GetNextString(next16); |
|
359 |
while( next16.CompareF(_L("End"))!= 0) |
|
360 |
{ |
|
361 |
aItem.GetNextString(dataType); |
|
362 |
//Convert variable name into 8 bit key |
|
363 |
next8.Copy(next16); |
|
364 |
||
365 |
if(dataType.CompareF(_L("Int") )== 0) |
|
366 |
{ |
|
367 |
//Value should be Integer |
|
368 |
aItem.GetNextInt(intValue); |
|
369 |
value.SetL((TInt32)intValue); |
|
370 |
aMap->InsertL(next8,value); |
|
371 |
} |
|
372 |
||
373 |
else if ( dataType.CompareF(_L("String") ) == 0) |
|
374 |
{ |
|
375 |
//Value should be 8 bit |
|
376 |
aItem.GetNextString(value16); |
|
377 |
value8.Copy(value16); |
|
378 |
value.SetL(value8); |
|
379 |
aMap->InsertL(next8,value); |
|
380 |
} |
|
381 |
else if ( dataType.CompareF(_L("UnicodeString") ) == 0) |
|
382 |
{ |
|
383 |
//Value should be 16 bit string |
|
384 |
aItem.GetNextString(value16); |
|
385 |
value.SetL(value16); |
|
386 |
aMap->InsertL(next8,value); |
|
387 |
} |
|
388 |
else if ( dataType.CompareF(_L("Map")) == 0) |
|
389 |
{ |
|
390 |
//Value should be map |
|
391 |
CLiwDefaultMap *map = CLiwDefaultMap::NewL(); |
|
392 |
value.SetL(map); |
|
393 |
aMap->InsertL(next8,value); |
|
394 |
map->DecRef(); |
|
395 |
||
396 |
if( FillMap(aItem,map) !=KErrNone) |
|
397 |
return KErrGeneral; |
|
398 |
||
399 |
} |
|
400 |
else if ( (dataType.CompareF(_L("List")) == 0)||dataType.CompareF(_L("IdList")) == 0) |
|
401 |
{ |
|
402 |
//Value should be map |
|
403 |
CLiwDefaultList *list = CLiwDefaultList::NewL(); |
|
404 |
value.SetL(list); |
|
405 |
aMap->InsertL(next8,value); |
|
406 |
list->DecRef(); |
|
407 |
||
408 |
if( FillList(aItem,list) !=KErrNone) |
|
409 |
return KErrGeneral; |
|
410 |
} |
|
411 |
else |
|
412 |
{ |
|
413 |
return KErrGeneral; |
|
414 |
} |
|
415 |
value.Reset(); |
|
416 |
aItem.GetNextString(next16); |
|
417 |
}//While loop |
|
418 |
||
419 |
||
420 |
return KErrNone; |
|
421 |
||
422 |
} |
|
423 |
||
424 |
||
425 |
||
426 |
TInt CProviderTest::FillList( CStifItemParser& aItem , CLiwDefaultList* aList ) |
|
427 |
||
428 |
{ |
|
429 |
||
430 |
TInt intValue; |
|
431 |
TPtrC16 value16; |
|
432 |
TBuf8<40> value8; |
|
433 |
TLiwVariant value; |
|
434 |
TBuf8<40> next8 ; |
|
435 |
TPtrC next16; |
|
436 |
TPtrC16 dataType; |
|
437 |
||
438 |
aItem.GetNextString(dataType); |
|
439 |
while( dataType.CompareF(_L("End"))!= 0) |
|
440 |
{ |
|
441 |
//aItem.GetNextString(dataType); |
|
442 |
||
443 |
if(dataType.CompareF(_L("Int") )== 0) |
|
444 |
{ |
|
445 |
//Value should be Integer |
|
446 |
aItem.GetNextInt(intValue); |
|
447 |
value.SetL((TInt32)intValue); |
|
448 |
aList->AppendL(value); |
|
449 |
} |
|
450 |
||
451 |
else if ( dataType.CompareF(_L("String") ) == 0) |
|
452 |
{ |
|
453 |
//Value should be 8 bit |
|
454 |
aItem.GetNextString(value16); |
|
455 |
value8.Copy(value16); |
|
456 |
value.SetL(value8); |
|
457 |
aList->AppendL(value); |
|
458 |
} |
|
459 |
else if ( dataType.CompareF(_L("UnicodeString") ) == 0) |
|
460 |
{ |
|
461 |
//Value should be 16 bit string |
|
462 |
aItem.GetNextString(value16); |
|
463 |
value.SetL(value16); |
|
464 |
aList->AppendL(value); |
|
465 |
} |
|
466 |
else if ( dataType.CompareF(_L("Map")) == 0) |
|
467 |
{ |
|
468 |
//Value should be map |
|
469 |
CLiwDefaultMap *map = CLiwDefaultMap::NewL(); |
|
470 |
value.SetL(map); |
|
471 |
aList->AppendL(value); |
|
472 |
map->DecRef(); |
|
473 |
||
474 |
if( FillMap(aItem,map) !=KErrNone) |
|
475 |
return KErrGeneral; |
|
476 |
||
477 |
} |
|
478 |
else if ( dataType.CompareF(_L("List")) == 0) |
|
479 |
{ |
|
480 |
//Value should be List |
|
481 |
CLiwDefaultList *list = CLiwDefaultList::NewL(); |
|
482 |
value.SetL(list); |
|
483 |
aList->AppendL(value); |
|
484 |
list->DecRef(); |
|
485 |
||
486 |
if( FillList(aItem,list) !=KErrNone) |
|
487 |
return KErrGeneral; |
|
488 |
||
489 |
} |
|
490 |
else |
|
491 |
{ |
|
492 |
return KErrGeneral; |
|
493 |
} |
|
494 |
value.Reset(); |
|
495 |
aItem.GetNextString(dataType); |
|
496 |
}//While loop |
|
497 |
||
498 |
||
499 |
return KErrNone; |
|
500 |
||
501 |
} |
|
502 |
||
503 |
||
504 |
void CProviderTest::PrintInputParameterList( CLiwGenericParamList* input ) |
|
505 |
{ |
|
506 |
||
507 |
// Show the Input List |
|
508 |
RFs fs; |
|
509 |
RFile file; |
|
510 |
User::LeaveIfError(fs.Connect()); |
|
511 |
||
512 |
CleanupClosePushL(fs);//1 |
|
513 |
TInt errfile=0; |
|
514 |
TEntry entry; |
|
515 |
||
516 |
||
517 |
||
518 |
if( fs.Entry(_L("c:\\Data\\Provider\\"),entry) != KErrNone) |
|
519 |
{ |
|
520 |
TInt ret = fs.MkDir(_L("c:\\Data\\Provider\\")); |
|
521 |
} |
|
522 |
||
523 |
TBuf<100> flname(_L("c:\\Data\\Provider\\InputList.xml")); |
|
524 |
||
525 |
errfile =file.Replace(fs,flname, EFileWrite | EFileStreamText); |
|
526 |
CleanupClosePushL(file);//2 |
|
527 |
||
528 |
||
529 |
/*------------------------------------------------------------------------------*/ |
|
530 |
//Generate Xml file |
|
531 |
TPtrC filebuf; |
|
532 |
||
533 |
||
534 |
CXmlConvertor* convertor = CXmlConvertor::NewL(); |
|
535 |
CleanupStack::PushL(convertor); |
|
536 |
convertor->BuildOutputTreeL(*input,filebuf); |
|
537 |
||
538 |
HBufC8* heapBuffer = HBufC8::NewL(filebuf.Length()); |
|
539 |
TPtr8 filebuf8(heapBuffer->Des()); |
|
540 |
filebuf8.Copy(filebuf); |
|
541 |
||
542 |
file.Write(filebuf8); |
|
543 |
||
544 |
delete heapBuffer; |
|
545 |
CleanupStack::PopAndDestroy(); |
|
546 |
||
547 |
/*------------------------------------------------------------------------------*/ |
|
548 |
||
549 |
||
550 |
CleanupStack::PopAndDestroy();//File 1 |
|
551 |
CleanupStack::PopAndDestroy();//File Session 2 |
|
552 |
} |
|
553 |
||
554 |
||
555 |
||
556 |
||
557 |
||
558 |
//Output parameter processing |
|
559 |
||
560 |
// ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
561 |
// None |
|
562 |
||
563 |
// End of File |