Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_mmc.cpp
15 // Tests locking, unlocking and clearing of a password on a suitable
16 // device. Currently, this device is a MultiMediaCard. The RFs API
17 // allows the user to store the password.
18 // This is a manual test, and the operator must observe that the notifier
19 // appears exactly when indicated by the program.
29 // definitions from p32mmc.h
31 const TInt KMMCCIDLength = 16;
36 static inline TUint32 BigEndian32(const TUint8*);
37 static inline void BigEndian4Bytes(TUint8* aPtr, TUint32 aVal);
41 inline TUint32 TMMC::BigEndian32(const TUint8* aPtr)
42 {return( (aPtr[0]<<24) | (aPtr[1]<<16) | (aPtr[2]<<8) | (aPtr[3]) );}
44 inline void TMMC::BigEndian4Bytes(TUint8* aPtr, TUint32 aVal)
46 aPtr[0] = (TUint8)((aVal >> 24) & 0xFF);
47 aPtr[1] = (TUint8)((aVal >> 16) & 0xFF);
48 aPtr[2] = (TUint8)((aVal >> 8) & 0xFF);
49 aPtr[3] = (TUint8)(aVal & 0xFF);
56 LOCAL_D RTest test(_L("t_mmc"));
59 LOCAL_D RFile TheFile;
62 _LIT(KSessionPath, "X:\\");
63 const TInt KDrv = EDriveX;
64 const TText KDrvLtr = 'x';
66 _LIT(KSessionPath, "D:\\");
67 const TInt KDrv = EDriveD;
68 const TText KDrvLtr = 'd';
71 _LIT(KTestFileName, "testFile");
73 enum TAccessType {EAccessUnlock, EAccessStore, EAccessCancel, EAccessWrongPw, EAccessNoNotifier};
75 LOCAL_D TMediaPassword KNul, KPw1, KPw2, KPw3, KPw4, KPw5;
78 const static TUint8 cid0[KMMCCIDLength] = // "CID0ccccccccccc#";
86 const static TUint8 cid0[KMMCCIDLength] = // big-endian, CID0
88 0x06, 0x00, 0x00, 0x31,
89 0x36, 0x4d, 0x20, 0x20,
90 0x20, 0x00, 0xb4, 0xff,
91 0xff, 0xff, 0x63, 0xd9
95 // local test functions
97 LOCAL_C void RemountMedia();
98 LOCAL_C void ClearControllerStore();
99 LOCAL_C void DeletePasswordFile();
100 LOCAL_C TInt CreateFile();
101 LOCAL_C TInt PWFileSize(TInt &aLength);
102 LOCAL_C TInt AccessDisk(TAccessType aAccess, const TDesC8 &aPWD);
103 LOCAL_C void TestHasPassword(TBool aIL, TBool aHP);
105 LOCAL_C void TestLockUnlockR();
106 LOCAL_C void TestNullPasswords();
107 LOCAL_C void TestLockUnlock();
109 LOCAL_C void TestPasswordStore();
110 LOCAL_C void TestWriteToDisk();
112 LOCAL_C void TestFormat();
113 LOCAL_C void TestRemount();
116 /** force a remount on the removable media. */
118 LOCAL_C void RemountMedia()
121 // UserSvr::ForceRemountMedia(ERemovableMedia0);
122 User::After(1 * 1500 * 1000);
124 // UserSvr::ForceRemountMedia(ERemovableMedia0);
125 // User::After(1 * 1500 * 1000);
126 test.Printf(_L("Remove and re-insert card. Press \'z\' when finished.\n"));
127 while (test.Getch() != 'z')
133 /** ask the user to replace the current lockable media with another */
135 LOCAL_C void ChangeMedia()
138 test.Printf(_L("Press f4 whilst holding down f5\n"));
139 test.Printf(_L("Press z when completed\n"));
140 while(test.Getch() != 'z')
143 test.Printf(_L("Remove and insert other card. Press \'z\' when finished.\n"));
144 while (test.Getch() != 'z')
150 /** disable auto-unlock by clearing controller store */
152 LOCAL_C void ClearControllerStore()
155 test(TBusLocalDrive::WritePasswordData(nulSt) == KErrNone);// empty
156 test(TBusLocalDrive::PasswordStoreLengthInBytes() == 0);
160 /** delete the password store file. Does not affect the auto-unlock mechanism. */
162 LOCAL_C void DeletePasswordFile()
165 TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
166 mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
169 User::After(100 * 1000);
170 r = TheFs.Delete(mediaPWrdFile);
171 } while (r == KErrInUse);
173 test(r == KErrNone || r == KErrNotFound);
177 /** attempt to create a file on the removable media and return any error code */
179 LOCAL_C TInt CreateFile()
182 TInt r = f.Replace(TheFs, KTestFileName, EFileShareAny);
189 /** get size of the media store file in bytes, and return any error code */
191 LOCAL_C TInt PWFileSize(TInt &aLength)
193 TInt r; // error code
195 // allow low priority background writer thread to start and finish
197 User::After(1 * 1000 * 1000);
199 TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
200 mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
202 if ((r = f.Open(TheFs, mediaPWrdFile, EFileShareAny)) == KErrNone)
213 * write message to screen and attempt to access disk. If card is locked then async
214 * notifier will be brought up from within file server.
217 LOCAL_C TInt AccessDisk(TAccessType aAccess, const TDesC8 &aPWD)
220 pwd.Copy((const TUint16 *)aPWD.Ptr(), aPWD.Length() / 2);
222 if (aAccess == EAccessUnlock || aAccess == EAccessStore)
223 test.Printf(_L("\"%S\": "), &pwd);
228 test.Printf(_L("unlock\n"));
232 test.Printf(_L("store\n"));
236 test.Printf(_L("cancel\n"));
240 test.Printf(_L("wrong\n"));
243 case EAccessNoNotifier:
244 test.Printf(_L("** no notifier **\n"));
252 TInt r = TheFile.Open(TheFs, KTestFileName, EFileShareAny);
261 * uses RFs::DriveInfo() to test if the card has a password. Is checking
262 * that iHasPassword in TMMCCard is maintained properly.
265 inline TBool bits_set(TUint aMsk, TUint aSel)
267 return (aMsk & aSel) == aSel;
270 LOCAL_C void TestHasPassword(TBool aIL, TBool aHP)
276 test(fs.Drive(di, d) == KErrNone);
279 test(aIL == bits_set(di.iMediaAtt, KMediaAttLocked | KMediaAttLockable | KMediaAttHasPassword));
280 test(aHP == bits_set(di.iMediaAtt, KMediaAttLockable | KMediaAttHasPassword));
282 test(aIL == bits_set(di.iMediaAtt, KMediaAttLocked | KMediaAttHasPassword));
283 test(aHP == bits_set(di.iMediaAtt, KMediaAttHasPassword));
288 // -------- test functions --------
292 * test return values of LockDrive(), UnlockDrive() and ClearPassword()
293 * without trying use the disk. This tests that the functions return the
294 * same values as the TBusLocalDrive functions.
296 * EPbPswdUnlock EPbPswdLock EPbPswdClear
297 * right wrong right wrong right wrong
298 * locked None AccDen AccDec AccDen AccDen AccDen
299 * unlocked AldExst AldExst None AccDec None AccDen
301 * Locked means inaccessible, not just has password.
304 LOCAL_C void TestLockUnlockR()
306 test.Start(_L("TestLockUnlockR"));
311 test.Next(_L("assign password"));
312 test(fs.LockDrive(d, KNul, KPw1, EFalse) == KErrNone); // assign test password
313 TestHasPassword(EFalse, ETrue);
314 RemountMedia(); // card is now locked
315 TestHasPassword(ETrue, ETrue);
317 test.Next(_L("lock locked card"));
318 test(fs.LockDrive(d, KPw2, KPw1, EFalse) == KErrAccessDenied); // lock locked wrong
319 TestHasPassword(ETrue, ETrue);
320 test(fs.LockDrive(d, KPw1, KPw1, EFalse) == KErrAccessDenied); // lock locked right
321 TestHasPassword(ETrue, ETrue);
323 test.Next(_L("unlock locked card"));
324 test(fs.UnlockDrive(d, KPw2, EFalse) == KErrAccessDenied); // unlock locked wrong
325 TestHasPassword(ETrue, ETrue);
326 test(fs.UnlockDrive(d, KPw1, EFalse) == KErrNone); // unlock locked right
327 TestHasPassword(EFalse, ETrue);
329 test.Next(_L("unlock unlocked card"));
330 test(fs.UnlockDrive(d, KPw1, EFalse) == KErrAlreadyExists); // unlock unlocked right
331 TestHasPassword(EFalse, ETrue);
332 test(fs.UnlockDrive(d, KPw2, EFalse) == KErrAlreadyExists); // unlock unlocked wrong
333 TestHasPassword(EFalse, ETrue);
335 test.Next(_L("lock unlocked card"));
336 test(fs.LockDrive(d, KPw2, KPw1, EFalse) == KErrAccessDenied); // lock unlocked wrong
337 TestHasPassword(EFalse, ETrue);
338 test(fs.LockDrive(d, KPw1, KPw1, EFalse) == KErrNone); // lock unlocked right
339 TestHasPassword(EFalse, ETrue);
341 test.Next(_L("clear unlocked card"));
342 test(fs.ClearPassword(d, KPw2) == KErrAccessDenied); // clear unlocked wrong
343 TestHasPassword(EFalse, ETrue);
346 test(fs.UnlockDrive(d, KPw1, EFalse) == KErrNone);
347 TestHasPassword(EFalse, ETrue);
348 test(fs.ClearPassword(d, KPw1) == KErrNone); // clear unlocked right
349 TestHasPassword(EFalse, EFalse);
351 test.Next(_L("assign password"));
352 test(fs.LockDrive(d, KNul, KPw1, EFalse) == KErrNone); // assign test password
353 TestHasPassword(EFalse, ETrue);
354 RemountMedia(); // card is now locked
355 TestHasPassword(ETrue, ETrue);
357 test.Next(_L("clear locked card"));
358 test(fs.ClearPassword(d, KPw2) == KErrAccessDenied); // clear locked wrong
359 TestHasPassword(ETrue, ETrue);
360 test(fs.ClearPassword(d, KPw1) == KErrAccessDenied); // clear locked right
361 TestHasPassword(ETrue, ETrue);
363 test.Next(_L("clean up for following tests"));
364 test(fs.UnlockDrive(d, KPw1, EFalse) == KErrNone);
365 TestHasPassword(EFalse, ETrue);
366 test(fs.ClearPassword(d, KPw1) == KErrNone);
367 TestHasPassword(EFalse, EFalse);
369 ClearControllerStore();
370 DeletePasswordFile();
376 /** test the special cases where null passwords are used. */
378 LOCAL_C void TestNullPasswords()
380 test.Start(_L("TestNullPasswords"));
382 test.Next(_L("card has no password"));
383 test(TheFs.LockDrive(KDrv, KNul, KNul, ETrue) == KErrAccessDenied);
384 test(TheFs.UnlockDrive(KDrv, KNul, ETrue) == KErrAlreadyExists);
385 test(TheFs.ClearPassword(KDrv, KNul) == KErrAccessDenied);
387 test.Next(_L("card has password and is unlocked"));
388 test(TheFs.LockDrive(KDrv, KNul, KPw1, ETrue) == KErrNone);
390 test(TheFs.LockDrive(KDrv, KNul, KNul, ETrue) == KErrAccessDenied);
391 test(TheFs.UnlockDrive(KDrv, KNul, ETrue) == KErrAlreadyExists);
392 test(TheFs.ClearPassword(KDrv, KNul) == KErrAccessDenied);
393 test(TheFs.ClearPassword(KDrv, KPw1) == KErrNone);
395 test.Next(_L("unlock with null disallowed"));
397 test(TheFs.UnlockDrive(KDrv, KNul, ETrue) == KErrAccessDenied);
398 test.Next(_L("check can still use card"));
399 test(TheFs.LockDrive(KDrv, KNul, KPw1, ETrue) == KErrNone); // check can still use
400 test(TheFs.ClearPassword(KDrv, KPw1) == KErrNone);
402 test.Next(_L("clean up for following tests"));
403 ClearControllerStore();
404 DeletePasswordFile();
410 /** test LockDrive(), UnlockDrive() and ClearPassword() with locked media notifier */
412 LOCAL_C void TestLockUnlock()
414 test.Start(_L("TestLockUnlock"));
419 test.Next(_L("create test file"));
420 test(CreateFile() == KErrNone);
422 test.Next(_L("lock card and don't store"));
423 test(fs.LockDrive(d, KNul, KPw1, EFalse) == KErrNone); // unlocked KPw1
424 TestHasPassword(EFalse, ETrue);
426 test.Next(_L("access with right pwd"));
427 RemountMedia(); // locked KPw1
428 TestHasPassword(ETrue, ETrue);
429 test(AccessDisk(EAccessUnlock, KPw1) == KErrNone);
430 TestHasPassword(EFalse, ETrue);
432 test.Next(_L("access with cancelled pwd"));
433 RemountMedia(); // locked KPw1
434 TestHasPassword(ETrue, ETrue);
435 test(AccessDisk(EAccessCancel, KNul) == KErrLocked);
436 TestHasPassword(ETrue, ETrue);
438 test.Next(_L("access with new stored pwd"));
440 TestHasPassword(ETrue, ETrue);
441 test(AccessDisk(EAccessStore, KPw1) == KErrNone); // unlocked KPw1
442 TestHasPassword(EFalse, ETrue);
444 test.Next(_L("access with stored pwd"));
445 RemountMedia(); // unlocked KPw1 (use store)
446 TestHasPassword(EFalse, ETrue);
447 test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone);
448 TestHasPassword(EFalse, ETrue);
450 test.Next(_L("lock wrong pwd"));
451 test(fs.LockDrive(d, KPw3, KPw2, EFalse) == KErrAccessDenied); // unlocked KPw1
452 TestHasPassword(EFalse, ETrue);
454 test.Next(_L("change pwd"));
455 test(fs.LockDrive(d, KPw1, KPw2, EFalse) == KErrNone); // unlocked KPw2 (rem from store)
456 TestHasPassword(EFalse, ETrue);
458 test.Next(_L("mapping removed from store"));
460 test(AccessDisk(EAccessUnlock, KPw2) == KErrNone);
461 TestHasPassword(EFalse, ETrue);
463 test.Next(_L("wrong password"));
464 RemountMedia(); // locked KPw2
465 TestHasPassword(ETrue, ETrue);
466 test(AccessDisk(EAccessWrongPw, KNul) == KErrLocked);
467 TestHasPassword(ETrue, ETrue);
469 test.Next(_L("unlocked card"));
470 test(fs.UnlockDrive(d, KPw2, ETrue) == KErrNone); // unlocked KPw2 (add to store)
471 TestHasPassword(EFalse, ETrue);
472 test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone); // before power down
473 TestHasPassword(EFalse, ETrue);
475 test.Next(_L("clear wrong pwd"));
476 test(fs.ClearPassword(d, KPw1) == KErrAccessDenied); // KPw2 backup kept
477 TestHasPassword(EFalse, ETrue);
478 RemountMedia(); // unlocked KPw2 (use store)
479 TestHasPassword(EFalse, ETrue);
480 test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone);
481 TestHasPassword(EFalse, ETrue);
483 test.Next(_L("change pwd"));
484 test(fs.LockDrive(d, KPw2, KPw1, EFalse) == KErrNone); // locked KPw1 (rem from store)
485 TestHasPassword(EFalse, ETrue);
487 TestHasPassword(ETrue, ETrue);
488 test(AccessDisk(EAccessUnlock, KPw1) == KErrNone);
489 TestHasPassword(EFalse, ETrue);
491 test.Next(_L("cancelled pwd"));
493 TestHasPassword(ETrue, ETrue);
494 test(AccessDisk(EAccessCancel, KNul) == KErrLocked);
495 TestHasPassword(ETrue, ETrue);
497 test.Next(_L("clean up for following tests"));
498 test(fs.UnlockDrive(d, KPw1, EFalse) == KErrNone);
499 TestHasPassword(EFalse, ETrue);
500 test(fs.ClearPassword(KDrv, KPw1) == KErrNone);
501 TestHasPassword(EFalse, EFalse);
503 TestHasPassword(EFalse, EFalse);
504 test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone);
505 TestHasPassword(EFalse, EFalse);
506 ClearControllerStore();
507 DeletePasswordFile();
514 * test password store by accessing disk in various states. Ensures password
515 * store file is right size after each operation. More detailed checking of
516 * the TBusLocalDrive::ReadPasswordData() ouput is done in t_pwstr.
519 LOCAL_C void TestPasswordStore()
521 test.Start(_L("TestPasswordStore"));
523 // TInt r; // general error code
527 test.Next(_L("create test file on first media"));
528 test(CreateFile() == KErrNone);
530 test.Next(_L("lock card and don't store"));
531 test(fs.LockDrive(d, KNul, KPw5, EFalse) == KErrNone); // {}
532 TestHasPassword(EFalse, ETrue);
534 test(PWFileSize(size1) == KErrNotFound);
536 test.Next(_L("lock card and store"));
537 test(fs.LockDrive(d, KPw5, KPw3, ETrue) == KErrNone); // {0 |-> 3}
538 TestHasPassword(EFalse, ETrue);
539 test.Next(_L("access media1 with stored password"));
542 TestHasPassword(EFalse, ETrue);
543 test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone);
544 TestHasPassword(EFalse, ETrue);
546 test.Next(_L("test password file exists"));
547 test(PWFileSize(size1) == KErrNone);
548 test(size1 == 16 + 4 + KPw3.Length());
550 test.Next(_L("change cards and add second password to store"));
553 test.Next(_L("create test file on second media"));
554 test(CreateFile() == KErrNone);
556 test.Next(_L("lock card and store"));
557 test(fs.LockDrive(d, KNul, KPw4, ETrue) == KErrNone); // {0 |-> 3, 1 |-> 4}
558 TestHasPassword(EFalse, ETrue);
561 test(PWFileSize(size2) == KErrNone);
562 test(size2 == 16 + 4 + KPw3.Length() + 16 + 4 + KPw4.Length());
564 test.Next(_L("access media2 with stored password"));
566 test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone);
567 TestHasPassword(EFalse, ETrue);
569 test.Next(_L("change password"));
570 test(fs.LockDrive(d, KPw4, KPw5, ETrue) == KErrNone); // {0 |-> 3, 1 |-> 5}
571 TestHasPassword(EFalse, ETrue);
574 test(PWFileSize(size3) == KErrNone);
575 test(size3 == 16 + 4 + KPw3.Length() + 16 + 4 + KPw5.Length());
577 test.Next(_L("access media1 with stored password"));
579 test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone);
581 test.Next(_L("remove password from media 1"));
582 test(fs.ClearPassword(d, KPw3) == KErrNone); // {1 |-> 5} - 0 |-> 3
583 TestHasPassword(EFalse, EFalse);
584 test(PWFileSize(size3) == KErrNone);
585 test(size3 == 16 + 4 + KPw5.Length());
587 test.Next(_L("clean up for following tests"));
589 test(fs.ClearPassword(d, KPw5) == KErrNone); // {} - 1 |-> 5
590 TestHasPassword(EFalse, EFalse);
591 test(PWFileSize(size3) == KErrNone);
593 test.Printf(_L("replace original card\n"));
594 ChangeMedia(); // use original card
595 ClearControllerStore();
596 DeletePasswordFile();
603 * check the spin off delayed writer thread can work when many requests are queued.
605 * The background writer runs at EPriorityMuchLess, so it will not be executed until
606 * this thread sleeps.
609 LOCAL_C void TestWriteToDisk()
611 test.Start(_L("TestWriteToDisk"));
613 TInt r; // error code
616 test.Next(_L("Queuing threads"));
617 test.Printf(_L("Queuing 100 writes\n"));
619 const TInt KQueueCnt = 100;
622 TMediaPassword oldPswd; // empty - no password at start
623 TMediaPassword newPswd;
624 for (i = 0; i < KQueueCnt; ++i)
626 newPswd.Fill(i, KMaxMediaPassword);
627 test(TheFs.LockDrive(KDrv, oldPswd, newPswd, ETrue) == KErrNone);
628 oldPswd.Copy(newPswd);
631 test.Printf(_L("Waiting 20 seconds for threads to complete\n"));
632 User::After(20 * 1000 * 1000);
634 // check password file contains the last writing.
636 test.Next(_L("check password file contains last writing"));
637 const TInt KFileLen = 16 + sizeof(TUint32) + KMaxMediaPassword;
639 TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
640 mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
641 test(f.Open(TheFs, mediaPWrdFile, EFileShareExclusive | EFileStream | EFileRead) == KErrNone);
643 test(f.Size(sz) == KErrNone);
644 test(sz == KFileLen);
646 TBuf8<KFileLen> chkBuf;
647 test(f.Read(chkBuf, KFileLen) == KErrNone);
648 // defer checking buffer contents until after password cleared so not left
649 // with locked card if test fails.
652 test(TheFs.ClearPassword(KDrv, oldPswd) == KErrNone);
653 User::After(1 * 1000 * 1000); // wait to finish writing
655 r = TheFs.Delete(mediaPWrdFile);
656 test(r == KErrNone || r == KErrNotFound);
657 test(TBusLocalDrive::WritePasswordData(noMappings) == KErrNone);
659 // check contents of password file correspond to last written buffer.
661 test(chkBuf.Length() == KFileLen);
662 test(chkBuf.Mid(0, KMMCCIDLength) == TPtrC8(cid0, KMMCCIDLength));
663 const TUint32 len = TMMC::BigEndian32(chkBuf.Mid(KMMCCIDLength, sizeof(TUint32)).Ptr());
664 test(len == TInt(KMaxMediaPassword));
665 test(chkBuf.Mid(KMMCCIDLength + sizeof(TUint32), KMMCCIDLength) == oldPswd);
667 test.Next(_L("clean up for following tests"));
668 ClearControllerStore();
669 DeletePasswordFile();
675 /** test unable to format locked card */
677 LOCAL_C void TestFormat()
679 test.Start(_L("TestFormat"));
681 // TInt r; // error code
686 bfDrv.Append(KDrvLtr);
690 test.Next(_L("create test file"));
691 test(CreateFile() == KErrNone);
693 test.Next(_L("lock drive"));
694 test(TheFs.LockDrive(KDrv, KNul, KPw2, EFalse) == KErrNone);
697 test.Next(_L("unlock card and don't store"));
698 test(AccessDisk(EAccessUnlock, KPw2) == KErrNone);
700 // format unlocked drive
701 test.Next(_L("format unlocked card"));
704 test(fmt.Open(fs, bfDrv, EHighDensity, count) == KErrNone);
707 test.Printf(_L("\rfmt:%d "), count);
708 test(fmt.Next(count) == KErrNone);
710 test.Printf(_L("\n"));
713 test.Next(_L("format locked media"));
714 RemountMedia(); // locked KPw2
715 test.Printf(_L("Notifier: No password required. Press cancel. \n"));
716 test(fmt.Open(fs, bfDrv, EHighDensity, count) == KErrLocked);
718 test.Next(_L("unlock locked card"));
719 test(fs.UnlockDrive(d, KPw2, EFalse) == KErrNone);
720 test(fs.ClearPassword(d, KPw2) == KErrNone);
722 test.Next(_L("create test file"));
723 test(CreateFile() == KErrNone);
725 test.Next(_L("remount media, check not locked"));
727 test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone);
729 test.Next(_L("clean up for following tests"));
730 ClearControllerStore();
731 DeletePasswordFile();
737 /** do media change with file open */
739 LOCAL_C void TestRemount()
741 test.Start(_L("TestRemount"));
743 // TInt r; // general error code
747 test.Next(_L("create file"));
750 _LIT(KFN, ":\\openfile");
752 test.Printf(_L("fn = \"%S\"\n"), &fn);
755 test(f.Replace(fs, fn, EFileShareAny) == KErrNone);
757 test.Next(_L("lock card"));
758 test(fs.LockDrive(d, KNul, KPw5, EFalse) == KErrNone);
760 test.Next(_L("access with right pwd"));
762 test(AccessDisk(EAccessUnlock, KPw5) == KErrNone);
764 test.Next(_L("access with wrong pwd"));
766 test(AccessDisk(EAccessWrongPw, KNul) == KErrLocked);
768 test.Next(_L("access with cancelled pwd"));
770 test(AccessDisk(EAccessCancel, KNul) == KErrLocked);
772 test.Next(_L("clear password"));
773 test(fs.UnlockDrive(d, KPw5, EFalse) == KErrNone);
774 test(fs.ClearPassword(d, KPw5) == KErrNone);
776 test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone);
778 test.Next(_L("close and delete file"));
780 test(fs.Delete(fn) == KErrNone);
782 test.Next(_L("clean up for following tests"));
783 ClearControllerStore();
784 DeletePasswordFile();
791 * entry point. Displays instructions; sets up heap checking; sets up
792 * file server session and calls individual tests. Mounts drive for WINS.
795 _LIT(KSDProtDriverFileName,"MEDSDP");
796 _LIT(KSDProtDriverObjName,"Media.SdP");
797 GLDEF_C TInt E32Main()
802 test.Start(_L("Starting T_MMC"));
804 test.Printf(_L("The notifier should only apear along with user instructions.\n"));
805 test.Printf(_L("The test has failed otherwise.\n"));
806 test.Printf(_L("\n"));
807 test.Printf(_L("Use return to simulate unlock button on notifier\n"));
808 test.Printf(_L("Use space to simulate store button on notifier\n"));
809 test.Printf(_L("Use escape to simulate cancel button on notifier\n"));
810 test.Printf(_L("Press a key to continue ...\n\n"));
813 test(TheFs.Connect() == KErrNone);
815 TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
816 mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
817 TParsePtrC ppc(mediaPWrdFile);
818 TInt r = TheFs.MkDir(ppc.DriveAndPath());
819 test(r == KErrNone || r == KErrAlreadyExists);
821 // The media driver for the protected area of the SD card uses mount
822 // info. This is also used for password unlocking by the MMC media driver.
823 // Due to a temporary problem with the way mount info. is assigned to DMedia
824 // objects which results in a conflict between the two drivers, unload
825 // the protected area SD card driver for duration of test.
826 TheFs.RemountDrive(KDrv,NULL,KLocDrvRemountPostponeRemount);
827 User::FreePhysicalDevice(KSDProtDriverObjName);
829 test(TheFs.SetSessionPath(KSessionPath) == KErrNone);
831 // initialize the TMediaPassword data
832 KNul.Copy(reinterpret_cast<const TUint8 *>(L""), 0);
833 KPw1.Copy(reinterpret_cast<const TUint8 *>(L"b"), 2);
834 KPw2.Copy(reinterpret_cast<const TUint8 *>(L"cd"), 4);
835 KPw3.Copy(reinterpret_cast<const TUint8 *>(L"def"), 6);
836 KPw4.Copy(reinterpret_cast<const TUint8 *>(L"efgh"), 8);
837 KPw5.Copy(reinterpret_cast<const TUint8 *>(L"fghij"), 10);
839 test.Next(_L("calling ClearControllerStore"));
840 ClearControllerStore();
841 test.Next(_L("calling DeletePasswordFile"));
842 DeletePasswordFile();
844 test.Next(_L("calling TestLockUnlockR"));
846 test.Next(_L("calling TestNullPasswords"));
848 test.Next(_L("calling TestLockUnlock"));
851 test.Next(_L("calling TestPasswordStore"));
853 test.Next(_L("calling TestWriteToDisk"));
856 test.Next(_L("calling TestFormat"));
858 test.Next(_L("calling TestRemount"));
861 // Restore SD Card protected area media driver
862 User::LoadPhysicalDevice(KSDProtDriverFileName);