1 /* |
|
2 * Copyright (c) 2009 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: For packing VMBXEngine test component. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <stiftestinterface.h> |
|
21 #include <stifparser.h> |
|
22 #include <e32math.h> |
|
23 #include <centralrepository.h> |
|
24 #include <cenrepnotifyhandler.h> |
|
25 |
|
26 #include "vmnumber.h" |
|
27 #include "vmbxenginetest.h" |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 const TUid KUidVoiceMailbox = {0x101F874F}; |
|
32 const TUint32 KVmUIKeyOpts = 0x00000010; |
|
33 |
|
34 |
|
35 const TInt KVmUIKeyOptsForSimOnly = 1; |
|
36 const TInt KVmDefaultUIKeyOpts = 0; |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // C++ default constructor can NOT contain any code, that |
|
40 // might leave. |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CVmbxEngineTest::CVmbxEngineTest( CTestModuleIf& aTestModuleIf ) : |
|
44 CScriptBase( aTestModuleIf ), iSession( NULL ), iNotifyHandler( NULL ) |
|
45 { |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // ConstructL |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 void CVmbxEngineTest::ConstructL() |
|
53 { |
|
54 // Constructing static buffer size logger, needed with OOM testing because |
|
55 // normally logger allocates memory from heap! |
|
56 iLog = CStifLogger::NewL( KLogPath, |
|
57 KLogFile, |
|
58 CStifLogger::ETxt, |
|
59 CStifLogger::EFile, |
|
60 EFalse, |
|
61 ETrue, |
|
62 ETrue, |
|
63 EFalse, |
|
64 ETrue, |
|
65 EFalse, |
|
66 100 ); |
|
67 iLog->Log( _L( "CVmbxEngineTest logging starts!" ) ); |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // NewL creates a new test module |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CVmbxEngineTest* CVmbxEngineTest::NewL( CTestModuleIf& aTestModuleIf ) |
|
75 { |
|
76 CVmbxEngineTest* self = new ( ELeave ) CVmbxEngineTest( aTestModuleIf ); |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop(); |
|
80 return self; |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // Destructor |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CVmbxEngineTest::~CVmbxEngineTest() |
|
88 { |
|
89 if ( iLog ) |
|
90 { |
|
91 iLog->Log( _L( "###### TEST MODULE CLOSED #######" ) ); |
|
92 delete iLog; |
|
93 } |
|
94 |
|
95 delete iVmbxNumber; |
|
96 |
|
97 if ( iNotifyHandler ) |
|
98 { |
|
99 iNotifyHandler->StopListening(); |
|
100 delete iNotifyHandler; |
|
101 } |
|
102 |
|
103 delete iSession; |
|
104 delete iNumberBuf; |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // From class CScriptBase. |
|
109 // Runs a script line |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 TInt CVmbxEngineTest::RunMethodL( CStifItemParser& aItem ) |
|
113 { |
|
114 static TStifFunctionInfo const KFunctions[] = |
|
115 { |
|
116 ENTRY( "Connect", CVmbxEngineTest::Connect ), |
|
117 ENTRY( "Close", CVmbxEngineTest::Close ), |
|
118 // test RVmbxNumber APIs |
|
119 ENTRY( "AllowedToChangeTheNumber", |
|
120 CVmbxEngineTest::AllowedToChangeTheNumber ), |
|
121 ENTRY( "SelectTypeL", CVmbxEngineTest::SelectTypeL ), |
|
122 ENTRY( "IsSimMemory", CVmbxEngineTest::IsSimMemory ), |
|
123 ENTRY( "QueryVideoMbxNumber", CVmbxEngineTest::QueryVideoMbxNumber ), |
|
124 ENTRY( "QueryNumberL", CVmbxEngineTest::QueryNumberL ), |
|
125 ENTRY( "GetVideoMbxNumber", CVmbxEngineTest::GetVideoMbxNumber ), |
|
126 ENTRY( "ConfCenRepForEditNotAllowedL", |
|
127 CVmbxEngineTest::ConfCenRepForEditNotAllowedL ), |
|
128 ENTRY( "RevertCenRepEditNotAllowedL", |
|
129 CVmbxEngineTest::RevertCenRepEditNotAllowedL ), |
|
130 ENTRY( "ConfCenRepForEditAllowedL", |
|
131 CVmbxEngineTest::ConfCenRepForEditAllowedL ), |
|
132 ENTRY( "InitGetNumFromSpecialMem", |
|
133 CVmbxEngineTest::InitGetNumFromSpecialMem ), |
|
134 ENTRY( "TestGetNumFromSpecialMem", |
|
135 CVmbxEngineTest::TestGetNumFromSpecialMem ), |
|
136 ENTRY( "CleanupGetNumFromSpecialMem", |
|
137 CVmbxEngineTest::CleanupGetNumFromSpecialMem ) |
|
138 }; |
|
139 |
|
140 const TInt count = sizeof( KFunctions ) / |
|
141 sizeof( TStifFunctionInfo ); |
|
142 |
|
143 return RunInternalL( KFunctions, count, aItem ); |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // Calls CVmbxEngineTest::Connect method |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CVmbxEngineTest::Connect( CStifItemParser& /*aItem*/ ) |
|
151 { |
|
152 TInt error = KErrAlreadyExists; |
|
153 if ( !iVmbxNumber ) |
|
154 { |
|
155 iVmbxNumber = new RVmbxNumber(); |
|
156 if ( iVmbxNumber ) |
|
157 { |
|
158 iLog->Log( _L( "Opening.." ) ); |
|
159 error = iVmbxNumber->Open(); |
|
160 if ( KErrNone == error ) |
|
161 { |
|
162 // save the source number temporarily |
|
163 // so that it will be used while some cases are reverted. |
|
164 SaveSourceNumber(); |
|
165 } |
|
166 } |
|
167 } |
|
168 iLog->Log( _L( "Connecting done, %d" ), error ); |
|
169 return error; |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // Calls CVmbxEngineTest::Close method |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 TInt CVmbxEngineTest::Close( CStifItemParser& /*aItem*/ ) |
|
177 { |
|
178 iLog->Log( _L( "Closing.." ) ); |
|
179 |
|
180 if ( iVmbxNumber ) |
|
181 { |
|
182 iVmbxNumber->Close(); |
|
183 delete iVmbxNumber; |
|
184 iVmbxNumber = NULL; |
|
185 |
|
186 if ( iNumberBuf ) |
|
187 { |
|
188 delete iNumberBuf; |
|
189 iNumberBuf = NULL; |
|
190 } |
|
191 } |
|
192 return KErrNone; |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CVmbxEngineTest::AllowedToChangeTheNumber method |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 TInt CVmbxEngineTest::AllowedToChangeTheNumber( CStifItemParser& /*aItem*/ ) |
|
200 { |
|
201 TInt result( KErrNone ); |
|
202 result = iVmbxNumber->AllowedToChangeTheNumber(); |
|
203 |
|
204 iLog->Log( _L( "AllowedToChangeTheNumber return %d" ), result); |
|
205 return result; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // CVmbxEngineTest::SelectTypeL method |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 TInt CVmbxEngineTest::SelectTypeL( CStifItemParser& /*aItem*/ ) |
|
213 { |
|
214 TInt result( KErrNone ); |
|
215 TRAP( result, iVmbxNumber->SelectTypeL( EVmbxDefine ) ); |
|
216 |
|
217 iLog->Log( _L( "SelectTypeL return result %d" ), result ); |
|
218 return result; |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // CVmbxEngineTest::IsSimMemory method |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 TInt CVmbxEngineTest::IsSimMemory( CStifItemParser& /*aItem*/ ) |
|
226 { |
|
227 // Use allownextresult keyword in config file to control what is expected |
|
228 // return value in your test case. |
|
229 TInt result( KErrNone ); |
|
230 result = iVmbxNumber->IsSimMemory(); |
|
231 iLog->Log( _L( "IsSimMemory return %d" ), result ); |
|
232 return result; |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // CVmbxEngineTest::QueryVideoMbxNumber method |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 TInt CVmbxEngineTest::QueryVideoMbxNumber( CStifItemParser& aItem ) |
|
240 { |
|
241 // Use allownextresult keyword in config file to control what is expected |
|
242 // return value in your test case. |
|
243 TInt result( KErrNone ); |
|
244 TBuf< KVmbxMaxNumberLength > number; |
|
245 |
|
246 TInt queryType( KErrNone ); |
|
247 aItem.GetNextInt( queryType ); |
|
248 |
|
249 TRAP( result, iVmbxNumber->QueryVideoMbxNumberL( |
|
250 ( TVmbxQueryType )queryType, number ) ); |
|
251 |
|
252 iLog->Log( _L( "QueryVideoMbxNumber return %d" ), result ); |
|
253 return result; |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // CVmbxEngineTest::QueryNumberL method |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 TInt CVmbxEngineTest::QueryNumberL( CStifItemParser& aItem ) |
|
261 { |
|
262 // Use allownextresult keyword in config file to control what is expected |
|
263 // return value in your test case. |
|
264 TInt result( KErrNone ); |
|
265 TBuf< KVmbxMaxNumberLength > number; |
|
266 |
|
267 TInt queryType( KErrNone ); |
|
268 aItem.GetNextInt( queryType ); |
|
269 |
|
270 TRAP( result, iVmbxNumber->QueryNumberL( ( TVmbxQueryType )queryType, |
|
271 number, EFalse ) ); |
|
272 |
|
273 iLog->Log( _L( "QueryNumberL return %d" ), result ); |
|
274 return result; |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // CVmbxEngineTest::GetVideoMbxNumber method |
|
279 // --------------------------------------------------------------------------- |
|
280 // |
|
281 TInt CVmbxEngineTest::GetVideoMbxNumber( CStifItemParser& /*aItem*/ ) |
|
282 { |
|
283 // Use allownextresult keyword in config file to control what is expected |
|
284 // return value in your test case. |
|
285 TInt result( KErrNone ); |
|
286 TBuf< KVmbxMaxNumberLength > number; |
|
287 |
|
288 result = iVmbxNumber->GetVideoMbxNumber( number ); |
|
289 |
|
290 iLog->Log( _L( "GetVideoMbxNumber return %d" ), result ); |
|
291 return result; |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------------------------- |
|
295 // Calls CVmbxEngineTest::ConfCenRepForEditNotAllowedL method |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 TInt CVmbxEngineTest::ConfCenRepForEditNotAllowedL( CStifItemParser& /*aItem*/ ) |
|
299 { |
|
300 TInt ret( KErrNone ); |
|
301 // create central repository for session and handler |
|
302 CreateCentralRepositoryL(); |
|
303 |
|
304 // configurate the key for the special condition like "sim only" |
|
305 ret = iSession->Set( KVmUIKeyOpts, KVmUIKeyOptsForSimOnly ); |
|
306 |
|
307 iLog->Log( _L( "ConfCenRepForEditNotAllowedL %d" ), ret ); |
|
308 return ret; |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // Calls CVmbxEngineTest::RevertCenRepEditNotAllowedL method |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 TInt CVmbxEngineTest::RevertCenRepEditNotAllowedL( CStifItemParser& /*aItem*/ ) |
|
316 { |
|
317 TInt ret( KErrNone ); |
|
318 // reset the key to default value |
|
319 ret = iSession->Set( KVmUIKeyOpts, KVmDefaultUIKeyOpts ); |
|
320 iLog->Log( _L( "RevertCenRepEditNotAllowedL %d" ), ret ); |
|
321 return ret; |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------------------------- |
|
325 // Calls CVmbxEngineTest::ConfCenRepForEditAllowedL method |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 TInt CVmbxEngineTest::ConfCenRepForEditAllowedL( CStifItemParser& /*aItem*/ ) |
|
329 { |
|
330 TInt ret( KErrNone ); |
|
331 // create central repository for session and handler |
|
332 CreateCentralRepositoryL(); |
|
333 |
|
334 // configurate the key for the special condition like "sim only" |
|
335 ret = iSession->Set( KVmUIKeyOpts, KVmDefaultUIKeyOpts ); |
|
336 |
|
337 iLog->Log( _L( "ConfCenRepForEditAllowedL %d" ), ret ); |
|
338 return ret; |
|
339 } |
|
340 |
|
341 // --------------------------------------------------------------------------- |
|
342 // Calls CVmbxEngineTest::InitGetNumFromSpecialMem method |
|
343 // --------------------------------------------------------------------------- |
|
344 // |
|
345 TInt CVmbxEngineTest::InitGetNumFromSpecialMem( CStifItemParser& aItem ) |
|
346 { |
|
347 TInt ret( KErrNone ); |
|
348 |
|
349 // Get number from Script file |
|
350 TPtrC numberFromScript; |
|
351 aItem.GetNextString( numberFromScript ); |
|
352 iLog->Log( _L( "InitGetNumFromSpecialMem saving number %S" ), |
|
353 &numberFromScript ); |
|
354 |
|
355 // the number need to be saved to the sim/phone memory |
|
356 // to init the special case |
|
357 ret = iVmbxNumber->SaveVmbxNumber( numberFromScript, |
|
358 EAlsActiveLineEntry ); |
|
359 |
|
360 iLog->Log( _L( "InitGetNumFromSpecialMem return %d" ), ret ); |
|
361 return ret; |
|
362 } |
|
363 |
|
364 // --------------------------------------------------------------------------- |
|
365 // Calls CVmbxEngineTest::TestGetNumFromSpecialMem method |
|
366 // --------------------------------------------------------------------------- |
|
367 // |
|
368 TInt CVmbxEngineTest::TestGetNumFromSpecialMem( CStifItemParser& aItem ) |
|
369 { |
|
370 TInt ret( KErrNotFound ); |
|
371 TBuf< KVmbxMaxNumberLength > number; |
|
372 // Use allownextresult keyword in config file to control what is expected |
|
373 // return value in your test case. |
|
374 |
|
375 TPtrC numberFromScript; |
|
376 aItem.GetNextString( numberFromScript ); |
|
377 iLog->Log( _L( "TestGetNumFromSpecialMem saving number %S" ), |
|
378 &numberFromScript ); |
|
379 |
|
380 ret = iVmbxNumber->GetVmbxNumber( number ); |
|
381 if ( KErrNone == ret && KErrNone == number.Compare( numberFromScript ) ) |
|
382 { |
|
383 ret = KErrNone; |
|
384 } |
|
385 |
|
386 iLog->Log( _L( "TestGetNumFromSpecialMem number %S" ), &number ); |
|
387 iLog->Log( _L( "TestGetNumFromSpecialMem return %d" ), ret ); |
|
388 return ret; |
|
389 } |
|
390 |
|
391 // --------------------------------------------------------------------------- |
|
392 // Calls CVmbxEngineTest::CleanupGetNumFromSpecialMem method |
|
393 // --------------------------------------------------------------------------- |
|
394 // |
|
395 TInt CVmbxEngineTest::CleanupGetNumFromSpecialMem( CStifItemParser& /*aItem*/ ) |
|
396 { |
|
397 TInt ret( KErrNone ); |
|
398 // revert the source number to sim/phone memory |
|
399 ret = iVmbxNumber->SaveVmbxNumber( *iNumberBuf, |
|
400 EAlsActiveLineEntry ); |
|
401 |
|
402 iLog->Log( _L( "CleanupGetNumFromSpecialMem return %d" ), ret ); |
|
403 return ret; |
|
404 } |
|
405 |
|
406 // --------------------------------------------------------------------------- |
|
407 // Save the source number temporarily |
|
408 // --------------------------------------------------------------------------- |
|
409 // |
|
410 void CVmbxEngineTest::SaveSourceNumber() |
|
411 { |
|
412 iNumberBuf = HBufC::New( KVmbxMaxNumberLength ); |
|
413 if ( iNumberBuf ) |
|
414 { |
|
415 TPtr ptr( iNumberBuf->Des() ); |
|
416 iVmbxNumber->GetVmbxNumber( ptr ); |
|
417 } |
|
418 } |
|
419 |
|
420 // --------------------------------------------------------------------------- |
|
421 // Create central repository for session and handler |
|
422 // --------------------------------------------------------------------------- |
|
423 // |
|
424 void CVmbxEngineTest::CreateCentralRepositoryL() |
|
425 { |
|
426 if ( !iSession ) |
|
427 { |
|
428 // create central repository |
|
429 iSession = CRepository::NewL( KUidVoiceMailbox ); |
|
430 } |
|
431 |
|
432 if ( !iNotifyHandler ) |
|
433 { |
|
434 // set notify handler, when the key had been changed |
|
435 // in the whole repository |
|
436 iNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iSession ); |
|
437 if ( iNotifyHandler ) |
|
438 { |
|
439 iNotifyHandler->StartListeningL(); |
|
440 } |
|
441 } |
|
442 } |
|
443 |
|
444 // ======== GLOBAL FUNCTIONS ======== |
|
445 // ----------------------------------------------------------------------------- |
|
446 // LibEntryL is a polymorphic Dll entry point |
|
447 // Returns: CScriptBase*: Pointer to Test Module object |
|
448 // ----------------------------------------------------------------------------- |
|
449 // |
|
450 EXPORT_C CScriptBase* LibEntryL( CTestModuleIf& aTestModuleIf ) |
|
451 { |
|
452 return CVmbxEngineTest::NewL( aTestModuleIf ); |
|
453 } |
|