kerneltest/f32test/fileshare/t_handshare.cpp
branchRCL_3
changeset 43 c1f20ce4abcf
parent 0 a41df078684a
child 44 3e88ff8f41d5
equal deleted inserted replaced
42:a179b74831c9 43:c1f20ce4abcf
    13 // Description:
    13 // Description:
    14 // f32test\server\t_handshare.cpp
    14 // f32test\server\t_handshare.cpp
    15 // 
    15 // 
    16 //
    16 //
    17 
    17 
       
    18 #define	__E32TEST_EXTENSION__
    18 #include <f32file.h>
    19 #include <f32file.h>
    19 #include <e32test.h>
    20 #include <e32test.h>
    20 #include "t_server.h"
    21 #include "t_server.h"
    21 #include "handshare.h"
    22 #include "handshare.h"
    22 
    23 
    39 	do
    40 	do
    40 		{
    41 		{
    41 		r=handsvr.Connect();
    42 		r=handsvr.Connect();
    42 		}
    43 		}
    43 		while(r==KErrNotFound);
    44 		while(r==KErrNotFound);
    44 	test(r==KErrNone);
    45 	test_KErrNone(r);
    45 	r=handsvr.SetTestDrive(drivenum);
    46 	r=handsvr.SetTestDrive(drivenum);
    46 	test(r==KErrNone);
    47 	test_KErrNone(r);
    47 	TInt ssh;
    48 	TInt ssh;
    48 	RFs fs1;
    49 	RFs fs1;
    49 	TInt fsh = handsvr.GetFileHandle(ssh, EFileRead);
    50 	TInt fsh = handsvr.GetFileHandle(ssh, EFileRead);
    50 
    51 
    51 	r = fs1.SetReturnedHandle(fsh);
    52 	r = fs1.SetReturnedHandle(fsh);
    52 	test(r==KErrNone);
    53 	test_KErrNone(r);
    53 	
    54 	
    54 	RFile file;
    55 	RFile file;
    55 	r=file.Adopt(fs1,ssh);
    56 	r=file.Adopt(fs1,ssh);
    56 	test(r==KErrNone);
    57 	test_KErrNone(r);
    57 	
    58 	
    58 	TBuf8<100> rbuf;
    59 	TBuf8<100> rbuf;
    59 	r=file.Read(0,rbuf);
    60 	r=file.Read(0,rbuf);
    60 	test(r==KErrNone);
    61 	test_KErrNone(r);
    61 	
    62 	
    62 	r=rbuf.CompareF(KTestData1());
    63 	r=rbuf.CompareF(KTestData1());
    63 	test(r==KErrNone);
    64 	test_KErrNone(r);
    64 	
    65 	
    65 	r=file.Write(KTestData());
    66 	r=file.Write(KTestData());
    66 	test(r==KErrAccessDenied);
    67 	test_Value(r, r==KErrAccessDenied);
    67 	
    68 	
    68 	r=file.ChangeMode(EFileWrite);
    69 	r=file.ChangeMode(EFileWrite);
    69 	test(r==KErrArgument);
    70 	test_Value(r, r==KErrArgument);
    70 	
    71 	
    71 	r=file.Rename(_L("\\newname.txt"));
    72 	r=file.Rename(_L("\\newname.txt"));
    72 	test(r==KErrPermissionDenied || r==KErrAccessDenied);
    73 	test_Value(r, r==KErrPermissionDenied || r==KErrAccessDenied);
    73 
    74 
    74 	file.Close();
    75 	file.Close();
    75 
    76 
    76 	fsh = handsvr.GetFileHandle(ssh, EFileRead);
    77 	fsh = handsvr.GetFileHandle(ssh, EFileRead);
    77 	r = fs1.SetReturnedHandle(fsh);
    78 	r = fs1.SetReturnedHandle(fsh);
    78 	test(r==KErrNone);
    79 	test_KErrNone(r);
    79 
    80 
    80 	// Adopt a bad sub-session handle
    81 	// Adopt a bad sub-session handle
    81 
    82 
    82 	r=file.Adopt(fs1, KNullHandle);
    83 	r=file.Adopt(fs1, KNullHandle);
    83 	test(r==KErrBadHandle);
    84 	test_Value(r, r==KErrBadHandle);
    84 
    85 
    85 	r=file.Adopt(fs1, -1);
    86 	r=file.Adopt(fs1, -1);
    86 	test(r==KErrBadHandle);
    87 	test_Value(r, r==KErrBadHandle);
    87 
    88 
    88 
    89 
    89 	handsvr.Close();
    90 	handsvr.Close();
    90 	file.Close();
    91 	file.Close();
    91 	RDebug::Print(_L("End Of Tests"));
    92 	RDebug::Print(_L("End Of Tests"));
    99 	{
   100 	{
   100 	test.Next(_L("RFile::Duplicate()"));
   101 	test.Next(_L("RFile::Duplicate()"));
   101 
   102 
   102 	RFs fs;
   103 	RFs fs;
   103 	TInt r=fs.Connect();
   104 	TInt r=fs.Connect();
   104 	test(r==KErrNone);
   105 	test_KErrNone(r);
   105 
   106 
   106 	// Check the number of open file handles
   107 	// Check the number of open file handles
   107 	TInt resCount = fs.ResourceCount();
   108 	TInt resCount = fs.ResourceCount();
   108 	test(resCount == 0);
   109 	test_Value(resCount, resCount == 0);
   109 
   110 
   110 	// create a file & fill it with data	
   111 	// create a file & fill it with data	
   111 	RFile file1;
   112 	RFile file1;
   112 	r=file1.Replace(fs,KCliFileName,EFileWrite);
   113 	r=file1.Replace(fs,KCliFileName,EFileWrite);
   113 	test(r==KErrNone);
   114 	test_KErrNone(r);
   114 	r=file1.Write(KTestData());
   115 	r=file1.Write(KTestData());
   115 	test(r==KErrNone);
   116 	test_KErrNone(r);
   116 	file1.Close();
   117 	file1.Close();
   117 
   118 
   118 	// open the file for read
   119 	// open the file for read
   119 	r = file1.Open(fs,KCliFileName,EFileRead);
   120 	r = file1.Open(fs,KCliFileName,EFileRead);
   120 	test(r==KErrNone);
   121 	test_KErrNone(r);
   121 	TBuf8<100> rbuf;
   122 	TBuf8<100> rbuf;
   122 	r = file1.Read(0,rbuf);
   123 	r = file1.Read(0,rbuf);
   123 	test(r==KErrNone);
   124 	test_KErrNone(r);
   124 	r=rbuf.CompareF(KTestData);
   125 	r=rbuf.CompareF(KTestData);
   125 	test(r==KErrNone);
   126 	test_KErrNone(r);
   126 
   127 
   127 
   128 
   128 	// clone the file
   129 	// clone the file
   129 	RFile file2;
   130 	RFile file2;
   130 	r = file2.Duplicate(file1);
   131 	r = file2.Duplicate(file1);
   131 	test(r==0);
   132 	test_Value(r, r==0);
   132 
   133 
   133 	// make sure file positions are the same
   134 	// make sure file positions are the same
   134 	TInt pos1 = 0;
   135 	TInt pos1 = 0;
   135 	r = file1.Seek(ESeekCurrent, pos1);
   136 	r = file1.Seek(ESeekCurrent, pos1);
   136 	test(r==KErrNone);
   137 	test_KErrNone(r);
   137 	TInt pos2 = 0;
   138 	TInt pos2 = 0;
   138 	r = file2.Seek(ESeekCurrent, pos2);
   139 	r = file2.Seek(ESeekCurrent, pos2);
   139 	test(r==KErrNone);
   140 	test_KErrNone(r);
   140 	test(pos1 == pos2);
   141 	test_Value(pos1, pos1 == pos2);
   141 
   142 
   142 	// change the position on the duplcated file handle & 
   143 	// change the position on the duplcated file handle & 
   143 	// verify that the original file handle's position is unchanged
   144 	// verify that the original file handle's position is unchanged
   144 	TInt oldPos1 = pos1;
   145 	TInt oldPos1 = pos1;
   145 	
   146 	
   146 	const TInt newPos2 = 5;
   147 	const TInt newPos2 = 5;
   147 	pos2 = newPos2;
   148 	pos2 = newPos2;
   148 	r = file2.Seek(ESeekStart, pos2);
   149 	r = file2.Seek(ESeekStart, pos2);
   149 	test(r==KErrNone);
   150 	test_KErrNone(r);
   150 	
   151 	
   151 	pos1 = 0;
   152 	pos1 = 0;
   152 	r = file1.Seek(ESeekCurrent, pos1);
   153 	r = file1.Seek(ESeekCurrent, pos1);
   153 	test(r==KErrNone);
   154 	test_KErrNone(r);
   154 	test(pos1 == oldPos1);
   155 	test_Value(pos1, pos1 == oldPos1);
   155 	
   156 	
   156 	pos2 = 0;
   157 	pos2 = 0;
   157 	r = file2.Seek(ESeekCurrent, pos2);
   158 	r = file2.Seek(ESeekCurrent, pos2);
   158 	test(r==KErrNone);
   159 	test_KErrNone(r);
   159 	test(pos2 == newPos2);
   160 	test_Value(pos2, pos2 == newPos2);
   160 	test(pos1 != pos2);
   161 	test_Value(pos1, pos1 != pos2);
   161 
   162 
   162 	// close the parent file and check we can still use the duplicated one.
   163 	// close the parent file and check we can still use the duplicated one.
   163 	file1.Close();
   164 	file1.Close();
   164 
   165 
   165 	// Check the number of open file handles - should be 1 (the duplicated one)
   166 	// Check the number of open file handles - should be 1 (the duplicated one)
   166 	resCount = fs.ResourceCount();
   167 	resCount = fs.ResourceCount();
   167 	test(resCount == 1);
   168 	test_Value(resCount, resCount == 1);
   168 
   169 
   169 	fs.Close();
   170 	fs.Close();
   170 
   171 
   171 	rbuf.FillZ();
   172 	rbuf.FillZ();
   172 
   173 
   173 	// reset to pos 0
   174 	// reset to pos 0
   174 	pos2 = 0;
   175 	pos2 = 0;
   175 	r = file2.Seek(ESeekStart, pos2);
   176 	r = file2.Seek(ESeekStart, pos2);
   176 	test(r==KErrNone);
   177 	test_KErrNone(r);
   177 	
   178 	
   178 	r=file2.Read(0,rbuf);
   179 	r=file2.Read(0,rbuf);
   179 	test(r==KErrNone);
   180 	test_KErrNone(r);
   180 	r=rbuf.CompareF(KTestData);
   181 	r=rbuf.CompareF(KTestData);
   181 	test(r==KErrNone);
   182 	test_KErrNone(r);
   182 	file2.Close();
   183 	file2.Close();
   183 
   184 
   184 	// start again - this time we're going to close the duplicated file first
   185 	// start again - this time we're going to close the duplicated file first
   185 	// and check we can still use the parent file
   186 	// and check we can still use the parent file
   186 
   187 
   187 	r = fs.Connect();
   188 	r = fs.Connect();
   188 	test(r==KErrNone);
   189 	test_KErrNone(r);
   189 
   190 
   190 	// Make a note of the number of open resources
   191 	// Make a note of the number of open resources
   191 	fs.ResourceCountMarkStart();
   192 	fs.ResourceCountMarkStart();
   192 
   193 
   193 	// open the file for read
   194 	// open the file for read
   194 	r = file1.Open(fs,KCliFileName,EFileRead);
   195 	r = file1.Open(fs,KCliFileName,EFileRead);
   195 	test(r==KErrNone);
   196 	test_KErrNone(r);
   196 
   197 
   197 
   198 
   198 	// clone the file & check we can read it
   199 	// clone the file & check we can read it
   199 	r = file2.Duplicate(file1, EOwnerThread);
   200 	r = file2.Duplicate(file1, EOwnerThread);
   200 	test(r==0);
   201 	test_Value(r, r==0);
   201 	rbuf.FillZ();
   202 	rbuf.FillZ();
   202 	r = file2.Read(0,rbuf);
   203 	r = file2.Read(0,rbuf);
   203 	test(r==KErrNone);
   204 	test_KErrNone(r);
   204 	r=rbuf.CompareF(KTestData);
   205 	r=rbuf.CompareF(KTestData);
   205 	test(r==KErrNone);
   206 	test_KErrNone(r);
   206 
   207 
   207 
   208 
   208 	// close the duplicated file and check we can still use the parent one.
   209 	// close the duplicated file and check we can still use the parent one.
   209 	file2.Close();
   210 	file2.Close();
   210 
   211 
   211 	rbuf.FillZ();
   212 	rbuf.FillZ();
   212 
   213 
   213 	// check we can read the parent file
   214 	// check we can read the parent file
   214 	r=file1.Read(0,rbuf);
   215 	r=file1.Read(0,rbuf);
   215 	test(r==KErrNone);
   216 	test_KErrNone(r);
   216 	r=rbuf.CompareF(KTestData);
   217 	r=rbuf.CompareF(KTestData);
   217 	test(r==KErrNone);
   218 	test_KErrNone(r);
   218 
   219 
   219 	// close the parent
   220 	// close the parent
   220 	file1.Close();
   221 	file1.Close();
   221 
   222 
   222 	// Check the number of open file handles
   223 	// Check the number of open file handles
   223 	fs.ResourceCountMarkEnd();
   224 	fs.ResourceCountMarkEnd();
   224 	resCount = fs.ResourceCount();
   225 	resCount = fs.ResourceCount();
   225 	test(resCount == 0);
   226 	test_Value(resCount, resCount == 0);
   226 
   227 
   227 	fs.Close();
   228 	fs.Close();
   228 	}
   229 	}
   229 
   230 
   230 
   231 
   237 	do
   238 	do
   238 		{
   239 		{
   239 		r=handsvr.Connect();
   240 		r=handsvr.Connect();
   240 		}
   241 		}
   241 	while(r==KErrNotFound);
   242 	while(r==KErrNotFound);
   242 	test(r==KErrNone);
   243 	test_KErrNone(r);
   243 
   244 
   244 	r=handsvr.SetTestDrive(drivenum);
   245 	r=handsvr.SetTestDrive(drivenum);
   245 	test(r==KErrNone);
   246 	test_KErrNone(r);
   246 
   247 
   247 	TInt ssh;
   248 	TInt ssh;
   248 	TInt fsh = handsvr.GetFileHandle2(ssh, EFileWrite);
   249 	TInt fsh = handsvr.GetFileHandle2(ssh, EFileWrite);
   249 	test (fsh >= 0);
   250 	test (fsh >= 0);
   250 
   251 
   258 	// adopt the file handle from FHServer
   259 	// adopt the file handle from FHServer
   259 	test.Next(_L("RFile::AdoptFromServer()"));
   260 	test.Next(_L("RFile::AdoptFromServer()"));
   260 
   261 
   261 	RFile file;
   262 	RFile file;
   262 	r=file.AdoptFromServer(fsh, ssh);
   263 	r=file.AdoptFromServer(fsh, ssh);
   263 	test(r==KErrNone);
   264 	test_KErrNone(r);
   264 
   265 
   265 	TBuf8<100> rbuf;
   266 	TBuf8<100> rbuf;
   266 	r=file.Read(0,rbuf);
   267 	r=file.Read(0,rbuf);
   267 	test(r==KErrNone);
   268 	test_KErrNone(r);
   268 
   269 
   269 	// server should write KTestData1 ("Server Write Server Write") to file
   270 	// server should write KTestData1 ("Server Write Server Write") to file
   270 	r=rbuf.CompareF(KTestData1);
   271 	r=rbuf.CompareF(KTestData1);
   271 	test(r==KErrNone);
   272 	test_KErrNone(r);
   272 
   273 
   273 	// reset to pos 0
   274 	// reset to pos 0
   274 	TInt pos = 0;
   275 	TInt pos = 0;
   275 	r = file.Seek(ESeekStart, pos);
   276 	r = file.Seek(ESeekStart, pos);
   276 	test(r==KErrNone);
   277 	test_KErrNone(r);
   277 	
   278 	
   278 	// overwrite with KTestData ("Client Write Client Write") to file
   279 	// overwrite with KTestData ("Client Write Client Write") to file
   279 	r=file.Write(KTestData());
   280 	r=file.Write(KTestData());
   280 	test(r==KErrNone);
   281 	test_KErrNone(r);
   281 	rbuf.FillZ();
   282 	rbuf.FillZ();
   282 	r=file.Read(0,rbuf);
   283 	r=file.Read(0,rbuf);
   283 	test(r==KErrNone);
   284 	test_KErrNone(r);
   284 	r=rbuf.CompareF(KTestData);
   285 	r=rbuf.CompareF(KTestData);
   285 	test(r==KErrNone);
   286 	test_KErrNone(r);
   286 
   287 
   287 // !!! Disable platform security tests until we get the new APIs
   288 // !!! Disable platform security tests until we get the new APIs
   288 //	r=file.Rename(_L("\\newname.txt"));
   289 //	r=file.Rename(_L("\\newname.txt"));
   289 //	test(r==KErrPermissionDenied);
   290 //	test_Value(r, r==KErrPermissionDenied);
   290 
   291 
   291 	test.Next(_L("RFile::Name()"));
   292 	test.Next(_L("RFile::Name()"));
   292 
   293 
   293 	// retrieve the file name from the server
   294 	// retrieve the file name from the server
   294 	TFileName name;
   295 	TFileName name;
   295 	r = file.Name(name);
   296 	r = file.Name(name);
   296 	test(r==KErrNone);
   297 	test_KErrNone(r);
   297 	r = name.Compare(KSvrFileName());
   298 	r = name.Compare(KSvrFileName());
   298 	test(r==0);
   299 	test_Value(r, r==0);
   299 	
   300 	
   300 
   301 
   301 	test.Next(_L("RFile::Duplicate()"));
   302 	test.Next(_L("RFile::Duplicate()"));
   302 	RFile file2;
   303 	RFile file2;
   303 	r = file2.Duplicate(file);
   304 	r = file2.Duplicate(file);
   304 	test(r==0);
   305 	test_Value(r, r==0);
   305 
   306 
   306 
   307 
   307 	TInt pos1 = 0;
   308 	TInt pos1 = 0;
   308 	r = file.Seek(ESeekCurrent, pos1);
   309 	r = file.Seek(ESeekCurrent, pos1);
   309 	test(r==KErrNone);
   310 	test_KErrNone(r);
   310 	TInt pos2 = 0;
   311 	TInt pos2 = 0;
   311 	r = file2.Seek(ESeekCurrent, pos2);
   312 	r = file2.Seek(ESeekCurrent, pos2);
   312 	test(r==KErrNone);
   313 	test_KErrNone(r);
   313 	test(pos1 == pos2);
   314 	test_Value(pos1, pos1 == pos2);
   314 
   315 
   315 	// close the parent file and check we can still use the duplicated one.
   316 	// close the parent file and check we can still use the duplicated one.
   316 	file.Close();
   317 	file.Close();
   317 
   318 
   318 	rbuf.FillZ();
   319 	rbuf.FillZ();
   319 
   320 
   320 	// reset to pos 0
   321 	// reset to pos 0
   321 	pos2 = 0;
   322 	pos2 = 0;
   322 	r = file2.Seek(ESeekStart, pos2);
   323 	r = file2.Seek(ESeekStart, pos2);
   323 	test(r==KErrNone);
   324 	test_KErrNone(r);
   324 	
   325 	
   325 	r=file2.Read(0,rbuf);
   326 	r=file2.Read(0,rbuf);
   326 	test(r==KErrNone);
   327 	test_KErrNone(r);
   327 	r=rbuf.CompareF(KTestData);
   328 	r=rbuf.CompareF(KTestData);
   328 	test(r==KErrNone);
   329 	test_KErrNone(r);
   329 	file2.Close();
   330 	file2.Close();
   330 	}
   331 	}
   331 
   332 
   332 
   333 
   333 // Request a test file & test what we can do with it
   334 // Request a test file & test what we can do with it
   337 	{
   338 	{
   338 	TInt r;
   339 	TInt r;
   339 
   340 
   340 	RFs fs;
   341 	RFs fs;
   341 	r=fs.Connect();
   342 	r=fs.Connect();
   342 	test(r==KErrNone);
   343 	test_KErrNone(r);
   343 	r=fs.ShareProtected();
   344 	r=fs.ShareProtected();
   344 	test(r==KErrNone);
   345 	test_KErrNone(r);
   345 
   346 
   346 	
   347 	
   347 	// define a filename in our private path
   348 	// define a filename in our private path
   348 	TPath newPath;
   349 	TPath newPath;
   349 	fs.PrivatePath(newPath);
   350 	fs.PrivatePath(newPath);
   350 	TFileName newFileName;
   351 	TFileName newFileName;
   351 	newFileName = newPath;
   352 	newFileName = newPath;
   352 	newFileName.Append(_L("newname.txt"));
   353 	newFileName.Append(_L("newname.txt"));
   353 	
   354 	
   354 	r=fs.CreatePrivatePath(drivenum);
   355 	r=fs.CreatePrivatePath(drivenum);
   355 	test(r==KErrNone);
   356 	test_KErrNone(r);
   356 	r=fs.SetSessionToPrivate(drivenum);
   357 	r=fs.SetSessionToPrivate(drivenum);
   357 
   358 
   358 	RFileHandleSharer handsvr;
   359 	RFileHandleSharer handsvr;
   359 	do
   360 	do
   360 		{
   361 		{
   361 		r=handsvr.Connect();
   362 		r=handsvr.Connect();
   362 		}
   363 		}
   363 	while(r==KErrNotFound);
   364 	while(r==KErrNotFound);
   364 	test(r==KErrNone);
   365 	test_KErrNone(r);
   365 
   366 
   366 	r=handsvr.SetTestDrive(drivenum);
   367 	r=handsvr.SetTestDrive(drivenum);
   367 	test(r==KErrNone);
   368 	test_KErrNone(r);
   368 
   369 
   369 	// Next verify that we can copy a file retrieved from the server
   370 	// Next verify that we can copy a file retrieved from the server
   370 	// using CFileMan::Copy()
   371 	// using CFileMan::Copy()
   371 
   372 
   372 	test.Next(_L("CFileMan::Copy()"));
   373 	test.Next(_L("CFileMan::Copy()"));
   375 	TInt fsh = handsvr.GetFileHandle2(ssh, EFileRead);
   376 	TInt fsh = handsvr.GetFileHandle2(ssh, EFileRead);
   376 	test (fsh >= 0);
   377 	test (fsh >= 0);
   377 
   378 
   378 	RFile file;
   379 	RFile file;
   379 	r=file.AdoptFromServer(fsh, ssh);
   380 	r=file.AdoptFromServer(fsh, ssh);
   380 	test(r==KErrNone);
   381 	test_KErrNone(r);
   381 
   382 
   382 
   383 
   383 	CFileMan* fileMan = NULL;
   384 	CFileMan* fileMan = NULL;
   384 	TRAP(r, fileMan = CFileMan::NewL(fs));
   385 	TRAP(r, fileMan = CFileMan::NewL(fs));
   385 	test(r == KErrNone && fileMan != NULL);
   386 	test_Value(r, r ==  KErrNone && fileMan != NULL);
   386 
   387 
   387 	// copy to file, overwrite 
   388 	// copy to file, overwrite 
   388 	r = fileMan->Copy(file, newFileName, CFileMan::EOverWrite);
   389 	r = fileMan->Copy(file, newFileName, CFileMan::EOverWrite);
   389 	test(r == KErrNone);
   390 	test_KErrNone(r);
   390 
   391 
   391 	// copy to file, don't overwrite 
   392 	// copy to file, don't overwrite 
   392 	r = fileMan->Copy(file, newFileName, 0);	
   393 	r = fileMan->Copy(file, newFileName, 0);	
   393 	test(r == KErrAlreadyExists);
   394 	test_Value(r, r ==  KErrAlreadyExists);
   394 
   395 
   395 	// copy to file, overwrite
   396 	// copy to file, overwrite
   396 	r = fileMan->Copy(file, newFileName, CFileMan::EOverWrite);
   397 	r = fileMan->Copy(file, newFileName, CFileMan::EOverWrite);
   397 	test(r == KErrNone);
   398 	test_KErrNone(r);
   398 
   399 
   399 	// copy to path
   400 	// copy to path
   400 	r = fileMan->Copy(file, newPath, CFileMan::EOverWrite);	
   401 	r = fileMan->Copy(file, newPath, CFileMan::EOverWrite);	
   401 	test(r == KErrNone);
   402 	test_KErrNone(r);
   402 
   403 
   403 	// copy to file, overwrite, asynchnonous
   404 	// copy to file, overwrite, asynchnonous
   404 	TRequestStatus status(KRequestPending);
   405 	TRequestStatus status(KRequestPending);
   405 	r = fileMan->Copy(file, newFileName, CFileMan::EOverWrite, status);
   406 	r = fileMan->Copy(file, newFileName, CFileMan::EOverWrite, status);
   406 	test(r == KErrNone);
   407 	test_KErrNone(r);
   407 	User::WaitForRequest(status);
   408 	User::WaitForRequest(status);
   408 	test(status == KErrNone);
   409 	test_KErrNone(status.Int());
   409 
   410 
   410 
   411 
   411 	// Negative tests...
   412 	// Negative tests...
   412 	TPath newLongPath;
   413 	TPath newLongPath;
   413 	TInt len;
   414 	TInt len;
   416 	// when the filename is appended to it
   417 	// when the filename is appended to it
   417 	newLongPath = newPath;
   418 	newLongPath = newPath;
   418 	for (len=newLongPath.Length(); len< KMaxPath -4; len = newLongPath.Length())
   419 	for (len=newLongPath.Length(); len< KMaxPath -4; len = newLongPath.Length())
   419 		newLongPath.Append(_L("x\\"));
   420 		newLongPath.Append(_L("x\\"));
   420 	r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite);	
   421 	r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite);	
   421 	test(r == KErrBadName);
   422 	test_Value(r, r ==  KErrBadName);
   422 
   423 
   423 	// copy to very long but valid path (no filename) which will overflow
   424 	// copy to very long but valid path (no filename) which will overflow
   424 	// when drive letter is pre-pended to it
   425 	// when drive letter is pre-pended to it
   425 	newLongPath = newPath;
   426 	newLongPath = newPath;
   426 	for (len=newLongPath.Length(); len< KMaxPath -2; len = newLongPath.Length())
   427 	for (len=newLongPath.Length(); len< KMaxPath -2; len = newLongPath.Length())
   427 		newLongPath.Append(_L("x\\"));
   428 		newLongPath.Append(_L("x\\"));
   428 	r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite);	
   429 	r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite);	
   429 	test(r == KErrBadName);
   430 	test_Value(r, r ==  KErrBadName);
   430 
   431 
   431 	// copy to very long but valid path and filename which will overflow
   432 	// copy to very long but valid path and filename which will overflow
   432 	// when drive letter is pre-pended to it
   433 	// when drive letter is pre-pended to it
   433 	newLongPath.Append(_L("y"));
   434 	newLongPath.Append(_L("y"));
   434 	r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite);	
   435 	r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite);	
   435 	test(r == KErrBadName);
   436 	test_Value(r, r ==  KErrBadName);
   436 
   437 
   437 	// copy to badly formed path 
   438 	// copy to badly formed path 
   438 	newLongPath = newPath;
   439 	newLongPath = newPath;
   439 	newLongPath.Append(_L("\\y"));
   440 	newLongPath.Append(_L("\\y"));
   440 	r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite);	
   441 	r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite);	
   441 	test(r == KErrBadName);
   442 	test_Value(r, r ==  KErrBadName);
   442 
   443 
   443 	// copy to correctly formed path which doesn't exist
   444 	// copy to correctly formed path which doesn't exist
   444 	newLongPath = newPath;
   445 	newLongPath = newPath;
   445 	newLongPath.Append(_L("x\\y\\z"));
   446 	newLongPath.Append(_L("x\\y\\z"));
   446 	r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite);	
   447 	r = fileMan->Copy(file, newLongPath, CFileMan::EOverWrite);	
   447 	test(r == KErrPathNotFound);
   448 	test_Value(r, r ==  KErrPathNotFound);
   448 
   449 
   449 	delete fileMan; fileMan = NULL;
   450 	delete fileMan; fileMan = NULL;
   450 
   451 
   451 	file.Close();
   452 	file.Close();
   452 
   453 
   459 	fsh = handsvr.GetFileHandle2(ssh, TFileMode(EFileShareAny | EFileWrite));
   460 	fsh = handsvr.GetFileHandle2(ssh, TFileMode(EFileShareAny | EFileWrite));
   460 	test (fsh >= 0);
   461 	test (fsh >= 0);
   461 
   462 
   462 	// adopt the file handle from FHServer
   463 	// adopt the file handle from FHServer
   463 	r=file.AdoptFromServer(fsh, ssh);
   464 	r=file.AdoptFromServer(fsh, ssh);
   464 	test(r==KErrNone);
   465 	test_KErrNone(r);
   465 
   466 
   466 	r=file.Rename(_L("newname.txt"));
   467 	r=file.Rename(_L("newname.txt"));
   467 	test(r==KErrPermissionDenied || r==KErrAccessDenied);
   468 	test_Value(r, r==KErrPermissionDenied || r==KErrAccessDenied);
   468 
   469 
   469 	// delete the file before we try to rename anything to it
   470 	// delete the file before we try to rename anything to it
   470 	r = fs.Delete(newFileName);
   471 	r = fs.Delete(newFileName);
   471 	test(r == KErrNone || r == KErrNotFound);
   472 	test_Value(r, r ==  KErrNone || r == KErrNotFound);
   472 
   473 
   473 	r=file.Rename(newFileName);
   474 	r=file.Rename(newFileName);
   474 	test(r==KErrPermissionDenied || r==KErrAccessDenied);
   475 	test_Value(r, r==KErrPermissionDenied || r==KErrAccessDenied);
   475 
   476 
   476 	file.Close();
   477 	file.Close();
   477 
   478 
   478 
   479 
   479 	// Next verify that we CAN rename a file retrieved from the server
   480 	// Next verify that we CAN rename a file retrieved from the server
   483 
   484 
   484 	fsh = handsvr.GetFileHandle2(ssh, EFileWrite);
   485 	fsh = handsvr.GetFileHandle2(ssh, EFileWrite);
   485 	test (fsh >= 0);
   486 	test (fsh >= 0);
   486 
   487 
   487 	r=file.AdoptFromServer(fsh, ssh);
   488 	r=file.AdoptFromServer(fsh, ssh);
   488 	test(r==KErrNone);
   489 	test_KErrNone(r);
   489 
   490 
   490 	// delete the file before we try to rename anything to it
   491 	// delete the file before we try to rename anything to it
   491 	r = fs.Delete(newFileName);
   492 	r = fs.Delete(newFileName);
   492 	test(r == KErrNone || r == KErrNotFound);
   493 	test_Value(r, r ==  KErrNone || r == KErrNotFound);
   493 
   494 
   494 	r=file.Rename(newFileName);
   495 	r=file.Rename(newFileName);
   495 	test(r==KErrNone);
   496 	test_KErrNone(r);
   496 
   497 
   497 	file.Close();
   498 	file.Close();
   498 
   499 
   499 	// Next verify that we can delete the file (which should now 
   500 	// Next verify that we can delete the file (which should now 
   500 	// have been moved to our private directory)
   501 	// have been moved to our private directory)
   501 	test.Next(_L("RFs::Delete()"));
   502 	test.Next(_L("RFs::Delete()"));
   502 	r = fs.Delete(newFileName);
   503 	r = fs.Delete(newFileName);
   503 	test(r == KErrNone);
   504 	test_KErrNone(r);
   504 
   505 
   505 	handsvr.Close();
   506 	handsvr.Close();
   506 
   507 
   507 	fs.Close();
   508 	fs.Close();
   508 	}
   509 	}
   513 //
   514 //
   514 GLDEF_C void PassFile()
   515 GLDEF_C void PassFile()
   515 	{
   516 	{
   516 	RFs fs;
   517 	RFs fs;
   517 	TInt r=fs.Connect();
   518 	TInt r=fs.Connect();
   518 	test(r==KErrNone);
   519 	test_KErrNone(r);
   519 
   520 
   520 	// Check the number of open file handles
   521 	// Check the number of open file handles
   521 	TInt resCount = fs.ResourceCount();
   522 	TInt resCount = fs.ResourceCount();
   522 	test(resCount == 0);
   523 	test_Value(resCount, resCount == 0);
   523 
   524 
   524 	r=fs.ShareProtected();
   525 	r=fs.ShareProtected();
   525 	test(r==KErrNone);
   526 	test_KErrNone(r);
   526 
   527 
   527 	r=fs.CreatePrivatePath(drivenum);
   528 	r=fs.CreatePrivatePath(drivenum);
   528 	test(r==KErrNone);
   529 	test_KErrNone(r);
   529 	r=fs.SetSessionToPrivate(drivenum);
   530 	r=fs.SetSessionToPrivate(drivenum);
   530 	
   531 	
   531 	
   532 	
   532 	RFile file1;
   533 	RFile file1;
   533 	r=file1.Replace(fs,KCliFileName,EFileWrite);
   534 	r=file1.Replace(fs,KCliFileName,EFileWrite);
   534 	test(r==KErrNone);
   535 	test_KErrNone(r);
   535 	r=file1.Write(KTestData());
   536 	r=file1.Write(KTestData());
   536 	test(r==KErrNone);
   537 	test_KErrNone(r);
   537 	file1.Close();
   538 	file1.Close();
   538 
   539 
   539 	RFileHandleSharer handsvr;
   540 	RFileHandleSharer handsvr;
   540 	do
   541 	do
   541 		{
   542 		{
   542 		r=handsvr.Connect();
   543 		r=handsvr.Connect();
   543 		}
   544 		}
   544 	while(r==KErrNotFound);
   545 	while(r==KErrNotFound);
   545 	test(r==KErrNone);
   546 	test_KErrNone(r);
   546 
   547 
   547 	r=handsvr.SetTestDrive(drivenum);
   548 	r=handsvr.SetTestDrive(drivenum);
   548 	test(r==KErrNone);
   549 	test_KErrNone(r);
   549 
   550 
   550 	r=fs.SetSessionToPrivate(drivenum);
   551 	r=fs.SetSessionToPrivate(drivenum);
   551 	test(r==KErrNone);
   552 	test_KErrNone(r);
   552 
   553 
   553 	r=file1.Open(fs,KCliFileName,EFileRead);
   554 	r=file1.Open(fs,KCliFileName,EFileRead);
   554 	test(r==KErrNone);
   555 	test_KErrNone(r);
   555 	
   556 	
   556 	// pass the file handle to FHServer
   557 	// pass the file handle to FHServer
   557 	test.Next(_L("RFile::TransferToServer()"));
   558 	test.Next(_L("RFile::TransferToServer()"));
   558 
   559 
   559 	TIpcArgs ipcArgs;
   560 	TIpcArgs ipcArgs;
   563 
   564 
   564 
   565 
   565 	// verify that the original file handle's position is unchanged
   566 	// verify that the original file handle's position is unchanged
   566 	TInt pos = 0;
   567 	TInt pos = 0;
   567 	r = file1.Seek(ESeekCurrent, pos);
   568 	r = file1.Seek(ESeekCurrent, pos);
   568 	test(r==KErrNone);
   569 	test_KErrNone(r);
   569 	test(pos == 0);
   570 	test_Value(pos, pos == 0);
   570 
   571 
   571 	// make sure we can still use it
   572 	// make sure we can still use it
   572 	TBuf8<100> rbuf;
   573 	TBuf8<100> rbuf;
   573 	r=file1.Read(0,rbuf);
   574 	r=file1.Read(0,rbuf);
   574 	test(r==KErrNone);
   575 	test_KErrNone(r);
   575 
   576 
   576 	// Close the file
   577 	// Close the file
   577 	file1.Close();	
   578 	file1.Close();	
   578 
   579 
   579 	handsvr.Close();
   580 	handsvr.Close();
   580 
   581 
   581 	r=fs.MkDir(_L("C:\\mdir"));
   582 	r=fs.MkDir(_L("C:\\mdir"));
   582 	test(r==KErrNone || r==KErrAlreadyExists);
   583 	test_Value(r, r==KErrNone || r==KErrAlreadyExists);
   583 	
   584 	
   584 	// Check the number of open file handles
   585 	// Check the number of open file handles
   585 	resCount = fs.ResourceCount();
   586 	resCount = fs.ResourceCount();
   586 	test(resCount == 0);
   587 	test_Value(resCount, resCount == 0);
   587 
   588 
   588 	fs.Close();
   589 	fs.Close();
   589 	}
   590 	}
   590 
   591 
   591 
   592 
   596 GLDEF_C void PassInvalidFile()
   597 GLDEF_C void PassInvalidFile()
   597 	{
   598 	{
   598 
   599 
   599 	RFs fs;
   600 	RFs fs;
   600 	TInt r=fs.Connect();
   601 	TInt r=fs.Connect();
   601 	test(r==KErrNone);
   602 	test_KErrNone(r);
   602 
   603 
   603 	// Check the number of open file handles
   604 	// Check the number of open file handles
   604 	TInt resCount = fs.ResourceCount();
   605 	TInt resCount = fs.ResourceCount();
   605 	test(resCount == 0);
   606 	test_Value(resCount, resCount == 0);
   606 
   607 
   607 	r=fs.ShareProtected();
   608 	r=fs.ShareProtected();
   608 	test(r==KErrNone);
   609 	test_KErrNone(r);
   609 
   610 
   610 	r=fs.CreatePrivatePath(drivenum);
   611 	r=fs.CreatePrivatePath(drivenum);
   611 	test(r==KErrNone);
   612 	test_KErrNone(r);
   612 	r=fs.SetSessionToPrivate(drivenum);
   613 	r=fs.SetSessionToPrivate(drivenum);
   613 	
   614 	
   614 	
   615 	
   615 	RFile file1;
   616 	RFile file1;
   616 	r=file1.Replace(fs,KCliFileName,EFileWrite);
   617 	r=file1.Replace(fs,KCliFileName,EFileWrite);
   617 	test(r==KErrNone);
   618 	test_KErrNone(r);
   618 	r=file1.Write(KTestData());
   619 	r=file1.Write(KTestData());
   619 	test(r==KErrNone);
   620 	test_KErrNone(r);
   620 	file1.Close();
   621 	file1.Close();
   621 
   622 
   622 	RFileHandleSharer handsvr;
   623 	RFileHandleSharer handsvr;
   623 	do
   624 	do
   624 		{
   625 		{
   625 		r=handsvr.Connect();
   626 		r=handsvr.Connect();
   626 		}
   627 		}
   627 	while(r==KErrNotFound);
   628 	while(r==KErrNotFound);
   628 	test(r==KErrNone);
   629 	test_KErrNone(r);
   629 
   630 
   630 	r=handsvr.SetTestDrive(drivenum);
   631 	r=handsvr.SetTestDrive(drivenum);
   631 	test(r==KErrNone);
   632 	test_KErrNone(r);
   632 
   633 
   633 	r=fs.SetSessionToPrivate(drivenum);
   634 	r=fs.SetSessionToPrivate(drivenum);
   634 	test(r==KErrNone);
   635 	test_KErrNone(r);
   635 
   636 
   636 	r=file1.Open(fs,KCliFileName,EFileRead);
   637 	r=file1.Open(fs,KCliFileName,EFileRead);
   637 	test(r==KErrNone);
   638 	test_KErrNone(r);
   638 	
   639 	
   639 	// check the resoure count - there should be 1 open file handle
   640 	// check the resoure count - there should be 1 open file handle
   640 	resCount = fs.ResourceCount();
   641 	resCount = fs.ResourceCount();
   641 	test(resCount == 1);
   642 	test_Value(resCount, resCount == 1);
   642 
   643 
   643 	// pass an invalid file handle to FHServer
   644 	// pass an invalid file handle to FHServer
   644 	// by overwriting the IPC slots
   645 	// by overwriting the IPC slots
   645 	test.Next(_L("PassInvalidFileHandle - RFile::TransferToServer()"));
   646 	test.Next(_L("PassInvalidFileHandle - RFile::TransferToServer()"));
   646 
   647 
   649 	// Pass a bad RFs handle
   650 	// Pass a bad RFs handle
   650 	file1.TransferToServer(ipcArgs, 0, 1);
   651 	file1.TransferToServer(ipcArgs, 0, 1);
   651 
   652 
   652 	// check the resoure count - there should be 2 open file handles
   653 	// check the resoure count - there should be 2 open file handles
   653 	resCount = fs.ResourceCount();
   654 	resCount = fs.ResourceCount();
   654 	test(resCount == 2);
   655 	test_Value(resCount, resCount == 2);
   655 
   656 
   656 	ipcArgs.Set(0, 0);	// invalidate the RFs handle
   657 	ipcArgs.Set(0, 0);	// invalidate the RFs handle
   657 	r = handsvr.PassInvalidFileHandle(ipcArgs);
   658 	r = handsvr.PassInvalidFileHandle(ipcArgs);
   658 	test (r == KErrBadHandle);
   659 	test_Value(r, r == KErrBadHandle);
   659 
   660 
   660 	// Pass a bad RFile handle
   661 	// Pass a bad RFile handle
   661 	file1.TransferToServer(ipcArgs, 0, 1);
   662 	file1.TransferToServer(ipcArgs, 0, 1);
   662 
   663 
   663 	// check the resoure count - there should be 3 open file handles
   664 	// check the resoure count - there should be 3 open file handles
   664 	resCount = fs.ResourceCount();
   665 	resCount = fs.ResourceCount();
   665 	test(resCount == 3);
   666 	test_Value(resCount, resCount == 3);
   666 
   667 
   667 	ipcArgs.Set(1, 0);	// invalidate the RFile handle
   668 	ipcArgs.Set(1, 0);	// invalidate the RFile handle
   668 	r = handsvr.PassInvalidFileHandle(ipcArgs);
   669 	r = handsvr.PassInvalidFileHandle(ipcArgs);
   669 	test (r == KErrBadHandle);
   670 	test_Value(r, r == KErrBadHandle);
   670 
   671 
   671 	// Pass bad RFs and RFile handles
   672 	// Pass bad RFs and RFile handles
   672 	file1.TransferToServer(ipcArgs, 0, 1);
   673 	file1.TransferToServer(ipcArgs, 0, 1);
   673 
   674 
   674 	// check the resoure count - there should be 4 open file handles
   675 	// check the resoure count - there should be 4 open file handles
   675 	resCount = fs.ResourceCount();
   676 	resCount = fs.ResourceCount();
   676 	test(resCount == 4);
   677 	test_Value(resCount, resCount == 4);
   677 
   678 
   678 
   679 
   679 	ipcArgs.Set(0, 0);	// invalidate the RFs handle
   680 	ipcArgs.Set(0, 0);	// invalidate the RFs handle
   680 	ipcArgs.Set(1, 0);	// invalidate the RFile handle
   681 	ipcArgs.Set(1, 0);	// invalidate the RFile handle
   681 	r = handsvr.PassInvalidFileHandle(ipcArgs);
   682 	r = handsvr.PassInvalidFileHandle(ipcArgs);
   682 	test (r == KErrBadHandle);
   683 	test_Value(r, r == KErrBadHandle);
   683 
   684 
   684 	// Close the file
   685 	// Close the file
   685 	handsvr.Close();
   686 	handsvr.Close();
   686 	file1.Close();	
   687 	file1.Close();	
   687 
   688 
   688 	// Check the number of open file handles
   689 	// Check the number of open file handles
   689 	resCount = fs.ResourceCount();
   690 	resCount = fs.ResourceCount();
   690 	test(resCount == 3);
   691 	test_Value(resCount, resCount == 3);
   691 
   692 
   692 	fs.Close();
   693 	fs.Close();
   693 	}
   694 	}
   694 
   695 
   695 
   696 
   700 GLDEF_C void PassFile(RProcess& aProcess)
   701 GLDEF_C void PassFile(RProcess& aProcess)
   701 	{
   702 	{
   702 	
   703 	
   703 	RFs fs;
   704 	RFs fs;
   704 	TInt r=fs.Connect();
   705 	TInt r=fs.Connect();
   705 	test(r==KErrNone);
   706 	test_KErrNone(r);
   706 
   707 
   707 	// Check the number of open file handles
   708 	// Check the number of open file handles
   708 	TInt resCount = fs.ResourceCount();
   709 	TInt resCount = fs.ResourceCount();
   709 	test(resCount == 0);
   710 	test_Value(resCount, resCount == 0);
   710 
   711 
   711 	r=fs.ShareProtected();
   712 	r=fs.ShareProtected();
   712 	test(r==KErrNone);
   713 	test_KErrNone(r);
   713 
   714 
   714 	r=fs.CreatePrivatePath(drivenum);
   715 	r=fs.CreatePrivatePath(drivenum);
   715 	test(r==KErrNone);
   716 	test_KErrNone(r);
   716 	r=fs.SetSessionToPrivate(drivenum);
   717 	r=fs.SetSessionToPrivate(drivenum);
   717 	
   718 	
   718 	
   719 	
   719 	RFile file1;
   720 	RFile file1;
   720 	r=file1.Replace(fs,KCliFileName,EFileWrite);
   721 	r=file1.Replace(fs,KCliFileName,EFileWrite);
   721 	test(r==KErrNone);
   722 	test_KErrNone(r);
   722 	r=file1.Write(KTestData());
   723 	r=file1.Write(KTestData());
   723 	test(r==KErrNone);
   724 	test_KErrNone(r);
   724 	file1.Close();
   725 	file1.Close();
   725 
   726 
   726 	r=file1.Open(fs, KCliFileName, EFileWrite);
   727 	r=file1.Open(fs, KCliFileName, EFileWrite);
   727 
   728 
   728 	test(r==KErrNone);
   729 	test_KErrNone(r);
   729 	
   730 	
   730 	// NB slot 0 is reserved for the command line
   731 	// NB slot 0 is reserved for the command line
   731 
   732 
   732 	test.Next(_L("RFile::TransferToProcess()"));
   733 	test.Next(_L("RFile::TransferToProcess()"));
   733 
   734 
   734 	r = file1.TransferToProcess(aProcess, 1, 2);
   735 	r = file1.TransferToProcess(aProcess, 1, 2);
   735 
   736 
   736 	r = aProcess.SetParameter(3, drivenum);
   737 	r = aProcess.SetParameter(3, drivenum);
   737 	test(r==KErrNone);
   738 	test_KErrNone(r);
   738 
   739 
   739 	r=fs.SetSessionToPrivate(drivenum);
   740 	r=fs.SetSessionToPrivate(drivenum);
   740 	test(r==KErrNone);
   741 	test_KErrNone(r);
   741 
   742 
   742 	// make sure we can still read from the file
   743 	// make sure we can still read from the file
   743 	TBuf8<100> rbuf;
   744 	TBuf8<100> rbuf;
   744 	r=file1.Read(0,rbuf);
   745 	r=file1.Read(0,rbuf);
   745 	test(r==KErrNone);
   746 	test_KErrNone(r);
   746 	r=rbuf.CompareF(KTestData());
   747 	r=rbuf.CompareF(KTestData());
   747 	test(r==KErrNone);
   748 	test_KErrNone(r);
   748 	file1.Close();
   749 	file1.Close();
   749 
   750 
   750 	r=fs.MkDir(_L("C:\\mdir"));
   751 	r=fs.MkDir(_L("C:\\mdir"));
   751 	test(r==KErrNone || r==KErrAlreadyExists);
   752 	test_Value(r, r==KErrNone || r==KErrAlreadyExists);
   752 	
   753 	
   753 	// Check the number of open file handles - 
   754 	// Check the number of open file handles - 
   754 	// should be 1 (the one duplicated for the other process)
   755 	// should be 1 (the one duplicated for the other process)
   755 	resCount = fs.ResourceCount();
   756 	resCount = fs.ResourceCount();
   756 	test(resCount == 1);
   757 	test_Value(resCount, resCount == 1);
   757 
   758 
   758 	fs.Close();
   759 	fs.Close();
   759 
   760 
   760 	// Start the server thread
   761 	// Start the server thread
   761 	aProcess.Resume();
   762 	aProcess.Resume();
   767 	do
   768 	do
   768 		{
   769 		{
   769 		r=handsvr.Connect();
   770 		r=handsvr.Connect();
   770 		}
   771 		}
   771 	while(r==KErrNotFound);
   772 	while(r==KErrNotFound);
   772 	test(r==KErrNone);
   773 	test_KErrNone(r);
   773 
   774 
   774 
   775 
   775 	r=handsvr.SetTestDrive(drivenum);
   776 	r=handsvr.SetTestDrive(drivenum);
   776 	test(r==KErrNone);
   777 	test_KErrNone(r);
   777 
   778 
   778 	// wait for server to read the file
   779 	// wait for server to read the file
   779 	r = handsvr.PassFileHandleProcess();
   780 	r = handsvr.PassFileHandleProcess();
   780 	test (r == KErrNone);
   781 	test_KErrNone(r);
   781 	
   782 	
   782 	handsvr.Close();
   783 	handsvr.Close();
   783 	}
   784 	}
   784 
   785 
   785 
   786 
   789 	RFs::CharToDrive(gDriveToTest,drivenum);
   790 	RFs::CharToDrive(gDriveToTest,drivenum);
   790 
   791 
   791 	// make sure the session path exists
   792 	// make sure the session path exists
   792 	RFs fs;
   793 	RFs fs;
   793 	TInt r = fs.Connect();
   794 	TInt r = fs.Connect();
   794 	test(r==KErrNone);
   795 	test_KErrNone(r);
   795 
   796 
   796 	TFileName sessionp;
   797 	TFileName sessionp;
   797 	fs.SessionPath(sessionp);
   798 	fs.SessionPath(sessionp);
   798 	r = fs.MkDirAll(sessionp);
   799 	r = fs.MkDirAll(sessionp);
   799 	test(r==KErrNone || r==KErrAlreadyExists);
   800 	test_Value(r, r==KErrNone || r==KErrAlreadyExists);
   800 	fs.Close();
   801 	fs.Close();
   801 
   802 
   802 	// Remember the number of open handles. Just for a sanity check ....
   803 	// Remember the number of open handles. Just for a sanity check ....
   803 	TInt start_thc, start_phc;
   804 	TInt start_thc, start_phc;
   804 	RThread().HandleCount(start_phc, start_thc);
   805 	RThread().HandleCount(start_phc, start_thc);
   805 	test.Printf(_L("Handles: start_phc %d, start_thc %d\n"), start_phc, start_thc);
   806 	test.Printf(_L("Handles: start_phc %d, start_thc %d\n"), start_phc, start_thc);
   806 
   807 
   807 	//create test server
   808 	//create test server
   808 	RProcess p;
   809 	RProcess p;
   809 	r = p.Create(_L("FHServer.exe"), KNullDesC);
   810 	r = p.Create(_L("FHServer.exe"), KNullDesC);
   810 	test(r==KErrNone);
   811 	test_KErrNone(r);
   811 
   812 
   812 	// RFile::Duplicate() tests
   813 	// RFile::Duplicate() tests
   813 	Duplicate();
   814 	Duplicate();
   814 
   815 
   815 	// Pass RFs/RFile handles to the server using RFile::TransferToProcess()
   816 	// Pass RFs/RFile handles to the server using RFile::TransferToProcess()
   823 
   824 
   824 	
   825 	
   825 	// Get an open writeable file from FHServer2 via FHServer 
   826 	// Get an open writeable file from FHServer2 via FHServer 
   826 	// using RFile::AdoptFromServer()
   827 	// using RFile::AdoptFromServer()
   827 	RequestFileWrite();
   828 	RequestFileWrite();
   828 
       
   829 	// Deprecated RFile::Adopt() test
   829 	// Deprecated RFile::Adopt() test
   830 	RequestFileDeprecatedAdopt();
   830 	RequestFileDeprecatedAdopt();
   831 
   831 
   832 	// negative test 
   832 	// negative test 
   833 	// Pass an invalid file handle to the server 
   833 	// Pass an invalid file handle to the server 
   840 	RequestFileTest();
   840 	RequestFileTest();
   841 
   841 
   842 	// stop the servers
   842 	// stop the servers
   843 	RFileHandleSharer handsvr;
   843 	RFileHandleSharer handsvr;
   844 	r=handsvr.Connect();
   844 	r=handsvr.Connect();
   845 	test(r==KErrNone);
   845 	test_KErrNone(r);
   846 	r = handsvr.Exit();
   846 	r = handsvr.Exit();
   847 	test(r == KErrNone);
   847 	test_KErrNone(r);
   848 	handsvr.Close();
   848 	handsvr.Close();
   849 	
   849 	
   850 	// delete the test file
   850 	// delete the test file
   851 	RFs cleanupfs;
   851 	RFs cleanupfs;
   852 	r=cleanupfs.Connect();
   852 	r=cleanupfs.Connect();
   853 	test(r==KErrNone);
   853 	test_KErrNone(r);
   854 	r=cleanupfs.SetSessionToPrivate(drivenum);
   854 	r=cleanupfs.SetSessionToPrivate(drivenum);
   855 	test(r==KErrNone);
   855 	test_KErrNone(r);
   856 	r=cleanupfs.Delete(KCliFileName);
   856 	r=cleanupfs.Delete(KCliFileName);
   857 	test(r==KErrNone || r==KErrNotFound);
   857 	test_Value(r, r==KErrNone || r==KErrNotFound);
   858 	cleanupfs.Close();
   858 	cleanupfs.Close();
   859 
   859 
   860 
   860 
   861 	// wait for server process to end
   861 	// wait for server process to end
   862 	TRequestStatus status;
   862 	TRequestStatus status;
   870 	// Sanity check for open handles
   870 	// Sanity check for open handles
   871 	TInt end_thc, end_phc;
   871 	TInt end_thc, end_phc;
   872 	RThread().HandleCount(end_phc, end_thc);
   872 	RThread().HandleCount(end_phc, end_thc);
   873 	test.Printf(_L("Handles: end_phc %d, end_thc %d\n"), end_phc, end_thc);
   873 	test.Printf(_L("Handles: end_phc %d, end_thc %d\n"), end_phc, end_thc);
   874 
   874 
   875 	test(start_thc == end_thc);
   875 	test_Value(start_thc, start_thc == end_thc);
   876 	test(start_phc == end_phc);
   876 	test_Value(start_phc, start_phc == end_phc);
   877 	
   877 	
   878 	// and also for pending requests ...
   878 	// and also for pending requests ...
   879 	test(RThread().RequestCount() == 0);
   879 	test_Value(RThread().RequestCount(), RThread().RequestCount() == 0);
   880 	
   880 	
   881 	
   881 	
   882 	RDebug::Print(_L("End Of Tests"));
   882 	RDebug::Print(_L("End Of Tests"));
   883 	}
   883 	}
   884 	
   884