kerneltest/f32test/server/t_fsys.cpp
changeset 281 13fbfa31d2ba
parent 266 0008ccd16016
child 271 dc268b18d709
equal deleted inserted replaced
266:0008ccd16016 281:13fbfa31d2ba
    28 using namespace Fat_Test_Utils;
    28 using namespace Fat_Test_Utils;
    29 
    29 
    30 RTest test(_L("T_FSYS"));
    30 RTest test(_L("T_FSYS"));
    31 static TInt64   gRndSeed;
    31 static TInt64   gRndSeed;
    32 
    32 
       
    33 _LIT(KTestFsy,  "T_TFSYS");
       
    34 _LIT(KTestFsy2, "T_TFSYS2");
       
    35 _LIT(KTestFsy3, "T_TFSYS3");
       
    36 
       
    37 _LIT(KTestFsName,  "Test");
       
    38 _LIT(KTestFsName2, "Test2");
       
    39 _LIT(KTestFsName3, "Test3");
       
    40 
       
    41 
       
    42 
    33 //---------------------------------------------------
    43 //---------------------------------------------------
    34 
    44 
    35 
    45 
    36 void InitGlobals()
    46 void InitGlobals()
    37 {
    47 {
    51     The maximum length for the file system and extension names is KMaxFSNameLength
    61     The maximum length for the file system and extension names is KMaxFSNameLength
    52     test how the file server supports this
    62     test how the file server supports this
    53 */
    63 */
    54 void TestFileSystemNameLength()
    64 void TestFileSystemNameLength()
    55 {
    65 {
    56     test.Next(_L("Test file system name lenght limits"));
    66     test.Next(_L("Test file system name length limits\n"));
    57     if(Is_SimulatedSystemDrive(TheFs, CurrentDrive()))
    67     if(Is_SimulatedSystemDrive(TheFs, CurrentDrive()))
    58     {
    68     {
    59         test.Printf(_L("Can't test on a simulated drive, skipping!"));
    69         test.Printf(_L("Can't test on a simulated drive, skipping!\n"));
    60         return;
    70         return;
    61     }
    71     }
    62 
    72 
    63     TInt nRes;
    73     TInt nRes;
    64     TBuf<1024> name;
    74     TBuf<1024> name;
   174     //-- mount original file system back to the drive
   184     //-- mount original file system back to the drive
   175     nRes = MountFileSystem(TheFs, CurrentDrive(), orgFSDesc);
   185     nRes = MountFileSystem(TheFs, CurrentDrive(), orgFSDesc);
   176     test_KErrNone(nRes);
   186     test_KErrNone(nRes);
   177 }
   187 }
   178 
   188 
   179 
   189 //---------------------------------------------------
   180 static void TestFileSystemNames()
   190 static void TestFileSystemNames()
   181     {
   191     {
   182     test.Next(_L("Read file system names for all drives"));
   192     test.Next(_L("TestFileSystemNames(). Read file system names for all drives\n"));
   183     TFullName name;
   193     TFullName name;
   184     TInt r;
   194     TBuf<60>  buf;
   185     for(TInt i=EDriveA;i<KMaxDrives;++i)
   195     TInt nRes;
   186         {
   196 
   187         r=TheFs.FileSystemName(name,i);
   197     TDriveList drvList;
   188         test_Value(r, r == KErrNone || r==KErrNotFound);
   198     nRes = TheFs.DriveList(drvList);
   189         TChar c;
   199     test_KErrNone(nRes);
   190         r=RFs::DriveToChar(i,c);
   200 
   191         test_KErrNone(r);
   201     for(TInt i=0; i<KMaxDrives; ++i)
   192         if(name.Length())       
   202         {
   193             test.Printf(_L("File System Name on drive %c is %S\n"),(char)c,&name);
   203         buf.Format(_L("drv %C: att:0x%02x"), 'A'+i, drvList[i]);
       
   204         
       
   205         nRes = TheFs.FileSystemName(name, i);
       
   206         test_Value(nRes, nRes == KErrNone || nRes==KErrNotFound);
       
   207         
       
   208         if(nRes == KErrNone)
       
   209             {
       
   210             buf.AppendFormat(_L(" Mounted FS:%S"), &name);
       
   211             }
   194         else
   212         else
   195             test.Printf(_L("No file system on drive %c\n"),(char)c);
   213             {
   196         }
   214             buf.Append(_L(" Mounted FS:"));
   197     }
   215             }
   198 
   216 
       
   217         buf.Append(_L("\n"));
       
   218         test.Printf(buf);
       
   219         }
       
   220     
       
   221     }
       
   222 
       
   223 //---------------------------------------------------
   199 static void CheckDismount(TDesC& aFs,TInt aDrive)
   224 static void CheckDismount(TDesC& aFs,TInt aDrive)
   200     {
   225     {
   201 
   226 
   202     if (aDrive==EDriveC) // ??? Can't test on C: - see below
   227     if (aDrive==EDriveC) // ??? Can't test on C: - see below
   203         return;
   228         return;
   214 
   239 
   215     TBuf<128> b;
   240     TBuf<128> b;
   216     TDriveInfo di;
   241     TDriveInfo di;
   217     r=TheFs.Drive(di,aDrive);
   242     r=TheFs.Drive(di,aDrive);
   218     test_KErrNone(r);
   243     test_KErrNone(r);
   219     b.Format(_L("Test dismounting of test file system on %c: (DrvAtt:%x MedAtt:%x)"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   244     b.Format(_L("Test dismounting of test file system on %c: (DrvAtt:%x MedAtt:%x)\n"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   220     test.Next(b);
   245     test.Next(b);
   221     
   246     
   222     // Test cannot dismount on rom drive
   247     // Test cannot dismount on rom drive
   223     test.Next(_L("Test cannot dismount on Rom drive"));
   248     test.Next(_L("Test cannot dismount on Rom drive\n"));
   224     TFullName zName;
   249     TFullName zName;
   225     r=TheFs.FileSystemName(zName,EDriveZ);
   250     r=TheFs.FileSystemName(zName,EDriveZ);
   226     test_KErrNone(r);
   251     test_KErrNone(r);
   227     r=TheFs.DismountFileSystem(zName,EDriveZ);
   252     r=TheFs.DismountFileSystem(zName,EDriveZ);
   228     test.Printf(_L("r=%d"),r);
   253     test.Printf(_L("r=%d\n"),r);
   229     // NB if paging is enabled on a ROFS partition which is part of the composite file system then the 
   254     // NB if paging is enabled on a ROFS partition which is part of the composite file system then the 
   230     // likelihood is that there will be a at least one file clamped: in this case there error will be KErrInUse
   255     // likelihood is that there will be a at least one file clamped: in this case there error will be KErrInUse
   231     test_Value(r, r == KErrAccessDenied || r==KErrInUse);
   256     test_Value(r, r == KErrAccessDenied || r==KErrInUse);
   232 
   257 
   233     // Test cannot dismount on wrong drive
   258     // Test cannot dismount on wrong drive
   234     test.Next(_L("Test cannot dismount on wrong drive"));
   259     test.Next(_L("Test cannot dismount on wrong drive\n"));
   235     r=TheFs.DismountFileSystem(aFs,EDriveA);
   260     r=TheFs.DismountFileSystem(aFs,EDriveA);
   236     test_Value(r, r == KErrNotReady);
   261     test_Value(r, r == KErrNotReady);
   237 
   262 
   238     // Test cannot dismount with wrong name
   263     // Test cannot dismount with wrong name
   239     test.Next(_L("Test cannot dismount with wrong file system name"));
   264     test.Next(_L("Test cannot dismount with wrong file system name\n"));
   240     r=TheFs.DismountFileSystem(_L("abc"),aDrive);
   265     r=TheFs.DismountFileSystem(_L("abc"),aDrive);
   241     test_Value(r, r == KErrNotFound);
   266     test_Value(r, r == KErrNotFound);
   242  
   267  
   243     // Test cannot dismount with a file open
   268     // Test cannot dismount with a file open
   244     test.Next(_L("Test cannot dismount with a file open"));
   269     test.Next(_L("Test cannot dismount with a file open\n"));
   245     r=TheFs.SetSessionPath(newSess);
   270     r=TheFs.SetSessionPath(newSess);
   246     RFile file;
   271     RFile file;
   247     r=file.Replace(TheFs,_L("abc"),EFileShareAny);
   272     r=file.Replace(TheFs,_L("abc"),EFileShareAny);
   248     test_KErrNone(r);
   273     test_KErrNone(r);
   249     r=TheFs.SessionPath(newSess);
   274     r=TheFs.SessionPath(newSess);
   254     r=TheFs.DismountFileSystem(aFs,aDrive);
   279     r=TheFs.DismountFileSystem(aFs,aDrive);
   255     test_Value(r, r == KErrInUse);
   280     test_Value(r, r == KErrInUse);
   256     file.Close();
   281     file.Close();
   257 
   282 
   258     // Now test dismount works
   283     // Now test dismount works
   259     test.Next(_L("Test dismounts OK"));
   284     test.Next(_L("Test dismounts OK\n"));
   260     r=TheFs.DismountFileSystem(aFs,aDrive);
   285     r=TheFs.DismountFileSystem(aFs,aDrive);
   261     if(r!=KErrNone)
   286     if(r!=KErrNone)
   262         {
   287         {
   263         test.Printf(_L("Error = %d"),r);    
   288         test.Printf(_L("Error = %d\n"),r);    
   264         test(EFalse);
   289         test(EFalse);
   265         }
   290         }
   266     TFullName n;
   291     TFullName n;
   267     r=TheFs.FileSystemName(n,aDrive);
   292     r=TheFs.FileSystemName(n,aDrive);
   268     test_Value(r, r == KErrNone || r==KErrNotFound);
   293     test_Value(r, r == KErrNone || r==KErrNotFound);
   287     test_KErrNone(r);
   312     test_KErrNone(r);
   288     }
   313     }
   289 
   314 
   290 static void TestDismountFileSystem(TInt aDrive)
   315 static void TestDismountFileSystem(TInt aDrive)
   291     {
   316     {
   292 
   317     test.Next(_L("TestDismountFileSystem()\n"));
   293     TInt r;
   318     TInt r;
   294     TFullName name;
   319     TFullName name;
   295     r=TheFs.FileSystemName(name,aDrive);
   320     r=TheFs.FileSystemName(name,aDrive);
   296     test_Value(r, r == KErrNone || r==KErrNotFound);
   321     test_Value(r, r == KErrNone || r==KErrNotFound);
   297     if(name.Length())
   322     if(name.Length())
   298         CheckDismount(name,aDrive);
   323         CheckDismount(name,aDrive);
   299     }
   324     }
   300 
   325 
   301 #if defined(__EPOC32__)
   326 //---------------------------------------------------
   302 static void TestFileSystem(TInt aDrive)
       
   303 //
   327 //
   304 // Mount a new CTestFileSystem on the drive under test
   328 // Mount a new CTestFileSystem on the drive under test
   305 //
   329 //
   306     {
   330 static void TestFileSystem(TInt aDrive)
       
   331     {
       
   332     test.Next(_L("TestFileSystem()\n"));
       
   333 
       
   334     if(Is_SimulatedSystemDrive(TheFs, aDrive))
       
   335         {
       
   336         test.Printf(_L("Can't test on a simulated drive, skipping!\n"));
       
   337         return;
       
   338         }
       
   339 
   307     TBuf<64> b;
   340     TBuf<64> b;
   308     TChar c;
   341     TChar c;
   309     TInt r=TheFs.DriveToChar(aDrive,c);
   342     TInt r=TheFs.DriveToChar(aDrive,c);
   310     test_KErrNone(r);
   343     test_KErrNone(r);
   311     TDriveInfo di;
   344     TDriveInfo di;
   312     r=TheFs.Drive(di,aDrive);
   345     r=TheFs.Drive(di,aDrive);
   313     test_KErrNone(r);
   346     test_KErrNone(r);
   314     b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   347     b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)\n"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   315     test.Next(b);
   348     test.Next(b);
   316 
   349 
   317     test.Next(_L("Test mounting of test file system"));
   350     test.Next(_L("Test mounting of test file system\n"));
   318     r=TheFs.AddFileSystem(_L("T_TFSYS"));
   351     r=TheFs.AddFileSystem(KTestFsy);
   319     if(r!=KErrNone && r!=KErrAlreadyExists)
   352     if(r!=KErrNone && r!=KErrAlreadyExists)
   320         {
   353         {
   321         test.Printf(_L("error=%d"),r);
   354         test.Printf(_L("error=%d\n"),r);
   322         test(EFalse);
   355         test(EFalse);
   323         }
   356         }
   324 
   357 
   325     TFullName oldFs;
   358     TFullName oldFs;
   326     r=TheFs.FileSystemName(oldFs,aDrive);
   359     r=TheFs.FileSystemName(oldFs,aDrive);
   328 //  r=TheFs.FileSystemName(oldFs,aDrive);
   361 //  r=TheFs.FileSystemName(oldFs,aDrive);
   329     test_KErrNone(r);
   362     test_KErrNone(r);
   330     r=TheFs.DismountFileSystem(oldFs,aDrive);
   363     r=TheFs.DismountFileSystem(oldFs,aDrive);
   331     if(r!=KErrNone)
   364     if(r!=KErrNone)
   332         {
   365         {
   333         test.Printf(_L("Error = %d"),r);    
   366         test.Printf(_L("Error = %d\n"),r);    
   334         test(EFalse);
   367         test(EFalse);
   335         }
   368         }
   336     r=TheFs.MountFileSystem(_L("Test"),aDrive);
   369     r=TheFs.MountFileSystem(KTestFsName,aDrive);
   337     test_KErrNone(r);
   370     test_KErrNone(r);
   338 
   371 
   339     TFileName newFs;
   372     TFileName newFs;
   340     r=TheFs.FileSystemName(newFs,aDrive);
   373     r=TheFs.FileSystemName(newFs,aDrive);
   341     test_KErrNone(r);
   374     test_KErrNone(r);
   342     test(newFs.Compare(_L("Test"))==0);
   375     test(newFs.Compare(KTestFsName)==0);
   343 
   376 
   344     // Check attributes
   377     // Check attributes
   345     TDriveInfo info;
   378     TDriveInfo info;
   346     r=TheFs.Drive(info,aDrive);
   379     r=TheFs.Drive(info,aDrive);
   347     test_KErrNone(r);
   380     test_KErrNone(r);
   348  
   381  
   349     test.Printf(_L("iType=%d,iConnectionBusType=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   382     test.Printf(_L("iType=%d,iConnectionBusType=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType, (TUint)info.iConnectionBusType,info.iDriveAtt,info.iMediaAtt);
   350         (TUint)info.iConnectionBusType,info.iDriveAtt,info.iMediaAtt);
       
   351 
   383 
   352     //Try to remove filesystem without dismounting.
   384     //Try to remove filesystem without dismounting.
   353     r=TheFs.RemoveFileSystem(_L("Test"));
   385     r=TheFs.RemoveFileSystem(KTestFsName);
   354     if(r!=KErrInUse)
   386     if(r!=KErrInUse)
   355         {
   387         {
   356         test.Printf(_L("error=%d"),r);
   388         test.Printf(_L("error=%d\n"),r);
   357         test(EFalse);
   389         test(EFalse);
   358         }
   390         }
   359     r=TheFs.FileSystemName(newFs,aDrive);
   391     r=TheFs.FileSystemName(newFs,aDrive);
   360     test_KErrNone(r);
   392     test_KErrNone(r);
   361     test(newFs.Compare(_L("Test"))==0);
   393     test(newFs.Compare(KTestFsName)==0);
   362 
   394 
   363     r=TheFs.DismountFileSystem(newFs,aDrive);
   395     r=TheFs.DismountFileSystem(newFs,aDrive);
   364     test_KErrNone(r);
   396     test_KErrNone(r);
   365 
   397 
   366     r=TheFs.MountFileSystem(oldFs,aDrive);
   398     r=TheFs.MountFileSystem(oldFs,aDrive);
   367     test_KErrNone(r);
   399     test_KErrNone(r);
   368     }
   400     }
   369 #endif
   401 
   370 
   402 //---------------------------------------------------
   371 static void TestMountInvalidDrive()
   403 static void TestMountInvalidDrive()
   372 //
   404     {
   373 // Attempt to mount FAT on non-local drive
   405     test.Next(_L("TestMountInvalidDrive(). Try mounting FS on an invalid drive\n"));
   374     {
   406 
   375     test.Start(_L("TestMountInvalidDrive"));
   407     //-- 1. find an invalid drive
   376 
   408     TInt drv = 0;
   377     TInt r;
   409     TDriveList drvList;
   378 
   410     
   379     test.Next(_L("Adding EFAT"));
   411     TInt nRes = TheFs.DriveList(drvList);
   380 #ifdef __WINS__
   412     test_KErrNone(nRes);
   381     _LIT(KFsNm, "EFAT32");
   413 
   382 #else
   414     for(drv =0; drv<KMaxDrives; ++drv)
   383     _LIT(KFsNm, "ELOCAL");
   415         {
   384 #endif
   416         if(!drvList[drv])
   385 
   417             break;
   386     r = TheFs.AddFileSystem(KFsNm);
   418         }
   387     test.Printf(_L("afs: r = %d\n"), r);
   419 
   388     test_Value(r, r == KErrNone || r == KErrAlreadyExists);
   420     test.Printf(_L("Try mounting a test FS onto drive:%C:\n"), 'A'+drv);
   389     test.Next(_L("mounting FAT on drive R"));
   421 
   390     r = TheFs.MountFileSystem(KFileSystemName_FAT, EDriveR);
   422     nRes = TheFs.AddFileSystem(KTestFsy);
   391     test_Value(r, r == KErrArgument);
   423     test_Value(nRes, nRes == KErrNone || nRes == KErrAlreadyExists);
   392     
   424 
   393     test.End();
   425     nRes = TheFs.MountFileSystem(KTestFsName, drv);
       
   426     test_Value(nRes, nRes == KErrArgument);
       
   427     
   394     }
   428     }
   395 
   429 
   396 // Additional step for INC083446: Corrupted miniSD not detected as corrupted by phone 
   430 // Additional step for INC083446: Corrupted miniSD not detected as corrupted by phone 
   397 static void TestMountingBrokenMedia(TInt aDrive)
   431 static void TestMountingBrokenMedia(TInt aDrive)
   398 //
   432 //
   407     TInt r=TheFs.DriveToChar(aDrive,c);
   441     TInt r=TheFs.DriveToChar(aDrive,c);
   408     test_KErrNone(r);
   442     test_KErrNone(r);
   409     TDriveInfo di;
   443     TDriveInfo di;
   410     r=TheFs.Drive(di,aDrive);
   444     r=TheFs.Drive(di,aDrive);
   411     test_KErrNone(r);
   445     test_KErrNone(r);
   412     b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   446     b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)\n"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   413     test.Next(b);
   447     test.Next(b);
   414 
   448 
   415     test.Next(_L("Test mounting of test file system"));
   449     test.Next(_L("Test mounting of test file system\n"));
   416     r=TheFs.AddFileSystem(_L("T_TFSYS2"));
   450     r=TheFs.AddFileSystem(KTestFsy2);
   417     if(r!=KErrNone && r!=KErrAlreadyExists)
   451     if(r!=KErrNone && r!=KErrAlreadyExists)
   418         {
   452         {
   419         test.Printf(_L("error=%d"),r);
   453         test.Printf(_L("error=%d\n"),r);
   420         test(EFalse);
   454         test(EFalse);
   421         }
   455         }
   422 
   456 
   423     TFullName oldFs;
   457     TFullName oldFs;
   424     r=TheFs.FileSystemName(oldFs,aDrive);
   458     r=TheFs.FileSystemName(oldFs,aDrive);
   425     test_KErrNone(r);
   459     test_KErrNone(r);
   426     r=TheFs.DismountFileSystem(oldFs,aDrive);
   460     r=TheFs.DismountFileSystem(oldFs,aDrive);
   427     if(r!=KErrNone)
   461     if(r!=KErrNone)
   428         {
   462         {
   429         test.Printf(_L("Error = %d"),r);    
   463         test.Printf(_L("Error = %d\n"),r);    
   430         test(EFalse);
   464         test(EFalse);
   431         }
   465         }
   432     r=TheFs.MountFileSystem(_L("Test2"),aDrive);
   466     r=TheFs.MountFileSystem(KTestFsName2 ,aDrive);
   433     test_Value(r, r == KErrCorrupt);
   467     test_Value(r, r == KErrCorrupt);
   434 
   468 
   435     TFileName newFs;
   469     TFileName newFs;
   436     r=TheFs.FileSystemName(newFs,aDrive);
   470     r=TheFs.FileSystemName(newFs,aDrive);
   437     test_KErrNone(r);
   471     test_KErrNone(r);
   438     test(newFs.Compare(_L("Test2"))==0);
   472     test(newFs.Compare(KTestFsName2)==0);
   439 
   473 
   440     // Get the number of remounts by checking the volume attributes -
   474     // Get the number of remounts by checking the volume attributes -
   441     // T_TFSYS2 hijacks the iBattery member to report back the number of times MountL() has been called
   475     // T_TFSYS2 hijacks the iBattery member to report back the number of times MountL() has been called
   442     TDriveInfo info;
   476     TDriveInfo info;
   443     TInt remounts;
   477     TInt remounts;
   444     r=TheFs.Drive(info,aDrive);
   478     r=TheFs.Drive(info,aDrive);
   445     test_KErrNone(r);
   479     test_KErrNone(r);
   446     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   480     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   447         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   481         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   448     remounts = (TInt) info.iBattery;
   482     remounts = (TInt) info.iBattery;
   449     test.Printf(_L("Initial remounts = %d"), remounts);
   483     test.Printf(_L("Initial remounts = %d\n"), remounts);
   450 
   484 
   451     // Make the file server attempt to remount the drive by looking for a non-existant DLL
   485     // Make the file server attempt to remount the drive by looking for a non-existant DLL
   452     // The file server should setop trying to remount the driver after KMaxMountFailures attempts
   486     // The file server should setop trying to remount the driver after KMaxMountFailures attempts
   453     const TInt KMaxMountFailures = 3;   // copied from sf_drv.cpp
   487     const TInt KMaxMountFailures = 3;   // copied from sf_drv.cpp
   454     const TInt KEntryAttempts = 10;
   488     const TInt KEntryAttempts = 10;
   463     r=TheFs.Drive(info,aDrive);
   497     r=TheFs.Drive(info,aDrive);
   464     test_KErrNone(r);
   498     test_KErrNone(r);
   465     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   499     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   466         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   500         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   467     remounts = (TInt) info.iBattery;
   501     remounts = (TInt) info.iBattery;
   468     test.Printf(_L("Remounts = %d"), remounts);
   502     test.Printf(_L("Remounts = %d\n"), remounts);
   469     test(remounts ==  KMaxMountFailures);
   503     test(remounts ==  KMaxMountFailures);
   470     
   504     
   471     // simulate a media change to reset failure count
   505     // simulate a media change to reset failure count
   472     r = TheFs.RemountDrive(aDrive, NULL, 0);
   506     r = TheFs.RemountDrive(aDrive, NULL, 0);
   473 
   507 
   482     r=TheFs.Drive(info,aDrive);
   516     r=TheFs.Drive(info,aDrive);
   483     test_KErrNone(r);
   517     test_KErrNone(r);
   484     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   518     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   485         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   519         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   486     remounts = (TInt) info.iBattery;
   520     remounts = (TInt) info.iBattery;
   487     test.Printf(_L("Remounts = %d"), remounts);
   521     test.Printf(_L("Remounts = %d\n"), remounts);
   488     test(remounts ==  KMaxMountFailures * 2);
   522     test(remounts ==  KMaxMountFailures * 2);
   489     
   523     
   490 
   524 
   491 
   525 
   492     r=TheFs.DismountFileSystem(newFs,aDrive);
   526     r=TheFs.DismountFileSystem(newFs,aDrive);
   493     test_KErrNone(r);
   527     test_KErrNone(r);
   494     r=TheFs.MountFileSystem(oldFs,aDrive);
   528     r=TheFs.MountFileSystem(oldFs,aDrive);
   495     test_KErrNone(r);
   529     test_KErrNone(r);
   496     
   530     
   497     r=TheFs.RemoveFileSystem(_L("Test2"));
   531     r=TheFs.RemoveFileSystem(KTestFsName2);
   498     if(r!=KErrNone)
   532     if(r!=KErrNone)
   499         {
   533         {
   500         test.Printf(_L("error=%d"),r);
   534         test.Printf(_L("error=%d\n"),r);
   501         test(EFalse);
   535         test(EFalse);
   502         }
   536         }
   503     }
   537     }
   504 
   538 
   505 
   539 
   506 /**
   540 /**
   507     Testing obtaining media serial number for the substituted drives
   541     Testing obtaining media serial number for the substituted drives
   508 */
   542 */
   509 static void TestSubstDriveMediaSerialNumber()
   543 static void TestSubstDriveMediaSerialNumber()
   510 {
   544 {
   511     test.Next(_L("Test obtaining media serial number for the substituted drives"));
   545     test.Next(_L("Test obtaining media serial number for the substituted drives\n"));
   512 
   546 
   513     TInt  nRes;
   547     TInt  nRes;
   514     const TInt currDrvNum=CurrentDrive();
   548     const TInt currDrvNum=CurrentDrive();
   515     
   549     
   516     TDriveInfo drvInfo;
   550     TDriveInfo drvInfo;
   585 //! @SYMTestPriority        High
   619 //! @SYMTestPriority        High
   586 //! @SYMTestStatus          Implemented
   620 //! @SYMTestStatus          Implemented
   587 //----------------------------------------------------------------------------------------------
   621 //----------------------------------------------------------------------------------------------
   588 static void TestFileSystemSubTypeQuery()
   622 static void TestFileSystemSubTypeQuery()
   589     {
   623     {
   590     test.Next(_L("Test querying sub type of the mounted file system"));
   624     test.Next(_L("Test querying sub type of the mounted file system\n"));
   591     TFSName fsName;
   625     TFSName fsName;
   592     TPckgBuf<TFSName> subName;
   626     TPckgBuf<TFSName> subName;
   593     TInt i, r;
   627     TInt i, r;
   594     TDriveInfo driveInfo;
   628     TDriveInfo driveInfo;
   595     TPckgBuf<TBool> fDrvSyncBuf;
   629     TPckgBuf<TBool> fDrvSyncBuf;
   688 //! @SYMTestPriority        High
   722 //! @SYMTestPriority        High
   689 //! @SYMTestStatus          Implemented
   723 //! @SYMTestStatus          Implemented
   690 //----------------------------------------------------------------------------------------------
   724 //----------------------------------------------------------------------------------------------
   691 static void TestFileSystemClusterSizeQuery()
   725 static void TestFileSystemClusterSizeQuery()
   692     {
   726     {
   693     test.Next(_L("Test querying cluster size information of the mounted file system"));
   727     test.Next(_L("Test querying cluster size information of the mounted file system\n"));
   694     TFullName fsName;
   728     TFullName fsName;
   695     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   729     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   696     TInt i, r;
   730     TInt i, r;
   697     TDriveInfo driveInfo;
   731     TDriveInfo driveInfo;
   698     for(i = EDriveA; i <= EDriveZ; ++i)
   732     for(i = EDriveA; i <= EDriveZ; ++i)
   793 //! @SYMTestPriority        High
   827 //! @SYMTestPriority        High
   794 //! @SYMTestStatus          Implemented
   828 //! @SYMTestStatus          Implemented
   795 //----------------------------------------------------------------------------------------------
   829 //----------------------------------------------------------------------------------------------
   796 static void TestMediaBlockSizeQuery()
   830 static void TestMediaBlockSizeQuery()
   797     {
   831     {
   798     test.Next(_L("Test querying block size information of the underlying media"));
   832     test.Next(_L("Test querying block size information of the underlying media\n"));
   799     #if defined(__WINS__)
   833     #if defined(__WINS__)
   800         test.Printf(_L("This test case runs on hardware only"));
   834         test.Printf(_L("This test case runs on hardware only\n"));
   801         return;
   835         return;
   802     
       
   803     #else   // test runs on hardware only.
   836     #else   // test runs on hardware only.
       
   837  
   804     TFSName fsName;
   838     TFSName fsName;
   805     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   839     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   806     TInt i, r;
   840     TInt i, r;
   807     TDriveInfo driveInfo;
   841     TDriveInfo driveInfo;
   808     for(i = EDriveA; i <= EDriveZ; ++i)
   842     for(i = EDriveA; i <= EDriveZ; ++i)
   912 //! @SYMTestPriority        High
   946 //! @SYMTestPriority        High
   913 //! @SYMTestStatus          Implemented
   947 //! @SYMTestStatus          Implemented
   914 //----------------------------------------------------------------------------------------------
   948 //----------------------------------------------------------------------------------------------
   915 static void TestFileSystemSubType()
   949 static void TestFileSystemSubType()
   916     {
   950     {
   917     test.Next(_L("Test wrapper API RFs::FileSystemSubType()'s behaviour"));
   951     test.Next(_L("Test wrapper API RFs::FileSystemSubType()'s behaviour\n"));
   918     TFSName fsName;
   952     TFSName fsName;
   919     TPckgBuf<TFSName> subName;
   953     TPckgBuf<TFSName> subName;
   920     TInt r;
   954     TInt r;
   921     TFSName subName1;
   955     TFSName subName1;
   922     TInt r1;
   956     TInt r1;
   954 //! @SYMTestPriority        High
   988 //! @SYMTestPriority        High
   955 //! @SYMTestStatus          Implemented
   989 //! @SYMTestStatus          Implemented
   956 //----------------------------------------------------------------------------------------------
   990 //----------------------------------------------------------------------------------------------
   957 static void TestVolumeIOParam()
   991 static void TestVolumeIOParam()
   958     {
   992     {
   959     test.Next(_L("Test wrapper API RFs::VolumeIOParam()'s behaviour"));
   993     test.Next(_L("Test wrapper API RFs::VolumeIOParam()'s behaviour\n"));
   960     TFSName fsName;
   994     TFSName fsName;
   961     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   995     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   962     TInt r;
   996     TInt r;
   963     TVolumeIOParamInfo ioInfo1;
   997     TVolumeIOParamInfo ioInfo1;
   964     TInt r1;
   998     TInt r1;
  1003     TInt r;
  1037     TInt r;
  1004 
  1038 
  1005     test.Printf(_L("Tested on drive: %c.\n"), (char)(aDrive+'A'));
  1039     test.Printf(_L("Tested on drive: %c.\n"), (char)(aDrive+'A'));
  1006 
  1040 
  1007     // Mount a new CTestFileSystem on the drive under test
  1041     // Mount a new CTestFileSystem on the drive under test
  1008     test.Next(_L("Test RFs::QueryVolumeInfoExt() on Testing File System"));
  1042     test.Next(_L("Test RFs::QueryVolumeInfoExt() on Testing File System\n"));
  1009     r = TheFs.AddFileSystem(_L("T_TFSYS3"));
  1043     r = TheFs.AddFileSystem(KTestFsy3);
  1010     if (r != KErrNone && r != KErrAlreadyExists)
  1044     if (r != KErrNone && r != KErrAlreadyExists)
  1011         {
  1045         {
  1012         test.Printf(_L("error=%d"),r);
  1046         test.Printf(_L("error=%d\n"),r);
  1013         test(EFalse);
  1047         test(EFalse);
  1014         }
  1048         }
  1015     TFSName oldFs;
  1049     TFSName oldFs;
  1016     r = TheFs.FileSystemName(oldFs,aDrive);
  1050     r = TheFs.FileSystemName(oldFs,aDrive);
  1017     test_KErrNone(r);
  1051     test_KErrNone(r);
  1018     r = TheFs.DismountFileSystem(oldFs,aDrive);
  1052     r = TheFs.DismountFileSystem(oldFs,aDrive);
  1019     if (r != KErrNone)
  1053     if (r != KErrNone)
  1020         {
  1054         {
  1021         test.Printf(_L("Error = %d"),r);    
  1055         test.Printf(_L("Error = %d\n"),r);    
  1022         test(EFalse);
  1056         test(EFalse);
  1023         }
  1057         }
  1024     r = TheFs.MountFileSystem(_L("Test3"),aDrive);
  1058     r = TheFs.MountFileSystem(KTestFsName3, aDrive);
  1025     test_KErrNone(r);
  1059     test_KErrNone(r);
  1026     TFSName newFs;
  1060     TFSName newFs;
  1027     r = TheFs.FileSystemName(newFs,aDrive);
  1061     r = TheFs.FileSystemName(newFs,aDrive);
  1028     test_KErrNone(r);
  1062     test_KErrNone(r);
  1029     test(newFs.Compare(_L("Test3"))==0);
  1063     test(newFs.Compare(KTestFsName3)==0);
  1030 
  1064 
  1031     // Sub type name query: 
  1065     // Sub type name query: 
  1032     TPckgBuf<TFSName> subNameP;
  1066     TPckgBuf<TFSName> subNameP;
  1033     r = TheFs.QueryVolumeInfoExt(aDrive, EFileSystemSubType, subNameP);
  1067     r = TheFs.QueryVolumeInfoExt(aDrive, EFileSystemSubType, subNameP);
  1034     test_KErrNone(r);
  1068     test_KErrNone(r);
  1044     r=TheFs.DismountFileSystem(newFs,aDrive);
  1078     r=TheFs.DismountFileSystem(newFs,aDrive);
  1045     test_KErrNone(r);
  1079     test_KErrNone(r);
  1046     r=TheFs.MountFileSystem(oldFs,aDrive);
  1080     r=TheFs.MountFileSystem(oldFs,aDrive);
  1047     test_KErrNone(r);
  1081     test_KErrNone(r);
  1048     
  1082     
  1049     r=TheFs.RemoveFileSystem(_L("Test3"));
  1083     r=TheFs.RemoveFileSystem(KTestFsName3);
  1050     if(r!=KErrNone)
  1084     if(r!=KErrNone)
  1051         {
  1085         {
  1052         test.Printf(_L("error=%d"),r);
  1086         test.Printf(_L("error=%d\n"),r);
  1053         test(EFalse);
  1087         test(EFalse);
  1054         }
  1088         }
  1055     }
  1089     }
  1056 
  1090 
  1057 
  1091 
  1066 */
  1100 */
  1067 static void TestRemountFSWithOpenedObjects()
  1101 static void TestRemountFSWithOpenedObjects()
  1068 {
  1102 {
  1069     test.Next(_L("Testing forcedly remounting FS with objects opened.\n"));
  1103     test.Next(_L("Testing forcedly remounting FS with objects opened.\n"));
  1070     
  1104     
       
  1105     //-- don't perform this test on a non-removable drive, generating media change on such drive
       
  1106     //-- doesn't always work
  1071     TInt nRes;
  1107     TInt nRes;
       
  1108     const TInt drvNumber = CurrentDrive();
       
  1109     TDriveInfo driveInfo;
       
  1110 
       
  1111     nRes = TheFs.Drive(driveInfo, drvNumber);
       
  1112     test_KErrNone(nRes);
       
  1113 
       
  1114     if(! (driveInfo.iDriveAtt & KDriveAttRemovable))
       
  1115     {
       
  1116         test.Printf(_L("Can't perform this test on a non-removable drive. Skippping!\n"));
       
  1117         return;
       
  1118     }
       
  1119 
  1072     
  1120     
  1073     //-- 1. create a file
  1121     //-- 1. create a file
  1074     _LIT(KFile, "\\test_file.file");
  1122     _LIT(KFile, "\\test_file.file");
  1075     const TUint KFileSz = 5000;
  1123     const TUint KFileSz = 5000;
  1076     
  1124     
  1081 
  1129 
  1082     //-- 2. open this file
  1130     //-- 2. open this file
  1083     nRes = file.Open(TheFs, KFile, EFileRead);
  1131     nRes = file.Open(TheFs, KFile, EFileRead);
  1084     test_KErrNone(nRes);
  1132     test_KErrNone(nRes);
  1085     
  1133     
  1086     const TInt drvNumber = CurrentDrive();
  1134     
  1087 
  1135 
  1088     //-- 2.1 try to dismount the FS, it must fail because of the opened object.
  1136     //-- 2.1 try to dismount the FS, it must fail because of the opened object.
  1089     TBuf<40> fsName;
  1137     TBuf<40> fsName;
  1090     nRes = TheFs.FileSystemName(fsName, drvNumber);
  1138     nRes = TheFs.FileSystemName(fsName, drvNumber);
  1091     test_KErrNone(nRes);
  1139     test_KErrNone(nRes);
  1095 
  1143 
  1096     // Flag from locmedia.h to simulate ejecting and re-inserting the media.
  1144     // Flag from locmedia.h to simulate ejecting and re-inserting the media.
  1097     const TUint KMediaRemountForceMediaChange = 0x00000001;
  1145     const TUint KMediaRemountForceMediaChange = 0x00000001;
  1098     TRequestStatus changeStatus;
  1146     TRequestStatus changeStatus;
  1099     TheFs.NotifyChange(ENotifyAll, changeStatus);
  1147     TheFs.NotifyChange(ENotifyAll, changeStatus);
  1100     TDriveInfo driveInfo;
  1148     
  1101     
  1149     
  1102     //-- 3. forcedly remount the drive
  1150     //-- 3. forcedly remount the drive
  1103     nRes = TheFs.RemountDrive(drvNumber, NULL, KMediaRemountForceMediaChange);
  1151     nRes = TheFs.RemountDrive(drvNumber, NULL, KMediaRemountForceMediaChange);
  1104     
  1152     
  1105     if(nRes == KErrNotSupported)
  1153     if(nRes == KErrNotSupported)
  1106     	{//-- this feature is not supported and the test is inconsistent.
  1154     	{//-- this feature is not supported and the test is inconsistent.
  1107         test.Printf(_L("RemountDrive() is not supported, the test is inconsistent!"));
  1155         test.Printf(_L("RemountDrive() is not supported, the test is inconsistent!\n"));
  1108         
  1156         
  1109         //-- remounting must work at least on MMC drives
  1157         //-- remounting must work at least on MMC drives
  1110         const TBool isFAT = Is_Fat(TheFs, drvNumber);
  1158         const TBool isFAT = Is_Fat(TheFs, drvNumber);
  1111 
  1159 
  1112         nRes = TheFs.Drive(driveInfo, drvNumber);
  1160         nRes = TheFs.Drive(driveInfo, drvNumber);
  1115         test_Value(driveInfo.iDriveAtt, !isFAT || (!(driveInfo.iDriveAtt & KDriveAttRemovable)));
  1163         test_Value(driveInfo.iDriveAtt, !isFAT || (!(driveInfo.iDriveAtt & KDriveAttRemovable)));
  1116     	}
  1164     	}
  1117     else
  1165     else
  1118     	{
  1166     	{
  1119 		test_Value(nRes, nRes == KErrNotReady || nRes == KErrNone);
  1167 		test_Value(nRes, nRes == KErrNotReady || nRes == KErrNone);
       
  1168 		test.Printf(_L("Waiting for the simulated media change...\n"));
  1120 		
  1169 		
  1121 		//-- 3.1 wait for media change to complete
  1170 		//-- 3.1 wait for media change to complete
  1122 		do
  1171 		do
  1123 			{
  1172 			{
  1124 			// Waiting for media change...
  1173 			// Waiting for media change...
  1150 
  1199 
  1151 }
  1200 }
  1152 //----------------------------------------------------------------------------------------------
  1201 //----------------------------------------------------------------------------------------------
  1153 static void TestFileSystem_MaxSupportedFileSizeQuery()
  1202 static void TestFileSystem_MaxSupportedFileSizeQuery()
  1154 {
  1203 {
  1155     test.Next(_L("Test querying max. supported file size on this file system"));
  1204     test.Next(_L("Test querying max. supported file size on this file system\n"));
  1156     TFullName fsName;
  1205     TFullName fsName;
  1157     TPckgBuf<TVolumeIOParamInfo> ioInfo;
  1206     TPckgBuf<TVolumeIOParamInfo> ioInfo;
  1158     TVolumeIOParamInfo& volInfo = ioInfo();
  1207     TVolumeIOParamInfo& volInfo = ioInfo();
  1159 
  1208 
  1160     const TInt drvNo=CurrentDrive();
  1209     const TInt drvNo=CurrentDrive();
  1181     }
  1230     }
  1182 
  1231 
  1183 }
  1232 }
  1184 
  1233 
  1185 //----------------------------------------------------------------------------------------------
  1234 //----------------------------------------------------------------------------------------------
  1186 GLDEF_C void CallTestsL()
  1235 void CallTestsL()
  1187 //
       
  1188 // Do all tests
       
  1189 //
       
  1190     {
  1236     {
  1191 
  1237 
  1192     //-- set up console output 
  1238     //-- set up console output 
  1193     Fat_Test_Utils::SetConsole(test.Console()); 
  1239     Fat_Test_Utils::SetConsole(test.Console()); 
  1194 
  1240 
  1195     TInt drive=CurrentDrive();
  1241     const TInt drive=CurrentDrive();
  1196 
       
  1197     PrintDrvInfo(TheFs, drive);
  1242     PrintDrvInfo(TheFs, drive);
  1198 
  1243 
  1199     //Do not run this test on the NAND drive, as
  1244     //Do not run this test on the NAND drive, as this has the FTL mounted as a primary extension
  1200     //this has the FTL mounted as a primary extension
       
  1201     //which causes the test to fail
  1245     //which causes the test to fail
  1202     #if defined(__WINS__)
  1246     
  1203         if (drive==EDriveU)
  1247     TFSName pExtName;
  1204             return;
  1248     pExtName.Zero();
  1205     #else
  1249    
  1206         TDriveInfo driveInfo;
  1250     TInt nRes = TheFs.ExtensionName(pExtName, drive, 0);
  1207         TheFs.Drive(driveInfo,drive);
  1251    
  1208         if (driveInfo.iType == EMediaNANDFlash)
  1252     if(nRes == KErrNone && pExtName.Length())
  1209             {
  1253         {
  1210             return;
  1254         test.Printf(_L("This test can't be run on a drive that has a primary extension:%S\n"), &pExtName);   
  1211             }
  1255         return;
  1212     #endif
  1256         }
  1213 
  1257 
  1214     //---------------------------------------
  1258     //---------------------------------------
  1215 
  1259 
  1216     InitGlobals();
  1260     InitGlobals();
  1217     
  1261     
  1218     //---------------------------------------
  1262     //---------------------------------------
  1219     TestFileSystemNames();
  1263     TestFileSystemNames();
  1220     TestFileSystemNameLength();
  1264     TestFileSystemNameLength();
  1221     TestDismountFileSystem(CurrentDrive());
  1265     TestDismountFileSystem(CurrentDrive());
  1222 #if defined(__EPOC32__)
       
  1223     TestFileSystem(CurrentDrive());
  1266     TestFileSystem(CurrentDrive());
  1224 #endif
       
  1225 
       
  1226     TestMountInvalidDrive();
  1267     TestMountInvalidDrive();
  1227     
       
  1228     TestMountingBrokenMedia(CurrentDrive());
  1268     TestMountingBrokenMedia(CurrentDrive());
  1229     TestSubstDriveMediaSerialNumber();
  1269     TestSubstDriveMediaSerialNumber();
  1230 
  1270 
  1231     TestFileSystemSubTypeQuery();
  1271     TestFileSystemSubTypeQuery();
  1232     TestFileSystemClusterSizeQuery();
  1272     TestFileSystemClusterSizeQuery();
  1233     TestMediaBlockSizeQuery();
  1273     TestMediaBlockSizeQuery();
  1234     TestFileSystemSubType();
  1274     TestFileSystemSubType();
  1235     TestVolumeIOParam();
  1275     TestVolumeIOParam();
  1236     TestQueryVolumeInfoExtOnTestFS(CurrentDrive());
  1276     TestQueryVolumeInfoExtOnTestFS(CurrentDrive());
  1237 
       
  1238     TestFileSystem_MaxSupportedFileSizeQuery();
  1277     TestFileSystem_MaxSupportedFileSizeQuery();
  1239 
       
  1240     TestRemountFSWithOpenedObjects();
  1278     TestRemountFSWithOpenedObjects();
  1241 
  1279 
  1242     //---------------------------------------
  1280     //---------------------------------------
  1243     DestroyGlobals();    
  1281     DestroyGlobals();    
  1244     }
  1282     }