kerneltest/f32test/server/t_pwstr.cpp
changeset 109 b3a1d9898418
parent 33 0173bcd7697c
child 244 a77889bee936
equal deleted inserted replaced
102:ef2a444a7410 109:b3a1d9898418
    16 // 
    16 // 
    17 //
    17 //
    18 
    18 
    19 //#include <p32mmc.h>
    19 //#include <p32mmc.h>
    20 
    20 
       
    21 #define __E32TEST_EXTENSION__
    21 #include <e32test.h>
    22 #include <e32test.h>
    22 #include <f32fsys.h>
    23 #include <f32fsys.h>
    23 #include <e32def.h>
    24 #include <e32def.h>
    24 #include <e32def_private.h>
    25 #include <e32def_private.h>
    25 #include <e32hal.h>
    26 #include <e32hal.h>
   387 	for (i = 0; i < wStore.Length(); i++)						// corrupt (partial)
   388 	for (i = 0; i < wStore.Length(); i++)						// corrupt (partial)
   388 		{
   389 		{
   389 		wStore.SetLength(i);
   390 		wStore.SetLength(i);
   390 		TInt r(TBLD.WritePasswordData(wStore));
   391 		TInt r(TBLD.WritePasswordData(wStore));
   391 		if (i == 0 || i == mapSizes[0][0] || i == mapSizes[0][0] + mapSizes[1][1])
   392 		if (i == 0 || i == mapSizes[0][0] || i == mapSizes[0][0] + mapSizes[1][1])
   392 			test(r == KErrNone);
   393 			{
       
   394 			test_KErrNone(r);
       
   395 			}
   393 		else
   396 		else
   394 			test(r == KErrCorrupt && TBLD.PasswordStoreLengthInBytes() == 0);
   397 			{
       
   398 			test_Value(r, r == KErrCorrupt && TBLD.PasswordStoreLengthInBytes() == 0);
       
   399 			}
   395 		}
   400 		}
   396 
   401 
   397 	test.Next(_L("Exceeding password store size"));	
   402 	test.Next(_L("Exceeding password store size"));	
   398 
   403 
   399 	wStore.Zero();	// empty password store
   404 	wStore.Zero();	// empty password store
   407 		AddMapping(wStore, CIDs[n], &password);
   412 		AddMapping(wStore, CIDs[n], &password);
   408 		test.Printf(_L("Mapping:%d store size: %d bytes\n"),n , wStore.Length() );
   413 		test.Printf(_L("Mapping:%d store size: %d bytes\n"),n , wStore.Length() );
   409 		const TInt r = TBLD.WritePasswordData(wStore);
   414 		const TInt r = TBLD.WritePasswordData(wStore);
   410 		test.Printf(_L("WritePasswordData() --> ret=%d\n"), r);
   415 		test.Printf(_L("WritePasswordData() --> ret=%d\n"), r);
   411 	 	if(n==KMaxNumOfStoreEntries)
   416 	 	if(n==KMaxNumOfStoreEntries)
   412 	 		test(r == KErrOverflow);
   417 			{
       
   418 	 		test_Value(r, r == KErrOverflow);
       
   419 			}
   413 	 	else
   420 	 	else
   414 	 		test(r == KErrNone);	
   421 			{
       
   422 	 		test_KErrNone(r);
       
   423 			}
   415 		}
   424 		}
   416 
   425 
   417 
   426 
   418 	// ReadPasswordData().
   427 	// ReadPasswordData().
   419 
   428 
   459 				AddMapping(wStore, CIDs[j], PWDs[k]);
   468 				AddMapping(wStore, CIDs[j], PWDs[k]);
   460 				AddMapping(wStore, CIDs[j + 1], PWDs[k + 1]);
   469 				AddMapping(wStore, CIDs[j + 1], PWDs[k + 1]);
   461 
   470 
   462 				if ((r = TBLD.WritePasswordData(wStore)) != KErrNone)
   471 				if ((r = TBLD.WritePasswordData(wStore)) != KErrNone)
   463 					{
   472 					{
   464 					test(r == KErrNoMemory);
   473 					test_Value(r, r == KErrNoMemory);
   465 					test(TBLD.PasswordStoreLengthInBytes() == 0);
   474 					test(TBLD.PasswordStoreLengthInBytes() == 0);
   466 					}
   475 					}
   467 				else
   476 				else
   468 					{
   477 					{
   469 					test(TBLD.ReadPasswordData(rStore) == KErrNone);
   478 					test(TBLD.ReadPasswordData(rStore) == KErrNone);
   598 
   607 
   599 		TTestMapping mp;
   608 		TTestMapping mp;
   600 		mp.iCIDIdx = cidIdx;
   609 		mp.iCIDIdx = cidIdx;
   601 		mp.iPWDIdx = pwdIdx;
   610 		mp.iPWDIdx = pwdIdx;
   602 		TRAP(r, aMP->InsertL(0, mp));
   611 		TRAP(r, aMP->InsertL(0, mp));
   603 		test(r == KErrNone);
   612 		test_KErrNone(r);
   604 
   613 
   605 		iBIdx += KMMCCIDLength + sizeof(TInt32) + pwd_len;
   614 		iBIdx += KMMCCIDLength + sizeof(TInt32) + pwd_len;
   606 		}
   615 		}
   607 	}
   616 	}
   608 
   617 
   741 //
   750 //
   742 	{
   751 	{
   743 	TInt r = AccessDisk();
   752 	TInt r = AccessDisk();
   744 	if (r != KErrLocked)
   753 	if (r != KErrLocked)
   745 		test.Printf(_L("AccessDisk() returned %d\n"), r);
   754 		test.Printf(_L("AccessDisk() returned %d\n"), r);
   746 	test(r == KErrLocked);
   755 	test_Value(r, r == KErrLocked);
   747 	test(TBLD.Unlock(aPWD, aStore) == KErrNone);
   756 	test(TBLD.Unlock(aPWD, aStore) == KErrNone);
   748 	}
   757 	}
   749 
   758 
   750 
   759 
   751 LOCAL_C void TestLockUnlock()
   760 LOCAL_C void TestLockUnlock()
  1314 	TMediaPassword& nulPWrd = *PWDs[0];
  1323 	TMediaPassword& nulPWrd = *PWDs[0];
  1315 	TMediaPassword& oldPWrd = *PWDs[1];
  1324 	TMediaPassword& oldPWrd = *PWDs[1];
  1316 	r = fs.LockDrive(RFsDNum, nulPWrd, oldPWrd, EFalse);
  1325 	r = fs.LockDrive(RFsDNum, nulPWrd, oldPWrd, EFalse);
  1317 	if (r != KErrNone)
  1326 	if (r != KErrNone)
  1318 		test.Printf(_L("RFs::LockDrive() returned %d\n"), r);
  1327 		test.Printf(_L("RFs::LockDrive() returned %d\n"), r);
  1319 	test(r == KErrNone);
  1328 	test_KErrNone(r);
  1320 
  1329 
  1321 	RemountMedia();		// card is now locked
  1330 	RemountMedia();		// card is now locked
  1322 
  1331 
  1323 	RFormat fmt;
  1332 	RFormat fmt;
  1324 	TPckgBuf<TInt> stepPkg;
  1333 	TPckgBuf<TInt> stepPkg;
  1327 
  1336 
  1328 	test.Next(_L("format locked card"));
  1337 	test.Next(_L("format locked card"));
  1329 	r = fmt.Open(fs, driveName, EHighDensity, stepPkg());
  1338 	r = fmt.Open(fs, driveName, EHighDensity, stepPkg());
  1330 	if (r != KErrLocked)
  1339 	if (r != KErrLocked)
  1331 		test.Printf(_L("RFormat::Next() returned %d\n"), r);
  1340 		test.Printf(_L("RFormat::Next() returned %d\n"), r);
  1332 	test(r == KErrLocked);
  1341 	test_Value(r, r == KErrLocked);
  1333 
  1342 
  1334 	test.Printf(_L("\n"));
  1343 	test.Printf(_L("\n"));
  1335 	fmt.Close();
  1344 	fmt.Close();
  1336 
  1345 
  1337 	_LIT(KLitStars,"********************");
  1346 	_LIT(KLitStars,"********************");
  1338 	test.Next(_L("force erase locked card"));
  1347 	test.Next(_L("force erase locked card"));
  1339 	r = fmt.Open(fs, driveName, EHighDensity | EForceErase, stepPkg());
  1348 	r = fmt.Open(fs, driveName, EHighDensity | EForceErase, stepPkg());
  1340 	if (r != KErrNone)
  1349 	if (r != KErrNone)
  1341 		test.Printf(_L("RFormat::Open() returned %d\n"), r);
  1350 		test.Printf(_L("RFormat::Open() returned %d\n"), r);
  1342 	test (r == KErrNone);
  1351 	test_KErrNone(r);
  1343 	
  1352 	
  1344 	while (stepPkg() > 0)
  1353 	while (stepPkg() > 0)
  1345 		{
  1354 		{
  1346 		TRequestStatus status;
  1355 		TRequestStatus status;
  1347 		fmt.Next(stepPkg, status);
  1356 		fmt.Next(stepPkg, status);
  1386 	test(TBLD.PasswordStoreLengthInBytes() == 0);
  1395 	test(TBLD.PasswordStoreLengthInBytes() == 0);
  1387 	
  1396 	
  1388 	test.Next(_L("lock card"));
  1397 	test.Next(_L("lock card"));
  1389 	test.Next(_L("assign test password"));
  1398 	test.Next(_L("assign test password"));
  1390 	r = TBLD.SetPassword(nulPWrd, testPassword, EFalse);
  1399 	r = TBLD.SetPassword(nulPWrd, testPassword, EFalse);
  1391 	test(r == KErrNone);
  1400 	test_KErrNone(r);
  1392 
  1401 
  1393 	RemountMedia();		// card is now locked
  1402 	RemountMedia();		// card is now locked
  1394 
  1403 
  1395 	// test Caps() reports that card is locked
  1404 	// test Caps() reports that card is locked
  1396 	test.Next(_L("test card is locked"));
  1405 	test.Next(_L("test card is locked"));
  1397 	TLocalDriveCapsV5 driveCaps;
  1406 	TLocalDriveCapsV5 driveCaps;
  1398 	TPckg<TLocalDriveCapsV5> driveCapsPkg(driveCaps);	
  1407 	TPckg<TLocalDriveCapsV5> driveCapsPkg(driveCaps);	
  1399 	r = TBLD.Caps(driveCapsPkg);
  1408 	r = TBLD.Caps(driveCapsPkg);
  1400 	test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1409 	test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1401 
  1410 
  1402 	test (r == KErrNone);
  1411 	test_KErrNone(r);
  1403 	test ((driveCaps.iMediaAtt & KMediaAttLocked) != 0);
  1412 	test ((driveCaps.iMediaAtt & KMediaAttLocked) != 0);
  1404 
  1413 
  1405 	// Write correct password to store
  1414 	// Write correct password to store
  1406 	test.Next(_L("write correct password to store"));
  1415 	test.Next(_L("write correct password to store"));
  1407 
  1416 
  1411 	AddMapping(storeDef, CIDs[0], &testPassword);
  1420 	AddMapping(storeDef, CIDs[0], &testPassword);
  1412 	r = TBLD.WritePasswordData(storeDef);
  1421 	r = TBLD.WritePasswordData(storeDef);
  1413 
  1422 
  1414 	test.Printf(_L("WritePasswordData() returned %d\n"), r);
  1423 	test.Printf(_L("WritePasswordData() returned %d\n"), r);
  1415 	
  1424 	
  1416 	test(r == KErrNone);
  1425 	test_KErrNone(r);
  1417 
  1426 
  1418 	// test Caps() reports that card is unlocked
  1427 	// test Caps() reports that card is unlocked
  1419 	test.Next(_L("test card is unlocked"));
  1428 	test.Next(_L("test card is unlocked"));
  1420 	r = TBLD.Caps(driveCapsPkg);
  1429 	r = TBLD.Caps(driveCapsPkg);
  1421 	test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1430 	test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1422 
  1431 
  1423 	test (r == KErrNone);
  1432 	test_KErrNone(r);
  1424 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1433 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1425 
  1434 
  1426 	// Clear the password, remount and test card is unlocked
  1435 	// Clear the password, remount and test card is unlocked
  1427 	test.Next(_L("clear password, remount & test card is unlocked"));
  1436 	test.Next(_L("clear password, remount & test card is unlocked"));
  1428 	test.Next(_L("clear the password"));	
  1437 	test.Next(_L("clear the password"));	
  1431 	test.Next(_L("test card is unlocked"));
  1440 	test.Next(_L("test card is unlocked"));
  1432 
  1441 
  1433 	r = TBLD.Caps(driveCapsPkg);
  1442 	r = TBLD.Caps(driveCapsPkg);
  1434 	test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1443 	test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1435 
  1444 
  1436 	test (r == KErrNone);
  1445 	test_KErrNone(r);
  1437 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1446 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1438 
  1447 
  1439 
  1448 
  1440 	delete pstoreDef;
  1449 	delete pstoreDef;
  1441 	pstoreDef = NULL;
  1450 	pstoreDef = NULL;
  1602 TBool TestLocked(RFs& aFs, TInt aTheMemoryCardDrive)
  1611 TBool TestLocked(RFs& aFs, TInt aTheMemoryCardDrive)
  1603 	{
  1612 	{
  1604     TDriveInfo info;
  1613     TDriveInfo info;
  1605 
  1614 
  1606 	TInt r = aFs.Drive(info, aTheMemoryCardDrive);
  1615 	TInt r = aFs.Drive(info, aTheMemoryCardDrive);
  1607 	test (r == KErrNone);
  1616 	test_KErrNone(r);
  1608 
  1617 
  1609 	return (info.iMediaAtt & KMediaAttLocked)?(TBool)ETrue:(TBool)EFalse;
  1618 	return (info.iMediaAtt & KMediaAttLocked)?(TBool)ETrue:(TBool)EFalse;
  1610 	}
  1619 	}
  1611 
  1620 
  1612 void WaitForPowerDownLock(RFs& aFs, TInt aTheMemoryCardDrive)
  1621 void WaitForPowerDownLock(RFs& aFs, TInt aTheMemoryCardDrive)
  1655 // Lock card (with password stored) 
  1664 // Lock card (with password stored) 
  1656 	test.Next(_L("Locking Card - Password Stored"));
  1665 	test.Next(_L("Locking Card - Password Stored"));
  1657 
  1666 
  1658 	test.Next(_L("Locking card (Successful)"))	;
  1667 	test.Next(_L("Locking card (Successful)"))	;
  1659 	r = TestLockCard(fs, RFsDNum, oldpassword, password, ETrue);
  1668 	r = TestLockCard(fs, RFsDNum, oldpassword, password, ETrue);
  1660 	test(r == KErrNone); 
  1669 	test_KErrNone(r); 
  1661 		
  1670 		
  1662 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1671 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1663 
  1672 
  1664 	test.Next(_L("Card reports unlocked - before PowerDown"));
  1673 	test.Next(_L("Card reports unlocked - before PowerDown"));
  1665 	r = TBLD.Caps(driveCapsPkg);
  1674 	r = TBLD.Caps(driveCapsPkg);
  1666 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1675 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1667 
  1676 
  1668 	test (r == KErrNone);
  1677 	test_KErrNone(r);
  1669 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1678 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1670 
  1679 
  1671 	WaitForPowerDownUnlock(fs, RFsDNum);
  1680 	WaitForPowerDownUnlock(fs, RFsDNum);
  1672 	
  1681 	
  1673 	test.Next(_L("Check card reports unlocked - after PowerDown"));
  1682 	test.Next(_L("Check card reports unlocked - after PowerDown"));
  1674 	r = TBLD.Caps(driveCapsPkg);
  1683 	r = TBLD.Caps(driveCapsPkg);
  1675 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1684 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1676 
  1685 
  1677 	test (r == KErrNone);
  1686 	test_KErrNone(r);
  1678 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1687 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1679 	
  1688 	
  1680 	test.Next(_L("Clear password (Successful)"));
  1689 	test.Next(_L("Clear password (Successful)"));
  1681 	r = TestClearPassword(fs, RFsDNum, password);
  1690 	r = TestClearPassword(fs, RFsDNum, password);
  1682 	test(r == KErrNone);
  1691 	test_KErrNone(r);
  1683 	
  1692 	
  1684 // Lock card (without password in store)
  1693 // Lock card (without password in store)
  1685 	test.Next(_L("Locking card - Password NOT Stored"));
  1694 	test.Next(_L("Locking card - Password NOT Stored"));
  1686 
  1695 
  1687 	test.Next(_L("Locking card (Successful)"));
  1696 	test.Next(_L("Locking card (Successful)"));
  1688 	r = TestLockCard(fs, RFsDNum, oldpassword, password, EFalse);
  1697 	r = TestLockCard(fs, RFsDNum, oldpassword, password, EFalse);
  1689 	test(r == KErrNone); 
  1698 	test_KErrNone(r); 
  1690 		
  1699 		
  1691 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1700 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1692 	
  1701 	
  1693 	test.Next(_L("Card is reports Unlocked - before PowerDown"));
  1702 	test.Next(_L("Card is reports Unlocked - before PowerDown"));
  1694 	r = TBLD.Caps(driveCapsPkg);
  1703 	r = TBLD.Caps(driveCapsPkg);
  1695 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1704 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1696 
  1705 
  1697 	test (r == KErrNone);
  1706 	test_KErrNone(r);
  1698 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1707 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1699 
  1708 
  1700 	WaitForPowerDownLock(fs, RFsDNum);
  1709 	WaitForPowerDownLock(fs, RFsDNum);
  1701 	
  1710 	
  1702 	test.Next(_L("Card reports Locked - after PowerDown"));
  1711 	test.Next(_L("Card reports Locked - after PowerDown"));
  1703 	r = TBLD.Caps(driveCapsPkg);
  1712 	r = TBLD.Caps(driveCapsPkg);
  1704 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1713 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1705 
  1714 
  1706 	test (r == KErrNone);
  1715 	test_KErrNone(r);
  1707 	test ((driveCaps.iMediaAtt & KMediaAttLocked) != 0);
  1716 	test ((driveCaps.iMediaAtt & KMediaAttLocked) != 0);
  1708 	
  1717 	
  1709 // Unlock card
  1718 // Unlock card
  1710 	test.Next(_L("Unlock 'locked' Card - Password Stored"));
  1719 	test.Next(_L("Unlock 'locked' Card - Password Stored"));
  1711 	
  1720 	
  1712 	test.Next(_L("Unlocking card (Successful)"))	;
  1721 	test.Next(_L("Unlocking card (Successful)"))	;
  1713 	r = TestUnlockCard(fs, RFsDNum, password, ETrue);
  1722 	r = TestUnlockCard(fs, RFsDNum, password, ETrue);
  1714 	test(r == KErrNone);
  1723 	test_KErrNone(r);
  1715 	test (!TestLocked(fs, RFsDNum)); // not locked as stack hasn't powered down
  1724 	test (!TestLocked(fs, RFsDNum)); // not locked as stack hasn't powered down
  1716 	
  1725 	
  1717 	test.Next(_L("Card reports unlocked - before PowerDown"));
  1726 	test.Next(_L("Card reports unlocked - before PowerDown"));
  1718 	r = TBLD.Caps(driveCapsPkg);
  1727 	r = TBLD.Caps(driveCapsPkg);
  1719 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1728 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1720 
  1729 
  1721 	test (r == KErrNone);
  1730 	test_KErrNone(r);
  1722 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1731 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1723 
  1732 
  1724 	WaitForPowerDownUnlock(fs, RFsDNum);
  1733 	WaitForPowerDownUnlock(fs, RFsDNum);
  1725 	
  1734 	
  1726 	test.Next(_L("Card reports unlocked - after PowerDown"));
  1735 	test.Next(_L("Card reports unlocked - after PowerDown"));
  1727 	r = TBLD.Caps(driveCapsPkg);
  1736 	r = TBLD.Caps(driveCapsPkg);
  1728 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1737 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
  1729 
  1738 
  1730 	test (r == KErrNone);
  1739 	test_KErrNone(r);
  1731 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1740 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
  1732 	
  1741 	
  1733 	test.Next(_L("Clearing Password (Successful)"));
  1742 	test.Next(_L("Clearing Password (Successful)"));
  1734 	r = TestClearPassword(fs, RFsDNum, password);
  1743 	r = TestClearPassword(fs, RFsDNum, password);
  1735 	test(r == KErrNone);
  1744 	test_KErrNone(r);
  1736 	
  1745 	
  1737 	fs.Close();
  1746 	fs.Close();
  1738 	
  1747 	
  1739 	test.End();
  1748 	test.End();
  1740 	}
  1749 	}
  1755 	TMediaPassword oldpassword;
  1764 	TMediaPassword oldpassword;
  1756 	TMediaPassword newpassword = (TUint8*) "salasana";
  1765 	TMediaPassword newpassword = (TUint8*) "salasana";
  1757 	TMediaPassword wrongpwd = (TUint8*) "failtest";
  1766 	TMediaPassword wrongpwd = (TUint8*) "failtest";
  1758 
  1767 
  1759 	r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse);
  1768 	r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse);
  1760 	test(r == KErrNone);
  1769 	test_KErrNone(r);
  1761 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1770 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1762 
  1771 
  1763 	test.Next(_L("test unlocking fails if still powered up"));
  1772 	test.Next(_L("test unlocking fails if still powered up"));
  1764 	r = TestUnlockCard(fs, RFsDNum, newpassword, EFalse);
  1773 	r = TestUnlockCard(fs, RFsDNum, newpassword, EFalse);
  1765 	test(r == KErrAlreadyExists);		// already unlocked (as stack won't have powered down yet)
  1774 	test_Value(r, r == KErrAlreadyExists);		// already unlocked (as stack won't have powered down yet)
  1766 	test (!TestLocked(fs, RFsDNum));
  1775 	test (!TestLocked(fs, RFsDNum));
  1767 
  1776 
  1768 	test.Next(_L("test clearing succeeds if still powered up"));
  1777 	test.Next(_L("test clearing succeeds if still powered up"));
  1769 	r = TestClearPassword(fs, RFsDNum, newpassword);
  1778 	r = TestClearPassword(fs, RFsDNum, newpassword);
  1770 	test(r == KErrNone);
  1779 	test_KErrNone(r);
  1771 	test(!TestLocked(fs, RFsDNum));
  1780 	test(!TestLocked(fs, RFsDNum));
  1772 	
  1781 	
  1773 	test.Next(_L("test locking card again"));
  1782 	test.Next(_L("test locking card again"));
  1774 	r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse);
  1783 	r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse);
  1775 	test(r == KErrNone);
  1784 	test_KErrNone(r);
  1776 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1785 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1777 
  1786 
  1778 	WaitForPowerDownLock(fs, RFsDNum);
  1787 	WaitForPowerDownLock(fs, RFsDNum);
  1779 
  1788 
  1780 	// DEF111681: CheckDisk is returning bad error code when run on locked SD card
  1789 	// DEF111681: CheckDisk is returning bad error code when run on locked SD card
  1786 	WaitForPowerDownLock(fs, RFsDNum);
  1795 	WaitForPowerDownLock(fs, RFsDNum);
  1787 	TFileName sessionPath;
  1796 	TFileName sessionPath;
  1788 	sessionPath=_L("?:\\");
  1797 	sessionPath=_L("?:\\");
  1789 	TChar driveLetter;
  1798 	TChar driveLetter;
  1790 	r = fs.DriveToChar(RFsDNum,driveLetter);
  1799 	r = fs.DriveToChar(RFsDNum,driveLetter);
  1791 	test(r==KErrNone);
  1800 	test_KErrNone(r);
  1792 	sessionPath[0]=(TText)driveLetter;
  1801 	sessionPath[0]=(TText)driveLetter;
  1793 	r = fs.CheckDisk(sessionPath);
  1802 	r = fs.CheckDisk(sessionPath);
  1794 	test(r == KErrNone || r == KErrLocked);
  1803 	test_Value(r, r == KErrNone || r == KErrLocked);
  1795 	WaitForPowerDownLock(fs, RFsDNum);
  1804 	WaitForPowerDownLock(fs, RFsDNum);
  1796 
  1805 
  1797 
  1806 
  1798 	// DEF111700: Formatting a locked SD/MMC leaves it in a bad state (causes panics later)
  1807 	// DEF111700: Formatting a locked SD/MMC leaves it in a bad state (causes panics later)
  1799 	// This was caused by format calling TDrive::MountMedia(ETrue) and then not dismounting
  1808 	// This was caused by format calling TDrive::MountMedia(ETrue) and then not dismounting
  1800 	r = fs.RemountDrive(RFsDNum);
  1809 	r = fs.RemountDrive(RFsDNum);
  1801 	test (r == KErrNone);
  1810 	test_KErrNone(r);
  1802 	RFormat fmt;
  1811 	RFormat fmt;
  1803 	TPckgBuf<TInt> stepPkg;
  1812 	TPckgBuf<TInt> stepPkg;
  1804 	TDriveUnit driveUnit(RFsDNum);
  1813 	TDriveUnit driveUnit(RFsDNum);
  1805 	TDriveName driveName = driveUnit.Name();
  1814 	TDriveName driveName = driveUnit.Name();
  1806 	test.Next(_L("format locked card"));
  1815 	test.Next(_L("format locked card"));
  1807 	r = fmt.Open(fs, driveName, EHighDensity, stepPkg());
  1816 	r = fmt.Open(fs, driveName, EHighDensity, stepPkg());
  1808 	if (r != KErrLocked)
  1817 	if (r != KErrLocked)
  1809 		test.Printf(_L("RFormat::Next() returned %d\n"), r);
  1818 		test.Printf(_L("RFormat::Next() returned %d\n"), r);
  1810 	test(r == KErrLocked);
  1819 	test_Value(r, r == KErrLocked);
  1811 	test.Printf(_L("\n"));
  1820 	test.Printf(_L("\n"));
  1812 	fmt.Close();
  1821 	fmt.Close();
  1813 	r = fs.CheckDisk(sessionPath);
  1822 	r = fs.CheckDisk(sessionPath);
  1814 	test(r == KErrLocked);
  1823 	test_Value(r, r == KErrLocked);
  1815 
  1824 
  1816 
  1825 
  1817 	test.Next(_L("test unlocking fails after powered down & unlocked with wrong password"));
  1826 	test.Next(_L("test unlocking fails after powered down & unlocked with wrong password"));
  1818 	r = TestUnlockCard(fs, RFsDNum, wrongpwd, EFalse);
  1827 	r = TestUnlockCard(fs, RFsDNum, wrongpwd, EFalse);
  1819 	test(r == KErrAccessDenied);		// unlocked should now fail
  1828 	test_Value(r, r == KErrAccessDenied);		// unlocked should now fail
  1820 
  1829 
  1821 	test.Next(_L("test unlocking succeeds for correct password after powered down & locked"));
  1830 	test.Next(_L("test unlocking succeeds for correct password after powered down & locked"));
  1822 	r = TestUnlockCard(fs, RFsDNum, newpassword, EFalse);
  1831 	r = TestUnlockCard(fs, RFsDNum, newpassword, EFalse);
  1823 	test(r == KErrNone);		// unlocked should now succeed
  1832 	test_KErrNone(r);		// unlocked should now succeed
  1824 
  1833 
  1825 	test.Next(_L("test unlocking fails after successful unlock"));
  1834 	test.Next(_L("test unlocking fails after successful unlock"));
  1826 	r = TestUnlockCard(fs, RFsDNum, wrongpwd, EFalse);
  1835 	r = TestUnlockCard(fs, RFsDNum, wrongpwd, EFalse);
  1827 	test(r == KErrAlreadyExists);		// unlocked should now succeed
  1836 	test_Value(r, r == KErrAlreadyExists);		// unlocked should now succeed
  1828 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1837 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1829 
  1838 
  1830 	test.Next(_L("test locking card with new password (with wrong password as old password)"));
  1839 	test.Next(_L("test locking card with new password (with wrong password as old password)"));
  1831 	r = TestLockCard(fs, RFsDNum, wrongpwd, newpassword, EFalse);
  1840 	r = TestLockCard(fs, RFsDNum, wrongpwd, newpassword, EFalse);
  1832 	test(r == KErrAccessDenied);
  1841 	test_Value(r, r == KErrAccessDenied);
  1833 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1842 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1834 
  1843 
  1835 	test.Next(_L("test locking card with new password (with right password as old password)"));
  1844 	test.Next(_L("test locking card with new password (with right password as old password)"));
  1836 	r = TestLockCard(fs, RFsDNum, newpassword, wrongpwd, EFalse);
  1845 	r = TestLockCard(fs, RFsDNum, newpassword, wrongpwd, EFalse);
  1837 	test(r == KErrNone);
  1846 	test_KErrNone(r);
  1838 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1847 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
  1839 
  1848 
  1840 	WaitForPowerDownLock(fs, RFsDNum);
  1849 	WaitForPowerDownLock(fs, RFsDNum);
  1841 	
  1850 	
  1842 	test.Next(_L("test clearing fails with wrong password if powered down & locked"));
  1851 	test.Next(_L("test clearing fails with wrong password if powered down & locked"));
  1843 	r = TestClearPassword(fs, RFsDNum, newpassword); // Note: we have set the wrong password as the new password
  1852 	r = TestClearPassword(fs, RFsDNum, newpassword); // Note: we have set the wrong password as the new password
  1844 	test(r == KErrAccessDenied);
  1853 	test_Value(r, r == KErrAccessDenied);
  1845 	test(TestLocked(fs, RFsDNum));
  1854 	test(TestLocked(fs, RFsDNum));
  1846 
  1855 
  1847 	test.Next(_L("test clearing succeeds with right password if powered down & locked"));
  1856 	test.Next(_L("test clearing succeeds with right password if powered down & locked"));
  1848 	r = TestClearPassword(fs, RFsDNum, wrongpwd);
  1857 	r = TestClearPassword(fs, RFsDNum, wrongpwd);
  1849 	test(r == KErrNone);
  1858 	test_KErrNone(r);
  1850 	test(!TestLocked(fs, RFsDNum));
  1859 	test(!TestLocked(fs, RFsDNum));
  1851 
  1860 
  1852 	test.Next(_L("test locking card again"));
  1861 	test.Next(_L("test locking card again"));
  1853 	r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse);
  1862 	r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse);
  1854 	test(r == KErrNone);
  1863 	test_KErrNone(r);
  1855 	test(!TestLocked(fs, RFsDNum));		// not locked yet as stack hasn't powered down
  1864 	test(!TestLocked(fs, RFsDNum));		// not locked yet as stack hasn't powered down
  1856 
  1865 
  1857 	test.Next(_L("test forced erase fails if still powered up"));
  1866 	test.Next(_L("test forced erase fails if still powered up"));
  1858 	r = ExecuteForcedEraseTestL(fs, RFsDNum);
  1867 	r = ExecuteForcedEraseTestL(fs, RFsDNum);
  1859 	test(r == KErrAccessDenied);		// fails because card is not yet locked
  1868 	test_Value(r, r == KErrAccessDenied);		// fails because card is not yet locked
  1860 
  1869 
  1861 	WaitForPowerDownLock(fs, RFsDNum);
  1870 	WaitForPowerDownLock(fs, RFsDNum);
  1862 
  1871 
  1863 
  1872 
  1864 	test.Next(_L("test forced erase succeeds if powered down & locked"));
  1873 	test.Next(_L("test forced erase succeeds if powered down & locked"));
  1865 	r = ExecuteForcedEraseTestL(fs, RFsDNum);
  1874 	r = ExecuteForcedEraseTestL(fs, RFsDNum);
  1866 	test(r == KErrNone);
  1875 	test_KErrNone(r);
  1867 
  1876 
  1868 	fs.Close();
  1877 	fs.Close();
  1869 	test.End();
  1878 	test.End();
  1870 	}
  1879 	}
  1871 
  1880 
  1882 
  1891 
  1883 	TFileName sessionPath;
  1892 	TFileName sessionPath;
  1884 	sessionPath=_L("?:\\");
  1893 	sessionPath=_L("?:\\");
  1885 	TChar driveLetter;
  1894 	TChar driveLetter;
  1886 	TInt r=fs.DriveToChar(RFsDNum,driveLetter);
  1895 	TInt r=fs.DriveToChar(RFsDNum,driveLetter);
  1887 	test(r==KErrNone);
  1896 	test_KErrNone(r);
  1888 	sessionPath[0]=(TText)driveLetter;
  1897 	sessionPath[0]=(TText)driveLetter;
  1889 	r=fs.SetSessionPath(sessionPath);
  1898 	r=fs.SetSessionPath(sessionPath);
  1890 	test(r==KErrNone);
  1899 	test_KErrNone(r);
  1891     
  1900     
  1892 	TInt nRes;
  1901 	TInt nRes;
  1893     TDriveInfo dInfo;
  1902     TDriveInfo dInfo;
  1894 
  1903 
  1895     nRes = fs.Drive(dInfo, RFsDNum);
  1904     nRes = fs.Drive(dInfo, RFsDNum);
  1896 	test(nRes == KErrNone);
  1905 	test_KErrNone(nRes);
  1897 	if (!(dInfo.iMediaAtt & KMediaAttLockable))
  1906 	if (!(dInfo.iMediaAtt & KMediaAttLockable))
  1898 		{
  1907 		{
  1899 		test.Printf(_L("Drive %d is not lockable %d\n"), RFsDNum);
  1908 		test.Printf(_L("Drive %d is not lockable %d\n"), RFsDNum);
  1900 		fs.Close();
  1909 		fs.Close();
  1901 		return;
  1910 		return;
  1903 
  1912 
  1904 	// attempt to lock the drive
  1913 	// attempt to lock the drive
  1905 	TMediaPassword oldPassword;
  1914 	TMediaPassword oldPassword;
  1906 	TMediaPassword newPassword = (TUint8*) "salasana";
  1915 	TMediaPassword newPassword = (TUint8*) "salasana";
  1907     nRes = fs.LockDrive(RFsDNum, oldPassword, newPassword, EFalse );
  1916     nRes = fs.LockDrive(RFsDNum, oldPassword, newPassword, EFalse );
  1908 	test(nRes == KErrNone);
  1917 	test_KErrNone(nRes);
  1909 
  1918 
  1910 	WaitForPowerDownLock(fs, RFsDNum);
  1919 	WaitForPowerDownLock(fs, RFsDNum);
  1911 
  1920 
  1912     TRequestStatus reqStatNotify1(KRequestPending);
  1921     TRequestStatus reqStatNotify1(KRequestPending);
  1913     
  1922     
  1922     //-- check that the notifier worked
  1931     //-- check that the notifier worked
  1923     User::WaitForRequest(reqStatNotify1);
  1932     User::WaitForRequest(reqStatNotify1);
  1924     test(reqStatNotify1.Int() == KErrNone);
  1933     test(reqStatNotify1.Int() == KErrNone);
  1925 
  1934 
  1926 	r = TestClearPassword(fs, RFsDNum, newPassword);
  1935 	r = TestClearPassword(fs, RFsDNum, newPassword);
  1927 	test(r == KErrNone);
  1936 	test_KErrNone(r);
  1928 	test(!TestLocked(fs, RFsDNum));
  1937 	test(!TestLocked(fs, RFsDNum));
  1929 	
  1938 	
  1930 	
  1939 	
  1931 	
  1940 	
  1932 	fs.Close();
  1941 	fs.Close();