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 // [INCLUDE FILES] - do not remove |
|
19 #include <e32svr.h> |
|
20 #include <StifParser.h> |
|
21 #include <Stiftestinterface.h> |
|
22 #include "UsbPersonalityPluginTest.h" |
|
23 #include "testdebug.h" |
|
24 #include <ecom/ecom.h> |
|
25 |
|
26 // EXTERNAL DATA STRUCTURES |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 const TInt KIdPCSuite = 5; |
|
33 const TInt KIdMediaTransfer = 4; |
|
34 const TInt KIdMassStorage = 2; |
|
35 |
|
36 const TUid KUidPCSuite = |
|
37 { |
|
38 0x102068DF |
|
39 }; |
|
40 const TUid KUidMediaTransfer = |
|
41 { |
|
42 0x10282C70 |
|
43 }; |
|
44 //const TUid KUidPCSuite2 = |
|
45 // { |
|
46 // 0x2000B5D2 |
|
47 // }; |
|
48 //const TUid KUidPhoneAsModem = |
|
49 // { |
|
50 // 0x20029E41 |
|
51 // }; |
|
52 const TUid KUidMassStorage = |
|
53 { |
|
54 0x1020DF7B |
|
55 }; |
|
56 |
|
57 // MACROS |
|
58 |
|
59 // LOCAL CONSTANTS AND MACROS |
|
60 |
|
61 // MODULE DATA STRUCTURES |
|
62 |
|
63 // LOCAL FUNCTION PROTOTYPES |
|
64 |
|
65 // FORWARD DECLARATIONS |
|
66 |
|
67 // ============================= LOCAL FUNCTIONS =============================== |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // ----------------------------------------------------------------------------- |
|
71 |
|
72 // ============================ MEMBER FUNCTIONS =============================== |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CUsbPersonalityPluginTest::TestConstructL |
|
76 // Construct here all test resources for test methods. |
|
77 // Called from ConstructL. |
|
78 // ----------------------------------------------------------------------------- |
|
79 |
|
80 void CUsbPersonalityPluginTest::TestConstructL() |
|
81 { |
|
82 TRACE_FUNC_ENTRY |
|
83 |
|
84 iUsbMan = new (ELeave) RUsb; |
|
85 iUsbMan->Connect(); |
|
86 iNotifier = CUsbPersonalityNotifier::NewL(); |
|
87 iParams = new (ELeave) TUsbPersonalityParams(*iUsbMan, *iNotifier); |
|
88 |
|
89 TRACE_FUNC_EXIT |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CUsbPersonalityPluginTest::TestDelete |
|
94 // Delete here all resources allocated and opened from test methods. |
|
95 // Called from destructor. |
|
96 // ----------------------------------------------------------------------------- |
|
97 |
|
98 void CUsbPersonalityPluginTest::TestDelete() |
|
99 { |
|
100 TRACE_FUNC_ENTRY |
|
101 |
|
102 if (iUsbMan) |
|
103 { |
|
104 iUsbMan->Close(); |
|
105 delete iUsbMan; |
|
106 iUsbMan = NULL; |
|
107 } |
|
108 if (iNotifier) |
|
109 { |
|
110 delete iNotifier; |
|
111 iNotifier = NULL; |
|
112 } |
|
113 if (iParams) |
|
114 { |
|
115 delete iParams; |
|
116 iParams = NULL; |
|
117 } |
|
118 if (iPlugin) |
|
119 { |
|
120 delete iPlugin; |
|
121 iPlugin = NULL; |
|
122 } |
|
123 |
|
124 REComSession::FinalClose(); |
|
125 |
|
126 TRACE_FUNC_EXIT |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CUsbPersonalityPluginTest::TestBlocksInfoL |
|
131 // Add new test block parameter entries below |
|
132 // ----------------------------------------------------------------------------- |
|
133 |
|
134 void CUsbPersonalityPluginTest::TestBlocksInfoL() |
|
135 { |
|
136 |
|
137 TESTENTRY( "InitializationTestL", CUsbPersonalityPluginTest::InitializationTestL ) |
|
138 { |
|
139 TESTPARAM( eGetString, eTestOption1 ) |
|
140 } |
|
141 TESTENTRY( "SetPersonalityTestL", CUsbPersonalityPluginTest::SetPersonalityTestL ) |
|
142 { |
|
143 TESTPARAM( eGetString, eTestOption1 ) |
|
144 TESTPARAM( eGetString, eTestOption2 ) |
|
145 } |
|
146 TESTENTRY( "ShowQueryTestL", CUsbPersonalityPluginTest::ShowQueryTestL ) |
|
147 { |
|
148 TESTPARAM( eGetString, eTestOption1 ) |
|
149 } |
|
150 TESTENTRY( "ShowConnectionNoteTestL", CUsbPersonalityPluginTest::ShowConnectionNoteTestL ) |
|
151 { |
|
152 TESTPARAM( eGetString, eTestOption1 ) |
|
153 TESTPARAM( eGetString, eTestOption2 ) |
|
154 } |
|
155 TESTENTRY( "CreatePersonalityPluginTestL", CUsbPersonalityPluginTest::CreatePersonalityPluginTestL ) |
|
156 { |
|
157 TESTPARAM( eGetString, eTestOption1 ) |
|
158 TESTPARAM( eGetString, eTestOption2 ) |
|
159 } |
|
160 TESTENTRY( "PreparePersonalityStartTestL", CUsbPersonalityPluginTest::PreparePersonalityStartTestL ) |
|
161 { |
|
162 TESTPARAM( eGetString, eTestOption1 ) |
|
163 TESTPARAM( eGetString, eTestOption2 ) |
|
164 } |
|
165 TESTENTRY( "FinishPersonalityStartTestL", CUsbPersonalityPluginTest::FinishPersonalityStartTestL ) |
|
166 { |
|
167 TESTPARAM( eGetString, eTestOption1 ) |
|
168 TESTPARAM( eGetString, eTestOption2 ) |
|
169 } |
|
170 TESTENTRY( "PreparePersonalityStopTestL", CUsbPersonalityPluginTest::PreparePersonalityStopTestL ) |
|
171 { |
|
172 TESTPARAM( eGetString, eTestOption1 ) |
|
173 TESTPARAM( eGetString, eTestOption2 ) |
|
174 } |
|
175 TESTENTRY( "FinishPersonalityStopTestL", CUsbPersonalityPluginTest::FinishPersonalityStopTestL ) |
|
176 { |
|
177 TESTPARAM( eGetString, eTestOption1 ) |
|
178 TESTPARAM( eGetString, eTestOption2 ) |
|
179 } |
|
180 } |
|
181 |
|
182 // Add test block methods implementation here |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CUsbPersonalityPluginTest::ExampleTestL |
|
185 // ----------------------------------------------------------------------------- |
|
186 |
|
187 void CUsbPersonalityPluginTest::ExampleTestL( |
|
188 TUsbPersonalityPluginTestBlockParams& aParams, |
|
189 TUsbPersonalityPluginTestResult& aTestResult) |
|
190 { |
|
191 TRACE_FUNC_ENTRY |
|
192 |
|
193 if (!aParams.iTestOption1.Compare(_L( "API" ))) |
|
194 { |
|
195 TRACE_INFO( "Api test option: %S", &aParams.iTestOption1 ) |
|
196 TRACE_INFO( "Api test sub-option: %S", &aParams.iTestOption2 ) |
|
197 TRACE_INFO( "Api test int option: %d", aParams.iTestIntOption1 ) |
|
198 TRACE_INFO( "Api test char option: %c", TText( aParams.iTestCharOption1 ) ) |
|
199 } |
|
200 else if (!aParams.iTestOption1.Compare(_L( "MODULE" ))) |
|
201 { |
|
202 TRACE_INFO( "Module test option: %S", &aParams.iTestOption1 ) |
|
203 TRACE_INFO( "Module test sub-option: %S", &aParams.iTestOption2 ) |
|
204 TRACE_INFO( "Module test int option: %d", aParams.iTestIntOption1 ) |
|
205 TRACE_INFO( "Module test char option: %c", TText( aParams.iTestCharOption1 ) ) |
|
206 } |
|
207 else if (!aParams.iTestOption1.Compare(_L( "BRANCH" ))) |
|
208 { |
|
209 TRACE_INFO( "Branch test option: %S", &aParams.iTestOption1 ) |
|
210 TRACE_INFO( "Branch test sub-option: %S", &aParams.iTestOption2 ) |
|
211 TRACE_INFO( "Branch test int option: %d", aParams.iTestIntOption1 ) |
|
212 TRACE_INFO( "Branch test char option: %c", TText( aParams.iTestCharOption1 ) ) |
|
213 } |
|
214 else |
|
215 { |
|
216 TRACE( "Invalid test parameter" ) |
|
217 TRACE_FUNC_EXIT |
|
218 User::Leave(KErrNotFound); |
|
219 } |
|
220 |
|
221 aTestResult = ETestCasePassed; |
|
222 TRACE_FUNC_EXIT |
|
223 } |
|
224 |
|
225 // Add other member functions implementation here |
|
226 void CUsbPersonalityPluginTest::InitializeTestObjectsL() |
|
227 { |
|
228 iActive = CUsbPersonalityPluginActiveObject::NewL(iPlugin, iLog, iParams); |
|
229 TRACE ( " test objects initialized " ); |
|
230 } |
|
231 |
|
232 void CUsbPersonalityPluginTest::DeleteTestObjects() |
|
233 { |
|
234 delete iActive; |
|
235 iActive = NULL; |
|
236 } |
|
237 |
|
238 void CUsbPersonalityPluginTest::InitializationTestL( |
|
239 TUsbPersonalityPluginTestBlockParams& aParams, |
|
240 TUsbPersonalityPluginTestResult& aTestResult) |
|
241 { |
|
242 TRACE_FUNC_ENTRY |
|
243 aTestResult = ETestCaseFailed; |
|
244 |
|
245 if (iNotifier) |
|
246 { |
|
247 aTestResult = ETestCasePassed; |
|
248 } |
|
249 |
|
250 TRACE_FUNC_EXIT |
|
251 } |
|
252 |
|
253 void CUsbPersonalityPluginTest::SetPersonalityTestL( |
|
254 TUsbPersonalityPluginTestBlockParams& aParams, |
|
255 TUsbPersonalityPluginTestResult& aTestResult) |
|
256 { |
|
257 TRACE_FUNC_ENTRY |
|
258 aTestResult = ETestCaseFailed; |
|
259 TInt id = GetIdFromString(aParams.iTestOption2); |
|
260 TRACE_INFO( " Set personality ID: %d", id ); |
|
261 |
|
262 iParams->SetPersonalityId(id); |
|
263 if (iParams->PersonalityId() == id) |
|
264 { |
|
265 aTestResult = ETestCasePassed; |
|
266 } |
|
267 |
|
268 TRACE_FUNC_EXIT |
|
269 } |
|
270 |
|
271 void CUsbPersonalityPluginTest::ShowQueryTestL( |
|
272 TUsbPersonalityPluginTestBlockParams& aParams, |
|
273 TUsbPersonalityPluginTestResult& aTestResult) |
|
274 { |
|
275 TRACE_FUNC_ENTRY |
|
276 aTestResult = ETestCaseFailed; |
|
277 |
|
278 TBuf8<8> iDummyBuf; |
|
279 |
|
280 TUSBQueriesNotifierParamsPckg queryParams; |
|
281 queryParams().iQuery = EUSBNotEnoughRam; |
|
282 |
|
283 TInt res = iNotifier->ShowQuery(KQueriesNotifier, queryParams, iDummyBuf); |
|
284 User::After(3000000); |
|
285 TRACE_INFO( " Query show ret %d ", res ) |
|
286 if (res == KErrNone) |
|
287 { |
|
288 aTestResult = ETestCasePassed; |
|
289 } |
|
290 |
|
291 TRACE_FUNC_EXIT |
|
292 } |
|
293 |
|
294 void CUsbPersonalityPluginTest::ShowConnectionNoteTestL( |
|
295 TUsbPersonalityPluginTestBlockParams& aParams, |
|
296 TUsbPersonalityPluginTestResult& aTestResult) |
|
297 { |
|
298 TRACE_FUNC_ENTRY |
|
299 aTestResult = ETestCaseFailed; |
|
300 |
|
301 TBuf8<8> iDummyBuf; |
|
302 |
|
303 TUSBConnectionNotifierParamsPckg noteParams; |
|
304 // noteParams().iPersonalityId = personalityId; |
|
305 |
|
306 TInt res = iNotifier->ShowQuery(KCableConnectedNotifierUid, noteParams, |
|
307 iDummyBuf); |
|
308 User::After(3000000); |
|
309 TRACE_INFO( " Connection note show ret %d ", res ) |
|
310 if (res == KErrNone) |
|
311 { |
|
312 aTestResult = ETestCasePassed; |
|
313 } |
|
314 |
|
315 TRACE_FUNC_EXIT |
|
316 } |
|
317 |
|
318 TInt CUsbPersonalityPluginTest::GetIdFromString(TPtrC aBuffer) |
|
319 { |
|
320 |
|
321 if (!aBuffer.Compare(_L("MS"))) |
|
322 { |
|
323 TRACE( " mass storage " ); |
|
324 return KIdMassStorage; |
|
325 } |
|
326 else if (!aBuffer.Compare(_L("PCS"))) |
|
327 { |
|
328 TRACE( " pc suite " ); |
|
329 return KIdPCSuite; |
|
330 } |
|
331 else if (!aBuffer.Compare(_L("MTP"))) |
|
332 { |
|
333 TRACE( " media transfer " ); |
|
334 return KIdMediaTransfer; |
|
335 } |
|
336 else |
|
337 { |
|
338 TRACE( " not found " ); |
|
339 return 0; |
|
340 } |
|
341 } |
|
342 |
|
343 TUid CUsbPersonalityPluginTest::GetUidFromId(TInt aId) |
|
344 { |
|
345 switch (aId) |
|
346 { |
|
347 case KIdMassStorage: |
|
348 return KUidMassStorage; |
|
349 case KIdPCSuite: |
|
350 return KUidPCSuite; |
|
351 case KIdMediaTransfer: |
|
352 return KUidMediaTransfer; |
|
353 default: |
|
354 return TUid::Uid(0x0); |
|
355 } |
|
356 } |
|
357 |
|
358 void CUsbPersonalityPluginTest::CreatePersonalityPluginTestL( |
|
359 TUsbPersonalityPluginTestBlockParams& aParams, |
|
360 TUsbPersonalityPluginTestResult& aTestResult) |
|
361 { |
|
362 TRACE_FUNC_ENTRY |
|
363 aTestResult = ETestCaseFailed; |
|
364 |
|
365 TInt id = GetIdFromString(aParams.iTestOption2); |
|
366 TUid uid = GetUidFromId(id); |
|
367 |
|
368 iPlugin = CUsbPersonalityPlugin::NewL(*iParams, uid); |
|
369 |
|
370 if (iPlugin) |
|
371 { |
|
372 TRACE( " plugin created ") |
|
373 aTestResult = ETestCasePassed; |
|
374 } |
|
375 |
|
376 TRACE_FUNC_EXIT |
|
377 } |
|
378 |
|
379 void CUsbPersonalityPluginTest::PreparePersonalityStartTestL( |
|
380 TUsbPersonalityPluginTestBlockParams& aParams, |
|
381 TUsbPersonalityPluginTestResult& aTestResult) |
|
382 { |
|
383 TRACE_FUNC_ENTRY |
|
384 |
|
385 aTestResult = ETestCaseFailed; |
|
386 |
|
387 TInt id = GetIdFromString(aParams.iTestOption2); |
|
388 TUid uid = GetUidFromId(id); |
|
389 iPlugin = CUsbPersonalityPlugin::NewL(*iParams, uid); |
|
390 |
|
391 InitializeTestObjectsL(); |
|
392 |
|
393 iActive->PreparePersonalityStart(iRequestStatus); |
|
394 |
|
395 TRACE_INFO( "prepare personality start status: %d, expected: %d", iRequestStatus.Int(), KErrNone ); |
|
396 User::LeaveIfError(iRequestStatus.Int()); |
|
397 |
|
398 aTestResult = ETestCasePassed; |
|
399 DeleteTestObjects(); |
|
400 |
|
401 TRACE_FUNC_EXIT |
|
402 } |
|
403 |
|
404 void CUsbPersonalityPluginTest::FinishPersonalityStartTestL( |
|
405 TUsbPersonalityPluginTestBlockParams& aParams, |
|
406 TUsbPersonalityPluginTestResult& aTestResult) |
|
407 { |
|
408 TRACE_FUNC_ENTRY |
|
409 |
|
410 aTestResult = ETestCaseFailed; |
|
411 |
|
412 TInt id = GetIdFromString(aParams.iTestOption2); |
|
413 TUid uid = GetUidFromId(id); |
|
414 iPlugin = CUsbPersonalityPlugin::NewL(*iParams, uid); |
|
415 |
|
416 InitializeTestObjectsL(); |
|
417 |
|
418 iActive->PreparePersonalityStart(iRequestStatus); |
|
419 TRACE_INFO( "prepare personality start status: %d, expected: %d", iRequestStatus.Int(), KErrNone ); |
|
420 User::LeaveIfError(iRequestStatus.Int()); |
|
421 |
|
422 iActive->FinishPersonalityStart(iRequestStatus); |
|
423 TRACE_INFO( "finish personality start status: %d, expected: %d", iRequestStatus.Int(), KErrNone ); |
|
424 |
|
425 iActive->PreparePersonalityStop(iRequestStatus); |
|
426 iActive->FinishPersonalityStart(iRequestStatus); |
|
427 User::LeaveIfError(iRequestStatus.Int()); |
|
428 |
|
429 aTestResult = ETestCasePassed; |
|
430 |
|
431 DeleteTestObjects(); |
|
432 |
|
433 TRACE_FUNC_EXIT |
|
434 } |
|
435 |
|
436 void CUsbPersonalityPluginTest::PreparePersonalityStopTestL( |
|
437 TUsbPersonalityPluginTestBlockParams& aParams, |
|
438 TUsbPersonalityPluginTestResult& aTestResult) |
|
439 { |
|
440 TRACE_FUNC_ENTRY |
|
441 |
|
442 aTestResult = ETestCaseFailed; |
|
443 |
|
444 TInt id = GetIdFromString(aParams.iTestOption2); |
|
445 TUid uid = GetUidFromId(id); |
|
446 iPlugin = CUsbPersonalityPlugin::NewL(*iParams, uid); |
|
447 |
|
448 InitializeTestObjectsL(); |
|
449 |
|
450 iActive->PreparePersonalityStart(iRequestStatus); |
|
451 TRACE_INFO( "prepare personality start status: %d, expected: %d", iRequestStatus.Int(), KErrNone ); |
|
452 User::LeaveIfError(iRequestStatus.Int()); |
|
453 |
|
454 iActive->FinishPersonalityStart(iRequestStatus); |
|
455 TRACE_INFO( "finish personality start status: %d, expected: %d", iRequestStatus.Int(), KErrNone ); |
|
456 User::LeaveIfError(iRequestStatus.Int()); |
|
457 |
|
458 iActive->PreparePersonalityStop(iRequestStatus); |
|
459 TRACE_INFO( "prepare personality stop status: %d, expected: %d", iRequestStatus.Int(), KErrNone ); |
|
460 User::LeaveIfError(iRequestStatus.Int()); |
|
461 |
|
462 aTestResult = ETestCasePassed; |
|
463 |
|
464 DeleteTestObjects(); |
|
465 |
|
466 TRACE_FUNC_EXIT |
|
467 } |
|
468 |
|
469 void CUsbPersonalityPluginTest::FinishPersonalityStopTestL( |
|
470 TUsbPersonalityPluginTestBlockParams& aParams, |
|
471 TUsbPersonalityPluginTestResult& aTestResult) |
|
472 { |
|
473 TRACE_FUNC_ENTRY |
|
474 |
|
475 aTestResult = ETestCaseFailed; |
|
476 |
|
477 TInt id = GetIdFromString(aParams.iTestOption2); |
|
478 TUid uid = GetUidFromId(id); |
|
479 iPlugin = CUsbPersonalityPlugin::NewL(*iParams, uid); |
|
480 |
|
481 InitializeTestObjectsL(); |
|
482 |
|
483 iActive->PreparePersonalityStart(iRequestStatus); |
|
484 TRACE_INFO( "prepare personality start status: %d, expected: %d", iRequestStatus.Int(), KErrNone ); |
|
485 User::LeaveIfError(iRequestStatus.Int()); |
|
486 |
|
487 iActive->FinishPersonalityStart(iRequestStatus); |
|
488 TRACE_INFO( "finish personality start status: %d, expected: %d", iRequestStatus.Int(), KErrNone ); |
|
489 User::LeaveIfError(iRequestStatus.Int()); |
|
490 |
|
491 iActive->PreparePersonalityStop(iRequestStatus); |
|
492 TRACE_INFO( "prepare personality stop status: %d, expected: %d", iRequestStatus.Int(), KErrNone ); |
|
493 User::LeaveIfError(iRequestStatus.Int()); |
|
494 |
|
495 iActive->FinishPersonalityStop(iRequestStatus); |
|
496 TRACE_INFO( "finish personality stop status: %d, expected: %d", iRequestStatus.Int(), KErrNone ); |
|
497 User::LeaveIfError(iRequestStatus.Int()); |
|
498 |
|
499 aTestResult = ETestCasePassed; |
|
500 |
|
501 DeleteTestObjects(); |
|
502 |
|
503 TRACE_FUNC_EXIT |
|
504 } |
|
505 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
506 // None |
|
507 |
|
508 // [End of File] - Do not remove |
|