kerneltest/f32test/server/t_fsys.cpp
branchRCL_3
changeset 294 039a3e647356
parent 268 345b1ca54e88
equal deleted inserted replaced
268:345b1ca54e88 294:039a3e647356
    18 #define __E32TEST_EXTENSION__
    18 #define __E32TEST_EXTENSION__
    19 
    19 
    20 #include <f32file.h>
    20 #include <f32file.h>
    21 #include <f32file_private.h>
    21 #include <f32file_private.h>
    22 #include <e32test.h>
    22 #include <e32test.h>
    23 #include <e32math.h>
       
    24 #include "t_server.h"
    23 #include "t_server.h"
    25 #include "fat_utils.h"
    24 #include "fat_utils.h"
    26 #include "filesystem_fat.h"
    25 #include "filesystem_fat.h"
    27 
    26 
    28 using namespace Fat_Test_Utils;
    27 using namespace Fat_Test_Utils;
    29 
    28 
    30 RTest test(_L("T_FSYS"));
    29 RTest test(_L("T_FSYS"));
    31 static TInt64   gRndSeed;
    30 
    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 
       
    43 //---------------------------------------------------
       
    44 
       
    45 
       
    46 void InitGlobals()
       
    47 {
       
    48     //-- initialise random generator 
       
    49     gRndSeed = 0xf73c1ab;
       
    50     Math::Rand(gRndSeed);
       
    51 }
       
    52 
       
    53 //---------------------------------------------------
       
    54 void DestroyGlobals()
       
    55 {
       
    56 }
       
    57 
       
    58 //---------------------------------------------------
       
    59 static void TestFileSystemNames()
    31 static void TestFileSystemNames()
    60     {
    32     {
    61     test.Next(_L("TestFileSystemNames(). Read file system names for all drives\n"));
    33     test.Next(_L("Read file system names for all drives"));
    62     TFullName name;
    34     TFullName name;
    63     TBuf<60>  buf;
    35     TInt r;
    64     TInt nRes;
    36     for(TInt i=EDriveA;i<KMaxDrives;++i)
    65 
    37         {
    66     TDriveList drvList;
    38         r=TheFs.FileSystemName(name,i);
    67     nRes = TheFs.DriveList(drvList);
    39         test(r==KErrNone || r==KErrNotFound);
    68     test_KErrNone(nRes);
    40         TChar c;
    69 
    41         r=RFs::DriveToChar(i,c);
    70     for(TInt i=0; i<KMaxDrives; ++i)
    42         test(r==KErrNone);
    71         {
    43         if(name.Length())       
    72         buf.Format(_L("drv %C: att:0x%02x"), 'A'+i, drvList[i]);
    44             test.Printf(_L("File System Name on drive %c is %S\n"),(char)c,&name);
    73         
       
    74         nRes = TheFs.FileSystemName(name, i);
       
    75         test_Value(nRes, nRes == KErrNone || nRes==KErrNotFound);
       
    76         
       
    77         if(nRes == KErrNone)
       
    78             {
       
    79             buf.AppendFormat(_L(" Mounted FS:%S"), &name);
       
    80             }
       
    81         else
    45         else
    82             {
    46             test.Printf(_L("No file system on drive %c\n"),(char)c);
    83             buf.Append(_L(" Mounted FS:"));
    47         }
    84             }
    48     }
    85 
    49 
    86         buf.Append(_L("\n"));
       
    87         test.Printf(buf);
       
    88         }
       
    89     
       
    90     }
       
    91 
       
    92 //---------------------------------------------------
       
    93 static void CheckDismount(TDesC& aFs,TInt aDrive)
    50 static void CheckDismount(TDesC& aFs,TInt aDrive)
    94     {
    51     {
    95 
    52 
    96     if (aDrive==EDriveC) // ??? Can't test on C: - see below
    53     if (aDrive==EDriveC) // ??? Can't test on C: - see below
    97         return;
    54         return;
    98     TInt r;
    55     TInt r;
    99     TFullName oldSess, newSess;
    56     TFullName oldSess, newSess;
   100     r=TheFs.SessionPath(oldSess);
    57     r=TheFs.SessionPath(oldSess);
   101     test_KErrNone(r);
    58     test(r==KErrNone);
   102     TChar c;
    59     TChar c;
   103     r=TheFs.DriveToChar(aDrive,c);
    60     r=TheFs.DriveToChar(aDrive,c);
   104     test_KErrNone(r);
    61     test(r==KErrNone);
   105     newSess.Append(c);
    62     newSess.Append(c);
   106     newSess.Append(':');
    63     newSess.Append(':');
   107     newSess.Append('\\');
    64     newSess.Append('\\');
   108 
    65 
   109     TBuf<128> b;
    66     TBuf<128> b;
   110     TDriveInfo di;
    67     TDriveInfo di;
   111     r=TheFs.Drive(di,aDrive);
    68     r=TheFs.Drive(di,aDrive);
   112     test_KErrNone(r);
    69     test(r==KErrNone);
   113     b.Format(_L("Test dismounting of test file system on %c: (DrvAtt:%x MedAtt:%x)\n"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
    70     b.Format(_L("Test dismounting of test file system on %c: (DrvAtt:%x MedAtt:%x)"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   114     test.Next(b);
    71     test.Next(b);
   115     
    72     
   116     // Test cannot dismount on rom drive
    73     // Test cannot dismount on rom drive
   117     test.Next(_L("Test cannot dismount on Rom drive\n"));
    74     test.Next(_L("Test cannot dismount on Rom drive"));
   118     TFullName zName;
    75     TFullName zName;
   119     r=TheFs.FileSystemName(zName,EDriveZ);
    76     r=TheFs.FileSystemName(zName,EDriveZ);
   120     test_KErrNone(r);
    77     test(r==KErrNone);
   121     r=TheFs.DismountFileSystem(zName,EDriveZ);
    78     r=TheFs.DismountFileSystem(zName,EDriveZ);
   122     test.Printf(_L("r=%d\n"),r);
    79     test.Printf(_L("r=%d"),r);
   123     // NB if paging is enabled on a ROFS partition which is part of the composite file system then the 
    80     // NB if paging is enabled on a ROFS partition which is part of the composite file system then the 
   124     // likelihood is that there will be a at least one file clamped: in this case there error will be KErrInUse
    81     // likelihood is that there will be a at least one file clamped: in this case there error will be KErrInUse
   125     test_Value(r, r == KErrAccessDenied || r==KErrInUse);
    82     test(r==KErrAccessDenied || r==KErrInUse);
   126 
    83 
   127     // Test cannot dismount on wrong drive
    84     // Test cannot dismount on wrong drive
   128     test.Next(_L("Test cannot dismount on wrong drive\n"));
    85     test.Next(_L("Test cannot dismount on wrong drive"));
   129     r=TheFs.DismountFileSystem(aFs,EDriveA);
    86     r=TheFs.DismountFileSystem(aFs,EDriveA);
   130     test_Value(r, r == KErrNotReady);
    87     test(r==KErrNotReady);
   131 
    88 
   132     // Test cannot dismount with wrong name
    89     // Test cannot dismount with wrong name
   133     test.Next(_L("Test cannot dismount with wrong file system name\n"));
    90     test.Next(_L("Test cannot dismount with wrong file system name"));
   134     r=TheFs.DismountFileSystem(_L("abc"),aDrive);
    91     r=TheFs.DismountFileSystem(_L("abc"),aDrive);
   135     test_Value(r, r == KErrNotFound);
    92     test(r==KErrNotFound);
   136  
    93  
   137     // Test cannot dismount with a file open
    94     // Test cannot dismount with a file open
   138     test.Next(_L("Test cannot dismount with a file open\n"));
    95     test.Next(_L("Test cannot dismount with a file open"));
   139     r=TheFs.SetSessionPath(newSess);
    96     r=TheFs.SetSessionPath(newSess);
   140     RFile file;
    97     RFile file;
   141     r=file.Replace(TheFs,_L("abc"),EFileShareAny);
    98     r=file.Replace(TheFs,_L("abc"),EFileShareAny);
   142     test_KErrNone(r);
    99     test(r==KErrNone);
   143     r=TheFs.SessionPath(newSess);
   100     r=TheFs.SessionPath(newSess);
   144     TBool open;
   101     TBool open;
   145     r=TheFs.IsFileOpen(_L("abc"),open);
   102     r=TheFs.IsFileOpen(_L("abc"),open);
   146     test_KErrNone(r);
   103     test(r==KErrNone);
   147     test(open);
   104     test(open);
   148     r=TheFs.DismountFileSystem(aFs,aDrive);
   105     r=TheFs.DismountFileSystem(aFs,aDrive);
   149     test_Value(r, r == KErrInUse);
   106     test(r==KErrInUse);
   150     file.Close();
   107     file.Close();
   151 
   108 
   152     // Now test dismount works
   109     // Now test dismount works
   153     test.Next(_L("Test dismounts OK\n"));
   110     test.Next(_L("Test dismounts OK"));
   154     r=TheFs.DismountFileSystem(aFs,aDrive);
   111     r=TheFs.DismountFileSystem(aFs,aDrive);
   155     if(r!=KErrNone)
   112     if(r!=KErrNone)
   156         {
   113         {
   157         test.Printf(_L("Error = %d\n"),r);    
   114         test.Printf(_L("Error = %d"),r);    
   158         test(EFalse);
   115         test(EFalse);
   159         }
   116         }
   160     TFullName n;
   117     TFullName n;
   161     r=TheFs.FileSystemName(n,aDrive);
   118     r=TheFs.FileSystemName(n,aDrive);
   162     test_Value(r, r == KErrNone || r==KErrNotFound);
   119     test(r==KErrNone || r==KErrNotFound);
   163     test(!n.Length());
   120     test(!n.Length());
   164     r=file.Replace(TheFs,_L("abc"),EFileShareAny);
   121     r=file.Replace(TheFs,_L("abc"),EFileShareAny);
   165     test_Value(r, r == KErrNotReady);
   122     test(r==KErrNotReady);
   166     file.Close();
   123     file.Close();
   167 
   124 
   168     r=TheFs.MountFileSystem(aFs,aDrive);
   125     r=TheFs.MountFileSystem(aFs,aDrive);
   169     if(r!=KErrNone) 
   126     if(r!=KErrNone) 
   170         {
   127         {
   171         test.Printf(_L("error = %d\n"),r);
   128         test.Printf(_L("error = %d\n"),r);
   172         test(EFalse);
   129         test(EFalse);
   173         }
   130         }
   174     r=TheFs.FileSystemName(n,aDrive);
   131     r=TheFs.FileSystemName(n,aDrive);
   175     test_KErrNone(r);
   132     test(r==KErrNone);
   176     test(n.Compare(aFs)==0);
   133     test(n.Compare(aFs)==0);
   177     r=file.Replace(TheFs,_L("abc"),EFileShareAny); // ??? bang
   134     r=file.Replace(TheFs,_L("abc"),EFileShareAny); // ??? bang
   178     test_KErrNone(r);
   135     test(r==KErrNone);
   179     file.Close();
   136     file.Close();
   180     r=TheFs.SetSessionPath(oldSess);
   137     r=TheFs.SetSessionPath(oldSess);
   181     test_KErrNone(r);
   138     test(r==KErrNone);
   182     }
   139     }
   183 
   140 
   184 static void TestDismountFileSystem(TInt aDrive)
   141 static void TestDismountFileSystem(TInt aDrive)
   185     {
   142     {
   186     test.Next(_L("TestDismountFileSystem()\n"));
   143 
   187     TInt r;
   144     TInt r;
   188     TFullName name;
   145     TFullName name;
   189     r=TheFs.FileSystemName(name,aDrive);
   146     r=TheFs.FileSystemName(name,aDrive);
   190     test_Value(r, r == KErrNone || r==KErrNotFound);
   147     test(r==KErrNone || r==KErrNotFound);
   191     if(name.Length())
   148     if(name.Length())
   192         CheckDismount(name,aDrive);
   149         CheckDismount(name,aDrive);
   193     }
   150     }
   194 
   151 
   195 //---------------------------------------------------
   152 #if defined(__EPOC32__)
       
   153 static void TestFileSystem(TInt aDrive)
   196 //
   154 //
   197 // Mount a new CTestFileSystem on the drive under test
   155 // Mount a new CTestFileSystem on the drive under test
   198 //
   156 //
   199 static void TestFileSystem(TInt aDrive)
   157     {
   200     {
       
   201     test.Next(_L("TestFileSystem()\n"));
       
   202 
       
   203     if(Is_Win32(TheFs, aDrive))
       
   204         {
       
   205         test.Printf(_L("Can't test on a simulated drive, skipping!\n"));
       
   206         return;
       
   207         }
       
   208 
       
   209     TBuf<64> b;
   158     TBuf<64> b;
   210     TChar c;
   159     TChar c;
   211     TInt r=TheFs.DriveToChar(aDrive,c);
   160     TInt r=TheFs.DriveToChar(aDrive,c);
   212     test_KErrNone(r);
   161     test(r==KErrNone);
   213     TDriveInfo di;
   162     TDriveInfo di;
   214     r=TheFs.Drive(di,aDrive);
   163     r=TheFs.Drive(di,aDrive);
   215     test_KErrNone(r);
   164     test(r==KErrNone);
   216     b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)\n"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   165     b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   217     test.Next(b);
   166     test.Next(b);
   218 
   167 
   219     test.Next(_L("Test mounting of test file system\n"));
   168     test.Next(_L("Test mounting of test file system"));
   220     r=TheFs.AddFileSystem(KTestFsy);
   169     r=TheFs.AddFileSystem(_L("T_TFSYS"));
   221     if(r!=KErrNone && r!=KErrAlreadyExists)
   170     if(r!=KErrNone && r!=KErrAlreadyExists)
   222         {
   171         {
   223         test.Printf(_L("error=%d\n"),r);
   172         test.Printf(_L("error=%d"),r);
   224         test(EFalse);
   173         test(EFalse);
   225         }
   174         }
   226 
   175 
   227     TFullName oldFs;
   176     TFullName oldFs;
   228     r=TheFs.FileSystemName(oldFs,aDrive);
   177     r=TheFs.FileSystemName(oldFs,aDrive);
   229 //  TFileName oldFs;
   178 //  TFileName oldFs;
   230 //  r=TheFs.FileSystemName(oldFs,aDrive);
   179 //  r=TheFs.FileSystemName(oldFs,aDrive);
   231     test_KErrNone(r);
   180     test(r==KErrNone);
   232     r=TheFs.DismountFileSystem(oldFs,aDrive);
   181     r=TheFs.DismountFileSystem(oldFs,aDrive);
   233     if(r!=KErrNone)
   182     if(r!=KErrNone)
   234         {
   183         {
   235         test.Printf(_L("Error = %d\n"),r);    
   184         test.Printf(_L("Error = %d"),r);    
   236         test(EFalse);
   185         test(EFalse);
   237         }
   186         }
   238     r=TheFs.MountFileSystem(KTestFsName,aDrive);
   187     r=TheFs.MountFileSystem(_L("Test"),aDrive);
   239     test_KErrNone(r);
   188     test(r==KErrNone);
   240 
   189 
   241     TFileName newFs;
   190     TFileName newFs;
   242     r=TheFs.FileSystemName(newFs,aDrive);
   191     r=TheFs.FileSystemName(newFs,aDrive);
   243     test_KErrNone(r);
   192     test(r==KErrNone);
   244     test(newFs.Compare(KTestFsName)==0);
   193     test(newFs.Compare(_L("Test"))==0);
   245 
   194 
   246     // Check attributes
   195     // Check attributes
   247     TDriveInfo info;
   196     TDriveInfo info;
   248     r=TheFs.Drive(info,aDrive);
   197     r=TheFs.Drive(info,aDrive);
   249     test_KErrNone(r);
   198     test(r==KErrNone);
   250  
   199  
   251     test.Printf(_L("iType=%d,iConnectionBusType=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType, (TUint)info.iConnectionBusType,info.iDriveAtt,info.iMediaAtt);
   200     test.Printf(_L("iType=%d,iConnectionBusType=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
       
   201         (TUint)info.iConnectionBusType,info.iDriveAtt,info.iMediaAtt);
   252 
   202 
   253     //Try to remove filesystem without dismounting.
   203     //Try to remove filesystem without dismounting.
   254     r=TheFs.RemoveFileSystem(KTestFsName);
   204     r=TheFs.RemoveFileSystem(_L("Test"));
   255     if(r!=KErrInUse)
   205     if(r!=KErrInUse)
   256         {
   206         {
   257         test.Printf(_L("error=%d\n"),r);
   207         test.Printf(_L("error=%d"),r);
   258         test(EFalse);
   208         test(EFalse);
   259         }
   209         }
   260     r=TheFs.FileSystemName(newFs,aDrive);
   210     r=TheFs.FileSystemName(newFs,aDrive);
   261     test_KErrNone(r);
   211     test(r==KErrNone);
   262     test(newFs.Compare(KTestFsName)==0);
   212     test(newFs.Compare(_L("Test"))==0);
   263 
   213 
   264     r=TheFs.DismountFileSystem(newFs,aDrive);
   214     r=TheFs.DismountFileSystem(newFs,aDrive);
   265     test_KErrNone(r);
   215     test(r==KErrNone);
   266 
   216 
   267     r=TheFs.MountFileSystem(oldFs,aDrive);
   217     r=TheFs.MountFileSystem(oldFs,aDrive);
   268     test_KErrNone(r);
   218     test(r==KErrNone);
   269     }
   219     }
   270 
   220 #endif
   271 //---------------------------------------------------
   221 
   272 static void TestMountInvalidDrive()
   222 static void TestMountInvalidDrive()
   273     {
   223 //
   274     test.Next(_L("TestMountInvalidDrive(). Try mounting FS on an invalid drive\n"));
   224 // Attempt to mount FAT on non-local drive
   275 
   225     {
   276     //-- 1. find an invalid drive
   226     test.Start(_L("TestMountInvalidDrive"));
   277     TInt drv = 0;
   227 
   278     TDriveList drvList;
   228     TInt r;
   279     
   229 
   280     TInt nRes = TheFs.DriveList(drvList);
   230     test.Next(_L("Adding EFAT"));
   281     test_KErrNone(nRes);
   231 #ifdef __WINS__
   282 
   232     _LIT(KFsNm, "EFAT32");
   283     for(drv =0; drv<KMaxDrives; ++drv)
   233 #else
   284         {
   234     _LIT(KFsNm, "ELOCAL");
   285         if(!drvList[drv])
   235 #endif
   286             break;
   236 
   287         }
   237     r = TheFs.AddFileSystem(KFsNm);
   288 
   238     test.Printf(_L("afs: r = %d\n"), r);
   289     test.Printf(_L("Try mounting a test FS onto drive:%C:\n"), 'A'+drv);
   239     test(r == KErrNone || r == KErrAlreadyExists);
   290 
   240     test.Next(_L("mounting FAT on drive R"));
   291     nRes = TheFs.AddFileSystem(KTestFsy);
   241     r = TheFs.MountFileSystem(KFileSystemName_FAT, EDriveR);
   292     test_Value(nRes, nRes == KErrNone || nRes == KErrAlreadyExists);
   242     test(r == KErrArgument);
   293 
   243     
   294     nRes = TheFs.MountFileSystem(KTestFsName, drv);
   244     test.End();
   295     test_Value(nRes, nRes == KErrArgument);
       
   296     
       
   297     }
   245     }
   298 
   246 
   299 // Additional step for INC083446: Corrupted miniSD not detected as corrupted by phone 
   247 // Additional step for INC083446: Corrupted miniSD not detected as corrupted by phone 
   300 static void TestMountingBrokenMedia(TInt aDrive)
   248 static void TestMountingBrokenMedia(TInt aDrive)
   301 //
   249 //
   306         return;
   254         return;
   307 
   255 
   308     TBuf<64> b;
   256     TBuf<64> b;
   309     TChar c;
   257     TChar c;
   310     TInt r=TheFs.DriveToChar(aDrive,c);
   258     TInt r=TheFs.DriveToChar(aDrive,c);
   311     test_KErrNone(r);
   259     test(r==KErrNone);
   312     TDriveInfo di;
   260     TDriveInfo di;
   313     r=TheFs.Drive(di,aDrive);
   261     r=TheFs.Drive(di,aDrive);
   314     test_KErrNone(r);
   262     test(r==KErrNone);
   315     b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)\n"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   263     b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
   316     test.Next(b);
   264     test.Next(b);
   317 
   265 
   318     test.Next(_L("Test mounting of test file system\n"));
   266     test.Next(_L("Test mounting of test file system"));
   319     r=TheFs.AddFileSystem(KTestFsy2);
   267     r=TheFs.AddFileSystem(_L("T_TFSYS2"));
   320     if(r!=KErrNone && r!=KErrAlreadyExists)
   268     if(r!=KErrNone && r!=KErrAlreadyExists)
   321         {
   269         {
   322         test.Printf(_L("error=%d\n"),r);
   270         test.Printf(_L("error=%d"),r);
   323         test(EFalse);
   271         test(EFalse);
   324         }
   272         }
   325 
   273 
   326     TFullName oldFs;
   274     TFullName oldFs;
   327     r=TheFs.FileSystemName(oldFs,aDrive);
   275     r=TheFs.FileSystemName(oldFs,aDrive);
   328     test_KErrNone(r);
   276     test(r==KErrNone);
   329     r=TheFs.DismountFileSystem(oldFs,aDrive);
   277     r=TheFs.DismountFileSystem(oldFs,aDrive);
   330     if(r!=KErrNone)
   278     if(r!=KErrNone)
   331         {
   279         {
   332         test.Printf(_L("Error = %d\n"),r);    
   280         test.Printf(_L("Error = %d"),r);    
   333         test(EFalse);
   281         test(EFalse);
   334         }
   282         }
   335     r=TheFs.MountFileSystem(KTestFsName2 ,aDrive);
   283     r=TheFs.MountFileSystem(_L("Test2"),aDrive);
   336     test_Value(r, r == KErrCorrupt);
   284     test(r == KErrCorrupt);
   337 
   285 
   338     TFileName newFs;
   286     TFileName newFs;
   339     r=TheFs.FileSystemName(newFs,aDrive);
   287     r=TheFs.FileSystemName(newFs,aDrive);
   340     test_KErrNone(r);
   288     test(r==KErrNone);
   341     test(newFs.Compare(KTestFsName2)==0);
   289     test(newFs.Compare(_L("Test2"))==0);
   342 
   290 
   343     // Get the number of remounts by checking the volume attributes -
   291     // Get the number of remounts by checking the volume attributes -
   344     // T_TFSYS2 hijacks the iBattery member to report back the number of times MountL() has been called
   292     // T_TFSYS2 hijacks the iBattery member to report back the number of times MountL() has been called
   345     TDriveInfo info;
   293     TDriveInfo info;
   346     TInt remounts;
   294     TInt remounts;
   347     r=TheFs.Drive(info,aDrive);
   295     r=TheFs.Drive(info,aDrive);
   348     test_KErrNone(r);
   296     test(r==KErrNone);
   349     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   297     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   350         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   298         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   351     remounts = (TInt) info.iBattery;
   299     remounts = (TInt) info.iBattery;
   352     test.Printf(_L("Initial remounts = %d\n"), remounts);
   300     test.Printf(_L("Initial remounts = %d"), remounts);
   353 
   301 
   354     // Make the file server attempt to remount the drive by looking for a non-existant DLL
   302     // Make the file server attempt to remount the drive by looking for a non-existant DLL
   355     // The file server should setop trying to remount the driver after KMaxMountFailures attempts
   303     // The file server should setop trying to remount the driver after KMaxMountFailures attempts
   356     const TInt KMaxMountFailures = 3;   // copied from sf_drv.cpp
   304     const TInt KMaxMountFailures = 3;   // copied from sf_drv.cpp
   357     const TInt KEntryAttempts = 10;
   305     const TInt KEntryAttempts = 10;
   359     for (entryAttempts=0; entryAttempts < KEntryAttempts; entryAttempts++)
   307     for (entryAttempts=0; entryAttempts < KEntryAttempts; entryAttempts++)
   360         {
   308         {
   361         TEntry entry;
   309         TEntry entry;
   362         _LIT(KNonExistantFilename, "NONEXISTANT_FILENAME.DLL");
   310         _LIT(KNonExistantFilename, "NONEXISTANT_FILENAME.DLL");
   363         r = TheFs.Entry(KNonExistantFilename, entry);
   311         r = TheFs.Entry(KNonExistantFilename, entry);
   364         test_Value(r, r == KErrCorrupt);
   312         test(r == KErrCorrupt);
   365         }
   313         }
   366     r=TheFs.Drive(info,aDrive);
   314     r=TheFs.Drive(info,aDrive);
   367     test_KErrNone(r);
   315     test(r==KErrNone);
   368     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   316     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   369         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   317         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   370     remounts = (TInt) info.iBattery;
   318     remounts = (TInt) info.iBattery;
   371     test.Printf(_L("Remounts = %d\n"), remounts);
   319     test.Printf(_L("Remounts = %d"), remounts);
   372     test(remounts ==  KMaxMountFailures);
   320     test(remounts ==  KMaxMountFailures);
   373     
   321     
   374     // simulate a media change to reset failure count
   322     // simulate a media change to reset failure count
   375     r = TheFs.RemountDrive(aDrive, NULL, 0);
   323     r = TheFs.RemountDrive(aDrive, NULL, 0);
   376 
   324 
   378     for (entryAttempts=0; entryAttempts < KEntryAttempts; entryAttempts++)
   326     for (entryAttempts=0; entryAttempts < KEntryAttempts; entryAttempts++)
   379         {
   327         {
   380         TEntry entry;
   328         TEntry entry;
   381         _LIT(KNonExistantFilename, "NONEXISTANT_FILENAME.DLL");
   329         _LIT(KNonExistantFilename, "NONEXISTANT_FILENAME.DLL");
   382         r = TheFs.Entry(KNonExistantFilename, entry);
   330         r = TheFs.Entry(KNonExistantFilename, entry);
   383         test_Value(r, r == KErrCorrupt);
   331         test(r == KErrCorrupt);
   384         }
   332         }
   385     r=TheFs.Drive(info,aDrive);
   333     r=TheFs.Drive(info,aDrive);
   386     test_KErrNone(r);
   334     test(r==KErrNone);
   387     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   335     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
   388         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   336         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
   389     remounts = (TInt) info.iBattery;
   337     remounts = (TInt) info.iBattery;
   390     test.Printf(_L("Remounts = %d\n"), remounts);
   338     test.Printf(_L("Remounts = %d"), remounts);
   391     test(remounts ==  KMaxMountFailures * 2);
   339     test(remounts ==  KMaxMountFailures * 2);
   392     
   340     
   393 
   341 
   394 
   342 
   395     r=TheFs.DismountFileSystem(newFs,aDrive);
   343     r=TheFs.DismountFileSystem(newFs,aDrive);
   396     test_KErrNone(r);
   344     test(r==KErrNone);
   397     r=TheFs.MountFileSystem(oldFs,aDrive);
   345     r=TheFs.MountFileSystem(oldFs,aDrive);
   398     test_KErrNone(r);
   346     test(r==KErrNone);
   399     
   347     
   400     r=TheFs.RemoveFileSystem(KTestFsName2);
   348     r=TheFs.RemoveFileSystem(_L("Test2"));
   401     if(r!=KErrNone)
   349     if(r!=KErrNone)
   402         {
   350         {
   403         test.Printf(_L("error=%d\n"),r);
   351         test.Printf(_L("error=%d"),r);
   404         test(EFalse);
   352         test(EFalse);
   405         }
   353         }
   406     }
   354     }
   407 
   355 
   408 
   356 
   409 /**
   357 /**
   410     Testing obtaining media serial number for the substituted drives
   358     Testing obtaining media serial number for the substituted drives
   411 */
   359 */
   412 static void TestSubstDriveMediaSerialNumber()
   360 static void TestSubstDriveMediaSerialNumber()
   413 {
   361 {
   414     test.Next(_L("Test obtaining media serial number for the substituted drives\n"));
   362     test.Next(_L("Test obtaining media serial number for the substituted drives"));
   415 
   363 
   416     TInt  nRes;
   364     TInt  nRes;
   417     const TInt currDrvNum=CurrentDrive();
   365     const TInt currDrvNum=CurrentDrive();
   418     
   366     
   419     TDriveInfo drvInfo;
   367     TDriveInfo drvInfo;
   420     nRes=TheFs.Drive(drvInfo, currDrvNum);
   368     nRes=TheFs.Drive(drvInfo, currDrvNum);
   421     test_KErrNone(nRes);
   369     test(nRes==KErrNone);
   422 
   370 
   423     if(drvInfo.iDriveAtt & (KDriveAttRom | KDriveAttRedirected | KDriveAttSubsted))
   371     if(drvInfo.iDriveAtt & (KDriveAttRom | KDriveAttRedirected | KDriveAttSubsted))
   424     {
   372     {
   425         test.Printf(_L("Can't test on this drive!\n"));
   373         test.Printf(_L("Can't test on this drive!\n"));
   426         return;
   374         return;
   435         TDriveInfo drvInfo;
   383         TDriveInfo drvInfo;
   436         if(KErrNone==TheFs.Drive(drvInfo, drvNum) && drvInfo.iType==EMediaNotPresent)
   384         if(KErrNone==TheFs.Drive(drvInfo, drvNum) && drvInfo.iType==EMediaNotPresent)
   437             {
   385             {
   438             // found a non-extant drive, test it...
   386             // found a non-extant drive, test it...
   439             nRes = TheFs.GetMediaSerialNumber(serNum, drvNum);
   387             nRes = TheFs.GetMediaSerialNumber(serNum, drvNum);
   440             test_Value(nRes, nRes == KErrNotReady);
   388             test(nRes == KErrNotReady);
   441             break;
   389             break;
   442             }
   390             }
   443         }
   391         }
   444     }
   392     }
   445     
   393     
   456     //-- make directory, which will be substituted ad a drive
   404     //-- make directory, which will be substituted ad a drive
   457     substPath.Format(_L("%c:\\SubstDrv1\\"), (TUint8)'A'+currDrvNum);
   405     substPath.Format(_L("%c:\\SubstDrv1\\"), (TUint8)'A'+currDrvNum);
   458     MakeDir(substPath);
   406     MakeDir(substPath);
   459   
   407   
   460     nRes = TheFs.SetSubst(substPath, KSubstDrv);
   408     nRes = TheFs.SetSubst(substPath, KSubstDrv);
   461     test_KErrNone(nRes);
   409     test(nRes == KErrNone);
   462 
   410 
   463     //-- an attempt to obtain Media Serial Number on a substed drive shall result in KErrNotSupported
   411     //-- an attempt to obtain Media Serial Number on a substed drive shall result in KErrNotSupported
   464     nRes = TheFs.GetMediaSerialNumber(serNum, KSubstDrv);
   412     nRes = TheFs.GetMediaSerialNumber(serNum, KSubstDrv);
   465     test_Value(nRes, nRes == KErrNotSupported);
   413     test(nRes == KErrNotSupported);
   466 
   414 
   467     //-- delete substed drive
   415     //-- delete substed drive
   468     nRes = TheFs.SetSubst(_L(""), KSubstDrv);
   416     nRes = TheFs.SetSubst(_L(""), KSubstDrv);
   469     test_KErrNone(nRes);
   417     test(nRes == KErrNone);
   470 }
   418 }
   471 
   419 
   472 
   420 
   473 //----------------------------------------------------------------------------------------------
   421 //----------------------------------------------------------------------------------------------
   474 //! @SYMTestCaseID      PBASE-t_fsys-0317
   422 //! @SYMTestCaseID      PBASE-t_fsys-0317
   488 //! @SYMTestPriority        High
   436 //! @SYMTestPriority        High
   489 //! @SYMTestStatus          Implemented
   437 //! @SYMTestStatus          Implemented
   490 //----------------------------------------------------------------------------------------------
   438 //----------------------------------------------------------------------------------------------
   491 static void TestFileSystemSubTypeQuery()
   439 static void TestFileSystemSubTypeQuery()
   492     {
   440     {
   493     test.Next(_L("Test querying sub type of the mounted file system\n"));
   441     test.Next(_L("Test querying sub type of the mounted file system"));
   494     TFSName fsName;
   442     TFSName fsName;
   495     TPckgBuf<TFSName> subName;
   443     TPckgBuf<TFSName> subName;
   496     TInt i, r;
   444     TInt i, r;
   497     TDriveInfo driveInfo;
   445     TDriveInfo driveInfo;
   498     TPckgBuf<TBool> fDrvSyncBuf;
   446     TPckgBuf<TBool> fDrvSyncBuf;
   503         r = TheFs.FileSystemName(fsName, i);
   451         r = TheFs.FileSystemName(fsName, i);
   504         if (r == KErrNone)
   452         if (r == KErrNone)
   505             {
   453             {
   506             test.Printf(_L("Tested on drive: %c.\n"), (char)(i+'A'));
   454             test.Printf(_L("Tested on drive: %c.\n"), (char)(i+'A'));
   507             r=TheFs.Drive(driveInfo, i);
   455             r=TheFs.Drive(driveInfo, i);
   508             test_KErrNone(r);
   456             test(r==KErrNone);
   509             
   457             
   510             if (driveInfo.iType==EMediaNotPresent)
   458             if (driveInfo.iType==EMediaNotPresent)
   511                 {
   459                 {
   512                 test.Printf(_L("The media is not present.\n"));
   460                 test.Printf(_L("The media is not present.\n"));
   513                 r = TheFs.QueryVolumeInfoExt(i, EFileSystemSubType, subName);
   461                 r = TheFs.QueryVolumeInfoExt(i, EFileSystemSubType, subName);
   514                 test_Value(r, r == KErrNone || r == KErrNotReady);
   462                 test(r == KErrNone || r == KErrNotReady);
   515                 }
   463                 }
   516             else if (driveInfo.iType==EMediaCdRom)
   464             else if (driveInfo.iType==EMediaCdRom)
   517                 {
   465                 {
   518                 test.Printf(_L("CD ROM with no media will report not ready!\n"));
   466                 test.Printf(_L("CD ROM with no media will report not ready!\n"));
   519                 r = TheFs.QueryVolumeInfoExt(i, EFileSystemSubType, subName);
   467                 r = TheFs.QueryVolumeInfoExt(i, EFileSystemSubType, subName);
   520                 test_Value(r, r == KErrNotReady);
   468                 test(r == KErrNotReady);
   521                 }
   469                 }
   522             else
   470             else
   523                 {
   471                 {
   524                 r = TheFs.QueryVolumeInfoExt(i, EFileSystemSubType, subName);
   472                 r = TheFs.QueryVolumeInfoExt(i, EFileSystemSubType, subName);
   525                 test_KErrNone(r);
   473                 test_KErrNone(r);
   526 
   474 
   527                 //-- test EIsDriveSync command
   475                 //-- test EIsDriveSync command
   528                 r = TheFs.QueryVolumeInfoExt(i, EIsDriveSync, fDrvSyncBuf);
   476                 r = TheFs.QueryVolumeInfoExt(i, EIsDriveSync, fDrvSyncBuf);
   529                 test_KErrNone(r);
   477                 test(r == KErrNone);
   530                 if(fDrvSyncBuf())
   478                 if(fDrvSyncBuf())
   531                     test.Printf(_L("The drive is Synchronous.\n"));
   479                     test.Printf(_L("The drive is Synchronous.\n"));
   532                 else
   480                 else
   533                     test.Printf(_L("The drive is Asynchronous.\n"));
   481                     test.Printf(_L("The drive is Asynchronous.\n"));
   534 
   482 
   535                 //-----------------
   483                 //-----------------
   536                 
   484                 
   537                 // if Fat, testing returning sub type name
   485                 // if Fat, testing returning sub type name
   538                 if (fsName.CompareF(KFileSystemName_FAT)==0)
   486                 if (fsName.CompareF(KFileSystemName_FAT)==0)
   539                     {
   487                     {
   540                     test_KErrNone(r);
   488                     test(r == KErrNone);
   541                     test(subName().CompareF(KFSSubType_FAT12)==0 ||
   489                     test(subName().CompareF(KFSSubType_FAT12)==0 ||
   542                          subName().CompareF(KFSSubType_FAT16)==0 ||
   490                          subName().CompareF(KFSSubType_FAT16)==0 ||
   543                          subName().CompareF(KFSSubType_FAT32)==0);
   491                          subName().CompareF(KFSSubType_FAT32)==0);
   544                     continue;
   492                     continue;
   545                     }
   493                     }
   546                 
   494                 
   547                 // if Lffs, testing returning file system name
   495                 // if Lffs, testing returning file system name
   548                 if (fsName.CompareF(_L("Lffs"))==0)
   496                 if (fsName.CompareF(_L("Lffs"))==0)
   549                     {
   497                     {
   550                     test_KErrNone(r);
   498                     test(r == KErrNone);
   551                     test(subName().CompareF(_L("Lffs"))==0);
   499                     test(subName().CompareF(_L("Lffs"))==0);
   552                     continue;
   500                     continue;
   553                     }
   501                     }
   554                 // if rofs, testing returning file system name
   502                 // if rofs, testing returning file system name
   555                 if (fsName.CompareF(_L("rofs"))==0)
   503                 if (fsName.CompareF(_L("rofs"))==0)
   556                     {
   504                     {
   557                     test_KErrNone(r);
   505                     test(r == KErrNone);
   558                     test(subName().CompareF(_L("rofs"))==0);
   506                     test(subName().CompareF(_L("rofs"))==0);
   559                     continue;
   507                     continue;
   560                     }
   508                     }
   561                 // if Composite, testing returning file system name
   509                 // if Composite, testing returning file system name
   562                 if (fsName.CompareF(_L("Composite"))==0)
   510                 if (fsName.CompareF(_L("Composite"))==0)
   563                     {
   511                     {
   564                     test_KErrNone(r);
   512                     test(r == KErrNone);
   565                     test(subName().CompareF(_L("Composite"))==0);
   513                     test(subName().CompareF(_L("Composite"))==0);
   566                     continue;
   514                     continue;
   567                     }
   515                     }
   568 
   516 
   569                 // else
   517                 // else
   570                 test_KErrNone(r);
   518                 test(r == KErrNone);
   571                 test(subName().Length()!=0);
   519                 test(subName().Length()!=0);
   572                 
   520                 
   573                 }
   521                 }
   574             }
   522             }
   575         }
   523         }
   591 //! @SYMTestPriority        High
   539 //! @SYMTestPriority        High
   592 //! @SYMTestStatus          Implemented
   540 //! @SYMTestStatus          Implemented
   593 //----------------------------------------------------------------------------------------------
   541 //----------------------------------------------------------------------------------------------
   594 static void TestFileSystemClusterSizeQuery()
   542 static void TestFileSystemClusterSizeQuery()
   595     {
   543     {
   596     test.Next(_L("Test querying cluster size information of the mounted file system\n"));
   544     test.Next(_L("Test querying cluster size information of the mounted file system"));
   597     TFullName fsName;
   545     TFullName fsName;
   598     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   546     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   599     TInt i, r;
   547     TInt i, r;
   600     TDriveInfo driveInfo;
   548     TDriveInfo driveInfo;
   601     for(i = EDriveA; i <= EDriveZ; ++i)
   549     for(i = EDriveA; i <= EDriveZ; ++i)
   604         if (r == KErrNone)
   552         if (r == KErrNone)
   605             {
   553             {
   606             test.Printf(_L("Tested on drive: %c.\n"), (char)(i+'A'));
   554             test.Printf(_L("Tested on drive: %c.\n"), (char)(i+'A'));
   607 
   555 
   608             r=TheFs.Drive(driveInfo, i);
   556             r=TheFs.Drive(driveInfo, i);
   609             test_KErrNone(r);
   557             test(r==KErrNone);
   610             // if no media present
   558             // if no media present
   611             if (driveInfo.iType==EMediaNotPresent)
   559             if (driveInfo.iType==EMediaNotPresent)
   612                 {
   560                 {
   613                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   561                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   614                 test_Value(r, r == KErrNone || r == KErrNotReady);
   562                 test(r == KErrNone || r == KErrNotReady);
   615                 }
   563                 }
   616             else if (driveInfo.iType==EMediaCdRom)
   564             else if (driveInfo.iType==EMediaCdRom)
   617                 {
   565                 {
   618                 test.Printf(_L("CD ROM with no media!\n"));
   566                 test.Printf(_L("CD ROM with no media!\n"));
   619                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   567                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   620                 test_Value(r, r == KErrNone || r == KErrNotReady);
   568                 test(r == KErrNone || r == KErrNotReady);
   621                 }
   569                 }
   622             else
   570             else
   623                 {
   571                 {
   624                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   572                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   625                 test(KErrNone == r);
   573                 test(KErrNone == r);
   652                                 drive.Disconnect();
   600                                 drive.Disconnect();
   653                             }
   601                             }
   654                         }
   602                         }
   655                         TPckg<TLocalDriveCapsV7> capsPckg(DriveCapsV7);
   603                         TPckg<TLocalDriveCapsV7> capsPckg(DriveCapsV7);
   656                         r=drive.Caps(capsPckg);
   604                         r=drive.Caps(capsPckg);
   657                         test_KErrNone(r);
   605                         test(r==KErrNone);
   658                         drive.Disconnect();
   606                         drive.Disconnect();
   659                         if(DriveCapsV7.iObjectModeSize == 0)
   607                         if(DriveCapsV7.iObjectModeSize == 0)
   660                         {
   608                         {
   661                     test(ioInfo().iClusterSize == 512);
   609                     test(ioInfo().iClusterSize == 512);
   662                     continue;
   610                     continue;
   696 //! @SYMTestPriority        High
   644 //! @SYMTestPriority        High
   697 //! @SYMTestStatus          Implemented
   645 //! @SYMTestStatus          Implemented
   698 //----------------------------------------------------------------------------------------------
   646 //----------------------------------------------------------------------------------------------
   699 static void TestMediaBlockSizeQuery()
   647 static void TestMediaBlockSizeQuery()
   700     {
   648     {
   701     test.Next(_L("Test querying block size information of the underlying media\n"));
   649     test.Next(_L("Test querying block size information of the underlying media"));
   702     #if defined(__WINS__)
   650     #if defined(__WINS__)
   703         test.Printf(_L("This test case runs on hardware only\n"));
   651         test.Printf(_L("This test case runs on hardware only"));
   704         return;
   652         return;
       
   653     
   705     #else   // test runs on hardware only.
   654     #else   // test runs on hardware only.
   706  
       
   707     TFSName fsName;
   655     TFSName fsName;
   708     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   656     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   709     TInt i, r;
   657     TInt i, r;
   710     TDriveInfo driveInfo;
   658     TDriveInfo driveInfo;
   711     for(i = EDriveA; i <= EDriveZ; ++i)
   659     for(i = EDriveA; i <= EDriveZ; ++i)
   713         r = TheFs.FileSystemName(fsName, i);
   661         r = TheFs.FileSystemName(fsName, i);
   714         if (r == KErrNone)
   662         if (r == KErrNone)
   715             {
   663             {
   716             test.Printf(_L("Tested on drive: %c.\n"), (char)(i+'A'));
   664             test.Printf(_L("Tested on drive: %c.\n"), (char)(i+'A'));
   717             r=TheFs.Drive(driveInfo, i);
   665             r=TheFs.Drive(driveInfo, i);
   718             test_KErrNone(r);
   666             test(r==KErrNone);
   719             // if no media present
   667             // if no media present
   720             if (driveInfo.iType==EMediaNotPresent)
   668             if (driveInfo.iType==EMediaNotPresent)
   721                 {
   669                 {
   722                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   670                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   723                 test_Value(r, r == KErrNone || r == KErrNotReady);
   671                 test(r == KErrNone || r == KErrNotReady);
   724                 }
   672                 }
   725             else if (driveInfo.iType==EMediaCdRom)
   673             else if (driveInfo.iType==EMediaCdRom)
   726                 {
   674                 {
   727                 test.Printf(_L("CD ROM with no media will report not ready!\n"));
   675                 test.Printf(_L("CD ROM with no media will report not ready!\n"));
   728                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   676                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   729                 test_Value(r, r == KErrNotReady);
   677                 test(r == KErrNotReady);
   730                 }
   678                 }
   731             else
   679             else
   732                 {
   680                 {
   733                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   681                 r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   734                 test(KErrNone == r);
   682                 test(KErrNone == r);
   775                             drive.Disconnect();
   723                             drive.Disconnect();
   776                             }
   724                             }
   777                         }
   725                         }
   778                     TPckg<TLocalDriveCapsV7> capsPckg(DriveCapsV7);
   726                     TPckg<TLocalDriveCapsV7> capsPckg(DriveCapsV7);
   779                     r=drive.Caps(capsPckg);
   727                     r=drive.Caps(capsPckg);
   780                     test_KErrNone(r);
   728                     test(r==KErrNone);
   781                     if ((fsName.CompareF(_L("Lffs"))==0) && (DriveCapsV7.iObjectModeSize != 0))
   729                     if ((fsName.CompareF(_L("Lffs"))==0) && (DriveCapsV7.iObjectModeSize != 0))
   782                         {                   
   730                         {                   
   783                         test(ioInfo().iBlockSize == (TInt) DriveCapsV7.iObjectModeSize);
   731                         test(ioInfo().iBlockSize == (TInt) DriveCapsV7.iObjectModeSize);
   784                         continue;
   732                         continue;
   785                         }
   733                         }
   815 //! @SYMTestPriority        High
   763 //! @SYMTestPriority        High
   816 //! @SYMTestStatus          Implemented
   764 //! @SYMTestStatus          Implemented
   817 //----------------------------------------------------------------------------------------------
   765 //----------------------------------------------------------------------------------------------
   818 static void TestFileSystemSubType()
   766 static void TestFileSystemSubType()
   819     {
   767     {
   820     test.Next(_L("Test wrapper API RFs::FileSystemSubType()'s behaviour\n"));
   768     test.Next(_L("Test wrapper API RFs::FileSystemSubType()'s behaviour"));
   821     TFSName fsName;
   769     TFSName fsName;
   822     TPckgBuf<TFSName> subName;
   770     TPckgBuf<TFSName> subName;
   823     TInt r;
   771     TInt r;
   824     TFSName subName1;
   772     TFSName subName1;
   825     TInt r1;
   773     TInt r1;
   830         if (r == KErrNone)
   778         if (r == KErrNone)
   831             {
   779             {
   832             test.Printf(_L("Tested on drive: %c.\n"), (char)(i+'A'));
   780             test.Printf(_L("Tested on drive: %c.\n"), (char)(i+'A'));
   833             r = TheFs.QueryVolumeInfoExt(i, EFileSystemSubType, subName);
   781             r = TheFs.QueryVolumeInfoExt(i, EFileSystemSubType, subName);
   834             r1 = TheFs.FileSystemSubType(i, subName1);
   782             r1 = TheFs.FileSystemSubType(i, subName1);
   835             test_Value(r, r == r1);
   783             test(r==r1);
   836             if (subName().Length())
   784             if (subName().Length())
   837                 {
   785                 {
   838                 test(subName().CompareF(subName1)==0);
   786                 test(subName().CompareF(subName1)==0);
   839                 }
   787                 }
   840             else
   788             else
   857 //! @SYMTestPriority        High
   805 //! @SYMTestPriority        High
   858 //! @SYMTestStatus          Implemented
   806 //! @SYMTestStatus          Implemented
   859 //----------------------------------------------------------------------------------------------
   807 //----------------------------------------------------------------------------------------------
   860 static void TestVolumeIOParam()
   808 static void TestVolumeIOParam()
   861     {
   809     {
   862     test.Next(_L("Test wrapper API RFs::VolumeIOParam()'s behaviour\n"));
   810     test.Next(_L("Test wrapper API RFs::VolumeIOParam()'s behaviour"));
   863     TFSName fsName;
   811     TFSName fsName;
   864     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   812     TPckgBuf<TVolumeIOParamInfo> ioInfo;
   865     TInt r;
   813     TInt r;
   866     TVolumeIOParamInfo ioInfo1;
   814     TVolumeIOParamInfo ioInfo1;
   867     TInt r1;
   815     TInt r1;
   872         if (r == KErrNone)
   820         if (r == KErrNone)
   873             {
   821             {
   874             test.Printf(_L("Tested on drive: %c.\n"), (char)(i+'A'));
   822             test.Printf(_L("Tested on drive: %c.\n"), (char)(i+'A'));
   875             r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   823             r = TheFs.QueryVolumeInfoExt(i, EIOParamInfo, ioInfo);
   876             r1 = TheFs.VolumeIOParam(i, ioInfo1);
   824             r1 = TheFs.VolumeIOParam(i, ioInfo1);
   877             test_Value(r, r == r1);
   825             test(r==r1);
   878             test(ioInfo().iBlockSize == ioInfo1.iBlockSize);
   826             test(ioInfo().iBlockSize == ioInfo1.iBlockSize);
   879             test(ioInfo().iClusterSize == ioInfo1.iClusterSize);
   827             test(ioInfo().iClusterSize == ioInfo1.iClusterSize);
   880             test(ioInfo().iRecReadBufSize == ioInfo1.iRecReadBufSize);
   828             test(ioInfo().iRecReadBufSize == ioInfo1.iRecReadBufSize);
   881             test(ioInfo().iRecWriteBufSize == ioInfo1.iRecWriteBufSize);
   829             test(ioInfo().iRecWriteBufSize == ioInfo1.iRecWriteBufSize);
   882             }
   830             }
   906     TInt r;
   854     TInt r;
   907 
   855 
   908     test.Printf(_L("Tested on drive: %c.\n"), (char)(aDrive+'A'));
   856     test.Printf(_L("Tested on drive: %c.\n"), (char)(aDrive+'A'));
   909 
   857 
   910     // Mount a new CTestFileSystem on the drive under test
   858     // Mount a new CTestFileSystem on the drive under test
   911     test.Next(_L("Test RFs::QueryVolumeInfoExt() on Testing File System\n"));
   859     test.Next(_L("Test RFs::QueryVolumeInfoExt() on Testing File System"));
   912     r = TheFs.AddFileSystem(KTestFsy3);
   860     r = TheFs.AddFileSystem(_L("T_TFSYS3"));
   913     if (r != KErrNone && r != KErrAlreadyExists)
   861     if (r != KErrNone && r != KErrAlreadyExists)
   914         {
   862         {
   915         test.Printf(_L("error=%d\n"),r);
   863         test.Printf(_L("error=%d"),r);
   916         test(EFalse);
   864         test(EFalse);
   917         }
   865         }
   918     TFSName oldFs;
   866     TFSName oldFs;
   919     r = TheFs.FileSystemName(oldFs,aDrive);
   867     r = TheFs.FileSystemName(oldFs,aDrive);
   920     test_KErrNone(r);
   868     test(r==KErrNone);
   921     r = TheFs.DismountFileSystem(oldFs,aDrive);
   869     r = TheFs.DismountFileSystem(oldFs,aDrive);
   922     if (r != KErrNone)
   870     if (r != KErrNone)
   923         {
   871         {
   924         test.Printf(_L("Error = %d\n"),r);    
   872         test.Printf(_L("Error = %d"),r);    
   925         test(EFalse);
   873         test(EFalse);
   926         }
   874         }
   927     r = TheFs.MountFileSystem(KTestFsName3, aDrive);
   875     r = TheFs.MountFileSystem(_L("Test3"),aDrive);
   928     test_KErrNone(r);
   876     test(r==KErrNone);
   929     TFSName newFs;
   877     TFSName newFs;
   930     r = TheFs.FileSystemName(newFs,aDrive);
   878     r = TheFs.FileSystemName(newFs,aDrive);
   931     test_KErrNone(r);
   879     test(r==KErrNone);
   932     test(newFs.Compare(KTestFsName3)==0);
   880     test(newFs.Compare(_L("Test3"))==0);
   933 
   881 
   934     // Sub type name query: 
   882     // Sub type name query: 
   935     TPckgBuf<TFSName> subNameP;
   883     TPckgBuf<TFSName> subNameP;
   936     r = TheFs.QueryVolumeInfoExt(aDrive, EFileSystemSubType, subNameP);
   884     r = TheFs.QueryVolumeInfoExt(aDrive, EFileSystemSubType, subNameP);
   937     test_KErrNone(r);
   885     test(r==KErrNone);
   938     test(subNameP() == _L("Test3SubType"));
   886     test(subNameP() == _L("Test3SubType"));
   939 
   887 
   940     // Cluster size querys:
   888     // Cluster size querys:
   941     TPckgBuf<TVolumeIOParamInfo> ioInfoP;
   889     TPckgBuf<TVolumeIOParamInfo> ioInfoP;
   942     r = TheFs.QueryVolumeInfoExt(aDrive, EIOParamInfo, ioInfoP);
   890     r = TheFs.QueryVolumeInfoExt(aDrive, EIOParamInfo, ioInfoP);
   943     test_KErrNone(r);
   891     test(r==KErrNone);
   944     test(ioInfoP().iClusterSize==1024);
   892     test(ioInfoP().iClusterSize==1024);
   945 
   893 
   946     // Mount the original file system back
   894     // Mount the original file system back
   947     r=TheFs.DismountFileSystem(newFs,aDrive);
   895     r=TheFs.DismountFileSystem(newFs,aDrive);
   948     test_KErrNone(r);
   896     test(r==KErrNone);
   949     r=TheFs.MountFileSystem(oldFs,aDrive);
   897     r=TheFs.MountFileSystem(oldFs,aDrive);
   950     test_KErrNone(r);
   898     test(r==KErrNone);
   951     
   899     
   952     r=TheFs.RemoveFileSystem(KTestFsName3);
   900     r=TheFs.RemoveFileSystem(_L("Test3"));
   953     if(r!=KErrNone)
   901     if(r!=KErrNone)
   954         {
   902         {
   955         test.Printf(_L("error=%d\n"),r);
   903         test.Printf(_L("error=%d"),r);
   956         test(EFalse);
   904         test(EFalse);
   957         }
   905         }
   958     }
   906     }
   959 
   907 
   960 
   908 
   969 */
   917 */
   970 static void TestRemountFSWithOpenedObjects()
   918 static void TestRemountFSWithOpenedObjects()
   971 {
   919 {
   972     test.Next(_L("Testing forcedly remounting FS with objects opened.\n"));
   920     test.Next(_L("Testing forcedly remounting FS with objects opened.\n"));
   973     
   921     
   974     //-- don't perform this test on a non-removable drive, generating media change on such drive
       
   975     //-- doesn't always work
       
   976     TInt nRes;
   922     TInt nRes;
   977     const TInt drvNumber = CurrentDrive();
   923     
   978     TDriveInfo driveInfo;
       
   979 
       
   980     nRes = TheFs.Drive(driveInfo, drvNumber);
       
   981     test_KErrNone(nRes);
       
   982 
       
   983     if(! (driveInfo.iDriveAtt & KDriveAttRemovable))
       
   984     {
       
   985         test.Printf(_L("Can't perform this test on a non-removable drive. Skippping!\n"));
       
   986         return;
       
   987     }
       
   988 
       
   989 
       
   990     //-- 1. create a file
   924     //-- 1. create a file
   991     _LIT(KFile, "\\test_file.file");
   925     _LIT(KFile, "\\test_file.file");
   992     const TUint KFileSz = 5000;
   926     const TUint KFileSz = 5000;
   993     
   927     
   994     nRes = CreateCheckableStuffedFile(TheFs, KFile, KFileSz);
   928     nRes = CreateCheckableStuffedFile(TheFs, KFile, KFileSz);
   998 
   932 
   999     //-- 2. open this file
   933     //-- 2. open this file
  1000     nRes = file.Open(TheFs, KFile, EFileRead);
   934     nRes = file.Open(TheFs, KFile, EFileRead);
  1001     test_KErrNone(nRes);
   935     test_KErrNone(nRes);
  1002     
   936     
  1003     
   937     const TInt drvNumber = CurrentDrive();
  1004 
   938 
  1005     //-- 2.1 try to dismount the FS, it must fail because of the opened object.
   939     //-- 2.1 try to dismount the FS, it must fail because of the opened object.
  1006     TBuf<40> fsName;
   940     TBuf<40> fsName;
  1007     nRes = TheFs.FileSystemName(fsName, drvNumber);
   941     nRes = TheFs.FileSystemName(fsName, drvNumber);
  1008     test_KErrNone(nRes);
   942     test_KErrNone(nRes);
  1012 
   946 
  1013     // Flag from locmedia.h to simulate ejecting and re-inserting the media.
   947     // Flag from locmedia.h to simulate ejecting and re-inserting the media.
  1014     const TUint KMediaRemountForceMediaChange = 0x00000001;
   948     const TUint KMediaRemountForceMediaChange = 0x00000001;
  1015     TRequestStatus changeStatus;
   949     TRequestStatus changeStatus;
  1016     TheFs.NotifyChange(ENotifyAll, changeStatus);
   950     TheFs.NotifyChange(ENotifyAll, changeStatus);
  1017     
   951     TDriveInfo driveInfo;
  1018     
   952     
  1019     //-- 3. forcedly remount the drive
   953     //-- 3. forcedly remount the drive
  1020     nRes = TheFs.RemountDrive(drvNumber, NULL, KMediaRemountForceMediaChange);
   954     nRes = TheFs.RemountDrive(drvNumber, NULL, KMediaRemountForceMediaChange);
  1021     
   955     
  1022     if(nRes == KErrNotSupported)
   956     if(nRes == KErrNotSupported)
  1023     	{//-- this feature is not supported and the test is inconsistent.
   957     	{//-- this feature is not supported and the test is inconsistent.
  1024         test.Printf(_L("RemountDrive() is not supported, the test is inconsistent!\n"));
   958         test.Printf(_L("RemountDrive() is not supported, the test is inconsistent!"));
  1025         
   959         
  1026         //-- remounting must work at least on MMC drives
   960         //-- remounting must work at least on MMC drives
  1027         const TBool isFAT = Is_Fat(TheFs, drvNumber);
   961         const TBool isFAT = Is_Fat(TheFs, drvNumber);
  1028 
   962 
  1029         nRes = TheFs.Drive(driveInfo, drvNumber);
   963         nRes = TheFs.Drive(driveInfo, drvNumber);
  1032         test_Value(driveInfo.iDriveAtt, !isFAT || (!(driveInfo.iDriveAtt & KDriveAttRemovable)));
   966         test_Value(driveInfo.iDriveAtt, !isFAT || (!(driveInfo.iDriveAtt & KDriveAttRemovable)));
  1033     	}
   967     	}
  1034     else
   968     else
  1035     	{
   969     	{
  1036 		test_Value(nRes, nRes == KErrNotReady || nRes == KErrNone);
   970 		test_Value(nRes, nRes == KErrNotReady || nRes == KErrNone);
  1037 		test.Printf(_L("Waiting for the simulated media change...\n"));
   971 		
  1038 
       
  1039 		//-- 3.1 wait for media change to complete
   972 		//-- 3.1 wait for media change to complete
  1040 		do
   973 		do
  1041 			{
   974 			{
  1042 			// Waiting for media change...
   975 			// Waiting for media change...
  1043 			User::WaitForRequest(changeStatus);
   976 			User::WaitForRequest(changeStatus);
  1068 
  1001 
  1069 }
  1002 }
  1070 //----------------------------------------------------------------------------------------------
  1003 //----------------------------------------------------------------------------------------------
  1071 static void TestFileSystem_MaxSupportedFileSizeQuery()
  1004 static void TestFileSystem_MaxSupportedFileSizeQuery()
  1072 {
  1005 {
  1073     test.Next(_L("Test querying max. supported file size on this file system\n"));
  1006     test.Next(_L("Test querying max. supported file size on this file system"));
  1074     TFullName fsName;
  1007     TFullName fsName;
  1075     TPckgBuf<TVolumeIOParamInfo> ioInfo;
  1008     TPckgBuf<TVolumeIOParamInfo> ioInfo;
  1076     TVolumeIOParamInfo& volInfo = ioInfo();
  1009     TVolumeIOParamInfo& volInfo = ioInfo();
  1077 
  1010 
  1078     const TInt drvNo=CurrentDrive();
  1011     const TInt drvNo=CurrentDrive();
  1099     }
  1032     }
  1100 
  1033 
  1101 }
  1034 }
  1102 
  1035 
  1103 //----------------------------------------------------------------------------------------------
  1036 //----------------------------------------------------------------------------------------------
  1104 void CallTestsL()
  1037 GLDEF_C void CallTestsL()
       
  1038 //
       
  1039 // Do all tests
       
  1040 //
  1105     {
  1041     {
  1106 
  1042 
  1107     //-- set up console output 
  1043     //-- set up console output 
  1108     Fat_Test_Utils::SetConsole(test.Console()); 
  1044     Fat_Test_Utils::SetConsole(test.Console()); 
  1109 
  1045 
  1110     const TInt drive=CurrentDrive();
  1046     TInt drive=CurrentDrive();
       
  1047 
  1111     PrintDrvInfo(TheFs, drive);
  1048     PrintDrvInfo(TheFs, drive);
  1112 
  1049 
  1113     //Do not run this test on the NAND drive, as this has the FTL mounted as a primary extension
  1050     //Do not run this test on the NAND drive, as
       
  1051     //this has the FTL mounted as a primary extension
  1114     //which causes the test to fail
  1052     //which causes the test to fail
  1115     
  1053     #if defined(__WINS__)
  1116     TFSName pExtName;
  1054         if (drive==EDriveU)
  1117     pExtName.Zero();
  1055             return;
  1118    
  1056     #else
  1119     TInt nRes = TheFs.ExtensionName(pExtName, drive, 0);
  1057         TDriveInfo driveInfo;
  1120    
  1058         TheFs.Drive(driveInfo,drive);
  1121     if(nRes == KErrNone && pExtName.Length())
  1059         if (driveInfo.iType == EMediaNANDFlash)
  1122         {
  1060             {
  1123         test.Printf(_L("This test can't be run on a drive that has a primary extension:%S\n"), &pExtName);   
  1061             return;
  1124         return;
  1062             }
  1125         }
  1063     #endif
  1126 
  1064 
  1127     //---------------------------------------
  1065     //---------------------------------------
  1128 
  1066 
  1129     InitGlobals();
       
  1130     
       
  1131     //---------------------------------------
       
  1132     TestFileSystemNames();
  1067     TestFileSystemNames();
  1133     TestDismountFileSystem(CurrentDrive());
  1068     TestDismountFileSystem(CurrentDrive());
       
  1069 #if defined(__EPOC32__)
  1134     TestFileSystem(CurrentDrive());
  1070     TestFileSystem(CurrentDrive());
       
  1071 #endif
       
  1072 
  1135     TestMountInvalidDrive();
  1073     TestMountInvalidDrive();
       
  1074     
  1136     TestMountingBrokenMedia(CurrentDrive());
  1075     TestMountingBrokenMedia(CurrentDrive());
  1137     TestSubstDriveMediaSerialNumber();
  1076     TestSubstDriveMediaSerialNumber();
  1138 
  1077 
  1139     TestFileSystemSubTypeQuery();
  1078     TestFileSystemSubTypeQuery();
  1140     TestFileSystemClusterSizeQuery();
  1079     TestFileSystemClusterSizeQuery();
  1141     TestMediaBlockSizeQuery();
  1080     TestMediaBlockSizeQuery();
  1142     TestFileSystemSubType();
  1081     TestFileSystemSubType();
  1143     TestVolumeIOParam();
  1082     TestVolumeIOParam();
  1144     TestQueryVolumeInfoExtOnTestFS(CurrentDrive());
  1083     TestQueryVolumeInfoExtOnTestFS(CurrentDrive());
       
  1084 
  1145     TestFileSystem_MaxSupportedFileSizeQuery();
  1085     TestFileSystem_MaxSupportedFileSizeQuery();
       
  1086 
  1146     TestRemountFSWithOpenedObjects();
  1087     TestRemountFSWithOpenedObjects();
  1147     
  1088     
  1148     //---------------------------------------
  1089     
  1149     DestroyGlobals();    
  1090     }
  1150     }