--- a/kerneltest/f32test/server/t_pwstr.cpp Fri Aug 06 16:34:38 2010 +0100
+++ b/kerneltest/f32test/server/t_pwstr.cpp Thu Aug 12 11:55:14 2010 +0100
@@ -1,4 +1,4 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of the License "Eclipse Public License v1.0"
@@ -101,6 +101,7 @@
// integrator, TBLDNum should be set to 3.
LOCAL_D TInt RFsDNum = -1; // File Server Drive number
+LOCAL_D TBool gManual = EFalse; // Manual Tests enabled
struct TTestMapping
{
@@ -1231,25 +1232,41 @@
test.Next(_L("open connection"));
RFs theFs;
test(theFs.Connect() == KErrNone);
-
+ // So that we are in a consistant state lets
+ // Remove the password file first. i.e. could be passwords left over from previous test failures
+ test.Next(_L("tidy up"));
+ TEntry theEntry;
+ TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
+ mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
+ test.Printf(_L("password file : %S\n"),&mediaPWrdFile);
+ error = theFs.Delete(mediaPWrdFile);
+ // Should be either KErrNone, KErrPathNotFound or KErrNotFound
+ test.Printf(_L("password file deleted: %d\n"),error);
// Now set the first password that we will use
test.Next(_L("lock the media card"));
TMediaPassword& nulPWrd = *PWDs[0];
TMediaPassword& oldPWrd = *PWDs[1];
error = theFs.LockDrive(KDriveNum, nulPWrd, oldPWrd, ETrue);
- test(KErrNone == error);
+ if (KErrNotSupported == error)
+ {
+ // Appears that passwords aren't supported on this drive config (i.e. NFE)
+ theFs.Close();
+ test.End();
+ return;
+ }
+ test_KErrNone(error);
// Verify that the password file does exist and is in the correct place
test.Next(_L("check password file exists"));
- TEntry theEntry;
- TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
- mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
error = theFs.Entry(mediaPWrdFile, theEntry);
- test (KErrNone == error);
-
+ test.Printf(_L("password file exists: %d\n"),error);
+ if (error != KErrNone && error != KErrNotFound)
+ {
+ test(0);
+ }
// Attempt to set a new password without specifying the current one
test.Next(_L("change password failure"));
@@ -1261,27 +1278,44 @@
// Change the password for a new one...
test.Next(_L("change password success"));
error = theFs.LockDrive(KDriveNum, oldPWrd, newPWrd, ETrue);
- test(KErrNone == error);
+ test_KErrNone(error);
// Clear the password
+ // NB The file server uses a separate thread to write to the password file,
+ // so we may need to wait a short while to see any change...
test.Next(_L("clear the password"));
error = theFs.ClearPassword(KDriveNum, newPWrd);
- test(KErrNone == error);
+ test_KErrNone(error);
// Check that the password has been removed from the file
// (KMediaPWrdFile should now be zero bytes in size)
test.Next(_L("check password removal"));
- error = theFs.Entry(mediaPWrdFile, theEntry);
- test (KErrNone == error);
- test (0 == theEntry.iSize);
+ theEntry.iSize = KMaxTInt;
+ TInt n;
+ for (n=0; theEntry.iSize > 0 && n<10; n++)
+ {
+ error = theFs.Entry(mediaPWrdFile, theEntry);
+ test_KErrNone(error);
+ test.Printf(_L("Password file size is %d\n"), theEntry.iSize);
+ if (theEntry.iSize > 0)
+ User::After(1000000);
+ }
+ test (theEntry.iSize == 0);
// Remove the password file
test.Next(_L("tidy up"));
- error = theFs.Delete(mediaPWrdFile);
- test (KErrNone == error);
+ error = KErrInUse;
+ for (n=0; error == KErrInUse && n<10; n++)
+ {
+ error = theFs.Delete(mediaPWrdFile);
+ test.Printf(_L("Deleting %S, Iter %d, r %d\n"), &mediaPWrdFile, n, error);
+ if (error == KErrInUse)
+ User::After(1000000);
+ }
+ test_KErrNone(error);
theFs.Close();
@@ -1466,15 +1500,18 @@
UserHal::DriveInfo(diBuf);
TDriveInfoV1 &di=diBuf();
- test.Printf(_L(" iRegisteredDriveBitmask 0x%08X"), di.iRegisteredDriveBitmask);
+ test.Printf(_L(" iRegisteredDriveBitmask 0x%08X\n"), di.iRegisteredDriveBitmask);
aDrive = -1;
TLocalDriveCapsV5Buf capsBuf;
TBusLocalDrive TBLD;
TLocalDriveCapsV5& caps = capsBuf();
+
TPtrC8 localSerialNum;
TInt registeredDriveNum = 0;
+
+ // Find a Drive that has Password support.
for(aDrive=0; aDrive < KMaxLocalDrives; aDrive++)
{
TInt driveNumberMask = 1 << aDrive;
@@ -1483,27 +1520,29 @@
test.Printf(_L(" Drive %d - %S\r\n"), aDrive, &di.iDriveName[registeredDriveNum]);
- // check that the card is readable (so we can ignore for empty card slots)
- if ((di.iDriveName[registeredDriveNum].MatchF(_L("MultiMediaCard0")) == KErrNone) ||
- (di.iDriveName[registeredDriveNum].MatchF(_L("SDIOCard0")) == KErrNone))
- {
-
- TBool TBLDChangedFlag;
- TInt r = TBLD.Connect(aDrive, TBLDChangedFlag);
+ TBool TBLDChangedFlag;
+ TInt r = TBLD.Connect(aDrive, TBLDChangedFlag);
//test.Printf(_L(" Connect returned %d\n"), r);
- if (r == KErrNone)
- {
- r = TBLD.Caps(capsBuf);
- localSerialNum.Set(caps.iSerialNum, caps.iSerialNumLength);
- const TInt KSectSize = 512;
- TBuf8<KSectSize> sect;
- r = TBLD.Read(0, KSectSize, sect);
+ if (r == KErrNone)
+ {
+ r = TBLD.Caps(capsBuf);
+
+ //Check media is lockable if not carry on
+ if (caps.iMediaAtt & KMediaAttLockable)
+ {
+ test.Printf(_L("Drive %d is Lockable\n"),aDrive);
+ localSerialNum.Set(caps.iSerialNum, caps.iSerialNumLength);
+ const TInt KSectSize = 512;
+ TBuf8<KSectSize> sect;
+ r = TBLD.Read(0, KSectSize, sect);
//test.Printf(_L(" Read returned %d\n"), r);
TBLD.Disconnect();
if (r == KErrNone)
break;
}
+
+ TBLD.Disconnect();
}
registeredDriveNum++;
}
@@ -1625,7 +1664,9 @@
for (n=0; n<30 && !TestLocked(aFs, aTheMemoryCardDrive); n++)
{
User::After(1000000);
+ test.Printf(_L("."));
}
+ test.Printf(_L("\n"));
test(n < 30);
test(TestLocked(aFs, aTheMemoryCardDrive)); // should now be locked
}
@@ -1941,7 +1982,6 @@
fs.Close();
}
-
LOCAL_C void RunTests()
//
// Main test routine. Calls other test functions.
@@ -1964,34 +2004,47 @@
test.Next(_L("Allocating test data"));
AllocateTestData();
- test.Next(_L("Testing locking / unlocking using file server APIs"));
- TestFsLockUnlock();
+ if (gManual)
+ {
+ test.Next(_L("Testing locking / unlocking using file server APIs"));
+ TestFsLockUnlock();
- test.Next(_L("Testing Power Down Status Reporting using file server APIs"));
- TestPowerDownStatus();
+ test.Next(_L("Testing Power Down Status Reporting using file server APIs"));
+ TestPowerDownStatus();
- test.Next(_L("Testing RFs::NotifyChange() with RFs::UnlockDrive()"));
- TestUnlockDriveNotifyChange();
+ test.Next(_L("Testing RFs::NotifyChange() with RFs::UnlockDrive()"));
+ TestUnlockDriveNotifyChange();
- test.Next(_L("Forced Erase"));
- TestFormatErase();
+ test.Next(_L("Forced Erase"));
+ TestFormatErase();
+ }
+
test.Next(_L("Testing store management"));
TestStaticStore();
- test.Next(_L("Testing locking functions"));
- TestLockUnlock();
- test.Next(_L("Testing Elide Passwords"));
- TestElidePasswords();
- test.Next(_L("Testing Null Passwords"));
- TestNullPasswords();
- test.Next(_L("Testing controller store"));
- TestControllerStore();
- test.Next(_L("Testing auto unlock"));
- TestAutoUnlock();
+
+ if (gManual)
+ {
+ test.Next(_L("Testing locking functions"));
+ TestLockUnlock();
+ test.Next(_L("Testing Elide Passwords"));
+ TestElidePasswords();
+ test.Next(_L("Testing Null Passwords"));
+ TestNullPasswords();
+ test.Next(_L("Testing controller store"));
+ TestControllerStore();
+ test.Next(_L("Testing auto unlock"));
+ TestAutoUnlock();
+ }
+
test.Next(_L("Testing password file"));
TestPasswordFile();
- test.Next(_L("Testing writing a valid password to store unlocks card"));
- TestWriteToPasswordStoreUnlocksCard();
-
+
+ if (gManual)
+ {
+ test.Next(_L("Testing writing a valid password to store unlocks card"));
+ TestWriteToPasswordStoreUnlocksCard();
+ }
+
test.Next(_L("Disconnecting TBLD"));
TBLD.Disconnect();
@@ -2001,15 +2054,43 @@
__UHEAP_MARKEND;
}
+LOCAL_D void ParseCommandLineArgs()
+ {
+
+ TBuf<0x100> cmd;
+ User::CommandLine(cmd);
+ TLex lex(cmd);
+
+ for (TPtrC token=lex.NextToken(); token.Length() != 0;token.Set(lex.NextToken()))
+ {
+ if (token.CompareF(_L("-m"))== 0)
+ {
+ gManual = ETrue;
+ continue;
+ }
+ }
+ }
TInt E32Main()
{
test.Title();
- test.Start(_L("E32Main"));
+ test.Start(_L("T_PWSTR"));
+
+#if defined(__WINS__)
+ if (!gManual)
+ {
+ test.Printf(_L("Automated T_PWSTR not supported on emulated devices\n"));
+ }
+ else
+#endif
+ {
+ ParseCommandLineArgs();
+
+ RunTests();
+ }
+
- RunTests();
-
test.End();
test.Close();