author | mikek |
Wed, 16 Jun 2010 12:59:18 +0100 | |
branch | GCC_SURGE |
changeset 160 | 30e086416910 |
parent 109 | b3a1d9898418 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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\fsstress\t_sesfs.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
#define __E32TEST_EXTENSION__ |
|
18 |
#include "t_sess.h" |
|
19 |
||
20 |
GLDEF_D TFileName tPath; |
|
21 |
GLREF_D TFileName gExeFileName; |
|
22 |
||
23 |
LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt); |
|
24 |
LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo); |
|
25 |
LOCAL_C void DriveInfo(TInt aDrive,TDriveInfo& anInfo); |
|
26 |
||
27 |
||
28 |
void TSessionTest::Initialise(RFs& aFs) |
|
29 |
// |
|
30 |
// Initialise iFs |
|
31 |
// |
|
32 |
{ |
|
33 |
iFs=aFs; |
|
34 |
} |
|
35 |
||
36 |
||
37 |
void TSessionTest::RunTests() |
|
38 |
// |
|
39 |
// Run tests on iFs file server session |
|
40 |
// |
|
41 |
||
42 |
{ |
|
43 |
||
44 |
testDriveList(); |
|
45 |
testDriveInfo(); |
|
46 |
testVolumeInfo(); |
|
47 |
testSetVolume(); |
|
48 |
testPath(); |
|
49 |
CreateTestDirectory(_L("\\SESSION_TEST\\TFSRV\\")); |
|
50 |
testInitialisation(); |
|
51 |
testSubst(); |
|
52 |
CopyFileToTestDirectory(); |
|
53 |
MakeAndDeleteFiles(); |
|
54 |
} |
|
55 |
||
56 |
||
57 |
||
58 |
void TSessionTest::testDriveList() |
|
59 |
// |
|
60 |
// Test the drive list. |
|
61 |
// |
|
62 |
{ |
|
63 |
||
64 |
test.Start(_L("The drive list")); |
|
65 |
TDriveList list; |
|
66 |
TDriveInfo info; |
|
67 |
TInt r=iFs.DriveList(list); |
|
68 |
test_KErrNone(r); |
|
69 |
for (TInt i=0;i<KMaxDrives;i++) |
|
70 |
{ |
|
71 |
if (list[i]) |
|
72 |
{ |
|
73 |
r = iFs.Drive(info, i); |
|
74 |
test_KErrNone(r); |
|
75 |
printDriveAtt(i,info.iDriveAtt); |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
test.End(); |
|
80 |
} |
|
81 |
||
82 |
void TSessionTest::testDriveInfo() |
|
83 |
// |
|
84 |
// Test the drive info. |
|
85 |
// |
|
86 |
{ |
|
87 |
||
88 |
test.Start(_L("The drive info")); |
|
89 |
TDriveList list; |
|
90 |
TInt r=iFs.DriveList(list); |
|
91 |
test_KErrNone(r); |
|
92 |
for (TInt i=0;i<KMaxDrives;i++) |
|
93 |
{ |
|
94 |
TInt att=list[i]; |
|
95 |
if (att) |
|
96 |
{ |
|
97 |
TDriveInfo d; |
|
98 |
r=iFs.Drive(d,i); |
|
99 |
test_KErrNone(r); |
|
100 |
printDriveInfo(i,d); |
|
101 |
test.Printf(_L("\n")); |
|
102 |
DriveInfo(i,d); |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
test.End(); |
|
107 |
} |
|
108 |
||
109 |
void TSessionTest::testVolumeInfo() |
|
110 |
// |
|
111 |
// Test volume info. |
|
112 |
// |
|
113 |
{ |
|
114 |
||
115 |
test.Start(_L("The volume info")); |
|
116 |
TDriveList list; |
|
117 |
TInt r=iFs.DriveList(list); |
|
118 |
test_KErrNone(r); |
|
119 |
for (TInt i=0;i<KMaxDrives;i++) |
|
120 |
{ |
|
121 |
TVolumeInfo v; |
|
122 |
TDriveInfo d; |
|
123 |
switch (r=iFs.Volume(v,i)) |
|
124 |
{ |
|
125 |
case KErrNone: |
|
126 |
printDriveInfo(i,v.iDrive); |
|
127 |
test.Printf(_L(" VOL=\"%S\" ID=%08x\n"),&v.iName,v.iUniqueID); |
|
128 |
test.Printf(_L(" SIZE=%ldK FREE=%ldK\n"),v.iSize/1024,v.iFree/1024); |
|
129 |
break; |
|
130 |
case KErrNotReady: |
|
131 |
r=iFs.Drive(d, i); |
|
132 |
test_KErrNone(r); |
|
133 |
if (d.iType == EMediaNotPresent) |
|
134 |
test.Printf(_L("%c: Medium not present - cannot perform test.\n"), i + 'A'); |
|
135 |
else |
|
136 |
test.Printf(_L("medium found (type %d) but drive %c: not ready\nPrevious test may have hung; else, check hardware.\n"), (TInt)d.iType, i + 'A'); |
|
137 |
break; |
|
138 |
case KErrPathNotFound: |
|
139 |
test.Printf(_L("%c: Not Found\n"), i + 'A'); |
|
140 |
break; |
|
141 |
case KErrCorrupt: |
|
142 |
test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), i + 'A'); |
|
143 |
default: |
|
144 |
test.Printf(_L("%c: Error %d - aborting test.\n"),i + 'A', r); |
|
145 |
test(0); |
|
146 |
} |
|
147 |
test.Printf(_L("\n")); |
|
148 |
} |
|
149 |
||
150 |
test.End(); |
|
151 |
} |
|
152 |
||
153 |
||
154 |
void TSessionTest::testPath() |
|
155 |
// |
|
156 |
// Test the path handling. |
|
157 |
// |
|
158 |
{ |
|
159 |
||
160 |
test.Start(_L("Test path handling")); |
|
161 |
||
162 |
TInt r; |
|
163 |
||
164 |
TFileName p; |
|
165 |
r=iFs.SessionPath(p); |
|
166 |
test_KErrNone(r); |
|
167 |
test.Printf(_L("SESSION=\"%S\"\n"),&p); |
|
168 |
r=iFs.SetSessionPath(_L("A:\\TEST\\")); |
|
169 |
test_KErrNone(r); |
|
170 |
r=iFs.SessionPath(p); |
|
171 |
test_KErrNone(r); |
|
172 |
test(p==_L("A:\\TEST\\")); |
|
173 |
r=iFs.SetSessionPath(gTestSessionPath); |
|
174 |
test_KErrNone(r); |
|
175 |
||
176 |
test.End(); |
|
177 |
} |
|
178 |
||
179 |
||
180 |
void TSessionTest::testInitialisation() |
|
181 |
// |
|
182 |
// Tests that calls to CheckedClose() are OK, ie, tests bug fix |
|
183 |
// |
|
184 |
{ |
|
185 |
test.Next(_L("Test calls to CheckedClose are OK")); |
|
186 |
||
187 |
RFile file; |
|
188 |
RDir dir; |
|
189 |
||
190 |
TInt count; |
|
191 |
RFormat format; |
|
192 |
TInt r=format.Open(iFs,_L("Z:\\"),EFullFormat,count); |
|
193 |
||
194 |
test_Value(r, r==KErrAccessDenied || r==KErrInUse); |
|
195 |
||
196 |
r=dir.Open(iFs,_L("\\SESSION_TEST\\ERRORTEST\\"),KEntryAttMatchMask); |
|
197 |
test_Value(r, r==KErrPathNotFound); |
|
198 |
||
199 |
r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest1.txt"),EFileRead); |
|
200 |
test_Value(r, r==KErrNotFound); |
|
201 |
||
202 |
r=dir.Open(iFs,_L("\\SESSION_TEST\\ERRORTEST2\\"),KEntryAttMatchMask); |
|
203 |
test_Value(r, r==KErrPathNotFound); |
|
204 |
||
205 |
r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest2.txt"),EFileRead); |
|
206 |
test_Value(r, r==KErrNotFound); |
|
207 |
||
208 |
r=dir.Open(iFs,_L("\\SESSION_TEST\\ERRORTEST3\\"),KEntryAttMatchMask); |
|
209 |
test_Value(r, r==KErrPathNotFound); |
|
210 |
||
211 |
r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest3.txt"),EFileRead); |
|
212 |
test_Value(r, r==KErrNotFound); |
|
213 |
||
214 |
r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest4.txt"),EFileRead); |
|
215 |
test_Value(r, r==KErrNotFound); |
|
216 |
||
217 |
format.Close(); |
|
218 |
dir.Close(); |
|
219 |
file.Close(); |
|
220 |
} |
|
221 |
||
222 |
||
223 |
void TSessionTest::testSubst() |
|
224 |
// |
|
225 |
// Test the substitute functions. |
|
226 |
// |
|
227 |
{ |
|
228 |
||
229 |
test.Printf(_L("Test subst")); |
|
230 |
TVolumeInfo v; |
|
231 |
TInt r=iFs.Volume(v); |
|
232 |
test_KErrNone(r); |
|
233 |
TDriveInfo origDI; |
|
234 |
r=iFs.Drive(origDI); |
|
235 |
test_KErrNone(r); |
|
236 |
||
237 |
TDriveInfo driveInfo; |
|
238 |
r=iFs.Drive(driveInfo,EDriveO); |
|
239 |
test_KErrNone(r); |
|
240 |
||
241 |
testSetVolume(); |
|
242 |
||
243 |
if (driveInfo.iDriveAtt==KDriveAttLocal) |
|
244 |
{ |
|
245 |
return; // Subst local drives fails |
|
246 |
} |
|
247 |
||
248 |
TFileName n; |
|
249 |
r=iFs.Subst(n,EDriveO); |
|
250 |
test_KErrNone(r); |
|
251 |
test(n.Length()==0); |
|
252 |
r=iFs.SetSubst(gTestSessionPath,EDriveO); |
|
253 |
test_KErrNone(r); |
|
254 |
r=iFs.Subst(n,EDriveO); |
|
255 |
test_KErrNone(r); |
|
256 |
test(n==gTestSessionPath); |
|
257 |
TVolumeInfo w; |
|
258 |
r=iFs.Volume(w,EDriveO); |
|
259 |
test_KErrNone(r); |
|
260 |
test(w.iDrive.iType==v.iDrive.iType); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
test(w.iDrive.iConnectionBusType==v.iDrive.iConnectionBusType); |
0 | 262 |
test(w.iDrive.iDriveAtt==KDriveAttSubsted); |
263 |
test(w.iDrive.iMediaAtt==v.iDrive.iMediaAtt); |
|
264 |
test(w.iUniqueID==v.iUniqueID); |
|
265 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
266 |
if(v.iDrive.iType != EMediaRam) // We can't assume that RAM disk will be the same size since last recorded... |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
267 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
268 |
test(w.iSize==v.iSize); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
269 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
270 |
// If this test is being run under windows using drive C then skip free space comparison |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
271 |
// as it is likely to fail as the windows file system is unlike to have static freespace |
0 | 272 |
#ifdef __WINS__ |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
273 |
if(User::UpperCase(gTestSessionPath[0]) != 'C') |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
274 |
{ |
0 | 275 |
#endif |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
276 |
test(w.iFree==v.iFree); |
0 | 277 |
|
278 |
#ifdef __WINS__ |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
279 |
} |
0 | 280 |
#endif |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
281 |
} |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
282 |
|
0 | 283 |
test(w.iName==v.iName); |
284 |
TDriveList driveList; |
|
285 |
r=iFs.DriveList(driveList); |
|
286 |
test_KErrNone(r); |
|
287 |
test(driveList[EDriveO]==KDriveAttSubsted); |
|
288 |
TDriveInfo d; |
|
289 |
r=iFs.Drive(d,EDriveO); |
|
290 |
test_KErrNone(r); |
|
291 |
test(d.iDriveAtt==KDriveAttSubsted); |
|
292 |
test(d.iMediaAtt==origDI.iMediaAtt); |
|
293 |
test(d.iType==origDI.iType); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
test(d.iConnectionBusType==origDI.iConnectionBusType); |
0 | 295 |
|
296 |
||
297 |
test.Next(_L("Test real name")); |
|
298 |
r=iFs.RealName(_L("O:\\FILE.XXX"),n); |
|
299 |
test_KErrNone(r); |
|
300 |
TFileName substedPath=gTestSessionPath; |
|
301 |
substedPath.Append(_L("FILE.XXX")); |
|
302 |
test(n.CompareF(substedPath)==KErrNone); |
|
303 |
// |
|
304 |
test.Next(_L("Test MkDir, Rename and RmDir on Substed drive")); |
|
305 |
_LIT(KTurgid,"turgid\\"); |
|
306 |
TFileName dir=gTestSessionPath; |
|
307 |
dir+=KTurgid; |
|
308 |
r=iFs.MkDirAll(dir); |
|
309 |
test_KErrNone(r); |
|
310 |
dir+=_L("subdir\\"); |
|
311 |
r=iFs.MkDir(dir); |
|
312 |
test_KErrNone(r); |
|
313 |
r=iFs.RmDir(_L("O:\\turgid\\subdir\\")); |
|
314 |
test_KErrNone(r); |
|
315 |
r=iFs.Rename(_L("O:\\turgid"), _L("O:\\facile")); |
|
316 |
test_KErrNone(r); |
|
317 |
r=iFs.MkDir(_L("O:\\insipid\\")); |
|
318 |
test_KErrNone(r); |
|
319 |
r=iFs.Rename(_L("O:\\insipid"), _L("O:\\glib")); |
|
320 |
test_KErrNone(r); |
|
321 |
r=iFs.RmDir(_L("O:\\facile\\")); |
|
322 |
test_KErrNone(r); |
|
323 |
_LIT(KGlib,"glib\\"); |
|
324 |
dir=gTestSessionPath; |
|
325 |
dir+=KGlib; |
|
326 |
r=iFs.RmDir(dir); |
|
327 |
test_KErrNone(r); |
|
328 |
test.Next(_L("Test file operations on Substed drive")); |
|
329 |
_LIT(File1,"File1.txt"); |
|
330 |
_LIT(File2,"File2.txt"); |
|
331 |
_LIT(SubstRoot,"O:\\"); |
|
332 |
_LIT(Subdir,"subdir\\"); |
|
333 |
TFileName name1,name2; |
|
334 |
name1=gTestSessionPath; |
|
335 |
name1+=File1; |
|
336 |
RFile f1; |
|
337 |
r=f1.Create(iFs,name1,EFileShareExclusive|EFileWrite); |
|
338 |
test_KErrNone(r); |
|
339 |
name2=SubstRoot; |
|
340 |
name2+=File2; |
|
341 |
TBool isValid=iFs.IsValidName(name2); |
|
342 |
test(isValid); |
|
343 |
r=f1.Rename(name2); |
|
344 |
test_KErrNone(r); |
|
345 |
f1.Close(); |
|
346 |
r=f1.Create(iFs,name1,EFileShareExclusive|EFileWrite); |
|
347 |
test_KErrNone(r); |
|
348 |
f1.Close(); |
|
349 |
r=iFs.Replace(name2,name1); |
|
350 |
test_KErrNone(r); |
|
351 |
r=iFs.Delete(name1); |
|
352 |
test_KErrNone(r); |
|
353 |
test.Next(_L("Test notifications on Substed drive")); |
|
354 |
name1=gTestSessionPath; |
|
355 |
name1+=Subdir; |
|
356 |
name2=SubstRoot; |
|
357 |
name2+=Subdir; |
|
358 |
// set up some extended notifications |
|
359 |
TRequestStatus status1; |
|
360 |
TRequestStatus status2; |
|
361 |
TRequestStatus status3; |
|
362 |
iFs.NotifyChange(ENotifyDir,status1,name1); |
|
363 |
test(status1==KRequestPending); |
|
364 |
iFs.NotifyChange(ENotifyDir,status2,name2); |
|
365 |
test(status2==KRequestPending); |
|
366 |
r=iFs.MkDirAll(name1); |
|
367 |
test_KErrNone(r); |
|
368 |
User::WaitForRequest(status1); |
|
369 |
User::WaitForRequest(status2); |
|
370 |
test(status1==KErrNone && status2==KErrNone); |
|
371 |
iFs.NotifyChange(ENotifyDir,status1,name1); |
|
372 |
test(status1==KRequestPending); |
|
373 |
iFs.NotifyChange(ENotifyDir,status2,name2); |
|
374 |
test(status2==KRequestPending); |
|
375 |
iFs.NotifyChange(ENotifyAll,status3,name2); |
|
376 |
test(status3==KRequestPending); |
|
377 |
r=f1.Temp(iFs,name2,n,EFileShareAny|EFileWrite); |
|
378 |
test_KErrNone(r); |
|
379 |
User::WaitForRequest(status3); |
|
380 |
test(status3==KErrNone && status1==KRequestPending && status2==KRequestPending); |
|
381 |
f1.Close(); |
|
382 |
iFs.NotifyChangeCancel(); |
|
383 |
test(status1==KErrCancel && status2==KErrCancel); |
|
384 |
User::WaitForRequest(status1); |
|
385 |
User::WaitForRequest(status2); |
|
386 |
r=iFs.Delete(n); |
|
387 |
test_KErrNone(r); |
|
388 |
r=iFs.RmDir(name1); |
|
389 |
test_KErrNone(r); |
|
390 |
// |
|
391 |
test.Next(_L("Test file systems on Substed drive")); |
|
392 |
// test cannot mount file system on substituted drive |
|
393 |
TInt sessionDrv; |
|
394 |
r=iFs.CharToDrive(gTestSessionPath[0],sessionDrv); |
|
395 |
test_KErrNone(r); |
|
396 |
r=iFs.FileSystemName(n,sessionDrv); |
|
397 |
test_Value(r, r==KErrNone || r==KErrNotFound); |
|
398 |
r=iFs.MountFileSystem(n,EDriveO); |
|
399 |
test_Value(r, r==KErrAccessDenied); |
|
400 |
// test file system name on substitued drive is null |
|
401 |
r=iFs.FileSystemName(n,EDriveO); |
|
402 |
test_Value(r, r==KErrNotFound && n==KNullDesC); |
|
403 |
// test cannot format a substitued drive |
|
404 |
RFormat format; |
|
405 |
TInt count; |
|
406 |
r=format.Open(iFs,SubstRoot,EHighDensity,count); |
|
407 |
test_Value(r, r==KErrAccessDenied); |
|
408 |
||
409 |
r=iFs.SetSubst(_L(""),EDriveO); |
|
410 |
test_KErrNone(r); |
|
411 |
r=iFs.Subst(n,EDriveO); |
|
412 |
test_KErrNone(r); |
|
413 |
test(n==_L("")); |
|
414 |
r=iFs.Drive(d,EDriveO); |
|
415 |
test_KErrNone(r); |
|
416 |
test(d.iDriveAtt==0); |
|
417 |
} |
|
418 |
||
419 |
||
420 |
LOCAL_C TInt CreateFileX(const TDesC& aBaseName,TInt aX, RFs iFs) |
|
421 |
// |
|
422 |
// Create a large file. Return KErrEof or KErrNone |
|
423 |
// |
|
424 |
{ |
|
425 |
||
426 |
TBuf<128> fileName=aBaseName; |
|
427 |
fileName.AppendNum(aX); |
|
428 |
RFile file; |
|
429 |
TInt r=file.Replace(iFs,fileName,EFileWrite); |
|
430 |
if (r==KErrDiskFull) |
|
431 |
return(r); |
|
432 |
if (r!=KErrNone) |
|
433 |
{ |
|
434 |
test.Printf(_L("ERROR:: Replace returned %d\n"),r); |
|
435 |
return(KErrDiskFull); |
|
436 |
} |
|
437 |
r=file.SetSize(65536); |
|
438 |
if (r==KErrDiskFull) |
|
439 |
{ |
|
440 |
file.Close(); |
|
441 |
return(r); |
|
442 |
} |
|
443 |
if (r!=KErrNone) |
|
444 |
{ |
|
445 |
test.Printf(_L("ERROR:: SetSize returned %d\n"),r); |
|
446 |
file.Close(); |
|
447 |
return(KErrDiskFull); |
|
448 |
} |
|
449 |
file.Close(); |
|
450 |
// r=iFs.CheckDisk(fileName); |
|
451 |
// if (r!=KErrNone && r!=KErrNotSupported) |
|
452 |
// { |
|
453 |
// test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
|
454 |
// test.Getch(); |
|
455 |
// return(KErrDiskFull); |
|
456 |
// } |
|
457 |
test.Printf(_L("Created file %d size 64k\n"),aX); |
|
458 |
return(KErrNone); |
|
459 |
} |
|
460 |
||
461 |
LOCAL_C TInt DeleteFileX(TBuf<128>& aBaseName,TInt aX, RFs iFs) |
|
462 |
// |
|
463 |
// Delete a file. |
|
464 |
// |
|
465 |
{ |
|
466 |
||
467 |
TBuf<128> fileName=aBaseName; |
|
468 |
fileName.AppendNum(aX); |
|
469 |
TInt r=iFs.Delete(fileName); |
|
470 |
test_KErrNone(r); |
|
471 |
// r=iFs.CheckDisk(fileName); |
|
472 |
// if (r!=KErrNone && r!=KErrNotSupported) |
|
473 |
// { |
|
474 |
// test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
|
475 |
// test_KErrNone(r); |
|
476 |
// } |
|
477 |
test.Printf(_L("Deleted File %d\n"),aX); |
|
478 |
return(KErrNone); |
|
479 |
} |
|
480 |
||
481 |
void TSessionTest::MakeAndDeleteFiles() |
|
482 |
// |
|
483 |
// Create and delete large files in a randomish order |
|
484 |
// |
|
485 |
{ |
|
486 |
||
487 |
test.Start(_L("Create and delete large files")); |
|
488 |
TInt r=iFs.MkDirAll(_L("\\SESSION_TEST\\SMALLDIRECTORY\\")); |
|
489 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
490 |
TBuf<128> fileName=_L("\\SESSION_TEST\\SMALLDIRECTORY\\FILE"); |
|
491 |
r=CreateFileX(fileName,0,iFs); |
|
492 |
test_KErrNone(r); |
|
493 |
r=CreateFileX(fileName,1,iFs); |
|
494 |
test_KErrNone(r); |
|
495 |
r=DeleteFileX(fileName,0,iFs); |
|
496 |
test_KErrNone(r); |
|
497 |
r=CreateFileX(fileName,2,iFs); |
|
498 |
test_KErrNone(r); |
|
499 |
r=CreateFileX(fileName,1,iFs); |
|
500 |
test_KErrNone(r); |
|
501 |
r=CreateFileX(fileName,3,iFs); |
|
502 |
test_KErrNone(r); |
|
503 |
r=DeleteFileX(fileName,1,iFs); |
|
504 |
test_KErrNone(r); |
|
505 |
r=CreateFileX(fileName,4,iFs); |
|
506 |
test_KErrNone(r); |
|
507 |
r=DeleteFileX(fileName,2,iFs); |
|
508 |
test_KErrNone(r); |
|
509 |
r=DeleteFileX(fileName,3,iFs); |
|
510 |
test_KErrNone(r); |
|
511 |
r=DeleteFileX(fileName,4,iFs); |
|
512 |
test_KErrNone(r); |
|
513 |
r=CreateFileX(fileName,1,iFs); |
|
514 |
test_KErrNone(r); |
|
515 |
r=DeleteFileX(fileName,1,iFs); |
|
516 |
test_KErrNone(r); |
|
517 |
||
518 |
r=iFs.CheckDisk(fileName); |
|
519 |
test_Value(r, r==KErrNone || r==KErrNotSupported); |
|
520 |
test.End(); |
|
521 |
} |
|
522 |
||
523 |
void TSessionTest::FillUpDisk() |
|
524 |
// |
|
525 |
// Test that a full disk is ok |
|
526 |
// |
|
527 |
{ |
|
528 |
||
529 |
test.Start(_L("Fill disk to capacity")); |
|
530 |
TInt r=iFs.MkDirAll(_L("\\SESSION_TEST\\BIGDIRECTORY\\")); |
|
531 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
532 |
TInt count=0; |
|
533 |
TFileName sessionPath; |
|
534 |
r=iFs.SessionPath(sessionPath); |
|
535 |
test_KErrNone(r); |
|
536 |
TBuf<128> fileName=_L("\\SESSION_TEST\\BIGDIRECTORY\\FILE"); |
|
537 |
FOREVER |
|
538 |
{ |
|
539 |
TInt r=CreateFileX(fileName,count,iFs); |
|
540 |
if (r==KErrDiskFull) |
|
541 |
break; |
|
542 |
test_KErrNone(r); |
|
543 |
count++; |
|
544 |
#if defined(__WINS__) |
|
545 |
if (count==32 && sessionPath[0]=='C') // Don't fill up disk on NT |
|
546 |
break; |
|
547 |
#endif |
|
548 |
} |
|
549 |
||
550 |
r=iFs.CheckDisk(fileName); |
|
551 |
test_Value(r, r==KErrNone || r==KErrNotSupported); |
|
552 |
||
553 |
while(count--) |
|
554 |
DeleteFileX(fileName,count,iFs); |
|
555 |
||
556 |
r=iFs.CheckDisk(fileName); |
|
557 |
test_Value(r, r==KErrNone || r==KErrNotSupported); |
|
558 |
||
559 |
test.End(); |
|
560 |
} |
|
561 |
||
562 |
void TSessionTest::CopyFileToTestDirectory() |
|
563 |
// |
|
564 |
// Make a copy of the file in ram |
|
565 |
// |
|
566 |
{ |
|
567 |
||
568 |
TFileName fn = _L("Z:\\TEST\\T_FSRV.CPP"); |
|
569 |
fn[0] = gExeFileName[0]; |
|
570 |
TParse f; |
|
571 |
TInt r=iFs.Parse(fn,f); |
|
572 |
test_KErrNone(r); |
|
573 |
test.Next(_L("Copying file to test directory")); |
|
574 |
TParse fCopy; |
|
575 |
r=iFs.Parse(f.NameAndExt(),fCopy); |
|
576 |
test_KErrNone(r); |
|
577 |
||
578 |
RFile f1; |
|
579 |
r=f1.Open(iFs,f.FullName(),EFileStreamText|EFileShareReadersOnly); |
|
580 |
test.Printf(_L("r=%d\n"),r); |
|
581 |
test_KErrNone(r); |
|
582 |
RFile f2; |
|
583 |
r=f2.Replace(iFs,fCopy.FullName(),EFileWrite); |
|
584 |
test_KErrNone(r); |
|
585 |
TBuf8<512> copyBuf; |
|
586 |
TInt rem; |
|
587 |
r=f1.Size(rem); |
|
588 |
test_KErrNone(r); |
|
589 |
TInt pos=0; |
|
590 |
while (rem) |
|
591 |
{ |
|
592 |
TInt s=Min(rem,copyBuf.MaxSize()); |
|
593 |
r=f1.Read(pos,copyBuf,s); |
|
594 |
test_KErrNone(r); |
|
595 |
test(copyBuf.Length()==s); |
|
596 |
r=f2.Write(pos,copyBuf,s); |
|
597 |
test_KErrNone(r); |
|
598 |
pos+=s; |
|
599 |
rem-=s; |
|
600 |
} |
|
601 |
f1.Close(); |
|
602 |
f2.Close(); |
|
603 |
} |
|
604 |
||
605 |
||
606 |
void TSessionTest::testSetVolume() |
|
607 |
// |
|
608 |
// Test setting the volume info. |
|
609 |
// |
|
610 |
{ |
|
611 |
||
612 |
test.Start(_L("Test setting the volume label")); |
|
613 |
||
614 |
#if defined(_UNICODE) |
|
615 |
test.Printf(_L("Unicode volume label set not implemented ****\n")); |
|
616 |
test.End(); |
|
617 |
return; |
|
618 |
#else |
|
619 |
TInt driveNum=CurrentDrive(); |
|
620 |
TVolumeInfo v; |
|
621 |
TInt r=iFs.Volume(v,driveNum); |
|
622 |
test_KErrNone(r); |
|
623 |
TFileName n=v.iName; |
|
624 |
test.Printf(_L("VOL=\"%S\"\n"),&n); |
|
625 |
||
626 |
test.Next(_L("Set volume label to nothing")); |
|
627 |
r=iFs.SetVolumeLabel(_L(""),driveNum); |
|
628 |
#if defined(__WINS__) |
|
629 |
if (r==KErrGeneral || r==KErrAccessDenied || r==KErrNotSupported) |
|
630 |
{ |
|
631 |
test.Printf(_L("Error %d: Set volume label not testing on WINS\n"),r); |
|
632 |
test.End(); |
|
633 |
return; |
|
634 |
} |
|
635 |
#endif |
|
636 |
test_KErrNone(r); |
|
637 |
r=iFs.Volume(v,driveNum); |
|
638 |
test_KErrNone(r); |
|
639 |
test(v.iName==_L("")); |
|
640 |
test.Printf(_L("VOL=\"%S\"\n"),&v.iName); |
|
641 |
||
642 |
test.Next(_L("Set volume label to ABCDEFGHIJK")); |
|
643 |
r=iFs.SetVolumeLabel(_L("ABCDEFGHIJK"),driveNum); |
|
644 |
test_KErrNone(r); |
|
645 |
r=iFs.Volume(v,driveNum); |
|
646 |
test_KErrNone(r); |
|
647 |
test(v.iName==_L("ABCDEFGHIJK")); |
|
648 |
test.Printf(_L("VOL=\"%S\"\n"),&v.iName); |
|
649 |
||
650 |
test.Next(_L("Set volume label back to nothing")); |
|
651 |
r=iFs.SetVolumeLabel(_L(""),driveNum); |
|
652 |
test_KErrNone(r); |
|
653 |
r=iFs.Volume(v,driveNum); |
|
654 |
test_KErrNone(r); |
|
655 |
test(v.iName==_L("")); |
|
656 |
test.Printf(_L("VOL=\"%S\"\n"),&v.iName); |
|
657 |
||
658 |
test.Next(_L("Set volume label to original")); |
|
659 |
r=iFs.SetVolumeLabel(n,driveNum); |
|
660 |
test_KErrNone(r); |
|
661 |
r=iFs.Volume(v,driveNum); |
|
662 |
test_KErrNone(r); |
|
663 |
test(v.iName==n); |
|
664 |
test.Printf(_L("VOL=\"%S\"\n"),&v.iName); |
|
665 |
||
666 |
test.End(); |
|
667 |
#endif |
|
668 |
} |
|
669 |
||
670 |
LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt) |
|
671 |
// |
|
672 |
// Print a drive attribute. |
|
673 |
// |
|
674 |
{ |
|
675 |
||
676 |
test.Printf(_L("%c: "),aDrive+'A'); |
|
677 |
if (anAtt&KDriveAttLocal) |
|
678 |
test.Printf(_L("LOCAL ")); |
|
679 |
if (anAtt&KDriveAttRom) |
|
680 |
test.Printf(_L("ROM ")); |
|
681 |
if (anAtt&KDriveAttRedirected) |
|
682 |
test.Printf(_L("REDIR ")); |
|
683 |
if (anAtt&KDriveAttSubsted) |
|
684 |
test.Printf(_L("SUBST ")); |
|
685 |
if (anAtt&KDriveAttInternal) |
|
686 |
test.Printf(_L("INTERNAL ")); |
|
687 |
if ((anAtt&KDriveAttRemovable) && !(anAtt&KDriveAttLogicallyRemovable)) |
|
688 |
test.Printf(_L("PHYSICALLY-REMOVABLE ")); |
|
689 |
if (anAtt&KDriveAttLogicallyRemovable) |
|
690 |
test.Printf(_L("LOGICALLY-REMOVABLE ")); |
|
691 |
if (anAtt&KDriveAttHidden) |
|
692 |
test.Printf(_L("HIDDEN ")); |
|
693 |
test.Printf(_L("\n")); |
|
694 |
} |
|
695 |
||
696 |
LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo) |
|
697 |
// |
|
698 |
// Print a drive info. |
|
699 |
// |
|
700 |
{ |
|
701 |
||
702 |
printDriveAtt(aDrive,anInfo.iDriveAtt); |
|
703 |
test.Printf(_L(" MEDIA-ATT=")); |
|
704 |
if (anInfo.iMediaAtt==0) |
|
705 |
test.Printf(_L("<none>")); |
|
706 |
if (anInfo.iMediaAtt&KMediaAttVariableSize) |
|
707 |
test.Printf(_L("VariableSize ")); |
|
708 |
if (anInfo.iMediaAtt&KMediaAttDualDensity) |
|
709 |
test.Printf(_L("DualDensity ")); |
|
710 |
if (anInfo.iMediaAtt&KMediaAttFormattable) |
|
711 |
test.Printf(_L("Formattable ")); |
|
712 |
if (anInfo.iMediaAtt&KMediaAttWriteProtected) |
|
713 |
test.Printf(_L("WProtected ")); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
714 |
test.Printf(_L("\n CONNECTION BUS=")); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
715 |
switch(anInfo.iConnectionBusType) |
0 | 716 |
{ |
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
717 |
case EConnectionBusInternal: test.Printf(_L("Internal\n")); break; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
718 |
case EConnectionBusUsb: test.Printf(_L("USB\n")); break; |
0 | 719 |
default: |
720 |
test.Printf(_L("Unknown value\n")); |
|
721 |
} |
|
722 |
test.Printf(_L(" MEDIA=")); |
|
723 |
switch(anInfo.iType) |
|
724 |
{ |
|
725 |
case EMediaNotPresent: test.Printf(_L("Not present\n")); break; |
|
726 |
case EMediaUnknown: test.Printf(_L("Unknown\n")); break; |
|
727 |
case EMediaFloppy: test.Printf(_L("Floppy\n")); break; |
|
728 |
case EMediaHardDisk: test.Printf(_L("Hard disk\n")); break; |
|
729 |
case EMediaCdRom: test.Printf(_L("CD Rom\n")); break; |
|
730 |
case EMediaRam: test.Printf(_L("Ram\n")); break; |
|
731 |
case EMediaFlash: test.Printf(_L("Flash\n")); break; |
|
732 |
case EMediaRom: test.Printf(_L("Rom\n")); break; |
|
733 |
case EMediaRemote: test.Printf(_L("Remote\n")); break; |
|
734 |
default: |
|
735 |
test.Printf(_L("Unknown value\n")); |
|
736 |
} |
|
737 |
} |
|
738 |
||
739 |
LOCAL_C void DriveInfo(TInt aDrive,TDriveInfo& anInfo) |
|
740 |
// |
|
741 |
// Test the drive info is reasonable |
|
742 |
// |
|
743 |
{ |
|
744 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
745 |
test(anInfo.iConnectionBusType==EConnectionBusInternal || anInfo.iConnectionBusType==EConnectionBusUsb); |
0 | 746 |
|
747 |
if (aDrive==EDriveZ) |
|
748 |
{ |
|
749 |
if (anInfo.iType==EMediaNotPresent) |
|
750 |
return; |
|
751 |
||
752 |
test(anInfo.iMediaAtt==KMediaAttWriteProtected); |
|
753 |
test(anInfo.iDriveAtt==(KDriveAttRom|KDriveAttInternal)); |
|
754 |
test(anInfo.iType==EMediaRom); |
|
755 |
} |
|
756 |
||
757 |
/* |
|
758 |
Why assume certain drive letters can only refer to certain drive types? |
|
759 |
else if (aDrive==EDriveC || aDrive==EDriveY) |
|
760 |
{ |
|
761 |
if (anInfo.iType==EMediaNotPresent) |
|
762 |
return; |
|
763 |
||
764 |
// test(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttInternal)); |
|
765 |
||
766 |
test(anInfo.iDriveAtt&(KDriveAttLocal|KDriveAttInternal)==KDriveAttLocal|KDriveAttInternal); // LFFS sets KDriveAttTransaction as well |
|
767 |
test(anInfo.iType==EMediaRam || anInfo.iType==EMediaFlash); |
|
768 |
if(anInfo.iType==EMediaRam) test(anInfo.iMediaAtt==(KMediaAttVariableSize|KMediaAttFormattable)); |
|
769 |
else if(anInfo.iType==EMediaFlash) test(anInfo.iMediaAtt==KMediaAttFormattable); |
|
770 |
} |
|
771 |
||
772 |
else if (aDrive==EDriveD || aDrive==EDriveX) |
|
773 |
{ |
|
774 |
if (anInfo.iType==EMediaNotPresent) |
|
775 |
return; |
|
776 |
||
777 |
test(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttRemovable)); |
|
778 |
test(anInfo.iType==EMediaHardDisk); |
|
779 |
test(anInfo.iMediaAtt&KMediaAttFormattable); |
|
780 |
} |
|
781 |
*/ |
|
782 |
} |
|
783 |
||
784 |
void TSessionTest::CreateTestDirectory(const TDesC& aSessionPath) |
|
785 |
// |
|
786 |
// Create directory for test |
|
787 |
// |
|
788 |
{ |
|
789 |
TParsePtrC path(aSessionPath); |
|
790 |
test(path.DrivePresent()==EFalse); |
|
791 |
||
792 |
TInt r=iFs.SetSessionPath(aSessionPath); |
|
793 |
test_KErrNone(r); |
|
794 |
r=iFs.SessionPath(gTestSessionPath); |
|
795 |
test_KErrNone(r); |
|
796 |
r=iFs.MkDirAll(gTestSessionPath); |
|
797 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
798 |
} |
|
799 |
||
800 |
TInt TSessionTest::CurrentDrive() |
|
801 |
// |
|
802 |
// Return the current drive number |
|
803 |
// |
|
804 |
{ |
|
805 |
||
806 |
TInt driveNum; |
|
807 |
TInt r=iFs.CharToDrive(gTestSessionPath[0],driveNum); |
|
808 |
test_KErrNone(r); |
|
809 |
return(driveNum); |
|
810 |
} |
|
811 |