|
1 /* |
|
2 * Copyright (c) 2002 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32svr.h> |
|
22 #include <StifParser.h> |
|
23 #include <Stiftestinterface.h> |
|
24 #include "TestHspApi.h" |
|
25 #include <hswidgetpublisher.h> |
|
26 #include <hswidget.h> |
|
27 #include <hsdataobserver.h> |
|
28 #include <liwservicehandler.h> |
|
29 #include <liwvariant.h> |
|
30 #include <liwgenericparam.h> |
|
31 #include <liwcommon.h> |
|
32 #include "waitactive.h" |
|
33 #include <hsexception.h> |
|
34 |
|
35 _LIT8( KResults, "results" ); |
|
36 |
|
37 _LIT8( KType, "type" ); |
|
38 _LIT( KCpData, "cp_data" ); |
|
39 _LIT8( KContentIdFormat, "%s:%s"); |
|
40 _LIT8( KPublisherId, "publisher" ); |
|
41 _LIT8( KContentType, "content_type" ); |
|
42 _LIT8( KContentId, "content_id" ); |
|
43 _LIT( KHsPublisher, "ai3templatedwidget" ); |
|
44 _LIT( KHsWidgetPublisher, "hswidgetpublisher"); |
|
45 _LIT( KAll, "all" ); |
|
46 _LIT8( KFilter, "filter" ); |
|
47 _LIT( KContentAndPublisher_Registry, "cp_data:publisher"); |
|
48 _LIT8( KRequestNotification, "RequestNotification" ); |
|
49 _LIT( KPublisher, "publisher" ); |
|
50 _LIT8( KActionTrigger, "action_trigger" ); |
|
51 _LIT8( KCPService, "Service.ContentPublishing" ); |
|
52 _LIT8( KActive, "active"); |
|
53 _LIT8( KSelected, "selected"); |
|
54 _LIT( KFakeContentId, "616" ); |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 LOCAL_C HBufC* StdStringTo16bitDescLC( const std::string& aSrcString ) |
|
61 { |
|
62 TPtrC8 srcDescriptor = (TUint8*) aSrcString.c_str(); |
|
63 HBufC* dstDescriptor = HBufC::NewLC( srcDescriptor.Length() ); |
|
64 dstDescriptor->Des().Copy( srcDescriptor ); |
|
65 return dstDescriptor; |
|
66 } |
|
67 |
|
68 // ============================ MEMBER FUNCTIONS =============================== |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CTestHspApi::Delete |
|
72 // Delete here all resources allocated and opened from test methods. |
|
73 // Called from destructor. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CTestHspApi::Delete() |
|
77 { |
|
78 mServiceInterface->Close(); |
|
79 delete mServiceHandler; |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CTestHspApi::RunMethodL |
|
84 // Run specified method. Contains also table of test mothods and their names. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 TInt CTestHspApi::RunMethodL( |
|
88 CStifItemParser& aItem ) |
|
89 { |
|
90 |
|
91 static TStifFunctionInfo const KFunctions[] = |
|
92 { |
|
93 // Copy this line for every implemented function. |
|
94 // First string is the function name used in TestScripter script file. |
|
95 // Second is the actual implementation member function. |
|
96 ENTRY( "TestHspApiConstrL", CTestHspApi::TestHspApiConstrL ), |
|
97 ENTRY( "TestHspWidgetAddWidgetItem1L", CTestHspApi::TestHspWidgetAddWidgetItem1L ), |
|
98 ENTRY( "TestHspWidgetAddWidgetItem2L", CTestHspApi::TestHspWidgetAddWidgetItem2L ), |
|
99 ENTRY( "TestHspWidgetAddWidgetItem3L", CTestHspApi::TestHspWidgetAddWidgetItem3L ), |
|
100 ENTRY( "TestHspApiDeleteWidgetL", CTestHspApi::TestHspApiDeleteWidgetL ), |
|
101 ENTRY( "TestHspApiSetDataObserver1L", CTestHspApi::TestHspApiSetDataObserver1L ), |
|
102 ENTRY( "TestHspApiSetDataObserver2L", CTestHspApi::TestHspApiSetDataObserver2L ), |
|
103 ENTRY( "TestHspApiGetWidgetL", CTestHspApi::TestHspApiGetWidgetL ), |
|
104 ENTRY( "TestHspApiWidgetRemoveItem1L", CTestHspApi::TestHspApiWidgetRemoveItem1L ), |
|
105 ENTRY( "TestHspApiWidgetRemoveItem2L", CTestHspApi::TestHspApiWidgetRemoveItem2L ), |
|
106 ENTRY( "TestHspApiExceptionL", CTestHspApi::TestHspApiExceptionL ), |
|
107 }; |
|
108 |
|
109 const TInt count = sizeof( KFunctions ) / |
|
110 sizeof( TStifFunctionInfo ); |
|
111 |
|
112 return RunInternalL( KFunctions, count, aItem ); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 TInt CTestHspApi::ExtractItemCountL( |
|
120 const CLiwGenericParamList& aInParamList ) |
|
121 { |
|
122 TInt result( KErrNotFound ); |
|
123 TInt count (0); |
|
124 TInt pos( 0 ); |
|
125 aInParamList.FindFirst( pos, KResults ); |
|
126 if( pos != KErrNotFound ) |
|
127 // results present - extract and return text |
|
128 { |
|
129 TLiwVariant variant = aInParamList[pos].Value(); |
|
130 CLiwIterable* iterable = variant.AsIterable(); |
|
131 iterable->Reset(); |
|
132 |
|
133 while(iterable->NextL( variant )) |
|
134 { |
|
135 count++; |
|
136 } |
|
137 |
|
138 iterable->Reset(); |
|
139 variant.Reset(); |
|
140 |
|
141 result = count; |
|
142 } |
|
143 |
|
144 return result; |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 TInt CTestHspApi::ExtractItemL( const CLiwGenericParamList& aInParamList, |
|
152 const TDesC8& aItemName, RBuf& aItemValue ) |
|
153 { |
|
154 TInt result( KErrNotFound ); |
|
155 TInt count (0); |
|
156 TInt pos( 0 ); |
|
157 aInParamList.FindFirst( pos, KResults ); |
|
158 if( pos != KErrNotFound ) |
|
159 // results present - extract and return text |
|
160 { |
|
161 TLiwVariant variant = aInParamList[pos].Value(); |
|
162 CLiwIterable* iterable = variant.AsIterable(); |
|
163 |
|
164 TLiwVariant item; |
|
165 while ( iterable->NextL( item ) ) |
|
166 { |
|
167 CLiwDefaultMap *map = CLiwDefaultMap::NewLC(); |
|
168 item.Get( *map ); |
|
169 TLiwVariant dataMapVariant; |
|
170 TBool found = map->FindL( _L8("data_map"), dataMapVariant ); |
|
171 if ( found ) |
|
172 { |
|
173 CLiwDefaultMap *dataMap = CLiwDefaultMap::NewLC(); |
|
174 dataMapVariant.Get( *dataMap ); |
|
175 TLiwVariant item1; |
|
176 found = dataMap->FindL( aItemName, item1 ); |
|
177 if ( found ) |
|
178 { |
|
179 TPtrC ptr; |
|
180 item1.Get( ptr ); |
|
181 aItemValue.Create( ptr ); |
|
182 result = KErrNone; |
|
183 } |
|
184 item1.Reset(); |
|
185 dataMapVariant.Reset(); |
|
186 CleanupStack::PopAndDestroy( dataMap ); |
|
187 } |
|
188 CleanupStack::PopAndDestroy( map ); |
|
189 } |
|
190 |
|
191 iterable->Reset(); |
|
192 variant.Reset(); |
|
193 } |
|
194 |
|
195 return result; |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 CLiwGenericParamList* CTestHspApi::GetListL( std::string& aContentType, |
|
203 std::string& aIdentifier, std::string& aWidgetName ) |
|
204 { |
|
205 TBool res( EFalse ); |
|
206 |
|
207 CLiwGenericParamList* inParam = &(mServiceHandler->InParamListL()); |
|
208 CLiwGenericParamList* outParam = &(mServiceHandler->OutParamListL()); |
|
209 |
|
210 TLiwGenericParam type(KType, TLiwVariant(KCpData)); |
|
211 inParam->AppendL(type); |
|
212 CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC(); |
|
213 |
|
214 TPtrC8 contentType = ((TUint8*)aContentType.c_str()); |
|
215 |
|
216 const TInt KSAPIContentNameMaxLength = 255; |
|
217 |
|
218 TBuf8<KSAPIContentNameMaxLength> contentId; |
|
219 contentId = (TUint8*)aIdentifier.c_str(); |
|
220 |
|
221 HBufC* publisherName = StdStringTo16bitDescLC( aIdentifier + ":hswidgetpublisher" ); |
|
222 cpdatamap->InsertL( KPublisherId, TLiwVariant( *publisherName )); |
|
223 cpdatamap->InsertL( KContentType, TLiwVariant( KAll )); |
|
224 cpdatamap->InsertL( KContentId, TLiwVariant( KFakeContentId )); |
|
225 |
|
226 TLiwGenericParam filter( KFilter, TLiwVariant( cpdatamap )); |
|
227 inParam->AppendL( filter ); |
|
228 mServiceInterface->ExecuteCmdL( _L8("GetList"), |
|
229 *inParam, *outParam); |
|
230 |
|
231 CleanupStack::PopAndDestroy( publisherName ); |
|
232 CleanupStack::PopAndDestroy( cpdatamap ); |
|
233 |
|
234 filter.Reset(); |
|
235 type.Reset(); |
|
236 |
|
237 inParam->Reset(); |
|
238 |
|
239 return outParam; |
|
240 } |
|
241 |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 TInt CTestHspApi::HandleNotifyL( |
|
248 TInt /*aCmdId*/, |
|
249 TInt /*aEventId*/, |
|
250 CLiwGenericParamList& aEventParamList, |
|
251 const CLiwGenericParamList& /*aInParamList*/) |
|
252 { |
|
253 iActionStatus = KErrNone; |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 CLiwGenericParamList* CTestHspApi::ExecuteActionL( std::string& aContentType, |
|
261 std::string& aIdentifier, std::string& aWidgetName ) |
|
262 { |
|
263 TBool res( EFalse ); |
|
264 |
|
265 // ---------------------------- |
|
266 // register for notification |
|
267 // ---------------------------- |
|
268 |
|
269 CLiwGenericParamList* inParam = &(mServiceHandler->InParamListL()); |
|
270 CLiwGenericParamList* outParam = &(mServiceHandler->OutParamListL()); |
|
271 CLiwDefaultMap* reqFilter = CLiwDefaultMap::NewLC(); |
|
272 |
|
273 //reqFilter->InsertL( KPublisherId, TLiwVariant( KHSPPublisher )); |
|
274 reqFilter->InsertL( KPublisherId, TLiwVariant( KAll )); |
|
275 reqFilter->InsertL( KContentType, TLiwVariant( KAll )); |
|
276 reqFilter->InsertL( KContentId, TLiwVariant( KAll )); |
|
277 //reqFilter->InsertL( KOperation, TLiwVariant( KOperationExecute )); |
|
278 |
|
279 inParam->AppendL(TLiwGenericParam(KType, TLiwVariant(KContentAndPublisher_Registry))); |
|
280 inParam->AppendL(TLiwGenericParam(KFilter, TLiwVariant(reqFilter))); |
|
281 |
|
282 mServiceInterface->ExecuteCmdL( KRequestNotification, |
|
283 *inParam, *outParam, 0, this ); |
|
284 |
|
285 outParam->Reset(); |
|
286 inParam->Reset(); |
|
287 CleanupStack::PopAndDestroy( reqFilter ); |
|
288 |
|
289 // -------------- |
|
290 // execute action |
|
291 // -------------- |
|
292 |
|
293 TLiwGenericParam type(KType, TLiwVariant(KPublisher)); |
|
294 inParam->AppendL(type); |
|
295 CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC(); |
|
296 |
|
297 TPtrC8 contentType = ((TUint8*)aContentType.c_str()); |
|
298 |
|
299 const TInt KSAPIContentNameMaxLength = 255; |
|
300 |
|
301 TBuf8<KSAPIContentNameMaxLength> contentId; |
|
302 contentId = (TUint8*)aIdentifier.c_str(); |
|
303 |
|
304 cpdatamap->InsertL( KPublisherId, TLiwVariant( KHsWidgetPublisher )); |
|
305 cpdatamap->InsertL( KContentType, TLiwVariant( KHsPublisher )); |
|
306 cpdatamap->InsertL( KContentId, TLiwVariant( contentId )); |
|
307 cpdatamap->InsertL( KActionTrigger, TLiwVariant( KActive )); |
|
308 |
|
309 TLiwGenericParam filter( KFilter, TLiwVariant( cpdatamap )); |
|
310 inParam->AppendL( filter ); |
|
311 mServiceInterface->ExecuteCmdL( _L8("ExecuteAction"), |
|
312 *inParam, *outParam ); |
|
313 |
|
314 CleanupStack::PopAndDestroy( cpdatamap ); |
|
315 |
|
316 filter.Reset(); |
|
317 type.Reset(); |
|
318 |
|
319 inParam->Reset(); |
|
320 |
|
321 return outParam; |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------------------------- |
|
325 // |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 CLiwGenericParamList* CTestHspApi::ExecuteActionSelectedL( std::string& aContentType, |
|
329 std::string& aIdentifier, std::string& aWidgetName ) |
|
330 { |
|
331 TBool res( EFalse ); |
|
332 |
|
333 // ---------------------------- |
|
334 // register for notification |
|
335 // ---------------------------- |
|
336 |
|
337 CLiwGenericParamList* inParam = &(mServiceHandler->InParamListL()); |
|
338 CLiwGenericParamList* outParam = &(mServiceHandler->OutParamListL()); |
|
339 CLiwDefaultMap* reqFilter = CLiwDefaultMap::NewLC(); |
|
340 |
|
341 //reqFilter->InsertL( KPublisherId, TLiwVariant( KHSPPublisher )); |
|
342 reqFilter->InsertL( KPublisherId, TLiwVariant( KAll )); |
|
343 reqFilter->InsertL( KContentType, TLiwVariant( KAll )); |
|
344 reqFilter->InsertL( KContentId, TLiwVariant( KAll )); |
|
345 //reqFilter->InsertL( KOperation, TLiwVariant( KOperationExecute )); |
|
346 |
|
347 inParam->AppendL(TLiwGenericParam(KType, TLiwVariant(KContentAndPublisher_Registry))); |
|
348 inParam->AppendL(TLiwGenericParam(KFilter, TLiwVariant(reqFilter))); |
|
349 |
|
350 mServiceInterface->ExecuteCmdL( KRequestNotification, |
|
351 *inParam, *outParam, 0, this ); |
|
352 |
|
353 outParam->Reset(); |
|
354 inParam->Reset(); |
|
355 CleanupStack::PopAndDestroy( reqFilter ); |
|
356 |
|
357 // -------------- |
|
358 // execute action |
|
359 // -------------- |
|
360 |
|
361 TLiwGenericParam type(KType, TLiwVariant(KPublisher)); |
|
362 inParam->AppendL(type); |
|
363 CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC(); |
|
364 |
|
365 TPtrC8 contentType = ((TUint8*)aContentType.c_str()); |
|
366 |
|
367 const TInt KSAPIContentNameMaxLength = 255; |
|
368 |
|
369 TBuf8<KSAPIContentNameMaxLength> contentId; |
|
370 contentId.Format( KContentIdFormat, |
|
371 ((TUint8*)aIdentifier.c_str()), |
|
372 ((TUint8*)aWidgetName.c_str()) ); |
|
373 |
|
374 cpdatamap->InsertL( KPublisherId, TLiwVariant( KHsWidgetPublisher )); |
|
375 cpdatamap->InsertL( KContentType, TLiwVariant( KHsPublisher )); |
|
376 cpdatamap->InsertL( KContentId, TLiwVariant( contentId )); |
|
377 cpdatamap->InsertL( KActionTrigger, TLiwVariant( KSelected )); |
|
378 |
|
379 TLiwGenericParam filter( KFilter, TLiwVariant( cpdatamap )); |
|
380 inParam->AppendL( filter ); |
|
381 mServiceInterface->ExecuteCmdL( _L8("ExecuteAction"), |
|
382 *inParam, *outParam ); |
|
383 |
|
384 CleanupStack::PopAndDestroy( cpdatamap ); |
|
385 |
|
386 filter.Reset(); |
|
387 type.Reset(); |
|
388 |
|
389 inParam->Reset(); |
|
390 |
|
391 return outParam; |
|
392 } |
|
393 |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 // --------------------------------------------------------------------------- |
|
397 // |
|
398 void CTestHspApi::WaitL(TInt aMicroSec) |
|
399 { |
|
400 CWaitActive* wait = CWaitActive::NewL(); |
|
401 wait->Wait(aMicroSec); |
|
402 delete wait; |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------------------------- |
|
406 // |
|
407 // --------------------------------------------------------------------------- |
|
408 // |
|
409 MLiwInterface* CTestHspApi::GetServiceInterfaceL() |
|
410 { |
|
411 CLiwGenericParamList* inParam = CLiwGenericParamList::NewL(); |
|
412 CleanupStack::PushL( inParam ); |
|
413 CLiwGenericParamList* outParam = CLiwGenericParamList::NewL(); |
|
414 CleanupStack::PushL( outParam ); |
|
415 // CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL( KLiwCmdAsStr, |
|
416 // KCPInterface, KCPService ); |
|
417 CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL( KLiwCmdAsStr, |
|
418 _L8("IContentPublishing"), KCPService ); |
|
419 |
|
420 crit->SetServiceClass( TUid::Uid(KLiwClassBase) ); |
|
421 |
|
422 RCriteriaArray a; |
|
423 a.AppendL(crit); |
|
424 |
|
425 mServiceHandler->AttachL(a); |
|
426 mServiceHandler->ExecuteServiceCmdL( *crit, *inParam, *outParam ); |
|
427 |
|
428 delete crit; |
|
429 a.Reset(); |
|
430 |
|
431 // find service interface |
|
432 TInt pos = 0; |
|
433 MLiwInterface* msgInterface = NULL; |
|
434 //outParam->FindFirst( pos, KCPInterface ); |
|
435 outParam->FindFirst( pos, _L8("IContentPublishing") ); |
|
436 if ( pos != KErrNotFound ) |
|
437 { |
|
438 msgInterface = (*outParam)[pos].Value().AsInterface(); |
|
439 } |
|
440 |
|
441 outParam->Reset(); |
|
442 inParam->Reset(); |
|
443 CleanupStack::PopAndDestroy( outParam ); |
|
444 CleanupStack::PopAndDestroy( inParam ); |
|
445 |
|
446 return msgInterface; |
|
447 } |
|
448 |
|
449 |
|
450 // from Observer interface |
|
451 |
|
452 // ----------------------------------------------------------------------------- |
|
453 // |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 void CTestHspApi::handleItemEvent( std::string aWidgetName, std::string aTemplateItemName, |
|
457 IHsDataObserver::EItemEvent aAction ) |
|
458 { |
|
459 TPtrC8 itemName = ((TUint8*)aTemplateItemName.c_str()); |
|
460 |
|
461 iItemActionStatus = KErrNone; |
|
462 } |
|
463 |
|
464 // ----------------------------------------------------------------------------- |
|
465 // |
|
466 // ----------------------------------------------------------------------------- |
|
467 // |
|
468 void CTestHspApi::handleEvent( std::string aWidgetName, |
|
469 IHsDataObserver::EEvent aAction ) |
|
470 { |
|
471 TPtrC8 widgetName = ((TUint8*)aWidgetName.c_str()); |
|
472 |
|
473 iActionStatus = KErrNone; |
|
474 } |
|
475 |
|
476 |
|
477 // ----------------------------------------------------------------------------- |
|
478 // |
|
479 // ----------------------------------------------------------------------------- |
|
480 // |
|
481 TInt CTestHspApi::TestHspApiConstrL( CStifItemParser& aItem ) |
|
482 { |
|
483 Hs::HsWidgetPublisher* mHSPApi = new Hs::HsWidgetPublisher(this); |
|
484 |
|
485 if ( mHSPApi ) |
|
486 { |
|
487 delete mHSPApi; |
|
488 return KErrNone; |
|
489 } |
|
490 else |
|
491 { |
|
492 return KErrGeneral; |
|
493 } |
|
494 } |
|
495 |
|
496 |
|
497 // ----------------------------------------------------------------------------- |
|
498 // |
|
499 // ----------------------------------------------------------------------------- |
|
500 // |
|
501 void CTestHspApi::AddTemplate( Hs::HsWidgetPublisher* aHspApi, std::string& aContentType, |
|
502 std::string& aIdentifier, std::string& aWidgetName ) |
|
503 { |
|
504 Hs::HsWidget& templ = aHspApi->createHsWidget( aContentType, aWidgetName, aIdentifier); |
|
505 std::string itemName1( "item_name_1" ); |
|
506 std::string itemValue1( "myimage1_image" ); |
|
507 templ.setItem( itemName1, itemValue1 ); |
|
508 std::string itemName2( "item_name_2" ); |
|
509 templ.setItem( itemName2, 1 ); |
|
510 std::string itemName3( "item_name_3" ); |
|
511 std::string itemValue3( "value_3" ); |
|
512 templ.setItem( itemName3, itemValue3 ); |
|
513 |
|
514 templ.setItem( itemName2, 1 ); |
|
515 templ.setItem( itemName2, itemValue3 ); |
|
516 |
|
517 SendFakeActivateEvent( aIdentifier ); |
|
518 WaitL( 1000000 ); |
|
519 |
|
520 aHspApi->publishHsWidget( templ ); |
|
521 } |
|
522 |
|
523 // ----------------------------------------------------------------------------- |
|
524 // |
|
525 // ----------------------------------------------------------------------------- |
|
526 // |
|
527 void CTestHspApi::SendFakeActivateEvent( std::string& aIdentifier ) |
|
528 { |
|
529 CLiwGenericParamList* inParam = &(mServiceHandler->InParamListL()); |
|
530 CLiwGenericParamList* outParam = &(mServiceHandler->OutParamListL()); |
|
531 |
|
532 TLiwGenericParam type(KType, TLiwVariant(KCpData)); |
|
533 inParam->AppendL(type); |
|
534 |
|
535 CLiwDefaultMap* map = CLiwDefaultMap::NewLC(); |
|
536 HBufC* publisherName = StdStringTo16bitDescLC( aIdentifier + ":hswidgetpublisher" ); |
|
537 map->InsertL( KPublisherId, TLiwVariant( *publisherName ) ); |
|
538 map->InsertL( KContentType, TLiwVariant( _L("hswidget") ) ); |
|
539 map->InsertL( KContentId, TLiwVariant( KFakeContentId ) ); |
|
540 map->InsertL( KType, TLiwVariant( _L("publisher") ) ); |
|
541 map->InsertL( KActionTrigger, TLiwVariant( _L8("active") ) ); |
|
542 map->InsertL( _L8("action_trigger16"), TLiwVariant( _L("active") ) ); |
|
543 map->InsertL( _L8("operation"), TLiwVariant( _L("execute") ) ); |
|
544 |
|
545 TLiwGenericParam filter( KFilter, TLiwVariant( map ) ); |
|
546 inParam->AppendL( filter ); |
|
547 |
|
548 mServiceInterface->ExecuteCmdL( _L8("ExecuteAction"), *inParam, *outParam); |
|
549 |
|
550 CleanupStack::PopAndDestroy( publisherName ); |
|
551 CleanupStack::PopAndDestroy( map ); |
|
552 } |
|
553 |
|
554 // ----------------------------------------------------------------------------- |
|
555 // |
|
556 // ----------------------------------------------------------------------------- |
|
557 // |
|
558 void CTestHspApi::AddExistingTemplate( Hs::HsWidgetPublisher* aHspApi, std::string& aContentType, |
|
559 std::string& aIdentifier, std::string& aWidgetName ) |
|
560 { |
|
561 Hs::HsWidget& templ = aHspApi->createHsWidget( aContentType, aWidgetName, aIdentifier); |
|
562 std::string itemName1( "item_name_1" ); |
|
563 std::string itemValue1( "myimage1_image" ); |
|
564 templ.setItem( itemName1, itemValue1 ); |
|
565 Hs::HsWidget& temp2 = aHspApi->createHsWidget( aContentType, aWidgetName, aIdentifier); |
|
566 aHspApi->publishHsWidget( templ ); |
|
567 } |
|
568 |
|
569 // ----------------------------------------------------------------------------- |
|
570 // |
|
571 // ----------------------------------------------------------------------------- |
|
572 // |
|
573 void CTestHspApi::AddAndRemoveTemplateItem1( Hs::HsWidgetPublisher* aHspApi, std::string& aContentType, |
|
574 std::string& aIdentifier, std::string& aWidgetName ) |
|
575 { |
|
576 Hs::HsWidget& templ = aHspApi->createHsWidget( aContentType, aWidgetName, aIdentifier); |
|
577 std::string itemName1( "item_name_1" ); |
|
578 std::string itemValue1( "myimage1_image" ); |
|
579 templ.setItem( itemName1, itemValue1 ); |
|
580 std::string itemName2( "item_name_2" ); |
|
581 templ.setItem( itemName2, 1 ); |
|
582 std::string itemName3( "item_name_3" ); |
|
583 std::string itemValue3( "value_3" ); |
|
584 templ.setItem( itemName3, itemValue3 ); |
|
585 templ.removeItem( itemName3 ); |
|
586 |
|
587 SendFakeActivateEvent( aIdentifier ); |
|
588 WaitL( 1000000 ); |
|
589 |
|
590 aHspApi->publishHsWidget( templ ); |
|
591 } |
|
592 |
|
593 // ----------------------------------------------------------------------------- |
|
594 // |
|
595 // ----------------------------------------------------------------------------- |
|
596 // |
|
597 void CTestHspApi::AddAndRemoveTemplateItem2( Hs::HsWidgetPublisher* aHspApi, std::string& aContentType, |
|
598 std::string& aIdentifier, std::string& aWidgetName ) |
|
599 { |
|
600 Hs::HsWidget& templ = aHspApi->createHsWidget( aContentType, aWidgetName, aIdentifier); |
|
601 std::string itemName1( "item_name_1" ); |
|
602 std::string itemValue1( "myimage1_image" ); |
|
603 templ.setItem( itemName1, itemValue1 ); |
|
604 std::string itemName2( "item_name_2" ); |
|
605 templ.setItem( itemName2, 1 ); |
|
606 std::string itemName3( "item_name_3" ); |
|
607 templ.removeItem( itemName3 ); |
|
608 aHspApi->publishHsWidget( templ ); |
|
609 } |
|
610 |
|
611 |
|
612 // ----------------------------------------------------------------------------- |
|
613 // |
|
614 // ----------------------------------------------------------------------------- |
|
615 // |
|
616 TInt CTestHspApi::TestHspWidgetAddWidgetItem1L( CStifItemParser& aItem ) |
|
617 { |
|
618 TInt err( KErrNone ); |
|
619 |
|
620 Hs::HsWidgetPublisher* mHSPApi = new Hs::HsWidgetPublisher( this ); |
|
621 |
|
622 std::string contentType( "ct" ); |
|
623 std::string identifier( "id" ); |
|
624 std::string widgetName( "wn" ); |
|
625 |
|
626 AddTemplate( mHSPApi, contentType, identifier, widgetName ); |
|
627 |
|
628 CLiwGenericParamList* res = GetListL( contentType, identifier, widgetName ); |
|
629 TInt count = ExtractItemCountL( *res ); |
|
630 |
|
631 delete mHSPApi; |
|
632 |
|
633 if ( count != 1 ) |
|
634 { |
|
635 err = KErrGeneral; |
|
636 } |
|
637 |
|
638 return err; |
|
639 } |
|
640 |
|
641 // ----------------------------------------------------------------------------- |
|
642 // |
|
643 // ----------------------------------------------------------------------------- |
|
644 // |
|
645 TInt CTestHspApi::TestHspWidgetAddWidgetItem2L( CStifItemParser& aItem ) |
|
646 { |
|
647 TInt err( KErrNone ); |
|
648 |
|
649 Hs::HsWidgetPublisher* mHSPApi = new Hs::HsWidgetPublisher( this ); |
|
650 |
|
651 std::string contentType( "ct" ); |
|
652 std::string identifier( "id" ); |
|
653 std::string widgetName( "wn" ); |
|
654 |
|
655 AddTemplate( mHSPApi, contentType, identifier, widgetName ); |
|
656 |
|
657 CLiwGenericParamList* res = GetListL( contentType, identifier, widgetName ); |
|
658 |
|
659 // check if item was really removed |
|
660 RBuf value; |
|
661 err = ExtractItemL( *res, _L8("item_name_3"), value ); |
|
662 |
|
663 if ( value.Compare( _L("value_3") ) ) |
|
664 { |
|
665 err = KErrGeneral; |
|
666 } |
|
667 |
|
668 value.Close(); |
|
669 |
|
670 delete mHSPApi; |
|
671 return err; |
|
672 } |
|
673 |
|
674 // ----------------------------------------------------------------------------- |
|
675 // |
|
676 // ----------------------------------------------------------------------------- |
|
677 // |
|
678 TInt CTestHspApi::TestHspWidgetAddWidgetItem3L( CStifItemParser& aItem ) |
|
679 { |
|
680 TInt err( KErrNone ); |
|
681 |
|
682 Hs::HsWidgetPublisher* mHSPApi = new Hs::HsWidgetPublisher( this ); |
|
683 |
|
684 std::string contentType( "ct" ); |
|
685 std::string identifier( "id" ); |
|
686 std::string widgetName( "wn" ); |
|
687 |
|
688 TInt reason( KErrNone ); |
|
689 try |
|
690 { |
|
691 // this should throw an exception with KAlreadyExists reason |
|
692 AddExistingTemplate( mHSPApi, contentType, identifier, widgetName ); |
|
693 } |
|
694 catch ( Hs::HsException& e ) |
|
695 { |
|
696 reason = e.getReason(); |
|
697 } |
|
698 |
|
699 if ( KErrAlreadyExists != reason ) |
|
700 { |
|
701 err = reason; |
|
702 } |
|
703 |
|
704 delete mHSPApi; |
|
705 return err; |
|
706 } |
|
707 |
|
708 // ----------------------------------------------------------------------------- |
|
709 // |
|
710 // ----------------------------------------------------------------------------- |
|
711 // |
|
712 TInt CTestHspApi::TestHspApiDeleteWidgetL( CStifItemParser& aItem ) |
|
713 { |
|
714 TInt err( KErrNone ); |
|
715 |
|
716 Hs::HsWidgetPublisher* mHSPApi = new Hs::HsWidgetPublisher( this ); |
|
717 |
|
718 std::string contentType( "ct" ); |
|
719 std::string identifier( "id" ); |
|
720 std::string widgetName( "wn" ); |
|
721 |
|
722 AddTemplate( mHSPApi, contentType, identifier, widgetName ); |
|
723 |
|
724 CLiwGenericParamList* res = GetListL( contentType, identifier, widgetName ); |
|
725 TInt count = ExtractItemCountL( *res ); |
|
726 |
|
727 if ( count != 1 ) |
|
728 { |
|
729 err = KErrGeneral; |
|
730 } |
|
731 |
|
732 res->Reset(); |
|
733 |
|
734 mHSPApi->removeHsWidget( contentType, widgetName, identifier ); |
|
735 |
|
736 res = GetListL( contentType, identifier, widgetName ); |
|
737 count = ExtractItemCountL( *res ); |
|
738 res->Reset(); |
|
739 |
|
740 if ( count != KErrNotFound ) |
|
741 { |
|
742 err = KErrGeneral; |
|
743 } |
|
744 |
|
745 delete mHSPApi; |
|
746 |
|
747 return err; |
|
748 } |
|
749 |
|
750 // ----------------------------------------------------------------------------- |
|
751 // |
|
752 // ----------------------------------------------------------------------------- |
|
753 // |
|
754 TInt CTestHspApi::TestHspApiSetDataObserver1L( CStifItemParser& aItem ) |
|
755 { |
|
756 TInt err( KErrNone ); |
|
757 |
|
758 Hs::HsWidgetPublisher* mHSPApi = new Hs::HsWidgetPublisher( this ); |
|
759 |
|
760 std::string contentType( "ct" ); |
|
761 std::string identifier( "id" ); |
|
762 std::string widgetName( "wn" ); |
|
763 |
|
764 AddTemplate( mHSPApi, contentType, identifier, widgetName ); |
|
765 |
|
766 ExecuteActionL( contentType, identifier, widgetName ); |
|
767 |
|
768 WaitL( 1000000 ); |
|
769 |
|
770 CLiwGenericParamList* res = GetListL( contentType, identifier, widgetName ); |
|
771 TInt count = ExtractItemCountL( *res ); |
|
772 |
|
773 if ( count != 1 ) |
|
774 { |
|
775 err = KErrGeneral; |
|
776 } |
|
777 |
|
778 res->Reset(); |
|
779 |
|
780 mHSPApi->removeHsWidget( contentType, widgetName, identifier ); |
|
781 |
|
782 res = GetListL( contentType, identifier, widgetName ); |
|
783 count = ExtractItemCountL( *res ); |
|
784 res->Reset(); |
|
785 |
|
786 if ( count != KErrNotFound ) |
|
787 { |
|
788 err = KErrGeneral; |
|
789 } |
|
790 |
|
791 delete mHSPApi; |
|
792 |
|
793 return err; |
|
794 } |
|
795 |
|
796 // ----------------------------------------------------------------------------- |
|
797 // |
|
798 // ----------------------------------------------------------------------------- |
|
799 // |
|
800 TInt CTestHspApi::TestHspApiSetDataObserver2L( CStifItemParser& aItem ) |
|
801 { |
|
802 TInt err( KErrNone ); |
|
803 |
|
804 Hs::HsWidgetPublisher* mHSPApi = new Hs::HsWidgetPublisher( this ); |
|
805 |
|
806 std::string contentType( "ct" ); |
|
807 std::string identifier( "id" ); |
|
808 std::string widgetName( "wn" ); |
|
809 |
|
810 AddTemplate( mHSPApi, contentType, identifier, widgetName ); |
|
811 |
|
812 ExecuteActionSelectedL( contentType, identifier, widgetName ); |
|
813 |
|
814 WaitL( 1000000 ); |
|
815 |
|
816 CLiwGenericParamList* res = GetListL( contentType, identifier, widgetName ); |
|
817 TInt count = ExtractItemCountL( *res ); |
|
818 |
|
819 if ( count != 1 ) |
|
820 { |
|
821 err = KErrGeneral; |
|
822 } |
|
823 |
|
824 res->Reset(); |
|
825 |
|
826 mHSPApi->removeHsWidget( contentType, widgetName, identifier ); |
|
827 |
|
828 res = GetListL( contentType, identifier, widgetName ); |
|
829 count = ExtractItemCountL( *res ); |
|
830 res->Reset(); |
|
831 |
|
832 if ( count != KErrNotFound ) |
|
833 { |
|
834 err = KErrGeneral; |
|
835 } |
|
836 |
|
837 delete mHSPApi; |
|
838 |
|
839 return err; |
|
840 } |
|
841 |
|
842 // ----------------------------------------------------------------------------- |
|
843 // |
|
844 // ----------------------------------------------------------------------------- |
|
845 // |
|
846 TInt CTestHspApi::TestHspApiGetWidgetL( CStifItemParser& aItem ) |
|
847 { |
|
848 TInt err( KErrNone ); |
|
849 |
|
850 Hs::HsWidgetPublisher* mHSPApi = new Hs::HsWidgetPublisher( this ); |
|
851 |
|
852 std::string contentType1( "ct1" ); |
|
853 std::string identifier1( "id1" ); |
|
854 std::string widgetName1( "wn1" ); |
|
855 |
|
856 AddTemplate( mHSPApi, contentType1, identifier1, widgetName1 ); |
|
857 |
|
858 Hs::HsWidget& templ1 = mHSPApi->getHsWidget( contentType1, widgetName1, identifier1 ); |
|
859 |
|
860 if (! &templ1 ) |
|
861 { |
|
862 err = KErrGeneral; |
|
863 } |
|
864 |
|
865 std::string contentType2( "ct2" ); |
|
866 std::string identifier2( "id2" ); |
|
867 std::string widgetName2( "wn2" ); |
|
868 |
|
869 try |
|
870 { |
|
871 Hs::HsWidget& templ2 = mHSPApi->getHsWidget( contentType2, widgetName2, identifier2 ); |
|
872 if ( &templ2 ) |
|
873 { |
|
874 err = KErrCancel; |
|
875 } |
|
876 } |
|
877 catch ( ... ) |
|
878 { |
|
879 |
|
880 } |
|
881 |
|
882 delete mHSPApi; |
|
883 |
|
884 return err; |
|
885 } |
|
886 |
|
887 |
|
888 // ----------------------------------------------------------------------------- |
|
889 // |
|
890 // ----------------------------------------------------------------------------- |
|
891 // |
|
892 TInt CTestHspApi::TestHspApiWidgetRemoveItem1L( CStifItemParser& aItem ) |
|
893 { |
|
894 TInt err( KErrNone ); |
|
895 |
|
896 Hs::HsWidgetPublisher* mHSPApi = new Hs::HsWidgetPublisher( this ); |
|
897 |
|
898 std::string contentType( "ct" ); |
|
899 std::string identifier( "id" ); |
|
900 std::string widgetName( "wn" ); |
|
901 |
|
902 AddAndRemoveTemplateItem1( mHSPApi, contentType, identifier, widgetName ); |
|
903 |
|
904 CLiwGenericParamList* res = GetListL( contentType, identifier, widgetName ); |
|
905 |
|
906 // check if item was really removed |
|
907 RBuf value; |
|
908 TInt ret = ExtractItemL( *res, _L8("item_name_3"), value ); |
|
909 |
|
910 if ( ret != KErrNotFound ) |
|
911 { |
|
912 err = ret; |
|
913 } |
|
914 |
|
915 delete mHSPApi; |
|
916 return err; |
|
917 } |
|
918 |
|
919 // ----------------------------------------------------------------------------- |
|
920 // |
|
921 // ----------------------------------------------------------------------------- |
|
922 // |
|
923 TInt CTestHspApi::TestHspApiWidgetRemoveItem2L( CStifItemParser& aItem ) |
|
924 { |
|
925 TInt err( KErrNone ); |
|
926 |
|
927 Hs::HsWidgetPublisher* mHSPApi = new Hs::HsWidgetPublisher( this ); |
|
928 |
|
929 std::string contentType( "ct" ); |
|
930 std::string identifier( "id" ); |
|
931 std::string widgetName( "wn" ); |
|
932 |
|
933 TInt reason( KErrNone ); |
|
934 |
|
935 try |
|
936 { |
|
937 AddAndRemoveTemplateItem2( mHSPApi, contentType, identifier, widgetName ); |
|
938 } |
|
939 catch( Hs::HsException& exception ) |
|
940 { |
|
941 reason = exception.getReason(); |
|
942 } |
|
943 |
|
944 if ( KErrNotFound != reason ) |
|
945 { |
|
946 err = reason; |
|
947 } |
|
948 |
|
949 delete mHSPApi; |
|
950 return err; |
|
951 } |
|
952 |
|
953 |
|
954 // ----------------------------------------------------------------------------- |
|
955 // |
|
956 // ----------------------------------------------------------------------------- |
|
957 // |
|
958 void CTestHspApi::ThrowHspException() |
|
959 { |
|
960 throw Hs::HsException( KErrGeneral ); |
|
961 } |
|
962 |
|
963 // ----------------------------------------------------------------------------- |
|
964 // |
|
965 // ----------------------------------------------------------------------------- |
|
966 // |
|
967 TInt CTestHspApi::TestHspApiExceptionL( CStifItemParser& aItem ) |
|
968 { |
|
969 TInt err( KErrNone ); |
|
970 TInt reason( KErrNone ); |
|
971 try |
|
972 { |
|
973 ThrowHspException(); |
|
974 } |
|
975 catch( Hs::HsException& exception ) |
|
976 { |
|
977 reason = exception.getReason(); |
|
978 } |
|
979 |
|
980 if ( KErrGeneral != reason ) |
|
981 { |
|
982 err = reason; |
|
983 } |
|
984 return err; |
|
985 } |