First public contribution.
1 // Copyright (c) 1996-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.
24 // Solve compilation problem caused by non-English locale
25 #pragma setlocale("english")
28 GLDEF_D RTest test(_L("B_GEN"));
30 // File test - general test of local filing system routines
31 // (finishes with formating current device).
32 // Modified from BB's epoc test code
34 #define MINIMUM_DATE (315532800L)
37 // GLREF_D P_DEVICE p_file;
38 // GLREF_D P_DEVICE p_wind,p_screen,p_cons;
40 GLDEF_D TBuf<0x100> gNameBuf;
41 GLDEF_D TBuf<0x100> gNameOut;
43 GLDEF_D RFile gFileErr;
46 GLDEF_D RFormat gFormat;
47 //GLDEF_D void *chan1,*chan2;
48 GLDEF_D TFileName fBuf;
49 //GLDEF_D TUint8 fBuf[P_FNAMESIZE];
52 LOCAL_D TBuf8<0x4000> gDataBuf;
53 LOCAL_D TEntry gFileEntry;
54 // LOCAL_D P_DINFO volInfo;
55 LOCAL_D TVolumeInfo volInfo;
56 // LOCAL_D P_NINFO nInfo;
57 LOCAL_D TFileName pathBuf;
60 LOCAL_D TInt NameErr=KErrBadName;
61 LOCAL_D TInt DirErr=KErrPathNotFound;
62 LOCAL_D TInt AccessErr=KErrAccessDenied;
63 LOCAL_D TInt LockedErr=KErrInUse;
64 LOCAL_D TInt ExistsErr=KErrAlreadyExists;
65 LOCAL_D TInt NotExistsErr=KErrNotFound;
66 LOCAL_D TInt EofErr=KErrEof;
67 LOCAL_D TInt DeviceErr=KErrNotReady;
68 //LOCAL_D TInt NoFileSystemErr=KErrNotReady;
69 //LOCAL_D TInt NotSupportedErr=KErrNotSupported;
70 LOCAL_D TInt ReadOnlyErr=KErrAccessDenied;
72 LOCAL_D TInt P_FASTREAM=EFileStream;
73 LOCAL_D TInt P_FAEXEC=0;
74 LOCAL_D TInt P_FAMOD=KEntryAttArchive;
75 LOCAL_D TInt P_FAREAD=KEntryAttReadOnly;
76 //LOCAL_D TInt P_FAHIDDEN=KEntryAttHidden;
77 //LOCAL_D TInt P_FASYSTEM=KEntryAttSystem;
78 //LOCAL_C TInt P_FAVOLUME=KEntryAttVolume;
79 LOCAL_C TInt P_FADIR=KEntryAttDir;
80 LOCAL_C TInt P_FRANDOM=0;
81 LOCAL_C TInt P_FABS=ESeekStart;
83 LOCAL_C TInt P_FUPDATE=EFileWrite;
86 LOCAL_C void doError(const TDesC &aMess, TInt anErr, TInt line)
88 test.Printf(_L("%S failed at line %d. Error %d\n"),&aMess, line, anErr);
91 #define Error(aMess, anErr) doError(aMess, anErr, __LINE__)
93 LOCAL_C void doError2(const TDesC &aMess, TInt anErr, TInt line, TInt callLine)
95 test.Printf(_L("%S failed at line %d. Error %d. Called from line %d\n"),&aMess, line, anErr, callLine); \
98 #define Error2(aMess, anErr, line) doError2(aMess, anErr, __LINE__, line)
100 LOCAL_C void testWrite(const TDesC& aName,TInt aLen,TInt32 aSize,TBool aShouldChange)
108 test.Printf(_L("Write %u bytes %u\n"),aLen,aShouldChange);
109 if ((c=TheFs.Entry(aName,gFileEntry))!=KErrNone)
110 Error(_L("File info 600"),c);
111 saveTime=gFileEntry.iModified;
112 User::After(3000000L); // 30 tenths of a sec = 30 00000 micro seconds
113 if ((c=gFile.Open(TheFs,aName,EFileWrite))!=KErrNone)
114 Error(_L("Open 50"),c);
115 if ((c=gFile.Write(gDataBuf,aLen))!=KErrNone)
116 Error(_L("Write"),c);
118 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
119 Error(_L("File info 601"),c);
120 if ((saveTime!=gFileEntry.iModified)!=aShouldChange)
121 Error(_L("Change flag check 6"),0);
122 if (gFileEntry.iSize!=aSize)
123 Error(_L("Size check 602"),0);
126 LOCAL_C void testSetEof(const TDesC& aName,TUint32 aPos,TBool aShouldChange)
128 // Set the end of a file
134 test.Printf(_L("Set EOF to %u %u\n"),aPos,aShouldChange);
135 if ((c=TheFs.Entry(aName,gFileEntry))!=KErrNone)
136 Error(_L("File info 500"),c);
137 saveTime=gFileEntry.iModified;
138 User::After(3000000L);
139 if ((c=gFile.Open(TheFs,aName,EFileWrite))!=KErrNone)
140 Error(_L("Open 50"),c);
141 if ((c=gFile.SetSize(aPos))!=KErrNone)
142 Error(_L("Set EOF 50"),c);
144 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
145 Error(_L("File info 501"),c);
146 if ((saveTime!=gFileEntry.iModified)!=aShouldChange)
147 Error(_L("Change flag check 5"),0);
151 LOCAL_C void testDir(const TDesC& aDirName)
153 // Create a directory
158 test.Printf(_L("Test dir %S\n"),&aDirName);
159 c=gDir.Open(TheFs,aDirName,KEntryAttNormal);
162 Error(_L("Directory open 1000"),c);
166 TChar drive(aDirName[0]);
168 c=RFs::CharToDrive(drive,driveNo);
170 if ((c=TheFs.Volume(volInfo,driveNo))!=KErrNone)
171 Error(_L("Device info 1000"),c);
176 LOCAL_C void testNodeInfo(const TDesC& aName,TInt type,TInt anErr)
183 test.Printf(_L("Node info: %S\n"),&aName);
184 // if ((c=p_ninfo(aDirName,&nInfo))!=anErr)
185 // Error(_L("Device info"),c);
188 // if (!(nInfo.version==2 || nInfo.version==3))
189 // Error(_L("Node version check"),0);
190 // if (nInfo.type!=type)
191 // Error(_L("Node type check"),0);
196 LOCAL_C void testDeviceInfo(const TDesC& aDeviceName,TInt anErr)
203 test.Printf(_L("Device info: %S\n"),&aDeviceName);
204 TInt drive=KDefaultDrive;
205 if (aDeviceName.Length())
207 c=RFs::CharToDrive(aDeviceName[0],drive);
210 if ((c=TheFs.Volume(volInfo,drive))!=anErr)
211 Error(_L("Device info"),c);
214 // if (!(volInfo.version==2 || volInfo.version==3)) ********* version is not a member of TVolumeInfo
215 // Error(_L("Device version check"),0);
216 if (volInfo.iFree>volInfo.iSize)
217 Error(_L("Free greater than size check"),0);
221 LOCAL_C void testFileInfo(const TDesC& aFileName,TInt anErr)
228 test.Printf(_L("File info: %S\n"),&aFileName);
229 if ((c=TheFs.Entry(aFileName,gFileEntry))!=anErr)
230 Error(_L("Get info 100"),c);
233 if (aFileName.Length()>=2 && aFileName[0]=='Z' && aFileName[1]==':')
235 if ((gFileEntry.iAtt&(P_FAREAD|P_FAEXEC|P_FASTREAM)) != (TUint32)(P_FAREAD|P_FAEXEC|P_FASTREAM) && gFileEntry.iAtt!=KEntryAttDir)
236 Error(_L("Info status check Z:\\"),0);
240 if (gFileEntry.iAtt&KEntryAttDir)
241 return; // Found directory entry
242 if (gFileEntry.iAtt!=(TUint32)(P_FASTREAM|P_FAMOD))
243 Error(_L("Info status check"),0);
244 if (gFileEntry.iSize!=0L)
245 Error(_L("Info size check"),0);
250 LOCAL_C void testRenameFromRoot(const TDesC& aRName,const TDesC& aDName)
257 if ((c=TheFs.Rename(aRName,aDName))!=KErrNone)
258 Error(_L("Rename 92"),c);
259 if ((c=gFile.Open(TheFs,aDName,EFileStream))!=KErrNone)
260 Error(_L("Open 92"),c);
262 if ((c=TheFs.Delete(aRName))!=NotExistsErr)
263 Error(_L("Delete 92"),c);
266 LOCAL_C void testRenameToRoot(const TDesC& pName,const TDesC& rName)
273 if ((c=gFile.Replace(TheFs,pName,EFileStream))!=KErrNone)
274 Error(_L("Create 91"),c);
276 if ((c=TheFs.Rename(pName,rName))!=KErrNone)
277 Error(_L("Rename 91"),c);
278 if ((c=gFile.Open(TheFs,rName,EFileStream))!=KErrNone)
279 Error(_L("Open 91"),c);
281 if ((c=TheFs.Delete(pName))!=NotExistsErr)
282 Error(_L("Delete 91"),c);
285 LOCAL_C void verifyTestPat1()
293 if ((c=gFile.Open(TheFs,_L("\\TESTPAT1.DAT"),EFileStream))!=KErrNone)
294 Error(_L("Create testpat1"),c);
295 gDataBuf.SetLength(0);
296 if ((c=gFile.Read(gDataBuf,512))!=KErrNone || gDataBuf.Length()!=512)
297 Error(_L("Read 90"),c);
301 if (gDataBuf[i]!='X')
302 Error(_L("Data check"),0);
306 void TestINC103141() // PDEF104017
308 test.Printf(_L("Test INC103141\n"));
309 _LIT(KDir1, "\\INC103141\\TEST");
310 _LIT(KDir2, "\\INC103141\\test");
313 dirname.Append(KPathDelimiter);
315 TInt err = TheFs.Rename(KDir1, KDir2);
316 test(err == KErrNone);
317 err = TheFs.RmDir(dirname);
318 test(err == KErrNone);
319 err = TheFs.RmDir(KDir1);
320 test(err == KErrNone);
323 LOCAL_C void testRename()
325 // Test TheFs.Rename function.
332 test.Printf(_L("Test TheFs.Rename\n"));
334 test.Printf(_L("Test rename into root\n"));
335 if ((c=gFile.Replace(TheFs,_L("\\TESTPAT1.DAT"),EFileStream|P_FUPDATE))!=KErrNone)
336 Error(_L("Create testpat1"),c);
337 gDataBuf.Fill('X',512);
338 if ((c=gFile.Write(gDataBuf,512))!=KErrNone)
339 Error(_L("Write 90"),c);
341 if ((c=TheFs.MkDir(_L("\\DIRX\\")))!=KErrNone)
342 Error(_L("Make dir 90"),c);
345 xName.Format(_L("\\DIRX\\FILEX%u"),i);
346 TPtrC rootName(xName.Ptr()+5,xName.Length()-5);
347 testRenameToRoot(xName,rootName);
351 test.Printf(_L("Test rename from root\n"));
354 xName.Format(_L("\\DIRX\\FILEX%u"),i);
355 TPtrC rootName(xName.Ptr()+5,xName.Length()-5);
356 testRenameFromRoot(rootName,xName);
361 xName.Format(_L("\\DIRX\\FILEX%u"),i);
362 if ((c=TheFs.Delete(xName))!=KErrNone)
363 Error(_L("Delete 93"),c);
365 if ((c=TheFs.RmDir(_L("\\DIRX\\")))!=KErrNone)
366 Error(_L("Delete DIRX"),c);
368 if ((c=TheFs.Delete(_L("\\TESTPAT1.DAT")))!=KErrNone)
369 Error(_L("Delete 80"),c);
371 test.Printf(_L("Test rename with wild cards\n"));
372 if ((c=TheFs.Rename(_L("*.*"),_L("FRED")))!=NameErr)
373 Error(_L("Rename 100"),c);
374 if ((c=TheFs.Rename(_L("?"),_L("FRED")))!=NameErr)
375 Error(_L("Rename 101"),c);
376 if ((c=TheFs.Rename(_L(""),_L("FRED")))!=KErrBadName) // NameErr)
377 Error(_L("Rename 101.11"),c);
378 if ((c=TheFs.Rename(_L("."),_L("FRED")))!=NameErr)
379 Error(_L("Rename 101.12"),c);
380 if ((c=TheFs.Rename(_L("NOEXIST"),_L("*")))!=NameErr)
381 Error(_L("Rename 101.1"),c);
382 if ((c=gFile.Create(TheFs,_L("FILE1"),EFileStream))!=KErrNone)
383 Error(_L("Create 101.2"),c);
385 if ((c=TheFs.Rename(_L("FILE1"),_L("AAA?")))!=NameErr)
386 Error(_L("Rename 101.3"),c);
387 if ((c=TheFs.Rename(_L("FILE1"),_L("")))!=KErrBadName) // NameErr)
388 Error(_L("Rename 101.41"),c);
389 if ((c=TheFs.Rename(_L(""),_L("")))!=KErrBadName) // NameErr)
390 Error(_L("Rename 101.42"),c);
391 if ((c=TheFs.Delete(_L("FILE1")))!=KErrNone)
392 Error(_L("Delete 101.5"),c);
393 if ((c=TheFs.Rename(_L("\\"),_L("FRED")))!=NameErr)
394 Error(_L("Rename 101.6"),c);
396 test.Printf(_L("Test rename of directories\n"));
397 if ((c=TheFs.MkDir(_L("\\DIR1\\")))!=KErrNone)
398 Error(_L("Make dir 102"),c);
399 if ((c=TheFs.Rename(_L("\\DIR1"),_L("\\A2345678.123")))!=KErrNone)
400 Error(_L("Rename 103.1"),c);
401 if ((c=TheFs.Rename(_L("\\A2345678.123"),_L("\\DIR2")))!=KErrNone)
402 Error(_L("Rename 103.2"),c);
403 if ((c=TheFs.Rename(_L("\\DIR2"),_L("\\A234567.1234")))!=KErrNone) // ****** NameErr) Long filenames are supported
404 Error(_L("Rename 103.3"),c);
405 if ((c=TheFs.Rename(_L("\\A234567.1234"),_L("\\DIR2")))!=KErrNone)
406 Error(_L("Rename 103.3"),c);
407 if ((c=TheFs.MkDir(_L("\\DIR1\\")))!=KErrNone)
408 Error(_L("Make dir 104"),c);
410 test.Printf(_L("Test rename of open files\n"));
411 if ((c=gFile.Create(TheFs,_L("\\DIR1\\FILE1"),EFileStreamText))!=KErrNone)
412 Error(_L("Create 105"),c);
413 if ((c=TheFs.Rename(_L("\\DIR1\\FILE1"),_L("\\DIR1\\FILE1")))!=LockedErr)
414 Error(_L("Rename 106"),c);
415 if ((c=TheFs.Rename(_L("\\DIR1\\FILE1"),_L("\\DIR2\\FILE1")))!=LockedErr)
416 Error(_L("Rename 106.1"),c);
417 if ((c=gFile2.Open(TheFs,_L("\\DIR2\\FILE1"),EFileStream))!=NotExistsErr)
418 Error(_L("Create 105"),c);
421 test.Printf(_L("Test rename to same name\n"));
422 if ((c=TheFs.Rename(_L("\\DIR1\\FILE1"),_L("\\DIR1\\FILE1")))!=KErrNone) // !=ExistsErr)
423 Error(_L("Rename 105.1"),c);
424 if ((c=TheFs.Rename(_L("\\DIR1"),_L("\\DIR1")))!=KErrNone) // !=ExistsErr)
425 Error(_L("Rename 105.2"),c);
427 test.Printf(_L("Test rename of read-only files\n")); // IS ALLOWED //
428 if ((c=TheFs.SetAtt(_L("\\DIR1\\FILE1"),KEntryAttReadOnly,0))!=KErrNone)
429 Error(_L("Att 106"),c);
430 if ((c=TheFs.Entry(_L("\\DIR1\\FILE1"),gFileEntry))!=KErrNone)
431 Error(_L("File info 106.1"),c);
432 test.Printf(_L("STATUS=%04x\n"),gFileEntry.iAtt);
433 if (gFileEntry.iAtt!=(TUint32)(P_FAREAD|P_FASTREAM|P_FAMOD))
434 Error(_L("Status check 106.2"),0);
435 if ((c=TheFs.Entry(_L("\\DIR1"),gFileEntry))!=KErrNone)
436 Error(_L("File info 106.3"),c);
437 test.Printf(_L("STATUS=%04x\n"),gFileEntry.iAtt);
438 if (gFileEntry.iAtt!=(TUint32)(P_FASTREAM|P_FADIR))
439 Error(_L("Status check 106.4"),0);
441 if ((c=TheFs.Rename(_L("\\DIR1\\FILE1"),_L("\\DIR1\\FILE1")))!=KErrNone) // !=ExistsErr)
442 Error(_L("Rename 107"),c);
443 if ((c=TheFs.Rename(_L("\\DIR1\\FILE1"),_L("\\DIR1\\FILE2")))!=KErrNone)
444 Error(_L("Rename 108"),c);
445 if ((c=TheFs.Rename(_L("\\DIR1\\FILE2"),_L("\\DIR2\\FILE2")))!=KErrNone)
446 Error(_L("Rename 109"),c);
447 if ((c=gFile2.Open(TheFs,_L("\\DIR2\\FILE2"),EFileStream))!=KErrNone)
448 Error(_L("Create 110"),c);
450 if ((c=TheFs.Rename(_L("\\DIR2\\FILE2"),_L("\\DIR1\\FILE1")))!=KErrNone)
451 Error(_L("Rename 110.1"),c);
452 if ((c=TheFs.SetAtt(_L("\\DIR1\\FILE1"),0,KEntryAttReadOnly))!=KErrNone)
453 Error(_L("Att 111"),c);
455 test.Printf(_L("Test rename of files across directories\n"));
456 if ((c=TheFs.Rename(_L("\\DIR1\\FILE1"),_L("\\DIR2\\FILE1")))!=KErrNone)
457 Error(_L("Rename 112"),c);
458 if ((c=gFile.Open(TheFs,_L("\\DIR2\\FILE1"),EFileStream))!=KErrNone)
459 Error(_L("Exist 113"),c);
462 test.Printf(_L("Test rename of directories across directories\n"));
463 if ((c=TheFs.Rename(_L("\\DIR1"),_L("\\DIR2\\DIR1")))!=KErrNone) // ******** AccessErr)
464 Error(_L("Rename 114"),c);
465 if ((c=TheFs.Rename(_L("\\DIR1"),_L("\\")))!=NameErr)
466 Error(_L("Rename 114.1"),c);
468 if ((c=TheFs.Delete(_L("\\DIR2\\FILE1")))!=KErrNone)
469 Error(_L("Delete 115"),c);
470 if ((c=TheFs.RmDir(_L("\\DIR2\\DIR1\\")))!=KErrNone)
471 Error(_L("Delete 115"),c);
472 if ((c=TheFs.RmDir(_L("\\DIR2\\")))!=KErrNone)
473 Error(_L("Delete 115"),c);
475 TestINC103141(); // PDEF104017
478 LOCAL_C void testDelete()
480 // Test RFs::Delete function.
485 test.Printf(_L("Test RFs::Delete\n"));
486 test.Printf(_L("Test delete non-empty directories\n"));
487 if ((c=TheFs.MkDir(_L("\\TESTDIR\\")))!=KErrNone)
488 Error(_L("Make dir 500"),c);
489 if ((c=gFile.Create(TheFs,_L("\\TESTDIR\\NAME.EXT"),EFileStream))!=KErrNone)
490 Error(_L("Create"),c);
491 if ((c=TheFs.Delete(_L("\\TESTDIR\\")))!=KErrBadName) // ******* AccessErr)
492 Error(_L("Delete 501"),c);
494 test.Printf(_L("Test delete open file\n"));
495 if ((c=TheFs.Delete(_L("\\TESTDIR\\NAME.EXT")))!=LockedErr)
496 Error(_L("Delete 502"),c);
498 if ((c=TheFs.Delete(_L("\\TESTDIR\\NAME.EXT")))!=KErrNone)
499 Error(_L("Delete 503"),c);
500 if ((c=TheFs.RmDir(_L("\\TESTDIR\\")))!=KErrNone)
501 Error(_L("Delete 504"),c);
504 LOCAL_C void testUnique(TUint fileFormat)
512 test.Printf(_L("Test RFile::Temp\n"));
513 gDataBuf.SetLength(1);
514 if ((c=gFile.Temp(TheFs,_L(""),gNameBuf,fileFormat))!=KErrNone)
515 Error(_L("Directory open 2000"),c);
516 if ((c=gFile.Write(gDataBuf,0))!=KErrNone)
517 Error(_L("Write 2000"),c);
518 if ((c=gFile.Write(gDataBuf,1))!=KErrNone)
519 Error(_L("Write 2000"),c);
521 if ((c=gFile.Seek(ESeekStart,pos))!=KErrNone) // !=E_FILE_INV) Temp file is random access
522 Error(_L("Seek 2000"),c);
524 if ((c=TheFs.Delete(gNameBuf))!=KErrNone)
525 Error(_L("Delete"),c);
528 LOCAL_C void testFileName(const TDesC& aFileName,TInt res)
535 if ((c=aFileName.Length())>20)
536 test.Printf(_L("%u char name\n"),c);
538 test.Printf(_L("\"%S\"\n"),&aFileName);
539 if ((c=gFile.Create(TheFs,aFileName,EFileStream))!=res)
540 Error(_L("Create 200"),c);
544 if ((c=gFile.Open(TheFs,aFileName,EFileStream))!=KErrNone)
545 Error(_L("Open 200"),c);
547 if ((c=TheFs.Delete(aFileName))!=KErrNone)
548 Error(_L("Delete 200"),c);
552 if ((c=gFile.Open(TheFs,aFileName,EFileStream))!=res) // test eg *.* //
553 Error(_L("Open 201"),c);
554 if ((c=gFile.Replace(TheFs,aFileName,EFileStream))!=res)
555 Error(_L("Replace 202"),c);
559 #if defined(_UNICODE)
560 LOCAL_C void testFileName(const TDesC8& aFileName,TInt res)
562 // Defined to cope with all the instances of testFileName(gDataBuf,...)
565 TPtrC gDataBuf16((TText*)aFileName.Ptr(),gDataBuf.Size()/sizeof(TText8));
566 testFileName(gDataBuf16,res);
570 LOCAL_C void testVolumeName(const TDesC& aVolumeName,TInt aResultExpected)
577 test.Printf(_L("\"%S\"\n"),&aVolumeName);
578 TInt drive=KDefaultDrive;
579 if (aVolumeName.Length()>=2 && aVolumeName[0]=='Z' && aVolumeName[1]==':')
582 TPtr volName((TText*)&aVolumeName[2],(aVolumeName.Length()-2),(aVolumeName.Length()-2));
583 result=TheFs.SetVolumeLabel(volName,drive);
586 result=TheFs.SetVolumeLabel(aVolumeName,drive);
588 if (result==KErrGeneral)
590 test.Printf(_L("KErrGeneral: Cannot set volume label on a substed drive!\n"));
593 if (result!=aResultExpected)
594 Error(_L("Set volume name returned"),result);
596 /* if (aResultExpected==FALSE)
598 if ((result=TheFs.Volume(volInfo))!=KErrNone)
599 Error(_L("Volume Info failed"),result);
600 TPtrC vol(aVolumeName);
601 if (vol!=volInfo.iName)
602 Error(_L("Check volume name failed"),0);
607 #define testMakeDir(aDirName, res) TestMakeDirLine(aDirName, res, __LINE__)
608 LOCAL_C void TestMakeDirLine(const TDesC& aDirName,TInt res, TInt line)
617 if ((c=aDirName.Length())>20)
618 test.Printf(_L("%u char name\n"),c);
620 test.Printf(_L("\"%S\"\n"),&aDirName);
621 if ((c=TheFs.MkDirAll(aDirName))!=res)
622 Error2(_L("Make directory 1"),c, line);
626 c=TheFs.Parse(aDirName,parse);
630 if (buf.Length()<=64)
632 test.Printf(_L("Open dir...\n"));
633 if ((c=gDir.Open(TheFs,buf,KEntryAttMaskSupported))!=KErrNone)
634 Error2(_L("Directory open 1"),c, line);
636 if ((c=gDir.Read(gFileEntry))!=EofErr)
638 test.Printf(_L("buf=\"%S\"\n"),&gFileEntry.iName);
639 Error2(_L("Directory read"),c, line);
647 test.Printf(_L("Delete \"%S\"\n"),&buf);
648 if ((c=TheFs.RmDir(buf))!=KErrNone)
649 Error2(_L("Delete directory"),c, line);
655 if (buf.LocateReverse('\\')==0)
666 #if defined(_UNICODE)
667 LOCAL_C void TestMakeDirLine(const TDesC8& aDirName, TInt res, TInt line)
669 // Defined to cope with all the instances of testMakeDir(gDataBuf,...)
673 TPtrC gDataBuf16((TText*)aDirName.Ptr(),gDataBuf.Size()/sizeof(TText8));
674 // Not sizeof(TText16) since gDataBuf is a TBuf*!
675 TestMakeDirLine(gDataBuf16, res, line);
680 LOCAL_C void testMedia(const TDesC& instructions,TInt anErr)
689 // p_errs(&errBuf[0],anErr);
691 pathBuf.SetLength(7);
692 test.Printf(_L("Test %S\n"),&errBuf);
693 test.Printf(_L("%S %S\n"),&instructions,&pathBuf);
696 if (anErr==WriteProtectErr)
698 if ((c=gFile.Open(TheFs,fBuf,P_FDIR))!=openErr)
699 Error(_L("Directory open 100"),c);
700 if (openErr==KErrNone)
703 Error(_L("Close 100"),c);
705 gNameBuf.SetLength(0);
706 if ((c=gFile.Open(TheFs,gNameBuf,P_FUNIQUE|EFileStream))!=anErr)
707 Error(_L("Create unique 100"),c);
711 Error(_L("Close 100"),c);
716 GLDEF_C void CallTestsL()
729 CreateTestDirectory(_L("\\F32-TST\\BGEN\\"));
730 // if (p_date()<MINIMUM_DATE)
731 // p_sdate(MINIMUM_DATE);
738 // testDir(_L("Z:")); // Session Path gets added -> KErrPathNotFound
739 // testDir(_L("Z:*")); // Session Path gets added -> KErrPathNotFound
740 // testDir(_L("Z:*.*")); // Session Path gets added -> KErrPathNotFound
742 testDir(_L("Z:\\*"));
743 testDir(_L("Z:\\*.*"));
745 test.Printf(_L("Test names containing '\\'\n"));
746 if ((c=gFile.Create(TheFs,_L("Q\\ZZZ"),EFileWrite))!=NameErr)
747 Error(_L("Create 1"),c);
749 test.Printf(_L("Test create in non-exist directory\n"));
750 if ((c=gFile.Create(TheFs,_L("\\Q1DDX\\ZZZ"),EFileWrite))!=DirErr)
751 Error(_L("Create 2"),c);
753 test.Printf(_L("Test filenames starting with '.'\n"));
754 if ((c=gFile.Create(TheFs,_L("\\.ZZZ"),EFileWrite))!=KErrNone) // ****** NameErr)
755 Error(_L("Create 3"),c);
757 if ((c=TheFs.Delete(_L("\\.ZZZ")))!=KErrNone)
758 Error(_L("Delete 3"),c);
760 test.Printf(_L("Test filenames starting with 05/E5\n"));
761 gNameBuf.SetLength(5);
767 gNameBuf.SetLength(4);
768 if ((c=gFile.Replace(TheFs,gNameBuf,EFileWrite))!=KErrNone)
769 Error(_L("Replace 4"),c);
771 if ((c=gFile.Open(TheFs,gNameBuf,EFileRead))!=KErrNone)
772 Error(_L("Open 4"),c);
775 // *************** Silly filename stuff rightly disallowed by NT
776 // gNameBuf.SetLength(5);
781 // gNameBuf[4]=0x00; // Zero terminator gets lost by VFAT
782 // if ((c=gFile.Replace(TheFs,gNameBuf,EFileWrite))!=KErrNone)
783 // Error(_L("Create 5"),c);
786 // if ((c=gFile.Open(TheFs,gNameBuf,EFileRead))!=KErrNone)
787 // Error(_L("Open 5"),c);
794 // goto skipMediaTest;
795 // testMedia(_L("OPEN DOOR ON"),NotReadyErr);
796 // testMedia(_L("INSERT CORRUPT RAM PACK (WRITE ENABLED) INTO"),CorruptMediaErr);
797 // testMedia(_L("INSERT CORRUPT RAM PACK (WRITE PROTECTED) INTO"),CorruptMediaErr);
798 // testMedia(_L("INSERT CORRUPT FLASH PACK (WRITE ENABLED) INTO"),CorruptMediaErr);
799 // testMedia(_L("INSERT CORRUPT FLASH PACK (WRITE PROTECTED) INTO"),CorruptMediaErr);
801 // testMedia(_L("INSERT UNKNOWN MEDIA INTO"),UnknownErr);
803 // testMedia(_L("INSERT GOOD RAM PACK (WRITE PROTECTED) INTO"),WriteProtectErr);
804 // if ((c=gFile.Open(TheFs,fBuf,P_FFORMAT))!=WriteProtectErr)
805 // Error(_L("Format RAM write protect"),c);
806 // testMedia(_L("INSERT GOOD FLASH PACK (WRITE PROTECTED) INTO"),WriteProtectErr);
807 // if ((c=gFile.Open(TheFs,fBuf,P_FFORMAT))!=WriteProtectErr)
808 // Error(_L("Format FLASH write protect"),c);
809 // testMedia(_L("INSERT GOOD PACK (WRITE ENABLED) INTO"),0);
812 //#endif // TEST_MEDIA //
815 // Test update is assumed for unique //
817 testUnique(EFileStream);
818 testUnique(EFileStreamText);
821 test.Printf(_L("Test get file info\n"));
822 // testFileInfo(_L("*.*"),NameErr); ********** Allowed (?)
823 testFileInfo(_L(""),KErrNone); // NameErr);
824 testFileInfo(_L("\\"),NameErr);
825 testFileInfo(_L("."),NameErr);
826 testFileInfo(_L(".."),NameErr);
827 testFileInfo(_L("a.1234"),KErrNotFound); // ********* NameErr);
828 testFileInfo(_L("a23456789"),KErrNotFound); // ********* NameErr);
829 testFileInfo(_L(".a"),KErrNotFound); // ********** NameErr);
830 testFileInfo(_L("?"),NameErr);
831 testFileInfo(_L("NOEXIST"),NotExistsErr);
832 testFileInfo(_L("\\NODIR\\NAME"),DirErr);
833 testFileInfo(_L("L:\\NAME"),DeviceErr);
834 gNameBuf.SetLength(0);
835 if ((c=gFile.Temp(TheFs,gNameBuf,gNameOut,EFileStream))!=KErrNone)
836 Error(_L("Open 1.1"),c);
837 testFileInfo(gNameOut,FALSE); // Not locked //
839 testFileInfo(gNameOut,FALSE);
840 if ((c=TheFs.Delete(gNameOut))!=KErrNone)
841 Error(_L("Delete"),c);
843 test.Printf(_L("Test get device info\n"));
844 testDeviceInfo(_L(""),FALSE); // NULL is current device //
845 testDeviceInfo(_L("L:"),DeviceErr);
846 testDeviceInfo(_L("Z:"),FALSE);
847 testDeviceInfo(fBuf,FALSE);
850 // test.Printf(_L("Test get node info\n"));
851 // testNodeInfo(_L("LOC::"),P_FSYSTYPE_HIER,FALSE);
852 // testNodeInfo(_L("Z:"),P_FSYSTYPE_FLAT,FALSE);
853 // testNodeInfo(_L("LOC:"),P_FSYSTYPE_HIER,FALSE);
854 // testNodeInfo(_L("LOC"),P_FSYSTYPE_HIER,FALSE);
855 // testNodeInfo(_L("*"),P_FSYSTYPE_HIER,FALSE);
856 // testNodeInfo(_L(""),P_FSYSTYPE_HIER,FALSE);
857 // testNodeInfo(_L("?"),P_FSYSTYPE_HIER,FALSE);
858 // testNodeInfo(_L("FRED"),P_FSYSTYPE_HIER,FALSE);
859 // testNodeInfo(_L("FRED::"),P_FSYSTYPE_HIER,FALSE);
860 // testNodeInfo(_L("....."),P_FSYSTYPE_HIER,FALSE);
861 // testNodeInfo(_L("LOC::zzzzzzzzzzzzzzzzzzzzzzzzz"),P_FSYSTYPE_HIER,FALSE);
862 // testNodeInfo(_L("LOC::\\"),P_FSYSTYPE_HIER,FALSE);
863 // testNodeInfo(_L("XXX::"),0,E_GEN_FSYS);
864 // testNodeInfo(_L("REM::"),0,E_GEN_FSYS);
865 // testNodeInfo(_L("...::"),0,E_GEN_FSYS);
867 // testFileInfo(_L("Z:SYS$WSRV.IMG"),FALSE);
868 // testFileInfo(_L("Z:\\SYS$WSRV.IMG"),NameErr); // \ not allowed - no path //
869 // testFileInfo(_L("Z:*"),FALSE); // Z: allows *'s ! //
870 // testFileInfo(_L("Z:SYS$WSRV."),NotExistsErr);
871 // testFileInfo(_L("XXX::"),NoFileSystemErr);
872 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
873 testFileInfo(_L("Z:\\Sys\\Bin\\ESHELL.EXE"),FALSE); // we now have paths //
875 testFileInfo(_L("Z:\\System\\Bin\\ESHELL.EXE"),FALSE); // we now have paths //
876 // testFileInfo(_L("Z:*"),KErrPathNotFound); // session path gets inserted ,FALSE);
877 // testFileInfo(_L("Z:SYS$WSRV."),NotExistsErr);
878 // testFileInfo(_L("H:"),KErrBadName); // ************** NoFileSystemErr);
880 test.Printf(_L("Test weird filenames\n"));
883 testFileName(_L("A B"),KErrNone); // ******* NameErr);
884 testFileName(_L(" AB"),KErrNone); // ******* NameErr);
885 testFileName(_L(" AB "),KErrNone); // ******* NameErr);
886 testFileName(_L(" AB"),KErrNone);
887 testFileName(_L(" AB . cdef"),KErrNone);
888 testFileName(_L(" AB . cdef "),KErrNone);
889 testFileName(_L("A2345678 "),KErrNone); // ******* NameErr);
890 testFileName(_L("A2345678.XY "),KErrNone); // ******* NameErr);
891 testFileName(_L("A2345678.XYZ "),KErrNone); // ******* NameErr);
892 testFileName(_L("A2345678 XYZ"),KErrNone); // ******* NameErr);
893 testFileName(_L(" "),NameErr);
894 testFileName(_L("\\A B\\NAME"),KErrPathNotFound); // ******* NameErr);
895 testFileName(_L("\\ \\NAME"),NameErr);
896 testFileName(_L("\\asdf\\qer\\ \\asdf\\NAME"),NameErr);
897 testFileName(_L(" "),NameErr);
898 testFileName(_L("C:\\asdf\\ "),NameErr);
899 // Test short names //
900 testFileName(_L(""),NameErr);
901 testFileName(_L("\\"),NameErr);
902 testFileName(_L("1"),FALSE);
903 testFileName(_L(".1"),KErrNone); // ******* NameErr);
904 testFileName(_L(".1"),KErrNone); // ******* NameErr);
905 testFileName(_L("\\.1"),KErrNone); // ******* NameErr);
906 testFileName(_L("1.1"),FALSE);
907 // Test long names //
908 testFileName(_L("12345678.123"),FALSE);
909 testFileName(_L("123456789.123"),KErrNone); // ******* NameErr);
910 testFileName(_L("12345678.1234"),KErrNone); // ******* NameErr);
911 testFileName(_L("1.1234"),KErrNone); // ******* NameErr);
912 testFileName(_L("123456789"),KErrNone); // ******* NameErr);
913 gDataBuf.SetLength(256);
914 gDataBuf.Fill('A',255);
915 testFileName(gDataBuf,NameErr);
916 gDataBuf.SetLength(257);
917 gDataBuf.Fill('B',256);
918 testFileName(gDataBuf,NameErr);
919 gDataBuf.SetLength(258);
920 gDataBuf.Fill('C',257);
921 testFileName(gDataBuf,NameErr);
922 gDataBuf.SetLength(4096);
923 gDataBuf.Fill('D',4095);
924 testFileName(gDataBuf,NameErr);
926 testFileName(_L("A.X"),FALSE);
927 testFileName(_L("A..X"),KErrNone); // ******* NameErr);
928 testFileName(_L("A.........X"),KErrNone); // ******* NameErr);
929 testFileName(_L("A."),FALSE);
930 testFileName(_L(".X"),KErrNone); // ******* NameErr);
931 testFileName(_L("."),NameErr);
932 testFileName(_L(".."),NameErr);
933 // testFileName(_L("..."),KErrNone); // NameErr); // !!! ********* NT error KErrAccessDenied (?)
934 testFileName(_L("\\a.x\\NAME"),DirErr); // DirErr == KErrPathNotFound
935 testFileName(_L("\\a..x\\NAME"),DirErr); // ******** NameErr);
936 testFileName(_L("\\.\\NAME"),NameErr);
937 testFileName(_L("\\..\\NAME"),NameErr);
938 // testFileName(_L("\\...\\NAME"),KErrPathNotFound); // ******** NameErr); // !! NT treats ... as .. ??
939 // Test WILD CARDS //
940 testFileName(_L("*.*"),NameErr);
941 testFileName(_L("*"),NameErr);
942 testFileName(_L("\\*"),NameErr);
943 testFileName(_L("?"),NameErr);
944 testFileName(_L("\\?"),NameErr);
945 testFileName(_L("\\A?B\\NAME"),NameErr);
946 testFileName(_L("\\A*B\\NAME"),NameErr);
947 testFileName(_L("\\*\\NAME"),NameErr);
948 testFileName(_L("\\********.***\\NAME"),NameErr);
949 testFileName(_L("A?X"),NameErr);
951 test.Printf(_L("Test set volume name\n"));
952 // New behaviour: SetVolumeName accepts any string < 12 chars
953 // No modifications are made on the string.
954 #if defined(__WINS__)
955 TInt ret=TheFs.SetVolumeLabel(_L("TEST"),KDefaultDrive);
956 if(ret==KErrNotSupported||ret==KErrAccessDenied)
958 test.Printf(_L("Error: Cannot set volume label on substed drive\n"));
964 testVolumeName(_L("TESTNAME.VOL"),KErrBadName); // 12 chars - too long for volume label
965 testVolumeName(_L("TESTNAME"),FALSE); // OK for 8 bit - too long for UNICODE
966 testVolumeName(_L("PQRSTUVWXYZ"),FALSE); // just uses the first 5 characters
967 testVolumeName(_L("ABCDE"),FALSE);
968 testVolumeName(_L("FGHIJK"),FALSE);
969 testVolumeName(_L(""),FALSE);
970 testVolumeName(_L(""),FALSE);
971 testVolumeName(_L("\\"),FALSE);
972 gNameBuf.SetLength(0);
973 if ((c=gFile.Temp(TheFs,gNameBuf,gNameOut,EFileStream))!=KErrNone)
974 Error(_L("Open 60"),c);
975 testVolumeName(_L("TEST_NAME"),FALSE); // Check not locked
977 if ((c=TheFs.Delete(gNameOut))!=KErrNone)
978 Error(_L("Delete"),c);
979 testVolumeName(_L("voL1"),FALSE);
980 testVolumeName(_L("\\vol1"),FALSE);
981 testVolumeName(_L("\\12345678.123"),KErrBadName);
982 testVolumeName(_L("\\123456.123"),FALSE);
983 testVolumeName(_L("\\vol1\\"),KErrNone);
984 testVolumeName(_L("."),KErrBadName); // Bug fix SW1-728 to prevent illegal characters
985 testVolumeName(_L(".."),KErrBadName); // in the volume name
986 testVolumeName(_L("A."),KErrBadName);
987 if (!IsTestingLFFS())
989 testVolumeName(_L("!\"\x9C$%^&@.(){"),KErrBadName);
990 testVolumeName(_L("!\"\x9C$%^&@("),KErrBadName);
992 testVolumeName(_L("*.*"),KErrBadName); // Wild cards not allowed
993 testVolumeName(_L("?.?"),KErrBadName);
994 testVolumeName(_L("????????.???"),KErrBadName);
995 testVolumeName(_L("????????.??"),KErrBadName);
996 testVolumeName(_L("ABC>DEF"),KErrBadName);
997 testVolumeName(_L("ABC<DEF"),KErrBadName);
998 testVolumeName(_L("ABC|DEF"),KErrBadName);
999 testVolumeName(_L("ABC/DEF"),KErrBadName);
1000 testVolumeName(_L("ABC\"DEF"),KErrBadName);
1001 testVolumeName(_L("ABC*DEF"),KErrBadName);
1002 testVolumeName(_L("ABC:DEF"),KErrBadName);
1003 testVolumeName(_L("ABC?DEF"),KErrBadName);
1004 testVolumeName(_L("ABC\\DEF"),KErrBadName);
1005 testVolumeName(_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),KErrBadName); // Too long
1006 testVolumeName(_L("VOLUME1"),FALSE); // Too long in UNICODE
1007 testVolumeName(_L("Z:VOLUME1"),KErrAccessDenied);
1010 test.Printf(_L("Test make directory\n"));
1013 testMakeDir(_L("\\A2345678.A23\\NAME"),FALSE);
1014 testMakeDir(_L("\\A23456789.A23\\NAME"),KErrNone); // ******** NameErr);
1015 testMakeDir(_L("\\A2345678.A234\\NAME"),KErrNone); // ******** NameErr);
1016 testMakeDir(_L("\\A.1234\\NAME"),KErrNone); // ********* NameErr);
1017 testMakeDir(_L("\\A2345678\\NAME"),FALSE);
1018 testMakeDir(_L("\\A23456789\\NAME"),KErrNone); // ******** NameErr);
1019 testMakeDir(_L("\\A.X\\NAME"),FALSE);
1020 testMakeDir(_L("\\A..X\\NAME"),KErrNone); // ******** NameErr);
1021 testMakeDir(_L("\\A.\\NAME"),NameErr);
1022 testMakeDir(_L("\\.X\\NAME"),KErrNone); // ******** NameErr);
1023 testMakeDir(_L("\\.\\NAME"),NameErr);
1024 testMakeDir(_L("\\..\\NAME"),NameErr);
1025 testMakeDir(_L("\\\\NAME"),NameErr);
1026 testMakeDir(_L("\\\\"),NameErr);
1027 testMakeDir(_L("\\A\\A2\\A23\\a2345678\\a2345678.\\a2345678.1\\a2345678.123"),NameErr);
1028 testMakeDir(_L("\\A\\A2\\A23\\a2345678\\a2345678.\\a2345678.1\\a2345678..123"),NameErr); // ******* NameErr);
1029 testMakeDir(_L("\\A\\A2\\A23\\a2345678\\a2345678.\\a2345678.1\\a2345678.1234"),NameErr); // ******* NameErr);
1030 gDataBuf.SetLength(256);
1031 gDataBuf.Fill('V',255);
1032 testMakeDir(gDataBuf,NameErr);
1033 gDataBuf.SetLength(257);
1034 gDataBuf.Fill('W',256);
1035 testMakeDir(gDataBuf,NameErr);
1036 gDataBuf.SetLength(258);
1037 gDataBuf.Fill('X',257);
1038 testMakeDir(gDataBuf,NameErr);
1039 gDataBuf.SetLength(259);
1040 gDataBuf.Fill('Y',258);
1041 testMakeDir(gDataBuf,NameErr);
1042 gDataBuf.SetLength(4096);
1043 gDataBuf.Fill('Z',4095);
1044 testMakeDir(gDataBuf,NameErr);
1047 testMakeDir(_L("A..X"),KErrAlreadyExists); // ******* NameErr);
1048 testMakeDir(_L("\\A\\"),FALSE);
1049 testMakeDir(_L("\\12345678.123\\"),FALSE);
1050 testMakeDir(_L("\\.\\"),NameErr);
1051 testMakeDir(_L("\\..\\"),NameErr);
1052 testMakeDir(_L("\\X\\"),FALSE);
1053 testMakeDir(_L("\\12345678.1234\\"),KErrNone); // ******* NameErr);
1054 testMakeDir(_L("\\123456789\\"),KErrNone); // ******** NameErr);
1056 testMakeDir(_L("\\A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z"),FALSE);
1057 testMakeDir(_L("\\00000000.000\\11111111.111\\22222222.222\\33333333.333\\45678901.3"),FALSE);
1058 testMakeDir(_L("\\00000000.000\\11111111.111\\22222222.222\\33333333.333\\45678901.34"),FALSE);
1059 testMakeDir(_L("\\00000000.000\\11111111.111\\22222222.222\\33333333.333\\45678901.345"),FALSE);
1060 testMakeDir(_L("\\00000000.000\\11111111.111\\22222222.222\\33333333.333\\45678901.3\\xxxxxxxx.xxx"),FALSE);
1061 testMakeDir(_L("\\00000000.000\\11111111.111\\22222222.222\\33333333.333\\45678901.34\\xxxxxxxx.xxx"),KErrNone); // ******* NameErr);
1062 testMakeDir(_L("\\00000000.000\\11111111.111\\22222222.222\\33333333.333\\45678901.345\\xxxxxxxx.xxx"),KErrNone); // ******* NameErr);
1063 testMakeDir(_L("\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\23"),FALSE);
1064 testMakeDir(_L("\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\23456789.123"),FALSE);
1065 testMakeDir(_L("\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\23\\5"),FALSE);
1066 testMakeDir(_L("\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\23\\56789012.456"),FALSE);
1067 testMakeDir(_L("\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\2\\4\\6\\8\\0\\234\\6"),KErrNone); // ******** NameErr);
1068 testMakeDir(_L("Z:\\ROMDIR\\"),KErrAccessDenied); // *********** NotSupportedErr);
1069 test.Printf(_L("Test setEof to same length\n"));
1070 gNameBuf.SetLength(0);
1071 if ((c=gFile.Temp(TheFs,gNameBuf,gNameOut,EFileStream|P_FUPDATE))!=KErrNone)
1072 Error(_L("Open 50"),c);
1074 testSetEof(gNameOut,0L,FALSE); // should be no change //
1075 testSetEof(gNameOut,1L,TRUE); // should be change //
1076 testSetEof(gNameOut,1L,FALSE); // should be no change //
1077 testSetEof(gNameOut,1L,FALSE);
1079 testSize=650L; // No room on M: for 65536 ! //
1082 testSetEof(gNameOut,testSize,TRUE);
1083 testSetEof(gNameOut,testSize,FALSE);
1084 testSetEof(gNameOut,testSize+1L,TRUE);
1085 testSetEof(gNameOut,testSize,TRUE);
1087 testSetEof(gNameOut,0L,TRUE);
1088 testSetEof(gNameOut,0L,FALSE);
1089 if ((c=TheFs.Delete(gNameOut))!=KErrNone)
1090 Error(_L("Delete"),c);
1092 test.Printf(_L("Test read of zero bytes\n"));
1093 gNameBuf.SetLength(0);
1095 if ((c=gFile.Temp(TheFs,gNameBuf,gNameOut,EFileStream|P_FUPDATE))!=KErrNone)
1096 Error(_L("Open 60"),c);
1097 if ((c=gFile.Read(gDataBuf,0))!=KErrNone) // ******** EofErr)
1098 Error(_L("Read 61"),c);
1099 if ((c=gFile.Read(gDataBuf,0))!=KErrNone) // ******** EofErr)
1100 Error(_L("Read 62"),c);
1101 if ((c=gFile.Write(gDataBuf,0))!=KErrNone)
1102 Error(_L("Write 63"),c);
1103 if ((c=gFile.Read(gDataBuf,0))!=KErrNone) // ******** EofErr)
1104 Error(_L("Read 64"),c);
1106 if ((c=gFile.Open(TheFs,gNameOut,EFileStream|P_FUPDATE|P_FRANDOM))!=KErrNone)
1107 Error(_L("Open 70"),c);
1108 if ((c=gFile.Read(gDataBuf,0))!=KErrNone) // ******** EofErr)
1109 Error(_L("Read 71"),c);
1110 gDataBuf.SetLength(1);
1112 if ((c=gFile.Write(gDataBuf,1))!=KErrNone)
1113 Error(_L("Write 72"),c);
1114 if ((c=gFile.Read(gDataBuf,0))!=KErrNone) // ********* EofErr)
1115 Error(_L("Read 73"),c);
1117 if ((c=gFile.Seek((TSeek)P_FABS,pos))!=KErrNone)
1118 Error(_L("Seek 74"),c);
1119 gDataBuf.SetLength(1);
1121 if ((c=gFile.Read(gDataBuf,0))!=KErrNone)
1122 Error(_L("Read 75"),c);
1123 // if (gDataBuf[0]!=0x83) *********** Read zeros the length of a buffer after a zero length read
1124 if (gDataBuf.Length()!=0)
1125 Error(_L("buffer 1 check"),0);
1126 if ((c=gFile.Read(gDataBuf,0))!=KErrNone)
1127 Error(_L("Read 76"),c);
1128 if ((c=gFile.Read(gDataBuf,1))!=KErrNone || gDataBuf.Length()!=1)
1129 Error(_L("Read 77"),c);
1130 if (gDataBuf[0]!=0xf0)
1131 Error(_L("buffer 1 check"),0);
1132 if ((c=gFile.Read(gDataBuf,0))!=KErrNone) // ******** EofErr)
1133 Error(_L("Read 78"),c);
1134 if ((c=gFile.Read(gDataBuf,16384))!=KErrNone) // ******* EofErr)
1135 Error(_L("Read 79"),c);
1137 if ((c=TheFs.Delete(gNameOut))!=KErrNone)
1138 Error(_L("Delete"),c);
1140 test.Printf(_L("Test write of zero bytes\n"));
1141 gNameBuf.SetLength(0);
1142 if ((c=gFile.Temp(TheFs,gNameBuf,gNameOut,EFileStream|P_FUPDATE))!=KErrNone)
1143 Error(_L("Open 50"),c);
1145 // ********** Error(_L("Close"),c); close has no return value
1146 gDataBuf.SetLength(16384);
1148 testWrite(gNameOut,0,0L,FALSE); // should be no change //
1149 testWrite(gNameOut,1,1L,TRUE); // should be change //
1150 testWrite(gNameOut,0,1L,FALSE);
1151 testWrite(gNameOut,0,1L,FALSE);
1152 testWrite(gNameOut,16384,16384L,TRUE);
1153 testWrite(gNameOut,0,16384L,FALSE);
1154 testWrite(gNameOut,16383,16384L,TRUE);
1157 if ((c=TheFs.Delete(gNameOut))!=KErrNone)
1158 Error(_L("Delete"),c);
1160 test.Printf(_L("Test ReadOnly files\n"));
1161 gNameBuf.SetLength(0);
1162 if ((c=gFile.Create(TheFs,_L("TEST1.TMP"),EFileStream|P_FUPDATE))!=KErrNone)
1163 Error(_L("Create 40"),c);
1165 if ((c=gFile.Temp(TheFs,gNameBuf,gNameOut,EFileStream|P_FUPDATE))!=KErrNone)
1166 Error(_L("Open 40"),c);
1168 attrib=KEntryAttReadOnly; // Remove writable //
1169 if ((c=TheFs.SetAtt(gNameOut,attrib,mask))!=LockedErr)
1170 Error(_L("TheFs.SetAtt not locked"),c);
1172 if ((c=TheFs.SetAtt(gNameOut,attrib,mask))!=KErrNone)
1173 Error(_L("Att 41"),c);
1174 if ((c=gFile.Open(TheFs,gNameOut,EFileStream|P_FUPDATE))!=AccessErr)
1175 Error(_L("Open 41"),c);
1176 if ((c=gFile.Open(TheFs,gNameOut,EFileStream))!=KErrNone)
1177 Error(_L("Open 42"),c);
1178 if ((c=gFileErr.Open(TheFs,gNameOut,EFileStream))!=LockedErr)
1179 Error(_L("Open 43"),c);
1180 if ((c=TheFs.Rename(_L("TEST1.TMP"),gNameOut))!=ExistsErr)
1181 Error(_L("Rename 43.1"),c);
1182 if ((c=gFileErr.Create(TheFs,gNameOut,EFileStream))!=ExistsErr) // LockedErr)
1183 Error(_L("Open 44"),c);
1184 if ((c=gFileErr.Replace(TheFs,gNameOut,EFileStream))!=LockedErr)
1185 Error(_L("Open 45"),c);
1187 if ((c=gFile.Create(TheFs,gNameOut,EFileStream))!=ExistsErr)
1188 Error(_L("Create 46"),c);
1189 if ((c=gFile.Replace(TheFs,gNameOut,EFileStream))!=AccessErr)
1190 Error(_L("Replace 47"),c);
1191 if ((c=gFile.Create(TheFs,_L("FILE1.TMP"),EFileStream))!=KErrNone)
1192 Error(_L("Create 48"),c);
1193 if ((c=TheFs.Rename(_L("FILE1.TMP"),_L("FILE2.TMP")))!=LockedErr)
1194 Error(_L("Rename 49"),c);
1196 if ((c=TheFs.Rename(_L("FILE1.TMP"),_L("FILE2.TMP")))!=KErrNone)
1197 Error(_L("Rename 50"),c);
1198 if ((c=TheFs.Rename(_L("FILE2.TMP"),gNameOut))!=ExistsErr)
1199 Error(_L("Rename 51"),c);
1200 if ((c=TheFs.Delete(gNameOut))!=AccessErr)
1201 Error(_L("Delete"),c);
1202 mask=KEntryAttReadOnly;
1204 if ((c=TheFs.SetAtt(gNameOut,attrib,mask))!=KErrNone)
1205 Error(_L("Att 42"),c);
1206 if ((c=TheFs.Delete(gNameOut))!=KErrNone)
1207 Error(_L("Delete 1"),c);
1208 if ((c=TheFs.Delete(_L("TEST1.TMP")))!=KErrNone)
1209 Error(_L("Delete 2"),c);
1210 if ((c=TheFs.Delete(_L("FILE2.TMP")))!=KErrNone)
1211 Error(_L("Delete 3"),c);
1213 test.Printf(_L("Test write/setEof without UPDATE\n"));
1214 if ((c=gFile.Create(TheFs,_L("B_GEN.001"),EFileStream))!=KErrNone)
1215 Error(_L("Open 30"),c);
1217 if ((c=gFile.Open(TheFs,_L("B_GEN.001"),EFileStream))!=KErrNone)
1218 Error(_L("Open 30"),c);
1220 if ((c=gFile.SetSize(pos))!=ReadOnlyErr)
1221 Error(_L("Set EOF 30"),c);
1222 if ((c=TheFs.Entry(_L("B_GEN.001"),gFileEntry))!=KErrNone)
1223 Error(_L("File info 30"),c);
1224 if (gFileEntry.iSize!=0L)
1225 Error(_L("Size check 30"),0);
1226 if ((c=gFile.Write(gDataBuf,1))!=ReadOnlyErr)
1227 Error(_L("Write 30"),c);
1228 if ((c=TheFs.Entry(_L("B_GEN.001"),gFileEntry))!=KErrNone)
1229 Error(_L("File info 31"),c);
1230 if (gFileEntry.iSize!=0L)
1231 Error(_L("Size check 31"),0);
1233 if ((c=TheFs.Entry(_L("B_GEN.001"),gFileEntry))!=KErrNone)
1234 Error(_L("File info 32"),c);
1235 if (gFileEntry.iSize!=0L)
1236 Error(_L("Size check 32"),0);
1237 if ((c=TheFs.Delete(_L("B_GEN.001")))!=KErrNone)
1238 Error(_L("Delete"),c);
1241 test.Printf(_L("Test dir entries are written out\n"));
1242 gNameBuf.SetLength(0);
1243 if ((c=gFile.Temp(TheFs,gNameBuf,gNameOut,EFileStream|P_FRANDOM))!=KErrNone)
1244 Error(_L("Open 20"),c);
1245 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1246 Error(_L("File info 0"),c);
1247 if ((gFileEntry.iAtt & P_FAMOD)==0)
1248 Error(_L("Status 20"),0);
1249 test.Printf(_L("Size=%u\n"),gFileEntry.iSize);
1250 if (gFileEntry.iSize!=0L)
1251 Error(_L("Size check 0"),0);
1252 saveTime=gFileEntry.iModified;
1253 test.Printf(_L("Wait 3 seconds...\n"));
1254 User::After(3000000L);
1255 gDataBuf.SetLength(1);
1256 if ((c=gFile.Write(gDataBuf,1))!=KErrNone)
1257 Error(_L("Write 1"),c);
1258 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1259 Error(_L("File info 1"),c);
1260 test.Printf(_L("Size=%u\n"),gFileEntry.iSize);
1261 if (gFileEntry.iSize!=1L)
1262 Error(_L("Size check 1"),0);
1263 if (gFileEntry.iModified==saveTime)
1264 Error(_L("Time update"),0);
1265 gDataBuf.SetLength(16384);
1266 if ((c=gFile.Write(gDataBuf,16384))!=KErrNone)
1267 Error(_L("Write 2"),c);
1268 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1269 Error(_L("File info 2"),c);
1270 test.Printf(_L("Size=%u\n"),gFileEntry.iSize);
1271 if (gFileEntry.iSize!=16385L)
1272 Error(_L("Size check 2"),0);
1274 if ((c=gFile.Seek((TSeek)P_FABS,pos))!=KErrNone)
1275 Error(_L("Seek 0"),c);
1276 if ((c=gFile.Write(gDataBuf,1))!=KErrNone)
1277 Error(_L("Write 3"),c);
1278 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1279 Error(_L("File info 3"),c);
1280 test.Printf(_L("Size=%u\n"),gFileEntry.iSize);
1281 if (gFileEntry.iSize!=16385L)
1282 Error(_L("Size check 3"),0);
1284 if ((c=gFile.Seek((TSeek)P_FABS,pos))!=KErrNone)
1285 Error(_L("Seek 1"),c);
1286 if ((c=gFile.Write(gDataBuf,16384))!=KErrNone)
1287 Error(_L("Write 4"),c);
1288 if ((c=gFile.Write(gDataBuf,1))!=KErrNone)
1289 Error(_L("Write 5"),c);
1290 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1291 Error(_L("File info 4"),c);
1292 test.Printf(_L("Size=%u\n"),gFileEntry.iSize);
1293 if (gFileEntry.iSize!=16385L)
1294 Error(_L("Size check 4"),0);
1295 if ((c=gFile.Write(gDataBuf,1))!=KErrNone)
1296 Error(_L("Write 6"),c);
1297 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1298 Error(_L("File info 5"),c);
1299 test.Printf(_L("Size=%u\n"),gFileEntry.iSize);
1300 if (gFileEntry.iSize!=16386L)
1301 Error(_L("Size check 5"),0);
1304 TInt r=(Math::Rand(seed) & 0x7fff);
1305 test.Printf(_L("%u) Set eof to %u\n"),i,r);
1307 if ((c=gFile.SetSize(pos))!=KErrNone)
1308 Error(_L("Set EOF 1"),c);
1309 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1310 Error(_L("File info 6"),c);
1311 if (gFileEntry.iSize!=r)
1312 Error(_L("Size check 6"),i);
1315 if ((c=gFile.SetSize(pos))!=KErrNone)
1316 Error(_L("Set EOF 2"),c);
1317 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1318 Error(_L("File info 7"),c);
1319 if (gFileEntry.iSize!=0L)
1320 Error(_L("Size check 7"),0);
1322 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1323 Error(_L("File info 8"),c);
1324 if (gFileEntry.iSize!=0L)
1325 Error(_L("Size check 7"),0);
1328 if ((c=TheFs.SetAtt(gNameOut,attrib,mask))!=KErrNone)
1329 Error(_L("Att 20"),c);
1332 if ((c=gFile.Open(TheFs,gNameOut,EFileStream|P_FUPDATE|P_FRANDOM))!=KErrNone)
1333 Error(_L("Open 21"),c);
1334 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1335 Error(_L("File info 9"),c);
1336 if (gFileEntry.iAtt & P_FAMOD)
1337 Error(_L("Status 21"),0);
1338 if ((c=gFile.Write(gDataBuf,0))!=KErrNone)
1339 Error(_L("Write 21"),c);
1340 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1341 Error(_L("File info 9"),c);
1342 if ((gFileEntry.iAtt & P_FAMOD)) // write 0 should not modify //
1343 Error(_L("Status 22"),0);
1347 if ((c=TheFs.SetAtt(gNameOut,attrib,mask))!=KErrNone)
1348 Error(_L("Att 20"),c);
1349 if ((c=gFile.Open(TheFs,gNameOut,EFileStream|P_FUPDATE|P_FRANDOM))!=KErrNone)
1350 Error(_L("Open 22"),c);
1351 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1352 Error(_L("File info 9"),c);
1353 if (gFileEntry.iAtt & P_FAMOD)
1354 Error(_L("Status 23"),0);
1356 if ((c=gFile.SetSize(pos))!=KErrNone) // no change //
1357 Error(_L("Set EOF 21"),c);
1358 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1359 Error(_L("File info 9"),c);
1360 if ((gFileEntry.iAtt & P_FAMOD))
1361 Error(_L("Status 24"),0);
1363 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1364 Error(_L("File info 0"),c);
1365 if ((c=gFile.Open(TheFs,gNameOut,EFileStream|P_FUPDATE|P_FRANDOM))!=KErrNone)
1366 Error(_L("Open 23"),c);
1367 saveTime=gFileEntry.iModified;
1368 test.Printf(_L("Wait 3 seconds...\n"));
1369 User::After(3000000L);
1370 if ((c=gFile.Flush())!=KErrNone) // Should not alter time //
1371 Error(_L("Flush 0"),c);
1372 if (gFileEntry.iModified!=saveTime)
1373 Error(_L("Flush new time"),0);
1375 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1376 Error(_L("File info 61"),c);
1377 if (gFileEntry.iModified!=saveTime)
1378 Error(_L("Close new time"),0);
1379 if ((c=gFile.Open(TheFs,gNameOut,EFileStream|P_FUPDATE|P_FRANDOM))!=KErrNone)
1380 Error(_L("Open 24"),c);
1381 if ((c=gFile.Write(gDataBuf,1))!=KErrNone)
1382 Error(_L("Write 60"),c);
1383 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1384 Error(_L("File info 62"),c);
1385 if (gFileEntry.iModified==saveTime)
1386 Error(_L("Write new time 1"),0);
1387 saveTime=gFileEntry.iModified;
1388 test.Printf(_L("Wait 3 seconds...\n"));
1389 User::After(3000000L);
1390 if ((c=gFile.Flush())!=KErrNone) // Should alter time //
1391 Error(_L("Flush 1"),c);
1392 if ((c=TheFs.Entry(gNameOut,gFileEntry))!=KErrNone)
1393 Error(_L("File info 64"),c);
1394 if (gFileEntry.iModified!=saveTime) // ==saveTime) // !!! Flush doesn't alter the time unless the file is modified
1395 Error(_L("Flush new time 1"),0);
1397 if ((c=TheFs.Delete(gNameOut))!=KErrNone)
1398 Error(_L("Delete"),c);
1400 test.Printf(_L("Test set file date\n"));
1401 gNameOut.SetLength(0);
1402 if ((c=gFile.Temp(TheFs,gNameBuf,gNameOut,EFileStream))!=KErrNone)
1403 Error(_L("Open 10"),c);
1405 if ((c=gFile.Open(TheFs,gNameOut,EFileStream))!=KErrNone)
1406 Error(_L("Open 10"),c); // Temp file is created as writable.
1408 if ((c=gFile.SetModified(fileTime))!=AccessErr) // LockedErr)
1409 Error(_L("Set file date 10"),c);
1413 for (i=0;i<DateTests;i++)
1415 // TUint32 testSeconds[] =
1418 // 315532799L, 315532800L, 315532801L,315532802L,
1419 // 0xfffffffeL,0xffffffffL,0x7fffffffL,
1420 // 0x80000000L,0x80000001L
1422 // TUint32 checkSeconds[] =
1424 // 315532800L, 315532800L, 315532800L, 315532800L, 315532802L,
1425 // 0xfffffffeL,0xfffffffeL,0x7ffffffeL,
1426 // 0x80000000L,0x80000000L
1428 // TInt64 num64((TReal)(testSeconds[i]*1000000)); // !!! NT fails on dates < 1601
1429 // TTime fileTime(num64);
1430 // if ((c=TheFs.SetModified(gNameBuf,fileTime))!=KErrNone)
1431 // Error(_L("Set file date 0"),c);
1432 // if ((c=TheFs.Entry(gNameBuf,gFileEntry))!=KErrNone)
1433 // Error(_L("File info 10"),c);
1434 // num64=(TReal)checkSeconds[i]*1000000;
1435 // if (gFileEntry.iModified.Int64()!=num64)
1436 // Error(_L("Date check 0"),i);
1438 if ((c=TheFs.Delete(gNameOut))!=KErrNone)
1439 Error(_L("Delete 1"),c);
1440 test.Printf(_L("Test format\n"));
1441 gNameOut.SetLength(0);
1442 if ((c=gFile.Temp(TheFs,gNameBuf,gNameOut,EFileStream))!=KErrNone)
1443 Error(_L("Open 1"),c);
1444 if ((c=gFormat.Open(TheFs,fBuf,EFullFormat,count))!=LockedErr)
1445 Error(_L("Format lock check 1"),c);
1446 if ((c=gFormat.Open(TheFs,fBuf,EQuickFormat,count))!=LockedErr)
1447 Error(_L("Format lock check 2"),c);
1450 if ((c=gFormat.Open(TheFs,fBuf,EFullFormat,count))!=KErrNone)
1452 if (c==LockedErr || c==AccessErr)
1454 test.Printf(_L("Format: locked, no test\n"));
1457 Error(_L("Format lock check"),c);
1460 // if ((c=p_read(chan2,&count,2))<0)
1462 // if (c==NotSupportedErr)
1464 // test.Printf(_L("Format: not supported, no test\n"));
1465 // goto noFormatClose;
1467 // Error(_L("Read format count"),c);
1471 // if ((c=g(chan2,&val,2))<0)
1475 // Error(_L("Format"),c);
1477 // test.Printf(_L("\r%05u %05u\n"),i,val);
1479 // if ((i-1)!=count)
1480 // Error(_L("Format count"),i);
1482 // if ((c=p_close(chan2))!=KErrNone)
1483 // Error(_L("Close"),c);
1486 DeleteTestDirectory();