sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\server\b_osfil.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: sl@0: const TInt KSizeExistsFile=26; sl@0: const TInt KSizeExistsFile2=25; sl@0: sl@0: GLDEF_D RTest test(_L("B_OSFIL")); sl@0: sl@0: /* these buffers get written to in order to change the file system */ sl@0: //LOCAL_D TBuf<5> fileSystemName =_L("LOC::"); /* default file system name */ sl@0: LOCAL_D TBuf<20> noDevice = _L("L:\\tmpfile.tmp"); sl@0: LOCAL_D TBuf<15> noDevicePath = _L("L:\\"); sl@0: LOCAL_D TBuf<28> noDirectory = _L("C:\\nodirect\\tmpfile.tmp"); sl@0: LOCAL_D TBuf<30> noDirectoryPath = _L("C:\\nodirect\\"); sl@0: LOCAL_D TBuf<20> noFile = _L("C:\\notafile.tmp"); sl@0: LOCAL_D TBuf<19> fileName = _L("C:\\tmpfile.tmp"); sl@0: LOCAL_D TBuf<20> existsFile = _L("C:\\tmpexst1.tmp"); sl@0: LOCAL_D TBuf<20> existsFile2 = _L("C:\\tmpexst2.tmp"); sl@0: LOCAL_D TBuf<21> renameFile1 = _L("C:\\tmpren1.tmp"); sl@0: LOCAL_D TBuf<21> renameFile2 = _L("C:\\tmpren2.tmp"); sl@0: LOCAL_D TBuf<34> directoryFile = _L("C:\\nodirect\\nodirect\\nodirect\\"); sl@0: LOCAL_D TBuf<14> openUniqueDir = _L("C:\\nodir2\\"); sl@0: sl@0: /*************************************************************************/ sl@0: LOCAL_C void TestInfo() sl@0: /* sl@0: Test the file info function sl@0: */ sl@0: { sl@0: TEntry entry; sl@0: TInt r=TheFs.Entry(noDevice,entry); sl@0: test((r==KErrNotReady)||(r==KErrPathNotFound)); sl@0: r=TheFs.Entry(noDirectory,entry); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.Entry(noFile,entry); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Entry(existsFile,entry); sl@0: test(r==KErrNone); sl@0: test(entry.iSize==KSizeExistsFile); sl@0: test(!entry.IsDir()); sl@0: test(!(entry.iAtt&KEntryAttDir)); sl@0: r=TheFs.Entry(existsFile2,entry); sl@0: test(r==KErrNone); sl@0: test(entry.iSize==KSizeExistsFile2); sl@0: test(!entry.IsDir()); sl@0: test(!(entry.iAtt&KEntryAttDir)); sl@0: } sl@0: sl@0: LOCAL_C void TestDelete() sl@0: /* sl@0: Test the delete sl@0: */ sl@0: { sl@0: TInt r=TheFs.Delete(noDevice); sl@0: test((r==KErrNotReady)||(r==KErrPathNotFound)); sl@0: r=TheFs.Delete(noDirectory); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.Delete(noFile); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Delete(existsFile); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(existsFile2); sl@0: test(r==KErrNone); sl@0: TEntry entry; sl@0: r=TheFs.Entry(existsFile,entry); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Entry(existsFile2,entry); sl@0: test(r==KErrNotFound); sl@0: } sl@0: sl@0: LOCAL_C void TestRename() sl@0: /* sl@0: Test the rename sl@0: */ sl@0: { sl@0: TInt r=TheFs.Rename(noDevice,fileName); sl@0: test(r==KErrArgument); sl@0: r=TheFs.Rename(noDirectory,fileName); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.Rename(noFile,fileName); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Rename(existsFile,existsFile2); sl@0: test(r==KErrAlreadyExists); sl@0: r=TheFs.Delete(existsFile); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(existsFile,existsFile); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Rename(existsFile2,existsFile); sl@0: test(r==KErrNone); sl@0: TEntry entry; sl@0: r=TheFs.Entry(existsFile2,entry); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Entry(existsFile,entry); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(existsFile); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void TestMkDir() sl@0: { sl@0: TParse fparse; sl@0: TInt r=TheFs.MkDirAll(directoryFile); sl@0: test(r==KErrNone); sl@0: TEntry entry; sl@0: r=TheFs.Entry(directoryFile.Left(directoryFile.Length()-1),entry); sl@0: test(r==KErrNone); sl@0: test(entry.IsDir()); sl@0: test(entry.iAtt&KEntryAttDir); sl@0: r=TheFs.RmDir(directoryFile); sl@0: test(r==KErrNone); sl@0: r=fparse.Set(directoryFile,NULL,NULL); sl@0: test(r==KErrNone); sl@0: r=fparse.PopDir(); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(fparse.DriveAndPath()); sl@0: test(r==KErrNone); sl@0: r=fparse.PopDir(); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(fparse.DriveAndPath()); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void TestOpenUnique() sl@0: /* sl@0: Test unique file name generator sl@0: */ sl@0: { sl@0: RFile p1; sl@0: RFile p2; sl@0: sl@0: TInt r=p1.Open(TheFs,noDevice,EFileStreamText); sl@0: test((r==KErrNotReady)||(r==KErrPathNotFound)); sl@0: r=p1.Open(TheFs,noDirectory,EFileStreamText); sl@0: test(r==KErrPathNotFound); sl@0: TFileName generated1; sl@0: r=p1.Temp(TheFs,noDevicePath,generated1,EFileStreamText); sl@0: test((r==KErrNotReady)||(r==KErrPathNotFound)); sl@0: r=p1.Temp(TheFs,noDirectoryPath,generated1,EFileStreamText); sl@0: test(r==KErrPathNotFound); sl@0: sl@0: r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText); sl@0: test(r==KErrNone); sl@0: TFileName generated2; sl@0: r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText); sl@0: test(r==KErrNone); sl@0: test(generated1!=generated2); sl@0: p1.Close(); sl@0: TFileName generated3; sl@0: r=p1.Temp(TheFs,_L(""),generated3,EFileStream); sl@0: test(r==KErrNone); sl@0: test(generated3!=generated2); sl@0: test(generated3!=generated1); sl@0: p2.Close(); sl@0: p1.Close(); sl@0: sl@0: r=TheFs.Delete(generated1); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(generated2); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(generated3); sl@0: test(r==KErrNone); sl@0: sl@0: r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText); sl@0: test(r==KErrNone); sl@0: r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText); sl@0: test(r==KErrNone); sl@0: test(generated1!=generated2); sl@0: p1.Close(); sl@0: r=p1.Temp(TheFs,_L(""),generated3,EFileStream); sl@0: test(r==KErrNone); sl@0: test(generated3!=generated2); sl@0: test(generated3!=generated1); sl@0: p2.Close(); sl@0: p1.Close(); sl@0: sl@0: r=TheFs.Delete(generated1); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(generated2); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(generated3); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.MkDir(openUniqueDir); sl@0: test(r==KErrNone); sl@0: r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream); sl@0: test(r==KErrNone); sl@0: r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText|EFileWrite); sl@0: test(r==KErrNone); sl@0: r=p1.Write(_L8("junk"),4); sl@0: test(r==KErrNone); sl@0: TInt pos=0; sl@0: r=p1.Seek(ESeekCurrent,pos);//P_FSET sl@0: test(r==KErrNone); sl@0: p1.Close(); sl@0: p2.Close(); sl@0: sl@0: r=TheFs.Delete(generated1); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(generated2); sl@0: test(r==KErrNone); sl@0: sl@0: r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream); sl@0: test(r==KErrNone); sl@0: r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText); sl@0: test(r==KErrNone); sl@0: p1.Close(); sl@0: sl@0: pos=0; sl@0: r=p2.Seek(ESeekStart,pos); sl@0: test(r==KErrNone); sl@0: p2.Close(); sl@0: r=TheFs.Delete(generated1); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(generated2); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(openUniqueDir); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void TestPaths() sl@0: { sl@0: TFileName path1; sl@0: TInt r=TheFs.SessionPath(path1); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetSessionPath(path1); sl@0: test(r==KErrNone); sl@0: TFileName path2; sl@0: r=TheFs.SessionPath(path2); sl@0: test(r==KErrNone); sl@0: test(path1==path2); sl@0: RDir dir; sl@0: r=dir.Open(TheFs,path1,0); sl@0: test(r==KErrNone); sl@0: dir.Close(); sl@0: } sl@0: sl@0: LOCAL_C void TestFileStatus() sl@0: { sl@0: TEntry blk; sl@0: TInt r=TheFs.Entry(existsFile,blk); sl@0: test(r==KErrNone); sl@0: TEntry blk1=blk; sl@0: sl@0: /* Toggle the write attribute */ sl@0: TUint clear,set; /* were modifying write attrib */ sl@0: if (blk1.IsReadOnly()) sl@0: { sl@0: clear=KEntryAttReadOnly; sl@0: set=0; sl@0: } sl@0: else sl@0: { sl@0: clear=0; sl@0: set=KEntryAttReadOnly; sl@0: } sl@0: r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(existsFile,blk); sl@0: test(r==KErrNone); sl@0: if (blk1.IsReadOnly()) sl@0: test(!blk.IsReadOnly()); sl@0: else sl@0: test(blk.IsReadOnly()); sl@0: sl@0: /* set write attrib back */ sl@0: r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(existsFile,blk); sl@0: test(r==KErrNone); sl@0: if (blk1.IsReadOnly()) sl@0: test(blk.IsReadOnly()); sl@0: else sl@0: test(!blk.IsReadOnly()); sl@0: sl@0: /* toggle the archive bit */ sl@0: if (blk1.IsArchive()) sl@0: { sl@0: clear=KEntryAttArchive; sl@0: set=0; sl@0: } sl@0: else sl@0: { sl@0: clear=0; sl@0: set=KEntryAttArchive; sl@0: } sl@0: r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(existsFile,blk); sl@0: test(r==KErrNone); sl@0: if (blk1.IsArchive()) sl@0: test(!blk.IsArchive()); sl@0: else sl@0: test(blk.IsArchive()); sl@0: /* set archive attrib back */ sl@0: r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(existsFile,blk); sl@0: test(r==KErrNone); sl@0: if (blk1.IsArchive()) sl@0: test(blk.IsArchive()); sl@0: else sl@0: test(!blk.IsArchive()); sl@0: sl@0: /* toggle the hidden bit */ sl@0: if (blk1.IsHidden()) sl@0: { sl@0: clear=KEntryAttHidden; sl@0: set=0; sl@0: } sl@0: else sl@0: { sl@0: clear=0; sl@0: set=KEntryAttHidden; sl@0: } sl@0: r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(existsFile,blk); sl@0: test(r==KErrNone); sl@0: if (blk1.IsHidden()) sl@0: test(!blk.IsHidden()); sl@0: else sl@0: test(blk.IsHidden()); sl@0: /* set hidden attrib back */ sl@0: r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(existsFile,blk); sl@0: test(r==KErrNone); sl@0: if (blk1.IsHidden()) sl@0: test(blk.IsHidden()); sl@0: else sl@0: test(!blk.IsHidden()); sl@0: sl@0: /* toggle the system bit */ sl@0: if (blk1.IsSystem()) sl@0: { sl@0: clear=KEntryAttSystem; sl@0: set=0; sl@0: } sl@0: else sl@0: { sl@0: clear=0; sl@0: set=KEntryAttSystem; sl@0: } sl@0: r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(existsFile,blk); sl@0: test(r==KErrNone); sl@0: if (blk1.IsSystem()) sl@0: test(!blk.IsSystem()); sl@0: else sl@0: test(blk.IsSystem()); sl@0: /* set system attrib back */ sl@0: r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(existsFile,blk); sl@0: test(r==KErrNone); sl@0: if (blk1.IsSystem()) sl@0: test(blk.IsSystem()); sl@0: else sl@0: test(!blk.IsSystem()); sl@0: r=TheFs.Delete(existsFile); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(existsFile2); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void CreateTestFiles() sl@0: { sl@0: RFile fcb; sl@0: TInt r=fcb.Replace(TheFs,existsFile,EFileWrite); sl@0: test(r==KErrNone); sl@0: r=fcb.Write(_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),KSizeExistsFile); sl@0: test(r==KErrNone); sl@0: fcb.Close(); sl@0: sl@0: r=fcb.Replace(TheFs,existsFile2,EFileWrite); sl@0: test(r==KErrNone); sl@0: r=fcb.Write(_L8("bcdefghijklmnopqrstuvwxyz"),KSizeExistsFile2); sl@0: test(r==KErrNone); sl@0: fcb.Close(); sl@0: } sl@0: sl@0: GLDEF_C void CallTestsL(void) sl@0: // sl@0: // Do testing on aDrive sl@0: // sl@0: { sl@0: test.Title(); sl@0: sl@0: TVolumeInfo di; sl@0: TInt r=TheFs.Volume(di); sl@0: test(r==KErrNone); sl@0: test.Start(_L("Info()")); sl@0: CreateTestFiles(); sl@0: TestInfo(); sl@0: test.Next(_L("Delete()")); sl@0: CreateTestFiles(); sl@0: TestDelete(); sl@0: test.Next(_L("Rename()")); sl@0: CreateTestFiles(); sl@0: TestRename(); sl@0: test.Next(_L("MkDir()")); sl@0: TestMkDir(); sl@0: test.Next(_L("Temp()")); sl@0: TestOpenUnique(); sl@0: test.Next(_L("Paths")); sl@0: TestPaths(); sl@0: test.Next(_L("File status")); sl@0: CreateTestFiles(); sl@0: TestFileStatus(); sl@0: test.End(); sl@0: }