|
1 /* |
|
2 * Copyright (c) 2001-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 the License "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 #include <e32test.h> |
|
20 #include <ct.h> |
|
21 #include <f32file.h> |
|
22 #include "MTestInterface.h" |
|
23 #include <ecom/ecom.h> |
|
24 |
|
25 RTest test(_L("CT Framework Tests")); |
|
26 |
|
27 |
|
28 |
|
29 TBool gLogging=ETrue; |
|
30 TBool gSilent=EFalse; |
|
31 |
|
32 const TInt gInterfaceA = 0x101f4e50; |
|
33 const TInt gInterfaceB = 0x101f4e51; |
|
34 const TInt gInterfaceC = 0x101f4e52; |
|
35 |
|
36 const TInt gAttribute1 = 0x101f4e4a; |
|
37 const TInt gAttribute2 = 0x101f4e4b; |
|
38 |
|
39 const TInt gImplementation6 = 0x101f4e4c; |
|
40 const TInt gImplementation5 = 0x101f4e4d; |
|
41 |
|
42 class CTestConsole:public CConsoleBase |
|
43 |
|
44 { |
|
45 public: |
|
46 static CTestConsole* NewL(CConsoleBase* aCon); |
|
47 TInt Create(const TDesC16& aTitle,TSize aSize) {return iCon->Create(aTitle,aSize);}; |
|
48 void Read(TRequestStatus& aStatus) {iCon->Read(aStatus);}; |
|
49 void ReadCancel(void) {iCon->ReadCancel();}; |
|
50 void Write(const TDesC16& aString); |
|
51 TPoint CursorPos(void) const {return iCon->CursorPos();}; |
|
52 void SetCursorPosAbs(const TPoint& aPos) {iCon->SetCursorPosAbs(aPos);}; |
|
53 void SetCursorPosRel(const TPoint& aPos) {iCon->SetCursorPosRel(aPos);}; |
|
54 void SetCursorHeight(TInt aHeight) {iCon->SetCursorHeight(aHeight);}; |
|
55 void SetTitle(const TDesC16& aTitle) {iCon->SetTitle(aTitle);}; |
|
56 void ClearScreen(void) {iCon->ClearScreen();}; |
|
57 void ClearToEndOfLine(void) {iCon->ClearToEndOfLine();}; |
|
58 TSize ScreenSize(void) const {return iCon->ScreenSize();}; |
|
59 TKeyCode KeyCode(void) const {return iCon->KeyCode();}; |
|
60 TUint KeyModifiers(void) const {return iCon->KeyModifiers();}; |
|
61 ~CTestConsole(void); |
|
62 void SetLogFile(RFile* aFile); |
|
63 private: |
|
64 CTestConsole(void); |
|
65 CConsoleBase* iCon; |
|
66 RFile* iFile; |
|
67 }; |
|
68 |
|
69 CTestConsole* CTestConsole::NewL(CConsoleBase* aCon) |
|
70 |
|
71 { |
|
72 CTestConsole* self; |
|
73 self=new (ELeave) CTestConsole; |
|
74 self->iCon=aCon; |
|
75 self->iFile=NULL; |
|
76 return self; |
|
77 } |
|
78 |
|
79 CTestConsole::CTestConsole(void):CConsoleBase() |
|
80 |
|
81 { |
|
82 } |
|
83 |
|
84 CTestConsole::~CTestConsole(void) |
|
85 |
|
86 { |
|
87 delete iCon; |
|
88 if (iFile) |
|
89 { |
|
90 iFile->Close(); |
|
91 } |
|
92 } |
|
93 |
|
94 void CTestConsole::Write(const TDesC16& aString) |
|
95 |
|
96 { |
|
97 if (gSilent) |
|
98 return; |
|
99 iCon->Write(aString); |
|
100 if ((iFile)&&(gLogging)) |
|
101 { |
|
102 TUint8 space[200]; |
|
103 TPtr8 ptr(space,200); |
|
104 ptr.Copy(aString); |
|
105 iFile->Write(ptr); |
|
106 } |
|
107 } |
|
108 |
|
109 void CTestConsole::SetLogFile(RFile* aFile) |
|
110 |
|
111 { |
|
112 iFile=aFile; |
|
113 } |
|
114 |
|
115 template <class T> class TTestArray |
|
116 { |
|
117 public: |
|
118 TTestArray(T* aArray, TInt aCount); |
|
119 TArray<T> Array(); |
|
120 private: |
|
121 static TInt Count(const CBase* aThat); |
|
122 static const TAny* Get(const CBase* aThat, TInt aIndex); |
|
123 |
|
124 T* iArray; |
|
125 TInt iCount; |
|
126 }; |
|
127 |
|
128 template <class T> TTestArray<T>::TTestArray(T* aArray, TInt aCount) |
|
129 : iArray(aArray), iCount(aCount) |
|
130 { |
|
131 } |
|
132 |
|
133 template <class T> TInt TTestArray<T>::Count(const CBase* aThat) |
|
134 { |
|
135 return reinterpret_cast<const TTestArray*>(aThat)->iCount; |
|
136 } |
|
137 |
|
138 template <class T> const TAny* TTestArray<T>::Get(const CBase* aThat, TInt aIndex) |
|
139 { |
|
140 return &reinterpret_cast<const TTestArray*>(aThat)->iArray[aIndex]; |
|
141 } |
|
142 |
|
143 template <class T> TArray<T> TTestArray<T>::Array() |
|
144 { |
|
145 return TArray<T>(Count, Get, reinterpret_cast<CBase*>(this)); |
|
146 } |
|
147 |
|
148 /** A filter that includes nothing (as a random easy-to-write test filter */ |
|
149 class TNoTokenTypes : public MCTTokenTypeFilter |
|
150 { |
|
151 public: |
|
152 /** Always returns EFalse. */ |
|
153 virtual TBool Accept(const CCTTokenTypeInfo& aTokenType) const; |
|
154 }; |
|
155 |
|
156 // Accept everything |
|
157 TBool TNoTokenTypes::Accept(const CCTTokenTypeInfo&) const |
|
158 { |
|
159 return EFalse; |
|
160 } |
|
161 |
|
162 class CStopScheduler : public CActive |
|
163 { |
|
164 public: |
|
165 void DoCancel() {}; |
|
166 void RunL(); |
|
167 CStopScheduler(); |
|
168 }; |
|
169 |
|
170 void CStopScheduler::RunL() |
|
171 { |
|
172 CActiveScheduler::Stop(); |
|
173 }; |
|
174 |
|
175 CStopScheduler::CStopScheduler() |
|
176 : CActive(EPriorityIdle) |
|
177 { |
|
178 CActiveScheduler::Add(this); |
|
179 SetActive(); |
|
180 TRequestStatus* r = &iStatus; |
|
181 User::RequestComplete(r, KErrNone); |
|
182 } |
|
183 |
|
184 TInt TokenTypeInfoListTestsL() |
|
185 { |
|
186 test.Printf(_L("1.1,Testing getting all token types,")); |
|
187 RCPointerArray<CCTTokenTypeInfo> myTokenTypes; |
|
188 CleanupClosePushL(myTokenTypes); |
|
189 |
|
190 CCTTokenTypeInfo::ListL(myTokenTypes); |
|
191 |
|
192 if (myTokenTypes.Count() < 6) |
|
193 { |
|
194 CleanupStack::PopAndDestroy(); |
|
195 test.Printf(_L("FAILED\r\n")); |
|
196 return (1); |
|
197 } |
|
198 |
|
199 myTokenTypes.ResetAndDestroy(); |
|
200 test.Printf(_L("PASSED\r\n")); |
|
201 |
|
202 test.Printf(_L("1.2,Testing user-supplied filter,")); |
|
203 TNoTokenTypes filter; |
|
204 CCTTokenTypeInfo::ListL(myTokenTypes, filter); |
|
205 |
|
206 if (myTokenTypes.Count() > 0) |
|
207 { |
|
208 CleanupStack::PopAndDestroy(); |
|
209 test.Printf(_L("FAILED\r\n")); |
|
210 return (2); |
|
211 } |
|
212 |
|
213 myTokenTypes.ResetAndDestroy(); |
|
214 test.Printf(_L("PASSED\r\n")); |
|
215 |
|
216 test.Printf(_L("1.3,Testing finding filters matching 1 interface,")); |
|
217 RArray<TUid> a; |
|
218 TUid aa = {gInterfaceA}; |
|
219 User::LeaveIfError(a.Append(aa)); |
|
220 CleanupClosePushL(a); |
|
221 TCTFindTokenTypesByInterface findA(a.Array()); |
|
222 CCTTokenTypeInfo::ListL(myTokenTypes, findA); |
|
223 if (myTokenTypes.Count() != 4) |
|
224 { |
|
225 CleanupStack::PopAndDestroy(2); |
|
226 test.Printf(_L("FAILED\r\n")); |
|
227 return (3); |
|
228 } |
|
229 TInt findAResults[] = {1,4,5,6}; |
|
230 TInt flag[] = {1,1,1,1}; |
|
231 for (TInt ii = 0; ii < 4; ii++) |
|
232 { |
|
233 TInt count = 0; |
|
234 TInt iii=0; |
|
235 TBuf<20> matchString; |
|
236 _LIT(format, "Test Token Type %d"); |
|
237 matchString.Format(format, findAResults[iii]); |
|
238 TBuf<20> idisplay_name= myTokenTypes[ii]->Label(); |
|
239 |
|
240 if (matchString.Compare(idisplay_name)) |
|
241 count++; |
|
242 else |
|
243 { |
|
244 if(flag[0]==1) |
|
245 flag[0]=0; |
|
246 else |
|
247 count++; |
|
248 } |
|
249 matchString.Format(format, findAResults[iii+1]); |
|
250 if (matchString.Compare(idisplay_name)) |
|
251 count++; |
|
252 else |
|
253 { |
|
254 if(flag[1]==1) |
|
255 flag[1]=0; |
|
256 else |
|
257 count++; |
|
258 } |
|
259 matchString.Format(format, findAResults[iii+2]); |
|
260 if (matchString.Compare(idisplay_name)) |
|
261 count++; |
|
262 else |
|
263 { |
|
264 if(flag[2]==1) |
|
265 flag[2]=0; |
|
266 else |
|
267 count++; |
|
268 } |
|
269 matchString.Format(format, findAResults[iii+3]); |
|
270 if (matchString.Compare(idisplay_name)) |
|
271 count++; |
|
272 else |
|
273 { |
|
274 if(flag[3]==1) |
|
275 flag[3]=0; |
|
276 else |
|
277 count++; |
|
278 } |
|
279 if(count==4) |
|
280 { |
|
281 CleanupStack::PopAndDestroy(2); |
|
282 test.Printf(_L("FAILED\r\n")); |
|
283 return (4); |
|
284 } |
|
285 } |
|
286 |
|
287 myTokenTypes.ResetAndDestroy(); |
|
288 test.Printf(_L("PASSED\r\n")); |
|
289 |
|
290 test.Printf(_L("1.5,Testing finding filters matching 2 interfaces,")); |
|
291 TUid aAndB[] = {{gInterfaceA}, {gInterfaceB}}; |
|
292 TTestArray<TUid> aAndBArray(aAndB, 2); |
|
293 TCTFindTokenTypesByInterface findAAndB(aAndBArray.Array()); |
|
294 CCTTokenTypeInfo::ListL(myTokenTypes, findAAndB); |
|
295 if (myTokenTypes.Count() != 2) |
|
296 { |
|
297 CleanupStack::PopAndDestroy(2); |
|
298 test.Printf(_L("FAILED\r\n")); |
|
299 return (5); |
|
300 } |
|
301 TInt findAAndBResults[] = {4,6}; |
|
302 TInt flag1[] = {1,1}; |
|
303 for (TInt jj = 0; jj < 2; jj++) |
|
304 { |
|
305 TInt count = 0; |
|
306 TInt jjj=0; |
|
307 TBuf<20> matchString; |
|
308 _LIT(format, "Test Token Type %d"); |
|
309 matchString.Format(format, findAAndBResults[jjj]); |
|
310 TBuf<20> idisplay_name = myTokenTypes[jj]->Label(); |
|
311 if (matchString.Compare(idisplay_name)) |
|
312 count++; |
|
313 else |
|
314 { |
|
315 if(flag1[0]==1) |
|
316 flag1[0]=0; |
|
317 else |
|
318 count++; |
|
319 } |
|
320 matchString.Format(format, findAAndBResults[jjj+1]); |
|
321 if (matchString.Compare(idisplay_name)) |
|
322 count++; |
|
323 else |
|
324 { |
|
325 if(flag1[1]==1) |
|
326 flag1[1]=0; |
|
327 else |
|
328 count++; |
|
329 } |
|
330 if(count==2) |
|
331 { |
|
332 CleanupStack::PopAndDestroy(2); |
|
333 test.Printf(_L("FAILED\r\n")); |
|
334 return (6); |
|
335 } |
|
336 } |
|
337 |
|
338 // NOTE No ResetAndDestroy |
|
339 test.Printf(_L("PASSED\r\n")); |
|
340 |
|
341 test.Printf(_L("1.6,Testing appending interface infos,")); |
|
342 CCTTokenTypeInfo::ListL(myTokenTypes, findA); |
|
343 if (myTokenTypes.Count() != 6) |
|
344 { |
|
345 CleanupStack::PopAndDestroy(2); |
|
346 test.Printf(_L("FAILED\r\n")); |
|
347 return (7); |
|
348 } |
|
349 TInt flag2[] = {1,1,1,1}; |
|
350 for (TInt kk = 0; kk < 4; kk++) |
|
351 { |
|
352 TInt count = 0; |
|
353 TInt kkk=0; |
|
354 TBuf<20> matchString; |
|
355 _LIT(format, "Test Token Type %d"); |
|
356 matchString.Format(format, findAResults[kkk]); |
|
357 TBuf<20> idisplay_name = myTokenTypes[kk+2]->Label(); |
|
358 if (matchString.Compare(idisplay_name)) |
|
359 count++; |
|
360 else |
|
361 { |
|
362 if(flag2[0]==1) |
|
363 flag2[0]=0; |
|
364 else |
|
365 count++; |
|
366 } |
|
367 matchString.Format(format, findAResults[kkk+1]); |
|
368 if (matchString.Compare(idisplay_name)) |
|
369 count++; |
|
370 else |
|
371 { |
|
372 if(flag2[1]==1) |
|
373 flag2[1]=0; |
|
374 else |
|
375 count++; |
|
376 } |
|
377 matchString.Format(format, findAResults[kkk+2]); |
|
378 if (matchString.Compare(idisplay_name)) |
|
379 count++; |
|
380 else |
|
381 { |
|
382 if(flag2[2]==1) |
|
383 flag2[2]=0; |
|
384 else |
|
385 count++; |
|
386 } |
|
387 matchString.Format(format, findAResults[kkk+3]); |
|
388 if (matchString.Compare(idisplay_name)) |
|
389 count++; |
|
390 else |
|
391 { |
|
392 if(flag2[3]==1) |
|
393 flag2[3]=0; |
|
394 else |
|
395 count++; |
|
396 } |
|
397 if(count==4) |
|
398 { |
|
399 CleanupStack::PopAndDestroy(2); |
|
400 test.Printf(_L("FAILED\r\n")); |
|
401 return (8); |
|
402 } |
|
403 } |
|
404 |
|
405 test.Printf(_L("PASSED\r\n")); |
|
406 |
|
407 myTokenTypes.ResetAndDestroy(); |
|
408 test.Printf(_L("1.7,Testing filtering by interface and attribute,")); |
|
409 TCTTokenTypeAttribute att = {{gAttribute1}, 1}; |
|
410 RArray<TCTTokenTypeAttribute> attArray(sizeof(TCTTokenTypeAttribute), &att, |
|
411 1); |
|
412 TCTFindTokenTypesByInterfaceAndAttribute findAWithAtt1(a.Array(), |
|
413 attArray.Array()); |
|
414 CCTTokenTypeInfo::ListL(myTokenTypes, findAWithAtt1); |
|
415 if (myTokenTypes.Count() != 1) |
|
416 { |
|
417 CleanupStack::PopAndDestroy(2); |
|
418 test.Printf(_L("FAILED\r\n")); |
|
419 return (9); |
|
420 } |
|
421 _LIT(KMatch, "Test Token Type 6"); |
|
422 if (myTokenTypes[0]->Label() != KMatch) |
|
423 { |
|
424 CleanupStack::PopAndDestroy(2); |
|
425 test.Printf(_L("FAILED\r\n")); |
|
426 return (10); |
|
427 } |
|
428 test.Printf(_L("PASSED\r\n")); |
|
429 |
|
430 CleanupStack::PopAndDestroy(2); |
|
431 return KErrNone; |
|
432 }; |
|
433 |
|
434 TInt TokenTypeInfoTestsL() |
|
435 { |
|
436 test.Printf(_L("2.1,Testing token type for tests,")); |
|
437 RCPointerArray<CCTTokenTypeInfo> myTokenTypes; |
|
438 CleanupClosePushL(myTokenTypes); |
|
439 TUid aABndC[] = {{gInterfaceA}, {gInterfaceB}, {gInterfaceC}}; |
|
440 TTestArray<TUid> aABndCArray(aABndC, 3); |
|
441 TCTFindTokenTypesByInterface findABAndC(aABndCArray.Array()); |
|
442 CCTTokenTypeInfo::ListL(myTokenTypes, findABAndC); |
|
443 if (myTokenTypes.Count() != 1) |
|
444 { |
|
445 CleanupStack::PopAndDestroy(); |
|
446 test.Printf(_L("FAILED\r\n")); |
|
447 return (1); |
|
448 } |
|
449 test.Printf(_L("PASSED\r\n")); |
|
450 |
|
451 test.Printf(_L("2.2,Test UID function,")); |
|
452 CCTTokenTypeInfo* info = myTokenTypes[0]; |
|
453 if (info->Type().iUid != gImplementation6) |
|
454 { |
|
455 CleanupStack::PopAndDestroy(); |
|
456 test.Printf(_L("FAILED\r\n")); |
|
457 return (1); |
|
458 } |
|
459 test.Printf(_L("PASSED\r\n")); |
|
460 |
|
461 test.Printf(_L("2.3,Test getting an array of interfaces,")); |
|
462 RArray<TUid> interfaces = info->Interfaces(); |
|
463 if (interfaces.Count() != 3) |
|
464 { |
|
465 CleanupStack::PopAndDestroy(); |
|
466 test.Printf(_L("FAILED\r\n")); |
|
467 return (4); |
|
468 } |
|
469 TUid refInterfaces[] = {{gInterfaceA}, {gInterfaceB}, {gInterfaceC}}; |
|
470 for (TInt ii = 0; ii < 3; ii++) |
|
471 { |
|
472 if (interfaces[ii] != refInterfaces[ii]) |
|
473 { |
|
474 CleanupStack::PopAndDestroy(); |
|
475 test.Printf(_L("FAILED\r\n")); |
|
476 return (5); |
|
477 } |
|
478 } |
|
479 test.Printf(_L("PASSED\r\n")); |
|
480 |
|
481 test.Printf(_L("2.4,Test getting an array of attributes,")); |
|
482 RArray<TCTTokenTypeAttribute> attributes = info->Attributes(); |
|
483 if (attributes.Count() != 2) |
|
484 { |
|
485 CleanupStack::PopAndDestroy(); |
|
486 test.Printf(_L("FAILED\r\n")); |
|
487 return (8); |
|
488 } |
|
489 TCTTokenTypeAttribute refAttributes[] = |
|
490 {{{gAttribute2}, 2}, {{gAttribute1}, 1}}; |
|
491 for (TInt jj = 0; jj < 2; jj++) |
|
492 { |
|
493 if (attributes[jj].iUID != refAttributes[jj].iUID || |
|
494 attributes[jj].iVal != refAttributes[jj].iVal) |
|
495 { |
|
496 CleanupStack::PopAndDestroy(); |
|
497 test.Printf(_L("FAILED\r\n")); |
|
498 return (9); |
|
499 } |
|
500 } |
|
501 test.Printf(_L("PASSED\r\n")); |
|
502 |
|
503 test.Printf(_L("2.5,Test getting the label,")); |
|
504 _LIT(KLabel, "Test Token Type 6"); |
|
505 if (info->Label() != KLabel) |
|
506 { |
|
507 CleanupStack::PopAndDestroy(); |
|
508 test.Printf(_L("FAILED\r\n")); |
|
509 return (10); |
|
510 } |
|
511 test.Printf(_L("PASSED\r\n")); |
|
512 |
|
513 test.Printf(_L("2.6,Test getting the type of the token type,")); |
|
514 TUid impl6 = {gImplementation6}; |
|
515 if (info->Type() != impl6) |
|
516 { |
|
517 CleanupStack::PopAndDestroy(); |
|
518 test.Printf(_L("FAILED\r\n")); |
|
519 return (11); |
|
520 } |
|
521 test.Printf(_L("PASSED\r\n")); |
|
522 |
|
523 CleanupStack::PopAndDestroy(); |
|
524 return KErrNone; |
|
525 } |
|
526 |
|
527 |
|
528 TInt TestTokenTypeL(MCTTokenType* aTokenType, TInt aNum) |
|
529 { |
|
530 test.Printf(_L("3.4.1,Getting token info,")); |
|
531 RCPointerArray<HBufC> tokenInfo; |
|
532 CleanupClosePushL(tokenInfo); |
|
533 TRequestStatus status = KRequestPending; |
|
534 aTokenType->List(tokenInfo, status); |
|
535 // Cancel call is pointelss as it does nothing in the test |
|
536 // plugin. But it won't do any harm to check it doesn't explode. |
|
537 aTokenType->CancelList(); |
|
538 User::WaitForRequest(status); |
|
539 if (status.Int() != KErrNone || tokenInfo.Count() != 1) |
|
540 { |
|
541 CleanupStack::PopAndDestroy(); |
|
542 test.Printf(_L("FAILED\r\n")); |
|
543 return (100); |
|
544 } |
|
545 test.Printf(_L("PASSED\r\n")); |
|
546 |
|
547 test.Printf(_L("3.4.1,Checking token type name,")); |
|
548 TBuf<20> buf; |
|
549 _LIT(KLabelFormat, "Test Token Type %d"); |
|
550 buf.Format(KLabelFormat, aNum); |
|
551 if (aTokenType->Label().Compare(buf)) |
|
552 { |
|
553 CleanupStack::PopAndDestroy(); |
|
554 test.Printf(_L("FAILED\r\n")); |
|
555 return (105); |
|
556 } |
|
557 test.Printf(_L("PASSED\r\n")); |
|
558 |
|
559 test.Printf(_L("3.4.2,Checking token type Type UID,")); |
|
560 TUid uid = {gImplementation5 + 5 - aNum}; |
|
561 if (aTokenType->Type() != uid) |
|
562 { |
|
563 CleanupStack::PopAndDestroy(); |
|
564 test.Printf(_L("FAILED\r\n")); |
|
565 return (105); |
|
566 } |
|
567 test.Printf(_L("PASSED\r\n")); |
|
568 |
|
569 test.Printf(_L("3.4.3,Checking token name,")); |
|
570 _LIT(KFormat, "Test Token %d"); |
|
571 buf.Format(KFormat, aNum); |
|
572 if (buf.Compare(*tokenInfo[0])) |
|
573 { |
|
574 CleanupStack::PopAndDestroy(); |
|
575 test.Printf(_L("FAILED\r\n")); |
|
576 return (101); |
|
577 } |
|
578 test.Printf(_L("PASSED\r\n")); |
|
579 |
|
580 test.Printf(_L("3.4.4,Opening token,")); |
|
581 status = KRequestPending; |
|
582 MCTToken* token; |
|
583 aTokenType->OpenToken(*tokenInfo[0], token, status); |
|
584 // Cancel call will fail as token isn't opened asynchronous. Check |
|
585 // that the reference counting still works. |
|
586 aTokenType->CancelOpenToken(); |
|
587 User::WaitForRequest(status); |
|
588 if (status.Int() != KErrNone) |
|
589 { |
|
590 CleanupStack::PopAndDestroy(); |
|
591 test.Printf(_L("FAILED\r\n")); |
|
592 return (102); |
|
593 } |
|
594 token->Release(); |
|
595 test.Printf(_L("PASSED\r\n")); |
|
596 |
|
597 test.Printf(_L("3.4.5,Opening token by handle,")); |
|
598 status = KRequestPending; |
|
599 TCTTokenHandle handle(aTokenType->Type(), 1); |
|
600 aTokenType->OpenToken(handle, token, status); |
|
601 User::WaitForRequest(status); |
|
602 if (status.Int() != KErrNone) |
|
603 { |
|
604 CleanupStack::PopAndDestroy(); |
|
605 test.Printf(_L("FAILED\r\n")); |
|
606 return (102); |
|
607 } |
|
608 test.Printf(_L("PASSED\r\n")); |
|
609 |
|
610 test.Printf(_L("3.4.6,Checking token's TokenType() function,")); |
|
611 if (&token->TokenType() != aTokenType) |
|
612 { |
|
613 CleanupStack::PopAndDestroy(); |
|
614 test.Printf(_L("FAILED\r\n")); |
|
615 return (102); |
|
616 } |
|
617 test.Printf(_L("PASSED\r\n")); |
|
618 |
|
619 _LIT(KVersion, "The Ultimate Version"); |
|
620 _LIT(KSerial, "Serial No. 1"); |
|
621 _LIT(KManufacturer, "ACME Corporation"); |
|
622 |
|
623 test.Printf(_L("3.4.6.1,Checking token's Information() function,")); |
|
624 if (token->Information(MCTToken::EVersion) != KVersion || |
|
625 token->Information(MCTToken::ESerialNo) != KSerial || |
|
626 token->Information(MCTToken::EManufacturer) != KManufacturer) |
|
627 { |
|
628 CleanupStack::PopAndDestroy(); |
|
629 test.Printf(_L("FAILED\r\n")); |
|
630 return (102); |
|
631 } |
|
632 test.Printf(_L("PASSED\r\n")); |
|
633 |
|
634 test.Printf(_L("3.4.7,Registering for removal notification,")); |
|
635 // This is another test to check that an API doesn't crash. We |
|
636 // call the base NotifyOnRemoval/CancelNotify functions and check |
|
637 // they do nothing! There's no point in creating derived versions |
|
638 // that do something as that would be testing the test plugin, not |
|
639 // the framework. |
|
640 TRequestStatus removalStatus; |
|
641 token->NotifyOnRemoval(removalStatus); |
|
642 token->CancelNotify(); |
|
643 test.Printf(_L("PASSED\r\n")); |
|
644 |
|
645 test.Printf(_L("3.4.9,Testing cancellation of async interface opening,")); |
|
646 MTestInterface* interface; |
|
647 MCTTokenInterface* temp; |
|
648 TUid intB = {gInterfaceB}; |
|
649 token->GetInterface(intB, temp, status); |
|
650 token->CancelGetInterface(); |
|
651 test.Printf(_L("PASSED\r\n")); |
|
652 |
|
653 test.Printf(_L("3.4.10,Opening an interface,")); |
|
654 status = KRequestPending; |
|
655 TUid intC = {gInterfaceC}; |
|
656 token->GetInterface(intC, temp, status); |
|
657 interface = static_cast<MTestInterface*>(temp); |
|
658 // Cancel call is pointelss as it does nothing in the test |
|
659 // plugin. But it won't do any harm to check it doesn't explode. |
|
660 token->CancelGetInterface(); |
|
661 CleanupReleasePushL(*interface); |
|
662 token->Release(); |
|
663 User::WaitForRequest(status); |
|
664 if (status.Int() != KErrNone) |
|
665 { |
|
666 CleanupStack::PopAndDestroy(2); |
|
667 test.Printf(_L("FAILED\r\n")); |
|
668 return (103); |
|
669 } |
|
670 test.Printf(_L("PASSED\r\n")); |
|
671 |
|
672 test.Printf(_L("3.4.11,Checking interface name,")); |
|
673 if (buf.Compare(interface->Label())) |
|
674 { |
|
675 CleanupStack::PopAndDestroy(2); |
|
676 test.Printf(_L("FAILED\r\n")); |
|
677 return (104); |
|
678 } |
|
679 test.Printf(_L("PASSED\r\n")); |
|
680 |
|
681 test.Printf(_L("3.4.12,Getting an object,")); |
|
682 MTestObject* object = interface->ObjectL(); |
|
683 object->Release(); |
|
684 test.Printf(_L("PASSED\r\n")); |
|
685 |
|
686 CleanupStack::PopAndDestroy(2); |
|
687 return KErrNone; |
|
688 } |
|
689 |
|
690 TInt TokenTypeTestsL() |
|
691 { |
|
692 test.Printf(_L("3.1,Getting token types for tests,")); |
|
693 RFs fs; |
|
694 RCPointerArray<CCTTokenTypeInfo> myTokenTypes; |
|
695 CleanupClosePushL(myTokenTypes); |
|
696 TUid aABndC[] = {{gInterfaceA}, {gInterfaceB}, {gInterfaceC}}; |
|
697 TTestArray<TUid> aABandCArray(aABndC, 3); |
|
698 TCTFindTokenTypesByInterface findABAndC(aABandCArray.Array()); |
|
699 CCTTokenTypeInfo::ListL(myTokenTypes, findABAndC); |
|
700 if (myTokenTypes.Count() != 1) |
|
701 { |
|
702 CleanupStack::PopAndDestroy(); |
|
703 test.Printf(_L("FAILED\r\n")); |
|
704 return (1); |
|
705 } |
|
706 test.Printf(_L("PASSED\r\n")); |
|
707 |
|
708 test.Printf(_L("3.2,Loading token type 6,")); |
|
709 MCTTokenType* token6 = MCTTokenType::NewL(*myTokenTypes[0], fs); |
|
710 if (!token6) |
|
711 { |
|
712 CleanupStack::PopAndDestroy(); |
|
713 test.Printf(_L("FAILED\r\n")); |
|
714 return (1); |
|
715 } |
|
716 CleanupReleasePushL(*token6); |
|
717 test.Printf(_L("PASSED\r\n")); |
|
718 |
|
719 TInt ret = TestTokenTypeL(token6, 6); |
|
720 if (ret) |
|
721 { |
|
722 CleanupStack::PopAndDestroy(2); |
|
723 return ret; |
|
724 } |
|
725 |
|
726 test.Printf(_L("3.3,Loading token type 5,")); |
|
727 TUid UID5 = {gImplementation5}; |
|
728 MCTTokenType* token5 = MCTTokenType::NewL(UID5, fs); |
|
729 if (!token5) |
|
730 { |
|
731 CleanupStack::PopAndDestroy(2); |
|
732 test.Printf(_L("FAILED\r\n")); |
|
733 return (2); |
|
734 } |
|
735 CleanupReleasePushL(*token5); |
|
736 test.Printf(_L("PASSED\r\n")); |
|
737 |
|
738 ret = TestTokenTypeL(token5, 5); |
|
739 CleanupStack::PopAndDestroy(3); |
|
740 |
|
741 return ret; |
|
742 } |
|
743 |
|
744 TInt MemoryTestL(TInt (*aFnToTest)()) |
|
745 { |
|
746 gLogging = EFalse; |
|
747 for (TInt ii = 1; ; ii++) |
|
748 { |
|
749 if (ii % 10) |
|
750 test.Printf(_L(".")); |
|
751 else |
|
752 test.Printf(_L("*")); |
|
753 if (!(ii % 50)) |
|
754 test.Printf(_L("\r\n")); |
|
755 gSilent = ETrue; |
|
756 __UHEAP_MARK; |
|
757 __UHEAP_FAILNEXT(ii); |
|
758 TRAPD(err,aFnToTest()); |
|
759 __UHEAP_RESET; |
|
760 REComSession::FinalClose(); |
|
761 __UHEAP_MARKEND; |
|
762 User::Heap().Check(); |
|
763 gSilent = EFalse; |
|
764 if (err != KErrNoMemory) |
|
765 { |
|
766 test.Printf(_L("\r\n")); |
|
767 gLogging = ETrue; |
|
768 return err; |
|
769 } |
|
770 } |
|
771 } |
|
772 |
|
773 void TestsL(void) |
|
774 { |
|
775 CActiveScheduler* as = new(ELeave) CActiveScheduler; |
|
776 CActiveScheduler::Install(as); |
|
777 |
|
778 TInt errors = 0; |
|
779 TInt ret; |
|
780 __UHEAP_MARK; |
|
781 ret = TokenTypeInfoListTestsL(); |
|
782 REComSession::FinalClose(); |
|
783 __UHEAP_MARKEND; |
|
784 if (ret) |
|
785 { |
|
786 test.Printf(_L("1.9,ERROR %d in Info List test,FAILED\r\n"),ret); |
|
787 errors++; |
|
788 } |
|
789 else |
|
790 { |
|
791 test.Printf(_L("1.9,Info List test,PASSED\r\n"),ret); |
|
792 } |
|
793 __UHEAP_MARK; |
|
794 ret = TokenTypeInfoTestsL(); |
|
795 REComSession::FinalClose(); |
|
796 __UHEAP_MARKEND; |
|
797 if (ret) |
|
798 { |
|
799 test.Printf(_L("2.9,ERROR %d in Info test,FAILED\r\n"),ret); |
|
800 errors++; |
|
801 } |
|
802 else |
|
803 { |
|
804 test.Printf(_L("2.9,Info test,PASSED\r\n"),ret); |
|
805 } |
|
806 |
|
807 __UHEAP_MARK; |
|
808 ret = TokenTypeTestsL(); |
|
809 REComSession::FinalClose(); |
|
810 __UHEAP_MARKEND; |
|
811 if (ret) |
|
812 { |
|
813 test.Printf(_L("3.9,ERROR %d in token test,FAILED\r\n"),ret); |
|
814 errors++; |
|
815 } |
|
816 else |
|
817 { |
|
818 test.Printf(_L("3.9,token test,PASSED\r\n"),ret); |
|
819 } |
|
820 |
|
821 ret = MemoryTestL(TokenTypeInfoListTestsL); |
|
822 if (ret) |
|
823 { |
|
824 test.Printf(_L("4.9,ERROR %d in Info List memory test,FAILED\r\n"),ret); |
|
825 errors++; |
|
826 } |
|
827 else |
|
828 { |
|
829 test.Printf(_L("4.9,Info List memory test,PASSED\r\n"),ret); |
|
830 } |
|
831 ret = MemoryTestL(TokenTypeTestsL); |
|
832 if (ret) |
|
833 { |
|
834 test.Printf(_L("5.9,ERROR %d in Token Type memory test,FAILED\r\n"),ret); |
|
835 errors++; |
|
836 } |
|
837 else |
|
838 { |
|
839 test.Printf(_L("5.9,Token Type memory test,PASSED\r\n"),ret); |
|
840 } |
|
841 |
|
842 test.Printf(_L("%d tests failed out of 44 hardcoded\r\n"), errors); |
|
843 |
|
844 |
|
845 if (errors) |
|
846 { |
|
847 test.Printf(_L("%d TESTS FAILED\r\n"),errors); |
|
848 } |
|
849 else |
|
850 { |
|
851 test.Printf(_L("ALL TESTS PASSED\r\n")); |
|
852 } |
|
853 |
|
854 delete as; |
|
855 } |
|
856 |
|
857 GLDEF_C TInt E32Main(void) |
|
858 |
|
859 { |
|
860 CTrapCleanup* cleanup; |
|
861 cleanup=CTrapCleanup::New(); |
|
862 test.Start(_L("Starting token framework tests\r\n")); |
|
863 CTestConsole* con=NULL; |
|
864 TRAPD(ret,con=CTestConsole::NewL(test.Console())); |
|
865 RFs fs; |
|
866 if (gLogging) |
|
867 { |
|
868 User::LeaveIfError(fs.Connect()); |
|
869 RFile* file; |
|
870 file=new (ELeave) RFile; |
|
871 TDriveUnit sysDrive (fs.GetSystemDrive()); |
|
872 TDriveName driveName(sysDrive.Name()); |
|
873 TBuf<64> logFile (driveName); |
|
874 logFile.Append(_L("\\T_CTFrameworkLog.txt")); |
|
875 User::LeaveIfError(file->Replace(fs, logFile, EFileShareAny|EFileWrite)); |
|
876 con->SetLogFile(file); |
|
877 } |
|
878 test.SetConsole(con); |
|
879 TRAP(ret,TestsL()); |
|
880 if (ret) |
|
881 { |
|
882 test.Printf(_L("Unexpected leave\r\n")); |
|
883 } |
|
884 gLogging=EFalse; |
|
885 test.Close(); |
|
886 delete cleanup; |
|
887 return(KErrNone); |
|
888 } |