|
1 /* |
|
2 * Copyright (c) 2010 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: unit test for the mcsplugin handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS HEADER |
|
20 #include "ut_sapidata.h" |
|
21 |
|
22 |
|
23 // EXTERNAL INCLUDES |
|
24 #include <digia/eunit/eunitmacros.h> |
|
25 #include <e32cmn.h> |
|
26 #include "aiutility.h" |
|
27 #include "aipluginsettings.h" |
|
28 |
|
29 // INTERNAL INCLUDES |
|
30 #define private public |
|
31 #include "sapidata.h" |
|
32 #undef private |
|
33 #include "sapidataplugin.h" |
|
34 #include "observer.h" |
|
35 |
|
36 // Implementation of the MTest interface |
|
37 void MTest::GetMenuItemsL() |
|
38 { |
|
39 |
|
40 } |
|
41 |
|
42 // CONSTRUCTION |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // UT_SapiData* UT_SapiData::NewL() |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 UT_SapiData* UT_SapiData::NewL() |
|
49 { |
|
50 UT_SapiData* self = UT_SapiData::NewLC(); |
|
51 CleanupStack::Pop(); |
|
52 |
|
53 return self; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // UT_SapiData* UT_SapiData::NewLC() |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 UT_SapiData* UT_SapiData::NewLC() |
|
61 { |
|
62 UT_SapiData* self = new(ELeave) UT_SapiData(); |
|
63 CleanupStack::PushL(self); |
|
64 |
|
65 self->ConstructL(); |
|
66 |
|
67 return self; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Destructor (virtual by CBase) |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 UT_SapiData::~UT_SapiData() |
|
75 { |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Default constructor |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 UT_SapiData::UT_SapiData() |
|
83 { |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // Second phase construct |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 void UT_SapiData::ConstructL() |
|
91 { |
|
92 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
93 // It generates the test case table. |
|
94 CEUnitTestSuiteClass::ConstructL(); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // void UT_SapiDataPlugin::SetupL() |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void UT_SapiData::SetupL() |
|
102 { |
|
103 iContentObserver = Observer::NewL(); |
|
104 TUid uid = { SAPIDP_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_DATAPLUGIN }; |
|
105 |
|
106 iPlugin = CSapiDataPlugin::NewL(); |
|
107 |
|
108 // Array owned by the plugin |
|
109 RAiSettingsItemArray settings; |
|
110 settings.ReserveL( 3 ); |
|
111 |
|
112 MAiPluginSettings* configuration( AiUtility::CreatePluginSettingsL() ); |
|
113 CleanupDeletePushL( configuration ); |
|
114 |
|
115 MAiPluginConfigurationItem& confItem = configuration->AiPluginConfigurationItem(); |
|
116 confItem.SetOwnerL( KPlugin ); |
|
117 confItem.SetNameL( KPublisher ); |
|
118 confItem.SetValueL( KMtSapiDataPlugin ); |
|
119 |
|
120 settings.AppendL( configuration ); |
|
121 CleanupStack::Pop( configuration ); |
|
122 |
|
123 // No publisher there, set empty |
|
124 iPlugin->ConfigureL( settings ); |
|
125 iPlugin->SubscribeL( *iContentObserver ); |
|
126 iPlugin->Start( CHsContentPublisher::ESystemStartup ); |
|
127 iPlugin->Resume( CHsContentPublisher::EForeground ); |
|
128 |
|
129 CleanupStack::PushL( iPlugin ); |
|
130 iData = CSapiData::NewL( iPlugin ); |
|
131 CleanupStack::Pop( iPlugin ); |
|
132 iData->SetContentIdL( KId ); |
|
133 iData->ConfigureL( settings ); |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // void UT_SapiDataPlugin::Teardown() |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 void UT_SapiData::Teardown() |
|
141 { |
|
142 if ( iContentObserver ) |
|
143 { |
|
144 delete iContentObserver; |
|
145 iContentObserver = NULL; |
|
146 } |
|
147 if ( iData ) |
|
148 { |
|
149 delete iData; |
|
150 iData = NULL; |
|
151 } |
|
152 if ( iPlugin ) |
|
153 { |
|
154 delete iPlugin; |
|
155 iPlugin = NULL; |
|
156 } |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // void UT_SapiData::TestConfigureL() |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 void UT_SapiData::TestConfigureL() |
|
164 { |
|
165 RAiSettingsItemArray configurationItemsArr; |
|
166 configurationItemsArr.ReserveL( 1 ); |
|
167 |
|
168 MAiPluginSettings* settings( AiUtility::CreatePluginSettingsL() ); |
|
169 CleanupDeletePushL( settings ); |
|
170 |
|
171 MAiPluginSettingsItem& item( settings->AiPluginSettingsItem() ); |
|
172 item.SetPublisherId( TUid::Uid( 3 ) ); |
|
173 |
|
174 _LIT( KPlugin, "plugin" ); |
|
175 _LIT( KPublisher16, "publisher" ); |
|
176 MAiPluginConfigurationItem& confItem = settings->AiPluginConfigurationItem(); |
|
177 confItem.SetOwnerL( KPlugin ); |
|
178 confItem.SetNameL( KPublisher16 ); |
|
179 |
|
180 TInt32 key( 0 ); |
|
181 |
|
182 item.SetKey( key ); |
|
183 _LIT( KValue, "value" ); |
|
184 item.SetValueL( KValue, EFalse ); |
|
185 |
|
186 configurationItemsArr.Append( settings ); |
|
187 CleanupStack::Pop( settings ); |
|
188 |
|
189 |
|
190 EUNIT_ASSERT_NO_LEAVE( iData->ConfigureL( configurationItemsArr ) ); |
|
191 |
|
192 //delete settings; |
|
193 configurationItemsArr.ResetAndDestroy(); |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // void UT_SapiData::TestSetContentIdL() |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void UT_SapiData::TestSetContentIdL() |
|
201 { |
|
202 _LIT8( KId, "11" ); |
|
203 EUNIT_ASSERT_NO_LEAVE( iData->SetContentIdL( KId ) ); |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // void UT_SapiData::TestSetStartupReasonL() |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 void UT_SapiData::TestSetStartupReasonL() |
|
211 { |
|
212 _LIT8( KStartupReason, "startup_reason" ); |
|
213 EUNIT_ASSERT_LEAVE( iData->SetStartupReasonL( KStartupReason ) ); |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // void UT_SapiData::TestIsPluginActive() |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 void UT_SapiData::TestIsPluginActive() |
|
221 { |
|
222 TBool res = iData->IsPluginActive(); |
|
223 EUNIT_ASSERT( res ); |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // void UT_SapiData::TestChangePublisherStatusL() |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void UT_SapiData::TestChangePublisherStatusL() |
|
231 { |
|
232 _LIT8( KStatus, "new_status" ); |
|
233 |
|
234 iData->SetUpdateNeeded( ETrue ); |
|
235 EUNIT_ASSERT_LEAVE( iData->ChangePublisherStatusL( KStatus ) ); |
|
236 |
|
237 iData->SetUpdateNeeded( EFalse ); |
|
238 EUNIT_ASSERT_LEAVE( iData->ChangePublisherStatusL( KStatus ) ); |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // void UT_SapiData::TestTriggerActiveL() |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 void UT_SapiData::TestTriggerActiveL() |
|
246 { |
|
247 EUNIT_ASSERT_LEAVE( iData->TriggerActiveL() ); |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // void UT_SapiData::TestUpdatePublisherStatusL() |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 void UT_SapiData::TestUpdatePublisherStatusL() |
|
255 { |
|
256 TBuf<10> publisher; |
|
257 publisher.Append( _L("publisher") ); |
|
258 EUNIT_ASSERT_NO_LEAVE( iData->UpdatePublisherStatusL( publisher) ); |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------------------------- |
|
262 // void UT_SapiData::TestCanUpdate() |
|
263 // --------------------------------------------------------------------------- |
|
264 // |
|
265 void UT_SapiData::TestCanUpdate() |
|
266 { |
|
267 TBuf<20> KId_EU; |
|
268 KId_EU.Append( _L("4")); |
|
269 |
|
270 TBuf<20> KAll_EU; |
|
271 KAll_EU.Append( _L("all")); |
|
272 |
|
273 TBufC<30> KPublisher_EU ( KMtSapiDataPlugin ); |
|
274 |
|
275 |
|
276 EUNIT_ASSERT( iData->CanUpdate( KPublisher_EU, KAll_EU, KId_EU ) ); |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------------------------- |
|
280 // void UT_SapiData::TestGetMenuItemsL() |
|
281 // --------------------------------------------------------------------------- |
|
282 // |
|
283 void UT_SapiData::TestGetMenuItemsL() |
|
284 { |
|
285 MTest* test; |
|
286 |
|
287 test = reinterpret_cast<MTest*> ( iData ); |
|
288 |
|
289 EUNIT_ASSERT_NO_LEAVE( test->GetMenuItemsL() ); |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------------------------- |
|
293 // void UT_SapiData::TestHasMenuItem() |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 void UT_SapiData::TestHasMenuItem() |
|
297 { |
|
298 _LIT16( KParam, "hello world" ); |
|
299 EUNIT_ASSERT( !iData->HasMenuItem(KParam) ); |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // void UT_SapiData::TestRemoveL() |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 void UT_SapiData::TestRemoveL() |
|
307 { |
|
308 TBuf<10> KAll; |
|
309 KAll.Append( _L("all") ); |
|
310 |
|
311 Observer* observer = Observer::NewL(); |
|
312 |
|
313 EUNIT_ASSERT_NO_LEAVE( iData->RemoveL(observer, KAll) ); |
|
314 |
|
315 delete observer; |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // void UT_SapiData::TestRefreshL() |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 void UT_SapiData::TestRefreshL() |
|
323 { |
|
324 TBuf<20> publisher; |
|
325 publisher.Append( _L("mt_sapi_plugin") ); |
|
326 TBuf<10> contentType; |
|
327 contentType.Append( _L("all") ); |
|
328 TBuf<10> contentId; |
|
329 contentId.Append( _L("4") ); |
|
330 TBuf<10> operation; |
|
331 operation.Append( _L("operation") ); |
|
332 CLiwDefaultMap* dataMap; |
|
333 |
|
334 iData->CanUpdate( publisher, contentType, contentId ); |
|
335 iData->RefreshL( publisher, contentType, contentId, operation, dataMap ); |
|
336 |
|
337 TInt id = 4; |
|
338 iPlugin->Clean(iContentObserver, id ); |
|
339 } |
|
340 |
|
341 // TEST TABLE |
|
342 |
|
343 EUNIT_BEGIN_TEST_TABLE |
|
344 ( |
|
345 UT_SapiData, |
|
346 "Sapidata plugin tests", |
|
347 "UNIT" |
|
348 ) |
|
349 |
|
350 EUNIT_TEST |
|
351 ( |
|
352 "Test configure", |
|
353 "CSapiData", |
|
354 "ConfigureL", |
|
355 "FUNCTIONALITY", |
|
356 SetupL, TestConfigureL, Teardown |
|
357 ) |
|
358 |
|
359 EUNIT_TEST |
|
360 ( |
|
361 "Test refresh", |
|
362 "CSapiData", |
|
363 "RefreshL", |
|
364 "FUNCTIONALITY", |
|
365 SetupL, TestRefreshL, Teardown |
|
366 ) |
|
367 |
|
368 EUNIT_TEST |
|
369 ( |
|
370 "Test set content ID", |
|
371 "CSapiData", |
|
372 "SetContentIdL", |
|
373 "FUNCTIONALITY", |
|
374 SetupL, TestSetContentIdL, Teardown |
|
375 ) |
|
376 |
|
377 EUNIT_TEST |
|
378 ( |
|
379 "Test set startup reason", |
|
380 "CSapiData", |
|
381 "SetStartupReasonL", |
|
382 "FUNCTIONALITY", |
|
383 SetupL, TestSetStartupReasonL, Teardown |
|
384 ) |
|
385 |
|
386 EUNIT_TEST |
|
387 ( |
|
388 "Test is plugin active", |
|
389 "CSapiData", |
|
390 "IsPluginActive", |
|
391 "FUNCTIONALITY", |
|
392 SetupL, TestIsPluginActive, Teardown |
|
393 ) |
|
394 |
|
395 EUNIT_TEST |
|
396 ( |
|
397 "Test change publisher status", |
|
398 "CSapiData", |
|
399 "ChangePublisherStatusL", |
|
400 "FUNCTIONALITY", |
|
401 SetupL, TestChangePublisherStatusL, Teardown |
|
402 ) |
|
403 |
|
404 EUNIT_TEST |
|
405 ( |
|
406 "Test trigger activate", |
|
407 "CSapiData", |
|
408 "TriggerActivateL", |
|
409 "FUNCTIONALITY", |
|
410 SetupL, TestTriggerActiveL, Teardown |
|
411 ) |
|
412 |
|
413 EUNIT_TEST |
|
414 ( |
|
415 "Test update publisher status", |
|
416 "CSapiData", |
|
417 "UpdatePublisherStatusL", |
|
418 "FUNCTIONALITY", |
|
419 SetupL, TestUpdatePublisherStatusL, Teardown |
|
420 ) |
|
421 |
|
422 EUNIT_TEST |
|
423 ( |
|
424 "Test can update", |
|
425 "CSapiData", |
|
426 "CanUpdate", |
|
427 "FUNCTIONALITY", |
|
428 SetupL, TestCanUpdate, Teardown |
|
429 ) |
|
430 |
|
431 EUNIT_TEST |
|
432 ( |
|
433 "Test get menu items", |
|
434 "CSapiData", |
|
435 "GetMenuItemsL", |
|
436 "FUNCTIONALITY", |
|
437 SetupL, TestGetMenuItemsL, Teardown |
|
438 ) |
|
439 |
|
440 EUNIT_TEST |
|
441 ( |
|
442 "Test has menu item", |
|
443 "CSapiData", |
|
444 "HasMenuItem", |
|
445 "FUNCTIONALITY", |
|
446 SetupL, TestHasMenuItem, Teardown |
|
447 ) |
|
448 |
|
449 EUNIT_TEST |
|
450 ( |
|
451 "Test remove", |
|
452 "CSapiData", |
|
453 "RemoveL", |
|
454 "FUNCTIONALITY", |
|
455 SetupL, TestRemoveL, Teardown |
|
456 ) |
|
457 |
|
458 EUNIT_END_TEST_TABLE |
|
459 |
|
460 // END OF FILE |