0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// f32test\server\b_osfil.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
149
|
18 |
#define __E32TEST_EXTENSION__
|
0
|
19 |
#include <f32file.h>
|
|
20 |
#include <e32test.h>
|
|
21 |
#include "t_server.h"
|
|
22 |
|
|
23 |
const TInt KSizeExistsFile=26;
|
|
24 |
const TInt KSizeExistsFile2=25;
|
|
25 |
|
|
26 |
GLDEF_D RTest test(_L("B_OSFIL"));
|
|
27 |
|
|
28 |
/* these buffers get written to in order to change the file system */
|
|
29 |
//LOCAL_D TBuf<5> fileSystemName =_L("LOC::"); /* default file system name */
|
|
30 |
LOCAL_D TBuf<20> noDevice = _L("L:\\tmpfile.tmp");
|
|
31 |
LOCAL_D TBuf<15> noDevicePath = _L("L:\\");
|
|
32 |
LOCAL_D TBuf<28> noDirectory = _L("C:\\nodirect\\tmpfile.tmp");
|
|
33 |
LOCAL_D TBuf<30> noDirectoryPath = _L("C:\\nodirect\\");
|
|
34 |
LOCAL_D TBuf<20> noFile = _L("C:\\notafile.tmp");
|
|
35 |
LOCAL_D TBuf<19> fileName = _L("C:\\tmpfile.tmp");
|
|
36 |
LOCAL_D TBuf<20> existsFile = _L("C:\\tmpexst1.tmp");
|
|
37 |
LOCAL_D TBuf<20> existsFile2 = _L("C:\\tmpexst2.tmp");
|
|
38 |
LOCAL_D TBuf<21> renameFile1 = _L("C:\\tmpren1.tmp");
|
|
39 |
LOCAL_D TBuf<21> renameFile2 = _L("C:\\tmpren2.tmp");
|
|
40 |
LOCAL_D TBuf<34> directoryFile = _L("C:\\nodirect\\nodirect\\nodirect\\");
|
|
41 |
LOCAL_D TBuf<14> openUniqueDir = _L("C:\\nodir2\\");
|
|
42 |
|
|
43 |
/*************************************************************************/
|
|
44 |
LOCAL_C void TestInfo()
|
|
45 |
/*
|
|
46 |
Test the file info function
|
|
47 |
*/
|
|
48 |
{
|
|
49 |
TEntry entry;
|
|
50 |
TInt r=TheFs.Entry(noDevice,entry);
|
149
|
51 |
test_Value(r, (r == KErrNotReady)||(r==KErrPathNotFound));
|
0
|
52 |
r=TheFs.Entry(noDirectory,entry);
|
149
|
53 |
test_Value(r, r == KErrPathNotFound);
|
0
|
54 |
r=TheFs.Entry(noFile,entry);
|
149
|
55 |
test_Value(r, r == KErrNotFound);
|
0
|
56 |
r=TheFs.Entry(existsFile,entry);
|
149
|
57 |
test_KErrNone(r);
|
0
|
58 |
test(entry.iSize==KSizeExistsFile);
|
|
59 |
test(!entry.IsDir());
|
|
60 |
test(!(entry.iAtt&KEntryAttDir));
|
|
61 |
r=TheFs.Entry(existsFile2,entry);
|
149
|
62 |
test_KErrNone(r);
|
0
|
63 |
test(entry.iSize==KSizeExistsFile2);
|
|
64 |
test(!entry.IsDir());
|
|
65 |
test(!(entry.iAtt&KEntryAttDir));
|
|
66 |
}
|
|
67 |
|
|
68 |
LOCAL_C void TestDelete()
|
|
69 |
/*
|
|
70 |
Test the delete
|
|
71 |
*/
|
|
72 |
{
|
|
73 |
TInt r=TheFs.Delete(noDevice);
|
149
|
74 |
test_Value(r, (r == KErrNotReady)||(r==KErrPathNotFound));
|
0
|
75 |
r=TheFs.Delete(noDirectory);
|
149
|
76 |
test_Value(r, r == KErrPathNotFound);
|
0
|
77 |
r=TheFs.Delete(noFile);
|
149
|
78 |
test_Value(r, r == KErrNotFound);
|
0
|
79 |
r=TheFs.Delete(existsFile);
|
149
|
80 |
test_KErrNone(r);
|
0
|
81 |
r=TheFs.Delete(existsFile2);
|
149
|
82 |
test_KErrNone(r);
|
0
|
83 |
TEntry entry;
|
|
84 |
r=TheFs.Entry(existsFile,entry);
|
149
|
85 |
test_Value(r, r == KErrNotFound);
|
0
|
86 |
r=TheFs.Entry(existsFile2,entry);
|
149
|
87 |
test_Value(r, r == KErrNotFound);
|
0
|
88 |
}
|
|
89 |
|
|
90 |
LOCAL_C void TestRename()
|
|
91 |
/*
|
|
92 |
Test the rename
|
|
93 |
*/
|
|
94 |
{
|
|
95 |
TInt r=TheFs.Rename(noDevice,fileName);
|
149
|
96 |
test_Value(r, r == KErrArgument);
|
0
|
97 |
r=TheFs.Rename(noDirectory,fileName);
|
149
|
98 |
test_Value(r, r == KErrPathNotFound);
|
0
|
99 |
r=TheFs.Rename(noFile,fileName);
|
149
|
100 |
test_Value(r, r == KErrNotFound);
|
0
|
101 |
r=TheFs.Rename(existsFile,existsFile2);
|
149
|
102 |
test_Value(r, r == KErrAlreadyExists);
|
0
|
103 |
r=TheFs.Delete(existsFile);
|
149
|
104 |
test_KErrNone(r);
|
0
|
105 |
r=TheFs.Rename(existsFile,existsFile);
|
149
|
106 |
test_Value(r, r == KErrNotFound);
|
0
|
107 |
r=TheFs.Rename(existsFile2,existsFile);
|
149
|
108 |
test_KErrNone(r);
|
0
|
109 |
TEntry entry;
|
|
110 |
r=TheFs.Entry(existsFile2,entry);
|
149
|
111 |
test_Value(r, r == KErrNotFound);
|
0
|
112 |
r=TheFs.Entry(existsFile,entry);
|
149
|
113 |
test_KErrNone(r);
|
0
|
114 |
r=TheFs.Delete(existsFile);
|
149
|
115 |
test_KErrNone(r);
|
0
|
116 |
}
|
|
117 |
|
|
118 |
LOCAL_C void TestMkDir()
|
|
119 |
{
|
|
120 |
TParse fparse;
|
|
121 |
TInt r=TheFs.MkDirAll(directoryFile);
|
149
|
122 |
test_KErrNone(r);
|
0
|
123 |
TEntry entry;
|
|
124 |
r=TheFs.Entry(directoryFile.Left(directoryFile.Length()-1),entry);
|
149
|
125 |
test_KErrNone(r);
|
0
|
126 |
test(entry.IsDir());
|
|
127 |
test(entry.iAtt&KEntryAttDir);
|
|
128 |
r=TheFs.RmDir(directoryFile);
|
149
|
129 |
test_KErrNone(r);
|
0
|
130 |
r=fparse.Set(directoryFile,NULL,NULL);
|
149
|
131 |
test_KErrNone(r);
|
0
|
132 |
r=fparse.PopDir();
|
149
|
133 |
test_KErrNone(r);
|
0
|
134 |
r=TheFs.RmDir(fparse.DriveAndPath());
|
149
|
135 |
test_KErrNone(r);
|
0
|
136 |
r=fparse.PopDir();
|
149
|
137 |
test_KErrNone(r);
|
0
|
138 |
r=TheFs.RmDir(fparse.DriveAndPath());
|
149
|
139 |
test_KErrNone(r);
|
0
|
140 |
}
|
|
141 |
|
|
142 |
|
|
143 |
LOCAL_C void TestOpenUnique()
|
|
144 |
/*
|
|
145 |
Test unique file name generator
|
|
146 |
*/
|
|
147 |
{
|
|
148 |
RFile p1;
|
|
149 |
RFile p2;
|
|
150 |
|
|
151 |
TInt r=p1.Open(TheFs,noDevice,EFileStreamText);
|
149
|
152 |
test_Value(r, (r == KErrNotReady)||(r==KErrPathNotFound));
|
0
|
153 |
r=p1.Open(TheFs,noDirectory,EFileStreamText);
|
149
|
154 |
test_Value(r, r == KErrPathNotFound);
|
0
|
155 |
TFileName generated1;
|
|
156 |
r=p1.Temp(TheFs,noDevicePath,generated1,EFileStreamText);
|
149
|
157 |
test_Value(r, (r == KErrNotReady)||(r==KErrPathNotFound));
|
0
|
158 |
r=p1.Temp(TheFs,noDirectoryPath,generated1,EFileStreamText);
|
149
|
159 |
test_Value(r, r == KErrPathNotFound);
|
0
|
160 |
|
|
161 |
r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText);
|
149
|
162 |
test_KErrNone(r);
|
0
|
163 |
TFileName generated2;
|
|
164 |
r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText);
|
149
|
165 |
test_KErrNone(r);
|
0
|
166 |
test(generated1!=generated2);
|
|
167 |
p1.Close();
|
|
168 |
TFileName generated3;
|
|
169 |
r=p1.Temp(TheFs,_L(""),generated3,EFileStream);
|
149
|
170 |
test_KErrNone(r);
|
0
|
171 |
test(generated3!=generated2);
|
|
172 |
test(generated3!=generated1);
|
|
173 |
p2.Close();
|
|
174 |
p1.Close();
|
|
175 |
|
|
176 |
r=TheFs.Delete(generated1);
|
149
|
177 |
test_KErrNone(r);
|
0
|
178 |
r=TheFs.Delete(generated2);
|
149
|
179 |
test_KErrNone(r);
|
0
|
180 |
r=TheFs.Delete(generated3);
|
149
|
181 |
test_KErrNone(r);
|
0
|
182 |
|
|
183 |
r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText);
|
149
|
184 |
test_KErrNone(r);
|
0
|
185 |
r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText);
|
149
|
186 |
test_KErrNone(r);
|
0
|
187 |
test(generated1!=generated2);
|
|
188 |
p1.Close();
|
|
189 |
r=p1.Temp(TheFs,_L(""),generated3,EFileStream);
|
149
|
190 |
test_KErrNone(r);
|
0
|
191 |
test(generated3!=generated2);
|
|
192 |
test(generated3!=generated1);
|
|
193 |
p2.Close();
|
|
194 |
p1.Close();
|
|
195 |
|
|
196 |
r=TheFs.Delete(generated1);
|
149
|
197 |
test_KErrNone(r);
|
0
|
198 |
r=TheFs.Delete(generated2);
|
149
|
199 |
test_KErrNone(r);
|
0
|
200 |
r=TheFs.Delete(generated3);
|
149
|
201 |
test_KErrNone(r);
|
0
|
202 |
|
|
203 |
r=TheFs.MkDir(openUniqueDir);
|
149
|
204 |
test_KErrNone(r);
|
0
|
205 |
r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream);
|
149
|
206 |
test_KErrNone(r);
|
0
|
207 |
r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText|EFileWrite);
|
149
|
208 |
test_KErrNone(r);
|
0
|
209 |
r=p1.Write(_L8("junk"),4);
|
149
|
210 |
test_KErrNone(r);
|
0
|
211 |
TInt pos=0;
|
|
212 |
r=p1.Seek(ESeekCurrent,pos);//P_FSET
|
149
|
213 |
test_KErrNone(r);
|
0
|
214 |
p1.Close();
|
|
215 |
p2.Close();
|
|
216 |
|
|
217 |
r=TheFs.Delete(generated1);
|
149
|
218 |
test_KErrNone(r);
|
0
|
219 |
r=TheFs.Delete(generated2);
|
149
|
220 |
test_KErrNone(r);
|
0
|
221 |
|
|
222 |
r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream);
|
149
|
223 |
test_KErrNone(r);
|
0
|
224 |
r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText);
|
149
|
225 |
test_KErrNone(r);
|
0
|
226 |
p1.Close();
|
|
227 |
|
|
228 |
pos=0;
|
|
229 |
r=p2.Seek(ESeekStart,pos);
|
149
|
230 |
test_KErrNone(r);
|
0
|
231 |
p2.Close();
|
|
232 |
r=TheFs.Delete(generated1);
|
149
|
233 |
test_KErrNone(r);
|
0
|
234 |
r=TheFs.Delete(generated2);
|
149
|
235 |
test_KErrNone(r);
|
0
|
236 |
r=TheFs.RmDir(openUniqueDir);
|
149
|
237 |
test_KErrNone(r);
|
0
|
238 |
}
|
|
239 |
|
|
240 |
LOCAL_C void TestPaths()
|
|
241 |
{
|
|
242 |
TFileName path1;
|
|
243 |
TInt r=TheFs.SessionPath(path1);
|
149
|
244 |
test_KErrNone(r);
|
0
|
245 |
r=TheFs.SetSessionPath(path1);
|
149
|
246 |
test_KErrNone(r);
|
0
|
247 |
TFileName path2;
|
|
248 |
r=TheFs.SessionPath(path2);
|
149
|
249 |
test_KErrNone(r);
|
0
|
250 |
test(path1==path2);
|
|
251 |
RDir dir;
|
|
252 |
r=dir.Open(TheFs,path1,0);
|
149
|
253 |
test_KErrNone(r);
|
0
|
254 |
dir.Close();
|
|
255 |
}
|
|
256 |
|
|
257 |
LOCAL_C void TestFileStatus()
|
|
258 |
{
|
|
259 |
TEntry blk;
|
|
260 |
TInt r=TheFs.Entry(existsFile,blk);
|
149
|
261 |
test_KErrNone(r);
|
0
|
262 |
TEntry blk1=blk;
|
|
263 |
|
|
264 |
/* Toggle the write attribute */
|
|
265 |
TUint clear,set; /* were modifying write attrib */
|
|
266 |
if (blk1.IsReadOnly())
|
|
267 |
{
|
|
268 |
clear=KEntryAttReadOnly;
|
|
269 |
set=0;
|
|
270 |
}
|
|
271 |
else
|
|
272 |
{
|
|
273 |
clear=0;
|
|
274 |
set=KEntryAttReadOnly;
|
|
275 |
}
|
|
276 |
r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
|
149
|
277 |
test_KErrNone(r);
|
0
|
278 |
r=TheFs.Entry(existsFile,blk);
|
149
|
279 |
test_KErrNone(r);
|
0
|
280 |
if (blk1.IsReadOnly())
|
|
281 |
test(!blk.IsReadOnly());
|
|
282 |
else
|
|
283 |
test(blk.IsReadOnly());
|
|
284 |
|
|
285 |
/* set write attrib back */
|
|
286 |
r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
|
149
|
287 |
test_KErrNone(r);
|
0
|
288 |
r=TheFs.Entry(existsFile,blk);
|
149
|
289 |
test_KErrNone(r);
|
0
|
290 |
if (blk1.IsReadOnly())
|
|
291 |
test(blk.IsReadOnly());
|
|
292 |
else
|
|
293 |
test(!blk.IsReadOnly());
|
|
294 |
|
|
295 |
/* toggle the archive bit */
|
|
296 |
if (blk1.IsArchive())
|
|
297 |
{
|
|
298 |
clear=KEntryAttArchive;
|
|
299 |
set=0;
|
|
300 |
}
|
|
301 |
else
|
|
302 |
{
|
|
303 |
clear=0;
|
|
304 |
set=KEntryAttArchive;
|
|
305 |
}
|
|
306 |
r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
|
149
|
307 |
test_KErrNone(r);
|
0
|
308 |
r=TheFs.Entry(existsFile,blk);
|
149
|
309 |
test_KErrNone(r);
|
0
|
310 |
if (blk1.IsArchive())
|
|
311 |
test(!blk.IsArchive());
|
|
312 |
else
|
|
313 |
test(blk.IsArchive());
|
|
314 |
/* set archive attrib back */
|
|
315 |
r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
|
149
|
316 |
test_KErrNone(r);
|
0
|
317 |
r=TheFs.Entry(existsFile,blk);
|
149
|
318 |
test_KErrNone(r);
|
0
|
319 |
if (blk1.IsArchive())
|
|
320 |
test(blk.IsArchive());
|
|
321 |
else
|
|
322 |
test(!blk.IsArchive());
|
|
323 |
|
|
324 |
/* toggle the hidden bit */
|
|
325 |
if (blk1.IsHidden())
|
|
326 |
{
|
|
327 |
clear=KEntryAttHidden;
|
|
328 |
set=0;
|
|
329 |
}
|
|
330 |
else
|
|
331 |
{
|
|
332 |
clear=0;
|
|
333 |
set=KEntryAttHidden;
|
|
334 |
}
|
|
335 |
r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
|
149
|
336 |
test_KErrNone(r);
|
0
|
337 |
r=TheFs.Entry(existsFile,blk);
|
149
|
338 |
test_KErrNone(r);
|
0
|
339 |
if (blk1.IsHidden())
|
|
340 |
test(!blk.IsHidden());
|
|
341 |
else
|
|
342 |
test(blk.IsHidden());
|
|
343 |
/* set hidden attrib back */
|
|
344 |
r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
|
149
|
345 |
test_KErrNone(r);
|
0
|
346 |
r=TheFs.Entry(existsFile,blk);
|
149
|
347 |
test_KErrNone(r);
|
0
|
348 |
if (blk1.IsHidden())
|
|
349 |
test(blk.IsHidden());
|
|
350 |
else
|
|
351 |
test(!blk.IsHidden());
|
|
352 |
|
|
353 |
/* toggle the system bit */
|
|
354 |
if (blk1.IsSystem())
|
|
355 |
{
|
|
356 |
clear=KEntryAttSystem;
|
|
357 |
set=0;
|
|
358 |
}
|
|
359 |
else
|
|
360 |
{
|
|
361 |
clear=0;
|
|
362 |
set=KEntryAttSystem;
|
|
363 |
}
|
|
364 |
r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
|
149
|
365 |
test_KErrNone(r);
|
0
|
366 |
r=TheFs.Entry(existsFile,blk);
|
149
|
367 |
test_KErrNone(r);
|
0
|
368 |
if (blk1.IsSystem())
|
|
369 |
test(!blk.IsSystem());
|
|
370 |
else
|
|
371 |
test(blk.IsSystem());
|
|
372 |
/* set system attrib back */
|
|
373 |
r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
|
149
|
374 |
test_KErrNone(r);
|
0
|
375 |
r=TheFs.Entry(existsFile,blk);
|
149
|
376 |
test_KErrNone(r);
|
0
|
377 |
if (blk1.IsSystem())
|
|
378 |
test(blk.IsSystem());
|
|
379 |
else
|
|
380 |
test(!blk.IsSystem());
|
|
381 |
r=TheFs.Delete(existsFile);
|
149
|
382 |
test_KErrNone(r);
|
0
|
383 |
r=TheFs.Delete(existsFile2);
|
149
|
384 |
test_KErrNone(r);
|
0
|
385 |
}
|
|
386 |
|
|
387 |
|
|
388 |
LOCAL_C void CreateTestFiles()
|
|
389 |
{
|
|
390 |
RFile fcb;
|
|
391 |
TInt r=fcb.Replace(TheFs,existsFile,EFileWrite);
|
149
|
392 |
test_KErrNone(r);
|
0
|
393 |
r=fcb.Write(_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),KSizeExistsFile);
|
149
|
394 |
test_KErrNone(r);
|
0
|
395 |
fcb.Close();
|
|
396 |
|
|
397 |
r=fcb.Replace(TheFs,existsFile2,EFileWrite);
|
149
|
398 |
test_KErrNone(r);
|
0
|
399 |
r=fcb.Write(_L8("bcdefghijklmnopqrstuvwxyz"),KSizeExistsFile2);
|
149
|
400 |
test_KErrNone(r);
|
0
|
401 |
fcb.Close();
|
|
402 |
}
|
|
403 |
|
|
404 |
GLDEF_C void CallTestsL(void)
|
|
405 |
//
|
|
406 |
// Do testing on aDrive
|
|
407 |
//
|
|
408 |
{
|
|
409 |
test.Title();
|
|
410 |
|
|
411 |
TVolumeInfo di;
|
|
412 |
TInt r=TheFs.Volume(di);
|
149
|
413 |
test_KErrNone(r);
|
0
|
414 |
test.Start(_L("Info()"));
|
|
415 |
CreateTestFiles();
|
|
416 |
TestInfo();
|
|
417 |
test.Next(_L("Delete()"));
|
|
418 |
CreateTestFiles();
|
|
419 |
TestDelete();
|
|
420 |
test.Next(_L("Rename()"));
|
|
421 |
CreateTestFiles();
|
|
422 |
TestRename();
|
|
423 |
test.Next(_L("MkDir()"));
|
|
424 |
TestMkDir();
|
|
425 |
test.Next(_L("Temp()"));
|
|
426 |
TestOpenUnique();
|
|
427 |
test.Next(_L("Paths"));
|
|
428 |
TestPaths();
|
|
429 |
test.Next(_L("File status"));
|
|
430 |
CreateTestFiles();
|
|
431 |
TestFileStatus();
|
|
432 |
test.End();
|
|
433 |
}
|