LOCAL_C void Test0(RTest& aTest) // // Scan for open files - no sessions // { aTest.Next(_L("Scan for open files with no sessions open")); CFileList* list; TOpenFileScan fileScan(TheFs); fileScan.NextL(list); if (list==NULL) return; TInt count=list->Count(); if (count==1) { gRunByBatch=ETrue; gBatchFile=(*list)[0].iName; delete list; fileScan.NextL(list); if (list==NULL) return; count=list->Count(); } while (count--) { TEntry entry=(*list)[count]; aTest.Printf(_L("%d) EntryName = %S\n"),count,&entry.iName); } //aTest.Printf(_L("Test will fail unless files are closed.\n")); //aTest.Printf(_L("Press any key ...\n")); //aTest.Getch(); }
LOCAL_C void Test1() // // This test is only called by default drive // Test OpenFileScan // { test.Next(_L("Scan for open files - one session only")); RFile file1,file2,file3; TFileName fn; fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; TInt r=file1.Open(TheFs,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FILE.CPP"); fn[0] = gExeFileName[0]; r=file2.Open(TheFs,fn,EFileRead); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file3.Open(TheFs,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); CFileList* list; TOpenFileScan fileScan(TheFs); fileScan.NextL(list); if (gRunByBatch) { test(list!=NULL); test(list->Count()==1); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L(".BAT"))>=0); delete list; fileScan.NextL(list); } test(list!=NULL); TInt count=list->Count(); test(count==3); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); entry=(*list)[1]; test(entry.iName.FindF(_L("T_FILE.CPP"))>=0); entry=(*list)[2]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); TThreadId threadId=fileScan.ThreadId(); RThread current; TThreadId currentId=current.Id(); test(threadId==currentId); delete list; fileScan.NextL(list); test(list==NULL); file1.Close(); file2.Close(); file3.Close(); }
LOCAL_C void Test4() // // Test openfilescan - rdirs, empty, full, empty rdirs. // { test.Next(_L("Scan for open files - check RDir sessions are ignored")); RFs fs1,fs2,fs3,fs4; TFileName fn; TInt r=fs1.Connect(); test(r==KErrNone); r=fs2.Connect(); test(r==KErrNone); r=fs3.Connect(); test(r==KErrNone); r=fs4.Connect(); test(r==KErrNone); RDir dir1,dir2,dir3,dir4; fn = _L("Z:\\TEST\\*.XDE"); fn[0] = gExeFileName[0]; r=dir1.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir2.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir3.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir4.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); RFile file1,file2,file3; fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file1.Open(fs2,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FILE.CPP"); fn[0] = gExeFileName[0]; r=file2.Open(fs2,fn,EFileRead); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file3.Open(fs2,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); RDir dir5,dir6,dir7,dir8; fn = _L("Z:\\TEST\\*.XDE"); fn[0] = gExeFileName[0]; r=dir5.Open(fs4,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir6.Open(fs4,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir7.Open(fs4,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir8.Open(fs4,fn,KEntryAttMaskSupported); test(r==KErrNone); CFileList* list; TOpenFileScan fileScan(TheFs); fileScan.NextL(list); if (gRunByBatch) { test(list!=NULL); test(list->Count()==1); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L(".BAT"))>=0); delete list; fileScan.NextL(list); } test(list!=NULL); TInt count=list->Count(); test(count==3); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); entry=(*list)[1]; test(entry.iName.FindF(_L("T_FILE.CPP"))>=0); entry=(*list)[2]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); TThreadId threadId=fileScan.ThreadId(); RThread current; TThreadId currentId=current.Id(); test(threadId==currentId); delete list; fileScan.NextL(list); test(list==NULL); file1.Close(); file2.Close(); file3.Close(); dir1.Close(); dir2.Close(); dir3.Close(); dir4.Close(); dir5.Close(); dir6.Close(); dir7.Close(); dir8.Close(); fs1.Close(); fs2.Close(); fs3.Close(); fs4.Close(); }
LOCAL_C void Test5() // // Test OpenFileScan // { test.Next(_L("Scan for open files - mixed RDirs and RFiles")); RFile file1,file2,file3; TFileName fn; fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; TInt r=file1.Open(TheFs,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FILE.CPP"); fn[0] = gExeFileName[0]; r=file2.Open(TheFs,fn,EFileRead); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file3.Open(TheFs,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); RDir dir1,dir2,dir3,dir4; fn = _L("Z:\\TEST\\*.XDE"); fn[0] = gExeFileName[0]; r=dir1.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir2.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir3.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir4.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); CFileList* list; TOpenFileScan fileScan(TheFs); fileScan.NextL(list); if (gRunByBatch) { test(list!=NULL); test(list->Count()==1); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L(".BAT"))>=0); delete list; fileScan.NextL(list); } test(list!=NULL); TInt count=list->Count(); test(count==3); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); entry=(*list)[1]; test(entry.iName.FindF(_L("T_FILE.CPP"))>=0); entry=(*list)[2]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); TThreadId threadId=fileScan.ThreadId(); RThread current; TThreadId currentId=current.Id(); test(threadId==currentId); delete list; fileScan.NextL(list); test(list==NULL); file1.Close(); file2.Close(); file3.Close(); dir1.Close(); dir2.Close(); dir3.Close(); dir4.Close(); }
LOCAL_C void Test3() // // Test openfilescan - empty, full, empty full // { test.Next(_L("Scan for open files - multiple sessions")); RFs fs1,fs2,fs3,fs4; TInt r=fs1.Connect(); test(r==KErrNone); r=fs2.Connect(); test(r==KErrNone); r=fs3.Connect(); test(r==KErrNone); r=fs4.Connect(); test(r==KErrNone); RFile file1,file2,file3; TFileName fn; fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file1.Open(fs2,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FILE.CPP"); fn[0] = gExeFileName[0]; r=file2.Open(fs2,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file3.Open(fs2,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); r=file1.Open(fs4,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FILE.CPP"); fn[0] = gExeFileName[0]; r=file2.Open(fs4,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file3.Open(fs4,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); CFileList* list; TOpenFileScan fileScan(TheFs); fileScan.NextL(list); if (gRunByBatch) { test(list!=NULL); test(list->Count()==1); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L(".BAT"))>=0); delete list; fileScan.NextL(list); } test(list!=NULL); TInt count=list->Count(); test(count==3); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); entry=(*list)[1]; test(entry.iName.FindF(_L("T_FILE.CPP"))>=0); entry=(*list)[2]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); TThreadId threadId=fileScan.ThreadId(); RThread current; TThreadId currentId=current.Id(); test(threadId==currentId); delete list; fileScan.NextL(list); test(list!=NULL); count=list->Count(); test(count==3); entry=(*list)[0]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); entry=(*list)[1]; test(entry.iName.FindF(_L("T_FILE.CPP"))>=0); entry=(*list)[2]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); threadId=fileScan.ThreadId(); currentId=current.Id(); test(threadId==currentId); delete list; fileScan.NextL(list); test(list==NULL); file1.Close(); file2.Close(); file3.Close(); fs1.Close(); fs2.Close(); fs3.Close(); fs4.Close(); }