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