|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS HEADER |
|
20 #include "MT_CFActionPlugIn.h" |
|
21 |
|
22 // EXTERNAL INCLUDES |
|
23 #include <EUnitMacros.h> |
|
24 #include <EUnitDecorators.h> |
|
25 #include <ECom/ECom.h> |
|
26 |
|
27 // INTERNAL INCLUDES |
|
28 #include <CFActionPlugin.h> |
|
29 #include <cfactionindication.h> |
|
30 #include "cfenvutils.h" |
|
31 |
|
32 // CONSTANTS |
|
33 const TUid KTestActionPluginImplementationUid = {0x10002003}; |
|
34 const TInt KSecDelay = 1000000; // 1 seconds |
|
35 |
|
36 _LIT( KTestActionIdTestAc3, "AC3" ); |
|
37 _LIT( KTestActionIdLeave, "AC_Leave" ); |
|
38 |
|
39 /** |
|
40 * Wait info. |
|
41 */ |
|
42 NONSHARABLE_CLASS( TWaitInfo ) |
|
43 { |
|
44 public: |
|
45 |
|
46 CPeriodic* iPeriodic; |
|
47 CActiveSchedulerWait* iWait; |
|
48 }; |
|
49 |
|
50 /** |
|
51 * Call back method when we need to stop active scheduler wait. |
|
52 */ |
|
53 LOCAL_C TInt WaitCallBack( TAny* aSelf ) |
|
54 { |
|
55 if( aSelf ) |
|
56 { |
|
57 TWaitInfo* info = static_cast<TWaitInfo*>( aSelf ); |
|
58 if( info->iPeriodic ) |
|
59 { |
|
60 info->iPeriodic->Cancel(); |
|
61 } |
|
62 if( info->iWait ) |
|
63 { |
|
64 if( info->iWait->IsStarted() ) |
|
65 { |
|
66 info->iWait->AsyncStop(); |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 return KErrNone; |
|
72 } |
|
73 |
|
74 /** |
|
75 * Helper method to wait current scheduler before teardown is completed. |
|
76 */ |
|
77 LOCAL_C void Wait( TInt aIntervalInMicorseconds ) |
|
78 { |
|
79 TWaitInfo info; |
|
80 |
|
81 // Construct periodic |
|
82 CPeriodic* periodic = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
83 CleanupStack::PushL( periodic ); |
|
84 info.iPeriodic = periodic; |
|
85 |
|
86 // Construct active scheduler wait |
|
87 CActiveSchedulerWait* wait = new( ELeave ) CActiveSchedulerWait; |
|
88 CleanupStack::PushL( wait ); |
|
89 info.iWait = wait; |
|
90 |
|
91 // Start timer and wait |
|
92 TCallBack cb( WaitCallBack, &info ); |
|
93 periodic->Start( aIntervalInMicorseconds, aIntervalInMicorseconds, cb ); |
|
94 wait->Start(); |
|
95 |
|
96 // Cleanup |
|
97 CleanupStack::PopAndDestroy( wait ); |
|
98 CleanupStack::PopAndDestroy( periodic ); |
|
99 } |
|
100 |
|
101 |
|
102 // CONSTRUCTION |
|
103 MT_CCFActionPlugIn* MT_CCFActionPlugIn::NewL() |
|
104 { |
|
105 MT_CCFActionPlugIn* self = MT_CCFActionPlugIn::NewLC(); |
|
106 CleanupStack::Pop(); |
|
107 |
|
108 return self; |
|
109 } |
|
110 |
|
111 MT_CCFActionPlugIn* MT_CCFActionPlugIn::NewLC() |
|
112 { |
|
113 MT_CCFActionPlugIn* self = new( ELeave ) MT_CCFActionPlugIn(); |
|
114 CleanupStack::PushL( self ); |
|
115 |
|
116 self->ConstructL(); |
|
117 |
|
118 return self; |
|
119 } |
|
120 |
|
121 // Destructor (virtual by CBase) |
|
122 MT_CCFActionPlugIn::~MT_CCFActionPlugIn() |
|
123 { |
|
124 // Enable screen saver |
|
125 CFEnvUtils::EnableScreenSaver( ETrue ); |
|
126 } |
|
127 |
|
128 // Default constructor |
|
129 MT_CCFActionPlugIn::MT_CCFActionPlugIn() |
|
130 { |
|
131 } |
|
132 |
|
133 // Second phase construct |
|
134 void MT_CCFActionPlugIn::ConstructL() |
|
135 { |
|
136 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
137 // It generates the test case table. |
|
138 CEUnitTestSuiteClass::ConstructL(); |
|
139 |
|
140 // Disable screen saver |
|
141 CFEnvUtils::EnableScreenSaver( EFalse ); |
|
142 } |
|
143 |
|
144 // METHODS |
|
145 |
|
146 |
|
147 void MT_CCFActionPlugIn::SetupL( ) |
|
148 { |
|
149 iCCFActionPlugIn = CCFActionPlugIn::NewL( KTestActionPluginImplementationUid ); |
|
150 iCCFActionPlugIn->InitializeL(); |
|
151 } |
|
152 |
|
153 void MT_CCFActionPlugIn::SetupEmptyL( ) |
|
154 { |
|
155 } |
|
156 |
|
157 void MT_CCFActionPlugIn::Teardown( ) |
|
158 { |
|
159 delete iCCFActionPlugIn; |
|
160 iCCFActionPlugIn = NULL; |
|
161 |
|
162 Wait( KSecDelay * 1 ); |
|
163 |
|
164 #ifdef __WINS__ |
|
165 REComSession::FinalClose(); |
|
166 #endif |
|
167 } |
|
168 |
|
169 void MT_CCFActionPlugIn::TeardownEmpty( ) |
|
170 { |
|
171 #ifdef __WINS__ |
|
172 REComSession::FinalClose(); |
|
173 #endif |
|
174 } |
|
175 |
|
176 void MT_CCFActionPlugIn::MT_CCFActionPlugIn_NewL( ) |
|
177 { |
|
178 CCFActionPlugIn* obj = CCFActionPlugIn::NewL( KTestActionPluginImplementationUid ); |
|
179 CleanupStack::PushL( obj ); |
|
180 |
|
181 EUNIT_ASSERT_DESC( obj, "Instance not created"); |
|
182 |
|
183 CleanupStack::PopAndDestroy( obj ); |
|
184 |
|
185 Wait( KSecDelay * 1 ); |
|
186 } |
|
187 |
|
188 void MT_CCFActionPlugIn::MT_CCFActionPlugIn_NewLC( ) |
|
189 { |
|
190 CCFActionPlugIn* obj = CCFActionPlugIn::NewLC( KTestActionPluginImplementationUid ); |
|
191 |
|
192 EUNIT_ASSERT_DESC( obj, "Instance not created"); |
|
193 |
|
194 CleanupStack::PopAndDestroy( obj ); |
|
195 |
|
196 Wait( KSecDelay * 1 ); |
|
197 } |
|
198 |
|
199 void MT_CCFActionPlugIn::MT_CCFActionPlugIn_AsyncExecutionCompletedL( ) |
|
200 { |
|
201 CCFActionIndication* actionIndication = CCFActionIndication::NewLC(); |
|
202 actionIndication->SetIdentifierL( KTestActionIdTestAc3 ); |
|
203 |
|
204 // Execute test |
|
205 EUNIT_ASSERT_NO_LEAVE( iCCFActionPlugIn->PrepareExecutionL() ); |
|
206 EUNIT_ASSERT_NO_LEAVE( iCCFActionPlugIn->ExecuteL( actionIndication ) ); |
|
207 Wait( KSecDelay * 5 ); |
|
208 iCCFActionPlugIn->FinishedExecution(); |
|
209 |
|
210 // Clean up |
|
211 CleanupStack::PopAndDestroy( actionIndication ); |
|
212 } |
|
213 |
|
214 void MT_CCFActionPlugIn::MT_CCFActionPlugIn_PrepareExecutionLL( ) |
|
215 { |
|
216 EUNIT_ASSERT_NO_LEAVE( iCCFActionPlugIn->PrepareExecutionL( ) ); |
|
217 } |
|
218 |
|
219 void MT_CCFActionPlugIn::MT_CCFActionPlugIn_FinishedExecutionL( ) |
|
220 { |
|
221 iCCFActionPlugIn->FinishedExecution( ); |
|
222 } |
|
223 |
|
224 void MT_CCFActionPlugIn::MT_CCFActionPlugIn_ExtensionL( ) |
|
225 { |
|
226 const TUid KSomeUid = {0x12345678}; |
|
227 TAny* interface = iCCFActionPlugIn->Extension( KSomeUid ); |
|
228 EUNIT_ASSERT_DESC( !interface, "Invalid interface returned"); |
|
229 } |
|
230 |
|
231 void MT_CCFActionPlugIn::MT_CCFActionPlugIn_ExecuteLL( ) |
|
232 { |
|
233 CCFActionIndication* actionIndication = NULL; |
|
234 |
|
235 actionIndication = CCFActionIndication::NewLC(); |
|
236 actionIndication->SetIdentifierL( KTestActionIdLeave ); |
|
237 EUNIT_ASSERT_NO_LEAVE( iCCFActionPlugIn->PrepareExecutionL() ); |
|
238 EUNIT_ASSERT_SPECIFIC_LEAVE( iCCFActionPlugIn->ExecuteL( actionIndication ), KErrArgument ); |
|
239 CleanupStack::PopAndDestroy( actionIndication ); |
|
240 |
|
241 actionIndication = CCFActionIndication::NewLC(); |
|
242 actionIndication->SetIdentifierL( KTestActionIdTestAc3 ); |
|
243 EUNIT_ASSERT_NO_LEAVE( iCCFActionPlugIn->PrepareExecutionL() ); |
|
244 EUNIT_ASSERT_NO_LEAVE( iCCFActionPlugIn->ExecuteL( actionIndication ) ); |
|
245 Wait( KSecDelay * 5 ); |
|
246 iCCFActionPlugIn->FinishedExecution(); |
|
247 CleanupStack::PopAndDestroy( actionIndication ); |
|
248 } |
|
249 |
|
250 void MT_CCFActionPlugIn::MT_CCFActionPlugIn_GetActionsLL( ) |
|
251 { |
|
252 CDesCArrayFlat* actions = new( ELeave ) CDesCArrayFlat( 10 ); |
|
253 CleanupStack::PushL( actions ); |
|
254 EUNIT_ASSERT_NO_LEAVE( iCCFActionPlugIn->GetActionsL( *actions ) ); |
|
255 TInt count = actions->Count(); |
|
256 EUNIT_ASSERT_DESC( count == 2, "Invalid action count" ); |
|
257 for( TInt i = 0; i < count; i++ ) |
|
258 { |
|
259 TPtrC action( (*actions)[i] ); |
|
260 EUNIT_ASSERT_DESC( action == KTestActionIdLeave || action == KTestActionIdTestAc3, "Invalid action" ); |
|
261 } |
|
262 CleanupStack::PopAndDestroy( actions ); |
|
263 } |
|
264 |
|
265 void MT_CCFActionPlugIn::MT_CCFActionPlugIn_SecurityPolicyL( ) |
|
266 { |
|
267 iCCFActionPlugIn->SecurityPolicy(); |
|
268 } |
|
269 |
|
270 |
|
271 // TEST TABLE |
|
272 EUNIT_BEGIN_TEST_TABLE( |
|
273 MT_CCFActionPlugIn, |
|
274 "Add test suite description here.", |
|
275 "UNIT" ) |
|
276 |
|
277 EUNIT_TEST( |
|
278 "NewL", |
|
279 "CCFActionPlugIn", |
|
280 "NewL", |
|
281 "FUNCTIONALITY", |
|
282 SetupEmptyL, MT_CCFActionPlugIn_NewL, TeardownEmpty) |
|
283 |
|
284 EUNIT_TEST( |
|
285 "NewLC", |
|
286 "CCFActionPlugIn", |
|
287 "NewLC", |
|
288 "FUNCTIONALITY", |
|
289 SetupEmptyL, MT_CCFActionPlugIn_NewLC, TeardownEmpty) |
|
290 |
|
291 EUNIT_TEST( |
|
292 "AsyncExecutionCompleted", |
|
293 "CCFActionPlugIn", |
|
294 "AsyncExecutionCompleted", |
|
295 "FUNCTIONALITY", |
|
296 SetupL, MT_CCFActionPlugIn_AsyncExecutionCompletedL, Teardown) |
|
297 |
|
298 EUNIT_TEST( |
|
299 "PrepareExecutionL", |
|
300 "CCFActionPlugIn", |
|
301 "PrepareExecutionL", |
|
302 "FUNCTIONALITY", |
|
303 SetupL, MT_CCFActionPlugIn_PrepareExecutionLL, Teardown) |
|
304 |
|
305 EUNIT_TEST( |
|
306 "FinishedExecution", |
|
307 "CCFActionPlugIn", |
|
308 "FinishedExecution", |
|
309 "FUNCTIONALITY", |
|
310 SetupL, MT_CCFActionPlugIn_FinishedExecutionL, Teardown) |
|
311 |
|
312 EUNIT_TEST( |
|
313 "Extension", |
|
314 "CCFActionPlugIn", |
|
315 "Extension", |
|
316 "FUNCTIONALITY", |
|
317 SetupL, MT_CCFActionPlugIn_ExtensionL, Teardown) |
|
318 |
|
319 EUNIT_TEST( |
|
320 "ExecuteL", |
|
321 "CCFActionPlugIn", |
|
322 "ExecuteL", |
|
323 "FUNCTIONALITY", |
|
324 SetupL, MT_CCFActionPlugIn_ExecuteLL, Teardown) |
|
325 |
|
326 EUNIT_TEST( |
|
327 "GetActionsL", |
|
328 "CCFActionPlugIn", |
|
329 "GetActionsL", |
|
330 "FUNCTIONALITY", |
|
331 SetupL, MT_CCFActionPlugIn_GetActionsLL, Teardown) |
|
332 |
|
333 EUNIT_TEST( |
|
334 "SecurityPolicy", |
|
335 "CCFActionPlugIn", |
|
336 "SecurityPolicy", |
|
337 "FUNCTIONALITY", |
|
338 SetupL, MT_CCFActionPlugIn_SecurityPolicyL, Teardown) |
|
339 |
|
340 |
|
341 EUNIT_END_TEST_TABLE |
|
342 |
|
343 // END OF FILE |