author | hgs |
Wed, 12 May 2010 10:34:10 +0100 | |
changeset 133 | 2a0ada0a1bf8 |
parent 33 | 0173bcd7697c |
child 109 | b3a1d9898418 |
child 175 | 5af6c74cd793 |
child 249 | a179b74831c9 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// |
|
15 |
||
16 |
#define __E32TEST_EXTENSION__ |
|
17 |
||
18 |
#include <f32file.h> |
|
19 |
#include <e32test.h> |
|
20 |
#include <e32svr.h> |
|
21 |
#include "t_server.h" |
|
22 |
#include "t_chlffs.h" |
|
23 |
#include "fs_utils.h" |
|
24 |
||
25 |
#include "f32_test_utils.h" |
|
26 |
||
27 |
using namespace F32_Test_Utils; |
|
28 |
||
29 |
RTest test(_L("T_FILE")); |
|
30 |
||
31 |
TBool gShortFileNamesSupported = EFalse; |
|
32 |
||
33 |
static TBuf8<1500> gBuf; |
|
34 |
||
35 |
TInt gDriveNum = -1; |
|
36 |
||
37 |
static void testShare() |
|
38 |
// |
|
39 |
// Test file sharing. |
|
40 |
// |
|
41 |
{ |
|
42 |
||
43 |
test.Start(_L("Test exclusive sharing")); |
|
44 |
MakeFile(_L("TESTER")); |
|
45 |
||
46 |
/* |
|
47 |
Extra code to answer a question about a potential WINS bug. WINS Elocal returns |
|
48 |
KErrAccessDenied to the write operation but EFat returns |
|
49 |
KErrNone... |
|
50 |
||
51 |
RFile f1; |
|
52 |
TInt r=f1.Open(TheFs,_L("TESTER"),EFileRead|EFileShareAny); |
|
53 |
test(r==KErrNone); |
|
54 |
RFile f2; |
|
55 |
r=f2.Open(TheFs,_L("TESTER"),EFileWrite|EFileShareAny); |
|
56 |
test(r==KErrNone); |
|
57 |
||
58 |
r=f2.Write(_L("0")); |
|
59 |
test.Printf(_L("returned %d"),r); |
|
60 |
||
61 |
f1.Close(); |
|
62 |
f2.Close(); |
|
63 |
||
64 |
r=TheFs.Delete(_L("TESTER")); |
|
65 |
test(r==KErrNone); |
|
66 |
*/ |
|
67 |
||
68 |
RFile f1; |
|
69 |
TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); |
|
70 |
test(r==KErrNone); |
|
71 |
RFile f2; |
|
72 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); |
|
73 |
test(r==KErrInUse); |
|
74 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
75 |
test(r==KErrInUse); |
|
76 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); |
|
77 |
test(r==KErrInUse); |
|
78 |
f1.Close(); |
|
79 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareExclusive); |
|
80 |
test(r==KErrNone); |
|
81 |
f1.Close(); |
|
82 |
||
83 |
test.Next(_L("Test readers only sharing")); |
|
84 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareReadersOnly); |
|
85 |
test(r==KErrArgument); |
|
86 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
87 |
test(r==KErrNone); |
|
88 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); |
|
89 |
test(r==KErrInUse); |
|
90 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); |
|
91 |
test(r==KErrInUse); |
|
92 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareReadersOnly); |
|
93 |
test(r==KErrArgument); |
|
94 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
95 |
test(r==KErrNone); |
|
96 |
f1.Close(); |
|
97 |
f2.Close(); |
|
98 |
||
99 |
test.Next(_L("Test any sharing")); |
|
100 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareAny); |
|
101 |
test(r==KErrNone); |
|
102 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); |
|
103 |
test(r==KErrInUse); |
|
104 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
105 |
test(r==KErrInUse); |
|
106 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); |
|
107 |
test(r==KErrNone); |
|
108 |
f1.Close(); |
|
109 |
f2.Close(); |
|
110 |
||
111 |
test.End(); |
|
112 |
} |
|
113 |
||
114 |
static void testChangeMode() |
|
115 |
// |
|
116 |
// Test changing the share mode of a file between EFileShareReadersOnly <-> EFileShareExclusive |
|
117 |
// |
|
118 |
{ |
|
119 |
||
120 |
test.Start(_L("Test change mode")); |
|
121 |
RFile f1; |
|
122 |
RFile f2; |
|
123 |
TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); |
|
124 |
test(r==KErrNone); // Opened exclusive |
|
125 |
r=f1.ChangeMode(EFileShareReadersOnly); |
|
126 |
test(r==KErrNone); // Change to readers only |
|
127 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
128 |
test(r==KErrNone); // Open as reader |
|
129 |
r=f1.ChangeMode(EFileShareExclusive); |
|
130 |
test(r==KErrAccessDenied); // Change back to exclusive fails |
|
131 |
r=f2.ChangeMode(EFileShareExclusive); |
|
132 |
test(r==KErrAccessDenied); // Change to exclusive fails |
|
133 |
f1.Close(); // Close other reader |
|
134 |
r=f2.ChangeMode(EFileShareExclusive); |
|
135 |
test(r==KErrNone); // Change to exclusive succeeds. |
|
136 |
f2.Close(); |
|
137 |
||
138 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
139 |
test(r==KErrNone); // Opened readers only |
|
140 |
r=f1.ChangeMode(EFileShareExclusive); |
|
141 |
test(r==KErrNone); // Change to exclusive |
|
142 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
143 |
test(r==KErrInUse); // Open as reader fails |
|
144 |
r=f1.ChangeMode(EFileShareReadersOnly); |
|
145 |
test(r==KErrNone); // Change to readers only |
|
146 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
147 |
test(r==KErrNone); // Open as reader |
|
148 |
r=f1.ChangeMode(EFileShareExclusive); |
|
149 |
test(r==KErrAccessDenied); // Change back to exclusive fails |
|
150 |
r=f2.ChangeMode(EFileShareExclusive); |
|
151 |
test(r==KErrAccessDenied); // Change to exclusive fails |
|
152 |
f1.Close(); // Close other reader |
|
153 |
r=f2.ChangeMode(EFileShareExclusive); |
|
154 |
test(r==KErrNone); // Change to exclusive succeeds. |
|
155 |
f2.Close(); |
|
156 |
||
157 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareExclusive); |
|
158 |
test(r==KErrNone); // Opened exclusive for writing |
|
159 |
r=f1.ChangeMode(EFileShareReadersOnly); |
|
160 |
test(r==KErrAccessDenied); // Change to readers fails |
|
161 |
r=f1.ChangeMode(EFileShareExclusive); |
|
162 |
test(r==KErrNone); // No change ok |
|
163 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
164 |
test(r==KErrInUse); // Open as reader fails |
|
165 |
f1.Close(); |
|
166 |
||
167 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); |
|
168 |
test(r==KErrNone); // Opened share any |
|
169 |
r=f1.ChangeMode(EFileShareExclusive); |
|
170 |
test(r==KErrAccessDenied); // Change to exclusive fails |
|
171 |
r=f1.ChangeMode(EFileShareReadersOnly); |
|
172 |
test(r==KErrAccessDenied); // Change to readers only fails |
|
173 |
f1.Close(); |
|
174 |
||
175 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); |
|
176 |
test(r==KErrNone); // Opened exclusive |
|
177 |
r=f1.ChangeMode(EFileShareAny); |
|
178 |
test(r==KErrArgument); // Change to share any fails KErrArgument |
|
179 |
r=f1.ChangeMode((TFileMode)42); |
|
180 |
test(r==KErrArgument); // Change to random value fails |
|
181 |
f1.Close(); |
|
182 |
test.End(); |
|
183 |
} |
|
184 |
||
185 |
static void testReadFile() |
|
186 |
// |
|
187 |
// Test read file handling. |
|
188 |
// |
|
189 |
{ |
|
190 |
||
191 |
test.Start(_L("Test read file")); |
|
192 |
RFile f,ZFile; |
|
193 |
TInt r=f.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText); |
|
194 |
test(r==KErrNone); |
|
195 |
TFileName fn = _L("Z:\\TEST\\T_FILE.CPP"); |
|
196 |
fn[0] = gExeFileName[0]; |
|
197 |
r=ZFile.Open(TheFs,fn,EFileStreamText); |
|
198 |
test(r==KErrNone); |
|
199 |
||
200 |
test.Next(_L("Read file")); |
|
201 |
TBuf8<0x100> a,b; |
|
202 |
FOREVER |
|
203 |
{ |
|
204 |
r=f.Read(b); |
|
205 |
test(r==KErrNone); |
|
206 |
r=ZFile.Read(a); |
|
207 |
test(r==KErrNone); |
|
208 |
test(a==b); |
|
209 |
if (b.Length()<b.MaxLength()) |
|
210 |
break; |
|
211 |
} |
|
212 |
b.SetLength(10); |
|
213 |
r=f.Read(b); |
|
214 |
test(r==KErrNone); |
|
215 |
test(b.Length()==0); |
|
216 |
f.Close(); |
|
217 |
ZFile.Close(); |
|
218 |
||
219 |
test.Next(_L("Read way beyond the end of the file")); |
|
220 |
r=f.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText); |
|
221 |
test(r==KErrNone); |
|
222 |
r=f.Read(3000000,gBuf); |
|
223 |
test(r==KErrNone); |
|
224 |
f.Close(); |
|
225 |
||
226 |
test.Next(_L("Write way beyond the end of the file")); |
|
227 |
r=f.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite); |
|
228 |
test(r==KErrNone); |
|
229 |
gBuf.SetLength(10); |
|
230 |
r=f.Write(3000000,gBuf); |
|
231 |
test(r==KErrNone); |
|
232 |
f.Close(); |
|
233 |
test.End(); |
|
234 |
} |
|
235 |
||
236 |
static void testMultipleReadFile() |
|
237 |
// |
|
238 |
// Test multiple read file handling. |
|
239 |
// |
|
240 |
{ |
|
241 |
||
242 |
test.Start(_L("Test multiple read file")); |
|
243 |
RFile f1; |
|
244 |
TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
245 |
test(r==KErrNone); |
|
246 |
RFile f2; |
|
247 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
248 |
test(r==KErrNone); |
|
249 |
||
250 |
test.Next(_L("Read file")); |
|
251 |
FOREVER |
|
252 |
{ |
|
253 |
TBuf8<0x100> b1; |
|
254 |
r=f1.Read(b1); |
|
255 |
test(r==KErrNone); |
|
256 |
TBuf8<0x100> b2; |
|
257 |
r=f2.Read(b2); |
|
258 |
test(r==KErrNone); |
|
259 |
test(b1==b2); |
|
260 |
if (b1.Length()<b1.MaxLength()) |
|
261 |
break; |
|
262 |
} |
|
263 |
||
264 |
test.Next(_L("Close file")); |
|
265 |
f1.Close(); |
|
266 |
f2.Close(); |
|
267 |
||
268 |
test.End(); |
|
269 |
} |
|
270 |
||
271 |
static void testWriteFile() |
|
272 |
// |
|
273 |
// Test write file handling. |
|
274 |
// |
|
275 |
{ |
|
276 |
test.Start(_L("Test write file")); |
|
277 |
RFile file; |
|
278 |
TFileName fn = _L("File.File"); |
|
279 |
TBuf8<16> testData=_L8("testData"); |
|
280 |
||
281 |
// write test 1 |
|
282 |
TInt r=file.Replace(TheFs,fn,EFileStreamText); |
|
283 |
test(r==KErrNone); |
|
284 |
||
285 |
test.Next(_L("Write file")); |
|
286 |
||
287 |
r=file.Write(testData); |
|
288 |
test(r==KErrNone); |
|
289 |
||
290 |
file.Close(); |
|
291 |
||
292 |
// test write modes |
|
293 |
// test writing with EFileRead |
|
294 |
r=file.Open(TheFs,fn,EFileStreamText|EFileRead); |
|
295 |
test(r==KErrNone); |
|
296 |
||
297 |
test.Next(_L("Write file")); |
|
298 |
r=file.Write(testData); |
|
299 |
test(r==KErrAccessDenied); |
|
300 |
file.Close(); |
|
301 |
||
302 |
// test writing with EFileWrite |
|
303 |
r=file.Open(TheFs,fn,EFileStreamText|EFileWrite); |
|
304 |
test(r==KErrNone); |
|
305 |
||
306 |
test.Next(_L("Write file")); |
|
307 |
r=file.Write(testData); |
|
308 |
test(r==KErrNone); |
|
309 |
file.Close(); |
|
310 |
||
311 |
// test writing with share mode EFileShareExclusive |
|
312 |
r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareExclusive); |
|
313 |
test(r==KErrNone); |
|
314 |
||
315 |
test.Next(_L("Write file")); |
|
316 |
r=file.Write(testData); |
|
317 |
test(r==KErrNone); |
|
318 |
file.Close(); |
|
319 |
||
320 |
// test writing with share mode EFileShareReadersOnly (fails with KErrArgument) |
|
321 |
r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareReadersOnly); |
|
322 |
test(r==KErrArgument); |
|
323 |
||
324 |
// test writing with share mode EFileShareReadersOrWriters |
|
325 |
r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareReadersOrWriters); |
|
326 |
test(r==KErrNone); |
|
327 |
||
328 |
test.Next(_L("Write file")); |
|
329 |
r=file.Write(testData); |
|
330 |
test(r==KErrNone); |
|
331 |
file.Close(); |
|
332 |
||
333 |
// test writing with share mode EFileShareAny |
|
334 |
r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareAny); |
|
335 |
test(r==KErrNone); |
|
336 |
||
337 |
test.Next(_L("Write file")); |
|
338 |
r=file.Write(testData); |
|
339 |
test(r==KErrNone); |
|
340 |
file.Close(); |
|
341 |
||
342 |
// tidy up |
|
343 |
r=TheFs.Delete(fn); |
|
344 |
test(r==KErrNone); |
|
345 |
||
346 |
test.End(); |
|
347 |
} |
|
348 |
||
349 |
static void CopyFileToTestDirectory() |
|
350 |
// |
|
351 |
// Make a copy of the file in ram |
|
352 |
// |
|
353 |
{ |
|
354 |
||
355 |
TFileName fn = _L("Z:\\TEST\\T_FILE.CPP"); |
|
356 |
fn[0] = gExeFileName[0]; |
|
357 |
TParse f; |
|
358 |
TInt r; |
|
359 |
r=TheFs.Parse(fn,f); |
|
360 |
test(r==KErrNone); |
|
361 |
TParse fCopy; |
|
362 |
r=TheFs.Parse(f.NameAndExt(),fCopy); |
|
363 |
test(r==KErrNone); |
|
364 |
||
365 |
RFile f1; |
|
366 |
r=f1.Open(TheFs,f.FullName(),EFileStreamText|EFileShareReadersOnly); |
|
367 |
test(r==KErrNone); |
|
368 |
RFile f2; |
|
369 |
r=f2.Replace(TheFs,fCopy.FullName(),EFileWrite); |
|
370 |
test(r==KErrNone); |
|
371 |
TBuf8<512> copyBuf; |
|
372 |
TInt rem; |
|
373 |
r=f1.Size(rem); |
|
374 |
test(r==KErrNone); |
|
375 |
TInt pos=0; |
|
376 |
while (rem) |
|
377 |
{ |
|
378 |
TInt s=Min(rem,copyBuf.MaxSize()); |
|
379 |
r=f1.Read(pos,copyBuf,s); |
|
380 |
test(r==KErrNone); |
|
381 |
test(copyBuf.Length()==s); |
|
382 |
r=f2.Write(pos,copyBuf,s); |
|
383 |
test(r==KErrNone); |
|
384 |
pos+=s; |
|
385 |
rem-=s; |
|
386 |
} |
|
387 |
f1.Close(); |
|
388 |
f2.Close(); |
|
389 |
} |
|
390 |
||
391 |
static void testFileText() |
|
392 |
// |
|
393 |
// Test TFileText class methods |
|
394 |
// |
|
395 |
{ |
|
396 |
||
397 |
test.Next(_L("Test file text")); |
|
398 |
TPtrC record[5]; |
|
399 |
record[0].Set(_L("First record")); |
|
400 |
record[1].Set(_L("Second record")); |
|
401 |
record[2].Set(_L("Third record")); |
|
402 |
record[3].Set(_L("Fourth record")); |
|
403 |
record[4].Set(_L("Fifth record")); |
|
404 |
||
405 |
RFile f; |
|
406 |
TInt r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0); |
|
407 |
test(r==KErrNone); |
|
408 |
TFileText textFile; |
|
409 |
textFile.Set(f); |
|
410 |
TInt i=0; |
|
411 |
for (i=0;i<5;i++) |
|
412 |
{ |
|
413 |
r=textFile.Write(record[i]); |
|
414 |
test(r==KErrNone); |
|
415 |
} |
|
416 |
r=textFile.Seek(ESeekStart); |
|
417 |
test(r==KErrNone); |
|
418 |
TBuf<16> recBuf; |
|
419 |
for(i=0;i<5;i++) |
|
420 |
{ |
|
421 |
r=textFile.Read(recBuf); |
|
422 |
test(r==KErrNone); |
|
423 |
test(recBuf==record[i]); |
|
424 |
} |
|
425 |
r=textFile.Read(recBuf); |
|
426 |
test(r==KErrEof); |
|
427 |
test(recBuf.Length()==0); |
|
428 |
f.Close(); |
|
429 |
||
430 |
test.Next(_L("Test dosfile terminator")); |
|
431 |
TPtrC8 trecord[7]; |
|
432 |
TPtrC tTextrecord[7]; |
|
433 |
tTextrecord[0].Set(_L("First record\r\n")); |
|
434 |
tTextrecord[1].Set(_L("Second record\r\n")); |
|
435 |
tTextrecord[2].Set(_L("Third record\r\n")); |
|
436 |
tTextrecord[3].Set(_L("Fourth record\r\n")); |
|
437 |
tTextrecord[4].Set(_L("Fifth record\r\n")); |
|
438 |
tTextrecord[5].Set(_L("Sixth record\n\r")); |
|
439 |
tTextrecord[6].Set(_L("Seventh record\n")); |
|
440 |
trecord[0].Set((TUint8*)tTextrecord[0].Ptr(),tTextrecord[0].Length()*sizeof(TText)); |
|
441 |
trecord[1].Set((TUint8*)tTextrecord[1].Ptr(),tTextrecord[1].Length()*sizeof(TText)); |
|
442 |
trecord[2].Set((TUint8*)tTextrecord[2].Ptr(),tTextrecord[2].Length()*sizeof(TText)); |
|
443 |
trecord[3].Set((TUint8*)tTextrecord[3].Ptr(),tTextrecord[3].Length()*sizeof(TText)); |
|
444 |
trecord[4].Set((TUint8*)tTextrecord[4].Ptr(),tTextrecord[4].Length()*sizeof(TText)); |
|
445 |
trecord[5].Set((TUint8*)tTextrecord[5].Ptr(),tTextrecord[5].Length()*sizeof(TText)); |
|
446 |
trecord[6].Set((TUint8*)tTextrecord[6].Ptr(),tTextrecord[6].Length()*sizeof(TText)); |
|
447 |
r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0); |
|
448 |
test(r==KErrNone); |
|
449 |
for(i=0;i<7;i++) |
|
450 |
{ |
|
451 |
TBuf8<256> buf; |
|
452 |
buf.Copy(trecord[i]); |
|
453 |
r=f.Write(buf); |
|
454 |
test(r==KErrNone); |
|
455 |
} |
|
456 |
textFile.Set(f); |
|
457 |
textFile.Seek(ESeekStart); |
|
458 |
for(i=0;i<5;i++) |
|
459 |
{ |
|
460 |
r=textFile.Read(recBuf); |
|
461 |
test(r==KErrNone); |
|
462 |
test(recBuf==record[i]); |
|
463 |
} |
|
464 |
r=textFile.Read(recBuf); |
|
465 |
test(r==KErrNone); |
|
466 |
test(recBuf==_L("Sixth record")); |
|
467 |
r=textFile.Read(recBuf); |
|
468 |
test(r==KErrNone); |
|
469 |
test(recBuf==_L("\rSeventh record")); |
|
470 |
r=textFile.Read(recBuf); |
|
471 |
test(r==KErrEof); |
|
472 |
test(recBuf.Length()==0); |
|
473 |
f.Close(); |
|
474 |
||
475 |
test.Next(_L("Test read with bufferSize == dataSize")); |
|
476 |
r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0); |
|
477 |
test(r==KErrNone); |
|
478 |
record[0].Set(_L("1234567890123456")); |
|
479 |
// trecord[0].Set(_L8("1234567890123456\r\n")); |
|
480 |
// trecord[1].Set(_L8("1234567890123456\n")); |
|
481 |
||
482 |
TPtrC tmpTextrecord; |
|
483 |
tmpTextrecord.Set(_L("1234567890123456\r\n")); |
|
484 |
trecord[0].Set((TUint8*)tmpTextrecord.Ptr(),tmpTextrecord.Length()*sizeof(TText)); |
|
485 |
||
486 |
tmpTextrecord.Set(_L("1234567890123456\n")); |
|
487 |
trecord[1].Set((TUint8*)tmpTextrecord.Ptr(),tmpTextrecord.Length()*sizeof(TText)); |
|
488 |
||
489 |
for (i=0;i<2;i++) |
|
490 |
{ |
|
491 |
r=f.Write(trecord[i]); |
|
492 |
test(r==KErrNone); |
|
493 |
} |
|
494 |
textFile.Set(f); |
|
495 |
textFile.Seek(ESeekStart); |
|
496 |
for(i=0;i<2;i++) |
|
497 |
{ |
|
498 |
r=textFile.Read(recBuf); |
|
499 |
test(r==KErrNone); |
|
500 |
test(recBuf==record[0]); |
|
501 |
} |
|
502 |
r=textFile.Read(recBuf); |
|
503 |
test(r==KErrEof); |
|
504 |
test(recBuf.Length()==0); |
|
505 |
f.Close(); |
|
506 |
||
507 |
test.Next(_L("Read into a buffer < recordSize")); |
|
508 |
TBuf<8> smallBuf; |
|
509 |
r=f.Open(TheFs,_L("TEXTFILE.txt"),0); |
|
510 |
test(r==KErrNone); |
|
511 |
textFile.Set(f); |
|
512 |
for(i=0;i<2;i++) |
|
513 |
{ |
|
514 |
r=textFile.Read(smallBuf); |
|
515 |
test(r==KErrTooBig); |
|
516 |
test(smallBuf==_L("12345678")); |
|
517 |
} |
|
518 |
f.Close(); |
|
519 |
||
520 |
test.Next(_L("Nasty cases: 1) \\r \\n split over buffer boundary")); |
|
521 |
r=f.Replace(TheFs,_L("TEXTFILE.txt"),0); |
|
522 |
test(r==KErrNone); |
|
523 |
HBufC* largeRecord=HBufC::NewL(600); |
|
524 |
largeRecord->Des().SetLength(250); |
|
525 |
largeRecord->Des().Fill('A'); |
|
526 |
largeRecord->Des()[249]='\n'; |
|
527 |
TPtrC8 bufPtr; |
|
528 |
bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); // Size() returns length in bytes |
|
529 |
r=f.Write(bufPtr); |
|
530 |
test(r==KErrNone); |
|
531 |
TBuf<16> boundaryBuf=_L("12345\r\n"); |
|
532 |
bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
533 |
r=f.Write(bufPtr); |
|
534 |
test(r==KErrNone); |
|
535 |
r=f.Write(trecord[0]); |
|
536 |
test(r==KErrNone); |
|
537 |
||
538 |
textFile.Set(f); |
|
539 |
textFile.Seek(ESeekStart); |
|
540 |
r=textFile.Read(recBuf); |
|
541 |
test(r==KErrTooBig); |
|
542 |
test(recBuf==_L("AAAAAAAAAAAAAAAA")); |
|
543 |
r=textFile.Read(recBuf); |
|
544 |
test(r==KErrNone); |
|
545 |
test(recBuf==_L("12345")); |
|
546 |
r=textFile.Read(recBuf); |
|
547 |
test(r==KErrNone); |
|
548 |
test(recBuf==record[0]); |
|
549 |
f.Close(); |
|
550 |
||
551 |
test.Next(_L("Nasty cases: 2) \\r on buffer boundary")); |
|
552 |
r=f.Replace(TheFs,_L("TEXTFILE.txt"),0); |
|
553 |
test(r==KErrNone); |
|
554 |
largeRecord->Des().SetLength(250); |
|
555 |
largeRecord->Des().Fill('A'); |
|
556 |
largeRecord->Des()[249]='\n'; |
|
557 |
bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); |
|
558 |
r=f.Write(bufPtr); |
|
559 |
test(r==KErrNone); |
|
560 |
boundaryBuf=_L("12345\rxyz\n"); |
|
561 |
bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
562 |
r=f.Write(bufPtr); |
|
563 |
test(r==KErrNone); |
|
564 |
r=f.Write(trecord[0]); |
|
565 |
test(r==KErrNone); |
|
566 |
||
567 |
textFile.Set(f); |
|
568 |
textFile.Seek(ESeekStart); |
|
569 |
r=textFile.Read(recBuf); |
|
570 |
test(r==KErrTooBig); |
|
571 |
test(recBuf==_L("AAAAAAAAAAAAAAAA")); |
|
572 |
r=textFile.Read(recBuf); |
|
573 |
test(r==KErrNone); |
|
574 |
test(recBuf==_L("12345\rxyz")); |
|
575 |
r=textFile.Read(recBuf); |
|
576 |
test(r==KErrNone); |
|
577 |
test(recBuf==record[0]); |
|
578 |
f.Close(); |
|
579 |
||
580 |
test.Next(_L("Nasty cases: 3) record size > buffer size")); |
|
581 |
r=f.Replace(TheFs,_L("TEXTFILE.txt"),0); |
|
582 |
test(r==KErrNone); |
|
583 |
largeRecord->Des().SetLength(600); |
|
584 |
largeRecord->Des().Fill('Z'); |
|
585 |
largeRecord->Des()[511]='\r'; |
|
586 |
largeRecord->Des()[599]='\n'; |
|
587 |
bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); |
|
588 |
r=f.Write(bufPtr); |
|
589 |
test(r==KErrNone); |
|
590 |
boundaryBuf=_L("12345\rxyz\n"); |
|
591 |
bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
592 |
r=f.Write(bufPtr); |
|
593 |
test(r==KErrNone); |
|
594 |
r=f.Write(trecord[0]); |
|
595 |
test(r==KErrNone); |
|
596 |
||
597 |
textFile.Set(f); |
|
598 |
textFile.Seek(ESeekStart); |
|
599 |
r=textFile.Read(recBuf); |
|
600 |
test(r==KErrTooBig); |
|
601 |
test(recBuf==_L("ZZZZZZZZZZZZZZZZ")); |
|
602 |
r=textFile.Read(recBuf); |
|
603 |
test(r==KErrNone); |
|
604 |
test(recBuf==_L("12345\rxyz")); |
|
605 |
r=textFile.Read(recBuf); |
|
606 |
test(r==KErrNone); |
|
607 |
test(recBuf==record[0]); |
|
608 |
||
609 |
TBuf<601> bigBuf; |
|
610 |
TPtrC largePtr((TText*)largeRecord->Ptr(),(largeRecord->Length()-1)); |
|
611 |
textFile.Seek(ESeekStart); |
|
612 |
r=textFile.Read(bigBuf); |
|
613 |
test(r==KErrNone); |
|
614 |
test(bigBuf==largePtr); |
|
615 |
r=textFile.Read(recBuf); |
|
616 |
test(r==KErrNone); |
|
617 |
test(recBuf==_L("12345\rxyz")); |
|
618 |
r=textFile.Read(recBuf); |
|
619 |
test(r==KErrNone); |
|
620 |
test(recBuf==record[0]); |
|
621 |
f.Close(); |
|
622 |
||
623 |
User::Free(largeRecord); |
|
624 |
} |
|
625 |
||
626 |
static void testFileTextEndRecord() |
|
627 |
// |
|
628 |
// Test terminating record |
|
629 |
// |
|
630 |
{ |
|
631 |
||
632 |
test.Next(_L("Test FileText last record has no terminator")); |
|
633 |
RFile f; |
|
634 |
TInt r=f.Replace(TheFs,_L("TextFile"),0); |
|
635 |
test(r==KErrNone); |
|
636 |
TPtrC8 bufPtr; |
|
637 |
TBuf<16>boundaryBuf=_L("Record1\n"); |
|
638 |
bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
639 |
r=f.Write(bufPtr); |
|
640 |
test(r==KErrNone); |
|
641 |
boundaryBuf=_L("Record2\n"); |
|
642 |
bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
643 |
r=f.Write(bufPtr); |
|
644 |
test(r==KErrNone); |
|
645 |
boundaryBuf=_L("Record3\n"); |
|
646 |
bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
647 |
r=f.Write(bufPtr); |
|
648 |
test(r==KErrNone); |
|
649 |
||
650 |
TFileText fText; |
|
651 |
fText.Set(f); |
|
652 |
r=fText.Seek(ESeekStart); |
|
653 |
test(r==KErrNone); |
|
654 |
TBuf<32> recBuf; |
|
655 |
r=fText.Read(recBuf); |
|
656 |
test(r==KErrNone); |
|
657 |
test(recBuf.MatchF(_L("record1"))!=KErrNotFound); |
|
658 |
r=fText.Read(recBuf); |
|
659 |
test(r==KErrNone); |
|
660 |
test(recBuf.MatchF(_L("record2"))!=KErrNotFound); |
|
661 |
r=fText.Read(recBuf); |
|
662 |
test(r==KErrNone); |
|
663 |
test(recBuf.MatchF(_L("record3"))!=KErrNotFound); |
|
664 |
r=fText.Read(recBuf); |
|
665 |
test(r==KErrEof); |
|
666 |
test(recBuf.Length()==0); |
|
667 |
f.Close(); |
|
668 |
||
669 |
TBuf<0x100> bigBuf(0x100); |
|
670 |
bigBuf.Fill('A'); |
|
671 |
r=f.Replace(TheFs,_L("TextFile"),0); |
|
672 |
test(r==KErrNone); |
|
673 |
||
674 |
bufPtr.Set((TUint8*)bigBuf.Ptr(),bigBuf.Size()); |
|
675 |
r=f.Write(bufPtr); |
|
676 |
test(r==KErrNone); |
|
677 |
||
678 |
fText.Set(f); |
|
679 |
r=fText.Seek(ESeekStart); |
|
680 |
test(r==KErrNone); |
|
681 |
bigBuf.SetLength(0); |
|
682 |
r=fText.Read(bigBuf); |
|
683 |
test.Printf(_L("fText.Read returns %d\n"),r); |
|
684 |
test(r==KErrNone); |
|
685 |
test.Printf(_L("BigBuf.Length()==%d\n"),bigBuf.Length()); |
|
686 |
test(bigBuf.Length()==0x100); |
|
687 |
r=fText.Read(bigBuf); |
|
688 |
test(r==KErrEof); |
|
689 |
test(bigBuf.Length()==0); |
|
690 |
f.Close(); |
|
691 |
} |
|
692 |
||
693 |
static void testFileNames() |
|
694 |
// |
|
695 |
// Test file names |
|
696 |
// |
|
697 |
{ |
|
698 |
||
699 |
test.Next(_L("Test temp filenames specify drive")); |
|
700 |
TFileName tempFileName; |
|
701 |
RFile f; |
|
702 |
TInt r=f.Temp(TheFs,_L(""),tempFileName,EFileRead); |
|
703 |
test(r==KErrNone); |
|
704 |
TParse p; |
|
705 |
p.Set(tempFileName,NULL,NULL); |
|
706 |
test(p.DrivePresent()); |
|
707 |
test(p.PathPresent()); |
|
708 |
test(p.NamePresent()); |
|
709 |
test(p.ExtPresent()); |
|
710 |
f.Close(); |
|
711 |
||
712 |
r=f.Replace(TheFs,_L("WELCOMETO"),EFileWrite); |
|
713 |
test(r==KErrNone); |
|
714 |
f.Close(); |
|
715 |
r=f.Replace(TheFs,_L("WELCOMETO.WRD"),EFileWrite); |
|
716 |
test(r==KErrNone); |
|
717 |
f.Close(); |
|
718 |
} |
|
719 |
||
720 |
// Nasty hack - mask attributes returned by RFile::Att() with this. |
|
721 |
// File server used to do this but that stopped the XIP attribute on the ROM file system |
|
722 |
// from being returned. It should really be up to the file system to return only |
|
723 |
// the attributes which it supports rather than having the file server unilaterally |
|
724 |
// mask off any attributes which don't exist on FAT. |
|
725 |
#define ATT_MASK 0x3f |
|
726 |
static void testFileAttributes() |
|
727 |
// |
|
728 |
// Test the archive attribute gets set |
|
729 |
// |
|
730 |
{ |
|
731 |
||
732 |
test.Next(_L("Archive att is set after creation")); |
|
733 |
RFile f; |
|
734 |
TInt r=TheFs.Delete(_L("FILEATT.ARC")); |
|
735 |
test(r==KErrNone || r==KErrNotFound); |
|
736 |
r=f.Create(TheFs,_L("FILEATT.ARC"),EFileRead); |
|
737 |
test(r==KErrNone); |
|
738 |
TUint atts; |
|
739 |
r=f.Att(atts); |
|
740 |
test(r==KErrNone); |
|
741 |
test((atts&ATT_MASK)==KEntryAttArchive); |
|
742 |
TEntry fileAtt; |
|
743 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
744 |
test(r==KErrNone); |
|
745 |
test(fileAtt.iAtt==KEntryAttArchive); |
|
746 |
f.Close(); |
|
747 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
748 |
test(r==KErrNone); |
|
749 |
test(fileAtt.iAtt==KEntryAttArchive); |
|
750 |
||
751 |
test.Next(_L("Archive att is set after a write")); |
|
752 |
TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive); |
|
753 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
754 |
test(r==KErrNone); |
|
755 |
test(fileAtt.iAtt==0); |
|
756 |
r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite); |
|
757 |
test(r==KErrNone); |
|
758 |
r=f.Write(_L8("Hello World")); |
|
759 |
test(r==KErrNone); |
|
760 |
r=f.Att(atts); |
|
761 |
test(r==KErrNone); |
|
762 |
test((atts&ATT_MASK)==KEntryAttArchive); |
|
763 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
764 |
test(r==KErrNone); |
|
765 |
test(fileAtt.iAtt==KEntryAttArchive); |
|
766 |
f.Close(); |
|
767 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
768 |
test(r==KErrNone); |
|
769 |
test(fileAtt.iAtt==KEntryAttArchive); |
|
770 |
||
771 |
test.Next(_L("Archive att is set after setsize")); |
|
772 |
TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive); |
|
773 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
774 |
test(r==KErrNone); |
|
775 |
test(fileAtt.iAtt==0); |
|
776 |
r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite); |
|
777 |
test(r==KErrNone); |
|
778 |
r=f.SetSize(447); |
|
779 |
test(r==KErrNone); |
|
780 |
TInt size; |
|
781 |
r=f.Size(size); |
|
782 |
test(r==KErrNone); |
|
783 |
test(size==447); |
|
784 |
r=f.Att(atts); |
|
785 |
test(r==KErrNone); |
|
786 |
test((atts&ATT_MASK)==KEntryAttArchive); |
|
787 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
788 |
test(r==KErrNone); |
|
789 |
test(fileAtt.iAtt==KEntryAttArchive); |
|
790 |
f.Close(); |
|
791 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
792 |
test(r==KErrNone); |
|
793 |
test(fileAtt.iAtt==KEntryAttArchive); |
|
794 |
||
795 |
test.Next(_L("Archive att is not set after open")); |
|
796 |
r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive); |
|
797 |
test(r==KErrNone); |
|
798 |
r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite); |
|
799 |
test(r==KErrNone); |
|
800 |
r=f.Att(atts); |
|
801 |
test(r==KErrNone); |
|
802 |
test((atts&ATT_MASK)==0); |
|
803 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
804 |
test(r==KErrNone); |
|
805 |
test(fileAtt.iAtt==0); |
|
806 |
f.Close(); |
|
807 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
808 |
test(r==KErrNone); |
|
809 |
test(fileAtt.iAtt==0); |
|
810 |
||
811 |
test.Next(_L("Archive att is not set after a read")); |
|
812 |
TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive); |
|
813 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
814 |
test(r==KErrNone); |
|
815 |
test(fileAtt.iAtt==0); |
|
816 |
r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite); |
|
817 |
test(r==KErrNone); |
|
818 |
TBuf8<16> readBuf; |
|
819 |
r=f.Read(readBuf); |
|
820 |
test(r==KErrNone); |
|
821 |
r=f.Att(atts); |
|
822 |
test(r==KErrNone); |
|
823 |
test((atts&ATT_MASK)==0); |
|
824 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
825 |
test(r==KErrNone); |
|
826 |
test(fileAtt.iAtt==0); |
|
827 |
f.Close(); |
|
828 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
829 |
test(r==KErrNone); |
|
830 |
test(fileAtt.iAtt==0); |
|
831 |
||
832 |
test.Next(_L("Archive att is set after replace")); |
|
833 |
r=f.Replace(TheFs,_L("FILEATT.ARC"),EFileWrite); |
|
834 |
test(r==KErrNone); |
|
835 |
r=f.Att(atts); |
|
836 |
test(r==KErrNone); |
|
837 |
test((atts&ATT_MASK)==KEntryAttArchive); |
|
838 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
839 |
test(r==KErrNone); |
|
840 |
test(fileAtt.iAtt==KEntryAttArchive); |
|
841 |
f.Close(); |
|
842 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
843 |
test(r==KErrNone); |
|
844 |
test(fileAtt.iAtt==KEntryAttArchive); |
|
845 |
||
846 |
test.Next(_L("Read only bit can be unset")); |
|
847 |
r=TheFs.SetAtt(_L("FILEATT.ARC"),KEntryAttReadOnly|KEntryAttHidden,0); |
|
848 |
test(r==KErrNone); |
|
849 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
850 |
test(r==KErrNone); |
|
851 |
test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive)); |
|
852 |
||
853 |
r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttHidden); |
|
854 |
test(r==KErrNone); |
|
855 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
856 |
test(r==KErrNone); |
|
857 |
test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttArchive)); |
|
858 |
||
859 |
r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttReadOnly); |
|
860 |
test(r==KErrNone); |
|
861 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
862 |
test(r==KErrNone); |
|
863 |
test(fileAtt.iAtt==(KEntryAttArchive)); |
|
864 |
||
865 |
r=TheFs.SetAtt(_L("FILEATT.ARC"),KEntryAttReadOnly|KEntryAttHidden,0); |
|
866 |
test(r==KErrNone); |
|
867 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
868 |
test(r==KErrNone); |
|
869 |
test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive)); |
|
870 |
||
871 |
r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttReadOnly); |
|
872 |
test(r==KErrNone); |
|
873 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
874 |
test(r==KErrNone); |
|
875 |
test(fileAtt.iAtt==(KEntryAttHidden|KEntryAttArchive)); |
|
876 |
||
877 |
r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttHidden); |
|
878 |
test(r==KErrNone); |
|
879 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
880 |
test(r==KErrNone); |
|
881 |
test(fileAtt.iAtt==(KEntryAttArchive)); |
|
882 |
||
883 |
TTime time(0); |
|
884 |
r=TheFs.SetEntry(_L("FILEATT.ARC"),time,KEntryAttReadOnly|KEntryAttHidden,0); |
|
885 |
test(r==KErrNone); |
|
886 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
887 |
test(r==KErrNone); |
|
888 |
test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive)); |
|
889 |
||
890 |
r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttHidden); |
|
891 |
test(r==KErrNone); |
|
892 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
893 |
test(r==KErrNone); |
|
894 |
test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttArchive)); |
|
895 |
||
896 |
r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttReadOnly); |
|
897 |
test(r==KErrNone); |
|
898 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
899 |
test(r==KErrNone); |
|
900 |
test(fileAtt.iAtt==(KEntryAttArchive)); |
|
901 |
||
902 |
r=TheFs.SetEntry(_L("FILEATT.ARC"),time,KEntryAttReadOnly|KEntryAttHidden,0); |
|
903 |
test(r==KErrNone); |
|
904 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
905 |
test(r==KErrNone); |
|
906 |
test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive)); |
|
907 |
||
908 |
r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttReadOnly); |
|
909 |
test(r==KErrNone); |
|
910 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
911 |
test(r==KErrNone); |
|
912 |
test(fileAtt.iAtt==(KEntryAttHidden|KEntryAttArchive)); |
|
913 |
||
914 |
r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttHidden); |
|
915 |
test(r==KErrNone); |
|
916 |
r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); |
|
917 |
test(r==KErrNone); |
|
918 |
test(fileAtt.iAtt==(KEntryAttArchive)); |
|
919 |
||
920 |
test.Next(_L("Cashing the 'read-only' attribute")); |
|
921 |
const TDesC& fname = _L("TEST.RO"); |
|
922 |
||
923 |
// Test RO attribute after creating a file |
|
924 |
r=f.Create(TheFs,fname,EFileWrite); |
|
925 |
test(r==KErrNone); |
|
926 |
r=f.SetAtt(KEntryAttReadOnly,0); |
|
927 |
test(r==KErrNone); |
|
928 |
r=f.Write(_L8("Hello World")); |
|
929 |
test(r==KErrNone); // <-- here! |
|
930 |
f.Close(); |
|
931 |
||
932 |
// Test we can't open for write or delete a RO file |
|
933 |
r=f.Open(TheFs,fname,EFileWrite); |
|
934 |
test(r==KErrAccessDenied); |
|
935 |
r=TheFs.Delete(fname); |
|
936 |
test(r==KErrAccessDenied); |
|
937 |
||
938 |
// Tidy up and re-create test file |
|
939 |
r=TheFs.SetAtt(fname,0,KEntryAttReadOnly); |
|
940 |
test(r==KErrNone); |
|
941 |
r=TheFs.Delete(fname); |
|
942 |
test(r==KErrNone); |
|
943 |
r=f.Create(TheFs,fname,EFileWrite); |
|
944 |
test(r==KErrNone); |
|
945 |
f.Close(); |
|
946 |
||
947 |
// Test RO attribute after opening a file |
|
948 |
r=f.Open(TheFs,fname,EFileWrite); |
|
949 |
test(r==KErrNone); |
|
950 |
r=f.SetAtt(KEntryAttReadOnly,0); |
|
951 |
test(r==KErrNone); |
|
952 |
r=f.Write(_L8("Hello World")); |
|
953 |
test(r==KErrNone); |
|
954 |
f.Close(); |
|
955 |
||
956 |
// Tidy up |
|
957 |
r=TheFs.SetAtt(fname,0,KEntryAttReadOnly); |
|
958 |
test(r==KErrNone); |
|
959 |
r=TheFs.Delete(fname); |
|
960 |
test(r==KErrNone); |
|
961 |
} |
|
962 |
||
963 |
static void testShortNameAccessorFunctions() |
|
964 |
// |
|
965 |
// Test RFs::GetShortName(...) |
|
966 |
// |
|
967 |
{ |
|
968 |
test.Next(_L("Test short name accessor functions")); |
|
969 |
||
970 |
if(!gShortFileNamesSupported) |
|
971 |
{ |
|
972 |
test.Printf(_L("Short Names are not supported!. Skipping...")); |
|
973 |
return; |
|
974 |
} |
|
975 |
||
976 |
||
977 |
TBuf<64> sessionPath; |
|
978 |
TInt r=TheFs.SessionPath(sessionPath); |
|
979 |
test(r==KErrNone); |
|
980 |
RFile f; |
|
981 |
r=TheFs.MkDirAll(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\RANDOM.ENDBIT")); |
|
982 |
test(r==KErrNone || r==KErrAlreadyExists); |
|
983 |
r=f.Replace(TheFs,_L("LONGFILENAME.LONGEXT"),EFileWrite); |
|
984 |
test(r==KErrNone); |
|
985 |
f.Close(); |
|
986 |
r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFILENAME.LONGEXT"),EFileWrite); |
|
987 |
test(r==KErrNone); |
|
988 |
f.Close(); |
|
989 |
r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD CHAR"),EFileWrite); |
|
990 |
test(r==KErrNone); |
|
991 |
f.Close(); |
|
992 |
r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GoodCHAR.TXT"),EFileWrite); |
|
993 |
test(r==KErrNone); |
|
994 |
f.Close(); |
|
995 |
TBuf<12> shortName1; |
|
996 |
TBuf<12> shortName2; |
|
997 |
TBuf<12> shortName3; |
|
998 |
TBuf<12> shortName4; |
|
999 |
TBuf<12> shortName5; |
|
1000 |
r=TheFs.GetShortName(_L("LONGFILENAME.LONGEXT"),shortName1); |
|
1001 |
test(r==KErrNone); |
|
1002 |
r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFILENAME.LONGEXT"),shortName2); |
|
1003 |
test(r==KErrNone); |
|
1004 |
r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD CHAR"),shortName3); |
|
1005 |
test(r==KErrNone); |
|
1006 |
r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),shortName4); |
|
1007 |
test(r==KErrNone); |
|
1008 |
r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY"),shortName5); |
|
1009 |
test(r==KErrNone); |
|
1010 |
||
1011 |
if(Is_Win32(TheFs, gDriveNum)) |
|
1012 |
{ |
|
1013 |
test(shortName1==_L("LONGFI~1.LON")); |
|
1014 |
test(shortName2==_L("LONGFI~1.LON")); |
|
1015 |
test(shortName3==_L("BADCHA~1")); |
|
1016 |
test(shortName4.FindF(_L("GOODCHAR.TXT"))>=0); |
|
1017 |
test(shortName5==_L("MIDDLE~1")); |
|
1018 |
} |
|
1019 |
else if(!IsTestingLFFS()) |
|
1020 |
{ |
|
1021 |
// LFFS short names not the same as VFAT ones |
|
1022 |
test(shortName1==_L("LONGFI~1.LON")); |
|
1023 |
test(shortName2==_L("LONGFI~1.LON")); |
|
1024 |
test(shortName3==_L("BAD_CHAR")); |
|
1025 |
test(shortName4.FindF(_L("GOODCHAR.TXT"))>=0); |
|
1026 |
test(shortName5==_L("MIDDLE~1")); |
|
1027 |
} |
|
1028 |
||
1029 |
TFileName longName1; |
|
1030 |
TFileName longName2; |
|
1031 |
TFileName longName3; |
|
1032 |
TFileName longName4; |
|
1033 |
TFileName longName5; |
|
1034 |
||
1035 |
if (Is_Win32(TheFs, gDriveNum)) |
|
1036 |
{ |
|
1037 |
r=TheFs.GetLongName(_L("LONGFI~1.LON"),longName1); |
|
1038 |
test(r==KErrNone); |
|
1039 |
r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFI~1.LON"),longName2); |
|
1040 |
test(r==KErrNone); |
|
1041 |
r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BADCHA~1"),longName3); |
|
1042 |
test(r==KErrNone); |
|
1043 |
r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),longName4); |
|
1044 |
test(r==KErrNone); |
|
1045 |
r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE~1"),longName5); |
|
1046 |
test(r==KErrNone); |
|
1047 |
} |
|
1048 |
else if (!IsTestingLFFS()) |
|
1049 |
{ |
|
1050 |
r=TheFs.GetLongName(_L("LONGFI~1.LON"),longName1); |
|
1051 |
test(r==KErrNone); |
|
1052 |
r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFI~1.LON"),longName2); |
|
1053 |
test(r==KErrNone); |
|
1054 |
r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD_CHAR"),longName3); |
|
1055 |
test(r==KErrNone); |
|
1056 |
r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),longName4); |
|
1057 |
test(r==KErrNone); |
|
1058 |
r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE~1"),longName5); |
|
1059 |
test(r==KErrNone); |
|
1060 |
} |
|
1061 |
else |
|
1062 |
{ |
|
1063 |
// LFFS longname tests |
|
1064 |
r=TheFs.GetLongName(shortName1,longName1); |
|
1065 |
test(r==KErrNone); |
|
1066 |
r=TheFs.SetSessionPath(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\")); |
|
1067 |
test(r==KErrNone); |
|
1068 |
r=TheFs.GetLongName(shortName2,longName2); |
|
1069 |
test(r==KErrNone); |
|
1070 |
r=TheFs.GetLongName(shortName3,longName3); |
|
1071 |
test(r==KErrNone); |
|
1072 |
r=TheFs.GetLongName(shortName4,longName4); |
|
1073 |
test(r==KErrNone); |
|
1074 |
r=TheFs.SetSessionPath(_L("\\F32-TST\\TFILE\\TOPLEVEL\\")); |
|
1075 |
test(r==KErrNone); |
|
1076 |
r=TheFs.GetLongName(shortName5,longName5); |
|
1077 |
test(r==KErrNone); |
|
1078 |
r=TheFs.SetSessionPath(sessionPath); |
|
1079 |
test(r==KErrNone); |
|
1080 |
} |
|
1081 |
||
1082 |
test(longName1==_L("LONGFILENAME.LONGEXT")); |
|
1083 |
test(longName2==_L("LONGFILENAME.LONGEXT")); |
|
1084 |
test(longName3==_L("BAD CHAR")); |
|
1085 |
test(longName4.FindF(_L("GOODCHAR.TXT"))>=0); |
|
1086 |
test(longName5==_L("MIDDLE-DIRECTORY")); |
|
1087 |
||
1088 |
r=TheFs.GetShortName(_L("XXX.YYY"),shortName1); |
|
1089 |
test(r==KErrNotFound); |
|
1090 |
r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-YROTCERID\\LASTDIR\\BAD-CHAR"),shortName1); |
|
1091 |
test(r==KErrPathNotFound); |
|
1092 |
r=TheFs.GetLongName(_L("XXX.YYY"),longName1); |
|
1093 |
test(r==KErrNotFound); |
|
1094 |
r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-YROTCERID\\LASTDIR\\BAD-CHAR"),longName1); |
|
1095 |
test(r==KErrPathNotFound); |
|
1096 |
||
1097 |
r=TheFs.Delete(_L("LONGFILENAME.LONGEXT")); |
|
1098 |
test(r==KErrNone); |
|
1099 |
||
1100 |
TEntry romEntry; |
|
1101 |
r=TheFs.Entry(_L("Z:\\System"),romEntry); |
|
1102 |
if (r==KErrNotReady) |
|
1103 |
{ |
|
1104 |
test.Printf(_L("ERROR: No rom filesystem present")); |
|
1105 |
//test.Getch(); |
|
1106 |
//return; |
|
1107 |
} |
|
1108 |
test(r==KErrNone); |
|
1109 |
TBuf<64> romFileName=_L("Z:\\"); |
|
1110 |
romFileName.Append(romEntry.iName); |
|
1111 |
r=TheFs.GetShortName(romFileName,shortName1); |
|
1112 |
test(r==KErrNotSupported); |
|
1113 |
r=TheFs.GetLongName(_L("Z:\\system"),longName1); |
|
1114 |
test(r==KErrNotSupported); |
|
1115 |
} |
|
1116 |
||
1117 |
static void RmDir(const TDesC& aDirName) |
|
1118 |
// |
|
1119 |
// Remove a directory |
|
1120 |
// |
|
1121 |
{ |
|
1122 |
CFileMan* fMan=CFileMan::NewL(TheFs); |
|
1123 |
test(fMan!=NULL); |
|
1124 |
TInt r=TheFs.SessionPath(gSessionPath); |
|
1125 |
test(r==KErrNone); |
|
1126 |
r=TheFs.CheckDisk(gSessionPath); |
|
1127 |
if (r!=KErrNone && r!=KErrNotSupported) |
|
1128 |
ReportCheckDiskFailure(r); |
|
1129 |
||
1130 |
TFileName removeDirName = gSessionPath; |
|
1131 |
removeDirName.Append(aDirName); |
|
1132 |
||
1133 |
fMan->Attribs(removeDirName, 0, KEntryAttReadOnly, 0, CFileMan::ERecurse); |
|
1134 |
r=fMan->RmDir(removeDirName); |
|
1135 |
test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound); |
|
1136 |
||
1137 |
delete fMan; |
|
1138 |
} |
|
1139 |
//--------------------------------------------- |
|
1140 |
//! @SYMTestCaseID PBASE-T_TFILE-0659 |
|
1141 |
//! @SYMTestType CT |
|
1142 |
//! @SYMREQ INC112803 |
|
1143 |
//! @SYMTestCaseDesc Tests that RFs::GetShortName() considers the file extension while generating |
|
1144 |
//! shortname from longname and applies ~num if applicable. |
|
1145 |
//! @SYMTestActions 1. Generates the shortname for the given filename. |
|
1146 |
//! 2. Validates the generated shortname against the original filename. |
|
1147 |
//! @SYMTestExpectedResults The operation completes with no error. Valid shortname is generated. |
|
1148 |
//! @SYMTestPriority High |
|
1149 |
//! @SYMTestStatus Implemented |
|
1150 |
//--------------------------------------------- |
|
1151 |
static void TestINC112803() |
|
1152 |
{ |
|
1153 |
||
1154 |
if(!gShortFileNamesSupported) |
|
1155 |
{ |
|
1156 |
test.Printf(_L("TestINC112803 : Short names are not supported!\n")); |
|
1157 |
return; |
|
1158 |
} |
|
1159 |
||
1160 |
||
1161 |
TInt err =0; |
|
1162 |
_LIT(KOrigFileName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222.JARX"); |
|
1163 |
_LIT(KOrigFileShortName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222~1.JAR"); |
|
1164 |
_LIT(KDestinationFileName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222.JAR"); |
|
1165 |
||
1166 |
// Make sure the file does not already exist |
|
1167 |
RmDir(_L("INC112803\\")); |
|
1168 |
||
1169 |
// Create directories and the file |
|
1170 |
MakeDir(_L("\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\")); |
|
1171 |
MakeFile(KOrigFileName,_L8("FILE PATH : \\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\")); |
|
1172 |
||
1173 |
// Check the generated shortname of the original file |
|
1174 |
TBuf<12> shortName; |
|
1175 |
err = TheFs.GetShortName(KOrigFileName, shortName); |
|
1176 |
test(err==KErrNone); |
|
1177 |
||
1178 |
// Validate the generated shorname against the original filename. |
|
1179 |
if (Is_Win32(TheFs, gDriveNum)) |
|
1180 |
{ |
|
1181 |
test(shortName==_L("2222~1.JAR")); |
|
1182 |
} |
|
1183 |
else if(!IsTestingLFFS()) |
|
1184 |
{ |
|
1185 |
// LFFS short names not the same as VFAT ones |
|
1186 |
test(shortName==_L("2222~1.JAR")); |
|
1187 |
} |
|
1188 |
||
1189 |
// Validate that the file "2222~1.JAR" can not be created as this is the shortname for "2222.JARX". |
|
1190 |
MakeFile(KOrigFileShortName,_L8("FILE PATH : \\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\")); |
|
1191 |
CheckFileExists(KOrigFileShortName, KErrNone, EFalse); |
|
1192 |
||
1193 |
err = TheFs.Rename(KOrigFileName,KDestinationFileName); |
|
1194 |
test(err==KErrNone); |
|
1195 |
||
1196 |
// Clean up before leaving |
|
1197 |
RmDir(_L("INC112803\\")); |
|
1198 |
} |
|
1199 |
||
1200 |
static void testIsFileOpen() |
|
1201 |
// |
|
1202 |
// Test the IsFileOpen method |
|
1203 |
// |
|
1204 |
{ |
|
1205 |
||
1206 |
test.Next(_L("Test IsFileOpen")); |
|
1207 |
TBool answer; |
|
1208 |
TInt r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); |
|
1209 |
test(r==KErrNotFound || (r==KErrNone && answer==EFalse)); |
|
1210 |
RFile f; |
|
1211 |
r=f.Replace(TheFs,_L("OPEN.FILE"),EFileWrite); |
|
1212 |
test(r==KErrNone); |
|
1213 |
r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); |
|
1214 |
test(r==KErrNone); |
|
1215 |
test(answer!=EFalse); |
|
1216 |
f.Close(); |
|
1217 |
r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); |
|
1218 |
test(r==KErrNone); |
|
1219 |
test(answer==EFalse); |
|
1220 |
r=TheFs.Delete(_L("OPEN.FILE")); |
|
1221 |
test(r==KErrNone); |
|
1222 |
||
1223 |
RFile f2; |
|
1224 |
r=f2.Replace(TheFs,_L("AnotherOpen.File"),EFileWrite); |
|
1225 |
test(r==KErrNone); |
|
1226 |
r=TheFs.IsFileOpen(_L("AnotherOpen.File"),answer); |
|
1227 |
test(r==KErrNone); |
|
1228 |
test(answer!=EFalse); |
|
1229 |
r=f.Replace(TheFs,_L("OPEN.FILE"),EFileWrite); |
|
1230 |
test(r==KErrNone); |
|
1231 |
r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); |
|
1232 |
test(r==KErrNone); |
|
1233 |
test(answer!=EFalse); |
|
1234 |
f2.Close(); |
|
1235 |
r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); |
|
1236 |
test(r==KErrNone); |
|
1237 |
test(answer!=EFalse); |
|
1238 |
f.Close(); |
|
1239 |
r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); |
|
1240 |
test(r==KErrNone); |
|
1241 |
test(answer==EFalse); |
|
1242 |
r=TheFs.Delete(_L("AnotherOpen.File")); |
|
1243 |
test(r==KErrNone); |
|
1244 |
r=TheFs.Delete(_L("OPEN.FILE")); |
|
1245 |
test(r==KErrNone); |
|
1246 |
} |
|
1247 |
||
1248 |
static void testDeleteOpenFiles() |
|
1249 |
// |
|
1250 |
// Test opened files cannot be deleted |
|
1251 |
// |
|
1252 |
{ |
|
1253 |
||
1254 |
test.Next(_L("Test opened files cannot be deleted")); |
|
1255 |
RFile f; |
|
1256 |
f.Close(); |
|
1257 |
TInt r=f.Replace(TheFs,_L("Open.File"),EFileWrite); |
|
1258 |
test(r==KErrNone); |
|
1259 |
r=TheFs.Delete(_L("OPEN.FILE")); |
|
1260 |
test(r==KErrInUse); |
|
1261 |
f.Close(); |
|
1262 |
f.Close(); |
|
1263 |
f.Close(); |
|
1264 |
r=TheFs.Delete(_L("Open.FILe")); |
|
1265 |
test(r==KErrNone); |
|
1266 |
||
1267 |
TFileName fileName; |
|
1268 |
r=f.Temp(TheFs,_L(""),fileName,EFileWrite); |
|
1269 |
test(r==KErrNone); |
|
1270 |
r=TheFs.Delete(fileName); |
|
1271 |
test(r==KErrInUse); |
|
1272 |
f.Close(); |
|
1273 |
r=TheFs.Delete(fileName); |
|
1274 |
test(r==KErrNone); |
|
1275 |
||
1276 |
MakeFile(_L("\\Documents\\TEstfile.txt")); |
|
1277 |
r=f.Open(TheFs,_L("\\Documents\\TEstfile.txt"),EFileWrite); |
|
1278 |
test(r==KErrNone); |
|
1279 |
r=TheFs.Delete(_L("\\Documents\\TEstfile.txt")); |
|
1280 |
test(r==KErrInUse); |
|
1281 |
r=TheFs.Delete(_L("\\documents\\TEstfile.txt")); |
|
1282 |
test(r==KErrInUse); |
|
1283 |
r=TheFs.Delete(_L("\\Documents.\\TEstfile.txt")); |
|
1284 |
test(r==KErrBadName); |
|
1285 |
r=TheFs.Delete(_L("\\documents.\\TEstfile.txt")); |
|
1286 |
test(r==KErrBadName); |
|
1287 |
r=TheFs.Delete(_L("\\Documents\\Testfile.txt")); |
|
1288 |
test(r==KErrInUse); |
|
1289 |
r=TheFs.Delete(_L("\\documents\\testfile.txt")); |
|
1290 |
test(r==KErrInUse); |
|
1291 |
r=TheFs.Delete(_L("\\Documents.\\TEstfile.TXT")); |
|
1292 |
test(r==KErrBadName); |
|
1293 |
r=TheFs.Delete(_L("\\docUMENTS.\\TESTFILE.TXT")); |
|
1294 |
test(r==KErrBadName); |
|
1295 |
f.Close(); |
|
1296 |
r=TheFs.Delete(_L("\\Documents\\TEstfile.TXT")); |
|
1297 |
test(r==KErrNone); |
|
1298 |
||
1299 |
MakeFile(_L("\\Documents\\Documents\\TEstfile.txt")); |
|
1300 |
r=f.Open(TheFs,_L("\\Documents\\Documents\\TEstfile.txt"),EFileWrite); |
|
1301 |
test(r==KErrNone); |
|
1302 |
r=TheFs.Delete(_L("\\Documents\\documents.\\TEstfile.txt")); |
|
1303 |
test(r==KErrBadName); |
|
1304 |
r=TheFs.Delete(_L("\\documents\\Documents.\\TEstfile.txt")); |
|
1305 |
test(r==KErrBadName); |
|
1306 |
r=TheFs.Delete(_L("\\Documents.\\documents\\TEstfile.txt")); |
|
1307 |
test(r==KErrBadName); |
|
1308 |
r=TheFs.Delete(_L("\\documents.\\Documents\\TEstfile.txt")); |
|
1309 |
test(r==KErrBadName); |
|
1310 |
r=TheFs.Delete(_L("\\Documents\\Documents\\Testfile.txt")); |
|
1311 |
test(r==KErrInUse); |
|
1312 |
r=TheFs.Delete(_L("\\documents\\documents\\testfile.txt")); |
|
1313 |
test(r==KErrInUse); |
|
1314 |
r=TheFs.Delete(_L("\\Documents.\\Documents.\\TEstfile.TXT")); |
|
1315 |
test(r==KErrBadName); |
|
1316 |
r=TheFs.Delete(_L("\\docUMENTS.\\docUMENTS.\\TESTFILE.TXT")); |
|
1317 |
test(r==KErrBadName); |
|
1318 |
||
1319 |
||
1320 |
r=TheFs.RmDir(_L("\\Documents\\")); |
|
1321 |
test(r==KErrInUse); |
|
1322 |
r=TheFs.RmDir(_L("\\documents\\")); |
|
1323 |
test(r==KErrInUse); |
|
1324 |
r=TheFs.RmDir(_L("\\Documents.\\")); |
|
1325 |
test(r==KErrBadName); |
|
1326 |
r=TheFs.RmDir(_L("\\documents.\\")); |
|
1327 |
test(r==KErrBadName); |
|
1328 |
r=TheFs.RmDir(_L("\\Documents\\documents\\")); |
|
1329 |
test(r==KErrInUse); |
|
1330 |
r=TheFs.RmDir(_L("\\documents\\documents.\\")); |
|
1331 |
test(r==KErrBadName); |
|
1332 |
r=TheFs.RmDir(_L("\\Documents.\\Documents\\")); |
|
1333 |
test(r==KErrBadName); |
|
1334 |
r=TheFs.RmDir(_L("\\documents.\\Documents.\\")); |
|
1335 |
test(r==KErrBadName); |
|
1336 |
r=TheFs.RmDir(_L("\\Documents\\TestFile.TXT")); |
|
1337 |
test(r==KErrInUse); |
|
1338 |
r=TheFs.RmDir(_L("\\documents\\TestFile")); |
|
1339 |
test(r==KErrInUse); |
|
1340 |
r=TheFs.RmDir(_L("\\Documents.\\Testfile.")); |
|
1341 |
test(r==KErrBadName); |
|
1342 |
r=TheFs.RmDir(_L("\\documents.\\t")); |
|
1343 |
test(r==KErrBadName); |
|
1344 |
f.Close(); |
|
1345 |
r=TheFs.Delete(_L("\\Documents\\documents\\TEstfile.TXT")); |
|
1346 |
test(r==KErrNone); |
|
1347 |
r=TheFs.RmDir(_L("\\Documents\\documents.\\")); |
|
1348 |
test(r==KErrBadName); |
|
1349 |
r=TheFs.RmDir(_L("\\Documents.\\")); |
|
1350 |
test(r==KErrBadName); |
|
1351 |
} |
|
1352 |
||
1353 |
static void testFileSeek() |
|
1354 |
// |
|
1355 |
// Test seeking |
|
1356 |
// |
|
1357 |
{ |
|
1358 |
test.Next(_L("Test file seek")); |
|
1359 |
RFile f; |
|
1360 |
TInt r=f.Open(TheFs,_L("T_File.cpp"),EFileWrite); |
|
1361 |
test(r==KErrNone); |
|
1362 |
||
1363 |
TBuf8<20> text1;TInt pos1=0; |
|
1364 |
TBuf8<20> text2;TInt pos2=510; |
|
1365 |
TBuf8<20> text3;TInt pos3=900; |
|
1366 |
TBuf8<20> text4;TInt pos4=2010; |
|
1367 |
TBuf8<20> text5;TInt pos5=4999; |
|
1368 |
||
1369 |
r=f.Read(pos1,text1); |
|
1370 |
test(r==KErrNone); |
|
1371 |
r=f.Read(pos2,text2); |
|
1372 |
test(r==KErrNone); |
|
1373 |
r=f.Read(pos3,text3); |
|
1374 |
test(r==KErrNone); |
|
1375 |
r=f.Read(pos4,text4); |
|
1376 |
test(r==KErrNone); |
|
1377 |
r=f.Read(pos5,text5); |
|
1378 |
test(r==KErrNone); |
|
1379 |
||
1380 |
TBuf8<20> testBuf; |
|
1381 |
||
1382 |
r=f.Read(pos3,testBuf); |
|
1383 |
test(r==KErrNone); |
|
1384 |
test(testBuf==text3); |
|
1385 |
||
1386 |
r=f.Read(pos1,testBuf); |
|
1387 |
test(r==KErrNone); |
|
1388 |
test(testBuf==text1); |
|
1389 |
||
1390 |
r=f.Read(pos4,testBuf); |
|
1391 |
test(r==KErrNone); |
|
1392 |
test(testBuf==text4); |
|
1393 |
||
1394 |
r=f.Read(pos2,testBuf); |
|
1395 |
test(r==KErrNone); |
|
1396 |
test(testBuf==text2); |
|
1397 |
||
1398 |
r=f.Read(pos5,testBuf); |
|
1399 |
test(r==KErrNone); |
|
1400 |
test(testBuf==text5); |
|
1401 |
||
1402 |
r=f.Read(pos2,testBuf); |
|
1403 |
test(r==KErrNone); |
|
1404 |
test(testBuf==text2); |
|
1405 |
r=f.SetSize(1023); |
|
1406 |
test(r==KErrNone); |
|
1407 |
r=f.Read(pos2,testBuf); |
|
1408 |
test(r==KErrNone); |
|
1409 |
test(testBuf==text2); |
|
1410 |
r=f.SetSize(1024); |
|
1411 |
test(r==KErrNone); |
|
1412 |
r=f.Read(pos1,testBuf); |
|
1413 |
test(r==KErrNone); |
|
1414 |
test(testBuf==text1); |
|
1415 |
r=f.Read(pos2,testBuf); |
|
1416 |
test(r==KErrNone); |
|
1417 |
test(testBuf==text2); |
|
1418 |
||
1419 |
r=f.Read(pos1,testBuf); |
|
1420 |
test(r==KErrNone); |
|
1421 |
test(testBuf==text1); |
|
1422 |
r=f.SetSize(511); |
|
1423 |
test(r==KErrNone); |
|
1424 |
r=f.Read(pos1,testBuf); |
|
1425 |
test(r==KErrNone); |
|
1426 |
test(testBuf==text1); |
|
1427 |
r=f.SetSize(512); |
|
1428 |
test(r==KErrNone); |
|
1429 |
r=f.Read(pos1,testBuf); |
|
1430 |
test(r==KErrNone); |
|
1431 |
test(testBuf==text1); |
|
1432 |
f.Close(); |
|
1433 |
} |
|
1434 |
||
1435 |
static void testMoreFileSeek() |
|
1436 |
// |
|
1437 |
// Further test of RFile::Seek() |
|
1438 |
// |
|
1439 |
{ |
|
1440 |
// Create a zero length file |
|
1441 |
RFile file; |
|
1442 |
TInt r=file.Replace(TheFs,_L("\\F32-TST\\TFILE\\seektest"),EFileRead|EFileWrite); |
|
1443 |
test(r==KErrNone); |
|
1444 |
r=file.SetSize(20); |
|
1445 |
test(r==KErrNone); |
|
1446 |
// Seek beyond the length of the file |
|
1447 |
TInt seekPos; |
|
1448 |
seekPos = 80; // Pick a likely offset |
|
1449 |
TInt err = file.Seek(ESeekEnd, seekPos); // and go there |
|
1450 |
test(err==KErrNone); |
|
1451 |
test(seekPos==20); // Somewhat non-intuitive? |
|
1452 |
||
1453 |
r=file.Write(_L8("A Devil's Haircut")); |
|
1454 |
test(r==KErrNone); |
|
1455 |
TInt newFileSize; |
|
1456 |
r=file.Size(newFileSize); |
|
1457 |
test(r==KErrNone); |
|
1458 |
||
1459 |
seekPos = 0; |
|
1460 |
err = file.Seek(ESeekCurrent, seekPos); // Find out where we ended up? |
|
1461 |
test(err==KErrNone); |
|
1462 |
test(seekPos==37); |
|
1463 |
||
1464 |
file.SetSize(512); |
|
1465 |
seekPos=513; |
|
1466 |
err=file.Seek(ESeekStart, seekPos); |
|
1467 |
test(err==KErrNone); |
|
1468 |
test(seekPos==513); |
|
1469 |
||
1470 |
err=file.Seek(ESeekEnd, seekPos); |
|
1471 |
test(err==KErrNone); |
|
1472 |
test(seekPos==512); |
|
1473 |
||
1474 |
seekPos=-530; |
|
1475 |
err=file.Seek(ESeekEnd, seekPos); |
|
1476 |
test(err==KErrNone); |
|
1477 |
test(seekPos==0); |
|
1478 |
||
1479 |
seekPos=-10; |
|
1480 |
err=file.Seek(ESeekEnd, seekPos); |
|
1481 |
test(err==KErrNone); |
|
1482 |
test(seekPos==502); |
|
1483 |
||
1484 |
seekPos=-10; |
|
1485 |
err=file.Seek(ESeekStart,seekPos); |
|
1486 |
test(err==KErrArgument); |
|
1487 |
test(seekPos==-10); |
|
1488 |
||
1489 |
seekPos=0; |
|
1490 |
err=file.Seek(ESeekEnd,seekPos); |
|
1491 |
test(err==KErrNone); |
|
1492 |
test(seekPos==512); |
|
1493 |
||
1494 |
file.Close(); |
|
1495 |
r=TheFs.Delete(_L("\\F32-TST\\TFILE\\seektest")); |
|
1496 |
test(r==KErrNone); |
|
1497 |
} |
|
1498 |
||
1499 |
static void testSetSize() |
|
1500 |
// |
|
1501 |
// Test setsize |
|
1502 |
// |
|
1503 |
{ |
|
1504 |
||
1505 |
test.Next(_L("Test SetSize")); |
|
1506 |
RFile f1; |
|
1507 |
TInt i=0; |
|
1508 |
TInt r=f1.Replace(TheFs,_L("File.File"),EFileWrite); |
|
1509 |
test(r==KErrNone); |
|
1510 |
gBuf.SetLength(32); |
|
1511 |
for(i=0;i<32;i++) |
|
1512 |
gBuf[i]=(TUint8)i; |
|
1513 |
r=f1.Write(gBuf); |
|
1514 |
test(r==KErrNone); |
|
1515 |
gBuf.SetLength(1334); |
|
1516 |
for(i=64;i<1334+64;i++) |
|
1517 |
gBuf[i-64]=(TUint8)i; |
|
1518 |
r=f1.Write(30,gBuf); |
|
1519 |
r=f1.Read(30,gBuf,1000); |
|
1520 |
test(r==KErrNone); |
|
1521 |
test(gBuf[0]==64); |
|
1522 |
test(gBuf[1]==65); |
|
1523 |
test(gBuf[2]==66); |
|
1524 |
f1.Close(); |
|
1525 |
||
1526 |
test.Next(_L("Open a large file")); |
|
1527 |
r=f1.Replace(TheFs,_L("File.File"),EFileWrite); |
|
1528 |
test(r==KErrNone); |
|
1529 |
CheckDisk(); |
|
1530 |
r=f1.SetSize(131072); // 128K |
|
1531 |
test(r==KErrNone); |
|
1532 |
TBuf8<16> testData=_L8("testData"); |
|
1533 |
r=f1.Write(131060,testData); |
|
1534 |
test(r==KErrNone); |
|
1535 |
f1.Close(); |
|
1536 |
r=f1.Open(TheFs,_L("File.File"),EFileRead); |
|
1537 |
test(r==KErrNone); |
|
1538 |
TInt size; |
|
1539 |
r=f1.Size(size); |
|
1540 |
test(r==KErrNone); |
|
1541 |
test(size==131072); |
|
1542 |
TBuf8<16> testData2; |
|
1543 |
r=f1.Read(131060,testData2,8); |
|
1544 |
test(r==KErrNone); |
|
1545 |
test(testData==testData2); |
|
1546 |
f1.Close(); |
|
1547 |
TheFs.Delete(_L("File.file")); |
|
1548 |
CheckDisk(); |
|
1549 |
} |
|
1550 |
||
1551 |
static void testIsRomAddress() |
|
1552 |
{ |
|
1553 |
RFile f; |
|
1554 |
TInt r=f.Open(TheFs, PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\eshell.exe"):_L("Z:\\System\\Bin\\eshell.exe"), EFileRead); |
|
1555 |
test(r==KErrNone); |
|
1556 |
TInt anAddress=0; |
|
1557 |
r=f.Seek(ESeekAddress, anAddress); |
|
1558 |
test(r==KErrNone); |
|
1559 |
#if !defined(__WINS__) |
|
1560 |
test(RFs::IsRomAddress((TAny *)anAddress)); // Always returns EFalse if WINS |
|
1561 |
#endif |
|
1562 |
test(RFs::IsRomAddress(NULL)==FALSE); |
|
1563 |
f.Close(); |
|
1564 |
} |
|
1565 |
||
1566 |
#include "../../../userlibandfileserver/fileserver/inc/message.h" |
|
1567 |
#include <f32plugin.h> |
|
1568 |
||
1569 |
static void testMiscellaneousReportedBugs() |
|
1570 |
// |
|
1571 |
// Test bug reports, real or imaginary |
|
1572 |
// |
|
1573 |
{ |
|
1574 |
||
1575 |
test.Next(_L("Miscellaneous tests")); |
|
1576 |
RFile f1; |
|
1577 |
TInt temp; |
|
1578 |
TInt r=f1.Replace(TheFs,_L("File.File"),EFileWrite); |
|
1579 |
test(r==KErrNone); |
|
1580 |
r=f1.Size(temp); |
|
1581 |
test(r==KErrNone); |
|
1582 |
test(temp==0); |
|
1583 |
TUint data=0; |
|
1584 |
TPtrC8 buf((TText8*)&data,1); |
|
1585 |
r=f1.Write(buf); |
|
1586 |
// r=f1.Write(_L("\0")); |
|
1587 |
test(r==KErrNone); |
|
1588 |
r=f1.Size(temp); |
|
1589 |
test(r==KErrNone); |
|
1590 |
test(temp==1); |
|
1591 |
temp=0; |
|
1592 |
r=f1.Seek(ESeekStart,temp); |
|
1593 |
test(r==KErrNone); |
|
1594 |
test(temp==0); |
|
1595 |
TBuf8<32> testBuf; |
|
1596 |
r=f1.Read(testBuf); |
|
1597 |
test(r==KErrNone); |
|
1598 |
test(testBuf==buf); |
|
1599 |
f1.Close(); |
|
1600 |
||
1601 |
class RHackFile : public RFile |
|
1602 |
{ |
|
1603 |
public: |
|
1604 |
inline TInt SendReceive(TInt aFunction, const TIpcArgs& aArgs) const |
|
1605 |
{ return RSubSessionBase::SendReceive(aFunction, aArgs); } |
|
1606 |
}; |
|
1607 |
||
1608 |
RHackFile f2; |
|
1609 |
f2.Open(TheFs, _L("File.File"), EFileRead); |
|
1610 |
test(r == KErrNone); |
|
1611 |
r = f2.SendReceive(/*47*/ EFsFileChangeMode, TIpcArgs(EFileRead | EFileWrite)); // <- must fail! |
|
1612 |
test(r == KErrArgument); |
|
1613 |
r = f2.Write(_L8("Hacked!")); // <- must fail! |
|
1614 |
test(r == KErrAccessDenied); |
|
1615 |
f2.Close(); |
|
1616 |
||
1617 |
r=TheFs.Delete(_L("File.FIle")); |
|
1618 |
test(r==KErrNone); |
|
1619 |
} |
|
1620 |
||
1621 |
static void testFileRename() |
|
1622 |
// |
|
1623 |
// Test rename |
|
1624 |
// |
|
1625 |
{ |
|
1626 |
||
1627 |
test.Next(_L("Test rename")); |
|
1628 |
TBuf<64> name1=_L("asdfasdfasdfasfd.qwer"); |
|
1629 |
TBuf<64> name2=_L("File.xyz"); |
|
1630 |
TBuf<64> name3=_L("ASdfasdFasdfasfd.qwer"); |
|
1631 |
TBuf8<64> contents; |
|
1632 |
||
1633 |
TInt r; |
|
1634 |
RFile f1; |
|
1635 |
||
1636 |
//-- test renaming a file to a non-existing directory |
|
1637 |
r = TheFs.MkDir(_L("\\temp\\")); |
|
1638 |
test(r==KErrNone || r==KErrAlreadyExists); |
|
1639 |
||
1640 |
r = f1.Replace(TheFs, _L("\\temp\\file1"), 0); |
|
1641 |
test(r==KErrNone); |
|
1642 |
||
1643 |
r = f1.Rename(_L("\\temp\\temp\\file1")); |
|
1644 |
test(r == KErrPathNotFound); |
|
1645 |
||
1646 |
f1.Close(); |
|
1647 |
||
1648 |
||
1649 |
r=f1.Replace(TheFs,name2,EFileWrite); |
|
1650 |
test(r==KErrNone); |
|
1651 |
r=f1.Write(_L8("1234")); |
|
1652 |
test(r==KErrNone); |
|
1653 |
TInt len=CheckFileExists(name2,KErrNone); |
|
1654 |
test(len==4); |
|
1655 |
r=f1.Rename(name1); |
|
1656 |
test(r==KErrNone); |
|
1657 |
||
1658 |
r=f1.Read(0,contents); |
|
1659 |
test(r==KErrNone); |
|
1660 |
test(contents==_L8("1234")); |
|
1661 |
r=f1.Write(4,_L8("5678")); |
|
1662 |
test(r==KErrNone); |
|
1663 |
||
1664 |
len=CheckFileExists(name1,KErrNone); |
|
1665 |
test(len==8); |
|
1666 |
CheckFileExists(name2,KErrNotFound); |
|
1667 |
r=f1.Write(8,_L8("90")); |
|
1668 |
test(r==KErrNone); |
|
1669 |
f1.Close(); |
|
1670 |
len=CheckFileExists(name1,KErrNone); |
|
1671 |
test(len==10); |
|
1672 |
||
1673 |
test.Next(_L("Test can change case using rename")); |
|
1674 |
r=f1.Open(TheFs,name1,EFileRead|EFileWrite); |
|
1675 |
test(r==KErrNone); |
|
1676 |
r=f1.Rename(name3); |
|
1677 |
test(r==KErrNone); |
|
1678 |
CheckFileExists(name1,KErrNone,EFalse); |
|
1679 |
len=CheckFileExists(name3,KErrNone); |
|
1680 |
test(len==10); |
|
1681 |
f1.Close(); |
|
1682 |
CheckFileExists(name1,KErrNone,EFalse); |
|
1683 |
len=CheckFileExists(name3,KErrNone); |
|
1684 |
test(len==10); |
|
1685 |
||
1686 |
test.Next(_L("Test can rename to an identical filename")); |
|
1687 |
r=f1.Open(TheFs,name3,EFileRead|EFileWrite); |
|
1688 |
test(r==KErrNone); |
|
1689 |
r=f1.Rename(name3); |
|
1690 |
test(r==KErrNone); |
|
1691 |
len=CheckFileExists(name3,KErrNone); |
|
1692 |
test(len==10); |
|
1693 |
f1.Close(); |
|
1694 |
len=CheckFileExists(name3,KErrNone); |
|
1695 |
test(len==10); |
|
1696 |
||
1697 |
test.Next(_L("Test rename to a name containing a wildcard is rejected")); |
|
1698 |
r=f1.Open(TheFs,name3,EFileRead|EFileWrite); |
|
1699 |
test(r==KErrNone); |
|
1700 |
r=f1.Rename(_L("asdf*ASDF")); |
|
1701 |
test(r==KErrBadName); |
|
1702 |
r=f1.Rename(_L("asdf?AF")); |
|
1703 |
test(r==KErrBadName); |
|
1704 |
f1.Close(); |
|
1705 |
||
1706 |
r=f1.Open(TheFs,name3,EFileRead); |
|
1707 |
test(r==KErrNone); |
|
1708 |
r=f1.Read(contents); |
|
1709 |
test(r==KErrNone); |
|
1710 |
test(contents==_L8("1234567890")); |
|
1711 |
r=f1.Read(contents); |
|
1712 |
test(r==KErrNone); |
|
1713 |
test(contents.Length()==0); |
|
1714 |
f1.Close(); |
|
1715 |
||
1716 |
test.Next(_L("Check file date is retained")); |
|
1717 |
TDateTime dateTime(1995,(TMonth)10,19,23,0,0,0); |
|
1718 |
TTime oldTime(dateTime); |
|
1719 |
r=TheFs.SetEntry(name3,oldTime,0,0); |
|
1720 |
test(r==KErrNone); |
|
1721 |
r=f1.Open(TheFs,name3,EFileRead|EFileWrite); |
|
1722 |
test(r==KErrNone); |
|
1723 |
TTime check; |
|
1724 |
r=f1.Modified(check); |
|
1725 |
test(r==KErrNone); |
|
1726 |
test(check==oldTime); |
|
1727 |
||
1728 |
r=f1.Rename(_L("OldFile.Old")); |
|
1729 |
test(r==KErrNone); |
|
1730 |
||
1731 |
r=f1.Modified(check); |
|
1732 |
test(r==KErrNone); |
|
1733 |
test(check==oldTime); |
|
1734 |
r=TheFs.Modified(_L("oldfile.old"),check); |
|
1735 |
test(r==KErrNone); |
|
1736 |
test(check==oldTime); |
|
1737 |
f1.Close(); |
|
1738 |
r=TheFs.Modified(_L("oldfile.old"),check); |
|
1739 |
test(r==KErrNone); |
|
1740 |
test(check==oldTime); |
|
1741 |
} |
|
1742 |
||
1743 |
static void TestFileUids() |
|
1744 |
// |
|
1745 |
// Test uids in files |
|
1746 |
// |
|
1747 |
{ |
|
1748 |
||
1749 |
test.Next(_L("Uids in files")); |
|
1750 |
TUidType uidData(TUid::Uid(1),TUid::Uid(1),TUid::Uid(1)); |
|
1751 |
MakeFile(_L("Tmp04005.$$$"),uidData,_L8("Some other data")); |
|
1752 |
TUidType uidData1(TUid::Uid(2),TUid::Uid(2),TUid::Uid(2)); |
|
1753 |
MakeFile(_L("Sketch(01)"),uidData1,_L8("A different sketch")); |
|
1754 |
||
1755 |
TEntry e; |
|
1756 |
TInt r=TheFs.Entry(_L("Tmp04005.$$$"),e); |
|
1757 |
test(r==KErrNone); |
|
1758 |
test(uidData==e.iType); |
|
1759 |
r=TheFs.Entry(_L("Sketch(01)"),e); |
|
1760 |
test(r==KErrNone); |
|
1761 |
test(uidData1==e.iType); |
|
1762 |
||
1763 |
test.Next(_L("Test replace preserves UIDs")); |
|
1764 |
r=TheFs.Replace(_L("Tmp04005.$$$"),_L("Sketch(01)")); |
|
1765 |
test(r==KErrNone); |
|
1766 |
||
1767 |
r=TheFs.Entry(_L("Tmp04005.$$$"),e); |
|
1768 |
test(r==KErrNotFound); |
|
1769 |
r=TheFs.Entry(_L("Sketch(01)"),e); |
|
1770 |
test(r==KErrNone); |
|
1771 |
test(uidData==e.iType); |
|
1772 |
} |
|
1773 |
||
1774 |
||
1775 |
static void TestMaxLengthFilenames() |
|
1776 |
// |
|
1777 |
// Test max length filenames can be created/deleted |
|
1778 |
// |
|
1779 |
{ |
|
1780 |
||
1781 |
#if defined(__WINS__) |
|
1782 |
if (gSessionPath[0]=='C') |
|
1783 |
return; |
|
1784 |
#endif |
|
1785 |
||
1786 |
test.Next(_L("Test max length filenames")); |
|
1787 |
TFileName bigName; |
|
1788 |
CreateLongName(bigName,gSeed,255); |
|
1789 |
bigName[0]='\\'; |
|
1790 |
RFile f; |
|
1791 |
TInt r=f.Create(TheFs,bigName,EFileRead); |
|
1792 |
test(r==KErrBadName); |
|
1793 |
bigName.SetLength(254); |
|
1794 |
r=f.Create(TheFs,bigName,EFileRead); |
|
1795 |
test(r==KErrNone); |
|
1796 |
f.Close(); |
|
1797 |
||
1798 |
TInt count; |
|
1799 |
TFileName countedBigName=bigName; |
|
1800 |
// This loop may not reach the '\' character, or we will get a bad path. |
|
1801 |
for (count=0;count<('Z'-'A');count++) |
|
1802 |
{ |
|
1803 |
countedBigName[2]=(TText)('A'+count); |
|
1804 |
r=f.Create(TheFs,countedBigName,EFileRead); |
|
1805 |
if (r==KErrDirFull) |
|
1806 |
{ |
|
1807 |
r=TheFs.Delete(countedBigName); |
|
1808 |
test(r==KErrNotFound); |
|
1809 |
break; |
|
1810 |
} |
|
1811 |
if (r!=KErrNone) |
|
1812 |
test.Printf(_L("File create failed:%d"),r); |
|
1813 |
test(r==KErrNone); |
|
1814 |
f.Close(); |
|
1815 |
} |
|
1816 |
while(count--) |
|
1817 |
{ |
|
1818 |
countedBigName[2]=(TText)('A'+count); |
|
1819 |
r=TheFs.Delete(countedBigName); |
|
1820 |
test(r==KErrNone); |
|
1821 |
} |
|
1822 |
||
1823 |
r=TheFs.Delete(bigName); |
|
1824 |
test(r==KErrNone); |
|
1825 |
||
1826 |
TFileName subDirFileName=_L("\\F32-TST\\TFILE"); |
|
1827 |
bigName.SetLength(241); |
|
1828 |
subDirFileName.Append(bigName); |
|
1829 |
r=f.Create(TheFs,subDirFileName,EFileRead); |
|
1830 |
test(r==KErrBadName); |
|
1831 |
subDirFileName.SetLength(254); |
|
1832 |
r=f.Create(TheFs,subDirFileName,EFileRead); |
|
1833 |
test(r==KErrNone); |
|
1834 |
f.Close(); |
|
1835 |
r=TheFs.Delete(subDirFileName); |
|
1836 |
test(r==KErrNone); |
|
1837 |
} |
|
1838 |
||
1839 |
||
1840 |
||
1841 |
||
1842 |
static void testReadersWriters() |
|
1843 |
// |
|
1844 |
// Test EFileShareReadersOrWriters file sharing. |
|
1845 |
// |
|
1846 |
{ |
|
1847 |
||
1848 |
test.Start(_L("Test EFileShareReadersOrWriters sharing")); |
|
1849 |
MakeFile(_L("TESTER")); |
|
1850 |
||
1851 |
// Open a file in EFileShareReadersOnly mode |
|
1852 |
RFile f1; |
|
1853 |
TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
1854 |
test(r==KErrNone); |
|
1855 |
||
1856 |
// Opening a share in EFileShareReadersOnly mode should succeed |
|
1857 |
RFile f2; |
|
1858 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
1859 |
test(r==KErrNone); |
|
1860 |
f2.Close(); |
|
1861 |
||
1862 |
// Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed |
|
1863 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); |
|
1864 |
test(r==KErrNone); |
|
1865 |
f2.Close(); |
|
1866 |
||
1867 |
// Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed |
|
1868 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); |
|
1869 |
test(r==KErrInUse); |
|
1870 |
||
1871 |
// Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed |
|
1872 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite); |
|
1873 |
test(r==KErrInUse); |
|
1874 |
||
1875 |
// Opening a share in EShareAny mode should fail |
|
1876 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); |
|
1877 |
test(r==KErrInUse); |
|
1878 |
||
1879 |
f1.Close(); |
|
1880 |
||
1881 |
////////////////////// |
|
1882 |
||
1883 |
// Open a file in EFileShareReadersOrWriters mode for reading |
|
1884 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); |
|
1885 |
test(r==KErrNone); |
|
1886 |
||
1887 |
// Opening a share in EFileShareExclusive mode should fail |
|
1888 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); |
|
1889 |
test(r==KErrInUse); |
|
1890 |
||
1891 |
// Opening a share in EFileShareReadersOnly mode should succeed |
|
1892 |
// (the share doesn't care if the file is opened for reading or writing) |
|
1893 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
1894 |
test(r==KErrNone); |
|
1895 |
f2.Close(); |
|
1896 |
||
1897 |
// Opening a share in EFileShareReadersOnly mode with EFileRead accesss should succeed |
|
1898 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); |
|
1899 |
test(r==KErrNone); |
|
1900 |
f2.Close(); |
|
1901 |
||
1902 |
// Opening a share in EFileShareReadersOnly mode with EFileWrite accesss should succeed |
|
1903 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); |
|
1904 |
test(r==KErrNone); |
|
1905 |
f2.Close(); |
|
1906 |
||
1907 |
// Opening a share in EFileShareReadersOnly mode with EFileRead|EFileWrite accesss should succeed |
|
1908 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite); |
|
1909 |
test(r==KErrNone); |
|
1910 |
f2.Close(); |
|
1911 |
||
1912 |
// Opening a share in EFileShareAny mode should succeed |
|
1913 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); |
|
1914 |
test(r==KErrNone); |
|
1915 |
f2.Close(); |
|
1916 |
||
1917 |
f1.Close(); |
|
1918 |
||
1919 |
////////////////////// |
|
1920 |
||
1921 |
// Open a file in EFileShareReadersOrWriters mode for writing |
|
1922 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); |
|
1923 |
test(r==KErrNone); |
|
1924 |
||
1925 |
// Opening a share in EFileShareExclusive mode should fail |
|
1926 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); |
|
1927 |
test(r==KErrInUse); |
|
1928 |
||
1929 |
// Opening a share in EFileShareReadersOnly mode should fail |
|
1930 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
1931 |
test(r==KErrInUse); |
|
1932 |
||
1933 |
// Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed |
|
1934 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); |
|
1935 |
test(r==KErrNone); |
|
1936 |
f2.Close(); |
|
1937 |
||
1938 |
// Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed |
|
1939 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); |
|
1940 |
test(r==KErrNone); |
|
1941 |
f2.Close(); |
|
1942 |
||
1943 |
// Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed |
|
1944 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite); |
|
1945 |
test(r==KErrNone); |
|
1946 |
f2.Close(); |
|
1947 |
||
1948 |
// Opening a share in EFileShareAny mode should succeed |
|
1949 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); |
|
1950 |
test(r==KErrNone); |
|
1951 |
f2.Close(); |
|
1952 |
||
1953 |
f1.Close(); |
|
1954 |
||
1955 |
////////////////////////// |
|
1956 |
||
1957 |
// Open a file in EFileShareAny mode |
|
1958 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); |
|
1959 |
test(r==KErrNone); |
|
1960 |
||
1961 |
// Opening a share in EFileShareExclusive mode should fail |
|
1962 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); |
|
1963 |
test(r==KErrInUse); |
|
1964 |
||
1965 |
// Opening a share in EFileShareReadersOnly mode should fail |
|
1966 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
1967 |
test(r==KErrInUse); |
|
1968 |
||
1969 |
// Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed |
|
1970 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); |
|
1971 |
test(r==KErrNone); |
|
1972 |
f2.Close(); |
|
1973 |
||
1974 |
// Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed |
|
1975 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); |
|
1976 |
test(r==KErrNone); |
|
1977 |
f2.Close(); |
|
1978 |
||
1979 |
// Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed |
|
1980 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite); |
|
1981 |
test(r==KErrNone); |
|
1982 |
f2.Close(); |
|
1983 |
||
1984 |
// Opening a share in EFileShareAny mode with should succeed |
|
1985 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); |
|
1986 |
test(r==KErrNone); |
|
1987 |
f2.Close(); |
|
1988 |
||
1989 |
f1.Close(); |
|
1990 |
||
1991 |
////////////////////// |
|
1992 |
||
1993 |
// Open a file in EFileShareReadersOrWriters mode for reading |
|
1994 |
r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); |
|
1995 |
test(r==KErrNone); |
|
1996 |
||
1997 |
// Opening a share in EFileShareReadersOnly mode should succeed |
|
1998 |
// - The share should now be promoted to EFileShareReadersOnly mode |
|
1999 |
r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); |
|
2000 |
test(r==KErrNone); |
|
2001 |
||
2002 |
TInt pass = 2; |
|
2003 |
while(pass--) |
|
2004 |
{ |
|
2005 |
RFile f3; |
|
2006 |
// Opening a share in EFileShareReadersOnly mode with EFileRead accesss should succeed |
|
2007 |
r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); |
|
2008 |
test(r==KErrNone); |
|
2009 |
f3.Close(); |
|
2010 |
||
2011 |
// Opening a share in EFileShareReadersOnly mode with EFileWrite accesss should fail |
|
2012 |
r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); |
|
2013 |
if(pass == 1) |
|
2014 |
{ |
|
2015 |
// The share is promoted - should obey EFileShareReadersOnly rules |
|
2016 |
test(r==KErrInUse); |
|
2017 |
} |
|
2018 |
else |
|
2019 |
{ |
|
2020 |
// The share is demoted - should obey EFileShareReadersOrWriters rules |
|
2021 |
test(r==KErrNone); |
|
2022 |
f3.Close(); |
|
2023 |
} |
|
2024 |
||
2025 |
// Opening a share in EFileShareReadersOnly mode with EFileRead|EFileWrite accesss should fail |
|
2026 |
r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite); |
|
2027 |
if(pass == 1) |
|
2028 |
{ |
|
2029 |
// The share is promoted - should obey EFileShareReadersOnly rules |
|
2030 |
test(r==KErrInUse); |
|
2031 |
} |
|
2032 |
else |
|
2033 |
{ |
|
2034 |
// The share is demoted - should obey EFileShareReadersOrWriters rules |
|
2035 |
test(r==KErrNone); |
|
2036 |
f3.Close(); |
|
2037 |
} |
|
2038 |
||
2039 |
// Opening a share in EFileShareAny mode should fails |
|
2040 |
r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); |
|
2041 |
if(pass == 1) |
|
2042 |
{ |
|
2043 |
// The share is promoted - should obey EFileShareReadersOnly rules |
|
2044 |
test(r==KErrInUse); |
|
2045 |
f2.Close(); |
|
2046 |
} |
|
2047 |
else |
|
2048 |
{ |
|
2049 |
// The share is demoted - should obey EFileShareReadersOrWriters rules |
|
2050 |
test(r==KErrNone); |
|
2051 |
f3.Close(); |
|
2052 |
} |
|
2053 |
} |
|
2054 |
||
2055 |
f1.Close(); |
|
2056 |
||
2057 |
test.End(); |
|
2058 |
} |
|
2059 |
||
2060 |
||
2061 |
static void testINC070455() |
|
2062 |
// |
|
2063 |
// INC070455 - RFile.ChangeMode() panics |
|
2064 |
// |
|
2065 |
{ |
|
2066 |
_LIT(KTestName, "Test INC070455 - RFile.ChangeMode() panics"); |
|
2067 |
test.Start(KTestName); |
|
2068 |
||
2069 |
||
2070 |
// To reproduce this defect, we need a filename of less than 10 characters. |
|
2071 |
// We cannot use the directories used by the rest of this test harness. |
|
2072 |
_LIT(KShortName, "C:\\file.txt"); |
|
2073 |
||
2074 |
||
2075 |
test.Next(_L("Create file...")); |
|
2076 |
RFile TheFile; |
|
2077 |
TInt r = TheFile.Create(TheFs, KShortName, EFileWrite); |
|
2078 |
test((KErrNone == r) || (KErrAlreadyExists == r)); |
|
2079 |
TheFile.Close(); |
|
2080 |
||
2081 |
||
2082 |
test.Next(_L("Re-open the file...")); |
|
2083 |
r = TheFile.Open(TheFs, KShortName, EFileRead | EFileShareExclusive); |
|
2084 |
test (KErrNone == r); |
|
2085 |
||
2086 |
||
2087 |
test.Next(_L("Change the file\'s mode...")); |
|
2088 |
r = TheFile.ChangeMode(EFileShareReadersOnly); |
|
2089 |
test (KErrNone == r); |
|
2090 |
TheFile.Close(); |
|
2091 |
||
2092 |
||
2093 |
test.Next(_L("Tidy up")); |
|
2094 |
r = TheFs.Delete(KShortName); |
|
2095 |
test (KErrNone == r); |
|
2096 |
||
2097 |
test.End(); |
|
2098 |
} |
|
2099 |
||
2100 |
||
2101 |
LOCAL_D TBuf8<0x80000> gLongBuf; |
|
2102 |
_LIT(KFileName, "\\zerolengthsourcedescriptortest.txt"); |
|
2103 |
||
2104 |
static void zeroSrcDesc() |
|
2105 |
{ |
|
2106 |
gLongBuf.Zero(); |
|
2107 |
} |
|
2108 |
||
2109 |
static void setSrcDescLen() |
|
2110 |
{ |
|
2111 |
gLongBuf.SetLength(0x80000); |
|
2112 |
} |
|
2113 |
||
2114 |
static void createTestFile(RFile& aFile) |
|
2115 |
{ |
|
2116 |
TInt r = aFile.Create(TheFs, KFileName, EFileWrite); |
|
2117 |
test((KErrNone == r) || (KErrAlreadyExists == r)); |
|
2118 |
} |
|
2119 |
||
2120 |
static void removeTestFile(RFile& aFile) |
|
2121 |
{ |
|
2122 |
aFile.Close(); |
|
2123 |
TInt r = TheFs.Delete(KFileName); |
|
2124 |
test (KErrNone == r); |
|
2125 |
} |
|
2126 |
||
2127 |
#ifdef _DEBUG |
|
2128 |
static TInt testWritePanic(TAny* aPtr) |
|
2129 |
{ |
|
2130 |
RFile * ptr = (RFile *)aPtr; |
|
2131 |
TInt r=ptr->Write(gLongBuf,0x80000); |
|
2132 |
test (KErrNone == r); |
|
2133 |
return KErrNone; |
|
2134 |
} |
|
2135 |
#endif |
|
2136 |
static void testNegativeLengthToWrite() |
|
2137 |
// |
|
2138 |
// DEF091545 - Tests added to check the write function behaviour with Negative length |
|
2139 |
{ |
|
2140 |
||
2141 |
test.Start(_L("Test RFile::Write variants with Negative Length parameter")); |
|
2142 |
||
2143 |
LOCAL_D TBuf8<0x100> gBuf; |
|
2144 |
RFile TheFile; |
|
2145 |
TInt r; |
|
2146 |
TRequestStatus status1(KRequestPending); |
|
2147 |
TRequestStatus status2(KRequestPending); |
|
2148 |
||
2149 |
// EXPORT_C TInt RFile::Write(const TDesC8& aDes,TInt aLength) |
|
2150 |
createTestFile(TheFile); |
|
2151 |
||
2152 |
r=TheFile.Write(gBuf, -1); |
|
2153 |
test(r==KErrArgument); |
|
2154 |
||
2155 |
removeTestFile(TheFile); |
|
2156 |
||
2157 |
// EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus) |
|
2158 |
createTestFile(TheFile); |
|
2159 |
TheFile.Write(gBuf,-1, status1); |
|
2160 |
User::WaitForRequest(status1); |
|
2161 |
test ( status1.Int() == KErrArgument); |
|
2162 |
||
2163 |
removeTestFile(TheFile); |
|
2164 |
||
2165 |
||
2166 |
||
2167 |
// EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes,TInt aLength) |
|
2168 |
createTestFile(TheFile); |
|
2169 |
r = TheFile.Write(0,gBuf,-1); |
|
2170 |
test(r==KErrArgument); |
|
2171 |
removeTestFile(TheFile); |
|
2172 |
||
2173 |
||
2174 |
// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) |
|
2175 |
createTestFile(TheFile); |
|
2176 |
TheFile.Write(0, gBuf,-1, status2); |
|
2177 |
User::WaitForRequest(status2); |
|
2178 |
test ( status2.Int() == KErrArgument); |
|
2179 |
removeTestFile(TheFile); |
|
2180 |
||
2181 |
test.End(); |
|
2182 |
||
2183 |
||
2184 |
||
2185 |
} |
|
2186 |
||
2187 |
static TInt testLockPanic(TAny* aPtr) |
|
2188 |
{ |
|
2189 |
TInt aPos=128; |
|
2190 |
TInt aLen=-1; |
|
2191 |
RFile * ptr = (RFile *)aPtr; |
|
2192 |
TInt r=ptr->Lock(aPos, aLen); |
|
2193 |
test (KErrNone == r); |
|
2194 |
return KErrNone; |
|
2195 |
} |
|
2196 |
||
2197 |
static TInt testUnLockPanic(TAny* aPtr) |
|
2198 |
{ |
|
2199 |
TInt aPos=128; |
|
2200 |
TInt aLen=-1; |
|
2201 |
RFile * ptr = (RFile *)aPtr; |
|
2202 |
TInt r=ptr->UnLock(aPos, aLen); |
|
2203 |
test (KErrNone == r); |
|
2204 |
return KErrNone; |
|
2205 |
} |
|
2206 |
||
2207 |
static TInt testSetSizePanic(TAny* aPtr) |
|
2208 |
{ |
|
2209 |
TInt aSize=-1; |
|
2210 |
RFile * ptr = (RFile *)aPtr; |
|
2211 |
TInt r=ptr->SetSize(aSize); |
|
2212 |
test (KErrNone == r); |
|
2213 |
return KErrNone; |
|
2214 |
} |
|
2215 |
||
2216 |
static void testNegativeLength() |
|
2217 |
{ |
|
2218 |
test.Start(_L("Test RFile::Lock, RFile::Unlock and RFile::SetSize with Negative Length parameter")); |
|
2219 |
||
2220 |
test(TheFs.ShareProtected() == KErrNone); |
|
2221 |
||
2222 |
RFile TheFile; |
|
2223 |
createTestFile(TheFile); |
|
2224 |
TRequestStatus status = KRequestPending; |
|
2225 |
||
2226 |
// launch call on separate thread as expected to panic |
|
2227 |
// Test Lock with a negative length |
|
2228 |
User::SetJustInTime(EFalse); |
|
2229 |
RThread t; |
|
2230 |
test(t.Create(_L("testLockPanic"), testLockPanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone); |
|
2231 |
t.Logon(status); |
|
2232 |
t.Resume(); |
|
2233 |
User::WaitForRequest(status); |
|
2234 |
User::SetJustInTime(ETrue); |
|
2235 |
test(t.ExitType() == EExitPanic); |
|
2236 |
test(t.ExitReason() == 17); |
|
2237 |
t.Close(); |
|
2238 |
||
2239 |
||
2240 |
// Test Unlock with a negative length |
|
2241 |
User::SetJustInTime(EFalse); |
|
2242 |
status = KRequestPending; |
|
2243 |
test(t.Create(_L("testUnLockPanic"), testUnLockPanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone); |
|
2244 |
t.Logon(status); |
|
2245 |
t.Resume(); |
|
2246 |
User::WaitForRequest(status); |
|
2247 |
test(t.ExitType() == EExitPanic); |
|
2248 |
test(t.ExitReason() == 18); |
|
2249 |
t.Close(); |
|
2250 |
User::SetJustInTime(ETrue); |
|
2251 |
||
2252 |
// Test SetSize with a negative length |
|
2253 |
User::SetJustInTime(EFalse); |
|
2254 |
status = KRequestPending; |
|
2255 |
test(t.Create(_L("testSetSizePanic"), testSetSizePanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone); |
|
2256 |
t.Logon(status); |
|
2257 |
t.Resume(); |
|
2258 |
User::WaitForRequest(status); |
|
2259 |
test(t.ExitType() == EExitPanic); |
|
2260 |
test(t.ExitReason() == 20); |
|
2261 |
t.Close(); |
|
2262 |
User::SetJustInTime(ETrue); |
|
2263 |
||
2264 |
removeTestFile(TheFile); |
|
2265 |
test.End(); |
|
2266 |
} |
|
2267 |
||
2268 |
static void testZeroLengthDescriptors() |
|
2269 |
// |
|
2270 |
// INC088416 - NAND thread crash when doing async writes to internal memory |
|
2271 |
// |
|
2272 |
// Test each variant of RFile::Write against zero length source descriptor arguements |
|
2273 |
{ |
|
2274 |
test.Start(_L("Test RFile::Write variants with Zero Length Source Descriptor")); |
|
2275 |
||
2276 |
RFile TheFile; |
|
2277 |
TRequestStatus status(KRequestPending); |
|
2278 |
||
2279 |
||
2280 |
// EXPORT_C TInt RFile::Write(const TDesC8& aDes) PASS ZERO length descriptor |
|
2281 |
||
2282 |
createTestFile(TheFile); |
|
2283 |
||
2284 |
zeroSrcDesc(); |
|
2285 |
||
2286 |
test.Next(_L("Execute sync call RFile::Write(const TDesC8& aDes) with zero length aDes")); |
|
2287 |
TInt r=TheFile.Write(gLongBuf); |
|
2288 |
test(r==KErrNone); |
|
2289 |
||
2290 |
test.Printf(_L("Test case passed\n")); |
|
2291 |
||
2292 |
removeTestFile(TheFile); |
|
2293 |
||
2294 |
||
2295 |
// EXPORT_C void RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) PASS ZERO length descriptor |
|
2296 |
||
2297 |
createTestFile(TheFile); |
|
2298 |
||
2299 |
status = KRequestPending; |
|
2300 |
zeroSrcDesc(); |
|
2301 |
||
2302 |
test.Next(_L("Start async call RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) with zero length sDes")); |
|
2303 |
TheFile.Write(gLongBuf,status); |
|
2304 |
User::WaitForRequest(status); |
|
2305 |
test(status.Int()==KErrNone); |
|
2306 |
||
2307 |
test.Printf(_L("Test case passed\n")); |
|
2308 |
||
2309 |
removeTestFile(TheFile); |
|
2310 |
||
2311 |
||
2312 |
// EXPORT_C void RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write |
|
2313 |
||
2314 |
createTestFile(TheFile); |
|
2315 |
||
2316 |
status = KRequestPending; |
|
2317 |
setSrcDescLen(); |
|
2318 |
||
2319 |
test.Next(_L("Start async call RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus)")); |
|
2320 |
TheFile.Write(gLongBuf,status); |
|
2321 |
test.Printf(_L("Zero source descriptor during async write\n")); |
|
2322 |
zeroSrcDesc(); |
|
2323 |
User::WaitForRequest(status); |
|
2324 |
test(status.Int()==KErrNone); |
|
2325 |
||
2326 |
test.Printf(_L("Test case passed\n")); |
|
2327 |
||
2328 |
removeTestFile(TheFile); |
|
2329 |
||
2330 |
||
2331 |
// EXPORT_C TInt RFile::Write(const TDesC8& aDes,TInt aLength) PASS ZERO length descriptor |
|
2332 |
||
2333 |
createTestFile(TheFile); |
|
2334 |
||
2335 |
status = KRequestPending; |
|
2336 |
zeroSrcDesc(); |
|
2337 |
||
2338 |
test.Next(_L("Execute sync call RFile::Write(const TDesC8& aDes,TInt aLength) with zero length aDes")); |
|
2339 |
#ifdef _DEBUG |
|
2340 |
// launch call on separate thread as expected to panic |
|
2341 |
User::SetJustInTime(EFalse); |
|
2342 |
status = KRequestPending; |
|
2343 |
RThread t; |
|
2344 |
test(t.Create(_L("testWritePanic"), testWritePanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone); |
|
2345 |
t.Logon(status); |
|
2346 |
t.Resume(); |
|
2347 |
User::WaitForRequest(status); |
|
2348 |
test(t.ExitType() == EExitPanic); |
|
2349 |
test(t.ExitReason() == 27); |
|
2350 |
t.Close(); |
|
2351 |
User::SetJustInTime(ETrue); |
|
2352 |
#else |
|
2353 |
||
2354 |
r=TheFile.Write(gLongBuf, 0x80000); |
|
2355 |
test(r==KErrNone); |
|
2356 |
#endif |
|
2357 |
||
2358 |
test.Printf(_L("Test case passed\n")); |
|
2359 |
||
2360 |
removeTestFile(TheFile); |
|
2361 |
||
2362 |
||
2363 |
// EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus) PASS ZERO length descriptor |
|
2364 |
||
2365 |
createTestFile(TheFile); |
|
2366 |
||
2367 |
status = KRequestPending; |
|
2368 |
zeroSrcDesc(); |
|
2369 |
||
2370 |
test.Next(_L("Start async call RFile::Write(const TDesC8& aDes, TInt aLength,TRequestStatus& aStatus) with zero length sDes")); |
|
2371 |
TheFile.Write(gLongBuf, 0x80000, status); ; |
|
2372 |
User::WaitForRequest(status); |
|
2373 |
test(status.Int()==KErrNone); |
|
2374 |
||
2375 |
test.Printf(_L("Test case passed\n")); |
|
2376 |
||
2377 |
removeTestFile(TheFile); |
|
2378 |
||
2379 |
||
2380 |
// EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write |
|
2381 |
||
2382 |
createTestFile(TheFile); |
|
2383 |
||
2384 |
status = KRequestPending; |
|
2385 |
setSrcDescLen(); |
|
2386 |
||
2387 |
test.Next(_L("Start async call RFile::Write(const TDesC8& aDes, Int aLength,TRequestStatus& aStatus)")); |
|
2388 |
TheFile.Write(gLongBuf,0x80000, status); |
|
2389 |
test.Printf(_L("Zero source descriptor during async write\n")); |
|
2390 |
zeroSrcDesc(); |
|
2391 |
User::WaitForRequest(status); |
|
2392 |
test(status.Int()==KErrNone); |
|
2393 |
||
2394 |
test.Printf(_L("Test case passed\n")); |
|
2395 |
||
2396 |
removeTestFile(TheFile); |
|
2397 |
||
2398 |
||
2399 |
// EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes) PASS ZERO length descriptor |
|
2400 |
||
2401 |
createTestFile(TheFile); |
|
2402 |
||
2403 |
zeroSrcDesc(); |
|
2404 |
||
2405 |
test.Next(_L("Execute sync call RFile::Write(TInt aPos, const TDesC8& aDes) with zero length aDes")); |
|
2406 |
r=TheFile.Write(0, gLongBuf); |
|
2407 |
test(r==KErrNone); |
|
2408 |
||
2409 |
test.Printf(_L("Test case passed\n")); |
|
2410 |
||
2411 |
removeTestFile(TheFile); |
|
2412 |
||
2413 |
||
2414 |
// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes,TRequestStatus& aStatus) PASS ZERO length descriptor |
|
2415 |
||
2416 |
createTestFile(TheFile); |
|
2417 |
||
2418 |
status = KRequestPending; |
|
2419 |
zeroSrcDesc(); |
|
2420 |
||
2421 |
test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TRequestStatus& aStatus) with zero length sDes")); |
|
2422 |
TheFile.Write(0, gLongBuf, status); |
|
2423 |
User::WaitForRequest(status); |
|
2424 |
test(status.Int()==KErrNone); |
|
2425 |
||
2426 |
test.Printf(_L("Test case passed\n")); |
|
2427 |
||
2428 |
removeTestFile(TheFile); |
|
2429 |
||
2430 |
||
2431 |
// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes,TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write |
|
2432 |
||
2433 |
createTestFile(TheFile); |
|
2434 |
||
2435 |
status = KRequestPending; |
|
2436 |
setSrcDescLen(); |
|
2437 |
||
2438 |
test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TRequestStatus& aStatus)")); |
|
2439 |
TheFile.Write(0, gLongBuf, status); |
|
2440 |
test.Printf(_L("Zero source descriptor during async write\n")); |
|
2441 |
zeroSrcDesc(); |
|
2442 |
User::WaitForRequest(status); |
|
2443 |
test(status.Int()==KErrNone); |
|
2444 |
||
2445 |
test.Printf(_L("Test case passed\n")); |
|
2446 |
||
2447 |
removeTestFile(TheFile); |
|
2448 |
||
2449 |
||
2450 |
// EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes,TInt aLength) PASS ZERO length descriptor |
|
2451 |
||
2452 |
createTestFile(TheFile); |
|
2453 |
||
2454 |
zeroSrcDesc(); |
|
2455 |
||
2456 |
test.Next(_L("Execute sync call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength) with zero length aDes")); |
|
2457 |
r=TheFile.Write(0, gLongBuf, 0x80000); |
|
2458 |
test(r==KErrNone); |
|
2459 |
||
2460 |
test.Printf(_L("Test case passed\n")); |
|
2461 |
||
2462 |
removeTestFile(TheFile); |
|
2463 |
||
2464 |
||
2465 |
// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) PASS ZERO length descriptor |
|
2466 |
||
2467 |
createTestFile(TheFile); |
|
2468 |
||
2469 |
status = KRequestPending; |
|
2470 |
zeroSrcDesc(); |
|
2471 |
||
2472 |
test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) with zero length sDes")); |
|
2473 |
TheFile.Write(0, gLongBuf, 0x80000, status); |
|
2474 |
User::WaitForRequest(status); |
|
2475 |
test(status.Int()==KErrNone); |
|
2476 |
||
2477 |
test.Printf(_L("Test case passed\n")); |
|
2478 |
||
2479 |
removeTestFile(TheFile); |
|
2480 |
||
2481 |
||
2482 |
// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write |
|
2483 |
||
2484 |
createTestFile(TheFile); |
|
2485 |
||
2486 |
status = KRequestPending; |
|
2487 |
setSrcDescLen(); |
|
2488 |
||
2489 |
test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus")); |
|
2490 |
TheFile.Write(0, gLongBuf, 0x80000, status); |
|
2491 |
test.Printf(_L("Zero source descriptor during async write\n")); |
|
2492 |
zeroSrcDesc(); |
|
2493 |
User::WaitForRequest(status); |
|
2494 |
test(status.Int()==KErrNone); |
|
2495 |
||
2496 |
test.Printf(_L("Test case passed\n")); |
|
2497 |
||
2498 |
removeTestFile(TheFile); |
|
2499 |
||
2500 |
||
2501 |
test.End(); |
|
2502 |
} |
|
2503 |
||
2504 |
static void testReadBufferOverflow() |
|
2505 |
// |
|
2506 |
// Test each variant of RFile::Read when the specified extent to read is |
|
2507 |
// greater than the available buffer space |
|
2508 |
// |
|
2509 |
{ |
|
2510 |
test.Start(_L("Test RFile::Read for oversized requests")); |
|
2511 |
||
2512 |
RFile file; |
|
2513 |
TInt r = file.Create(TheFs, KFileName, EFileRead); |
|
2514 |
test((KErrNone == r) || (KErrAlreadyExists == r)); |
|
2515 |
||
2516 |
TInt err = KErrNone; |
|
2517 |
TRequestStatus status(KRequestPending); |
|
2518 |
TBuf8<2> buf8; |
|
2519 |
||
2520 |
// EXPORT_C TInt RFile::Read(TDes8& aDes,TInt aLength) const |
|
2521 |
err = file.Read(buf8,5); |
|
2522 |
test(err==KErrOverflow); |
|
2523 |
err = KErrNone; |
|
2524 |
||
2525 |
// EXPORT_C void RFile::Read(TDes8& aDes,TInt aLength,TRequestStatus& aStatus) const |
|
2526 |
file.Read(buf8,5,status); |
|
2527 |
test(status.Int()==KErrOverflow); |
|
2528 |
status = KRequestPending; |
|
2529 |
||
2530 |
// EXPORT_C TInt RFile::Read(TInt aPos,TDes8& aDes,TInt aLength) const |
|
2531 |
err = file.Read(0,buf8,5); |
|
2532 |
test(err==KErrOverflow); |
|
2533 |
||
2534 |
// EXPORT_C void RFile::Read(TInt aPos,TDes8& aDes,TInt aLength,TRequestStatus& aStatus) const |
|
2535 |
file.Read(0,buf8,5,status); |
|
2536 |
test(status.Int()==KErrOverflow); |
|
2537 |
||
2538 |
removeTestFile(file); |
|
2539 |
test.End(); |
|
2540 |
} |
|
2541 |
||
2542 |
RSemaphore gSleepThread; |
|
2543 |
TFileName gLastTempFileName; |
|
2544 |
enum TTestDoCMode |
|
2545 |
{ |
|
2546 |
EDoCPanic=1, |
|
2547 |
EDoCDeleteOnClose=2 |
|
2548 |
}; |
|
2549 |
||
2550 |
static TInt DeleteOnCloseClientThread(TAny* aMode) |
|
2551 |
{ |
|
2552 |
TTestDoCMode testMode = *(TTestDoCMode*)&aMode; |
|
2553 |
TUint fileMode=EFileRead; |
|
2554 |
RFs fs; |
|
2555 |
RFile file; |
|
2556 |
||
2557 |
TInt r=fs.Connect(); |
|
2558 |
test(r==KErrNone); |
|
2559 |
r=fs.SetSessionPath(gSessionPath); |
|
2560 |
test(r==KErrNone); |
|
2561 |
if (testMode & EDoCDeleteOnClose) |
|
2562 |
fileMode|=EDeleteOnClose; |
|
2563 |
r=file.Temp(fs,_L(""),gLastTempFileName,fileMode); |
|
2564 |
test(r==KErrNone); |
|
2565 |
// Signal controlling thread and pause for panic where requested |
|
2566 |
// by caller. |
|
2567 |
if (testMode & EDoCPanic) |
|
2568 |
{ |
|
2569 |
gSleepThread.Signal(); |
|
2570 |
User::After(10000000); |
|
2571 |
} |
|
2572 |
file.Close(); |
|
2573 |
if (!(testMode & EDoCPanic)) |
|
2574 |
gSleepThread.Signal(); |
|
2575 |
fs.Close(); |
|
2576 |
return KErrNone; |
|
2577 |
} |
|
2578 |
||
2579 |
static void TestDeleteOnClose() |
|
2580 |
// |
|
2581 |
// Test RFile::Temp delete on close behaviour |
|
2582 |
// |
|
2583 |
{ |
|
2584 |
test.Start(_L("RFile::Temp default file close behaviour")); |
|
2585 |
||
2586 |
gSleepThread.CreateLocal(0); |
|
2587 |
RThread clientThread; |
|
2588 |
RFile file; |
|
2589 |
RFile file2; |
|
2590 |
TFileName filename =_L("DoCFile.tst"); |
|
2591 |
TInt r; |
|
2592 |
||
2593 |
// |
|
2594 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2595 |
//! @SYMTestCaseID PBASE-t_file-0804 |
|
2596 |
//! @SYMTestType UT |
|
2597 |
//! @SYMTestCaseDesc Verifying the original behaviour of RFile::Temp() |
|
2598 |
//! @SYMPREQ CR1266 |
|
2599 |
//! @SYMTestPriority High |
|
2600 |
//! @SYMTestActions |
|
2601 |
//! 1. Test thread creates a file with DeleteOnClose flag unset and |
|
2602 |
//! exits normally. |
|
2603 |
//! The main test body attempts to delete the resulting temporary |
|
2604 |
//! file. |
|
2605 |
//! |
|
2606 |
//! @SYMTestExpectedResults |
|
2607 |
//! 1. The temporary file is successfully created and deleted. |
|
2608 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2609 |
r=clientThread.Create(_L("DeleteOnCloseClientThread 1"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)0); |
|
2610 |
test(r==KErrNone); |
|
2611 |
clientThread.Resume(); |
|
2612 |
gSleepThread.Wait(); |
|
2613 |
r=TheFs.Delete(gLastTempFileName); |
|
2614 |
test(r==KErrNone); |
|
2615 |
clientThread.Close(); |
|
2616 |
||
2617 |
// |
|
2618 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2619 |
//! @SYMTestCaseID PBASE-t_file-0805 |
|
2620 |
//! @SYMTestType UT |
|
2621 |
//! @SYMTestCaseDesc Verifying the Delete on Close behaviour of RFile::Temp() |
|
2622 |
//! @SYMPREQ CR1266 |
|
2623 |
//! @SYMTestPriority High |
|
2624 |
//! @SYMTestActions |
|
2625 |
//! 1. Test thread creates a file with DeleteOnClose flag set and |
|
2626 |
//! exits normally. |
|
2627 |
//! The main test body attempts to delete the resulting temporary |
|
2628 |
//! file. |
|
2629 |
//! |
|
2630 |
//! @SYMTestExpectedResults |
|
2631 |
//! 1. The temporary file is successfully created and automatically |
|
2632 |
//! deleted upon close. The subsequent attempted file deletion |
|
2633 |
//! by the main test body should fail with KErrNotFound. |
|
2634 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2635 |
test.Next(_L("RFile::Temp EDeleteOnClose behaviour")); |
|
2636 |
r=clientThread.Create(_L("DeleteOnCloseClientThread 2"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)EDoCDeleteOnClose); |
|
2637 |
test(r==KErrNone); |
|
2638 |
clientThread.Resume(); |
|
2639 |
gSleepThread.Wait(); |
|
2640 |
r=TheFs.Delete(gLastTempFileName); |
|
2641 |
test(r==KErrNotFound); |
|
2642 |
clientThread.Close(); |
|
2643 |
||
2644 |
// |
|
2645 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2646 |
//! @SYMTestCaseID PBASE-t_file-0806 |
|
2647 |
//! @SYMTestType UT |
|
2648 |
//! @SYMTestCaseDesc Verifying the original, panic behaviour of RFile::Temp() |
|
2649 |
//! @SYMPREQ CR1266 |
|
2650 |
//! @SYMTestPriority High |
|
2651 |
//! @SYMTestActions |
|
2652 |
//! 1. Test thread creates a file with DeleteOnClose flag unset and |
|
2653 |
//! is paniced by the main test body. |
|
2654 |
//! The main test body attempts to delete the resulting temporary |
|
2655 |
//! file. |
|
2656 |
//! |
|
2657 |
//! @SYMTestExpectedResults |
|
2658 |
//! 1. The temporary file is successfully created and deleted. |
|
2659 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2660 |
test.Next(_L("RFile::Temp default panic behaviour")); |
|
2661 |
r=clientThread.Create(_L("DeleteOnCloseClientThread 3"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)EDoCPanic); |
|
2662 |
test(r==KErrNone); |
|
2663 |
clientThread.Resume(); |
|
2664 |
gSleepThread.Wait(); |
|
2665 |
User::SetJustInTime(EFalse); |
|
2666 |
clientThread.Panic(_L("Panic temp file thread #3"),KErrGeneral); |
|
2667 |
User::SetJustInTime(ETrue); |
|
2668 |
CLOSE_AND_WAIT(clientThread); |
|
2669 |
FsBarrier(); |
|
2670 |
r=TheFs.Delete(gLastTempFileName); |
|
2671 |
test(r==KErrNone); |
|
2672 |
||
2673 |
// |
|
2674 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2675 |
//! @SYMTestCaseID PBASE-t_file-0807 |
|
2676 |
//! @SYMTestType UT |
|
2677 |
//! @SYMTestCaseDesc Verifying the Delete on Close, panic behaviour of RFile::Temp() |
|
2678 |
//! @SYMPREQ CR1266 |
|
2679 |
//! @SYMTestPriority High |
|
2680 |
//! @SYMTestActions |
|
2681 |
//! 1. Test thread creates a file with DeleteOnClose flag set and |
|
2682 |
//! is paniced by the main test body. |
|
2683 |
//! The main test body attempts to delete the resulting temporary |
|
2684 |
//! file. |
|
2685 |
//! |
|
2686 |
//! @SYMTestExpectedResults |
|
2687 |
//! 1. The temporary file is successfully created and automatically |
|
2688 |
//! deleted upon close. The subsequent attempted file deletion |
|
2689 |
//! by the main test body should fail with KErrNotFound. |
|
2690 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2691 |
test.Next(_L("RFile::Temp EDeleteOnClose panic behaviour")); |
|
2692 |
r=clientThread.Create(_L("DeleteOnCloseClientThread 4"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)(EDoCPanic|EDoCDeleteOnClose)); |
|
2693 |
test(r==KErrNone); |
|
2694 |
clientThread.Resume(); |
|
2695 |
gSleepThread.Wait(); |
|
2696 |
User::SetJustInTime(EFalse); |
|
2697 |
clientThread.Panic(_L("Panic temp file thread #4"),KErrGeneral); |
|
2698 |
User::SetJustInTime(ETrue); |
|
2699 |
CLOSE_AND_WAIT(clientThread); |
|
2700 |
FsBarrier(); |
|
2701 |
r=TheFs.Delete(gLastTempFileName); |
|
2702 |
test(r==KErrNotFound); |
|
2703 |
||
2704 |
// |
|
2705 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2706 |
//! @SYMTestCaseID PBASE-t_file-0808 |
|
2707 |
//! @SYMTestType UT |
|
2708 |
//! @SYMTestCaseDesc Verifying RFile::Create() supports Delete On Close. |
|
2709 |
//! @SYMPREQ CR1266 |
|
2710 |
//! @SYMTestPriority High |
|
2711 |
//! @SYMTestActions |
|
2712 |
//! 1. Test creates a file with DeleteOnClose flag set and |
|
2713 |
//! then closes the file. |
|
2714 |
//! 2. Test attempts to delete the file. |
|
2715 |
//! |
|
2716 |
//! @SYMTestExpectedResults |
|
2717 |
//! 1. The file creation should succeed. |
|
2718 |
//! 2. The file deletion should fail with KErrNotFound. |
|
2719 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2720 |
test.Next(_L("RFile::Create EDeleteOnClose behaviour")); |
|
2721 |
r=file.Create(TheFs,_L("DoC5"),EFileRead|EFileWrite|EDeleteOnClose); |
|
2722 |
test(r==KErrNone); |
|
2723 |
file.Close(); |
|
2724 |
r=TheFs.Delete(filename); |
|
2725 |
test(r==KErrNotFound); |
|
2726 |
||
2727 |
// |
|
2728 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2729 |
//! @SYMTestCaseID PBASE-t_file-0809 |
|
2730 |
//! @SYMTestType UT |
|
2731 |
//! @SYMTestCaseDesc Verifying Delete On Close with multiple subsessions. |
|
2732 |
//! @SYMPREQ CR1266 |
|
2733 |
//! @SYMTestPriority High |
|
2734 |
//! @SYMTestActions |
|
2735 |
//! 1. Test creates a file with DeleteOnClose and FileShareAny flags |
|
2736 |
//! set, opens the file a second time with the FileShareAny flag set |
|
2737 |
//! and then closes the first file handle. |
|
2738 |
//! 2. Test attempts to delete the file. |
|
2739 |
//! 3. The second file handle is closed and the test attempts to delete |
|
2740 |
//! the file. |
|
2741 |
//! |
|
2742 |
//! @SYMTestExpectedResults |
|
2743 |
//! 1. The file create and file open should succeed. |
|
2744 |
//! 2. The file deletion should fail with KErrInUse. |
|
2745 |
//! 3. The file deletion should fail with KErrNotFound. |
|
2746 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2747 |
test.Next(_L("DoC 6 - Multiple subsessions")); |
|
2748 |
r=file.Create(TheFs,filename,EFileShareAny|EFileRead|EFileWrite|EDeleteOnClose); |
|
2749 |
test(r==KErrNone); |
|
2750 |
r=file2.Open(TheFs,filename,EFileShareAny|EFileRead|EFileWrite); |
|
2751 |
test(r==KErrNone); |
|
2752 |
file.Close(); |
|
2753 |
test(r==KErrNone); |
|
2754 |
r=TheFs.Delete(filename); |
|
2755 |
test(r==KErrInUse); |
|
2756 |
file2.Close(); |
|
2757 |
r=TheFs.Delete(filename); |
|
2758 |
test(r==KErrNotFound); |
|
2759 |
||
2760 |
// |
|
2761 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2762 |
//! @SYMTestCaseID PBASE-t_file-0810 |
|
2763 |
//! @SYMTestType UT |
|
2764 |
//! @SYMTestCaseDesc Verifying Delete On Close with preexisting file. |
|
2765 |
//! @SYMPREQ CR1266 |
|
2766 |
//! @SYMTestPriority High |
|
2767 |
//! @SYMTestActions |
|
2768 |
//! 1. Test creates and closes a file, then attempts to create the same |
|
2769 |
//! file with Delete on Close set. |
|
2770 |
//! |
|
2771 |
//! @SYMTestExpectedResults |
|
2772 |
//! 1. The second create should fail with KErrAlreadyExists. |
|
2773 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2774 |
test.Next(_L("RFile::Create existing file behaviour")); |
|
2775 |
r=file.Create(TheFs,filename,EFileRead|EFileWrite); |
|
2776 |
test(r==KErrNone); |
|
2777 |
file.Close(); |
|
2778 |
r=file.Create(TheFs,filename,EFileRead|EFileWrite|EDeleteOnClose); |
|
2779 |
test(r==KErrAlreadyExists); |
|
2780 |
||
2781 |
// |
|
2782 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2783 |
//! @SYMTestCaseID PBASE-t_file-0811 |
|
2784 |
//! @SYMTestType UT |
|
2785 |
//! @SYMTestCaseDesc Verifying existing file cannot be opened with delete on close set. |
|
2786 |
//! @SYMPREQ CR1266 |
|
2787 |
//! @SYMTestPriority High |
|
2788 |
//! @SYMTestActions |
|
2789 |
//! 1. Test attempts to open an existing file with delete on close set. |
|
2790 |
//! |
|
2791 |
//! @SYMTestExpectedResults |
|
2792 |
//! 1. The open should fail with KErrArgument. |
|
2793 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2794 |
test.Next(_L("RFile::Open EDeleteOnClose flag validation")); |
|
2795 |
r=file.Open(TheFs,filename,EFileRead|EFileWrite|EDeleteOnClose); |
|
2796 |
test(r==KErrArgument); |
|
2797 |
r=TheFs.Delete(filename); |
|
2798 |
test(r==KErrNone); |
|
2799 |
||
2800 |
gSleepThread.Close(); |
|
2801 |
test.End(); |
|
2802 |
} |
|
2803 |
||
2804 |
//-------------------------------------------------------------- |
|
2805 |
/** |
|
2806 |
Test that flushing dirty file cache does not affect file attributes and time. |
|
2807 |
This test shall pass disregarding if there is file cache or not. |
|
2808 |
||
2809 |
*/ |
|
2810 |
void TestFileAttributesAndCacheFlushing() |
|
2811 |
{ |
|
2812 |
test.Next(_L("Test that file cache flushing does not affect the file attributes.")); |
|
2813 |
if(Is_Win32(TheFs, gDriveNum)) |
|
2814 |
{ |
|
2815 |
test.Printf(_L("This test doesn't work on Win32 FS, skipping!\n")); |
|
2816 |
return; |
|
2817 |
} |
|
2818 |
||
2819 |
_LIT(KFile, "\\file1"); |
|
2820 |
||
2821 |
TInt nRes; |
|
2822 |
TEntry entry; |
|
2823 |
TheFs.Delete(KFile); |
|
2824 |
||
2825 |
//-- 1. create test file |
|
2826 |
nRes = CreateEmptyFile(TheFs, KFile, 33); |
|
2827 |
test(nRes == KErrNone); |
|
2828 |
||
2829 |
//-- 2. open it for write |
|
2830 |
RFile file; |
|
2831 |
nRes = file.Open(TheFs, KFile, EFileWrite); |
|
2832 |
test(nRes == KErrNone); |
|
2833 |
||
2834 |
//-- 3. write a couple of bytes there. This must cause 'Archive' attribute set |
|
2835 |
nRes = file.Write(0, _L8("a")); |
|
2836 |
test(nRes == KErrNone); |
|
2837 |
nRes = file.Write(10, _L8("b")); |
|
2838 |
test(nRes == KErrNone); |
|
2839 |
||
2840 |
nRes = TheFs.Entry(KFile, entry); |
|
2841 |
test(nRes == KErrNone); |
|
2842 |
||
2843 |
test(entry.IsArchive()); //-- 'A' attribute must be set. |
|
2844 |
||
2845 |
//-- the file cache (if present) is dirty now. Dirty data timer starts to tick. |
|
2846 |
//-- 4. set new file attributes (w/o 'A') and creation time |
|
2847 |
const TUint newAtt = KEntryAttSystem ; |
|
2848 |
nRes = file.SetAtt(newAtt, ~newAtt & KEntryAttMaskSupported); |
|
2849 |
test(nRes == KErrNone); |
|
2850 |
||
2851 |
TTime newTime; |
|
2852 |
nRes = newTime.Set(_L("19970310:101809.000000")); |
|
2853 |
test(nRes == KErrNone); |
|
2854 |
nRes = file.SetModified(newTime); |
|
2855 |
test(nRes == KErrNone); |
|
2856 |
||
2857 |
//-- 5. wait 5 seconds. file server shall flush dirty data during this period. |
|
2858 |
User::After(5*K1Sec); |
|
2859 |
||
2860 |
//-- 6. check that attributes haven't chanded because of flush |
|
2861 |
nRes = file.Flush(); //-- this will flush attributes to the media |
|
2862 |
test(nRes == KErrNone); |
|
2863 |
||
2864 |
nRes = TheFs.Entry(KFile, entry); |
|
2865 |
test(nRes == KErrNone); |
|
2866 |
||
2867 |
test(entry.iAtt == newAtt); |
|
2868 |
test(entry.iModified.DateTime().Year() == 1997); |
|
2869 |
test(entry.iModified.DateTime().Month() == 3); |
|
2870 |
test(entry.iModified.DateTime().Day() == 10); |
|
2871 |
||
2872 |
//-- 7. write some data and ensure that 'A' attribute is set now and 'modified' time updated |
|
2873 |
nRes = file.Write(12, _L8("c")); |
|
2874 |
test(nRes == KErrNone); |
|
2875 |
||
2876 |
file.Close(); //-- this will flush attributes to the media |
|
2877 |
||
2878 |
nRes = TheFs.Entry(KFile, entry); |
|
2879 |
test(nRes == KErrNone); |
|
2880 |
test(entry.iAtt == (newAtt | KEntryAttArchive)); |
|
2881 |
test(entry.iModified.DateTime().Year() != 1997); |
|
2882 |
||
2883 |
||
2884 |
||
2885 |
} |
|
2886 |
||
2887 |
/** |
|
2888 |
Testing access to the very last bytes in the maximal (for FAT32) file size. |
|
2889 |
This test must pass regardless of write caching configuration. |
|
2890 |
*/ |
|
2891 |
void TestMaxFileSize() |
|
2892 |
{ |
|
2893 |
test.Next(_L("test maximal file size on FAT32\n")); |
|
2894 |
||
2895 |
#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
2896 |
||
2897 |
if(!Is_Fat32(TheFs, gDriveNum)) |
|
2898 |
{ |
|
2899 |
test.Printf(_L("This test requires FAT32! skipping.\n")); |
|
2900 |
return; |
|
2901 |
} |
|
2902 |
||
2903 |
TInt nRes; |
|
2904 |
||
2905 |
//-- check disk space, it shall be > 4G |
|
2906 |
TVolumeInfo volInfo; |
|
2907 |
nRes = TheFs.Volume(volInfo, gDriveNum); |
|
2908 |
test(nRes == KErrNone); |
|
2909 |
||
2910 |
const TUint32 KMaxFAT32FileSize = 0xFFFFFFFF; // 4GB-1 |
|
2911 |
||
2912 |
if(volInfo.iFree <= KMaxFAT32FileSize) |
|
2913 |
{ |
|
2914 |
test.Printf(_L("Not enough space for 4GB file! skipping.\n")); |
|
2915 |
return; |
|
2916 |
} |
|
2917 |
||
2918 |
_LIT(KFileName, "\\huge_file"); |
|
2919 |
TBuf8<10> buf(10); |
|
2920 |
RFile64 file64; |
|
2921 |
||
2922 |
//-- 1. create 4GB-1 file |
|
2923 |
//-- this file has enabled write caching by default |
|
2924 |
test.Printf(_L("creating maximal length file, size = 0x%x\n"),KMaxFAT32FileSize); |
|
2925 |
nRes = file64.Replace(TheFs, KFileName, EFileWrite); |
|
2926 |
test(nRes == KErrNone); |
|
2927 |
||
2928 |
const TInt64 fileSize = KMaxFAT32FileSize; |
|
2929 |
||
2930 |
nRes = file64.SetSize(fileSize); |
|
2931 |
test(nRes == KErrNone); |
|
2932 |
||
2933 |
test.Printf(_L("seeking to the file end...\n")); |
|
2934 |
TInt64 filePos = 0; |
|
2935 |
nRes = file64.Seek(ESeekEnd, filePos); |
|
2936 |
test(nRes == KErrNone); |
|
2937 |
||
2938 |
||
2939 |
test.Printf(_L("test writing to the last bytes of the file (rel pos addressing) \n")); |
|
2940 |
||
2941 |
//-- 1. writing using relative position |
|
2942 |
filePos = -1; |
|
2943 |
nRes = file64.Seek(ESeekEnd, filePos); |
|
2944 |
test(nRes == KErrNone); |
|
2945 |
test(filePos == fileSize-1); |
|
2946 |
||
2947 |
nRes = file64.Write(_L8("z")); //-- write 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file |
|
2948 |
test(nRes == KErrNone); |
|
2949 |
||
2950 |
nRes = file64.Write(_L8("x")); //-- write 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail |
|
2951 |
test(nRes == KErrNotSupported); |
|
2952 |
||
2953 |
nRes = file64.Flush(); |
|
2954 |
test(nRes == KErrNone); |
|
2955 |
||
2956 |
//-- 1.1 check the result by reading data using rel. pos |
|
2957 |
filePos = -1; |
|
2958 |
nRes = file64.Seek(ESeekEnd, filePos); |
|
2959 |
test(nRes == KErrNone); |
|
2960 |
test(filePos == fileSize-1); |
|
2961 |
||
2962 |
test.Printf(_L("reading 1 byte at pos: 0x%x\n"), filePos); |
|
2963 |
nRes = file64.Read(buf, 1); //-- read 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file |
|
2964 |
test(nRes == KErrNone); |
|
2965 |
test(buf.Length() == 1 && buf[0]=='z'); |
|
2966 |
||
2967 |
nRes = file64.Read(buf, 1); //-- read 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail |
|
2968 |
test(nRes == KErrNone); |
|
2969 |
test(buf.Length() == 0); |
|
2970 |
||
2971 |
file64.Close(); |
|
2972 |
||
2973 |
test.Printf(_L("test writing to the last bytes of the file (absolute pos addressing) \n")); |
|
2974 |
//-- 2. writing using absolute position |
|
2975 |
nRes = file64.Open(TheFs, KFileName, EFileWrite); |
|
2976 |
test(nRes == KErrNone); |
|
2977 |
||
2978 |
filePos = fileSize-1; |
|
2979 |
||
2980 |
nRes = file64.Write(filePos-2, _L8("0"), 1); //-- write 1 byte a pos 0xFFFFFFFC |
|
2981 |
test(nRes == KErrNone); |
|
2982 |
||
2983 |
nRes = file64.Write(filePos, _L8("a"), 1); //-- write 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file |
|
2984 |
test(nRes == KErrNone); |
|
2985 |
||
2986 |
nRes = file64.Write(filePos+1, _L8("b"), 1); //-- write 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail |
|
2987 |
test(nRes == KErrNotSupported); |
|
2988 |
||
2989 |
nRes = file64.Flush(); |
|
2990 |
test(nRes == KErrNone); |
|
2991 |
||
2992 |
//-- 1.1 check the result by reading data absolute rel. position |
|
2993 |
||
2994 |
nRes = file64.Read(filePos-2, buf, 1); //-- read 1 byte a pos 0xFFFFFFFD |
|
2995 |
test(nRes == KErrNone); |
|
2996 |
test(buf.Length() == 1 && buf[0]=='0'); |
|
2997 |
||
2998 |
nRes = file64.Read(filePos, buf, 1); //-- read 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file |
|
2999 |
test(nRes == KErrNone); |
|
3000 |
test(buf.Length() == 1 && buf[0]=='a'); |
|
3001 |
||
3002 |
nRes = file64.Read(filePos+1, buf, 1); //-- read 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size |
|
3003 |
test(nRes == KErrNone); |
|
3004 |
test(buf.Length() == 0); |
|
3005 |
||
3006 |
nRes = file64.Read(filePos+2, buf, 1); //buf.Len must be 0 |
|
3007 |
test(nRes == KErrNone); |
|
3008 |
test(buf.Length() == 0); |
|
3009 |
||
3010 |
file64.Close(); |
|
3011 |
||
3012 |
test.Printf(_L("deleting the huge file.\n")); |
|
3013 |
nRes = TheFs.Delete(KFileName); |
|
3014 |
test(nRes == KErrNone); |
|
3015 |
||
3016 |
#else |
|
3017 |
||
3018 |
test.Printf(_L("RFile64 is not supported! Skipping.\n")); |
|
3019 |
||
3020 |
#endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
3021 |
||
3022 |
} |
|
3023 |
||
3024 |
||
3025 |
//-------------------------------------------------------------- |
|
3026 |
||
3027 |
void CallTestsL() |
|
3028 |
{ |
|
3029 |
||
3030 |
//-- set up console output |
|
3031 |
F32_Test_Utils::SetConsole(test.Console()); |
|
3032 |
||
3033 |
TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum); |
|
3034 |
test(nRes==KErrNone); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3035 |
|
0 | 3036 |
PrintDrvInfo(TheFs, gDriveNum); |
3037 |
||
3038 |
//-- FAT Supports short file names |
|
3039 |
if(Is_Fat(TheFs, gDriveNum)) |
|
3040 |
gShortFileNamesSupported = ETrue; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3041 |
|
0 | 3042 |
if(Is_Win32(TheFs, gDriveNum)) |
3043 |
{//-- find out if this is NTFS and if it supports short names (this feature can be switched OFF) |
|
3044 |
||
3045 |
_LIT(KLongFN, "\\this is a long file name"); |
|
3046 |
nRes = CreateEmptyFile(TheFs, KLongFN, 10); |
|
3047 |
test(nRes==KErrNone); |
|
3048 |
||
3049 |
TBuf<12> shortName; |
|
3050 |
nRes = TheFs.GetShortName(KLongFN, shortName); |
|
3051 |
gShortFileNamesSupported = (nRes == KErrNone); |
|
3052 |
||
3053 |
nRes = TheFs.Delete(KLongFN); |
|
3054 |
test(nRes==KErrNone); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3055 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3056 |
DeleteTestDirectory(); |
0 | 3057 |
} |
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3058 |
else |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3059 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3060 |
nRes = FormatDrive(TheFs, gDriveNum, ETrue); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3061 |
test(nRes==KErrNone); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3062 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3063 |
|
0 | 3064 |
CreateTestDirectory(_L("\\F32-TST\\TFILE\\")); |
3065 |
||
3066 |
testFileRename(); |
|
3067 |
testSetSize(); |
|
3068 |
CopyFileToTestDirectory(); |
|
3069 |
testFileSeek(); |
|
3070 |
testMoreFileSeek(); |
|
3071 |
CopyFileToTestDirectory(); |
|
3072 |
testFileText(); |
|
3073 |
testFileTextEndRecord(); |
|
3074 |
testDeleteOpenFiles(); |
|
3075 |
testFileAttributes(); |
|
3076 |
testFileNames(); |
|
3077 |
testShare(); |
|
3078 |
testReadersWriters(); |
|
3079 |
testReadFile(); |
|
3080 |
testMultipleReadFile(); |
|
3081 |
testWriteFile(); |
|
3082 |
testChangeMode(); |
|
3083 |
testShortNameAccessorFunctions(); |
|
3084 |
testIsFileOpen(); |
|
3085 |
testMiscellaneousReportedBugs(); |
|
3086 |
testIsRomAddress(); |
|
3087 |
TestFileUids(); |
|
3088 |
TestMaxLengthFilenames(); |
|
3089 |
testINC070455(); |
|
3090 |
TestINC112803(); |
|
3091 |
testZeroLengthDescriptors(); |
|
3092 |
testNegativeLengthToWrite(); |
|
3093 |
testNegativeLength(); |
|
3094 |
testReadBufferOverflow(); |
|
3095 |
TestDeleteOnClose(); |
|
3096 |
TestFileAttributesAndCacheFlushing(); |
|
3097 |
TestMaxFileSize(); |
|
3098 |
||
3099 |
DeleteTestDirectory(); |
|
3100 |
} |
|
3101 |