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