os/kernelhwsrv/kerneltest/f32test/server/t_dctcbdiskadmin.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_dctcbdiskadmin.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,999 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <f32file.h>
    1.20 +#include <e32test.h>
    1.21 +#include <e32std.h>
    1.22 +#include <e32std_private.h>
    1.23 +#include <e32def.h>
    1.24 +#include <e32def_private.h>
    1.25 +#include <e32svr.h>
    1.26 +#include "t_server.h"
    1.27 +
    1.28 +GLDEF_D RTest test(_L("t_dctcbdiskadmin"));
    1.29 +GLDEF_D TTime gTimeNow;
    1.30 +LOCAL_D TInt gTheDriveNum;
    1.31 +
    1.32 +const TInt KPathPosition = 2;
    1.33 +_LIT(KExpectedPrivatePath, "\\Private\\00000001\\");
    1.34 +_LIT(KResourcePath, "?:\\Resource\\");
    1.35 +_LIT(KSystemPath,	"?:\\Sys\\");
    1.36 +_LIT(KPrivatePath,	"?:\\Private\\");
    1.37 +_LIT(KPrivateFalseID,	"?:\\Private\\FFFFFFFF\\");
    1.38 +_LIT(KDriveName,	"Billy");
    1.39 +_LIT(KVolLable,		"Benny");
    1.40 +_LIT(KFileSys,	"systemfile.txt");
    1.41 +_LIT(KFileSys3, "sysfile.rna");
    1.42 +_LIT(KFilePri,	"privatefile.txt");
    1.43 +_LIT(KFilePri2,	"privatefile.tmp");
    1.44 +_LIT(KFilePri3,	"prifile.rna");
    1.45 +_LIT(KFileRes,	"resourcefile.txt");
    1.46 +_LIT(KFileRes3,	"resfile.rna");
    1.47 +_LIT(KMkDirSub,"Subdir\\");
    1.48 +_LIT(KOldFile,"?:\\Anyold.txt");
    1.49 +_LIT(KWildPath, "Z:\\SYS\\");
    1.50 +_LIT(KWildFile, "*");
    1.51 +
    1.52 +TCapability TheCaps;
    1.53 +TBuf<4> driveBuf=_L("?:\\");
    1.54 +RFormat format;
    1.55 +TInt count;
    1.56 +RRawDisk rawdisk;
    1.57 +RFile file1;
    1.58 +RFile file2;
    1.59 +RDir	dir;
    1.60 +
    1.61 +TInt r;
    1.62 +TBuf<40> fsname;
    1.63 +TBuf<40> systestname;
    1.64 +TBuf<40> pritestname;
    1.65 +TBuf<40> restestname;
    1.66 +TBuf<40> theprivatepath;
    1.67 +TBuf<40> pritestfalseidname;
    1.68 +TBuf<40> mkdirname;
    1.69 +TFileName fromTemp;
    1.70 +
    1.71 +TBuf<25> sysfilename;
    1.72 +TBuf<30> realName;
    1.73 +TBuf<40> shortfilename;
    1.74 +TBuf<40> longfilename;
    1.75 +
    1.76 +TRequestStatus aStat1;
    1.77 +TRequestStatus aStat2;
    1.78 +TRequestStatus aStat3;
    1.79 +TRequestStatus aStat4;
    1.80 +
    1.81 +TVolumeInfo aVolInfo;
    1.82 +//	TDriveInfo adriveInfo;
    1.83 +
    1.84 +TBuf<40> systestfile;
    1.85 +TBuf<40> pritestfile;
    1.86 +TBuf<40> restestfile;
    1.87 +TBuf<40> systestfile1;
    1.88 +TBuf<40> pritestfile1;
    1.89 +TBuf<40> restestfile1;
    1.90 +
    1.91 +TTime testtime;
    1.92 +TBuf<20> oldName;
    1.93 +
    1.94 +TBuf<25> temp;
    1.95 +
    1.96 +TEntry entry;
    1.97 +
    1.98 +
    1.99 +LOCAL_C void privateFalseIDRFsTest()
   1.100 +//
   1.101 +//
   1.102 +//
   1.103 +	{
   1.104 +	__UHEAP_MARK;
   1.105 +
   1.106 +	//private and wrong UID
   1.107 +	pritestfalseidname=KPrivateFalseID;
   1.108 +	pritestfalseidname[0]=(TText)('A' + gTheDriveNum);
   1.109 +	
   1.110 +	mkdirname.Zero();
   1.111 +	mkdirname.Append(pritestfalseidname);
   1.112 +	mkdirname.Append(KMkDirSub);
   1.113 +
   1.114 +	r=TheFs.MkDirAll(mkdirname);	
   1.115 +	test(r==KErrPermissionDenied);
   1.116 +
   1.117 +	r=TheFs.RmDir(mkdirname);	
   1.118 +	test(r==KErrPermissionDenied);
   1.119 +
   1.120 +	r=TheFs.SetSubst(pritestfalseidname,EDriveO);
   1.121 +	test(r==KErrPermissionDenied);
   1.122 +
   1.123 +	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
   1.124 +	test(r==KErrNone);
   1.125 +
   1.126 +	r=TheFs.SetSessionPath(pritestfalseidname);
   1.127 +	test(r==KErrPermissionDenied);
   1.128 +
   1.129 +	TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname);
   1.130 +	test(aStat2==KErrPermissionDenied);
   1.131 +
   1.132 +
   1.133 +	pritestfile=KPrivateFalseID;
   1.134 +	pritestfile[0]=(TText)('A' + gTheDriveNum);
   1.135 +	pritestfile1=pritestfile;
   1.136 +	pritestfile.Append(KFilePri2);
   1.137 +	pritestfile1.Append(KFilePri3);
   1.138 +	
   1.139 +	oldName=KOldFile;
   1.140 +	oldName[0]=(TText)gDriveToTest;
   1.141 +
   1.142 +	r=TheFs.GetShortName(pritestfile, shortfilename);
   1.143 +	test(r==KErrPermissionDenied || r==KErrNotSupported);
   1.144 +
   1.145 +	r=TheFs.GetLongName(pritestfile1, longfilename);
   1.146 +	test(r==KErrPermissionDenied || r==KErrNotSupported);
   1.147 +
   1.148 +	r=file1.Create(TheFs,oldName,EFileWrite);
   1.149 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.150 +	file1.Close();
   1.151 +
   1.152 +	r=TheFs.Replace(oldName,pritestfile);
   1.153 +	test(r==KErrPermissionDenied);
   1.154 +	
   1.155 +	r=TheFs.Rename(pritestfile,pritestfile1);
   1.156 +	test(r==KErrPermissionDenied);
   1.157 +	
   1.158 +	r=TheFs.Entry(pritestfile1,entry);
   1.159 +	test(r==KErrPermissionDenied);
   1.160 +
   1.161 +	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   1.162 +	test(r==KErrPermissionDenied);
   1.163 +
   1.164 +	r=TheFs.Delete(pritestfile1);
   1.165 +	test(r==KErrPermissionDenied);
   1.166 +
   1.167 +	r=TheFs.Delete(oldName);
   1.168 +	test(r==KErrNone);
   1.169 +
   1.170 +	__UHEAP_MARKEND;
   1.171 +	}
   1.172 +LOCAL_C void systemRFsTest()
   1.173 +//
   1.174 +//	RFs test on system Directory
   1.175 +//
   1.176 +	{
   1.177 +	__UHEAP_MARK;
   1.178 +
   1.179 +	systestname=KSystemPath;
   1.180 +	systestname[0]=(TText)('A' + gTheDriveNum);
   1.181 +	
   1.182 +	mkdirname.Zero();
   1.183 +	mkdirname.Append(systestname);
   1.184 +	mkdirname.Append(KMkDirSub);
   1.185 +	r=TheFs.MkDirAll(mkdirname);	
   1.186 +	test(r==KErrNone);
   1.187 +
   1.188 +	TheFs.RmDir(mkdirname);
   1.189 +	test(r==KErrNone);
   1.190 +
   1.191 +	r=TheFs.SetSubst(systestname,EDriveO);
   1.192 +	test(r==KErrNone);
   1.193 +	
   1.194 +	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
   1.195 +	test(r==KErrPermissionDenied);
   1.196 +
   1.197 +	r=TheFs.SetSubst(_L(""),EDriveO); //to unsubst
   1.198 +	test(r==KErrNone);
   1.199 +
   1.200 +	r=TheFs.SetSessionPath(systestname);
   1.201 +	test(r==KErrPermissionDenied);
   1.202 +	
   1.203 +	TheFs.NotifyChange(ENotifyAll,aStat1,systestname);
   1.204 +	test(aStat1==KErrPermissionDenied);
   1.205 +
   1.206 +	systestfile=KSystemPath;
   1.207 +	systestfile[0]=(TText)('A' + gTheDriveNum);
   1.208 +	systestfile1=systestfile;
   1.209 +	systestfile.Append(KFileSys);
   1.210 +	systestfile1.Append(KFileSys3);
   1.211 +	
   1.212 +	oldName=KOldFile;
   1.213 +	oldName[0]=(TText)gDriveToTest;
   1.214 +
   1.215 +	r=TheFs.GetShortName(systestfile, shortfilename);
   1.216 +	test(r==KErrPermissionDenied || r==KErrNotSupported);
   1.217 +
   1.218 +	r=TheFs.GetLongName(systestfile1, longfilename);
   1.219 +	test(r==KErrPermissionDenied || r==KErrNotSupported);
   1.220 +
   1.221 +	r=file1.Create(TheFs,oldName,EFileWrite);
   1.222 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.223 +	file1.Close();
   1.224 +
   1.225 +	r=TheFs.Replace(oldName,systestfile);
   1.226 +	test(r==KErrNone);
   1.227 +	
   1.228 +	r=TheFs.Delete(systestfile1);
   1.229 +	test(r==KErrNone || r==KErrNotFound);
   1.230 +
   1.231 +	r=TheFs.Rename(systestfile,systestfile1);
   1.232 +	test(r==KErrNone);
   1.233 +	
   1.234 +	r=TheFs.Entry(systestfile1,entry);
   1.235 +	test(r==KErrPermissionDenied);
   1.236 +
   1.237 +	r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   1.238 +	test(r==KErrNone);
   1.239 +
   1.240 +	r=TheFs.Delete(systestfile1);
   1.241 +	test(r==KErrNone);
   1.242 +
   1.243 +	__UHEAP_MARKEND;
   1.244 +	}
   1.245 +
   1.246 +LOCAL_C void ResourceRFsTest()
   1.247 +//
   1.248 +//
   1.249 +//
   1.250 +	{
   1.251 +	__UHEAP_MARK;
   1.252 +
   1.253 +	restestname=KResourcePath;
   1.254 +	restestname[0]=(TText)('A' + gTheDriveNum);
   1.255 +	
   1.256 +	mkdirname.Zero();
   1.257 +	mkdirname.Append(restestname);
   1.258 +	mkdirname.Append(KMkDirSub);
   1.259 +	r=TheFs.MkDirAll(mkdirname);	
   1.260 +	test(r==KErrNone);
   1.261 +
   1.262 +	TheFs.RmDir(mkdirname);
   1.263 +	test(r==KErrNone);
   1.264 +
   1.265 +	r=TheFs.SetSubst(restestname,EDriveO);
   1.266 +	test(r==KErrNone);
   1.267 +	
   1.268 +	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
   1.269 +	test(r==KErrNone);
   1.270 +
   1.271 +	r=TheFs.SetSubst(_L(""),EDriveO); //to unsubst
   1.272 +	test(r==KErrNone);
   1.273 +
   1.274 +	r=TheFs.SetSessionPath(restestname);
   1.275 +	test(r==KErrNone);
   1.276 +	
   1.277 +	TheFs.NotifyChange(ENotifyAll,aStat4,restestname);
   1.278 +	test(aStat4==KRequestPending);
   1.279 +
   1.280 +	restestfile=KResourcePath;
   1.281 +	restestfile[0]=(TText)('A' + gTheDriveNum);
   1.282 +	restestfile1=restestfile;
   1.283 +	restestfile.Append(KFileRes);
   1.284 +	restestfile1.Append(KFileRes3);
   1.285 +	
   1.286 +	oldName=KOldFile;
   1.287 +	oldName[0]=(TText)gDriveToTest;
   1.288 +
   1.289 +	r=TheFs.GetShortName(restestfile, shortfilename);
   1.290 +	test(r==KErrNone || KErrNotFound || r==KErrNotSupported);
   1.291 +
   1.292 +	r=TheFs.GetLongName(restestfile1, longfilename);
   1.293 +	test(r==KErrNone || KErrNotFound || r==KErrNotSupported);
   1.294 +
   1.295 +	r=file1.Create(TheFs,oldName,EFileWrite);
   1.296 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.297 +	file1.Close();
   1.298 +
   1.299 +	r=TheFs.Replace(oldName,restestfile);
   1.300 +	test(r==KErrNone);
   1.301 +	
   1.302 +	r=TheFs.Delete(restestfile1);
   1.303 +	test(r==KErrNone || r==KErrNotFound);
   1.304 +
   1.305 +	r=TheFs.Rename(restestfile,restestfile1);
   1.306 +	test(r==KErrNone);
   1.307 +	
   1.308 +	r=TheFs.Entry(restestfile1,entry);
   1.309 +	test(r==KErrNone);
   1.310 +
   1.311 +	r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   1.312 +	test(r==KErrNone);
   1.313 +
   1.314 +	r=TheFs.Delete(restestfile1);
   1.315 +	test(r==KErrNone);
   1.316 +
   1.317 +
   1.318 +	__UHEAP_MARKEND;
   1.319 +	}
   1.320 +
   1.321 +LOCAL_C void privateRFsTest()
   1.322 +//
   1.323 +//
   1.324 +//
   1.325 +	{
   1.326 +	__UHEAP_MARK;
   1.327 +
   1.328 +	//private
   1.329 +	pritestname=KPrivatePath;
   1.330 +	pritestname[0]=(TText)('A' + gTheDriveNum);
   1.331 +	
   1.332 +	mkdirname.Zero();
   1.333 +	mkdirname.Append(pritestname);
   1.334 +	mkdirname.Append(KMkDirSub);
   1.335 +
   1.336 +	r=TheFs.MkDirAll(mkdirname);	
   1.337 +	test(r==KErrPermissionDenied);
   1.338 +
   1.339 +	r=TheFs.RmDir(mkdirname);	
   1.340 +	test(r==KErrPermissionDenied);
   1.341 +
   1.342 +	r=TheFs.SetSubst(pritestname,EDriveO);
   1.343 +	test(r==KErrPermissionDenied);
   1.344 +
   1.345 +	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
   1.346 +	test(r==KErrNone);
   1.347 +
   1.348 +	r=TheFs.SetSessionPath(pritestname);
   1.349 +	test(r==KErrPermissionDenied);
   1.350 +
   1.351 +	TheFs.NotifyChange(ENotifyAll,aStat2,pritestname);
   1.352 +	test(aStat2==KErrPermissionDenied);
   1.353 +
   1.354 +
   1.355 +	pritestfile=KPrivatePath;
   1.356 +	pritestfile[0]=(TText)('A' + gTheDriveNum);
   1.357 +	pritestfile1=pritestfile;
   1.358 +	pritestfile.Append(KFilePri2);
   1.359 +	pritestfile1.Append(KFilePri3);
   1.360 +	
   1.361 +	oldName=KOldFile;
   1.362 +	oldName[0]=(TText)gDriveToTest;
   1.363 +
   1.364 +	r=TheFs.GetShortName(pritestfile, shortfilename);
   1.365 +	test(r==KErrPermissionDenied || r==KErrNotSupported);
   1.366 +
   1.367 +	r=TheFs.GetLongName(pritestfile1, longfilename);
   1.368 +	test(r==KErrPermissionDenied || r==KErrNotSupported);
   1.369 +
   1.370 +	r=file1.Create(TheFs,oldName,EFileWrite);
   1.371 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.372 +	file1.Close();
   1.373 +
   1.374 +	r=TheFs.Replace(oldName,pritestfile);
   1.375 +	test(r==KErrPermissionDenied);
   1.376 +	
   1.377 +	r=TheFs.Rename(pritestfile,pritestfile1);
   1.378 +	test(r==KErrPermissionDenied);
   1.379 +	
   1.380 +	r=TheFs.Entry(pritestfile1,entry);
   1.381 +	test(r==KErrPermissionDenied);
   1.382 +
   1.383 +	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   1.384 +	test(r==KErrPermissionDenied);
   1.385 +
   1.386 +	r=TheFs.Delete(pritestfile1);
   1.387 +	test(r==KErrPermissionDenied);
   1.388 +
   1.389 +
   1.390 +	__UHEAP_MARKEND;
   1.391 +	}
   1.392 +
   1.393 +
   1.394 +LOCAL_C void privateSIDRFstest()
   1.395 +	{
   1.396 +	__UHEAP_MARK;
   1.397 +
   1.398 +	theprivatepath[0]=(TText)gDriveToTest;	
   1.399 +	test.Printf(_L("the Private Path = %S"),&theprivatepath);
   1.400 +
   1.401 +	mkdirname.Zero();
   1.402 +	mkdirname.Append(theprivatepath);
   1.403 +	mkdirname.Append(KMkDirSub);
   1.404 +	r=TheFs.MkDirAll(mkdirname);	
   1.405 +	test(r==KErrNone);
   1.406 +
   1.407 +	r=TheFs.RmDir(mkdirname);	
   1.408 +	test(r==KErrNone);
   1.409 +
   1.410 +	r=TheFs.SetSubst(theprivatepath,EDriveO);	
   1.411 +	test(r==KErrNone); 
   1.412 +
   1.413 +	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
   1.414 +	test(r==KErrNone);
   1.415 +
   1.416 +	r=TheFs.SetSubst(_L(""),EDriveO);	 //to unsubst
   1.417 +	test(r==KErrNone);
   1.418 +
   1.419 +	r=TheFs.SetSessionPath(theprivatepath);
   1.420 +	test(r==KErrNone);
   1.421 +
   1.422 +	TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath);
   1.423 +	test(aStat3==KRequestPending);
   1.424 +
   1.425 +	pritestfile=theprivatepath;
   1.426 +	pritestfile[0]=(TText)('A' + gTheDriveNum);
   1.427 +	pritestfile1=pritestfile;
   1.428 +	pritestfile.Append(KFilePri2);
   1.429 +	pritestfile1.Append(KFilePri3);
   1.430 +	
   1.431 +	oldName=KOldFile;
   1.432 +	oldName[0]=(TText)gDriveToTest;
   1.433 +
   1.434 +	r=TheFs.GetShortName(pritestfile, shortfilename);
   1.435 +	test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
   1.436 +
   1.437 +	r=TheFs.GetLongName(pritestfile1, longfilename);
   1.438 +	test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
   1.439 +
   1.440 +	r=file1.Create(TheFs,oldName,EFileWrite);
   1.441 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.442 +	file1.Close();
   1.443 +
   1.444 +	r=TheFs.Replace(oldName,pritestfile);
   1.445 +	test(r==KErrNone);
   1.446 +	
   1.447 +	r=TheFs.Rename(pritestfile,pritestfile1);
   1.448 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.449 +	
   1.450 +	r=TheFs.Entry(pritestfile1,entry);
   1.451 +	test(r==KErrNone);
   1.452 +
   1.453 +	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   1.454 +	test(r==KErrNone);
   1.455 +
   1.456 +	r=TheFs.Delete(pritestfile1);
   1.457 +	test(r==KErrNone);
   1.458 +
   1.459 +	__UHEAP_MARKEND;
   1.460 +	}
   1.461 +
   1.462 +
   1.463 +LOCAL_C void systemRFiletest()
   1.464 +//
   1.465 +//RFile testing with session path set to //system//
   1.466 +//
   1.467 +	{
   1.468 +	__UHEAP_MARK;
   1.469 +
   1.470 +	r=TheFs.SetSessionPath(systestname);
   1.471 +	test(r==KErrPermissionDenied);
   1.472 +
   1.473 +	r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite);
   1.474 +	test(r==KErrNone);
   1.475 +	file1.Close();
   1.476 +
   1.477 +	systestfile=KSystemPath;
   1.478 +	systestfile[0]=(TText)('A' + gTheDriveNum);
   1.479 +	systestfile1=systestfile;
   1.480 +	systestfile.Append(KFileSys);
   1.481 +	systestfile1.Append(KFileSys3);
   1.482 +
   1.483 +	r=file1.Create(TheFs,systestfile,EFileWrite);
   1.484 +	test(r==KErrNone);
   1.485 +	file1.Close();
   1.486 +
   1.487 +	r=file1.Open(TheFs,systestfile,EFileWrite);
   1.488 +	test(r==KErrNone);
   1.489 +	file1.Close();
   1.490 +	
   1.491 +	r=file1.Open(TheFs,systestfile,EFileRead);
   1.492 +	test(r==KErrPermissionDenied);
   1.493 +	file1.Close();
   1.494 +
   1.495 +	r=file1.Replace(TheFs,systestfile,EFileWrite);
   1.496 +	test(r==KErrNone);
   1.497 +	
   1.498 +	r=file1.Rename(systestfile1);
   1.499 +	test(r==KErrNone);
   1.500 +	file1.Close();
   1.501 +
   1.502 +    TFindFile finder(TheFs);
   1.503 +    CDir* dir = NULL;
   1.504 +    r=finder.FindWildByDir(KWildFile, KWildPath, dir);
   1.505 +	if (!(r==KErrPermissionDenied))
   1.506 +        test.Printf(_L("T_DCTCBDISKADMIN: test find wildcards r = %d (expected KErrPermissionDenied)\n"), r);
   1.507 +	test(r==KErrPermissionDenied);
   1.508 +//	delete dir;
   1.509 +
   1.510 +	r=TheFs.Delete(fromTemp);
   1.511 +	test(r==KErrNone);
   1.512 +
   1.513 +	r=TheFs.Delete(systestfile1);
   1.514 +	test(r==KErrNone);
   1.515 +	
   1.516 +
   1.517 +	__UHEAP_MARKEND;
   1.518 +	}
   1.519 +
   1.520 +LOCAL_C void resourceRFiletest()
   1.521 +//
   1.522 +//RFile testing with session path set to //resource//
   1.523 +//
   1.524 +	{
   1.525 +	__UHEAP_MARK;
   1.526 +
   1.527 +	r=TheFs.SetSessionPath(restestname);
   1.528 +	test(r==KErrNone);
   1.529 +
   1.530 +	r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite);
   1.531 +	test(r==KErrNone);
   1.532 +	file1.Close();
   1.533 +
   1.534 +	r=file1.Create(TheFs,KFileRes,EFileWrite);
   1.535 +	test(r==KErrNone);
   1.536 +	file1.Close();
   1.537 +
   1.538 +	r=file1.Open(TheFs,KFileRes,EFileWrite|EFileShareExclusive );
   1.539 +	test(r==KErrNone);
   1.540 +	
   1.541 +	r=file1.Rename(KFileRes3);
   1.542 +	test(r==KErrNone);
   1.543 +	file1.Close();
   1.544 +
   1.545 +	r=file1.Open(TheFs,KFileRes3,EFileShareReadersOrWriters|EFileRead);
   1.546 +	test(r==KErrNone);
   1.547 +	file1.Close();
   1.548 +
   1.549 +	r=file1.Open(TheFs,KFileRes3,EFileShareReadersOrWriters|EFileWrite);
   1.550 +	test(r==KErrNone);
   1.551 +	file1.Close();
   1.552 +
   1.553 +	r=file1.Open(TheFs,KFileRes3,EFileShareReadersOnly);
   1.554 +	test(r==KErrNone);
   1.555 +
   1.556 +	r=file1.ChangeMode(EFileShareExclusive);
   1.557 +	test(r==KErrNone);
   1.558 +	file1.Close();
   1.559 +
   1.560 +	r=file1.Replace(TheFs,KFileRes,EFileWrite);
   1.561 +	test(r==KErrNone);
   1.562 +	file1.Close();	
   1.563 +
   1.564 +	r=TheFs.Delete(KFileRes);
   1.565 +	test(r==KErrNone);
   1.566 +
   1.567 +	r=TheFs.Delete(KFileRes3);
   1.568 +	test(r==KErrNone);
   1.569 +
   1.570 +	r=TheFs.Delete(fromTemp);
   1.571 +	test(r==KErrNone);
   1.572 +
   1.573 +	__UHEAP_MARKEND;
   1.574 +	}
   1.575 +
   1.576 +
   1.577 +LOCAL_C void privatefalseIDRFiletest()
   1.578 +//
   1.579 +//RFile testing with session path set to //Private//<false ID>//
   1.580 +//
   1.581 +	{
   1.582 +	__UHEAP_MARK;
   1.583 +
   1.584 +	r=TheFs.SetSessionPath(pritestfalseidname);
   1.585 +	test(r==KErrPermissionDenied);
   1.586 +
   1.587 +	// Since can't set the session path to what is required, so use
   1.588 +	// an explicit path
   1.589 +	pritestfile=pritestfalseidname;
   1.590 +	pritestfile[0]=(TText)('A' + gTheDriveNum);
   1.591 +	pritestfile.Append(KFilePri);
   1.592 +
   1.593 +	r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite);
   1.594 +	test(r==KErrPermissionDenied);
   1.595 +	file1.Close();
   1.596 +
   1.597 +	r=file1.Create(TheFs,pritestfile,EFileWrite);
   1.598 +	test(r==KErrPermissionDenied);
   1.599 +	file1.Close();
   1.600 +
   1.601 +	r=file1.Open(TheFs,pritestfile,EFileWrite);
   1.602 +	test(r==KErrPermissionDenied);
   1.603 +	file1.Close();
   1.604 +	
   1.605 +	r=file1.Replace(TheFs,pritestfile,EFileWrite);
   1.606 +	test(r==KErrPermissionDenied);
   1.607 +
   1.608 +	// Can't perform this operation since file1 has not been created
   1.609 +/*	r=file1.Rename(KFilePri3);
   1.610 +	test(r==KErrPermissionDenied);
   1.611 +	file1.Close();
   1.612 +*/
   1.613 +	__UHEAP_MARKEND;
   1.614 +	}
   1.615 +
   1.616 +
   1.617 +
   1.618 +LOCAL_C void privateRFiletest()
   1.619 +//
   1.620 +//RFile testing with session path set to //Private//
   1.621 +//
   1.622 +	{
   1.623 +	__UHEAP_MARK;
   1.624 +
   1.625 +	r=TheFs.SetSessionPath(pritestname);
   1.626 +	test(r==KErrPermissionDenied);
   1.627 +
   1.628 +	r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite);
   1.629 +	test(r==KErrPermissionDenied);
   1.630 +	file1.Close();
   1.631 +
   1.632 +	// Since can't set session path create explicit path
   1.633 +	pritestfile=KPrivatePath;
   1.634 +	pritestfile[0]=(TText)('A' + gTheDriveNum);
   1.635 +	pritestfile.Append(KFilePri);
   1.636 +
   1.637 +	r=file1.Create(TheFs,pritestfile,EFileWrite);
   1.638 +	test(r==KErrPermissionDenied);
   1.639 +	file1.Close();
   1.640 +
   1.641 +	r=file1.Open(TheFs,pritestfile,EFileWrite);
   1.642 +	test(r==KErrPermissionDenied);
   1.643 +	file1.Close();
   1.644 +	
   1.645 +	r=file1.Open(TheFs,pritestfile,EFileRead);
   1.646 +	test(r==KErrPermissionDenied);
   1.647 +	file1.Close();
   1.648 +	
   1.649 +	r=file1.Replace(TheFs,pritestfile,EFileWrite);
   1.650 +	test(r==KErrPermissionDenied);
   1.651 +
   1.652 +	// Can't rename nor delete since file1 not created
   1.653 +/*
   1.654 +	r=file1.Rename(KFilePri3);
   1.655 +	test(r==KErrPermissionDenied);
   1.656 +	file1.Close();
   1.657 +
   1.658 +	r=TheFs.Delete(fromTemp);
   1.659 +	test(r==KErrNone);
   1.660 +*/
   1.661 +
   1.662 +	__UHEAP_MARKEND;
   1.663 +	}
   1.664 +
   1.665 +
   1.666 +
   1.667 +LOCAL_C void privateSIDRFiletest()
   1.668 +//
   1.669 +//Rfile Testing with session path set to //Private//UID//
   1.670 +//
   1.671 +	{
   1.672 +	__UHEAP_MARK;
   1.673 +
   1.674 +	r=TheFs.SetSessionToPrivate(gTheDriveNum);
   1.675 +	test(r==KErrNone);
   1.676 +	
   1.677 +	r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite);
   1.678 +	test(r==KErrNone);
   1.679 +	file1.Close();
   1.680 +
   1.681 +	r=file1.Create(TheFs,KFilePri,EFileWrite);
   1.682 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.683 +	file1.Close();
   1.684 +
   1.685 +	r=file1.Open(TheFs,KFilePri,EFileWrite);
   1.686 +	test(r==KErrNone);
   1.687 +	file1.Close();
   1.688 +	
   1.689 +	r=file1.Open(TheFs,KFilePri,EFileRead);
   1.690 +	test(r==KErrNone);
   1.691 +	file1.Close();
   1.692 +	
   1.693 +	r=file1.Replace(TheFs,KFilePri,EFileWrite);
   1.694 +	test(r==KErrNone);
   1.695 +	
   1.696 +	r=file1.Rename(KFilePri3);
   1.697 +	test(r==KErrNone);
   1.698 +	file1.Close();
   1.699 +
   1.700 +	r=TheFs.Delete(KFilePri3);
   1.701 +	test(r==KErrNone);
   1.702 +
   1.703 +	r=TheFs.Delete(fromTemp);
   1.704 +	test(r==KErrNone);
   1.705 +
   1.706 +	__UHEAP_MARKEND;
   1.707 +	}
   1.708 +
   1.709 +LOCAL_C void RDirtest()
   1.710 +//
   1.711 +//
   1.712 +//
   1.713 +	{
   1.714 +	__UHEAP_MARK;
   1.715 +
   1.716 +
   1.717 +	//system
   1.718 +	CDir*	dirEntries;
   1.719 +	TBuf<30> dirNameBuf(KSystemPath);
   1.720 +	dirNameBuf[0]=(TText)gDriveToTest;
   1.721 +	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   1.722 +	test(r==KErrPermissionDenied);
   1.723 +	dir.Close();
   1.724 +	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   1.725 +	test(r==KErrPermissionDenied);
   1.726 +	dirNameBuf.Zero();
   1.727 +	delete dirEntries;
   1.728 +
   1.729 +	//Private
   1.730 +	dirNameBuf=KPrivatePath;
   1.731 +	dirNameBuf[0]=(TText)gDriveToTest;
   1.732 +	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   1.733 +	test(r==KErrPermissionDenied);
   1.734 +	dir.Close();
   1.735 +	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   1.736 +	test(r==KErrPermissionDenied);
   1.737 +	dirNameBuf.Zero();
   1.738 +	delete dirEntries;
   1.739 +
   1.740 +	//Private//<wrong ID>//
   1.741 +	dirNameBuf=KPrivateFalseID;
   1.742 +	dirNameBuf[0]=(TText)gDriveToTest;
   1.743 +	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   1.744 +	test(r==KErrPermissionDenied);
   1.745 +	dir.Close();
   1.746 +	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   1.747 +	test(r==KErrPermissionDenied);
   1.748 +	dirNameBuf.Zero();
   1.749 +	delete dirEntries;
   1.750 +
   1.751 +	//Private/uid
   1.752 +	TheFs.PrivatePath(dirNameBuf);
   1.753 +	dirNameBuf.Insert(0,_L("?:"));
   1.754 +	dirNameBuf[0]=(TText)gDriveToTest;
   1.755 +	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   1.756 +	test(r==KErrNone);
   1.757 +	dir.Close();
   1.758 +	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   1.759 +	test(r==KErrNone);
   1.760 +	dirNameBuf.Zero();
   1.761 +	delete dirEntries;
   1.762 +	//Resource
   1.763 +	
   1.764 +	dirNameBuf=KResourcePath;
   1.765 +	dirNameBuf[0]=(TText)gDriveToTest;
   1.766 +	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   1.767 +	test(r==KErrNone);
   1.768 +	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   1.769 +	test(r==KErrNone);
   1.770 +	dir.Close();
   1.771 +	delete dirEntries;
   1.772 +
   1.773 +	__UHEAP_MARKEND;
   1.774 +	}
   1.775 +
   1.776 +
   1.777 +LOCAL_C void TestTcbDiskAdmin()
   1.778 +//
   1.779 +//	Test with tcb capabilities
   1.780 +//
   1.781 +	{
   1.782 +	__UHEAP_MARK;
   1.783 +
   1.784 +	r=TheFs.FileSystemName(fsname,gTheDriveNum);
   1.785 +	test(r==KErrNone);
   1.786 +	r = DismountFileSystem(TheFs, fsname, gTheDriveNum);
   1.787 +	test(r==KErrNone || r==KErrNotFound);
   1.788 +//	r=TheFs.RemoveFileSystem(fsname);	//can not test due to bug else where fix exists
   1.789 +//	test(r==KErrNone);
   1.790 +//	r=TheFs.AddFileSystem(fsname);
   1.791 +//	test(r==KErrNone);
   1.792 +	r = MountFileSystem(TheFs, fsname, gTheDriveNum);
   1.793 +	test(r==KErrNone);
   1.794 +	r=TheFs.SetDriveName(gTheDriveNum,KDriveName);
   1.795 +	test(r==KErrNone);
   1.796 +#ifndef __WINS__
   1.797 + 	r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum);
   1.798 +	test(r==KErrNone);
   1.799 +#endif
   1.800 +
   1.801 +	systemRFsTest();
   1.802 +	ResourceRFsTest();
   1.803 +	privateRFsTest();	
   1.804 +	privateSIDRFstest();
   1.805 +	privateFalseIDRFsTest();
   1.806 +
   1.807 +	systemRFiletest();
   1.808 +	resourceRFiletest();
   1.809 +	privateRFiletest();
   1.810 +	privateSIDRFiletest();
   1.811 +	privatefalseIDRFiletest();
   1.812 +
   1.813 +	//check notifier return values set in rfs testing
   1.814 +	User::WaitForRequest(aStat1);
   1.815 +	User::WaitForRequest(aStat2);
   1.816 +	User::WaitForRequest(aStat3);
   1.817 +	User::WaitForRequest(aStat4);
   1.818 +	test(aStat1==KErrPermissionDenied);
   1.819 +	test(aStat2==KErrPermissionDenied);
   1.820 +	test(aStat3==KErrNone);
   1.821 +	test(aStat4==KErrNone);
   1.822 +
   1.823 +	r=TheFs.SetSessionPath(systestname);
   1.824 +	test(r==KErrPermissionDenied);
   1.825 +	
   1.826 +//Test RRawDisk class
   1.827 +	r=rawdisk.Open(TheFs,gTheDriveNum);
   1.828 +	test(r==KErrNone);
   1.829 +	rawdisk.Close();
   1.830 +
   1.831 +	RDirtest();
   1.832 +
   1.833 +#ifdef __WINS__
   1.834 +	if (User::UpperCase(driveBuf[0]) != 'C')
   1.835 +#endif
   1.836 +		{
   1.837 +		//Test RFormat class
   1.838 +		r=format.Open(TheFs,driveBuf,EHighDensity,count);
   1.839 +		test(r==KErrNone);
   1.840 +
   1.841 +		while(count)	
   1.842 +			{
   1.843 +			TInt r=format.Next(count);
   1.844 +			test(r==KErrNone);
   1.845 +			}
   1.846 +		format.Close();
   1.847 +		}
   1.848 +
   1.849 +	driveBuf[0]=(TText)gDriveToTest;
   1.850 +	r=TheFs.ScanDrive(driveBuf);
   1.851 +	test(r==KErrNone || r==KErrNotSupported);
   1.852 +	r=TheFs.CheckDisk(driveBuf);
   1.853 +	test(r==KErrNone || r==KErrNotSupported);
   1.854 +
   1.855 +	__UHEAP_MARKEND;
   1.856 +	}
   1.857 +
   1.858 +LOCAL_C void TestCaps()
   1.859 +//
   1.860 +//	test format etc that require certain capabilities
   1.861 +//
   1.862 +	{
   1.863 +
   1.864 +	__UHEAP_MARK;
   1.865 +#ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   1.866 +	const char myDiagMsg[] = "Capability Check Failure";
   1.867 +#endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   1.868 +	r=RProcess().HasCapability(ECapabilityTCB,ECapabilityDiskAdmin, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
   1.869 +	test(r);
   1.870 +
   1.871 +	driveBuf[0]=(TText)gDriveToTest;
   1.872 +	r=TheFs.SessionPath(temp);
   1.873 +	test(r==KErrNone);
   1.874 +
   1.875 +	test.Printf(_L("Session path: %S"),&temp);
   1.876 +
   1.877 +	r=TheFs.CreatePrivatePath(gTheDriveNum);
   1.878 +	test(r==KErrNone || r== KErrAlreadyExists);
   1.879 +
   1.880 +	TBuf<18> tempPri;
   1.881 +	r=TheFs.PrivatePath(tempPri);
   1.882 +	test(r==KErrNone);
   1.883 +	theprivatepath = _L("?:");
   1.884 +	theprivatepath.Append(tempPri);
   1.885 +
   1.886 +	TestTcbDiskAdmin();
   1.887 +
   1.888 +	TFileName thesessionpath;
   1.889 +
   1.890 +	r=TheFs.SetSessionToPrivate(gTheDriveNum);
   1.891 +	test(r==KErrNone);
   1.892 +	r=TheFs.SessionPath(thesessionpath);
   1.893 +	test(r==KErrNone);
   1.894 +	
   1.895 +	test(thesessionpath == theprivatepath);
   1.896 +
   1.897 +	__UHEAP_MARKEND;
   1.898 +	}
   1.899 +
   1.900 +LOCAL_C void CleanupL()
   1.901 +//
   1.902 +// Clean up tests
   1.903 +//
   1.904 +	{
   1.905 +	test.Next(_L("Delete test directory"));
   1.906 +	CFileMan* fMan=CFileMan::NewL(TheFs);
   1.907 +	TInt r=fMan->RmDir(gSessionPath);
   1.908 +	test(r==KErrNone || r==KErrPathNotFound);
   1.909 +
   1.910 +	TBuf<20> delDir;
   1.911 +	delDir=KResourcePath;
   1.912 +	delDir[0]=(TText)gDriveToTest;
   1.913 +	r=fMan->RmDir(delDir);
   1.914 +	test(r==KErrNone || r==KErrPathNotFound);
   1.915 +	delete fMan;
   1.916 +
   1.917 +	delDir=KSystemPath;
   1.918 +	delDir[0]=(TText)gDriveToTest;
   1.919 +	r=TheFs.RmDir(delDir);
   1.920 +	test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
   1.921 +	}
   1.922 +
   1.923 +GLDEF_C void CallTestsL(/*TChar aDriveLetter*/)
   1.924 +//
   1.925 +// Do all tests
   1.926 +//
   1.927 +	{
   1.928 +	if( !PlatSec::IsCapabilityEnforced(ECapabilityTCB) || 
   1.929 +		!PlatSec::IsCapabilityEnforced(ECapabilityDiskAdmin))
   1.930 +		{
   1.931 +		test.Printf(_L("Insufficient capabilities enabled - leaving t_dctcbdiskadmin"));
   1.932 +		test.Printf(_L("\n")); // Prevent overwrite by next print
   1.933 +		return;
   1.934 +		}
   1.935 +
   1.936 +	__UHEAP_MARK;
   1.937 +
   1.938 +	TurnAllocFailureOff();
   1.939 +
   1.940 +	TheFs.CharToDrive(gDriveToTest,gTheDriveNum);
   1.941 +	
   1.942 +	TBuf<30> sesspath;
   1.943 +	sesspath=_L("?:\\");
   1.944 +	sesspath[0] = (TText)gDriveToTest;
   1.945 +
   1.946 +	TInt r= TheFs.SetSessionPath(sesspath);
   1.947 +	test(r==KErrNone);
   1.948 +
   1.949 +	//cleanup from previous run of this test
   1.950 +	RProcess tp;
   1.951 +	r=tp.Create(_L("clean_prepdc.exe"),sesspath);
   1.952 +	test(r==KErrNone);
   1.953 +	{
   1.954 +	TRequestStatus ps;
   1.955 +	tp.Logon(ps);
   1.956 +	tp.Resume();
   1.957 +	tp.Close();
   1.958 +	User::WaitForRequest(ps);
   1.959 +	}
   1.960 +
   1.961 +	//check double mode ie that Defpath still works	
   1.962 +	RFs fs1;
   1.963 +	RFs fs2;
   1.964 +	
   1.965 +	r=fs1.Connect();
   1.966 +	test(r==KErrNone);
   1.967 +	r=fs1.SessionPath(sesspath);
   1.968 +	test(r==KErrNone);
   1.969 +	test.Printf(_L("session1 Path=%S"),&sesspath);
   1.970 +
   1.971 +	TBuf<30> privatepath;
   1.972 +	r=fs1.SetSessionToPrivate(gTheDriveNum);
   1.973 +	test(r==KErrNone);
   1.974 +	r=fs1.PrivatePath(privatepath);
   1.975 +	test(r==KErrNone);
   1.976 +	r=privatepath.Compare(KExpectedPrivatePath());
   1.977 +	test(r==0);
   1.978 +	r=fs1.SessionPath(sesspath);
   1.979 +	test(r==KErrNone);
   1.980 +	r=privatepath.Compare(sesspath.Mid(KPathPosition));
   1.981 +	test(r==0);
   1.982 +	r=fs1.CreatePrivatePath(gTheDriveNum);
   1.983 +	test(r==KErrNone);
   1.984 +	fs1.Close();
   1.985 +
   1.986 +	r=fs2.Connect();
   1.987 +	test(r==KErrNone);
   1.988 +	r=fs2.SessionPath(sesspath);
   1.989 +	test(r==KErrNone);
   1.990 +	test.Printf(_L("session2 Path=%S"),&sesspath);
   1.991 +	fs2.Close();
   1.992 +
   1.993 +	__UHEAP_MARK;
   1.994 +	TestCaps();
   1.995 +	__UHEAP_MARKEND;
   1.996 +
   1.997 +	test.Printf(_L("No of files open=%d"), TheFs.ResourceCount());
   1.998 +
   1.999 +	CleanupL();
  1.1000 +	__UHEAP_MARKEND;
  1.1001 +
  1.1002 +	}