149 case RFileHandleSharer::EMsgExit: |
150 case RFileHandleSharer::EMsgExit: |
150 { |
151 { |
151 // stop server2 |
152 // stop server2 |
152 RFileHandleSharer2 handsvr2; |
153 RFileHandleSharer2 handsvr2; |
153 TInt r=handsvr2.Connect(); |
154 TInt r=handsvr2.Connect(); |
154 test(r==KErrNone); |
155 test_KErrNone(r); |
155 r = handsvr2.Exit(); |
156 r = handsvr2.Exit(); |
156 test(r==KErrNone || r == KErrServerTerminated); |
157 test_Value(r, r ==KErrNone || r == KErrServerTerminated); |
157 handsvr2.Close(); |
158 handsvr2.Close(); |
158 |
159 |
159 aMessage.Complete(KErrNone); |
160 aMessage.Complete(KErrNone); |
160 |
161 |
161 CActiveScheduler::Stop(); |
162 CActiveScheduler::Stop(); |
188 TInt fileMode = aMsg.Int1(); |
189 TInt fileMode = aMsg.Int1(); |
189 |
190 |
190 RFs fs; |
191 RFs fs; |
191 TInt r=fs.Connect(); |
192 TInt r=fs.Connect(); |
192 r=fs.CreatePrivatePath(gTestDrive); |
193 r=fs.CreatePrivatePath(gTestDrive); |
193 test(r==KErrNone); |
194 test_KErrNone(r); |
194 r=fs.SetSessionToPrivate(gTestDrive); |
195 r=fs.SetSessionToPrivate(gTestDrive); |
195 test(r==KErrNone); |
196 test_KErrNone(r); |
196 r=fs.ShareProtected(); |
197 r=fs.ShareProtected(); |
197 test(r==KErrNone); |
198 test_KErrNone(r); |
198 RFile file1; |
199 RFile file1; |
199 r=file1.Create(fs,KSvrFileName,EFileWrite); |
200 r=file1.Create(fs,KSvrFileName,EFileWrite); |
200 test(r==KErrNone || r==KErrAlreadyExists); |
201 test_Value(r, r ==KErrNone || r==KErrAlreadyExists); |
201 if (r==KErrAlreadyExists) |
202 if (r==KErrAlreadyExists) |
202 { |
203 { |
203 r=file1.Open(fs,KSvrFileName, EFileWrite); |
204 r=file1.Open(fs,KSvrFileName, EFileWrite); |
204 test(r==KErrNone); |
205 test_KErrNone(r); |
205 } |
206 } |
206 r=file1.Write(KTestData1()); |
207 r=file1.Write(KTestData1()); |
207 test(r==KErrNone); |
208 test_KErrNone(r); |
208 file1.Close(); |
209 file1.Close(); |
209 |
210 |
210 r=file1.Open(fs,KSvrFileName, fileMode); |
211 r=file1.Open(fs,KSvrFileName, fileMode); |
211 test(r==KErrNone); |
212 test_KErrNone(r); |
212 |
213 |
213 TInt fssh=file1.SubSessionHandle(); |
214 TInt fssh=file1.SubSessionHandle(); |
214 r=aMsg.Write(0, TPckgC<TInt>(fssh)); |
215 r=aMsg.Write(0, TPckgC<TInt>(fssh)); |
215 test(r==KErrNone); |
216 test_KErrNone(r); |
216 aMsg.Complete(fs); |
217 aMsg.Complete(fs); |
217 fs.Close(); |
218 fs.Close(); |
218 } |
219 } |
219 |
220 |
220 // |
221 // |
230 // get the requested file mode |
231 // get the requested file mode |
231 TInt fileMode = aMsg.Int1(); |
232 TInt fileMode = aMsg.Int1(); |
232 |
233 |
233 RFileHandleSharer2 handsvr2; |
234 RFileHandleSharer2 handsvr2; |
234 TInt r = handsvr2.Connect(); |
235 TInt r = handsvr2.Connect(); |
235 test(r==KErrNone); |
236 test_KErrNone(r); |
236 |
237 |
237 TInt ssh; |
238 TInt ssh; |
238 TInt fsh = handsvr2.GetFileHandle(ssh, TFileMode(fileMode)); |
239 TInt fsh = handsvr2.GetFileHandle(ssh, TFileMode(fileMode)); |
239 test(fsh >= 0); |
240 test_Value(fsh, fsh >= 0); |
240 |
241 |
241 // adopt the file from FHServer2 |
242 // adopt the file from FHServer2 |
242 RFile file; |
243 RFile file; |
243 r=file.AdoptFromServer(fsh, ssh); |
244 r=file.AdoptFromServer(fsh, ssh); |
244 test(r==KErrNone); |
245 test_KErrNone(r); |
245 |
246 |
246 test.Next(_L("RFile::TransferToClient()")); |
247 test.Next(_L("RFile::TransferToClient()")); |
247 |
248 |
248 // transfer the file to the client |
249 // transfer the file to the client |
249 r = file.TransferToClient(aMsg, 0); |
250 r = file.TransferToClient(aMsg, 0); |
250 test(r==KErrNone); |
251 test_KErrNone(r); |
251 |
252 |
252 // test we can still use the file |
253 // test we can still use the file |
253 TInt pos = 0; |
254 TInt pos = 0; |
254 r = file.Seek(ESeekStart, pos); |
255 r = file.Seek(ESeekStart, pos); |
255 test(r==KErrNone); |
256 test_KErrNone(r); |
256 TBuf8<100> rbuf; |
257 TBuf8<100> rbuf; |
257 r=file.Read(0,rbuf); |
258 r=file.Read(0,rbuf); |
258 test(r==KErrNone); |
259 test_KErrNone(r); |
259 r=rbuf.CompareF(KTestData1()); |
260 r=rbuf.CompareF(KTestData1()); |
260 test(r==KErrNone); |
261 test_KErrNone(r); |
261 |
262 |
262 handsvr2.Close(); |
263 handsvr2.Close(); |
263 |
264 |
264 file.Close(); |
265 file.Close(); |
265 |
266 |
275 test.Next(_L("RFile::AdoptFromClient()")); |
276 test.Next(_L("RFile::AdoptFromClient()")); |
276 |
277 |
277 // connect to FHServer2 |
278 // connect to FHServer2 |
278 RFileHandleSharer2 handsvr2; |
279 RFileHandleSharer2 handsvr2; |
279 TInt r = handsvr2.Connect(); |
280 TInt r = handsvr2.Connect(); |
280 test(r==KErrNone); |
281 test_KErrNone(r); |
281 |
282 |
282 RFile file; |
283 RFile file; |
283 |
284 |
284 // Message slot 0 is a RFs handle |
285 // Message slot 0 is a RFs handle |
285 // Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle()) |
286 // Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle()) |
286 r = file.AdoptFromClient(aMsg, 0, 1); |
287 r = file.AdoptFromClient(aMsg, 0, 1); |
287 test(r==KErrNone); |
288 test_KErrNone(r); |
288 |
289 |
289 |
290 |
290 |
291 |
291 TBuf8<100> rbuf; |
292 TBuf8<100> rbuf; |
292 r=file.Read(0,rbuf); |
293 r=file.Read(0,rbuf); |
293 test(r==KErrNone); |
294 test_KErrNone(r); |
294 r=rbuf.CompareF(KTestData()); |
295 r=rbuf.CompareF(KTestData()); |
295 test(r==KErrNone); |
296 test_KErrNone(r); |
296 r=file.Write(KTestData1()); |
297 r=file.Write(KTestData1()); |
297 test(r==KErrAccessDenied); |
298 test_Value(r, r ==KErrAccessDenied); |
298 r=file.ChangeMode(EFileWrite); |
299 r=file.ChangeMode(EFileWrite); |
299 test(r==KErrArgument); |
300 test_Value(r, r ==KErrArgument); |
300 r=file.Rename(_L("\\newname.txt")); |
301 r=file.Rename(_L("\\newname.txt")); |
301 test(r==KErrPermissionDenied || r==KErrAccessDenied); |
302 test_Value(r, r ==KErrPermissionDenied || r==KErrAccessDenied); |
302 // should try a delete |
303 // should try a delete |
303 |
304 |
304 // pass the file handle to FHServer2 |
305 // pass the file handle to FHServer2 |
305 test.Next(_L("RFile::TransferToServer()")); |
306 test.Next(_L("RFile::TransferToServer()")); |
306 |
307 |
307 TIpcArgs ipcArgs; |
308 TIpcArgs ipcArgs; |
308 file.TransferToServer(ipcArgs, 0, 1); |
309 file.TransferToServer(ipcArgs, 0, 1); |
309 r = handsvr2.PassFileHandle(ipcArgs); |
310 r = handsvr2.PassFileHandle(ipcArgs); |
310 test(r==KErrNone); |
311 test_KErrNone(r); |
311 |
312 |
312 TInt pos = 0; |
313 TInt pos = 0; |
313 r = file.Seek(ESeekStart, pos); |
314 r = file.Seek(ESeekStart, pos); |
314 test(r==KErrNone); |
315 test_KErrNone(r); |
315 r=file.Read(0,rbuf); |
316 r=file.Read(0,rbuf); |
316 test(r==KErrNone); |
317 test_KErrNone(r); |
317 r=rbuf.CompareF(KTestData()); |
318 r=rbuf.CompareF(KTestData()); |
318 test(r==KErrNone); |
319 test_KErrNone(r); |
319 |
320 |
320 file.Close(); |
321 file.Close(); |
321 |
322 |
322 handsvr2.Close(); |
323 handsvr2.Close(); |
323 |
324 |
332 { |
333 { |
333 test.Next(_L("RFile::AdoptFromCreator()")); |
334 test.Next(_L("RFile::AdoptFromCreator()")); |
334 |
335 |
335 RFile file; |
336 RFile file; |
336 TInt r = file.AdoptFromCreator(1, 2); |
337 TInt r = file.AdoptFromCreator(1, 2); |
337 test(r == KErrNone); |
338 test_KErrNone(r); |
338 |
339 |
339 TBuf8<100> rbuf; |
340 TBuf8<100> rbuf; |
340 r=file.Read(0,rbuf); |
341 r=file.Read(0,rbuf); |
341 test(r==KErrNone); |
342 test_KErrNone(r); |
342 r=rbuf.CompareF(KTestData()); |
343 r=rbuf.CompareF(KTestData()); |
343 test(r==KErrNone); |
344 test_KErrNone(r); |
344 |
345 |
345 test.Next(_L("RFile::Rename()")); |
346 test.Next(_L("RFile::Rename()")); |
346 |
347 |
347 // define a filename in our private path |
348 // define a filename in our private path |
348 RFs fs; |
349 RFs fs; |
349 r=fs.Connect(); |
350 r=fs.Connect(); |
350 test(r==KErrNone); |
351 test_KErrNone(r); |
351 |
352 |
352 TFileName sessionp; |
353 TFileName sessionp; |
353 fs.SessionPath(sessionp); |
354 fs.SessionPath(sessionp); |
354 r = fs.MkDirAll(sessionp); |
355 r = fs.MkDirAll(sessionp); |
355 test(r==KErrNone || r==KErrAlreadyExists); |
356 test_Value(r, r ==KErrNone || r==KErrAlreadyExists); |
356 |
357 |
357 r=fs.ShareProtected(); |
358 r=fs.ShareProtected(); |
358 test(r==KErrNone); |
359 test_KErrNone(r); |
359 |
360 |
360 r=fs.CreatePrivatePath(gTestDrive); |
361 r=fs.CreatePrivatePath(gTestDrive); |
361 test(r==KErrNone); |
362 test_KErrNone(r); |
362 r=fs.SetSessionToPrivate(gTestDrive); |
363 r=fs.SetSessionToPrivate(gTestDrive); |
363 test(r==KErrNone); |
364 test_KErrNone(r); |
364 |
365 |
365 TPath newPath; |
366 TPath newPath; |
366 fs.PrivatePath(newPath); |
367 fs.PrivatePath(newPath); |
367 TFileName newFileName; |
368 TFileName newFileName; |
368 newFileName = newPath; |
369 newFileName = newPath; |
369 newFileName.Append(_L("newname.txt")); |
370 newFileName.Append(_L("newname.txt")); |
370 |
371 |
371 // delete the file before we try to rename anything to it |
372 // delete the file before we try to rename anything to it |
372 r = fs.Delete(newFileName); |
373 r = fs.Delete(newFileName); |
373 test(r == KErrNone || r == KErrNotFound); |
374 test_Value(r, r == KErrNone || r == KErrNotFound); |
374 |
375 |
375 r=file.Rename(newFileName); |
376 r=file.Rename(newFileName); |
376 test(r==KErrNone); |
377 test_KErrNone(r); |
377 |
378 |
378 file.Close(); |
379 file.Close(); |
379 |
380 |
380 // Next verify that we can delete the file (which should now |
381 // Next verify that we can delete the file (which should now |
381 // have been moved to our private directory) |
382 // have been moved to our private directory) |
382 test.Next(_L("RFs::Delete()")); |
383 test.Next(_L("RFs::Delete()")); |
383 r = fs.Delete(newFileName); |
384 r = fs.Delete(newFileName); |
384 test(r == KErrNone); |
385 test_KErrNone(r); |
385 |
386 |
386 fs.Close(); |
387 fs.Close(); |
387 |
388 |
388 |
389 |
389 aMsg.Complete(KErrNone); |
390 aMsg.Complete(KErrNone); |
400 RFile file; |
401 RFile file; |
401 |
402 |
402 // Message slot 0 is a RFs handle |
403 // Message slot 0 is a RFs handle |
403 // Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle()) |
404 // Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle()) |
404 TInt r = file.AdoptFromClient(aMsg, 0, 1); |
405 TInt r = file.AdoptFromClient(aMsg, 0, 1); |
405 test(r==KErrBadHandle); |
406 test_Value(r, r ==KErrBadHandle); |
406 |
407 |
407 |
408 |
408 aMsg.Complete(r); |
409 aMsg.Complete(r); |
409 } |
410 } |
410 |
411 |
645 delete cleanup; |
646 delete cleanup; |
646 |
647 |
647 // Sanity check for open handles |
648 // Sanity check for open handles |
648 TInt end_thc, end_phc; |
649 TInt end_thc, end_phc; |
649 RThread().HandleCount(end_phc, end_thc); |
650 RThread().HandleCount(end_phc, end_thc); |
650 test(start_thc == end_thc); |
651 test_Value(start_thc, start_thc == end_thc); |
651 // test(start_phc == end_phc); |
652 // test(start_phc == end_phc); |
652 // and also for pending requests ... |
653 // and also for pending requests ... |
653 test(RThread().RequestCount() == 0); |
654 test_Value(RThread().RequestCount(), RThread().RequestCount() == 0); |
654 |
655 |
655 |
656 |
656 return KErrNone; |
657 return KErrNone; |
657 } |
658 } |
658 |
659 |
687 test.Start(_L("Starting tests...")); |
688 test.Start(_L("Starting tests...")); |
688 |
689 |
689 // start server2 in a seperate thread |
690 // start server2 in a seperate thread |
690 RThread server2Thread; |
691 RThread server2Thread; |
691 TInt r = server2Thread.Create(_L("FHServer2"), FHServer2, KDefaultStackSize, KHeapSize, KHeapSize, NULL); |
692 TInt r = server2Thread.Create(_L("FHServer2"), FHServer2, KDefaultStackSize, KHeapSize, KHeapSize, NULL); |
692 test(r==KErrNone); |
693 test_KErrNone(r); |
693 TRequestStatus statq; |
694 TRequestStatus statq; |
694 server2Thread.Logon(statq); |
695 server2Thread.Logon(statq); |
695 server2Thread.Resume(); |
696 server2Thread.Resume(); |
696 |
697 |
697 CActiveScheduler::Start(); |
698 CActiveScheduler::Start(); |
698 |
699 |
699 |
700 |
700 // wait for server2's thread to end gracefully |
701 // wait for server2's thread to end gracefully |
701 User::WaitForRequest(statq); |
702 User::WaitForRequest(statq); |
702 test(statq == KErrNone); |
703 test_KErrNone(statq.Int()); |
703 |
704 |
704 server2Thread.Close(); |
705 server2Thread.Close(); |
705 |
706 |
706 RFs cleanupfs; |
707 RFs cleanupfs; |
707 r = cleanupfs.Connect(); |
708 r = cleanupfs.Connect(); |
708 test(r==KErrNone); |
709 test_KErrNone(r); |
709 r=cleanupfs.SetSessionToPrivate(gTestDrive); |
710 r=cleanupfs.SetSessionToPrivate(gTestDrive); |
710 test(r==KErrNone); |
711 test_KErrNone(r); |
711 r=cleanupfs.Delete(KSvrFileName); |
712 r=cleanupfs.Delete(KSvrFileName); |
712 test(r==KErrNone || r==KErrNotFound); |
713 test_Value(r, r ==KErrNone || r==KErrNotFound); |
713 cleanupfs.Close(); |
714 cleanupfs.Close(); |
714 |
715 |
715 |
716 |
716 test.End(); |
717 test.End(); |
717 |
718 |
720 delete cleanup; |
721 delete cleanup; |
721 |
722 |
722 // Sanity check for open handles and pending requests |
723 // Sanity check for open handles and pending requests |
723 TInt end_thc, end_phc; |
724 TInt end_thc, end_phc; |
724 RThread().HandleCount(end_phc, end_thc); |
725 RThread().HandleCount(end_phc, end_thc); |
725 test(start_thc == end_thc); |
726 test_Value(start_thc, start_thc == end_thc); |
726 test(start_phc == end_phc); |
727 test_Value(start_phc, start_phc == end_phc); |
727 test(RThread().RequestCount() == 0); |
728 test_Value(RThread().RequestCount(), RThread().RequestCount() == 0); |
728 |
729 |
729 return 0; |
730 return 0; |
730 } |
731 } |