0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// f32test\server\t_rdsect.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#define __E32TEST_EXTENSION__
|
|
19 |
|
|
20 |
#include <f32file.h>
|
|
21 |
#include <e32test.h>
|
|
22 |
|
|
23 |
#include "t_server.h"
|
|
24 |
#include "t_chlffs.h"
|
|
25 |
|
|
26 |
#if defined(__WINS__)
|
|
27 |
#define WIN32_LEAN_AND_MEAN
|
|
28 |
#pragma warning (disable:4201) // warning C4201: nonstandard extension used : nameless struct/union
|
|
29 |
#pragma warning (default:4201) // warning C4201: nonstandard extension used : nameless struct/union
|
|
30 |
#endif
|
|
31 |
|
|
32 |
#if defined(_UNICODE)
|
|
33 |
#if !defined(UNICODE)
|
|
34 |
#define UNICODE
|
|
35 |
#endif
|
|
36 |
#endif
|
|
37 |
|
|
38 |
GLDEF_D RTest test(_L("T_RDSECT"));
|
|
39 |
|
|
40 |
|
|
41 |
TBuf<26> alphaBuffer=_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
|
42 |
TBuf<10> numberBuffer=_L("0123456789");
|
|
43 |
TBuf<14> humptyBuffer=_L("Humpty-Dumpty!");
|
|
44 |
TPtr8 alphaPtr((TText8*)alphaBuffer.Ptr(),alphaBuffer.Size(),alphaBuffer.Size());
|
|
45 |
TPtr8 numberPtr((TText8*)numberBuffer.Ptr(),numberBuffer.Size(),numberBuffer.Size());
|
|
46 |
TPtr8 humptyPtr((TText8*)humptyBuffer.Ptr(),humptyBuffer.Size(),humptyBuffer.Size());
|
|
47 |
|
|
48 |
|
|
49 |
/*
|
|
50 |
|
|
51 |
What this test is for:
|
|
52 |
|
|
53 |
Tests the implementation of RFs::ReadFileSection() which has been designed
|
|
54 |
to allow reading from a file regardless of its lock state.
|
|
55 |
Under the EPOC FAT filesystem, the function accesses the raw file data without
|
|
56 |
opening the file using a share mode. This is obviously a dangerous activity
|
|
57 |
should the file be currently open for writing by another user - but the file
|
|
58 |
server makes no guarantees as to the data it returns! The function allows the
|
|
59 |
caller to specify the starting position in the file from which to read the data
|
|
60 |
and the length of data required.
|
|
61 |
|
|
62 |
This test creates a number of files and tests the use of the function when the
|
|
63 |
files are closed and when they are open in a number of access modes.
|
|
64 |
It also tests reading a UID from the files using this new function.
|
|
65 |
|
|
66 |
*/
|
|
67 |
|
|
68 |
LOCAL_C void CreateTestFiles()
|
|
69 |
//
|
|
70 |
// Create files with uids for testing
|
|
71 |
//
|
|
72 |
{
|
|
73 |
|
|
74 |
test.Next(_L("Create test files"));
|
|
75 |
TInt r=TheFs.MkDir(_L("\\F32-TST\\"));
|
|
76 |
test(r==KErrNone || r==KErrAlreadyExists);
|
|
77 |
|
|
78 |
RFile file;
|
|
79 |
|
|
80 |
// Create \\gSessionPath\\UIDCHK.BLG - with uid no data
|
|
81 |
r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.BLG"),EFileRead|EFileWrite);
|
|
82 |
test_KErrNone(r);
|
|
83 |
TUidType uidType(TUid::Uid('U'),TUid::Uid('I'),TUid::Uid('D'));
|
|
84 |
TCheckedUid checkedUid(uidType);
|
|
85 |
TPtrC8 buf((TUint8*)&checkedUid,sizeof(TCheckedUid));
|
|
86 |
r=file.Write(buf);
|
|
87 |
test_KErrNone(r);
|
|
88 |
file.Close();
|
|
89 |
|
|
90 |
// Create \\gSessionPath\\UIDCHK.MSG - with uid and data
|
|
91 |
r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.MSG"),EFileRead|EFileWrite);
|
|
92 |
test_KErrNone(r);
|
|
93 |
TUidType uidType2(TUid::Uid('X'),TUid::Uid('Y'),TUid::Uid('Z'));
|
|
94 |
checkedUid.Set(uidType2);
|
|
95 |
buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
|
|
96 |
r=file.Write(buf);
|
|
97 |
test_KErrNone(r);
|
|
98 |
r=file.Write(_L8("More file data"));
|
|
99 |
test_KErrNone(r);
|
|
100 |
file.Close();
|
|
101 |
|
|
102 |
// Create \\gSessionPath\\UIDCHK.DAT - uid stored only in the file
|
|
103 |
r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileRead|EFileWrite);
|
|
104 |
test_KErrNone(r);
|
|
105 |
TUidType uidType3(TUid::Uid('D'),TUid::Uid('A'),TUid::Uid('T'));
|
|
106 |
checkedUid.Set(uidType3);
|
|
107 |
buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
|
|
108 |
r=file.Write(buf);
|
|
109 |
test_KErrNone(r);
|
|
110 |
r=file.Write(_L8("More file data"));
|
|
111 |
test_KErrNone(r);
|
|
112 |
file.Close();
|
|
113 |
|
|
114 |
// Make a few random files - these will be deleted before the test begins
|
|
115 |
// but are necessary to try to split file ReadFileSection into non-contiguous clusters
|
|
116 |
|
|
117 |
r=file.Replace(TheFs,_L("\\F32-TST\\Temp1.txt"),EFileRead|EFileWrite);
|
|
118 |
test_KErrNone(r);
|
|
119 |
file.SetSize(550);
|
|
120 |
file.Close();
|
|
121 |
|
|
122 |
r=file.Replace(TheFs,_L("\\F32-TST\\Temp2.txt"),EFileRead|EFileWrite);
|
|
123 |
test_KErrNone(r);
|
|
124 |
file.SetSize(256);
|
|
125 |
file.Close();
|
|
126 |
|
|
127 |
r=file.Replace(TheFs,_L("\\F32-TST\\Temp3.txt"),EFileRead|EFileWrite);
|
|
128 |
test_KErrNone(r);
|
|
129 |
file.SetSize(256);
|
|
130 |
file.Close();
|
|
131 |
|
|
132 |
r=file.Replace(TheFs,_L("\\F32-TST\\Temp4.txt"),EFileRead|EFileWrite);
|
|
133 |
test_KErrNone(r);
|
|
134 |
file.SetSize(550);
|
|
135 |
file.Close();
|
|
136 |
|
|
137 |
r=file.Replace(TheFs,_L("\\F32-TST\\Temp5.txt"),EFileRead|EFileWrite);
|
|
138 |
test_KErrNone(r);
|
|
139 |
file.SetSize(256);
|
|
140 |
file.Close();
|
|
141 |
|
|
142 |
r=file.Replace(TheFs,_L("\\F32-TST\\Temp6.txt"),EFileRead|EFileWrite);
|
|
143 |
test_KErrNone(r);
|
|
144 |
file.SetSize(256);
|
|
145 |
file.Close();
|
|
146 |
|
|
147 |
r=file.Replace(TheFs,_L("\\F32-TST\\Temp7.txt"),EFileRead|EFileWrite);
|
|
148 |
test_KErrNone(r);
|
|
149 |
file.SetSize(256);
|
|
150 |
file.Close();
|
|
151 |
|
|
152 |
r=file.Replace(TheFs,_L("\\F32-TST\\Temp8.txt"),EFileRead|EFileWrite);
|
|
153 |
test_KErrNone(r);
|
|
154 |
file.SetSize(256);
|
|
155 |
file.Close();
|
|
156 |
|
|
157 |
r=file.Replace(TheFs,_L("\\F32-TST\\Temp9.txt"),EFileRead|EFileWrite);
|
|
158 |
test_KErrNone(r);
|
|
159 |
file.SetSize(256);
|
|
160 |
file.Close();
|
|
161 |
|
|
162 |
r=file.Replace(TheFs,_L("\\F32-TST\\Temp10.txt"),EFileRead|EFileWrite);
|
|
163 |
test_KErrNone(r);
|
|
164 |
file.SetSize(256);
|
|
165 |
file.Close();
|
|
166 |
|
|
167 |
TheFs.Delete(_L("\\F32-TST\\Temp2.txt"));
|
|
168 |
TheFs.Delete(_L("\\F32-TST\\Temp4.txt"));
|
|
169 |
TheFs.Delete(_L("\\F32-TST\\Temp6.txt"));
|
|
170 |
TheFs.Delete(_L("\\F32-TST\\Temp8.txt"));
|
|
171 |
TheFs.Delete(_L("\\F32-TST\\Temp10.txt"));
|
|
172 |
|
|
173 |
r=file.Replace(TheFs,_L("\\F32-TST\\ReadFileSection1.txt"),EFileRead|EFileWrite);
|
|
174 |
test_KErrNone(r);
|
|
175 |
|
|
176 |
// Write 5000 bytes of nonsense
|
|
177 |
|
|
178 |
TInt i=0;
|
|
179 |
for ( ; i<100; i++)
|
|
180 |
{
|
|
181 |
r=file.Write(alphaPtr);
|
|
182 |
test_KErrNone(r);
|
|
183 |
r=file.Write(numberPtr);
|
|
184 |
test_KErrNone(r);
|
|
185 |
r=file.Write(humptyPtr);
|
|
186 |
test_KErrNone(r);
|
|
187 |
}
|
|
188 |
|
|
189 |
file.Close();
|
|
190 |
|
|
191 |
TheFs.Delete(_L("\\F32-TST\\Temp1.txt"));
|
|
192 |
TheFs.Delete(_L("\\F32-TST\\Temp3.txt"));
|
|
193 |
TheFs.Delete(_L("\\F32-TST\\Temp5.txt"));
|
|
194 |
TheFs.Delete(_L("\\F32-TST\\Temp7.txt"));
|
|
195 |
TheFs.Delete(_L("\\F32-TST\\Temp9.txt"));
|
|
196 |
}
|
|
197 |
|
|
198 |
#if !defined(_UNICODE)
|
|
199 |
|
|
200 |
LOCAL_C void Test1()
|
|
201 |
//
|
|
202 |
// Test RFs::ReadFileSection()
|
|
203 |
//
|
|
204 |
{
|
|
205 |
|
|
206 |
test.Next(_L("Use RFs::ReadFileSection() to read from a file"));
|
|
207 |
|
|
208 |
// First, test for non-existant file
|
|
209 |
TBuf<256> testDes;
|
|
210 |
TInt r=TheFs.ReadFileSection(_L("\\F32-tst\\NonExistantFile.txt"),0,testDes,52);
|
|
211 |
test(r==KErrNotFound);
|
|
212 |
test(testDes.Length()==0);
|
|
213 |
|
|
214 |
// Test with file closed
|
|
215 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,testDes,26);
|
|
216 |
test_KErrNone(r);
|
|
217 |
test(testDes.Length()==26);
|
|
218 |
test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
219 |
|
|
220 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),26,testDes,10);
|
|
221 |
test_KErrNone(r);
|
|
222 |
test(testDes==_L("0123456789"));
|
|
223 |
test(testDes.Length()==10);
|
|
224 |
|
|
225 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),36,testDes,14);
|
|
226 |
test_KErrNone(r);
|
|
227 |
test(testDes==_L("Humpty-Dumpty!"));
|
|
228 |
test(testDes.Length()==14);
|
|
229 |
|
|
230 |
// Test with file open EFileShareAny|EFileRead
|
|
231 |
RFile file;
|
|
232 |
r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileRead);
|
|
233 |
test_KErrNone(r);
|
|
234 |
|
|
235 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),50,testDes,26);
|
|
236 |
test_KErrNone(r);
|
|
237 |
test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
238 |
test(testDes.Length()==26);
|
|
239 |
|
|
240 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),76,testDes,10);
|
|
241 |
test_KErrNone(r);
|
|
242 |
test(testDes==_L("0123456789"));
|
|
243 |
test(testDes.Length()==10);
|
|
244 |
|
|
245 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),86,testDes,14);
|
|
246 |
test_KErrNone(r);
|
|
247 |
test(testDes==_L("Humpty-Dumpty!"));
|
|
248 |
test(testDes.Length()==14);
|
|
249 |
|
|
250 |
file.Close();
|
|
251 |
|
|
252 |
// Test with file open EFileShareExclusive|EFileRead
|
|
253 |
r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareExclusive|EFileRead);
|
|
254 |
test_KErrNone(r);
|
|
255 |
|
|
256 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),100,testDes,26);
|
|
257 |
test_KErrNone(r);
|
|
258 |
test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
259 |
test(testDes.Length()==26);
|
|
260 |
|
|
261 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),126,testDes,10);
|
|
262 |
test_KErrNone(r);
|
|
263 |
test(testDes==_L("0123456789"));
|
|
264 |
test(testDes.Length()==10);
|
|
265 |
|
|
266 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),136,testDes,14);
|
|
267 |
test_KErrNone(r);
|
|
268 |
test(testDes==_L("Humpty-Dumpty!"));
|
|
269 |
test(testDes.Length()==14);
|
|
270 |
|
|
271 |
file.Close();
|
|
272 |
|
|
273 |
// Test with file open EFileShareExclusive|EFileWrite
|
|
274 |
r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareExclusive|EFileWrite);
|
|
275 |
test_KErrNone(r);
|
|
276 |
|
|
277 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),150,testDes,26);
|
|
278 |
test_KErrNone(r);
|
|
279 |
test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
280 |
test(testDes.Length()==26);
|
|
281 |
|
|
282 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),176,testDes,10);
|
|
283 |
test_KErrNone(r);
|
|
284 |
test(testDes==_L("0123456789"));
|
|
285 |
test(testDes.Length()==10);
|
|
286 |
|
|
287 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),186,testDes,14);
|
|
288 |
test_KErrNone(r);
|
|
289 |
test(testDes==_L("Humpty-Dumpty!"));
|
|
290 |
test(testDes.Length()==14);
|
|
291 |
|
|
292 |
file.Close();
|
|
293 |
|
|
294 |
|
|
295 |
// Test with file open EFileShareReadersOnly|EFileRead
|
|
296 |
r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareReadersOnly|EFileRead);
|
|
297 |
test_KErrNone(r);
|
|
298 |
|
|
299 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),200,testDes,26);
|
|
300 |
test_KErrNone(r);
|
|
301 |
test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
302 |
test(testDes.Length()==26);
|
|
303 |
|
|
304 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),226,testDes,10);
|
|
305 |
test_KErrNone(r);
|
|
306 |
test(testDes==_L("0123456789"));
|
|
307 |
test(testDes.Length()==10);
|
|
308 |
|
|
309 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),236,testDes,14);
|
|
310 |
test_KErrNone(r);
|
|
311 |
test(testDes==_L("Humpty-Dumpty!"));
|
|
312 |
test(testDes.Length()==14);
|
|
313 |
|
|
314 |
file.Close();
|
|
315 |
|
|
316 |
// Test with several accesses to a file EFileShareAny|EFileWrite
|
|
317 |
r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
|
|
318 |
test_KErrNone(r);
|
|
319 |
|
|
320 |
RFile secondFile;
|
|
321 |
r=secondFile.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
|
|
322 |
test_KErrNone(r);
|
|
323 |
|
|
324 |
RFile thirdFile;
|
|
325 |
r=thirdFile.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
|
|
326 |
test_KErrNone(r);
|
|
327 |
|
|
328 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),250,testDes,26);
|
|
329 |
test_KErrNone(r);
|
|
330 |
test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
331 |
test(testDes.Length()==26);
|
|
332 |
|
|
333 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),276,testDes,10);
|
|
334 |
test_KErrNone(r);
|
|
335 |
test(testDes==_L("0123456789"));
|
|
336 |
test(testDes.Length()==10);
|
|
337 |
|
|
338 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),286,testDes,14);
|
|
339 |
test_KErrNone(r);
|
|
340 |
test(testDes==_L("Humpty-Dumpty!"));
|
|
341 |
test(testDes.Length()==14);
|
|
342 |
|
|
343 |
// Test across potential cluster boundaries
|
|
344 |
|
|
345 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),500,testDes,100);
|
|
346 |
test_KErrNone(r);
|
|
347 |
test(testDes.Length()==100);
|
|
348 |
test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!"));
|
|
349 |
|
|
350 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),1000,testDes,100);
|
|
351 |
test_KErrNone(r);
|
|
352 |
test(testDes.Length()==100);
|
|
353 |
test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!"));
|
|
354 |
|
|
355 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),1500,testDes,100);
|
|
356 |
test_KErrNone(r);
|
|
357 |
test(testDes.Length()==100);
|
|
358 |
test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!"));
|
|
359 |
|
|
360 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,testDes,100);
|
|
361 |
test_KErrNone(r);
|
|
362 |
test(testDes.Length()==100);
|
|
363 |
test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!"));
|
|
364 |
|
|
365 |
file.Close();
|
|
366 |
secondFile.Close();
|
|
367 |
thirdFile.Close();
|
|
368 |
}
|
|
369 |
|
|
370 |
|
|
371 |
LOCAL_C void Test2()
|
|
372 |
//
|
|
373 |
// Test RFs::ReadFileSection() on UID reads
|
|
374 |
//
|
|
375 |
{
|
|
376 |
|
|
377 |
|
|
378 |
test.Next(_L("Use RFs::ReadFileSection() to read UIDs from files"));
|
|
379 |
|
|
380 |
TBuf8<sizeof(TCheckedUid)> uidBuf(sizeof(TCheckedUid));
|
|
381 |
TPtr uidPtr((TText*)uidBuf.Ptr(),sizeof(TCheckedUid),sizeof(TCheckedUid));
|
|
382 |
|
|
383 |
TInt r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.BLG"),0,uidPtr,sizeof(TCheckedUid));
|
|
384 |
test_KErrNone(r);
|
|
385 |
TCheckedUid uid(uidBuf);
|
|
386 |
TUidType uidType=uid.UidType();
|
|
387 |
test(uidType.IsValid());
|
|
388 |
|
|
389 |
test(uidType[0]==TUid::Uid('U') && uidType[1]==TUid::Uid('I') && uidType[2]==TUid::Uid('D'));
|
|
390 |
|
|
391 |
r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.MSG"),0,uidBuf,sizeof(TCheckedUid));
|
|
392 |
test_KErrNone(r);
|
|
393 |
uid.Set(uidBuf);
|
|
394 |
uidType=uid.UidType();
|
|
395 |
test(uidType.IsValid());
|
|
396 |
test(uidType[0]==TUid::Uid('X') && uidType[1]==TUid::Uid('Y') && uidType[2]==TUid::Uid('Z'));
|
|
397 |
|
|
398 |
|
|
399 |
// Test for Null File length
|
|
400 |
TBuf8<256> testDesN;
|
|
401 |
test.Next(_L("Check for null file name"));
|
|
402 |
r=TheFs.ReadFileSection(_L(""),0,testDesN,26);
|
|
403 |
test(r==KErrBadName);
|
|
404 |
|
|
405 |
// Check the lentgh of descriptor.
|
|
406 |
TInt x = testDesN.Length();
|
|
407 |
test ( x == 0);
|
|
408 |
|
|
409 |
test.Next(_L("Check for non existing file"));
|
|
410 |
r=TheFs.ReadFileSection(_L("sdfsd.dfg"),0,testDesN,26);
|
|
411 |
test.Printf(_L("Return %d"),r);
|
|
412 |
test((r==KErrNotFound) || (r == KErrPathNotFound));
|
|
413 |
|
|
414 |
// Check the lentgh of descriptor.
|
|
415 |
x = testDesN.Length();
|
|
416 |
test ( x == 0);
|
|
417 |
|
|
418 |
r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
|
|
419 |
test_KErrNone(r);
|
|
420 |
uid.Set(uidBuf);
|
|
421 |
uidType=uid.UidType();
|
|
422 |
test(uidType.IsValid());
|
|
423 |
test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
|
|
424 |
|
|
425 |
|
|
426 |
}
|
|
427 |
|
|
428 |
LOCAL_C void Test3()
|
|
429 |
//
|
|
430 |
// Test uid's can be read when the file is open
|
|
431 |
//
|
|
432 |
// EFileShareExclusive,EFileShareReadersOnly,EFileShareAny,
|
|
433 |
// EFileStream=0,EFileStreamText=0x100,
|
|
434 |
// EFileRead=0,EFileWrite=0x200
|
|
435 |
//
|
|
436 |
{
|
|
437 |
|
|
438 |
test.Next(_L("Test that UIDs can be read from open files"));
|
|
439 |
RFile file;
|
|
440 |
|
|
441 |
// Test with file open EFileShareExclusive|EFileRead
|
|
442 |
TInt r=file.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareExclusive|EFileRead);
|
|
443 |
test_KErrNone(r);
|
|
444 |
|
|
445 |
TBuf8<sizeof(TCheckedUid)> uidBuf;
|
|
446 |
|
|
447 |
r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
|
|
448 |
test_KErrNone(r);
|
|
449 |
|
|
450 |
TCheckedUid uid(uidBuf);
|
|
451 |
TUidType uidType=uid.UidType();
|
|
452 |
test(uidType.IsValid());
|
|
453 |
test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
|
|
454 |
|
|
455 |
file.Close();
|
|
456 |
|
|
457 |
// Test with file open EFileShareExclusive|EFileWrite
|
|
458 |
r=file.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareExclusive|EFileWrite);
|
|
459 |
test_KErrNone(r);
|
|
460 |
|
|
461 |
r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
|
|
462 |
test_KErrNone(r);
|
|
463 |
uid.Set(uidBuf);
|
|
464 |
uidType=uid.UidType();
|
|
465 |
test(uidType.IsValid());
|
|
466 |
test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
|
|
467 |
|
|
468 |
file.Close();
|
|
469 |
|
|
470 |
// Test with file open EFileShareReadersOnly|EFileRead
|
|
471 |
r=file.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareReadersOnly|EFileRead);
|
|
472 |
test_KErrNone(r);
|
|
473 |
|
|
474 |
r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
|
|
475 |
test_KErrNone(r);
|
|
476 |
uid.Set(uidBuf);
|
|
477 |
uidType=uid.UidType();
|
|
478 |
test(uidType.IsValid());
|
|
479 |
test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
|
|
480 |
|
|
481 |
file.Close();
|
|
482 |
|
|
483 |
|
|
484 |
// Test with file open EFileShareAny|EFileRead
|
|
485 |
r=file.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareAny|EFileRead);
|
|
486 |
test_KErrNone(r);
|
|
487 |
|
|
488 |
r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
|
|
489 |
test_KErrNone(r);
|
|
490 |
uid.Set(uidBuf);
|
|
491 |
uidType=uid.UidType();
|
|
492 |
test(uidType.IsValid());
|
|
493 |
test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
|
|
494 |
|
|
495 |
file.Close();
|
|
496 |
|
|
497 |
// Test with several accesses to file open EFileShareAny|EFileWrite
|
|
498 |
r=file.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareAny|EFileWrite);
|
|
499 |
test_KErrNone(r);
|
|
500 |
|
|
501 |
RFile secondFile;
|
|
502 |
r=secondFile.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareAny|EFileWrite);
|
|
503 |
test_KErrNone(r);
|
|
504 |
|
|
505 |
RFile thirdFile;
|
|
506 |
r=thirdFile.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareAny|EFileRead);
|
|
507 |
test_KErrNone(r);
|
|
508 |
|
|
509 |
r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
|
|
510 |
test_KErrNone(r);
|
|
511 |
uid.Set(uidBuf);
|
|
512 |
uidType=uid.UidType();
|
|
513 |
test(uidType.IsValid());
|
|
514 |
test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
|
|
515 |
|
|
516 |
file.Close();
|
|
517 |
secondFile.Close();
|
|
518 |
thirdFile.Close();
|
|
519 |
|
|
520 |
}
|
|
521 |
|
|
522 |
|
|
523 |
LOCAL_C void TestErrors()
|
|
524 |
//
|
|
525 |
// Test errors and boundary conditions
|
|
526 |
//
|
|
527 |
{
|
|
528 |
|
|
529 |
test.Next(_L("Test Error handling"));
|
|
530 |
|
|
531 |
// Test that specifying a zero length section returns a zero length descriptor
|
|
532 |
TBuf<30> testDes;
|
|
533 |
TInt r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),25,testDes,0);
|
|
534 |
test_KErrNone(r);
|
|
535 |
test(testDes.Length()==0);
|
|
536 |
|
|
537 |
// Test that specifying a negative starting position causes a panic
|
|
538 |
// r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),-1,testDes,10);
|
|
539 |
// This will panic: See RFs::ReadFileSection() code - relevant lines are
|
|
540 |
// __ASSERT_ALWAYS(aPos>=0,Panic(EPosNegative));
|
|
541 |
|
|
542 |
// Test that specifying a section of greater length than the descriptor to
|
|
543 |
// hold the data will cause a panic
|
|
544 |
// r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,testDes,45);
|
|
545 |
// This will panic: See RFs::ReadFileSection() code - relevant lines are
|
|
546 |
// __ASSERT_ALWAYS(aDes.MaxLength()>=aLength,Panic(EBadLength));
|
|
547 |
|
|
548 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,testDes,-20);
|
|
549 |
test(r==KErrArgument);
|
|
550 |
|
|
551 |
// Test that specifying a position and length which extends beyond the end of
|
|
552 |
// the file returns a zero length descriptor and KErrNone
|
|
553 |
|
|
554 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4993,testDes,20);
|
|
555 |
test_KErrNone(r);
|
|
556 |
test(testDes.Length()==7);
|
|
557 |
test(testDes==_L("Dumpty!"));
|
|
558 |
|
|
559 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4999,testDes,1);
|
|
560 |
test_KErrNone(r);
|
|
561 |
test(testDes.Length()==1);
|
|
562 |
test(testDes==_L("!"));
|
|
563 |
|
|
564 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),5000,testDes,1);
|
|
565 |
test_KErrNone(r);
|
|
566 |
test(testDes.Length()==0);
|
|
567 |
|
|
568 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),5550,testDes,20);
|
|
569 |
test_KErrNone(r);
|
|
570 |
test(testDes.Length()==0);
|
|
571 |
|
|
572 |
// Test reading the whole file
|
|
573 |
HBufC* hDes=HBufC::New(5002);
|
|
574 |
if (!hDes)
|
|
575 |
User::Leave(KErrNoMemory);
|
|
576 |
TPtr pDes=hDes->Des();
|
|
577 |
|
|
578 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,5000);
|
|
579 |
test_KErrNone(r);
|
|
580 |
test(pDes.Length()==5000);
|
|
581 |
|
|
582 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,5000);
|
|
583 |
test_KErrNone(r);
|
|
584 |
test(pDes.Length()==5000);
|
|
585 |
|
|
586 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,5002);
|
|
587 |
test_KErrNone(r);
|
|
588 |
test(pDes.Length()==5000);
|
|
589 |
|
|
590 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,pDes,3000);
|
|
591 |
test_KErrNone(r);
|
|
592 |
test(pDes.Length()==3000);
|
|
593 |
|
|
594 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,pDes,4002);
|
|
595 |
test_KErrNone(r);
|
|
596 |
test(pDes.Length()==3000);
|
|
597 |
|
|
598 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),5000,pDes,5002);
|
|
599 |
test_KErrNone(r);
|
|
600 |
test(pDes.Length()==0);
|
|
601 |
|
|
602 |
delete hDes;
|
|
603 |
}
|
|
604 |
|
|
605 |
#else
|
|
606 |
|
|
607 |
|
|
608 |
// BEGINNING OF UNICODE TESTS
|
|
609 |
|
|
610 |
LOCAL_C void TestUnicode()
|
|
611 |
//
|
|
612 |
// Test RFs::ReadFileSection()
|
|
613 |
//
|
|
614 |
{
|
|
615 |
test.Next(_L("Use RFs::ReadFileSection() to read from a file"));
|
|
616 |
|
|
617 |
// First, test for non-existant file
|
|
618 |
TBuf8<256> testDes;
|
|
619 |
TInt r=TheFs.ReadFileSection(_L("\\F32-tst\\NonExistantFile.txt"),0,testDes,52);
|
|
620 |
test(r==KErrNotFound);
|
|
621 |
test(testDes.Length()==0);
|
|
622 |
|
|
623 |
// Test with file closed
|
|
624 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,testDes,52);
|
|
625 |
test_KErrNone(r);
|
|
626 |
test(testDes.Length()==52);
|
|
627 |
test(testDes==alphaPtr);
|
|
628 |
|
|
629 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),52,testDes,20);
|
|
630 |
test_KErrNone(r);
|
|
631 |
test(testDes==numberPtr);
|
|
632 |
test(testDes.Length()==20);
|
|
633 |
|
|
634 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),72,testDes,28);
|
|
635 |
test_KErrNone(r);
|
|
636 |
test(testDes==humptyPtr);
|
|
637 |
test(testDes.Length()==28);
|
|
638 |
|
|
639 |
// Test for Null File length
|
|
640 |
TBuf8<256> testDesN;
|
|
641 |
test.Next(_L("Check for null file name"));
|
|
642 |
r=TheFs.ReadFileSection(_L(""),0,testDesN,26);
|
|
643 |
test(r==KErrBadName);
|
|
644 |
|
|
645 |
// Check the lentgh of descriptor.
|
|
646 |
TInt x = testDesN.Length();
|
|
647 |
test ( x == 0);
|
|
648 |
|
|
649 |
test.Next(_L("Check for non existing file"));
|
|
650 |
r=TheFs.ReadFileSection(_L("sdfsd.dfg"),0,testDesN,26);
|
|
651 |
test.Printf(_L("Return %d"),r);
|
|
652 |
test((r==KErrNotFound) || (r == KErrPathNotFound));
|
|
653 |
|
|
654 |
// Check the lentgh of descriptor.
|
|
655 |
x = testDesN.Length();
|
|
656 |
test ( x == 0);
|
|
657 |
|
|
658 |
// Test for Empty directory
|
|
659 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\"),0,testDesN,52);
|
|
660 |
test(r==KErrBadName);
|
|
661 |
test(testDesN.Length()==0);
|
|
662 |
|
|
663 |
// Test for File with wildcard name
|
|
664 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\*.txt"),0,testDesN,52);
|
|
665 |
test(r==KErrBadName);
|
|
666 |
test(testDesN.Length()==0);
|
|
667 |
|
|
668 |
// Test for Folder with wildcard name
|
|
669 |
r=TheFs.ReadFileSection(_L("\\F32-tst*\\ReadFileSection1.txt"),0,testDesN,52);
|
|
670 |
test(r==KErrBadName);
|
|
671 |
test(testDesN.Length()==0);
|
|
672 |
|
|
673 |
// Test for Root directory
|
|
674 |
r=TheFs.ReadFileSection(_L("\\"),0,testDesN,52);
|
|
675 |
test(r==KErrBadName);
|
|
676 |
test(testDesN.Length()==0);
|
|
677 |
|
|
678 |
// Test for no file being specified.
|
|
679 |
r=TheFs.ReadFileSection(_L(""),0,testDesN,26);
|
|
680 |
test(r==KErrBadName);
|
|
681 |
test(testDesN.Length()==0);
|
|
682 |
|
|
683 |
|
|
684 |
// Test with file open EFileShareAny|EFileRead
|
|
685 |
RFile file;
|
|
686 |
r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileRead);
|
|
687 |
test_KErrNone(r);
|
|
688 |
|
|
689 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),100,testDes,52);
|
|
690 |
test_KErrNone(r);
|
|
691 |
test(testDes==alphaPtr);
|
|
692 |
test(testDes.Length()==52);
|
|
693 |
|
|
694 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),152,testDes,20);
|
|
695 |
test_KErrNone(r);
|
|
696 |
test(testDes==numberPtr);
|
|
697 |
test(testDes.Length()==20);
|
|
698 |
|
|
699 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),172,testDes,28);
|
|
700 |
test_KErrNone(r);
|
|
701 |
test(testDes==humptyPtr);
|
|
702 |
test(testDes.Length()==28);
|
|
703 |
|
|
704 |
file.Close();
|
|
705 |
|
|
706 |
// Test with file open EFileShareExclusive|EFileRead
|
|
707 |
r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareExclusive|EFileRead);
|
|
708 |
test_KErrNone(r);
|
|
709 |
|
|
710 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),200,testDes,52);
|
|
711 |
test_KErrNone(r);
|
|
712 |
test(testDes==alphaPtr);
|
|
713 |
test(testDes.Length()==52);
|
|
714 |
|
|
715 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),252,testDes,20);
|
|
716 |
test_KErrNone(r);
|
|
717 |
test(testDes==numberPtr);
|
|
718 |
test(testDes.Length()==20);
|
|
719 |
|
|
720 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),272,testDes,28);
|
|
721 |
test_KErrNone(r);
|
|
722 |
test(testDes==humptyPtr);
|
|
723 |
test(testDes.Length()==28);
|
|
724 |
|
|
725 |
file.Close();
|
|
726 |
|
|
727 |
// Test with file open EFileShareExclusive|EFileWrite
|
|
728 |
r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareExclusive|EFileWrite);
|
|
729 |
test_KErrNone(r);
|
|
730 |
|
|
731 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),300,testDes,52);
|
|
732 |
test_KErrNone(r);
|
|
733 |
test(testDes==alphaPtr);
|
|
734 |
test(testDes.Length()==52);
|
|
735 |
|
|
736 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),352,testDes,20);
|
|
737 |
test_KErrNone(r);
|
|
738 |
test(testDes==numberPtr);
|
|
739 |
test(testDes.Length()==20);
|
|
740 |
|
|
741 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),372,testDes,28);
|
|
742 |
test_KErrNone(r);
|
|
743 |
test(testDes==humptyPtr);
|
|
744 |
test(testDes.Length()==28);
|
|
745 |
|
|
746 |
file.Close();
|
|
747 |
|
|
748 |
|
|
749 |
// Test with file open EFileShareReadersOnly|EFileRead
|
|
750 |
r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareReadersOnly|EFileRead);
|
|
751 |
test_KErrNone(r);
|
|
752 |
|
|
753 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),400,testDes,52);
|
|
754 |
test_KErrNone(r);
|
|
755 |
test(testDes==alphaPtr);
|
|
756 |
test(testDes.Length()==52);
|
|
757 |
|
|
758 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),452,testDes,20);
|
|
759 |
test_KErrNone(r);
|
|
760 |
test(testDes==numberPtr);
|
|
761 |
test(testDes.Length()==20);
|
|
762 |
|
|
763 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),472,testDes,28);
|
|
764 |
test_KErrNone(r);
|
|
765 |
test(testDes==humptyPtr);
|
|
766 |
test(testDes.Length()==28);
|
|
767 |
|
|
768 |
file.Close();
|
|
769 |
|
|
770 |
// Test with several accesses to a file EFileShareAny|EFileWrite
|
|
771 |
r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
|
|
772 |
test_KErrNone(r);
|
|
773 |
|
|
774 |
RFile secondFile;
|
|
775 |
r=secondFile.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
|
|
776 |
test_KErrNone(r);
|
|
777 |
|
|
778 |
RFile thirdFile;
|
|
779 |
r=thirdFile.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
|
|
780 |
test_KErrNone(r);
|
|
781 |
|
|
782 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),500,testDes,52);
|
|
783 |
test_KErrNone(r);
|
|
784 |
|
|
785 |
#if defined(__WINS__)
|
|
786 |
#if defined(_DEBUG)
|
|
787 |
test(testDes==alphaPtr);
|
|
788 |
test(testDes.Length()==52);
|
|
789 |
#endif
|
|
790 |
#else
|
|
791 |
test(testDes==alphaPtr);
|
|
792 |
test(testDes.Length()==52);
|
|
793 |
#endif
|
|
794 |
|
|
795 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),552,testDes,20);
|
|
796 |
test_KErrNone(r);
|
|
797 |
test(testDes==numberPtr);
|
|
798 |
test(testDes.Length()==20);
|
|
799 |
|
|
800 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),572,testDes,28);
|
|
801 |
test_KErrNone(r);
|
|
802 |
test(testDes==humptyPtr);
|
|
803 |
test(testDes.Length()==28);
|
|
804 |
|
|
805 |
// Test across potential cluster boundaries
|
|
806 |
|
|
807 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),1000,testDes,200);
|
|
808 |
test_KErrNone(r);
|
|
809 |
test(testDes.Length()==200);
|
|
810 |
TBuf8<200> amalgam;
|
|
811 |
TInt i=0;
|
|
812 |
for (; i<2; i++)
|
|
813 |
{
|
|
814 |
amalgam.Append(alphaPtr);
|
|
815 |
amalgam.Append(numberPtr);
|
|
816 |
amalgam.Append(humptyPtr);
|
|
817 |
}
|
|
818 |
|
|
819 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),1000,testDes,200);
|
|
820 |
test_KErrNone(r);
|
|
821 |
test(testDes.Length()==200);
|
|
822 |
test(testDes==amalgam);
|
|
823 |
|
|
824 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),3000,testDes,200);
|
|
825 |
test_KErrNone(r);
|
|
826 |
test(testDes.Length()==200);
|
|
827 |
test(testDes==amalgam);
|
|
828 |
|
|
829 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4000,testDes,200);
|
|
830 |
test_KErrNone(r);
|
|
831 |
test(testDes.Length()==200);
|
|
832 |
test(testDes==amalgam);
|
|
833 |
|
|
834 |
file.Close();
|
|
835 |
secondFile.Close();
|
|
836 |
thirdFile.Close();
|
|
837 |
|
|
838 |
// Test errors and boundary conditions
|
|
839 |
test.Next(_L("Test Error handling"));
|
|
840 |
|
|
841 |
// Test that specifying a zero length section returns a zero length descriptor
|
|
842 |
TBuf8<30> testDes2;
|
|
843 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),50,testDes2,0);
|
|
844 |
test_KErrNone(r);
|
|
845 |
test(testDes2.Length()==0);
|
|
846 |
|
|
847 |
// Test that specifying a negative starting position causes a panic
|
|
848 |
// r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),-1,testDes2,10);
|
|
849 |
// This will panic: See RFs::ReadFileSection() code - relevant lines are
|
|
850 |
// __ASSERT_ALWAYS(aPos>=0,Panic(EPosNegative));
|
|
851 |
|
|
852 |
// Test that specifying a section of greater length than the descriptor to
|
|
853 |
// hold the data will cause a panic
|
|
854 |
// r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,testDes2,45);
|
|
855 |
// This will panic: See RFs::ReadFileSection() code - relevant lines are
|
|
856 |
// __ASSERT_ALWAYS(aDes.MaxLength()>=aLength,Panic(EBadLength));
|
|
857 |
|
|
858 |
|
|
859 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,testDes2,-20);
|
|
860 |
test(r==KErrArgument);
|
|
861 |
|
|
862 |
// Test that specifying a position and length which extends beyond the end of
|
|
863 |
// the file returns a zero length descriptor and KErrNone
|
|
864 |
|
|
865 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),9993,testDes2,30);
|
|
866 |
test_KErrNone(r);
|
|
867 |
test(testDes2.Length()==7);
|
|
868 |
test(testDes2==humptyPtr.Right(7));
|
|
869 |
|
|
870 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),9999,testDes2,1);
|
|
871 |
test_KErrNone(r);
|
|
872 |
test(testDes2.Length()==1);
|
|
873 |
test(testDes2==humptyPtr.Right(1));
|
|
874 |
|
|
875 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),10000,testDes2,1);
|
|
876 |
test_KErrNone(r);
|
|
877 |
test(testDes2.Length()==0);
|
|
878 |
|
|
879 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),10550,testDes2,20);
|
|
880 |
test_KErrNone(r);
|
|
881 |
test(testDes2.Length()==0);
|
|
882 |
|
|
883 |
// Test reading the whole file
|
|
884 |
HBufC8* hDes=HBufC8::New(10002);
|
|
885 |
if (!hDes)
|
|
886 |
User::Leave(KErrNoMemory);
|
|
887 |
TPtr8 pDes=hDes->Des();
|
|
888 |
|
|
889 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,10000);
|
|
890 |
test_KErrNone(r);
|
|
891 |
test(pDes.Length()==10000);
|
|
892 |
|
|
893 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,10000);
|
|
894 |
test_KErrNone(r);
|
|
895 |
test(pDes.Length()==10000);
|
|
896 |
|
|
897 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,10002);
|
|
898 |
test_KErrNone(r);
|
|
899 |
test(pDes.Length()==10000);
|
|
900 |
|
|
901 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4000,pDes,6000);
|
|
902 |
test_KErrNone(r);
|
|
903 |
test(pDes.Length()==6000);
|
|
904 |
|
|
905 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4000,pDes,8002);
|
|
906 |
test_KErrNone(r);
|
|
907 |
test(pDes.Length()==6000);
|
|
908 |
|
|
909 |
r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),10000,pDes,10002);
|
|
910 |
test_KErrNone(r);
|
|
911 |
test(pDes.Length()==0);
|
|
912 |
|
|
913 |
delete hDes;
|
|
914 |
}
|
|
915 |
|
|
916 |
#endif
|
|
917 |
|
|
918 |
|
|
919 |
LOCAL_C void TestZ()
|
|
920 |
//
|
|
921 |
// Test Rom filesystem
|
|
922 |
//
|
|
923 |
{
|
|
924 |
test.Next(_L("Use RFs::ReadFileSection() to read from a file on the ROM"));
|
|
925 |
#if defined (__WINS__)
|
|
926 |
// Requires a copy of t_rdsect.txt in z directory (\EPOC32\RELEASE\WINS\BUILD\Z\TEST)
|
|
927 |
// Initially, test with file closed
|
|
928 |
TBuf8<256> testDes;
|
|
929 |
TBuf8<27> temp1;
|
|
930 |
TInt r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),0,temp1,26);
|
|
931 |
test_KErrNone(r);
|
|
932 |
test(temp1.Length()==26);
|
|
933 |
test(temp1==_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
934 |
|
|
935 |
TBuf8<11> temp2;
|
|
936 |
r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),26,temp2,10);
|
|
937 |
test_KErrNone(r);
|
|
938 |
test(temp2==_L8("0123456789"));
|
|
939 |
test(temp2.Length()==10);
|
|
940 |
|
|
941 |
r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),36,testDes,14);
|
|
942 |
test_KErrNone(r);
|
|
943 |
test(testDes==_L8("Humpty-Dumpty!"));
|
|
944 |
test(testDes.Length()==14);
|
|
945 |
|
|
946 |
// Test with file open EFileShareAny|EFileRead
|
|
947 |
RFile file;
|
|
948 |
r=file.Open(TheFs,_L("Z:\\test\\t_rdsect.txt"),EFileShareAny|EFileRead);
|
|
949 |
test_KErrNone(r);
|
|
950 |
|
|
951 |
r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),50,testDes,26);
|
|
952 |
test_KErrNone(r);
|
|
953 |
test(testDes==_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
954 |
test(testDes.Length()==26);
|
|
955 |
|
|
956 |
r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),76,testDes,10);
|
|
957 |
test_KErrNone(r);
|
|
958 |
test(testDes==_L8("0123456789"));
|
|
959 |
test(testDes.Length()==10);
|
|
960 |
|
|
961 |
r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),86,testDes,14);
|
|
962 |
test_KErrNone(r);
|
|
963 |
test(testDes==_L8("Humpty-Dumpty!"));
|
|
964 |
test(testDes.Length()==14);
|
|
965 |
|
|
966 |
file.Close();
|
|
967 |
#else
|
|
968 |
// Test for MARM builds - oby file puts file in ROM (z:\test\)
|
|
969 |
// The file is the ASCII version
|
|
970 |
|
|
971 |
test.Next(_L("read small descriptor\n"));
|
|
972 |
TBuf8<256> testDes;
|
|
973 |
TBuf8<27> temp1;
|
|
974 |
TInt r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),0,temp1,26);
|
|
975 |
test_KErrNone(r);
|
|
976 |
test(temp1.Length()==26);
|
|
977 |
test(temp1==_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
978 |
|
|
979 |
TBuf8<11> temp2;
|
|
980 |
r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),26,temp2,10);
|
|
981 |
test_KErrNone(r);
|
|
982 |
test(temp2.Length()==10);
|
|
983 |
#if !defined (UNICODE)
|
|
984 |
test(testDes==_L8("0123456789"));
|
|
985 |
#endif
|
|
986 |
r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),36,testDes,14);
|
|
987 |
test_KErrNone(r);
|
|
988 |
test(testDes.Length()==14);
|
|
989 |
#if !defined (UNICODE)
|
|
990 |
test(testDes==_L8("Humpty-Dumpty!"));
|
|
991 |
#endif
|
|
992 |
r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),50,testDes,26);
|
|
993 |
test_KErrNone(r);
|
|
994 |
test(testDes.Length()==26);
|
|
995 |
#if !defined (UNICODE)
|
|
996 |
test(testDes==_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
997 |
#endif
|
|
998 |
r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),76,testDes,10);
|
|
999 |
test_KErrNone(r);
|
|
1000 |
test(testDes.Length()==10);
|
|
1001 |
#if !defined (UNICODE)
|
|
1002 |
test(testDes==_L8("0123456789"));
|
|
1003 |
#endif
|
|
1004 |
r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),86,testDes,14);
|
|
1005 |
test_KErrNone(r);
|
|
1006 |
test(testDes.Length()==14);
|
|
1007 |
#if !defined (UNICODE)
|
|
1008 |
test(testDes==_L8("Humpty-Dumpty!"));
|
|
1009 |
#endif
|
|
1010 |
#endif
|
|
1011 |
}
|
|
1012 |
|
|
1013 |
LOCAL_C void DoTestsL()
|
|
1014 |
//
|
|
1015 |
// Do all tests
|
|
1016 |
//
|
|
1017 |
{
|
|
1018 |
CreateTestFiles();
|
|
1019 |
#if !defined (_UNICODE)
|
|
1020 |
Test1();
|
|
1021 |
Test2();
|
|
1022 |
Test3();
|
|
1023 |
TestErrors();
|
|
1024 |
#else
|
|
1025 |
TestUnicode();
|
|
1026 |
#endif
|
|
1027 |
TestZ();
|
|
1028 |
}
|
|
1029 |
|
|
1030 |
GLDEF_C void CallTestsL(void)
|
|
1031 |
//
|
|
1032 |
// Test formatting
|
|
1033 |
//
|
|
1034 |
{
|
|
1035 |
|
|
1036 |
test.Title();
|
|
1037 |
test.Start(_L("Testing filesystem on default drive"));
|
|
1038 |
|
|
1039 |
TChar driveLetter;
|
|
1040 |
if (IsSessionDriveLFFS(TheFs,driveLetter))
|
|
1041 |
{
|
|
1042 |
test.Printf(_L("CallTestsL: Skipped: test does not run on LFFS.\n"));
|
|
1043 |
return;
|
|
1044 |
}
|
|
1045 |
|
|
1046 |
DoTestsL();
|
|
1047 |
CheckDisk();
|
|
1048 |
|
|
1049 |
test.End();
|
|
1050 |
test.Close();
|
|
1051 |
return;
|
|
1052 |
}
|
|
1053 |
|