sl@0: // Copyright (c) 1995-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: // sl@0: sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: #include "t_chlffs.h" sl@0: sl@0: GLDEF_D RTest test(_L("T_NMBS")); sl@0: sl@0: LOCAL_C void testMkDirRmDir() sl@0: // sl@0: // Test the MkDir functions. sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test MkDir")); sl@0: sl@0: TInt r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\TNMBS\\TEST\\")); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\TNMBS\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\TNMBS\\TEST\\")); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Test RmDir 1.0")); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\TEST\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\")); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Test MkDirAll 1.0")); sl@0: r=TheFs.MkDirAll(_L("\\F32-TST\\TNMBS\\TEST\\")); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Test RmDir 2.0")); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\TEST\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\")); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Test MkDirAll 2.0")); sl@0: r=TheFs.MkDirAll(_L("\\F32-TST\\TNMBS\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.MkDirAll(_L("\\F32-TST\\TNMBS\\TEST\\")); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Test RmDir 3.0")); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\TEST\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\")); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Test mkdir and rmdir on root")); sl@0: r=TheFs.RmDir(_L("\\File.TXT")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.MkDir(_L("\\asdf.ere")); sl@0: test(r==KErrAlreadyExists); sl@0: r=TheFs.MkDirAll(_L("\\asdf.ere")); sl@0: test(r==KErrAlreadyExists); sl@0: sl@0: test.Next(_L("Test error code return values")); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\\\ABCDEF\\")); sl@0: sl@0: test(r==KErrBadName); sl@0: sl@0: test.Next(_L("Test MkDir with trailing spaces")); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\TESTMKDIR \\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\TESTMKDIR\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.MkDirAll(_L("\\F32-TST\\TESTMKDIR \\NOTCREATED\\NORTHIS \\")); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\TESTMKDIR\\NOTCREATED\\")); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\TESTMKDIR\\")); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.MkDirAll(_L("\\F32-TST\\TNMBS\\")); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void testRename() sl@0: // sl@0: // Test the rename function. sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test rename directories")); sl@0: TInt r=TheFs.MkDirAll(_L("\\F32-TST\\ABCDEF\\GPQ\\")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\"),_L("\\F32-TST\\ABCDEF\\LMED")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\GPQ"),_L("\\F32-TST\\LMED")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\LMED\\")); sl@0: test(r==KErrNone); sl@0: sl@0: MakeDir(_L("\\F32-TST\\ABC\\")); sl@0: MakeFile(_L("\\F32-TST\\ABCDEF\\GPQ\\asdf.txt")); sl@0: MakeFile(_L("\\F32-TST\\asdf.txt")); sl@0: sl@0: test.Next(_L("Test rename directory while subfile is open")); sl@0: RFile f; sl@0: r=f.Open(TheFs,_L("\\F32-TST\\ABCDEF\\GPQ\\asdf.txt"),EFileRead); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\xxxyyy")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\xxxyyy")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABC"),_L("\\F32-TST\\XXX")); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\xxxyyy")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\XXX"),_L("\\F32-TST\\ABC")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(_L("\\"),_L("\\BLARG")); sl@0: test(r==KErrBadName); sl@0: sl@0: r=f.Open(TheFs,_L("\\F32-TST\\asdf.txt"),EFileRead); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\xxxyyy"),_L("\\F32-TST\\ABCDEF")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\"),_L("\\ABCDEF")); sl@0: test(r==KErrInUse); sl@0: f.Close(); sl@0: sl@0: r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\GPQ\\asdf.txt")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("\\F32-TST\\asdf.txt")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\GPQ\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\ABC\\")); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Rename(_L("\\TST-E32\\123456"),_L("\\F32-TST\\ABCDEF")); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.Rename(_L("\\F32-TST\\123456"),_L("\\F32-TST\\ABCDEF")); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Rename(_L("\\TST-E32\\123456"),_L("\\F32-TST\\FEDCBA")); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.Rename(_L("\\F32-TST\\FEDCBA"),_L("\\TST-E32\\123456")); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\123456")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\123456"),_L("\\F32-TST\\XYZABC")); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Test rename files")); sl@0: r=f.Create(TheFs,_L("\\F32-TST\\XYZABC\\OLDNAME.TXT"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=TheFs.Rename(_L("\\F32-TST\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\XYZABC\\NEWNAME.TXT")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("\\F32-TST\\XYZABC\\NEWNAME.TXT")); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Test rename checks for duplicate entries")); sl@0: r=TheFs.MkDirAll(_L("\\F32-TST\\ABCDEF\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\XYZABC")); sl@0: test(r==KErrAlreadyExists); sl@0: r=f.Create(TheFs,_L("\\F32-TST\\XYZABC\\OLDNAME.TXT"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=f.Create(TheFs,_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=TheFs.Rename(_L("\\F32-TST\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\XYZABC\\NEWNAME.TXT")); sl@0: test(r==KErrAlreadyExists); sl@0: sl@0: test.Next(_L("Test rename across directories")); sl@0: r=TheFs.Rename(_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"),_L("\\F32-TST\\ABCDEF\\OLDNAME.TXT")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"),_L("\\F32-TST\\ABCDEF\\OLDNAME.TXT")); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Rename(_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"),_L("\\F32-TST\\ABCDEF\\DIFNAME.TXT")); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Rename(_L("\\F32-TST\\XYZABC"),_L("\\F32-TST\\ABCDEF\\XYZABC")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\ABCDEF\\NEWNAME.TXT")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\NewNAME.TXT"),_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT")); sl@0: test(r==KErrNone); sl@0: test.Next(_L("Test rename across drive error code")); sl@0: r=TheFs.Rename(_L("Z:\\BLEG"),_L("C:\\FRUM")); sl@0: test(r==KErrArgument); sl@0: test.Next(_L("Test rename to identical names")); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT")); sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\ABCDEF\\XYZABC\\OLdnAME.TXT")); sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),KErrNone,EFalse); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLdnAME.TXT"),KErrNone,ETrue); sl@0: sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\ABCDEF\\NEWNAME.TXT")); sl@0: test(r==KErrNone); sl@0: test.Next(_L("Test RmDir")); sl@0: r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\NEWNAME.TXT")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\OLDNAME.TXT")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\XYZABC\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\")); sl@0: test(r==KErrNone); sl@0: } sl@0: LOCAL_C void TestLongFileName() sl@0: { sl@0: #ifndef __EPOC32__ //emulator sl@0: if (gDriveToTest.GetLowerCase()=='c') sl@0: return;//don't perform this test for c: in emulator as emulator uses windows system calls sl@0: //windows doesn't create a directory with length more than 244 characters sl@0: #endif sl@0: sl@0: test.Next(_L("Test renaming 257 characters directories")); sl@0: _LIT(KLongFileName256, "256dir_IncludingBackslash_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); sl@0: _LIT(KLongFileName257, "257dir_IncludingBackslash_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); sl@0: TBuf<260> Path; sl@0: TBuf<10> baseDir; sl@0: sl@0: baseDir.Format(_L("%c:\\"),(TUint)(gDriveToTest)); sl@0: Path.Copy(baseDir); sl@0: Path.Append(KLongFileName256); sl@0: Path.Append(_L("\\")); sl@0: sl@0: TInt result = KErrNone; sl@0: //-- 1. create directory in Root which total path length is 256 symbols. result = TheFs.MkDirAll(Path); sl@0: result=TheFs.MkDirAll(Path); sl@0: test((result==KErrNone)||(result==KErrAlreadyExists)); sl@0: sl@0: test.Next(_L("Renaming a 265 char directory to a 257 char directory")); sl@0: result=TheFs.SetSessionPath(baseDir); sl@0: test(result==KErrNone); sl@0: TheFs.SessionPath(baseDir); sl@0: test.Printf(_L("Session path was set to: %S"), &baseDir); sl@0: sl@0: //-- 2. try to rename this directory to one with 257 character total path length sl@0: test.Printf(_L("Renaming 256-char directory to 257")); sl@0: result = KErrNone; sl@0: Path.Copy(KLongFileName257); sl@0: result = TheFs.Rename(KLongFileName256, Path); sl@0: test(result==KErrBadName); sl@0: //-- 3. try to rename this directory to one with 258 character total path length sl@0: sl@0: Path.Append(_L("z")); sl@0: result = TheFs.Rename(KLongFileName256, Path); sl@0: test(result==KErrBadName); sl@0: sl@0: } sl@0: LOCAL_C void testRenameCase() sl@0: // sl@0: // Test renaming "AGENDA" to "agenda" sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test rename case")); sl@0: MakeDir(_L("\\F32-TST\\RENAMECASE\\")); sl@0: TInt r=TheFs.SetSessionPath(_L("\\F32-TST\\RENAMECASE\\")); sl@0: test(r==KErrNone); sl@0: sl@0: MakeFile(_L("file1.txt")); sl@0: MakeFile(_L("FILE2.TXT")); sl@0: MakeFile(_L("AGENDA")); sl@0: MakeFile(_L("agenda.one")); sl@0: sl@0: TEntry entry; sl@0: r=TheFs.Rename(_L("FILE1.TXT"),_L("FILE1.TXT")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("File1.txt"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("FILE1.TXT")); sl@0: sl@0: r=TheFs.Rename(_L("file2.txt"),_L("file2.txt")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("File2.txt"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("file2.txt")); sl@0: sl@0: r=TheFs.Rename(_L("agenda."),_L("agenda.two")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("Agenda.two"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("agenda.two")); sl@0: sl@0: r=TheFs.Rename(_L("AGENDA.ONE"),_L("AGENDA.ONE")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("Agenda.one"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("AGENDA.ONE")); sl@0: sl@0: r=TheFs.Rename(_L("FILE1.TXT"),_L("file1.txt")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("File1.txt"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("file1.txt")); sl@0: sl@0: r=TheFs.Rename(_L("file2.txt"),_L("FILE2.TXT")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("File2.txt"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("FILE2.TXT")); sl@0: sl@0: r=TheFs.Rename(_L("agenda.two"),_L("AGENDA")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("Agenda"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("AGENDA")); sl@0: sl@0: r=TheFs.Rename(_L("AGENDA.ONE"),_L("agenda.one")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("Agenda.one"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("agenda.one")); sl@0: sl@0: r=TheFs.Rename(_L("FILE1.TXT"),_L("FILe1.txt")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("File1.txt"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("FILe1.txt")); sl@0: sl@0: r=TheFs.Rename(_L("file2.txt"),_L("FILE3.TXT")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("File3.txt"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("FILE3.TXT")); sl@0: sl@0: r=TheFs.Rename(_L("agenda."),_L("AGENDA1")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("Agenda1"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("AGENDA1")); sl@0: sl@0: r=TheFs.Rename(_L("AGENDA.ONE"),_L("Agenda.One")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("Agenda.one"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("Agenda.One")); sl@0: sl@0: r=TheFs.Delete(_L("file1.txt")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("file3.txt")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("Agenda1")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("AGENDA.ONE")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\RENAMECASE\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetSessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void testReplace() sl@0: // sl@0: // Test the replace function sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test Replace")); sl@0: TInt r=TheFs.MkDirAll(_L("\\F32-TST\\ABCDEF\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Replace(_L("\\TST-E32\\123456"),_L("\\F32-TST\\ABCDEF")); sl@0: test(r==KErrAccessDenied); // Do not replace directories sl@0: r=TheFs.Replace(_L("\\F32-TST\\123456"),_L("\\F32-TST\\ABCDEF")); sl@0: test(r==KErrAccessDenied); sl@0: r=TheFs.Replace(_L("\\TST-E32\\123456"),_L("\\F32-TST\\FEDCBA")); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.Replace(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\123456")); sl@0: test(r==KErrAccessDenied); sl@0: sl@0: test.Next(_L("Replace a file with itself (8.3 filename)")); sl@0: MakeFile(_L("\\F32-TST\\ABCDEF\\TEST1.SPR")); sl@0: r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEST1.SPR"),_L("\\F32-TST\\ABCDEF\\TEST1.SPR")); sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEST1.SPR"),KErrNone); sl@0: r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEST1.SPR"),_L("\\F32-TST\\ABCDEF\\test1.spr")); sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEST1.SPR"),KErrNone,ETrue); // Replace does not rename existing file sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\test1.spr"),KErrNone,EFalse); sl@0: sl@0: test.Next(_L("Replace a file with itself (vfat filename)")); sl@0: MakeFile(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR")); sl@0: r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"),_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR")); sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"),KErrNone); sl@0: r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"),_L("\\F32-TST\\ABCDEF\\test_sheet(01).spr")); sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"),KErrNone,ETrue); // Replace does not rename existing file sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\test_sheet(01).spr"),KErrNone,EFalse); sl@0: sl@0: test.Next(_L("Replace preserves file contents (8.3 filename)")); sl@0: MakeFile(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"),_L8("Original Data")); sl@0: MakeFile(_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"),_L8("NewData")); sl@0: r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"),_L("\\F32-TST\\ABCDEF\\SHEET1.SPR")); sl@0: test(r==KErrNone); sl@0: CheckFileContents(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"),_L8("NewData")); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"),KErrNotFound); sl@0: sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"),_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"),_L("\\F32-TST\\ABCDEF\\SHEET1.SPR")); sl@0: test(r==KErrNone); sl@0: CheckFileContents(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"),_L8("NewData")); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"),KErrNotFound); sl@0: sl@0: test.Next(_L("Replace preserves file contents (vfat fileName)")); sl@0: MakeFile(_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"),_L8("Original Data")); sl@0: MakeFile(_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"),_L8("NewData")); sl@0: r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"),_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR")); sl@0: test(r==KErrNone); sl@0: CheckFileContents(_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"),_L8("NewData")); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"),KErrNotFound); sl@0: sl@0: r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"),_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"),_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR")); sl@0: test(r==KErrNone); sl@0: CheckFileContents(_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"),_L8("NewData")); sl@0: CheckFileExists(_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"),KErrNotFound); sl@0: sl@0: r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR\\")); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\TEST1.SPR")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\")); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Check file date is retained")); sl@0: MakeFile(_L("OldFile.Old")); sl@0: MakeFile(_L("NewFile.new")); sl@0: sl@0: TDateTime newDate(1998,(TMonth)2,3,11,12,0,0); sl@0: TTime newTime(newDate); sl@0: sl@0: r=TheFs.SetEntry(_L("NewFile.new"),newTime,0,0); sl@0: test(r==KErrNone); sl@0: sl@0: TEntry entry; sl@0: r=TheFs.Entry(_L("NewFile.new"),entry); sl@0: test(r==KErrNone); sl@0: sl@0: TTime checkReturnedTime=entry.iModified; sl@0: TDateTime dateTime=checkReturnedTime.DateTime(); sl@0: sl@0: test(entry.iModified==newTime); sl@0: sl@0: TDateTime oldDate(1996,(TMonth)2,3,23,0,0,0); sl@0: TTime oldTime(oldDate); sl@0: r=TheFs.SetEntry(_L("OldFile.old"),oldTime,0,0); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.Replace(_L("NewFile.new"),_L("OldFile.old")); sl@0: test(r==KErrNone); sl@0: TTime check; sl@0: r=TheFs.Modified(_L("OldFile.old"),check); sl@0: test(r==KErrNone); sl@0: TDateTime checkDateTime=check.DateTime(); sl@0: sl@0: test(checkDateTime.Year()==dateTime.Year()); sl@0: test(checkDateTime.Month()==dateTime.Month()); sl@0: test(checkDateTime.Day()==dateTime.Day()); sl@0: test(checkDateTime.Hour()==dateTime.Hour()); sl@0: test(checkDateTime.Minute()==dateTime.Minute()); sl@0: test(checkDateTime.Second()==dateTime.Second()); sl@0: sl@0: test.Next(_L("Replace 'Agenda' with 'Agenda.'")); sl@0: MakeFile(_L("Agenda")); sl@0: r=TheFs.Replace(_L("Agenda"),_L("Agenda.")); sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("Agenda"),KErrNone,ETrue); sl@0: CheckFileExists(_L("Agenda."),KErrNone,ETrue); sl@0: CheckFileExists(_L("AGENDA"),KErrNone,EFalse); sl@0: CheckFileExists(_L("AGENDA."),KErrNone,EFalse); sl@0: sl@0: r=TheFs.Replace(_L("Agenda"),_L("Agenda.")); sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("Agenda"),KErrNone,ETrue); sl@0: CheckFileExists(_L("Agenda."),KErrNone,ETrue); sl@0: CheckFileExists(_L("AGENDA"),KErrNone,EFalse); sl@0: CheckFileExists(_L("AGENDA."),KErrNone,EFalse); sl@0: sl@0: r=TheFs.Replace(_L("Agenda."),_L("AGENDA")); sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("Agenda"),KErrNone,ETrue); // Replace does not rename existing file sl@0: CheckFileExists(_L("Agenda."),KErrNone,ETrue); sl@0: CheckFileExists(_L("AGENDA"),KErrNone,EFalse); sl@0: CheckFileExists(_L("AGENDA."),KErrNone,EFalse); sl@0: sl@0: r=TheFs.Replace(_L("AGENDA."),_L("AGENDA.")); // Unchanged, ie still 'Agenda' sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("Agenda"),KErrNone,ETrue); sl@0: CheckFileExists(_L("Agenda."),KErrNone,ETrue); sl@0: CheckFileExists(_L("AGENDA"),KErrNone,EFalse); sl@0: CheckFileExists(_L("AGENDA."),KErrNone,EFalse); sl@0: } sl@0: sl@0: LOCAL_C void testEntry() sl@0: // sl@0: // Test RFs::Entry(..) function sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Get directory entry")); sl@0: TEntry entry; sl@0: TInt r=TheFs.Entry(_L("\\BLEERRG\\"),entry); sl@0: test(r==KErrNotFound); // BLEERRG does not exist sl@0: r=TheFs.Entry(_L("\\F32-TST"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("F32-TST")||entry.iName==_L("F32-TST.")); sl@0: if (IsTestingLFFS()) sl@0: { sl@0: r=TheFs.Rename(_L("\\F32-TST.\\"),_L("\\F32-TST\\")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Entry(_L("\\F32-TST"),entry); sl@0: test(r==KErrNone); sl@0: } sl@0: test(entry.iName==_L("F32-TST")); sl@0: test(entry.IsDir()); sl@0: sl@0: test.Next(_L("Get file entry")); sl@0: RFile f; sl@0: r=f.Replace(TheFs,_L("ENTRY.TXT"),EFileStream); sl@0: test(r==KErrNone); sl@0: r=f.Write(_L8("Entry data")); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=TheFs.Entry(_L("\\F32-TST\\TNMBS\\ENTRY.TXT"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("ENTRY.TXT")); sl@0: test(!entry.IsDir()); sl@0: sl@0: test.Next(_L("Get the root directory")); sl@0: r=TheFs.Entry(_L("\\"),entry); sl@0: test(r==KErrBadName); sl@0: } sl@0: sl@0: LOCAL_C void testRenameRegression() sl@0: // sl@0: // Regression tests for rename sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("More rename tests")); sl@0: MakeFile(_L("\\F32-TST\\asdf")); sl@0: TInt r=TheFs.Rename(_L("\\F32-TST\\asdf"),_L("*")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Rename(_L("\\F32-TST\\"),_L("*")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Rename(_L("\\F32-TST\\"),_L("\\F32-TST.\\")); sl@0: test(r==KErrBadName); sl@0: CheckFileExists(_L("\\F32-TST\\asdf"),KErrNone); sl@0: r=TheFs.Rename(_L("\\F32-TST\\asdf"),_L("\\F32-TST\\Asdf.")); sl@0: test(r==KErrNone); sl@0: CheckFileExists(_L("\\F32-TST\\asdf"),KErrNone,EFalse); sl@0: CheckFileExists(_L("\\F32-TST\\Asdf"),KErrNone,ETrue); sl@0: sl@0: TBuf<4> shortName; sl@0: shortName.SetLength(1); sl@0: shortName[0]=0xff; sl@0: r=TheFs.Rename(_L("\\F32-TST\\asdf"),shortName); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("\\F32-TST\\Asdf")); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Delete(shortName); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void testMaxNameLength() sl@0: // sl@0: // Create files and directories with the maximum name length sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test max name length")); sl@0: TBuf<128> longNameBase=_L("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); sl@0: TFullName longName=_L("\\F32-TST\\MAXNAMELEN\\"); sl@0: sl@0: longName.Append(longNameBase); sl@0: longName.Append(_L("\\")); sl@0: longName.Append(longNameBase); sl@0: longName.Append(_L("\\")); sl@0: sl@0: TInt r=TheFs.MkDirAll(longName); sl@0: test(r==KErrNone); sl@0: sl@0: TInt i=0; sl@0: FOREVER sl@0: { sl@0: longName.Append(_L("X")); sl@0: longName.Append(_L("\\")); sl@0: r=TheFs.MkDirAll(longName); sl@0: if (r!=KErrNone) sl@0: break; sl@0: i++; sl@0: } sl@0: sl@0: longName.SetLength(longName.Length()-2); sl@0: r=TheFs.RmDir(longName); sl@0: test(r==KErrNone); // Make room for file sl@0: longName.SetLength(longName.Length()-2); sl@0: sl@0: TFullName oldSessionPath; sl@0: r=TheFs.SessionPath(oldSessionPath); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetSessionPath(longName); sl@0: test(r==KErrNone); sl@0: r=TheFs.SessionPath(longName); sl@0: test(r==KErrNone); sl@0: sl@0: test.Printf(_L("MaxPathLength achieved = %d chars\n"),longName.Length()); sl@0: TBuf<32> fileName=_L("012345678901234567890"); sl@0: RFile f; sl@0: while (fileName.Length()) sl@0: { sl@0: r=f.Replace(TheFs,fileName,EFileWrite); sl@0: if (r==KErrNone) sl@0: break; sl@0: fileName.SetLength(fileName.Length()-1); sl@0: } sl@0: sl@0: f.Close(); sl@0: test.Printf(_L("Added filename %S\n"),&fileName); sl@0: r=f.Open(TheFs,fileName,EFileRead); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: sl@0: CFileMan* fMan=CFileMan::NewL(TheFs); sl@0: r=fMan->RmDir(_L("\\F32-TST\\MAXNAMELEN\\")); sl@0: test(r==KErrNone); sl@0: delete fMan; sl@0: sl@0: r=f.Open(TheFs,fileName,EFileRead); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.SetSessionPath(oldSessionPath); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void testErrorReturnValues() sl@0: // sl@0: // Test error return values sl@0: // sl@0: { sl@0: sl@0: TInt r; sl@0: test.Next(_L("Create folder with the name of an existing file")); sl@0: MakeFile(_L("\\BLUE")); sl@0: if (!IsTestingLFFS()) sl@0: { //FIXME: Bad error codes from LFFS sl@0: r=TheFs.MkDir(_L("\\BLUE\\")); sl@0: test(r==KErrAccessDenied); sl@0: MakeFile(_L("\\RED\\BLUE")); sl@0: r=TheFs.MkDir(_L("\\RED\\BLUE\\")); sl@0: test(r==KErrAccessDenied); sl@0: r=TheFs.MkDirAll(_L("\\BLUE\\GREEN\\ORANGE\\")); sl@0: test(r==KErrAccessDenied); sl@0: } sl@0: sl@0: test.Next(_L("Create folder with the name of an existing folder")); sl@0: MakeDir(_L("\\VOLVO\\")); sl@0: r=TheFs.MkDir(_L("\\VOLVO\\")); sl@0: test(r==KErrAlreadyExists); sl@0: MakeDir(_L("\\FORD\\VOLKSWAGEN\\")); sl@0: r=TheFs.MkDirAll(_L("\\ford\\volkswagen\\")); sl@0: test(r==KErrAlreadyExists); sl@0: sl@0: RFile f; sl@0: if (!IsTestingLFFS()) sl@0: { //FIXME Bad error codes from LFFS sl@0: test.Next(_L("Create a file with the name of an existing folder")); sl@0: r=f.Create(TheFs,_L("\\VOLVO"),EFileRead|EFileWrite); sl@0: test(r==KErrAccessDenied); sl@0: r=f.Replace(TheFs,_L("\\VOLVO"),EFileRead|EFileWrite); sl@0: test(r==KErrAccessDenied); sl@0: r=f.Open(TheFs,_L("\\VOLVO"),EFileRead|EFileWrite); sl@0: test(r==KErrAccessDenied); sl@0: r=f.Create(TheFs,_L("\\FORD\\VOLKSWAGEN"),EFileRead|EFileWrite); sl@0: test(r==KErrAccessDenied); sl@0: r=f.Replace(TheFs,_L("\\FORD\\VOLKSWAGEN"),EFileRead|EFileWrite); sl@0: test(r==KErrAccessDenied); sl@0: r=f.Open(TheFs,_L("\\FORD\\VOLKSWAGEN"),EFileRead|EFileWrite); sl@0: test(r==KErrAccessDenied); sl@0: } sl@0: sl@0: test.Next(_L("Create a file with the name of an existing file")); sl@0: r=f.Create(TheFs,_L("\\BLUE"),EFileRead|EFileWrite); sl@0: test(r==KErrAlreadyExists); sl@0: } sl@0: sl@0: LOCAL_C void testSetEntry() sl@0: // sl@0: // Test set entry sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test SetEntry")); sl@0: // TDateTime dateTime(1968,ENovember,19,12,59,0,0); Year must be > 1980 sl@0: TDateTime dateTime(1981,ENovember,19,12,59,0,0); sl@0: TTime time(dateTime); sl@0: MakeFile(_L("DUMENTRY.")); sl@0: sl@0: RFile f; sl@0: TInt r=f.Open(TheFs,_L("dumentry"),EFileRead); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttReadOnly,KEntryAttArchive); sl@0: test(r==KErrInUse); sl@0: f.Close(); sl@0: sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttReadOnly,KEntryAttArchive); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),KEntryAttReadOnly,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttVolume,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttRemote,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir|KEntryAttVolume,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir|KEntryAttRemote,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttVolume|KEntryAttRemote,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir|KEntryAttVolume|KEntryAttRemote,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttDir); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttVolume); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttRemote); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttDir|KEntryAttVolume); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttDir|KEntryAttRemote); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttVolume|KEntryAttRemote); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttDir|KEntryAttVolume|KEntryAttRemote); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir,KEntryAttVolume); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir,KEntryAttRemote); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttVolume,KEntryAttDir); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttVolume,KEntryAttRemote); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttRemote,KEntryAttDir); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttRemote,KEntryAttVolume); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: sl@0: r=f.Open(TheFs,_L("dumentry"),EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: r=f.SetAtt(KEntryAttDir,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: r=f.SetAtt(KEntryAttVolume,KEntryAttDir); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("DUMEntry"),0,TTime(dateTime)); sl@0: f.Close(); sl@0: r=TheFs.Delete(_L("dumEntry.")); sl@0: test(r==KErrNone); sl@0: sl@0: MakeDir(_L("\\DumEntry\\")); sl@0: r=TheFs.SetEntry(_L("\\dumentry\\"),time,KEntryAttReadOnly,KEntryAttArchive); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("\\DUMEntry"),KEntryAttReadOnly|KEntryAttDir,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("\\dumentry."),time,0,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("\\dumentry"),time,KEntryAttDir,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("\\dumentry"),time,KEntryAttVolume,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("\\dumentry"),time,KEntryAttVolume|KEntryAttDir,0); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("\\dumentry"),time,0,KEntryAttVolume|KEntryAttDir); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("\\dumentry"),time,0,KEntryAttVolume); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("\\dumentry"),time,0,KEntryAttDir); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("\\dumentry"),time,KEntryAttVolume,KEntryAttDir); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime)); sl@0: r=TheFs.SetEntry(_L("\\dumentry"),time,KEntryAttDir,KEntryAttVolume); sl@0: test(r==KErrNone); sl@0: CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime)); sl@0: r=TheFs.RmDir(_L("\\dumEntry\\")); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void testSetFileAttributes() sl@0: // sl@0: // Test RFile::SetAtt() and RFile::Set() sl@0: // sl@0: { sl@0: // First test RFile::SetAtt() function sl@0: sl@0: test.Next(_L("Test RFile::SetAtt()")); sl@0: sl@0: // Create a file "TEMPFILE.TMP" and set attributes to hidden sl@0: RFile file; sl@0: TInt r=file.Replace(TheFs,_L("TEMPFILE.TMP"),0); sl@0: test(r==KErrNone || r==KErrPathNotFound); sl@0: r=file.SetAtt(KEntryAttHidden,0); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Check attributes are as set sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: TUint atts; sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test(atts&KEntryAttHidden); sl@0: sl@0: // Change attributes from hidden to system sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.SetAtt(KEntryAttSystem,KEntryAttHidden); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Check attributes have been changed sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test(atts&KEntryAttSystem); sl@0: sl@0: // Change attributes to normal sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.SetAtt(KEntryAttNormal,KEntryAttSystem|KEntryAttArchive); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Check attributes have been changed sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test(atts==KEntryAttNormal); sl@0: sl@0: // Attempt to change attributes from normal file to directory sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.SetAtt(KEntryAttDir,KEntryAttNormal); sl@0: test(r==KErrNone); // Returns KErrNone but DOESN'T change the file to a directory sl@0: file.Close(); sl@0: sl@0: // Check the file has not been changed to a directory sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test((TInt)(atts&KEntryAttDir)==KErrNone); sl@0: sl@0: // Change the attributes from normal file to hidden file sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.SetAtt(KEntryAttHidden,KEntryAttNormal); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Check the attributes have been changed sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test(atts&KEntryAttHidden); sl@0: sl@0: // Try to change the attributes from hidden file to volume sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.SetAtt(KEntryAttVolume,KEntryAttHidden); sl@0: test(r==KErrNone); // Returns KErrNone but DOESN'T change the file to a volume sl@0: file.Close(); sl@0: sl@0: // Check that the hidden file has not been changed to a volume sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test((TInt)(atts&KEntryAttVolume)==KErrNone); sl@0: sl@0: // Test RFile::Set() function sl@0: sl@0: test.Next(_L("Test RFile::Set()")); sl@0: sl@0: // Check attributes sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test(atts==KEntryAttNormal); sl@0: sl@0: // Change attributes from hidden to system - and change modification time sl@0: TDateTime dateTime(1998,EMay,25,18,23,0,0); sl@0: TTime modTime1(dateTime); sl@0: TTime retTime; sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Set(modTime1,KEntryAttSystem,KEntryAttNormal); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Check attributes have been changed sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: r=file.Modified(retTime); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test(atts&KEntryAttSystem); sl@0: test(retTime==modTime1); sl@0: sl@0: // Change attributes to normal - and change modification time sl@0: dateTime.Set(1997,EMay,24,17,25,0,0); sl@0: TTime modTime2(dateTime); sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Set(modTime2,KEntryAttNormal,KEntryAttSystem|KEntryAttArchive); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Check attributes have been changed sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: r=file.Modified(retTime); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test(atts==KEntryAttNormal); sl@0: test(retTime==modTime2); sl@0: sl@0: // Attempt to change attributes from normal file to directory sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Set(modTime1,KEntryAttDir,KEntryAttNormal); sl@0: test(r==KErrNone); // Returns KErrNone but DOESN'T change the file to a directory sl@0: file.Close(); sl@0: sl@0: // Check the file has not been changed to a directory sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: r=file.Modified(retTime); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test((TInt)(atts&KEntryAttDir)==KErrNone); sl@0: test(retTime==modTime1);// Modification time should have been set successfully sl@0: sl@0: // Change the attributes from normal file to hidden file - and change modification time sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Set(modTime1,KEntryAttHidden,KEntryAttNormal); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Check the attributes have been changed sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: r=file.Modified(retTime); sl@0: file.Close(); sl@0: test(atts&KEntryAttHidden); sl@0: test(retTime==modTime1); sl@0: sl@0: // Try to change the attributes from hidden file to volume sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Set(modTime2,KEntryAttVolume,KEntryAttHidden); sl@0: test(r==KErrNone); // Returns KErrNone but DOESN'T change the file to a volume sl@0: file.Close(); sl@0: sl@0: // Check that the hidden file has not been changed to a volume sl@0: file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite); sl@0: r=file.Att(atts); sl@0: test(r==KErrNone); sl@0: r=file.Modified(retTime); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test((TInt)(atts&KEntryAttVolume)==KErrNone); sl@0: test(retTime==modTime2); // Modification time should have been set successfully sl@0: sl@0: r=TheFs.Delete(_L("TEMPFILE.TMP")); sl@0: sl@0: } sl@0: sl@0: sl@0: GLDEF_C void CallTestsL() sl@0: // sl@0: // Do tests relative to session path sl@0: // sl@0: { sl@0: sl@0: TurnAllocFailureOff(); sl@0: CreateTestDirectory(_L("\\F32-TST\\TNMBS\\")); sl@0: testMkDirRmDir(); // Must come first sl@0: testSetEntry(); sl@0: testSetFileAttributes(); sl@0: testRename(); sl@0: TestLongFileName(); sl@0: testRenameRegression(); sl@0: testRenameCase(); sl@0: testMaxNameLength(); sl@0: testEntry(); sl@0: testReplace(); sl@0: testErrorReturnValues(); sl@0: DeleteTestDirectory(); sl@0: } sl@0: