kerneltest/f32test/server/t_fsys.cpp
changeset 271 dc268b18d709
parent 269 d57b86b1867a
child 279 957c583b417b
equal deleted inserted replaced
269:d57b86b1867a 271:dc268b18d709
    53 //---------------------------------------------------
    53 //---------------------------------------------------
    54 void DestroyGlobals()
    54 void DestroyGlobals()
    55 {
    55 {
    56 }
    56 }
    57 
    57 
       
    58 
       
    59 //---------------------------------------------------
       
    60 /**
       
    61     Test CFsMountHelper class functionality
       
    62 */
       
    63 void TestFsMountHelper()
       
    64 {
       
    65     test.Next(_L("Test CFsMountHelper class functionality\n"));
       
    66 
       
    67     if(Is_SimulatedSystemDrive(TheFs, CurrentDrive()))
       
    68     {
       
    69         test.Printf(_L("Can't test on a simulated drive, skipping!\n"));
       
    70         return;
       
    71     }
       
    72 
       
    73     TInt    nRes;
       
    74     TFSName fsName;
       
    75     TFSName fsName1;
       
    76 
       
    77     CFsMountHelper* pHelper1 = CFsMountHelper::New(TheFs, CurrentDrive());
       
    78     test(pHelper1 !=0);
       
    79 
       
    80     CFsMountHelper* pHelper2 = CFsMountHelper::New(TheFs, CurrentDrive());
       
    81     test(pHelper2 !=0);
       
    82 
       
    83 
       
    84     //-- 1. store the original file system state
       
    85     nRes = pHelper1->GetMountProperties();
       
    86     test_KErrNone(nRes);
       
    87 
       
    88     //-- 1.1 simple case. dismount the file system and mount it back
       
    89     nRes = TheFs.FileSystemName(fsName, CurrentDrive());
       
    90     test_KErrNone(nRes);
       
    91     
       
    92     nRes = pHelper1->DismountFileSystem();
       
    93     test_KErrNone(nRes);
       
    94 
       
    95     nRes = pHelper1->MountFileSystem();
       
    96     test_KErrNone(nRes);
       
    97 
       
    98     nRes = TheFs.FileSystemName(fsName1, CurrentDrive());
       
    99     test_KErrNone(nRes);
       
   100     test(fsName1 == fsName);
       
   101 
       
   102     //-- 1.2 attempts to dismount FS that has files opened
       
   103     _LIT(KFileName, "\\myfile");
       
   104     _LIT8(KFileData, "\\this is the file data");
       
   105     RFile file;
       
   106 
       
   107     nRes = file.Replace(TheFs, KFileName, EFileWrite);
       
   108     test_KErrNone(nRes);
       
   109 
       
   110     //-- 1.2.1 simplistic API
       
   111     nRes = pHelper1->DismountFileSystem();
       
   112     test_Value(nRes, nRes == KErrInUse);
       
   113 
       
   114     //-- 1.2.1 more advanced asynchronous API
       
   115     
       
   116     TRequestStatus stat;
       
   117     
       
   118     //-- 1.2.1.1 simple normal dismounting, Rfs::DismountFileSystem() analog
       
   119     pHelper1->DismountFileSystem(stat, CFsMountHelper::ENormal);
       
   120     User::WaitForRequest(stat);
       
   121     test_Value(stat.Int(), stat.Int() == KErrInUse);
       
   122 
       
   123     //-- 1.2.1.2 dismount with notifying clients (no clients, so it should succeed)
       
   124     //-- this will be a kind of forced dismounting
       
   125     pHelper1->DismountFileSystem(stat, CFsMountHelper::ENotifyClients);
       
   126     User::WaitForRequest(stat);
       
   127     test_KErrNone(stat.Int());
       
   128 
       
   129     nRes = file.Write(KFileData);
       
   130     test_Value(nRes, nRes == KErrNotReady); //-- no file system on the drive
       
   131 
       
   132     //-- mount the file system back
       
   133     nRes = pHelper1->MountFileSystem();
       
   134     test_KErrNone(nRes);
       
   135 
       
   136     nRes = file.Write(KFileData);
       
   137     test_Value(nRes, nRes == KErrDisMounted);
       
   138     file.Close();
       
   139     
       
   140     //-- 1.2.1.3 forced dismounting
       
   141     nRes = file.Replace(TheFs, KFileName, EFileWrite);
       
   142     test_KErrNone(nRes);
       
   143 
       
   144     pHelper1->DismountFileSystem(stat, CFsMountHelper::ENormal);
       
   145     User::WaitForRequest(stat);
       
   146     test_Value(stat.Int(), stat.Int() == KErrInUse);
       
   147 
       
   148 
       
   149     pHelper1->DismountFileSystem(stat, CFsMountHelper::EForceImmediate);
       
   150     User::WaitForRequest(stat);
       
   151     test_KErrNone(stat.Int());
       
   152 
       
   153     nRes = file.Write(KFileData);
       
   154     test_Value(nRes, nRes == KErrNotReady); //-- no file system on the drive
       
   155     
       
   156     file.Close();
       
   157 
       
   158     //-- there is no file system on the drive. 
       
   159     
       
   160     //-- test weird use cases 
       
   161     nRes = pHelper2->GetMountProperties();
       
   162     test_Value(nRes, nRes == KErrNotFound)
       
   163     
       
   164     //nRes = pHelper2->MountFileSystem(); //-- this will trigger an assert in debug mode
       
   165 
       
   166     //-- 2. test extensions
       
   167     
       
   168     //-- 2.1 mount the file system back
       
   169     nRes = pHelper1->MountFileSystem();
       
   170     test_KErrNone(nRes);
       
   171     
       
   172     //-- 2.2 install secondary extension
       
   173     _LIT(KExtensionLog,"T_LOGEXT");     //-- test secondary extension module name *.fxt
       
   174     _LIT(KExtensionLogName,"Logger");   //-- extension name
       
   175 
       
   176     nRes = TheFs.AddExtension(KExtensionLog);
       
   177     test_KErrNone(nRes);
       
   178 
       
   179     nRes = TheFs.MountExtension(KExtensionLogName, CurrentDrive());
       
   180     test_KErrNone(nRes);
       
   181 
       
   182     nRes = TheFs.ExtensionName(fsName1, CurrentDrive(), 0); //-- extension slot 0
       
   183     test(nRes == KErrNone);
       
   184     test(fsName1 == KExtensionLogName);
       
   185 
       
   186     nRes = TheFs.ExtensionName(fsName1, CurrentDrive(), 1); //-- extension slot 1
       
   187     test_Value(nRes, nRes == KErrNotFound)
       
   188 
       
   189 
       
   190     //-- 2.3 dismount the file system, it has now different set of properties comparing to ones stored in the pHelper1
       
   191     nRes = pHelper2->GetMountProperties();
       
   192     test(nRes == KErrNone);
       
   193 
       
   194     nRes = pHelper2->DismountFileSystem();
       
   195     test_KErrNone(nRes);
       
   196 
       
   197     //-- 2.3.1 mount the original FS (without extension)
       
   198     nRes = pHelper1->MountFileSystem();
       
   199     test_KErrNone(nRes);
       
   200 
       
   201     nRes = TheFs.ExtensionName(fsName1, CurrentDrive(), 0); //-- extension slot 0
       
   202     test_Value(nRes, nRes == KErrNotFound)
       
   203 
       
   204     nRes = TheFs.ExtensionName(fsName1, CurrentDrive(), 1); //-- extension slot 1
       
   205     test_Value(nRes, nRes == KErrNotFound)
       
   206 
       
   207     nRes = pHelper1->DismountFileSystem();
       
   208     test_KErrNone(nRes);
       
   209 
       
   210     //-- 2.3.2 mount back the FS with extension
       
   211     nRes = pHelper2->MountFileSystem();
       
   212     test_KErrNone(nRes);
       
   213 
       
   214     nRes = TheFs.ExtensionName(fsName1, CurrentDrive(), 0); //-- extension slot 0
       
   215     test(nRes == KErrNone);
       
   216     test(fsName1 == KExtensionLogName);
       
   217 
       
   218     //-- 2.4 remove the extensions and dismount the file system with properties stored in pHelper2
       
   219     nRes = TheFs.ExtensionName(fsName1, CurrentDrive(), 1); //-- extension slot 1
       
   220     test_Value(nRes, nRes == KErrNotFound)
       
   221 
       
   222     nRes = pHelper2->DismountFileSystem();
       
   223     test_KErrNone(nRes);
       
   224 
       
   225     nRes = TheFs.RemoveExtension(KExtensionLogName);
       
   226     test_KErrNone(nRes);
       
   227 
       
   228 
       
   229     //-- 2.4 restore the original file system
       
   230     nRes = pHelper1->MountFileSystem();
       
   231     test_KErrNone(nRes);
       
   232 
       
   233     nRes = TheFs.ExtensionName(fsName1, CurrentDrive(), 0); //-- extension slot 0
       
   234     test_Value(nRes, nRes == KErrNotFound)
       
   235 
       
   236     nRes = TheFs.ExtensionName(fsName1, CurrentDrive(), 1); //-- extension slot 1
       
   237     test_Value(nRes, nRes == KErrNotFound)
       
   238 
       
   239     nRes = TheFs.FileSystemName(fsName1, CurrentDrive());
       
   240     test_KErrNone(nRes);
       
   241     test(fsName1 == fsName);
       
   242 
       
   243     pHelper1->Close(); //-- just for testing
       
   244 
       
   245     delete pHelper1;
       
   246     delete pHelper2;
       
   247 }
       
   248 
    58 //---------------------------------------------------
   249 //---------------------------------------------------
    59 
   250 
    60 /**
   251 /**
    61     The maximum length for the file system and extension names is KMaxFSNameLength
   252     The maximum length for the file system and extension names is KMaxFSNameLength
    62     test how the file server supports this
   253     test how the file server supports this
   136     test_Value(nRes, nRes == KErrNotFound);
   327     test_Value(nRes, nRes == KErrNotFound);
   137     
   328     
   138     
   329     
   139     //====================================================
   330     //====================================================
   140     //-- dismount original file system from the drive
   331     //-- dismount original file system from the drive
   141     TFSDescriptor orgFSDesc;
   332     
   142     nRes = GetFileSystemDescriptor(TheFs, CurrentDrive(), orgFSDesc);
   333     CFsMountHelper* pHelper = CFsMountHelper::New(TheFs, CurrentDrive());
   143     test_KErrNone(nRes);
   334     test(pHelper !=0);
   144 
   335 
   145     nRes = TheFs.DismountFileSystem(orgFSDesc.iFsName, CurrentDrive());
   336     nRes = pHelper->GetMountProperties();
       
   337     test_KErrNone(nRes);
       
   338 
       
   339     nRes = pHelper->DismountFileSystem();
   146     test_KErrNone(nRes);
   340     test_KErrNone(nRes);
   147 
   341 
   148     //-- 2. try to mount a FS/extension with the invalid name
   342     //-- 2. try to mount a FS/extension with the invalid name
   149     
   343     
   150     //-- 2.1 try empty names
   344     //-- 2.1 try empty names
   180     
   374     
   181     
   375     
   182     
   376     
   183     
   377     
   184     //-- mount original file system back to the drive
   378     //-- mount original file system back to the drive
   185     nRes = MountFileSystem(TheFs, CurrentDrive(), orgFSDesc);
   379     nRes = pHelper->MountFileSystem();
   186     test_KErrNone(nRes);
   380     test_KErrNone(nRes);
       
   381 
       
   382     delete pHelper;
   187 }
   383 }
   188 
   384 
   189 //---------------------------------------------------
   385 //---------------------------------------------------
   190 static void TestFileSystemNames()
   386 static void TestFileSystemNames()
   191     {
   387     {
  1258     //---------------------------------------
  1454     //---------------------------------------
  1259 
  1455 
  1260     InitGlobals();
  1456     InitGlobals();
  1261     
  1457     
  1262     //---------------------------------------
  1458     //---------------------------------------
       
  1459 
       
  1460     TestFsMountHelper();
  1263     TestFileSystemNames();
  1461     TestFileSystemNames();
  1264     TestFileSystemNameLength();
  1462     TestFileSystemNameLength();
  1265     TestDismountFileSystem(CurrentDrive());
  1463     TestDismountFileSystem(CurrentDrive());
  1266     TestFileSystem(CurrentDrive());
  1464     TestFileSystem(CurrentDrive());
  1267     TestMountInvalidDrive();
  1465     TestMountInvalidDrive();