|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // CLASS HEADER |
|
19 #include "mt_sapidataplugin.h" |
|
20 |
|
21 // EXTERNAL INCLUDES |
|
22 #include <digia/eunit/eunitmacros.h> |
|
23 #include <hspluginsettings.h> |
|
24 #include <aipluginsettings.h> |
|
25 #include <aiutility.h> |
|
26 //using namespace HSPluginSettingsIf; |
|
27 #include <sapidataplugin.h> |
|
28 #include <sapidatapluginuids.hrh> |
|
29 |
|
30 // INTERNAL INCLUDES |
|
31 #include "observer.h" |
|
32 #include "aicpsexecuteparam.h" |
|
33 #include "sapidataplugin.h" |
|
34 #include "caicpscommandbuffer_stub.h" |
|
35 #include <mcspluginuids.hrh> |
|
36 |
|
37 _LIT( KPubData, "publisherData" ); |
|
38 _LIT( KText, "Hello test!" ); |
|
39 _LIT( KPublisher, "publisher" ); |
|
40 _LIT( KWRTPublisher, "wrt_publisher"); |
|
41 _LIT( KTemplateWidget,"ai3templatedwidget"); |
|
42 _LIT( KContentIdValue, "com.accuweather.widget.touchNG" ); |
|
43 _LIT8( KContentType, "content_type" ); |
|
44 _LIT8( KContentId, "content_id" ); |
|
45 _LIT8( KAction1, "active_1" ); |
|
46 _LIT8( KAction2, "active_2" ); |
|
47 _LIT8( KPublisherId, "publisherId" ); |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CleanupResetAndDestroy() |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 static void CleanupResetAndDestroy( TAny* aAny ) |
|
54 { |
|
55 static_cast< RAiSettingsItemArray* >( aAny )->ResetAndDestroy(); |
|
56 } |
|
57 |
|
58 // CONSTRUCTION |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // MT_SapiDataPlugin* MT_SapiDataPlugin::NewL() |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 MT_SapiDataPlugin* MT_SapiDataPlugin::NewL() |
|
65 { |
|
66 MT_SapiDataPlugin* self = MT_SapiDataPlugin::NewLC(); |
|
67 CleanupStack::Pop(); |
|
68 |
|
69 return self; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // MT_SapiDataPlugin* MT_SapiDataPlugin::NewLC() |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 MT_SapiDataPlugin* MT_SapiDataPlugin::NewLC() |
|
77 { |
|
78 MT_SapiDataPlugin* self = new( ELeave ) MT_SapiDataPlugin(); |
|
79 CleanupStack::PushL( self ); |
|
80 |
|
81 self->ConstructL(); |
|
82 |
|
83 return self; |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // MT_SapiDataPlugin::~MT_SapiDataPlugin() |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 MT_SapiDataPlugin::~MT_SapiDataPlugin() |
|
91 { |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // MT_SapiDataPlugin::MT_SapiDataPlugin() |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 MT_SapiDataPlugin::MT_SapiDataPlugin() |
|
99 { |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // void MT_SapiDataPlugin::ConstructL() |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 void MT_SapiDataPlugin::ConstructL() |
|
107 { |
|
108 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
109 // It generates the test case table. |
|
110 CEUnitTestSuiteClass::ConstructL(); |
|
111 } |
|
112 |
|
113 // METHODS |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // void MT_SapiDataPlugin::SetupL() |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void MT_SapiDataPlugin::SetupL() |
|
120 { |
|
121 iContentObserver = Observer::NewL(); |
|
122 |
|
123 iPlugin = CSapiDataPlugin::NewL( ); |
|
124 |
|
125 // Array owned by the plugin |
|
126 RAiSettingsItemArray settings; |
|
127 CleanupStack::PushL( TCleanupItem( CleanupResetAndDestroy, &settings ) ); |
|
128 |
|
129 MAiPluginSettings* configuration( AiUtility::CreatePluginSettingsL() ); |
|
130 CleanupDeletePushL( configuration ); |
|
131 |
|
132 MAiPluginConfigurationItem& item( configuration->AiPluginConfigurationItem() ); |
|
133 |
|
134 _LIT( KPlugin, "plugin" ); |
|
135 _LIT( KPublisher, "publisher" ); |
|
136 _LIT( KMtSapiDataPlugin, "mt_sapi_plugin" ); |
|
137 |
|
138 item.SetOwnerL( KPlugin() ); |
|
139 item.SetNameL( KPublisher() ); |
|
140 item.SetValueL( KMtSapiDataPlugin() ); |
|
141 |
|
142 settings.AppendL( configuration ); |
|
143 CleanupStack::Pop( configuration ); |
|
144 |
|
145 iCommandBuffer = CAiCpsCommandBuffer::NewL(); |
|
146 |
|
147 // Ensure interface is available |
|
148 iCommandBuffer->GetCPSInterfaceL(); |
|
149 |
|
150 // No publisher there, set empty |
|
151 iPlugin->SetProperty( CHsContentPublisher::ECpsCmdBuffer, static_cast< MAiCpsCommandBuffer* >( iCommandBuffer ) ); |
|
152 iPlugin->ConfigureL( settings ); |
|
153 iPlugin->SubscribeL( *iContentObserver ); |
|
154 iPlugin->Start( CHsContentPublisher::ESystemStartup ); |
|
155 iPlugin->Resume( CHsContentPublisher::EForeground ); |
|
156 |
|
157 CleanupStack::PopAndDestroy(); // settings |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // void MT_SapiDataPlugin::Teardown() |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 void MT_SapiDataPlugin::Teardown() |
|
165 { |
|
166 if ( iPlugin ) |
|
167 { |
|
168 delete iPlugin; |
|
169 iPlugin = NULL; |
|
170 } |
|
171 if ( iContentObserver ) |
|
172 { |
|
173 delete iContentObserver; |
|
174 iContentObserver = NULL; |
|
175 } |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // void MT_SapiDataPlugin::TestCommandBuffer() |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 void MT_SapiDataPlugin::TestCommandBuffer() |
|
183 { |
|
184 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
185 filter->InsertL( KPublisherId, TLiwVariant( KWRTPublisher )); |
|
186 filter->InsertL( KContentType, TLiwVariant( KTemplateWidget )); |
|
187 filter->InsertL( KContentId, TLiwVariant( KContentIdValue )); |
|
188 |
|
189 iCommandBuffer->Flush(); |
|
190 |
|
191 iCommandBuffer->AddCommand( _L("1"), KPubData, filter, KAction1 ); |
|
192 iCommandBuffer->AddCommand( _L("1"), KPubData, filter, KAction2 ); |
|
193 |
|
194 iCommandBuffer->AddCommand( _L("2"), KPubData, filter, KAction1 ); |
|
195 |
|
196 EUNIT_ASSERT_EQUALS( iCommandBuffer->iPlugins.Count(), 2); |
|
197 EUNIT_ASSERT_EQUALS( iCommandBuffer->iPlugins[0]->iActions.Count(), 2); |
|
198 |
|
199 CleanupStack::PopAndDestroy( filter ); |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // void MT_SapiDataPlugin::TestActivity() |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 void MT_SapiDataPlugin::TestActivity() |
|
207 { |
|
208 iPlugin->Stop( CHsContentPublisher::ESystemShutdown ); |
|
209 EUNIT_ASSERT(iPlugin->IsStopped()); |
|
210 |
|
211 iPlugin->Resume( CHsContentPublisher::EForeground ); |
|
212 EUNIT_ASSERT(!iPlugin->IsActive()); |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // void MT_SapiDataPlugin::TestSuspendL() |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 void MT_SapiDataPlugin::TestSuspendL() |
|
220 { |
|
221 EUNIT_ASSERT( iPlugin->IsActive() ); |
|
222 iPlugin->Suspend( CHsContentPublisher::EBackground ); |
|
223 EUNIT_ASSERT( !iPlugin->IsActive() ); |
|
224 iPlugin->Stop( CHsContentPublisher::ESystemShutdown ); |
|
225 EUNIT_ASSERT( iPlugin->IsStopped() ); |
|
226 iPlugin->Suspend( CHsContentPublisher::EBackground ); |
|
227 EUNIT_ASSERT( iPlugin->IsStopped() ); |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // void MT_SapiDataPlugin::TestPropertyL() |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void MT_SapiDataPlugin::TestPropertyL() |
|
235 { |
|
236 TAny* anyPtr = NULL; |
|
237 |
|
238 anyPtr = iPlugin->GetProperty( CHsContentPublisher::EPublisherContent ); |
|
239 EUNIT_ASSERT( anyPtr ); |
|
240 |
|
241 iPlugin->Stop( CHsContentPublisher::ESystemShutdown ); |
|
242 iPlugin->SetProperty( CHsContentPublisher::ECpsCmdBuffer, NULL ); |
|
243 EUNIT_ASSERT_SPECIFIC_LEAVE( iPlugin->StartL( CHsContentPublisher::ESystemStartup ), KErrNotSupported ); |
|
244 |
|
245 anyPtr = iPlugin->GetProperty( CHsContentPublisher::ECpsCmdBuffer ); |
|
246 EUNIT_ASSERT( anyPtr == NULL ); |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // void MT_SapiDataPlugin::TestFreeEngineL() |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void MT_SapiDataPlugin::TestPublishL() |
|
254 { |
|
255 TInt cID1 = 1; |
|
256 TInt cID2 = 2; |
|
257 TBool founded = EFalse; |
|
258 TPtrC valPtr; |
|
259 valPtr.Set( KText ); |
|
260 |
|
261 iPlugin->PublishTextL( iContentObserver, cID1, valPtr ); |
|
262 |
|
263 HBufC* contentText = HBufC::NewLC(valPtr.Size()); |
|
264 TPtr cDes = contentText->Des(); |
|
265 cDes.Copy(valPtr); |
|
266 |
|
267 for (int i = 0; i < iPlugin->iDataArray.Count(); i++) |
|
268 if ( iPlugin->iDataArray[i] == *contentText ) |
|
269 { |
|
270 founded = ETrue; |
|
271 break; |
|
272 } |
|
273 |
|
274 EUNIT_ASSERT(founded); |
|
275 |
|
276 CleanupStack::Pop( contentText ); |
|
277 } |
|
278 |
|
279 // TEST TABLE |
|
280 |
|
281 EUNIT_BEGIN_TEST_TABLE |
|
282 ( |
|
283 MT_SapiDataPlugin, |
|
284 "SapiDataPlugin module tests", |
|
285 "MODULE" |
|
286 ) |
|
287 |
|
288 EUNIT_TEST |
|
289 ( |
|
290 "Activity", |
|
291 "SapiDataPlugin", |
|
292 "Stop, Resume", |
|
293 "FUNCTIONALITY", |
|
294 SetupL, TestActivity, Teardown |
|
295 ) |
|
296 |
|
297 EUNIT_TEST |
|
298 ( |
|
299 "Suspend", |
|
300 "SapiDataPlugin", |
|
301 "Suspend", |
|
302 "FUNCTIONALITY", |
|
303 SetupL, TestSuspendL, Teardown |
|
304 ) |
|
305 |
|
306 EUNIT_TEST |
|
307 ( |
|
308 "Test property", |
|
309 "SapiDataPlugin", |
|
310 "GetPropertyL, SetPropertyL", |
|
311 "FUNCTIONALITY", |
|
312 SetupL, TestPropertyL, Teardown |
|
313 ) |
|
314 |
|
315 EUNIT_TEST |
|
316 ( |
|
317 "Test publish", |
|
318 "SapiDataPlugin", |
|
319 "Publish", |
|
320 "FUNCTIONALITY", |
|
321 SetupL, TestPublishL, Teardown |
|
322 ) |
|
323 |
|
324 EUNIT_TEST |
|
325 ( |
|
326 "Test command buffer", |
|
327 "SapiDataPlugin", |
|
328 "CAiCpsCommandBuffer", |
|
329 "FUNCTIONALITY", |
|
330 SetupL, TestCommandBuffer, Teardown |
|
331 ) |
|
332 |
|
333 EUNIT_END_TEST_TABLE |
|
334 |
|
335 // END OF FILE |