kerneltest/f32test/server/t_dctcballfiles.cpp
changeset 0 a41df078684a
child 109 b3a1d9898418
child 256 c1f20ce4abcf
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <f32file.h>
       
    17 #include <e32test.h>
       
    18 #include <e32std.h>
       
    19 #include <e32std_private.h>
       
    20 #include <e32svr.h>
       
    21 #include <e32def.h>
       
    22 #include <e32def_private.h>
       
    23 #include "t_server.h"
       
    24 
       
    25 GLDEF_D RTest test(_L("t_dctcballfiles"));
       
    26 GLDEF_D TTime gTimeNow;
       
    27 LOCAL_D TInt gTheDriveNum;
       
    28 
       
    29 const TInt KPathPosition = 2;
       
    30 _LIT(KExpectedPrivatePath, "\\Private\\00000001\\");
       
    31 
       
    32 _LIT(KResourcePath, "?:\\Resource\\");
       
    33 _LIT(KSystemPath,	"?:\\Sys\\");
       
    34 _LIT(KPrivatePath,	"?:\\Private\\");
       
    35 _LIT(KPrivateFalseID,	"?:\\Private\\FFFFFFFF\\");
       
    36 _LIT(KDriveName,	"Billy");
       
    37 _LIT(KVolLable,		"Benny");
       
    38 _LIT(KFileSys,	"systemfile.txt");
       
    39 _LIT(KFileSys3, "sysfile.rna");
       
    40 _LIT(KFilePri,	"privatefile.txt");
       
    41 _LIT(KFilePri2,	"privatefile.tmp");
       
    42 _LIT(KFilePri3,	"prifile.rna");
       
    43 _LIT(KFileRes,	"resourcefile.txt");
       
    44 _LIT(KFileRes3,	"resfile.rna");
       
    45 _LIT(KMkDirSub,"Subdir\\");
       
    46 _LIT(KOldFile,"?:\\Anyold.txt");
       
    47 _LIT(KWildPath, "Z:\\SYS\\");
       
    48 _LIT(KWildFile, "*");
       
    49 
       
    50 TCapability TheCaps;
       
    51 TBuf<4> driveBuf=_L("?:\\");
       
    52 RFormat format;
       
    53 TInt count;
       
    54 RRawDisk rawdisk;
       
    55 RFile file1;
       
    56 RFile file2;
       
    57 RDir	dir;
       
    58 
       
    59 TInt r;
       
    60 TBuf<40> fsname;
       
    61 TBuf<40> systestname;
       
    62 TBuf<40> pritestname;
       
    63 TBuf<40> restestname;
       
    64 TBuf<40> theprivatepath;
       
    65 TBuf<40> pritestfalseidname;
       
    66 TBuf<40> mkdirname;
       
    67 TFileName fromTemp;
       
    68 
       
    69 TBuf<25> sysfilename;
       
    70 TBuf<30> realName;
       
    71 TBuf<40> shortfilename;
       
    72 TBuf<40> longfilename;
       
    73 
       
    74 TRequestStatus aStat1;
       
    75 TRequestStatus aStat2;
       
    76 TRequestStatus aStat3;
       
    77 TRequestStatus aStat4;
       
    78 
       
    79 TVolumeInfo aVolInfo;
       
    80 //	TDriveInfo adriveInfo;
       
    81 
       
    82 TBuf<40> systestfile;
       
    83 TBuf<40> pritestfile;
       
    84 TBuf<40> restestfile;
       
    85 TBuf<40> systestfile1;
       
    86 TBuf<40> pritestfile1;
       
    87 TBuf<40> restestfile1;
       
    88 
       
    89 TTime testtime;
       
    90 TBuf<20> oldName;
       
    91 
       
    92 TBuf<25> temp;
       
    93 
       
    94 TEntry entry;
       
    95 
       
    96 
       
    97 LOCAL_C void systemRFsTest()
       
    98 //
       
    99 //	RFs test on system Directory
       
   100 //
       
   101 	{
       
   102 	systestname=KSystemPath;
       
   103 	systestname[0]=(TText)('A' + gTheDriveNum);
       
   104 	
       
   105 	mkdirname.Zero();
       
   106 	mkdirname.Append(systestname);
       
   107 	mkdirname.Append(KMkDirSub);
       
   108 	r=TheFs.MkDirAll(mkdirname);	
       
   109 	test(r==KErrNone);
       
   110 
       
   111 	TheFs.RmDir(mkdirname);
       
   112 	test(r==KErrNone);
       
   113 
       
   114 	r=TheFs.SetSubst(systestname,EDriveO);
       
   115 	test(r==KErrPermissionDenied);
       
   116 	
       
   117 	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
       
   118 	test(r==KErrNone);
       
   119 
       
   120 	r=TheFs.SetSessionPath(systestname);
       
   121 	test(r==KErrNone);
       
   122 	
       
   123 	TheFs.NotifyChange(ENotifyAll,aStat1,systestname);
       
   124 	test(aStat1==KRequestPending);
       
   125 
       
   126 	systestfile=KSystemPath;
       
   127 	systestfile[0]=(TText)('A' + gTheDriveNum);
       
   128 	systestfile1=systestfile;
       
   129 	systestfile.Append(KFileSys);
       
   130 	systestfile1.Append(KFileSys3);
       
   131 	
       
   132 	oldName=KOldFile;
       
   133 	oldName[0]=(TText)gDriveToTest;
       
   134 
       
   135 	r=TheFs.GetShortName(systestfile, shortfilename);
       
   136 	test(r==KErrNotFound || r==KErrNotSupported);
       
   137 
       
   138 	r=TheFs.GetLongName(systestfile1, longfilename);
       
   139 	test(r==KErrNotFound || r==KErrNotSupported);
       
   140 
       
   141 	r=file1.Create(TheFs,oldName,EFileWrite);
       
   142 	test(r==KErrNone || r==KErrAlreadyExists);
       
   143 	file1.Close();
       
   144 
       
   145 	r=TheFs.Replace(oldName,systestfile);
       
   146 	test(r==KErrNone);
       
   147 	
       
   148 	r=TheFs.Rename(systestfile,systestfile1);
       
   149 	test(r==KErrNone);
       
   150 	
       
   151 	r=TheFs.Entry(systestfile1,entry);
       
   152 	test(r==KErrNone);
       
   153 
       
   154 	r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
       
   155 	test(r==KErrNone);
       
   156 
       
   157 	r=TheFs.Delete(systestfile1);
       
   158 	test(r==KErrNone);
       
   159 	}
       
   160 
       
   161 LOCAL_C void ResourceRFsTest()
       
   162 //
       
   163 //
       
   164 //
       
   165 	{
       
   166 	restestname=KResourcePath;
       
   167 	restestname[0]=(TText)('A' + gTheDriveNum);
       
   168 	
       
   169 	mkdirname.Zero();
       
   170 	mkdirname.Append(restestname);
       
   171 	mkdirname.Append(KMkDirSub);
       
   172 	r=TheFs.MkDirAll(mkdirname);	
       
   173 	test(r==KErrNone);
       
   174 
       
   175 	TheFs.RmDir(mkdirname);
       
   176 	test(r==KErrNone);
       
   177 
       
   178 	r=TheFs.SetSubst(restestname,EDriveO);
       
   179 	test(r==KErrPermissionDenied);
       
   180 	
       
   181 	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
       
   182 	test(r==KErrNone);
       
   183 
       
   184 	r=TheFs.SetSessionPath(restestname);
       
   185 	test(r==KErrNone);
       
   186 	
       
   187 	TheFs.NotifyChange(ENotifyAll,aStat4,restestname);
       
   188 	test(aStat4==KRequestPending);
       
   189 
       
   190 	restestfile=KResourcePath;
       
   191 	restestfile[0]=(TText)('A' + gTheDriveNum);
       
   192 	restestfile1=restestfile;
       
   193 	restestfile.Append(KFileRes);
       
   194 	restestfile1.Append(KFileRes3);
       
   195 	
       
   196 	oldName=KOldFile;
       
   197 	oldName[0]=(TText)gDriveToTest;
       
   198 
       
   199 	r=TheFs.GetShortName(restestfile, shortfilename);
       
   200 	test(r==KErrNone || KErrNotFound || r==KErrNotSupported);
       
   201 
       
   202 	r=TheFs.GetLongName(restestfile1, longfilename);
       
   203 	test(r==KErrNone || KErrNotFound || r==KErrNotSupported);
       
   204 
       
   205 	r=file1.Create(TheFs,oldName,EFileWrite);
       
   206 	test(r==KErrNone || r==KErrAlreadyExists);
       
   207 	file1.Close();
       
   208 
       
   209 	r=TheFs.Replace(oldName,restestfile);
       
   210 	test(r==KErrNone);
       
   211 	
       
   212 	r=TheFs.Rename(restestfile,restestfile1);
       
   213 	test(r==KErrNone);
       
   214 	
       
   215 	r=TheFs.Entry(restestfile1,entry);
       
   216 	test(r==KErrNone);
       
   217 
       
   218 	r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
       
   219 	test(r==KErrNone);
       
   220 
       
   221 	r=TheFs.Delete(restestfile1);
       
   222 	test(r==KErrNone);
       
   223 
       
   224 	}
       
   225 
       
   226 
       
   227 LOCAL_C void privatefalseIDRFsTest()
       
   228 //
       
   229 //
       
   230 //
       
   231 	{
       
   232 	pritestfalseidname=KPrivateFalseID;
       
   233 	pritestfalseidname[0]=(TText)('A' + gTheDriveNum);
       
   234 	
       
   235 	mkdirname.Zero();
       
   236 	mkdirname.Append(pritestfalseidname);
       
   237 	mkdirname.Append(KMkDirSub);
       
   238 
       
   239 	r=TheFs.MkDirAll(mkdirname);	
       
   240 	test(r==KErrNone);
       
   241 
       
   242 	r=TheFs.RmDir(mkdirname);	
       
   243 	test(r==KErrNone);
       
   244 
       
   245 	r=TheFs.SetSubst(pritestfalseidname,EDriveO);
       
   246 	test(r==KErrPermissionDenied);
       
   247 
       
   248 	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
       
   249 	test(r==KErrNone);
       
   250 
       
   251 	r=TheFs.SetSessionPath(pritestfalseidname);
       
   252 	test(r==KErrNone);
       
   253 
       
   254 	TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname);
       
   255 	test(aStat2==KRequestPending);
       
   256 
       
   257 
       
   258 	pritestfile=KPrivateFalseID;
       
   259 	pritestfile[0]=(TText)('A' + gTheDriveNum);
       
   260 	pritestfile1=pritestfile;
       
   261 	pritestfile.Append(KFilePri2);
       
   262 	pritestfile1.Append(KFilePri3);
       
   263 	
       
   264 	oldName=KOldFile;
       
   265 	oldName[0]=(TText)gDriveToTest;
       
   266 
       
   267 	r=TheFs.GetShortName(pritestfile, shortfilename);
       
   268 	test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
       
   269 
       
   270 	r=TheFs.GetLongName(pritestfile1, longfilename);
       
   271 	test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
       
   272 
       
   273 	r=file1.Create(TheFs,oldName,EFileWrite);
       
   274 	test(r==KErrNone || r==KErrAlreadyExists);
       
   275 	file1.Close();
       
   276 
       
   277 	r=TheFs.Replace(oldName,pritestfile);
       
   278 	test(r==KErrNone);
       
   279 	
       
   280 	r=TheFs.Rename(pritestfile,pritestfile1);
       
   281 	test(r==KErrNone);
       
   282 	
       
   283 	r=TheFs.Entry(pritestfile1,entry);
       
   284 	test(r==KErrNone);
       
   285 
       
   286 	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
       
   287 	test(r==KErrNone);
       
   288 
       
   289 	r=TheFs.Delete(pritestfile1);
       
   290 	test(r==KErrNone);
       
   291 
       
   292 	}
       
   293 
       
   294 
       
   295 LOCAL_C void privateRFsTest()
       
   296 //
       
   297 //
       
   298 //
       
   299 	{
       
   300 	//private
       
   301 	pritestname=KPrivatePath;
       
   302 	pritestname[0]=(TText)('A' + gTheDriveNum);
       
   303 	
       
   304 	mkdirname.Zero();
       
   305 	mkdirname.Append(pritestname);
       
   306 	mkdirname.Append(KMkDirSub);
       
   307 
       
   308 	r=TheFs.MkDirAll(mkdirname);	
       
   309 	test(r==KErrNone);
       
   310 
       
   311 	r=TheFs.RmDir(mkdirname);	
       
   312 	test(r==KErrNone);
       
   313 
       
   314 	r=TheFs.SetSubst(pritestname,EDriveO);
       
   315 	test(r==KErrPermissionDenied);
       
   316 
       
   317 	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
       
   318 	test(r==KErrNone);
       
   319 
       
   320 	r=TheFs.SetSessionPath(pritestname);
       
   321 	test(r==KErrNone);
       
   322 
       
   323 	TheFs.NotifyChange(ENotifyAll,aStat2,pritestname);
       
   324 	test(aStat2==KRequestPending);
       
   325 
       
   326 
       
   327 	pritestfile=KPrivatePath;
       
   328 	pritestfile[0]=(TText)('A' + gTheDriveNum);
       
   329 	pritestfile1=pritestfile;
       
   330 	pritestfile.Append(KFilePri2);
       
   331 	pritestfile1.Append(KFilePri3);
       
   332 	
       
   333 	oldName=KOldFile;
       
   334 	oldName[0]=(TText)gDriveToTest;
       
   335 
       
   336 	r=TheFs.GetShortName(pritestfile, shortfilename);
       
   337 	test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
       
   338 
       
   339 	r=TheFs.GetLongName(pritestfile1, longfilename);
       
   340 	test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
       
   341 
       
   342 	r=file1.Create(TheFs,oldName,EFileWrite);
       
   343 	test(r==KErrNone || r==KErrAlreadyExists);
       
   344 	file1.Close();
       
   345 
       
   346 	r=TheFs.Replace(oldName,pritestfile);
       
   347 	test(r==KErrNone);
       
   348 	
       
   349 	r=TheFs.Rename(pritestfile,pritestfile1);
       
   350 	test(r==KErrNone);
       
   351 	
       
   352 	r=TheFs.Entry(pritestfile1,entry);
       
   353 	test(r==KErrNone);
       
   354 
       
   355 	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
       
   356 	test(r==KErrNone);
       
   357 
       
   358 	r=TheFs.Delete(pritestfile1);
       
   359 	test(r==KErrNone);
       
   360 
       
   361 	}
       
   362 
       
   363 
       
   364 LOCAL_C void privateSIDRFstest()
       
   365 	{
       
   366 	theprivatepath[0]=(TText)gDriveToTest;	
       
   367 	test.Printf(_L("the Private Path = %S"),&theprivatepath);
       
   368 
       
   369 	mkdirname.Zero();
       
   370 	mkdirname.Append(theprivatepath);
       
   371 	mkdirname.Append(KMkDirSub);
       
   372 	r=TheFs.MkDirAll(mkdirname);	
       
   373 	test(r==KErrNone);
       
   374 
       
   375 	r=TheFs.RmDir(mkdirname);	
       
   376 	test(r==KErrNone);
       
   377 
       
   378 	r=TheFs.SetSubst(theprivatepath,EDriveO);	
       
   379 	test(r==KErrPermissionDenied);
       
   380 
       
   381 	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
       
   382 	test(r==KErrNone);
       
   383 
       
   384 	r=TheFs.SetSessionPath(theprivatepath);
       
   385 	test(r==KErrNone);
       
   386 
       
   387 	TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath);
       
   388 	test(aStat3==KRequestPending);
       
   389 
       
   390 	pritestfile=theprivatepath;
       
   391 	pritestfile[0]=(TText)('A' + gTheDriveNum);
       
   392 	pritestfile1=pritestfile;
       
   393 	pritestfile.Append(KFilePri2);
       
   394 	pritestfile1.Append(KFilePri3);
       
   395 	
       
   396 	oldName=KOldFile;
       
   397 	oldName[0]=(TText)gDriveToTest;
       
   398 
       
   399 	r=TheFs.GetShortName(pritestfile, shortfilename);
       
   400 	test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
       
   401 
       
   402 	r=TheFs.GetLongName(pritestfile1, longfilename);
       
   403 	test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
       
   404 
       
   405 	r=file1.Create(TheFs,oldName,EFileWrite);
       
   406 	test(r==KErrNone || r==KErrAlreadyExists);
       
   407 	file1.Close();
       
   408 
       
   409 	r=TheFs.Replace(oldName,pritestfile);
       
   410 	test(r==KErrNone);
       
   411 	
       
   412 	r=TheFs.Rename(pritestfile,pritestfile1);
       
   413 	test(r==KErrNone || r==KErrAlreadyExists);
       
   414 	
       
   415 	r=TheFs.Entry(pritestfile1,entry);
       
   416 	test(r==KErrNone);
       
   417 
       
   418 	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
       
   419 	test(r==KErrNone);
       
   420 
       
   421 	r=TheFs.Delete(pritestfile1);
       
   422 	test(r==KErrNone);
       
   423 	}
       
   424 
       
   425 
       
   426 LOCAL_C void systemRFiletest()
       
   427 //
       
   428 //RFile testing with session path set to //system//
       
   429 //
       
   430 	{
       
   431 
       
   432 	r=TheFs.SetSessionPath(systestname);
       
   433 	test(r==KErrNone);
       
   434 
       
   435 	r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite);
       
   436 	test(r==KErrNone);
       
   437 	file1.Close();
       
   438 
       
   439 	r=file1.Create(TheFs,KFileSys,EFileWrite);
       
   440 	test(r==KErrNone);
       
   441 	file1.Close();
       
   442 
       
   443 	r=file1.Open(TheFs,KFileSys,EFileWrite);
       
   444 	test(r==KErrNone);
       
   445 	file1.Close();
       
   446 	
       
   447 	r=file1.Open(TheFs,KFileSys,EFileRead);
       
   448 	test(r==KErrNone);
       
   449 	file1.Close();
       
   450 
       
   451 	r=file1.Replace(TheFs,KFileSys,EFileWrite);
       
   452 	test(r==KErrNone);
       
   453 	
       
   454 	r=file1.Rename(KFileSys3);
       
   455 	test(r==KErrNone);
       
   456 	file1.Close();
       
   457 
       
   458     TFindFile finder(TheFs);
       
   459     CDir* dir = NULL;
       
   460     r=finder.FindWildByDir(KWildFile, KWildPath, dir);
       
   461 	if (!(r==KErrNone))
       
   462         test.Printf(_L("T_DCTCBALLFILES: test find wildcards r = %d (expected KErrNone)\n"), r);
       
   463 	test(r==KErrNone);
       
   464 	delete dir;
       
   465 	}
       
   466 
       
   467 LOCAL_C void resourceRFiletest()
       
   468 //
       
   469 //RFile testing with session path set to //resource//
       
   470 //
       
   471 	{
       
   472 	r=TheFs.SetSessionPath(restestname);
       
   473 	test(r==KErrNone);
       
   474 
       
   475 	r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite);
       
   476 	test(r==KErrNone);
       
   477 	file1.Close();
       
   478 
       
   479 	r=file1.Create(TheFs,KFileRes,EFileWrite);
       
   480 	test(r==KErrNone);
       
   481 	file1.Close();
       
   482 
       
   483 	r=file1.Open(TheFs,KFileRes,EFileWrite|EFileShareExclusive );
       
   484 	test(r==KErrNone);
       
   485 	
       
   486 	r=file1.Rename(KFileRes3);
       
   487 	test(r==KErrNone);
       
   488 	file1.Close();
       
   489 
       
   490 	r=file1.Open(TheFs,KFileRes3,EFileShareReadersOrWriters|EFileRead);
       
   491 	test(r==KErrNone);
       
   492 	file1.Close();
       
   493 
       
   494 	r=file1.Open(TheFs,KFileRes3,EFileShareReadersOrWriters|EFileWrite);
       
   495 	test(r==KErrNone);
       
   496 	file1.Close();
       
   497 
       
   498 	r=file1.Open(TheFs,KFileRes3,EFileShareReadersOnly);
       
   499 	test(r==KErrNone);
       
   500 
       
   501 	r=file1.ChangeMode(EFileShareExclusive);
       
   502 	test(r==KErrNone);
       
   503 	file1.Close();
       
   504 
       
   505 	r=file1.Replace(TheFs,KFileRes,EFileWrite);
       
   506 	test(r==KErrNone);
       
   507 	file1.Close();	
       
   508 	}
       
   509 
       
   510 
       
   511 LOCAL_C void privateRFiletest()
       
   512 //
       
   513 //RFile testing with session path set to //Private//
       
   514 //
       
   515 	{
       
   516 	r=TheFs.SetSessionPath(pritestfalseidname);
       
   517 	test(r==KErrNone);
       
   518 
       
   519 	r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite);
       
   520 	test(r==KErrNone);
       
   521 	file1.Close();
       
   522 
       
   523 	r=file1.Create(TheFs,KFilePri,EFileWrite);
       
   524 	test(r==KErrNone);
       
   525 	file1.Close();
       
   526 
       
   527 	r=file1.Open(TheFs,KFilePri,EFileWrite);
       
   528 	test(r==KErrNone);
       
   529 	file1.Close();
       
   530 	
       
   531 	r=file1.Open(TheFs,KFilePri,EFileRead);
       
   532 	test(r==KErrNone);
       
   533 	file1.Close();
       
   534 	
       
   535 	r=file1.Replace(TheFs,KFilePri,EFileWrite);
       
   536 	test(r==KErrNone);
       
   537 	
       
   538 	r=file1.Rename(KFilePri3);
       
   539 	test(r==KErrNone);
       
   540 	file1.Close();
       
   541 	}
       
   542 
       
   543 
       
   544 LOCAL_C void privatefalseIDRFiletest()
       
   545 //
       
   546 //RFile testing with session path set to //Private//
       
   547 //
       
   548 	{
       
   549 	r=TheFs.SetSessionPath(pritestname);
       
   550 	test(r==KErrNone);
       
   551 
       
   552 	r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite);
       
   553 	test(r==KErrNone);
       
   554 	file1.Close();
       
   555 
       
   556 	r=file1.Create(TheFs,KFilePri,EFileWrite);
       
   557 	test(r==KErrNone);
       
   558 	file1.Close();
       
   559 
       
   560 	r=file1.Open(TheFs,KFilePri,EFileWrite);
       
   561 	test(r==KErrNone);
       
   562 	file1.Close();
       
   563 	
       
   564 	r=file1.Open(TheFs,KFilePri,EFileRead);
       
   565 	test(r==KErrNone);
       
   566 	file1.Close();
       
   567 	
       
   568 	r=file1.Replace(TheFs,KFilePri,EFileWrite);
       
   569 	test(r==KErrNone);
       
   570 	
       
   571 	r=file1.Rename(KFilePri3);
       
   572 	test(r==KErrNone);
       
   573 	file1.Close();
       
   574 	}
       
   575 
       
   576 
       
   577 LOCAL_C void privateSIDRFiletest()
       
   578 //
       
   579 //Rfile Testing with session path set to //Private//UID//
       
   580 //
       
   581 	{
       
   582 	r=TheFs.SetSessionToPrivate(gTheDriveNum);
       
   583 	test(r==KErrNone);
       
   584 	
       
   585 	r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite);
       
   586 	test(r==KErrNone);
       
   587 	file1.Close();
       
   588 
       
   589 	r=file1.Create(TheFs,KFilePri,EFileWrite);
       
   590 	test(r==KErrNone);
       
   591 	file1.Close();
       
   592 
       
   593 	r=file1.Open(TheFs,KFilePri,EFileWrite);
       
   594 	test(r==KErrNone);
       
   595 	file1.Close();
       
   596 	
       
   597 	r=file1.Open(TheFs,KFilePri,EFileRead);
       
   598 	test(r==KErrNone);
       
   599 	file1.Close();
       
   600 	
       
   601 	r=file1.Replace(TheFs,KFilePri,EFileWrite);
       
   602 	test(r==KErrNone);
       
   603 	
       
   604 	r=file1.Rename(KFilePri3);
       
   605 	test(r==KErrNone);
       
   606 	file1.Close();
       
   607 	}
       
   608 
       
   609 LOCAL_C void RDirtest()
       
   610 //
       
   611 //
       
   612 //
       
   613 	{
       
   614 
       
   615 	//system
       
   616 	CDir*	dirEntries;
       
   617 	TBuf<30> dirNameBuf(KSystemPath);
       
   618 	dirNameBuf[0]=(TText)gDriveToTest;
       
   619 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
       
   620 	test(r==KErrNone);
       
   621 	dir.Close();
       
   622 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
       
   623 	test(r==KErrNone);
       
   624 	dirNameBuf.Zero();
       
   625 	delete dirEntries;
       
   626 
       
   627 	//Private
       
   628 	dirNameBuf=KPrivatePath;
       
   629 	dirNameBuf[0]=(TText)gDriveToTest;
       
   630 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
       
   631 	test(r==KErrNone);
       
   632 	dir.Close();
       
   633 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
       
   634 	test(r==KErrNone);
       
   635 	dirNameBuf.Zero();
       
   636 	delete dirEntries;
       
   637 
       
   638 	//Private//false ID
       
   639 	dirNameBuf=KPrivateFalseID;
       
   640 	dirNameBuf[0]=(TText)gDriveToTest;
       
   641 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
       
   642 	test(r==KErrNone);
       
   643 	dir.Close();
       
   644 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
       
   645 	test(r==KErrNone);
       
   646 	dirNameBuf.Zero();
       
   647 	delete dirEntries;
       
   648 
       
   649 	//Private/uid
       
   650 	TheFs.PrivatePath(dirNameBuf);
       
   651 	dirNameBuf.Insert(0,_L("?:"));
       
   652 	dirNameBuf[0]=(TText)gDriveToTest;
       
   653 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
       
   654 	test(r==KErrNone);
       
   655 	dir.Close();
       
   656 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
       
   657 	test(r==KErrNone);
       
   658 	dirNameBuf.Zero();
       
   659 	delete dirEntries;
       
   660 	//Resource
       
   661 	dirNameBuf=KResourcePath;
       
   662 	dirNameBuf[0]=(TText)gDriveToTest;
       
   663 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
       
   664 	test(r==KErrNone);
       
   665 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
       
   666 	test(r==KErrNone);
       
   667 	dir.Close();
       
   668 	delete dirEntries;
       
   669 	}
       
   670 
       
   671 
       
   672 LOCAL_C void TestTcbAllfiles()
       
   673 //
       
   674 //	Test with tcb capabilities
       
   675 //
       
   676 	{
       
   677 	r=TheFs.FileSystemName(fsname,gTheDriveNum);
       
   678 	test(r==KErrNone);
       
   679 	r = DismountFileSystem(TheFs, fsname, gTheDriveNum);
       
   680 	test(r==KErrPermissionDenied);
       
   681 //	r=TheFs.RemoveFileSystem(fsname);	//can not test due to bug else where fix exists
       
   682 //	test(r==KErrNone);
       
   683 //	r=TheFs.AddFileSystem(fsname);
       
   684 //	test(r==KErrNone);
       
   685 	r = MountFileSystem(TheFs, fsname, gTheDriveNum);
       
   686 	test(r==KErrPermissionDenied);
       
   687 	test.Printf(_L("r=%d"),r);
       
   688 	r=TheFs.SetDriveName(gTheDriveNum,KDriveName);
       
   689 	test(r==KErrPermissionDenied);
       
   690 #ifndef __WINS__
       
   691  	r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum);
       
   692 	test(r==KErrPermissionDenied);
       
   693 #endif
       
   694 
       
   695 	systemRFsTest();
       
   696 	ResourceRFsTest();
       
   697 	privateRFsTest();	
       
   698 	privateSIDRFstest();
       
   699 	privatefalseIDRFsTest();
       
   700 
       
   701 	systemRFiletest();
       
   702 	resourceRFiletest();
       
   703 	privateRFiletest();
       
   704 	privateSIDRFiletest();
       
   705 	privatefalseIDRFiletest();
       
   706 
       
   707 	//check notifier return values set in rfs testing
       
   708 	User::WaitForRequest(aStat1);
       
   709 	User::WaitForRequest(aStat2);
       
   710 	User::WaitForRequest(aStat3);
       
   711 	User::WaitForRequest(aStat4);
       
   712 	test(aStat1==KErrNone);
       
   713 	test(aStat2==KErrNone);
       
   714 	test(aStat3==KErrNone);
       
   715 	test(aStat4==KErrNone);
       
   716 
       
   717 	r=TheFs.SetSessionPath(systestname);
       
   718 	test(r==KErrNone);
       
   719 	
       
   720 //Test RRawDisk class
       
   721 	r=rawdisk.Open(TheFs,gTheDriveNum);
       
   722 	test(r==KErrNone);
       
   723 	rawdisk.Close();
       
   724 
       
   725 	RDirtest();
       
   726 
       
   727 #ifdef __WINS__
       
   728 	if (User::UpperCase(driveBuf[0]) != 'C')
       
   729 #endif
       
   730 		{
       
   731 		//Test RFormat class
       
   732 		r=format.Open(TheFs,driveBuf,EHighDensity,count);
       
   733 		test(r==KErrPermissionDenied);
       
   734 
       
   735 		while(count)	
       
   736 			{
       
   737 			TInt r=format.Next(count);
       
   738 			test(r==KErrNone);
       
   739 			}
       
   740 		format.Close();
       
   741 		}
       
   742 
       
   743 	driveBuf[0]=(TText)gDriveToTest;
       
   744 	r=TheFs.ScanDrive(driveBuf);
       
   745 	RDebug::Print(_L("r=%d"),r);
       
   746 	test(r==KErrPermissionDenied);
       
   747 	r=TheFs.CheckDisk(driveBuf);
       
   748 	test(r==KErrPermissionDenied);
       
   749 	}
       
   750 
       
   751 LOCAL_C void TestCaps()
       
   752 //
       
   753 //	test format etc that require certain capabilities
       
   754 //
       
   755 	{
       
   756 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
       
   757 	const char myDiagMsg[] = "Capability Check Failure";
       
   758 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
       
   759 	r=RProcess().HasCapability(ECapabilityTCB, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
       
   760 	test(r);
       
   761 	r=RProcess().HasCapability(ECapabilityAllFiles, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
       
   762 	test(r);
       
   763 	
       
   764 	driveBuf[0]=(TText)gDriveToTest;
       
   765 	r=TheFs.SessionPath(temp);
       
   766 	test(r==KErrNone);
       
   767 
       
   768 	test.Printf(_L("Session path: %S"),&temp);
       
   769 
       
   770 	r=TheFs.CreatePrivatePath(gTheDriveNum);
       
   771 	test(r==KErrNone || r== KErrAlreadyExists);
       
   772 
       
   773 	TBuf<18> tempPri;
       
   774 	r=TheFs.PrivatePath(tempPri);
       
   775 	test(r==KErrNone);
       
   776 	theprivatepath = _L("?:");
       
   777 	theprivatepath.Append(tempPri);
       
   778 
       
   779 	TestTcbAllfiles();
       
   780 	
       
   781 	TFileName thesessionpath;
       
   782 	r=TheFs.SetSessionToPrivate(gTheDriveNum);
       
   783 	test(r==KErrNone);
       
   784 	r=TheFs.SessionPath(thesessionpath);
       
   785 	test(r==KErrNone);
       
   786 
       
   787 	test(thesessionpath == theprivatepath);
       
   788 	}
       
   789 
       
   790 
       
   791 TFileName dirName;
       
   792 
       
   793 LOCAL_C void ScanDir(const TDesC& aName, CDirScan::TScanDirection aDirection, TInt aError)
       
   794 	{
       
   795 	CDirScan* scanner = NULL;
       
   796 	TRAP(r, scanner = CDirScan::NewL(TheFs));
       
   797 	test(r == KErrNone && scanner);
       
   798 
       
   799 	TRAP(r, scanner->SetScanDataL(aName,KEntryAttDir,ESortByName|EAscending,aDirection));
       
   800 	test(r == KErrNone);
       
   801 
       
   802 	CDir *entryList=NULL;
       
   803 	for (;;)
       
   804 		{
       
   805 		TRAP(r, scanner->NextL(entryList));
       
   806 		test(r == aError);
       
   807 		if (entryList==NULL)
       
   808 			break;
       
   809 
       
   810         TInt count=entryList->Count();
       
   811 
       
   812         while (count--)
       
   813 			{
       
   814 			TEntry data=(*entryList)[count];
       
   815 			TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
       
   816 			
       
   817 			dirName = path;
       
   818 			dirName.Append(data.iName);
       
   819 			test.Printf(_L("    %S\n"),&dirName);
       
   820 			
       
   821 			}
       
   822 		delete entryList;
       
   823 		entryList=NULL;
       
   824 		}
       
   825 	delete scanner;
       
   826 
       
   827 	}
       
   828 
       
   829 /**
       
   830 The following test, tests CFileMan and CDirScan API on folders private and sys
       
   831 to confirm that any operation on these folders for any app with incorrect capability
       
   832 returns KErrPermissionDenied. This test step was added as a result of DEF051428
       
   833 ("PlatSec: Incorrect errors returned by f32")
       
   834 */
       
   835 LOCAL_C void TestCaging()
       
   836 	{
       
   837 	CFileMan* fMan=CFileMan::NewL(TheFs);
       
   838 	TInt r;
       
   839 	if(fMan!=NULL)
       
   840 		{		
       
   841 		
       
   842 		// Checking the private path
       
   843 		TBuf<30> privatepath;
       
   844 		r=TheFs.PrivatePath(privatepath);
       
   845 		test.Printf(_L("Private Path is=%S"),&privatepath);
       
   846 		
       
   847 		r = TheFs.MkDir(_L("\\Caged\\"));
       
   848 		test(r==KErrNone || r==KErrAlreadyExists);
       
   849 		
       
   850 		CDir* entryCount=NULL;
       
   851 		r=TheFs.GetDir(_L("\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount);
       
   852 		test(r==KErrNone);
       
   853 		
       
   854 		delete entryCount;
       
   855 		entryCount=NULL;
       
   856 
       
   857 
       
   858 		//Testing Copy
       
   859 		CDir* entryCount2=NULL;
       
   860 		r=fMan->Copy(_L("\\sys\\"),_L("\\Caged\\"));
       
   861 		test(r == KErrNone);
       
   862 		r=fMan->Copy(_L("\\*"),_L("\\Caged\\"));
       
   863 		test(r == KErrNone);
       
   864 		
       
   865 		r=TheFs.GetDir(_L("\\Caged\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount2);
       
   866 		test(r==KErrNone);
       
   867 		
       
   868 		delete entryCount2;
       
   869 		entryCount2=NULL;
       
   870 	
       
   871 		r=fMan->Copy(_L("\\private\\two\\moo"),_L("\\private\\two\\mew")); 
       
   872 		test(r == KErrPathNotFound);
       
   873 	
       
   874 		// Create a test file
       
   875 		RFile testFile;
       
   876 		r = testFile.Replace(TheFs, _L("\\capTest"),EFileWrite);
       
   877 		test(r==KErrNone || r==KErrAlreadyExists);
       
   878 		testFile.Close();
       
   879 		
       
   880 		TFileName name;
       
   881 		name = privatepath;
       
   882 		name.Append(_L("privateFile.tst"));
       
   883 		RFile privateFile;
       
   884 		r = privateFile.Replace(TheFs, name,EFileWrite);
       
   885 		test(r==KErrNone || r==KErrAlreadyExists);
       
   886 		privateFile.Close();
       
   887 
       
   888 	
       
   889 		r=fMan->Copy(_L("\\capTest"),_L("\\private\\two\\moo")); 
       
   890 		test(r == KErrPathNotFound);
       
   891 		r=fMan->Copy(_L("\\capTest"),_L("\\sys\\bin\\moo")); 
       
   892 		test(r == KErrPathNotFound); 
       
   893 		r=fMan->Copy(_L("\\sys\\bin\\capTest"),_L("\\sys\\bin\\moo")); 
       
   894 		test(r == KErrPathNotFound);
       
   895 		r=fMan->Copy(_L("\\capTest"),_L("\\sys\\capTest")); 
       
   896 		test(r == KErrNone || r==KErrAlreadyExists); 
       
   897 		r=fMan->Copy(_L("\\sys\\*"),_L("\\"));
       
   898 		test (r==KErrNone);
       
   899 		r=fMan->Copy(name,_L("\\sys\\"));
       
   900 		test(r==KErrNone);
       
   901 
       
   902 		// Testing Attribs
       
   903 		r=fMan->Attribs(_L("\\private\\two\\moo"),KEntryAttReadOnly,0,TTime(0)); 
       
   904 		test(r == KErrPathNotFound);
       
   905 		r=fMan->Attribs(_L("\\private\\moo"),KEntryAttReadOnly,0,TTime(0)); 
       
   906 		test(r == KErrNotFound);
       
   907 		r=fMan->Attribs(name,KEntryAttReadOnly,0,TTime(0));
       
   908 		test(r == KErrNone);
       
   909 		r=fMan->Attribs(name,0,KEntryAttReadOnly,TTime(0));
       
   910 		test(r == KErrNone);
       
   911 
       
   912 		// Testing Move
       
   913 		r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo"));
       
   914 		test(r == KErrPathNotFound);
       
   915 		r=fMan->Move(_L("\\private\\two\\moo.."),_L("\\private\\one\\moo"));
       
   916 		test(r == KErrPathNotFound);
       
   917 		r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo.."));
       
   918 		test(r == KErrPathNotFound);
       
   919 		r=fMan->Move(name,_L("\\privateFile.tst"));
       
   920 		test(r == KErrNone);
       
   921 		r=fMan->Move(_L("\\privateFile.tst"),name);
       
   922 		test(r == KErrNone);
       
   923 
       
   924 
       
   925 		// Testing RmDir
       
   926 		r=fMan->RmDir(_L("\\private\\"));
       
   927 		test(r == KErrNone);
       
   928 		// put it back where it was
       
   929 		r = TheFs.MkDirAll(_L("\\private\\00000001\\"));
       
   930 		test(r == KErrNone);
       
   931 		r=fMan->RmDir(_L("\\private\\two\\"));
       
   932 		test(r == KErrPathNotFound);
       
   933 		r=fMan->RmDir(_L("\\private\\tw?\\"));
       
   934 		test(r == KErrBadName);
       
   935 
       
   936 		r=fMan->RmDir(_L("\\private\\two\\"));
       
   937 		test(r == KErrPathNotFound);
       
   938 		r=fMan->RmDir(_L("\\private\\tw?\\"));
       
   939 		test(r == KErrBadName);
       
   940 		
       
   941 		
       
   942 		// Testing Rename
       
   943 		r=fMan->Rename(_L("\\private\\two\\moo"),_L("\\private\\two\\mew")); 
       
   944 		test(r == KErrPathNotFound);
       
   945 		
       
   946 		// Testing Delete
       
   947 		r=fMan->Delete(_L("\\private\\two\\test")); 
       
   948 		test(r == KErrPathNotFound);
       
   949 		r=fMan->Delete(_L("\\private\\moo")); 
       
   950 		test(r == KErrNotFound);
       
   951 		
       
   952 		//Something that actually exists in Private
       
   953 		r=fMan->Rename(name,_L("\\private\\00000001\\moo")); 
       
   954 		test(r == KErrNotFound);
       
   955 		r=fMan->Rename(_L("\\private\\00000001\\moo"),name); 
       
   956 		test(r == KErrNotFound);
       
   957 		r=fMan->Copy(name,_L("\\private\\00000001\\moo")); 
       
   958 		test(r == KErrNotFound);
       
   959 		r=fMan->Delete(_L("\\private\\00000001\\moo")); 
       
   960 		test(r == KErrNotFound);
       
   961 
       
   962 		// Clean up the test data
       
   963 		r=fMan->RmDir(_L("\\Caged\\")); 
       
   964 		test(r == KErrNone);
       
   965 		r=fMan->Delete(_L("\\capTest")); 
       
   966 		test(r == KErrNone);
       
   967 		delete(fMan);
       
   968 		}
       
   969 	
       
   970 	// CDirScan tests
       
   971 	ScanDir(_L("\\"), CDirScan::EScanUpTree, KErrNone);
       
   972 	ScanDir(_L("\\"), CDirScan::EScanDownTree, KErrNone);
       
   973 	ScanDir(_L("\\private\\"), CDirScan::EScanDownTree, KErrNone);
       
   974 	ScanDir(_L("\\private\\"), CDirScan::EScanUpTree, KErrNone);
       
   975 	ScanDir(_L("\\sys\\"), CDirScan::EScanDownTree, KErrNone);
       
   976 	ScanDir(_L("\\sys\\"), CDirScan::EScanUpTree, KErrNone);
       
   977 	}
       
   978 
       
   979 LOCAL_C void CleanupL()
       
   980 //
       
   981 // Clean up tests
       
   982 //
       
   983 	{
       
   984 	test.Next(_L("Delete test directory"));
       
   985 	CFileMan* fMan=CFileMan::NewL(TheFs);
       
   986 	TInt r=fMan->RmDir(gSessionPath);
       
   987 	test(r==KErrNone || KErrPathNotFound);
       
   988 	delete fMan;
       
   989 	}
       
   990 
       
   991 GLDEF_C void CallTestsL(/*TChar aDriveLetter*/)
       
   992 //
       
   993 // Do all tests
       
   994 //
       
   995 	{
       
   996 	if( !PlatSec::IsCapabilityEnforced(ECapabilityTCB) || 
       
   997 		!PlatSec::IsCapabilityEnforced(ECapabilityAllFiles))
       
   998 		{
       
   999 		test.Printf(_L("Insufficient capabilities enabled - leaving t_dctcballfiles"));
       
  1000 		test.Printf(_L("\n")); // Prevent overwrite by next print
       
  1001 		return;
       
  1002 		}
       
  1003 	TurnAllocFailureOff();
       
  1004 	TheFs.CharToDrive(gDriveToTest,gTheDriveNum);
       
  1005 	
       
  1006 	TBuf<30> sesspath;
       
  1007 	sesspath=_L("?:\\");
       
  1008 	sesspath[0] = (TText)gDriveToTest;
       
  1009 
       
  1010 	TInt r= TheFs.SetSessionPath(sesspath);
       
  1011 	test(r==KErrNone);
       
  1012 
       
  1013 	//cleanup from previous run of this test
       
  1014 	TBuf<20> delDir;
       
  1015 	CFileMan* fMan=CFileMan::NewL(TheFs);
       
  1016 	delDir=KResourcePath;
       
  1017 	delDir[0]=(TText)gDriveToTest;
       
  1018 	r=fMan->RmDir(delDir);
       
  1019 	test(r==KErrNone || KErrNotFound);
       
  1020 	delDir=KSystemPath;
       
  1021 	delDir[0]=(TText)gDriveToTest;
       
  1022 	r=fMan->RmDir(delDir);
       
  1023 	test(r==KErrNone || KErrNotFound);
       
  1024 	delDir=KPrivatePath;
       
  1025 	delDir[0]=(TText)gDriveToTest;
       
  1026 	r=fMan->RmDir(delDir);
       
  1027 	test(r==KErrNone || KErrNotFound);
       
  1028 	delete fMan;
       
  1029 
       
  1030 	//check double mode ie that Defpath still works	
       
  1031 	RFs fs1;
       
  1032 	RFs fs2;
       
  1033 	
       
  1034 	r=fs1.Connect();
       
  1035 	test(r==KErrNone);
       
  1036 	r=fs1.SessionPath(sesspath);
       
  1037 	test(r==KErrNone);
       
  1038 	test.Printf(_L("session1 Path=%S"),&sesspath);
       
  1039 
       
  1040 	TBuf<30> privatepath;
       
  1041 	r=fs1.SetSessionToPrivate(gTheDriveNum);
       
  1042 	test(r==KErrNone);
       
  1043 	r=fs1.PrivatePath(privatepath);
       
  1044 	test(r==KErrNone);
       
  1045 	r=privatepath.Compare(KExpectedPrivatePath());
       
  1046 	test(r==0);
       
  1047 	r=fs1.SessionPath(sesspath);
       
  1048 	test(r==KErrNone);
       
  1049 	r=privatepath.Compare(sesspath.Mid(KPathPosition));
       
  1050 	test(r==0);
       
  1051 	r=fs1.CreatePrivatePath(gTheDriveNum);
       
  1052 	test(r==KErrNone);
       
  1053 	fs1.Close();
       
  1054 
       
  1055 	r=fs2.Connect();
       
  1056 	test(r==KErrNone);
       
  1057 	r=fs2.SessionPath(sesspath);
       
  1058 	test(r==KErrNone);
       
  1059 	test.Printf(_L("session2 Path=%S"),&sesspath);
       
  1060 	fs2.Close();
       
  1061 
       
  1062 	TestCaps();
       
  1063 	TestCaging();
       
  1064 
       
  1065 	test.Printf(_L("No of files open=%d"), TheFs.ResourceCount());
       
  1066 
       
  1067 	CleanupL();
       
  1068 	}