Update contrib.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 GLDEF_D RTest test(_L("T_NMBS"));
23 LOCAL_C void testMkDirRmDir()
25 // Test the MkDir functions.
29 test.Next(_L("Test MkDir"));
31 TInt r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\"));
33 r=TheFs.MkDir(_L("\\F32-TST\\TNMBS\\TEST\\"));
34 test(r==KErrPathNotFound);
35 r=TheFs.MkDir(_L("\\F32-TST\\TNMBS\\"));
37 r=TheFs.MkDir(_L("\\F32-TST\\TNMBS\\TEST\\"));
40 test.Next(_L("Test RmDir 1.0"));
41 r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\TEST\\"));
43 r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\"));
46 test.Next(_L("Test MkDirAll 1.0"));
47 r=TheFs.MkDirAll(_L("\\F32-TST\\TNMBS\\TEST\\"));
50 test.Next(_L("Test RmDir 2.0"));
51 r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\TEST\\"));
53 r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\"));
56 test.Next(_L("Test MkDirAll 2.0"));
57 r=TheFs.MkDirAll(_L("\\F32-TST\\TNMBS\\"));
59 r=TheFs.MkDirAll(_L("\\F32-TST\\TNMBS\\TEST\\"));
62 test.Next(_L("Test RmDir 3.0"));
63 r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\TEST\\"));
65 r=TheFs.RmDir(_L("\\F32-TST\\TNMBS\\"));
68 test.Next(_L("Test mkdir and rmdir on root"));
69 r=TheFs.RmDir(_L("\\File.TXT"));
71 r=TheFs.MkDir(_L("\\asdf.ere"));
72 test(r==KErrAlreadyExists);
73 r=TheFs.MkDirAll(_L("\\asdf.ere"));
74 test(r==KErrAlreadyExists);
76 test.Next(_L("Test error code return values"));
77 r=TheFs.MkDir(_L("\\F32-TST\\\\ABCDEF\\"));
81 test.Next(_L("Test MkDir with trailing spaces"));
82 r=TheFs.MkDir(_L("\\F32-TST\\TESTMKDIR \\"));
84 r=TheFs.RmDir(_L("\\F32-TST\\TESTMKDIR\\"));
86 r=TheFs.MkDirAll(_L("\\F32-TST\\TESTMKDIR \\NOTCREATED\\NORTHIS \\"));
87 test(r==KErrPathNotFound);
88 r=TheFs.RmDir(_L("\\F32-TST\\TESTMKDIR\\NOTCREATED\\"));
89 test(r==KErrNotFound);
90 r=TheFs.RmDir(_L("\\F32-TST\\TESTMKDIR\\"));
93 r=TheFs.MkDirAll(_L("\\F32-TST\\TNMBS\\"));
97 LOCAL_C void testRename()
99 // Test the rename function.
103 test.Next(_L("Test rename directories"));
104 TInt r=TheFs.MkDirAll(_L("\\F32-TST\\ABCDEF\\GPQ\\"));
105 test(r==KErrNone || r==KErrAlreadyExists);
106 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\"),_L("\\F32-TST\\ABCDEF\\LMED"));
108 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\GPQ"),_L("\\F32-TST\\LMED"));
110 r=TheFs.RmDir(_L("\\F32-TST\\LMED\\"));
113 MakeDir(_L("\\F32-TST\\ABC\\"));
114 MakeFile(_L("\\F32-TST\\ABCDEF\\GPQ\\asdf.txt"));
115 MakeFile(_L("\\F32-TST\\asdf.txt"));
117 test.Next(_L("Test rename directory while subfile is open"));
119 r=f.Open(TheFs,_L("\\F32-TST\\ABCDEF\\GPQ\\asdf.txt"),EFileRead);
121 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\xxxyyy"));
123 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\xxxyyy"));
125 r=TheFs.Rename(_L("\\F32-TST\\ABC"),_L("\\F32-TST\\XXX"));
128 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\xxxyyy"));
130 r=TheFs.Rename(_L("\\F32-TST\\XXX"),_L("\\F32-TST\\ABC"));
132 r=TheFs.Rename(_L("\\"),_L("\\BLARG"));
133 test(r==KErrBadName);
135 r=f.Open(TheFs,_L("\\F32-TST\\asdf.txt"),EFileRead);
137 r=TheFs.Rename(_L("\\F32-TST\\xxxyyy"),_L("\\F32-TST\\ABCDEF"));
139 r=TheFs.Rename(_L("\\F32-TST\\"),_L("\\ABCDEF"));
143 r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\GPQ\\asdf.txt"));
145 r=TheFs.Delete(_L("\\F32-TST\\asdf.txt"));
147 r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\GPQ\\"));
149 r=TheFs.RmDir(_L("\\F32-TST\\ABC\\"));
152 r=TheFs.Rename(_L("\\TST-E32\\123456"),_L("\\F32-TST\\ABCDEF"));
153 test(r==KErrPathNotFound);
154 r=TheFs.Rename(_L("\\F32-TST\\123456"),_L("\\F32-TST\\ABCDEF"));
155 test(r==KErrNotFound);
156 r=TheFs.Rename(_L("\\TST-E32\\123456"),_L("\\F32-TST\\FEDCBA"));
157 test(r==KErrPathNotFound);
158 r=TheFs.Rename(_L("\\F32-TST\\FEDCBA"),_L("\\TST-E32\\123456"));
159 test(r==KErrNotFound);
160 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\123456"));
162 r=TheFs.Rename(_L("\\F32-TST\\123456"),_L("\\F32-TST\\XYZABC"));
165 test.Next(_L("Test rename files"));
166 r=f.Create(TheFs,_L("\\F32-TST\\XYZABC\\OLDNAME.TXT"),EFileRead|EFileWrite);
169 r=TheFs.Rename(_L("\\F32-TST\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"));
171 r=TheFs.Delete(_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"));
174 test.Next(_L("Test rename checks for duplicate entries"));
175 r=TheFs.MkDirAll(_L("\\F32-TST\\ABCDEF\\"));
177 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\XYZABC"));
178 test(r==KErrAlreadyExists);
179 r=f.Create(TheFs,_L("\\F32-TST\\XYZABC\\OLDNAME.TXT"),EFileRead|EFileWrite);
182 r=f.Create(TheFs,_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"),EFileRead|EFileWrite);
185 r=TheFs.Rename(_L("\\F32-TST\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"));
186 test(r==KErrAlreadyExists);
188 test.Next(_L("Test rename across directories"));
189 r=TheFs.Rename(_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"),_L("\\F32-TST\\ABCDEF\\OLDNAME.TXT"));
191 r=TheFs.Rename(_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"),_L("\\F32-TST\\ABCDEF\\OLDNAME.TXT"));
192 test(r==KErrNotFound);
193 r=TheFs.Rename(_L("\\F32-TST\\XYZABC\\NEWNAME.TXT"),_L("\\F32-TST\\ABCDEF\\DIFNAME.TXT"));
194 test(r==KErrNotFound);
195 r=TheFs.Rename(_L("\\F32-TST\\XYZABC"),_L("\\F32-TST\\ABCDEF\\XYZABC"));
197 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\ABCDEF\\NEWNAME.TXT"));
199 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\NewNAME.TXT"),_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"));
201 test.Next(_L("Test rename across drive error code"));
202 r=TheFs.Rename(_L("Z:\\BLEG"),_L("C:\\FRUM"));
203 test(r==KErrArgument);
204 test.Next(_L("Test rename to identical names"));
205 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"));
207 CheckFileExists(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),KErrNone);
208 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\ABCDEF\\XYZABC\\OLdnAME.TXT"));
210 CheckFileExists(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),KErrNone,EFalse);
211 CheckFileExists(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLdnAME.TXT"),KErrNone,ETrue);
213 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\XYZABC\\OLDNAME.TXT"),_L("\\F32-TST\\ABCDEF\\NEWNAME.TXT"));
215 test.Next(_L("Test RmDir"));
216 r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\NEWNAME.TXT"));
218 r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\OLDNAME.TXT"));
220 r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\XYZABC\\"));
222 r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\"));
225 LOCAL_C void TestLongFileName()
227 #ifndef __EPOC32__ //emulator
228 if (gDriveToTest.GetLowerCase()=='c')
229 return;//don't perform this test for c: in emulator as emulator uses windows system calls
230 //windows doesn't create a directory with length more than 244 characters
233 test.Next(_L("Test renaming 257 characters directories"));
234 _LIT(KLongFileName256, "256dir_IncludingBackslash_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
235 _LIT(KLongFileName257, "257dir_IncludingBackslash_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
239 baseDir.Format(_L("%c:\\"),(TUint)(gDriveToTest));
241 Path.Append(KLongFileName256);
242 Path.Append(_L("\\"));
244 TInt result = KErrNone;
245 //-- 1. create directory in Root which total path length is 256 symbols. result = TheFs.MkDirAll(Path);
246 result=TheFs.MkDirAll(Path);
247 test((result==KErrNone)||(result==KErrAlreadyExists));
249 test.Next(_L("Renaming a 265 char directory to a 257 char directory"));
250 result=TheFs.SetSessionPath(baseDir);
251 test(result==KErrNone);
252 TheFs.SessionPath(baseDir);
253 test.Printf(_L("Session path was set to: %S"), &baseDir);
255 //-- 2. try to rename this directory to one with 257 character total path length
256 test.Printf(_L("Renaming 256-char directory to 257"));
258 Path.Copy(KLongFileName257);
259 result = TheFs.Rename(KLongFileName256, Path);
260 test(result==KErrBadName);
261 //-- 3. try to rename this directory to one with 258 character total path length
263 Path.Append(_L("z"));
264 result = TheFs.Rename(KLongFileName256, Path);
265 test(result==KErrBadName);
268 LOCAL_C void testRenameCase()
270 // Test renaming "AGENDA" to "agenda"
274 test.Next(_L("Test rename case"));
275 MakeDir(_L("\\F32-TST\\RENAMECASE\\"));
276 TInt r=TheFs.SetSessionPath(_L("\\F32-TST\\RENAMECASE\\"));
279 MakeFile(_L("file1.txt"));
280 MakeFile(_L("FILE2.TXT"));
281 MakeFile(_L("AGENDA"));
282 MakeFile(_L("agenda.one"));
285 r=TheFs.Rename(_L("FILE1.TXT"),_L("FILE1.TXT"));
287 r=TheFs.Entry(_L("File1.txt"),entry);
289 test(entry.iName==_L("FILE1.TXT"));
291 r=TheFs.Rename(_L("file2.txt"),_L("file2.txt"));
293 r=TheFs.Entry(_L("File2.txt"),entry);
295 test(entry.iName==_L("file2.txt"));
297 r=TheFs.Rename(_L("agenda."),_L("agenda.two"));
299 r=TheFs.Entry(_L("Agenda.two"),entry);
301 test(entry.iName==_L("agenda.two"));
303 r=TheFs.Rename(_L("AGENDA.ONE"),_L("AGENDA.ONE"));
305 r=TheFs.Entry(_L("Agenda.one"),entry);
307 test(entry.iName==_L("AGENDA.ONE"));
309 r=TheFs.Rename(_L("FILE1.TXT"),_L("file1.txt"));
311 r=TheFs.Entry(_L("File1.txt"),entry);
313 test(entry.iName==_L("file1.txt"));
315 r=TheFs.Rename(_L("file2.txt"),_L("FILE2.TXT"));
317 r=TheFs.Entry(_L("File2.txt"),entry);
319 test(entry.iName==_L("FILE2.TXT"));
321 r=TheFs.Rename(_L("agenda.two"),_L("AGENDA"));
323 r=TheFs.Entry(_L("Agenda"),entry);
325 test(entry.iName==_L("AGENDA"));
327 r=TheFs.Rename(_L("AGENDA.ONE"),_L("agenda.one"));
329 r=TheFs.Entry(_L("Agenda.one"),entry);
331 test(entry.iName==_L("agenda.one"));
333 r=TheFs.Rename(_L("FILE1.TXT"),_L("FILe1.txt"));
335 r=TheFs.Entry(_L("File1.txt"),entry);
337 test(entry.iName==_L("FILe1.txt"));
339 r=TheFs.Rename(_L("file2.txt"),_L("FILE3.TXT"));
341 r=TheFs.Entry(_L("File3.txt"),entry);
343 test(entry.iName==_L("FILE3.TXT"));
345 r=TheFs.Rename(_L("agenda."),_L("AGENDA1"));
347 r=TheFs.Entry(_L("Agenda1"),entry);
349 test(entry.iName==_L("AGENDA1"));
351 r=TheFs.Rename(_L("AGENDA.ONE"),_L("Agenda.One"));
353 r=TheFs.Entry(_L("Agenda.one"),entry);
355 test(entry.iName==_L("Agenda.One"));
357 r=TheFs.Delete(_L("file1.txt"));
359 r=TheFs.Delete(_L("file3.txt"));
361 r=TheFs.Delete(_L("Agenda1"));
363 r=TheFs.Delete(_L("AGENDA.ONE"));
365 r=TheFs.RmDir(_L("\\F32-TST\\RENAMECASE\\"));
367 r=TheFs.SetSessionPath(gSessionPath);
371 LOCAL_C void testReplace()
373 // Test the replace function
377 test.Next(_L("Test Replace"));
378 TInt r=TheFs.MkDirAll(_L("\\F32-TST\\ABCDEF\\"));
380 r=TheFs.Replace(_L("\\TST-E32\\123456"),_L("\\F32-TST\\ABCDEF"));
381 test(r==KErrAccessDenied); // Do not replace directories
382 r=TheFs.Replace(_L("\\F32-TST\\123456"),_L("\\F32-TST\\ABCDEF"));
383 test(r==KErrAccessDenied);
384 r=TheFs.Replace(_L("\\TST-E32\\123456"),_L("\\F32-TST\\FEDCBA"));
385 test(r==KErrPathNotFound);
386 r=TheFs.Replace(_L("\\F32-TST\\ABCDEF"),_L("\\F32-TST\\123456"));
387 test(r==KErrAccessDenied);
389 test.Next(_L("Replace a file with itself (8.3 filename)"));
390 MakeFile(_L("\\F32-TST\\ABCDEF\\TEST1.SPR"));
391 r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEST1.SPR"),_L("\\F32-TST\\ABCDEF\\TEST1.SPR"));
393 CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEST1.SPR"),KErrNone);
394 r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEST1.SPR"),_L("\\F32-TST\\ABCDEF\\test1.spr"));
396 CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEST1.SPR"),KErrNone,ETrue); // Replace does not rename existing file
397 CheckFileExists(_L("\\F32-TST\\ABCDEF\\test1.spr"),KErrNone,EFalse);
399 test.Next(_L("Replace a file with itself (vfat filename)"));
400 MakeFile(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"));
401 r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"),_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"));
403 CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"),KErrNone);
404 r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"),_L("\\F32-TST\\ABCDEF\\test_sheet(01).spr"));
406 CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"),KErrNone,ETrue); // Replace does not rename existing file
407 CheckFileExists(_L("\\F32-TST\\ABCDEF\\test_sheet(01).spr"),KErrNone,EFalse);
409 test.Next(_L("Replace preserves file contents (8.3 filename)"));
410 MakeFile(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"),_L8("Original Data"));
411 MakeFile(_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"),_L8("NewData"));
412 r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"),_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"));
414 CheckFileContents(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"),_L8("NewData"));
415 CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"),KErrNotFound);
417 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"),_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"));
419 r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"),_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"));
421 CheckFileContents(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"),_L8("NewData"));
422 CheckFileExists(_L("\\F32-TST\\ABCDEF\\TEMP0001.SPR"),KErrNotFound);
424 test.Next(_L("Replace preserves file contents (vfat fileName)"));
425 MakeFile(_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"),_L8("Original Data"));
426 MakeFile(_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"),_L8("NewData"));
427 r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"),_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"));
429 CheckFileContents(_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"),_L8("NewData"));
430 CheckFileExists(_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"),KErrNotFound);
432 r=TheFs.Rename(_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"),_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"));
434 r=TheFs.Replace(_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"),_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"));
436 CheckFileContents(_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"),_L8("NewData"));
437 CheckFileExists(_L("\\F32-TST\\ABCDEF\\NEW_TEMP0001.SPR"),KErrNotFound);
439 r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\"));
441 r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR\\"));
442 test(r==KErrPathNotFound);
443 r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\SHEET1.SPR"));
445 r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\SHEET_TEST1.SPR"));
447 r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\TEST1.SPR"));
449 r=TheFs.Delete(_L("\\F32-TST\\ABCDEF\\TEST_SHEET(01).SPR"));
451 r=TheFs.RmDir(_L("\\F32-TST\\ABCDEF\\"));
454 test.Next(_L("Check file date is retained"));
455 MakeFile(_L("OldFile.Old"));
456 MakeFile(_L("NewFile.new"));
458 TDateTime newDate(1998,(TMonth)2,3,11,12,0,0);
459 TTime newTime(newDate);
461 r=TheFs.SetEntry(_L("NewFile.new"),newTime,0,0);
465 r=TheFs.Entry(_L("NewFile.new"),entry);
468 TTime checkReturnedTime=entry.iModified;
469 TDateTime dateTime=checkReturnedTime.DateTime();
471 test(entry.iModified==newTime);
473 TDateTime oldDate(1996,(TMonth)2,3,23,0,0,0);
474 TTime oldTime(oldDate);
475 r=TheFs.SetEntry(_L("OldFile.old"),oldTime,0,0);
478 TheFs.Replace(_L("NewFile.new"),_L("OldFile.old"));
481 r=TheFs.Modified(_L("OldFile.old"),check);
483 TDateTime checkDateTime=check.DateTime();
485 test(checkDateTime.Year()==dateTime.Year());
486 test(checkDateTime.Month()==dateTime.Month());
487 test(checkDateTime.Day()==dateTime.Day());
488 test(checkDateTime.Hour()==dateTime.Hour());
489 test(checkDateTime.Minute()==dateTime.Minute());
490 test(checkDateTime.Second()==dateTime.Second());
492 test.Next(_L("Replace 'Agenda' with 'Agenda.'"));
493 MakeFile(_L("Agenda"));
494 r=TheFs.Replace(_L("Agenda"),_L("Agenda."));
496 CheckFileExists(_L("Agenda"),KErrNone,ETrue);
497 CheckFileExists(_L("Agenda."),KErrNone,ETrue);
498 CheckFileExists(_L("AGENDA"),KErrNone,EFalse);
499 CheckFileExists(_L("AGENDA."),KErrNone,EFalse);
501 r=TheFs.Replace(_L("Agenda"),_L("Agenda."));
503 CheckFileExists(_L("Agenda"),KErrNone,ETrue);
504 CheckFileExists(_L("Agenda."),KErrNone,ETrue);
505 CheckFileExists(_L("AGENDA"),KErrNone,EFalse);
506 CheckFileExists(_L("AGENDA."),KErrNone,EFalse);
508 r=TheFs.Replace(_L("Agenda."),_L("AGENDA"));
510 CheckFileExists(_L("Agenda"),KErrNone,ETrue); // Replace does not rename existing file
511 CheckFileExists(_L("Agenda."),KErrNone,ETrue);
512 CheckFileExists(_L("AGENDA"),KErrNone,EFalse);
513 CheckFileExists(_L("AGENDA."),KErrNone,EFalse);
515 r=TheFs.Replace(_L("AGENDA."),_L("AGENDA.")); // Unchanged, ie still 'Agenda'
517 CheckFileExists(_L("Agenda"),KErrNone,ETrue);
518 CheckFileExists(_L("Agenda."),KErrNone,ETrue);
519 CheckFileExists(_L("AGENDA"),KErrNone,EFalse);
520 CheckFileExists(_L("AGENDA."),KErrNone,EFalse);
523 LOCAL_C void testEntry()
525 // Test RFs::Entry(..) function
529 test.Next(_L("Get directory entry"));
531 TInt r=TheFs.Entry(_L("\\BLEERRG\\"),entry);
532 test(r==KErrNotFound); // BLEERRG does not exist
533 r=TheFs.Entry(_L("\\F32-TST"),entry);
535 test(entry.iName==_L("F32-TST")||entry.iName==_L("F32-TST."));
538 r=TheFs.Rename(_L("\\F32-TST.\\"),_L("\\F32-TST\\"));
539 test(r==KErrBadName);
540 r=TheFs.Entry(_L("\\F32-TST"),entry);
543 test(entry.iName==_L("F32-TST"));
546 test.Next(_L("Get file entry"));
548 r=f.Replace(TheFs,_L("ENTRY.TXT"),EFileStream);
550 r=f.Write(_L8("Entry data"));
553 r=TheFs.Entry(_L("\\F32-TST\\TNMBS\\ENTRY.TXT"),entry);
555 test(entry.iName==_L("ENTRY.TXT"));
556 test(!entry.IsDir());
558 test.Next(_L("Get the root directory"));
559 r=TheFs.Entry(_L("\\"),entry);
560 test(r==KErrBadName);
563 LOCAL_C void testRenameRegression()
565 // Regression tests for rename
569 test.Next(_L("More rename tests"));
570 MakeFile(_L("\\F32-TST\\asdf"));
571 TInt r=TheFs.Rename(_L("\\F32-TST\\asdf"),_L("*"));
572 test(r==KErrBadName);
573 r=TheFs.Rename(_L("\\F32-TST\\"),_L("*"));
574 test(r==KErrBadName);
575 r=TheFs.Rename(_L("\\F32-TST\\"),_L("\\F32-TST.\\"));
576 test(r==KErrBadName);
577 CheckFileExists(_L("\\F32-TST\\asdf"),KErrNone);
578 r=TheFs.Rename(_L("\\F32-TST\\asdf"),_L("\\F32-TST\\Asdf."));
580 CheckFileExists(_L("\\F32-TST\\asdf"),KErrNone,EFalse);
581 CheckFileExists(_L("\\F32-TST\\Asdf"),KErrNone,ETrue);
584 shortName.SetLength(1);
586 r=TheFs.Rename(_L("\\F32-TST\\asdf"),shortName);
588 r=TheFs.Delete(_L("\\F32-TST\\Asdf"));
589 test(r==KErrNotFound);
590 r=TheFs.Delete(shortName);
594 LOCAL_C void testMaxNameLength()
596 // Create files and directories with the maximum name length
600 test.Next(_L("Test max name length"));
601 TBuf<128> longNameBase=_L("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
602 TFullName longName=_L("\\F32-TST\\MAXNAMELEN\\");
604 longName.Append(longNameBase);
605 longName.Append(_L("\\"));
606 longName.Append(longNameBase);
607 longName.Append(_L("\\"));
609 TInt r=TheFs.MkDirAll(longName);
615 longName.Append(_L("X"));
616 longName.Append(_L("\\"));
617 r=TheFs.MkDirAll(longName);
623 longName.SetLength(longName.Length()-2);
624 r=TheFs.RmDir(longName);
625 test(r==KErrNone); // Make room for file
626 longName.SetLength(longName.Length()-2);
628 TFullName oldSessionPath;
629 r=TheFs.SessionPath(oldSessionPath);
631 r=TheFs.SetSessionPath(longName);
633 r=TheFs.SessionPath(longName);
636 test.Printf(_L("MaxPathLength achieved = %d chars\n"),longName.Length());
637 TBuf<32> fileName=_L("012345678901234567890");
639 while (fileName.Length())
641 r=f.Replace(TheFs,fileName,EFileWrite);
644 fileName.SetLength(fileName.Length()-1);
648 test.Printf(_L("Added filename %S\n"),&fileName);
649 r=f.Open(TheFs,fileName,EFileRead);
653 CFileMan* fMan=CFileMan::NewL(TheFs);
654 r=fMan->RmDir(_L("\\F32-TST\\MAXNAMELEN\\"));
658 r=f.Open(TheFs,fileName,EFileRead);
659 test(r==KErrPathNotFound);
660 r=TheFs.SetSessionPath(oldSessionPath);
664 LOCAL_C void testErrorReturnValues()
666 // Test error return values
671 test.Next(_L("Create folder with the name of an existing file"));
672 MakeFile(_L("\\BLUE"));
673 if (!IsTestingLFFS())
674 { //FIXME: Bad error codes from LFFS
675 r=TheFs.MkDir(_L("\\BLUE\\"));
676 test(r==KErrAccessDenied);
677 MakeFile(_L("\\RED\\BLUE"));
678 r=TheFs.MkDir(_L("\\RED\\BLUE\\"));
679 test(r==KErrAccessDenied);
680 r=TheFs.MkDirAll(_L("\\BLUE\\GREEN\\ORANGE\\"));
681 test(r==KErrAccessDenied);
684 test.Next(_L("Create folder with the name of an existing folder"));
685 MakeDir(_L("\\VOLVO\\"));
686 r=TheFs.MkDir(_L("\\VOLVO\\"));
687 test(r==KErrAlreadyExists);
688 MakeDir(_L("\\FORD\\VOLKSWAGEN\\"));
689 r=TheFs.MkDirAll(_L("\\ford\\volkswagen\\"));
690 test(r==KErrAlreadyExists);
693 if (!IsTestingLFFS())
694 { //FIXME Bad error codes from LFFS
695 test.Next(_L("Create a file with the name of an existing folder"));
696 r=f.Create(TheFs,_L("\\VOLVO"),EFileRead|EFileWrite);
697 test(r==KErrAccessDenied);
698 r=f.Replace(TheFs,_L("\\VOLVO"),EFileRead|EFileWrite);
699 test(r==KErrAccessDenied);
700 r=f.Open(TheFs,_L("\\VOLVO"),EFileRead|EFileWrite);
701 test(r==KErrAccessDenied);
702 r=f.Create(TheFs,_L("\\FORD\\VOLKSWAGEN"),EFileRead|EFileWrite);
703 test(r==KErrAccessDenied);
704 r=f.Replace(TheFs,_L("\\FORD\\VOLKSWAGEN"),EFileRead|EFileWrite);
705 test(r==KErrAccessDenied);
706 r=f.Open(TheFs,_L("\\FORD\\VOLKSWAGEN"),EFileRead|EFileWrite);
707 test(r==KErrAccessDenied);
710 test.Next(_L("Create a file with the name of an existing file"));
711 r=f.Create(TheFs,_L("\\BLUE"),EFileRead|EFileWrite);
712 test(r==KErrAlreadyExists);
715 LOCAL_C void testSetEntry()
721 test.Next(_L("Test SetEntry"));
722 // TDateTime dateTime(1968,ENovember,19,12,59,0,0); Year must be > 1980
723 TDateTime dateTime(1981,ENovember,19,12,59,0,0);
724 TTime time(dateTime);
725 MakeFile(_L("DUMENTRY."));
728 TInt r=f.Open(TheFs,_L("dumentry"),EFileRead);
730 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttReadOnly,KEntryAttArchive);
734 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttReadOnly,KEntryAttArchive);
736 CheckEntry(_L("DUMEntry"),KEntryAttReadOnly,TTime(dateTime));
737 r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttReadOnly);
739 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
740 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir,0);
742 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
743 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttVolume,0);
745 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
746 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttRemote,0);
748 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
749 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir|KEntryAttVolume,0);
751 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
752 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir|KEntryAttRemote,0);
754 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
755 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttVolume|KEntryAttRemote,0);
757 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
758 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir|KEntryAttVolume|KEntryAttRemote,0);
760 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
761 r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttDir);
763 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
764 r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttVolume);
766 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
767 r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttRemote);
769 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
770 r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttDir|KEntryAttVolume);
772 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
773 r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttDir|KEntryAttRemote);
775 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
776 r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttVolume|KEntryAttRemote);
778 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
779 r=TheFs.SetEntry(_L("dumentry."),time,0,KEntryAttDir|KEntryAttVolume|KEntryAttRemote);
781 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
782 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir,KEntryAttVolume);
784 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
785 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttDir,KEntryAttRemote);
787 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
788 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttVolume,KEntryAttDir);
790 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
791 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttVolume,KEntryAttRemote);
793 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
794 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttRemote,KEntryAttDir);
796 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
797 r=TheFs.SetEntry(_L("dumentry."),time,KEntryAttRemote,KEntryAttVolume);
799 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
801 r=f.Open(TheFs,_L("dumentry"),EFileWrite);
804 r=f.SetAtt(KEntryAttDir,0);
806 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
807 r=f.SetAtt(KEntryAttVolume,KEntryAttDir);
809 CheckEntry(_L("DUMEntry"),0,TTime(dateTime));
811 r=TheFs.Delete(_L("dumEntry."));
814 MakeDir(_L("\\DumEntry\\"));
815 r=TheFs.SetEntry(_L("\\dumentry\\"),time,KEntryAttReadOnly,KEntryAttArchive);
817 CheckEntry(_L("\\DUMEntry"),KEntryAttReadOnly|KEntryAttDir,TTime(dateTime));
818 r=TheFs.SetEntry(_L("\\dumentry."),time,0,KEntryAttReadOnly);
820 CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime));
821 r=TheFs.SetEntry(_L("\\dumentry"),time,KEntryAttDir,0);
823 CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime));
824 r=TheFs.SetEntry(_L("\\dumentry"),time,KEntryAttVolume,0);
826 CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime));
827 r=TheFs.SetEntry(_L("\\dumentry"),time,KEntryAttVolume|KEntryAttDir,0);
829 CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime));
830 r=TheFs.SetEntry(_L("\\dumentry"),time,0,KEntryAttVolume|KEntryAttDir);
832 CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime));
833 r=TheFs.SetEntry(_L("\\dumentry"),time,0,KEntryAttVolume);
835 CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime));
836 r=TheFs.SetEntry(_L("\\dumentry"),time,0,KEntryAttDir);
838 CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime));
839 r=TheFs.SetEntry(_L("\\dumentry"),time,KEntryAttVolume,KEntryAttDir);
841 CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime));
842 r=TheFs.SetEntry(_L("\\dumentry"),time,KEntryAttDir,KEntryAttVolume);
844 CheckEntry(_L("\\DUMEntry"),KEntryAttDir,TTime(dateTime));
845 r=TheFs.RmDir(_L("\\dumEntry\\"));
850 LOCAL_C void testSetFileAttributes()
852 // Test RFile::SetAtt() and RFile::Set()
855 // First test RFile::SetAtt() function
857 test.Next(_L("Test RFile::SetAtt()"));
859 // Create a file "TEMPFILE.TMP" and set attributes to hidden
861 TInt r=file.Replace(TheFs,_L("TEMPFILE.TMP"),0);
862 test(r==KErrNone || r==KErrPathNotFound);
863 r=file.SetAtt(KEntryAttHidden,0);
867 // Check attributes are as set
868 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
873 test(atts&KEntryAttHidden);
875 // Change attributes from hidden to system
876 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
877 r=file.SetAtt(KEntryAttSystem,KEntryAttHidden);
881 // Check attributes have been changed
882 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
886 test(atts&KEntryAttSystem);
888 // Change attributes to normal
889 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
890 r=file.SetAtt(KEntryAttNormal,KEntryAttSystem|KEntryAttArchive);
894 // Check attributes have been changed
895 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
899 test(atts==KEntryAttNormal);
901 // Attempt to change attributes from normal file to directory
902 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
903 r=file.SetAtt(KEntryAttDir,KEntryAttNormal);
904 test(r==KErrNone); // Returns KErrNone but DOESN'T change the file to a directory
907 // Check the file has not been changed to a directory
908 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
912 test((TInt)(atts&KEntryAttDir)==KErrNone);
914 // Change the attributes from normal file to hidden file
915 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
916 r=file.SetAtt(KEntryAttHidden,KEntryAttNormal);
920 // Check the attributes have been changed
921 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
925 test(atts&KEntryAttHidden);
927 // Try to change the attributes from hidden file to volume
928 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
929 r=file.SetAtt(KEntryAttVolume,KEntryAttHidden);
930 test(r==KErrNone); // Returns KErrNone but DOESN'T change the file to a volume
933 // Check that the hidden file has not been changed to a volume
934 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
938 test((TInt)(atts&KEntryAttVolume)==KErrNone);
940 // Test RFile::Set() function
942 test.Next(_L("Test RFile::Set()"));
945 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
949 test(atts==KEntryAttNormal);
951 // Change attributes from hidden to system - and change modification time
952 TDateTime dateTime(1998,EMay,25,18,23,0,0);
953 TTime modTime1(dateTime);
955 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
956 r=file.Set(modTime1,KEntryAttSystem,KEntryAttNormal);
960 // Check attributes have been changed
961 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
964 r=file.Modified(retTime);
967 test(atts&KEntryAttSystem);
968 test(retTime==modTime1);
970 // Change attributes to normal - and change modification time
971 dateTime.Set(1997,EMay,24,17,25,0,0);
972 TTime modTime2(dateTime);
973 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
974 r=file.Set(modTime2,KEntryAttNormal,KEntryAttSystem|KEntryAttArchive);
978 // Check attributes have been changed
979 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
982 r=file.Modified(retTime);
985 test(atts==KEntryAttNormal);
986 test(retTime==modTime2);
988 // Attempt to change attributes from normal file to directory
989 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
990 r=file.Set(modTime1,KEntryAttDir,KEntryAttNormal);
991 test(r==KErrNone); // Returns KErrNone but DOESN'T change the file to a directory
994 // Check the file has not been changed to a directory
995 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
998 r=file.Modified(retTime);
1001 test((TInt)(atts&KEntryAttDir)==KErrNone);
1002 test(retTime==modTime1);// Modification time should have been set successfully
1004 // Change the attributes from normal file to hidden file - and change modification time
1005 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
1006 r=file.Set(modTime1,KEntryAttHidden,KEntryAttNormal);
1010 // Check the attributes have been changed
1011 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
1014 r=file.Modified(retTime);
1016 test(atts&KEntryAttHidden);
1017 test(retTime==modTime1);
1019 // Try to change the attributes from hidden file to volume
1020 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
1021 r=file.Set(modTime2,KEntryAttVolume,KEntryAttHidden);
1022 test(r==KErrNone); // Returns KErrNone but DOESN'T change the file to a volume
1025 // Check that the hidden file has not been changed to a volume
1026 file.Open(TheFs,_L("TEMPFILE.TMP"),EFileWrite);
1029 r=file.Modified(retTime);
1032 test((TInt)(atts&KEntryAttVolume)==KErrNone);
1033 test(retTime==modTime2); // Modification time should have been set successfully
1035 r=TheFs.Delete(_L("TEMPFILE.TMP"));
1040 GLDEF_C void CallTestsL()
1042 // Do tests relative to session path
1046 TurnAllocFailureOff();
1047 CreateTestDirectory(_L("\\F32-TST\\TNMBS\\"));
1048 testMkDirRmDir(); // Must come first
1050 testSetFileAttributes();
1053 testRenameRegression();
1055 testMaxNameLength();
1058 testErrorReturnValues();
1059 DeleteTestDirectory();