Update contrib.
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.
14 // f32test\server\b_osfil.cpp
22 const TInt KSizeExistsFile=26;
23 const TInt KSizeExistsFile2=25;
25 GLDEF_D RTest test(_L("B_OSFIL"));
27 /* these buffers get written to in order to change the file system */
28 //LOCAL_D TBuf<5> fileSystemName =_L("LOC::"); /* default file system name */
29 LOCAL_D TBuf<20> noDevice = _L("L:\\tmpfile.tmp");
30 LOCAL_D TBuf<15> noDevicePath = _L("L:\\");
31 LOCAL_D TBuf<28> noDirectory = _L("C:\\nodirect\\tmpfile.tmp");
32 LOCAL_D TBuf<30> noDirectoryPath = _L("C:\\nodirect\\");
33 LOCAL_D TBuf<20> noFile = _L("C:\\notafile.tmp");
34 LOCAL_D TBuf<19> fileName = _L("C:\\tmpfile.tmp");
35 LOCAL_D TBuf<20> existsFile = _L("C:\\tmpexst1.tmp");
36 LOCAL_D TBuf<20> existsFile2 = _L("C:\\tmpexst2.tmp");
37 LOCAL_D TBuf<21> renameFile1 = _L("C:\\tmpren1.tmp");
38 LOCAL_D TBuf<21> renameFile2 = _L("C:\\tmpren2.tmp");
39 LOCAL_D TBuf<34> directoryFile = _L("C:\\nodirect\\nodirect\\nodirect\\");
40 LOCAL_D TBuf<14> openUniqueDir = _L("C:\\nodir2\\");
42 /*************************************************************************/
43 LOCAL_C void TestInfo()
45 Test the file info function
49 TInt r=TheFs.Entry(noDevice,entry);
50 test((r==KErrNotReady)||(r==KErrPathNotFound));
51 r=TheFs.Entry(noDirectory,entry);
52 test(r==KErrPathNotFound);
53 r=TheFs.Entry(noFile,entry);
54 test(r==KErrNotFound);
55 r=TheFs.Entry(existsFile,entry);
57 test(entry.iSize==KSizeExistsFile);
59 test(!(entry.iAtt&KEntryAttDir));
60 r=TheFs.Entry(existsFile2,entry);
62 test(entry.iSize==KSizeExistsFile2);
64 test(!(entry.iAtt&KEntryAttDir));
67 LOCAL_C void TestDelete()
72 TInt r=TheFs.Delete(noDevice);
73 test((r==KErrNotReady)||(r==KErrPathNotFound));
74 r=TheFs.Delete(noDirectory);
75 test(r==KErrPathNotFound);
76 r=TheFs.Delete(noFile);
77 test(r==KErrNotFound);
78 r=TheFs.Delete(existsFile);
80 r=TheFs.Delete(existsFile2);
83 r=TheFs.Entry(existsFile,entry);
84 test(r==KErrNotFound);
85 r=TheFs.Entry(existsFile2,entry);
86 test(r==KErrNotFound);
89 LOCAL_C void TestRename()
94 TInt r=TheFs.Rename(noDevice,fileName);
95 test(r==KErrArgument);
96 r=TheFs.Rename(noDirectory,fileName);
97 test(r==KErrPathNotFound);
98 r=TheFs.Rename(noFile,fileName);
99 test(r==KErrNotFound);
100 r=TheFs.Rename(existsFile,existsFile2);
101 test(r==KErrAlreadyExists);
102 r=TheFs.Delete(existsFile);
104 r=TheFs.Rename(existsFile,existsFile);
105 test(r==KErrNotFound);
106 r=TheFs.Rename(existsFile2,existsFile);
109 r=TheFs.Entry(existsFile2,entry);
110 test(r==KErrNotFound);
111 r=TheFs.Entry(existsFile,entry);
113 r=TheFs.Delete(existsFile);
117 LOCAL_C void TestMkDir()
120 TInt r=TheFs.MkDirAll(directoryFile);
123 r=TheFs.Entry(directoryFile.Left(directoryFile.Length()-1),entry);
126 test(entry.iAtt&KEntryAttDir);
127 r=TheFs.RmDir(directoryFile);
129 r=fparse.Set(directoryFile,NULL,NULL);
133 r=TheFs.RmDir(fparse.DriveAndPath());
137 r=TheFs.RmDir(fparse.DriveAndPath());
142 LOCAL_C void TestOpenUnique()
144 Test unique file name generator
150 TInt r=p1.Open(TheFs,noDevice,EFileStreamText);
151 test((r==KErrNotReady)||(r==KErrPathNotFound));
152 r=p1.Open(TheFs,noDirectory,EFileStreamText);
153 test(r==KErrPathNotFound);
154 TFileName generated1;
155 r=p1.Temp(TheFs,noDevicePath,generated1,EFileStreamText);
156 test((r==KErrNotReady)||(r==KErrPathNotFound));
157 r=p1.Temp(TheFs,noDirectoryPath,generated1,EFileStreamText);
158 test(r==KErrPathNotFound);
160 r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText);
162 TFileName generated2;
163 r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText);
165 test(generated1!=generated2);
167 TFileName generated3;
168 r=p1.Temp(TheFs,_L(""),generated3,EFileStream);
170 test(generated3!=generated2);
171 test(generated3!=generated1);
175 r=TheFs.Delete(generated1);
177 r=TheFs.Delete(generated2);
179 r=TheFs.Delete(generated3);
182 r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText);
184 r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText);
186 test(generated1!=generated2);
188 r=p1.Temp(TheFs,_L(""),generated3,EFileStream);
190 test(generated3!=generated2);
191 test(generated3!=generated1);
195 r=TheFs.Delete(generated1);
197 r=TheFs.Delete(generated2);
199 r=TheFs.Delete(generated3);
202 r=TheFs.MkDir(openUniqueDir);
204 r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream);
206 r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText|EFileWrite);
208 r=p1.Write(_L8("junk"),4);
211 r=p1.Seek(ESeekCurrent,pos);//P_FSET
216 r=TheFs.Delete(generated1);
218 r=TheFs.Delete(generated2);
221 r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream);
223 r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText);
228 r=p2.Seek(ESeekStart,pos);
231 r=TheFs.Delete(generated1);
233 r=TheFs.Delete(generated2);
235 r=TheFs.RmDir(openUniqueDir);
239 LOCAL_C void TestPaths()
242 TInt r=TheFs.SessionPath(path1);
244 r=TheFs.SetSessionPath(path1);
247 r=TheFs.SessionPath(path2);
251 r=dir.Open(TheFs,path1,0);
256 LOCAL_C void TestFileStatus()
259 TInt r=TheFs.Entry(existsFile,blk);
263 /* Toggle the write attribute */
264 TUint clear,set; /* were modifying write attrib */
265 if (blk1.IsReadOnly())
267 clear=KEntryAttReadOnly;
273 set=KEntryAttReadOnly;
275 r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
277 r=TheFs.Entry(existsFile,blk);
279 if (blk1.IsReadOnly())
280 test(!blk.IsReadOnly());
282 test(blk.IsReadOnly());
284 /* set write attrib back */
285 r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
287 r=TheFs.Entry(existsFile,blk);
289 if (blk1.IsReadOnly())
290 test(blk.IsReadOnly());
292 test(!blk.IsReadOnly());
294 /* toggle the archive bit */
295 if (blk1.IsArchive())
297 clear=KEntryAttArchive;
303 set=KEntryAttArchive;
305 r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
307 r=TheFs.Entry(existsFile,blk);
309 if (blk1.IsArchive())
310 test(!blk.IsArchive());
312 test(blk.IsArchive());
313 /* set archive attrib back */
314 r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
316 r=TheFs.Entry(existsFile,blk);
318 if (blk1.IsArchive())
319 test(blk.IsArchive());
321 test(!blk.IsArchive());
323 /* toggle the hidden bit */
326 clear=KEntryAttHidden;
334 r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
336 r=TheFs.Entry(existsFile,blk);
339 test(!blk.IsHidden());
341 test(blk.IsHidden());
342 /* set hidden attrib back */
343 r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
345 r=TheFs.Entry(existsFile,blk);
348 test(blk.IsHidden());
350 test(!blk.IsHidden());
352 /* toggle the system bit */
355 clear=KEntryAttSystem;
363 r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
365 r=TheFs.Entry(existsFile,blk);
368 test(!blk.IsSystem());
370 test(blk.IsSystem());
371 /* set system attrib back */
372 r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
374 r=TheFs.Entry(existsFile,blk);
377 test(blk.IsSystem());
379 test(!blk.IsSystem());
380 r=TheFs.Delete(existsFile);
382 r=TheFs.Delete(existsFile2);
387 LOCAL_C void CreateTestFiles()
390 TInt r=fcb.Replace(TheFs,existsFile,EFileWrite);
392 r=fcb.Write(_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),KSizeExistsFile);
396 r=fcb.Replace(TheFs,existsFile2,EFileWrite);
398 r=fcb.Write(_L8("bcdefghijklmnopqrstuvwxyz"),KSizeExistsFile2);
403 GLDEF_C void CallTestsL(void)
405 // Do testing on aDrive
411 TInt r=TheFs.Volume(di);
413 test.Start(_L("Info()"));
416 test.Next(_L("Delete()"));
419 test.Next(_L("Rename()"));
422 test.Next(_L("MkDir()"));
424 test.Next(_L("Temp()"));
426 test.Next(_L("Paths"));
428 test.Next(_L("File status"));