sl@0
|
1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// f32test\server\t_rand.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <f32file.h>
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
#include <e32math.h>
|
sl@0
|
21 |
#include <e32hal.h>
|
sl@0
|
22 |
#include "t_server.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
GLDEF_D RTest test(_L("T_RAND"));
|
sl@0
|
25 |
|
sl@0
|
26 |
LOCAL_D TBuf8<512> testBuf(512);
|
sl@0
|
27 |
LOCAL_D TInt64 TheSeed=917824;
|
sl@0
|
28 |
LOCAL_D TInt KMaxIteration;
|
sl@0
|
29 |
LOCAL_D const TInt KMaxFiles=4;
|
sl@0
|
30 |
LOCAL_D const TInt KMaxLengthIncrement=7770;
|
sl@0
|
31 |
LOCAL_D const TInt mult[] = { 1, 5, 13, 37};
|
sl@0
|
32 |
LOCAL_D const TInt KReduceSizeFrequency=20; // 1 reduce in ?? iterations
|
sl@0
|
33 |
LOCAL_D const TInt KCheckFileFrequency=20000; // 1 check in ?? iterations
|
sl@0
|
34 |
LOCAL_D const TInt KMaxBufferLength=0x8000;
|
sl@0
|
35 |
|
sl@0
|
36 |
LOCAL_C void WriteCluster(RFile& aFile,TInt aCluster)
|
sl@0
|
37 |
//
|
sl@0
|
38 |
// Extend aFile by 1 cluster
|
sl@0
|
39 |
//
|
sl@0
|
40 |
{
|
sl@0
|
41 |
|
sl@0
|
42 |
TUint8* bufPtr=(TUint8*)testBuf.Ptr();
|
sl@0
|
43 |
testBuf.SetLength(testBuf.MaxSize());
|
sl@0
|
44 |
Mem::Fill(bufPtr,testBuf.MaxSize(),aCluster);
|
sl@0
|
45 |
TInt r=aFile.Write(testBuf);
|
sl@0
|
46 |
test(r==KErrNone);
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster)
|
sl@0
|
50 |
//
|
sl@0
|
51 |
// Seek to aCluster and check it is found correctly
|
sl@0
|
52 |
//
|
sl@0
|
53 |
{
|
sl@0
|
54 |
TBuf8<508> seekBuf(508);
|
sl@0
|
55 |
TInt r=aFile.Read(aCluster*testBuf.MaxSize(),seekBuf);
|
sl@0
|
56 |
test(r==KErrNone);
|
sl@0
|
57 |
test(seekBuf[0]==(TUint8)aCluster && seekBuf[507]==(TUint8)aCluster);
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster1,TInt aCluster2)
|
sl@0
|
61 |
//
|
sl@0
|
62 |
// Seek to aCluster and check it is found correctly
|
sl@0
|
63 |
//
|
sl@0
|
64 |
{
|
sl@0
|
65 |
TBuf8<508> seekBuf(508);
|
sl@0
|
66 |
TInt r=aFile.Read(aCluster1*testBuf.MaxSize(),seekBuf);
|
sl@0
|
67 |
test(r==KErrNone);
|
sl@0
|
68 |
test(seekBuf[0]==(TUint8)aCluster1 && seekBuf[507]==(TUint8)aCluster1);
|
sl@0
|
69 |
r=aFile.Read(aCluster2*testBuf.MaxSize(),seekBuf);
|
sl@0
|
70 |
test(r==KErrNone);
|
sl@0
|
71 |
test(seekBuf[0]==(TUint8)aCluster2 && seekBuf[507]==(TUint8)aCluster2);
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
LOCAL_C void ExhaustiveTest(RFile& aFile,TInt aCount1)
|
sl@0
|
75 |
//
|
sl@0
|
76 |
// Test every possible seeking combination
|
sl@0
|
77 |
//
|
sl@0
|
78 |
{
|
sl@0
|
79 |
|
sl@0
|
80 |
TInt i=0,k=0;
|
sl@0
|
81 |
for(k=0;k<aCount1;k++)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
for(i=aCount1-1;i>0;i--)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
SeekToCluster(aFile,i);
|
sl@0
|
86 |
SeekToCluster(aFile,k);
|
sl@0
|
87 |
}
|
sl@0
|
88 |
test.Printf(_L("Seek from %d \r"),k);
|
sl@0
|
89 |
}
|
sl@0
|
90 |
test.Printf(_L("\n"));
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
LOCAL_C void Test1()
|
sl@0
|
94 |
//
|
sl@0
|
95 |
// Test openning a large file
|
sl@0
|
96 |
//
|
sl@0
|
97 |
{
|
sl@0
|
98 |
|
sl@0
|
99 |
test.Next(_L("Create interleaved files"));
|
sl@0
|
100 |
RFile f1,f2;
|
sl@0
|
101 |
//
|
sl@0
|
102 |
TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
|
sl@0
|
103 |
test(r==KErrNone);
|
sl@0
|
104 |
r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite);
|
sl@0
|
105 |
test(r==KErrNone);
|
sl@0
|
106 |
//
|
sl@0
|
107 |
TInt maxListLength=4;
|
sl@0
|
108 |
TInt i=0,k=0;
|
sl@0
|
109 |
TInt countf1=0;
|
sl@0
|
110 |
TInt countf2=0;
|
sl@0
|
111 |
for (k=0;k<maxListLength;k++)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
for (i=0;i<maxListLength;i++)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
TInt j;
|
sl@0
|
116 |
for (j=0;j<=i;j++)
|
sl@0
|
117 |
WriteCluster(f1,countf1++);
|
sl@0
|
118 |
for (j=0;j<=k;j++)
|
sl@0
|
119 |
WriteCluster(f2,countf2++);
|
sl@0
|
120 |
test.Printf(_L("Written %d to file1 %d to file2\n"),i+1,k+1);
|
sl@0
|
121 |
}
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
ExhaustiveTest(f1,countf1);
|
sl@0
|
125 |
ExhaustiveTest(f2,countf2);
|
sl@0
|
126 |
|
sl@0
|
127 |
SeekToCluster(f1,1,10);
|
sl@0
|
128 |
SeekToCluster(f1,6,3);
|
sl@0
|
129 |
SeekToCluster(f1,8,4);
|
sl@0
|
130 |
SeekToCluster(f1,12,3);
|
sl@0
|
131 |
SeekToCluster(f1,23,32);
|
sl@0
|
132 |
SeekToCluster(f1,5,8);
|
sl@0
|
133 |
SeekToCluster(f1,7,9);
|
sl@0
|
134 |
SeekToCluster(f1,12,1);
|
sl@0
|
135 |
SeekToCluster(f1,2,32);
|
sl@0
|
136 |
SeekToCluster(f1,16,8);
|
sl@0
|
137 |
SeekToCluster(f1,9,5);
|
sl@0
|
138 |
SeekToCluster(f1,33,6);
|
sl@0
|
139 |
SeekToCluster(f1,13,7);
|
sl@0
|
140 |
SeekToCluster(f1,9,17);
|
sl@0
|
141 |
SeekToCluster(f1,4,5);
|
sl@0
|
142 |
SeekToCluster(f1,5,31);
|
sl@0
|
143 |
SeekToCluster(f1,11,10);
|
sl@0
|
144 |
SeekToCluster(f1,1,2);
|
sl@0
|
145 |
SeekToCluster(f1,5,5);
|
sl@0
|
146 |
|
sl@0
|
147 |
f1.Close();
|
sl@0
|
148 |
f2.Close();
|
sl@0
|
149 |
r=TheFs.Delete(_L("BIGFile1.tst"));
|
sl@0
|
150 |
test(r==KErrNone);
|
sl@0
|
151 |
r=TheFs.Delete(_L("BIGFile2.tst"));
|
sl@0
|
152 |
test(r==KErrNone);
|
sl@0
|
153 |
CheckDisk();
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
LOCAL_C void Test2()
|
sl@0
|
157 |
//
|
sl@0
|
158 |
// Reproduce old bugs
|
sl@0
|
159 |
//
|
sl@0
|
160 |
{
|
sl@0
|
161 |
|
sl@0
|
162 |
test.Next(_L("Regression Protection"));
|
sl@0
|
163 |
RFile f1,f2;
|
sl@0
|
164 |
//
|
sl@0
|
165 |
TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
|
sl@0
|
166 |
test(r==KErrNone);
|
sl@0
|
167 |
r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite);
|
sl@0
|
168 |
test(r==KErrNone);
|
sl@0
|
169 |
//
|
sl@0
|
170 |
WriteCluster(f1,0);
|
sl@0
|
171 |
WriteCluster(f1,1);
|
sl@0
|
172 |
WriteCluster(f1,2);
|
sl@0
|
173 |
WriteCluster(f1,3);
|
sl@0
|
174 |
WriteCluster(f1,4);
|
sl@0
|
175 |
WriteCluster(f1,5);
|
sl@0
|
176 |
WriteCluster(f2,0);
|
sl@0
|
177 |
WriteCluster(f1,6);
|
sl@0
|
178 |
//
|
sl@0
|
179 |
SeekToCluster(f1,6);
|
sl@0
|
180 |
SeekToCluster(f1,4);
|
sl@0
|
181 |
//
|
sl@0
|
182 |
f1.Close();
|
sl@0
|
183 |
f2.Close();
|
sl@0
|
184 |
r=TheFs.Delete(_L("BIGFile1.tst"));
|
sl@0
|
185 |
test(r==KErrNone);
|
sl@0
|
186 |
r=TheFs.Delete(_L("BIGFile2.tst"));
|
sl@0
|
187 |
test(r==KErrNone);
|
sl@0
|
188 |
CheckDisk();
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
LOCAL_C void Test3()
|
sl@0
|
192 |
//
|
sl@0
|
193 |
// Change file size while seeking
|
sl@0
|
194 |
//
|
sl@0
|
195 |
{
|
sl@0
|
196 |
|
sl@0
|
197 |
test.Next(_L("Alter filesize"));
|
sl@0
|
198 |
RFile f1;
|
sl@0
|
199 |
TheSeed=917824;
|
sl@0
|
200 |
TInt i=0,j=0;
|
sl@0
|
201 |
//
|
sl@0
|
202 |
TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
|
sl@0
|
203 |
test(r==KErrNone);
|
sl@0
|
204 |
|
sl@0
|
205 |
r=f1.SetSize(65534);
|
sl@0
|
206 |
test(r==KErrNone);
|
sl@0
|
207 |
|
sl@0
|
208 |
for(i=0;i<=15;i++)
|
sl@0
|
209 |
WriteCluster(f1,i);
|
sl@0
|
210 |
|
sl@0
|
211 |
for (j=0;j<100;j++)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
TInt cluster1=Math::Rand(TheSeed)%15;
|
sl@0
|
214 |
TInt cluster2=Math::Rand(TheSeed)%15;
|
sl@0
|
215 |
SeekToCluster(f1,cluster2,cluster1);
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
test.Next(_L("Increase Size"));
|
sl@0
|
219 |
r=f1.SetSize(1048577);
|
sl@0
|
220 |
test(r==KErrNone || r==KErrDiskFull);
|
sl@0
|
221 |
if (r==KErrDiskFull)
|
sl@0
|
222 |
{
|
sl@0
|
223 |
test.Printf(_L("File too big\n"));
|
sl@0
|
224 |
f1.Close();
|
sl@0
|
225 |
return;
|
sl@0
|
226 |
}
|
sl@0
|
227 |
|
sl@0
|
228 |
test.Next(_L("Test data still present"));
|
sl@0
|
229 |
for (j=0;j<200;j++)
|
sl@0
|
230 |
{
|
sl@0
|
231 |
TInt cluster1=Math::Rand(TheSeed)%15;
|
sl@0
|
232 |
TInt cluster2=Math::Rand(TheSeed)%15;
|
sl@0
|
233 |
SeekToCluster(f1,cluster2,cluster1);
|
sl@0
|
234 |
}
|
sl@0
|
235 |
|
sl@0
|
236 |
TInt newPos=8192;
|
sl@0
|
237 |
r=f1.Seek(ESeekStart,newPos);
|
sl@0
|
238 |
test(r==KErrNone);
|
sl@0
|
239 |
|
sl@0
|
240 |
test.Next(_L("Write more data"));
|
sl@0
|
241 |
for(i=16;i<83;i++)
|
sl@0
|
242 |
WriteCluster(f1,i);
|
sl@0
|
243 |
|
sl@0
|
244 |
test.Next(_L("Seek to new data"));
|
sl@0
|
245 |
for (j=0;j<200;j++)
|
sl@0
|
246 |
{
|
sl@0
|
247 |
TInt cluster1=Math::Rand(TheSeed)%83;
|
sl@0
|
248 |
TInt cluster2=Math::Rand(TheSeed)%83;
|
sl@0
|
249 |
SeekToCluster(f1,cluster2,cluster1);
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
test.Next(_L("Reduce file size"));
|
sl@0
|
253 |
r=f1.SetSize(135000);
|
sl@0
|
254 |
test(r==KErrNone);
|
sl@0
|
255 |
|
sl@0
|
256 |
test.Next(_L("Test data still present"));
|
sl@0
|
257 |
for (j=0;j<200;j++)
|
sl@0
|
258 |
{
|
sl@0
|
259 |
TInt cluster1=Math::Rand(TheSeed)%31;
|
sl@0
|
260 |
TInt cluster2=Math::Rand(TheSeed)%31;
|
sl@0
|
261 |
SeekToCluster(f1,cluster2,cluster1);
|
sl@0
|
262 |
}
|
sl@0
|
263 |
|
sl@0
|
264 |
f1.Close();
|
sl@0
|
265 |
}
|
sl@0
|
266 |
|
sl@0
|
267 |
class TFileReader
|
sl@0
|
268 |
{
|
sl@0
|
269 |
public:
|
sl@0
|
270 |
TFileReader(RFile* aFile);
|
sl@0
|
271 |
void Next(TUint8& aVal,TInt& aLength);
|
sl@0
|
272 |
TBool Compare(TUint8 aVal,TInt aLength);
|
sl@0
|
273 |
private:
|
sl@0
|
274 |
RFile iFile;
|
sl@0
|
275 |
TBuf8<512> iData;
|
sl@0
|
276 |
TInt iPos;
|
sl@0
|
277 |
};
|
sl@0
|
278 |
|
sl@0
|
279 |
TFileReader::TFileReader(RFile* aFile)
|
sl@0
|
280 |
//
|
sl@0
|
281 |
// Constructor
|
sl@0
|
282 |
//
|
sl@0
|
283 |
: iFile(*aFile), iPos(0)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
|
sl@0
|
286 |
TInt r=iFile.Read(0,iData);
|
sl@0
|
287 |
test(r==KErrNone);
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
void TFileReader::Next(TUint8& aVal,TInt& aLength)
|
sl@0
|
291 |
//
|
sl@0
|
292 |
// Read aLength contiguous bytes with aVal
|
sl@0
|
293 |
//
|
sl@0
|
294 |
{
|
sl@0
|
295 |
|
sl@0
|
296 |
if (iPos==iData.Length())
|
sl@0
|
297 |
{
|
sl@0
|
298 |
TInt r=iFile.Read(iData);
|
sl@0
|
299 |
test(r==KErrNone);
|
sl@0
|
300 |
iPos=0;
|
sl@0
|
301 |
if (iData.Length()==0)
|
sl@0
|
302 |
{
|
sl@0
|
303 |
aLength=0;
|
sl@0
|
304 |
return;
|
sl@0
|
305 |
}
|
sl@0
|
306 |
}
|
sl@0
|
307 |
|
sl@0
|
308 |
aVal=iData[iPos];
|
sl@0
|
309 |
aLength=0;
|
sl@0
|
310 |
while(iPos<iData.Length())
|
sl@0
|
311 |
{
|
sl@0
|
312 |
if (iData[iPos]!=aVal)
|
sl@0
|
313 |
break;
|
sl@0
|
314 |
iPos++;
|
sl@0
|
315 |
aLength++;
|
sl@0
|
316 |
}
|
sl@0
|
317 |
}
|
sl@0
|
318 |
|
sl@0
|
319 |
TBool TFileReader::Compare(TUint8 aVal, TInt aLength)
|
sl@0
|
320 |
//
|
sl@0
|
321 |
// Compare file contents == aVal for aLength bytes
|
sl@0
|
322 |
//
|
sl@0
|
323 |
{
|
sl@0
|
324 |
|
sl@0
|
325 |
FOREVER
|
sl@0
|
326 |
{
|
sl@0
|
327 |
if(iPos==iData.Length())
|
sl@0
|
328 |
{
|
sl@0
|
329 |
TInt r=iFile.Read(iData);
|
sl@0
|
330 |
if (r!=KErrNone)
|
sl@0
|
331 |
{
|
sl@0
|
332 |
test.Printf(_L("READ error %d\n"),r);
|
sl@0
|
333 |
//test.Getch();
|
sl@0
|
334 |
RFs fs;
|
sl@0
|
335 |
r=fs.Connect();
|
sl@0
|
336 |
test.Printf(_L("connect returned %d\n"),r);
|
sl@0
|
337 |
//test.Getch();
|
sl@0
|
338 |
fs.Close();
|
sl@0
|
339 |
test(0);
|
sl@0
|
340 |
return(EFalse);
|
sl@0
|
341 |
}
|
sl@0
|
342 |
iPos=0;
|
sl@0
|
343 |
if (iData.Length()==0)
|
sl@0
|
344 |
{
|
sl@0
|
345 |
test.Printf(_L("\nFound Error\n"));
|
sl@0
|
346 |
test(0);
|
sl@0
|
347 |
//test.Getch();
|
sl@0
|
348 |
return(EFalse);
|
sl@0
|
349 |
}
|
sl@0
|
350 |
}
|
sl@0
|
351 |
while(iPos<iData.Length())
|
sl@0
|
352 |
{
|
sl@0
|
353 |
if (iData[iPos]!=aVal)
|
sl@0
|
354 |
{
|
sl@0
|
355 |
test.Printf(_L("\nFound Error\n"));
|
sl@0
|
356 |
test(0);
|
sl@0
|
357 |
//test.Getch();
|
sl@0
|
358 |
return(EFalse);
|
sl@0
|
359 |
}
|
sl@0
|
360 |
iPos++;
|
sl@0
|
361 |
aLength--;
|
sl@0
|
362 |
if (aLength==0)
|
sl@0
|
363 |
return(ETrue);
|
sl@0
|
364 |
}
|
sl@0
|
365 |
}
|
sl@0
|
366 |
}
|
sl@0
|
367 |
|
sl@0
|
368 |
LOCAL_C void CheckFileContents(RFile* aFile)
|
sl@0
|
369 |
//
|
sl@0
|
370 |
// Check all files have consistent contents
|
sl@0
|
371 |
//
|
sl@0
|
372 |
{
|
sl@0
|
373 |
|
sl@0
|
374 |
TFileReader f0(aFile);
|
sl@0
|
375 |
TFileReader f1(aFile+1);
|
sl@0
|
376 |
TFileReader f2(aFile+2);
|
sl@0
|
377 |
TFileReader f3(aFile+3);
|
sl@0
|
378 |
|
sl@0
|
379 |
FOREVER
|
sl@0
|
380 |
{
|
sl@0
|
381 |
TUint8 val;
|
sl@0
|
382 |
TInt length;
|
sl@0
|
383 |
f0.Next(val,length);
|
sl@0
|
384 |
if (length==0)
|
sl@0
|
385 |
break;
|
sl@0
|
386 |
test(f1.Compare(val,length*mult[1]));
|
sl@0
|
387 |
test(f2.Compare(val,length*mult[2]));
|
sl@0
|
388 |
test(f3.Compare(val,length*mult[3]));
|
sl@0
|
389 |
}
|
sl@0
|
390 |
|
sl@0
|
391 |
TUint8 val;
|
sl@0
|
392 |
TInt length;
|
sl@0
|
393 |
f1.Next(val,length);
|
sl@0
|
394 |
if (length!=0)
|
sl@0
|
395 |
{
|
sl@0
|
396 |
test.Printf(_L("\nFound Error\n"));
|
sl@0
|
397 |
test(0);
|
sl@0
|
398 |
//test.Getch();
|
sl@0
|
399 |
}
|
sl@0
|
400 |
test(length==0);
|
sl@0
|
401 |
f2.Next(val,length);
|
sl@0
|
402 |
if (length!=0)
|
sl@0
|
403 |
{
|
sl@0
|
404 |
test.Printf(_L("\nFound Error\n"));
|
sl@0
|
405 |
test(0);
|
sl@0
|
406 |
//test.Getch();
|
sl@0
|
407 |
}
|
sl@0
|
408 |
test(length==0);
|
sl@0
|
409 |
f3.Next(val,length);
|
sl@0
|
410 |
if (length!=0)
|
sl@0
|
411 |
{
|
sl@0
|
412 |
test.Printf(_L("\nFound Error\n"));
|
sl@0
|
413 |
test(0);
|
sl@0
|
414 |
//test.Getch();
|
sl@0
|
415 |
}
|
sl@0
|
416 |
test(length==0);
|
sl@0
|
417 |
}
|
sl@0
|
418 |
|
sl@0
|
419 |
LOCAL_C void Test4()
|
sl@0
|
420 |
//
|
sl@0
|
421 |
// Read, write and resize 4 interleaved files
|
sl@0
|
422 |
//
|
sl@0
|
423 |
{
|
sl@0
|
424 |
|
sl@0
|
425 |
RFile f[KMaxFiles];
|
sl@0
|
426 |
HBufC8* dataBuf=HBufC8::NewL(KMaxBufferLength);
|
sl@0
|
427 |
|
sl@0
|
428 |
TInt r=f[0].Replace(TheFs,_L("TEST1.DAT"),EFileWrite);
|
sl@0
|
429 |
test(r==KErrNone);
|
sl@0
|
430 |
r=f[1].Replace(TheFs,_L("TEST2.DAT"),EFileWrite);
|
sl@0
|
431 |
test(r==KErrNone);
|
sl@0
|
432 |
r=f[2].Replace(TheFs,_L("TEST3.DAT"),EFileWrite);
|
sl@0
|
433 |
test(r==KErrNone);
|
sl@0
|
434 |
r=f[3].Replace(TheFs,_L("TEST4.DAT"),EFileWrite);
|
sl@0
|
435 |
test(r==KErrNone);
|
sl@0
|
436 |
|
sl@0
|
437 |
TInt size=0;
|
sl@0
|
438 |
TInt iteration=0;
|
sl@0
|
439 |
|
sl@0
|
440 |
FOREVER
|
sl@0
|
441 |
{
|
sl@0
|
442 |
iteration++;
|
sl@0
|
443 |
TInt pos=(size) ? Math::Rand(TheSeed)%size : 0;
|
sl@0
|
444 |
TInt len=Math::Rand(TheSeed)%KMaxLengthIncrement;
|
sl@0
|
445 |
TInt order=Math::Rand(TheSeed)%KMaxFiles;
|
sl@0
|
446 |
TInt value=Math::Rand(TheSeed)%KMaxTUint8;
|
sl@0
|
447 |
|
sl@0
|
448 |
TUint8* data=(TUint8*)dataBuf->Ptr();
|
sl@0
|
449 |
Mem::Fill(data,KMaxBufferLength,value);
|
sl@0
|
450 |
|
sl@0
|
451 |
if (pos+len>size)
|
sl@0
|
452 |
size=pos+len;
|
sl@0
|
453 |
|
sl@0
|
454 |
for (TInt i=0;i<KMaxFiles;i++)
|
sl@0
|
455 |
{
|
sl@0
|
456 |
TInt fileNum=(order+i)%KMaxFiles;
|
sl@0
|
457 |
TInt s=len*mult[fileNum];
|
sl@0
|
458 |
TInt filePos=pos*mult[fileNum];
|
sl@0
|
459 |
r=f[fileNum].Seek(ESeekStart,filePos);
|
sl@0
|
460 |
test(r==KErrNone);
|
sl@0
|
461 |
|
sl@0
|
462 |
while(s>0)
|
sl@0
|
463 |
{
|
sl@0
|
464 |
TInt l=(s>KMaxBufferLength) ? KMaxBufferLength : s;
|
sl@0
|
465 |
dataBuf->Des().SetLength(l);
|
sl@0
|
466 |
r=f[fileNum].Write(*dataBuf);
|
sl@0
|
467 |
|
sl@0
|
468 |
// Flush if write caching enabled to ensure we get disk space notifications
|
sl@0
|
469 |
if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone))
|
sl@0
|
470 |
r = f[fileNum].Flush();
|
sl@0
|
471 |
|
sl@0
|
472 |
if (r==KErrDiskFull)
|
sl@0
|
473 |
goto End;
|
sl@0
|
474 |
test(r==KErrNone);
|
sl@0
|
475 |
s-=l;
|
sl@0
|
476 |
}
|
sl@0
|
477 |
|
sl@0
|
478 |
}
|
sl@0
|
479 |
|
sl@0
|
480 |
if ((iteration%KCheckFileFrequency)==0)
|
sl@0
|
481 |
CheckFileContents(&f[0]);
|
sl@0
|
482 |
|
sl@0
|
483 |
test.Printf(_L("Iteration %d, size %d \r"),iteration,size);
|
sl@0
|
484 |
if (iteration==KMaxIteration)
|
sl@0
|
485 |
break;
|
sl@0
|
486 |
|
sl@0
|
487 |
if ((iteration%KReduceSizeFrequency)==0)
|
sl@0
|
488 |
{
|
sl@0
|
489 |
size=(size) ? Math::Rand(TheSeed)%size : 0;
|
sl@0
|
490 |
test.Printf(_L("\nReduceSize newsize=%d\n"),size);
|
sl@0
|
491 |
for (TInt i=0;i<KMaxFiles;i++)
|
sl@0
|
492 |
{
|
sl@0
|
493 |
TInt fileNum=(order+i)%KMaxFiles;
|
sl@0
|
494 |
r=f[fileNum].SetSize(size*mult[fileNum]);
|
sl@0
|
495 |
test(r==KErrNone);
|
sl@0
|
496 |
}
|
sl@0
|
497 |
CheckFileContents(&f[0]);
|
sl@0
|
498 |
}
|
sl@0
|
499 |
}
|
sl@0
|
500 |
End:
|
sl@0
|
501 |
delete dataBuf;
|
sl@0
|
502 |
for (TInt i=0;i<KMaxFiles;i++)
|
sl@0
|
503 |
f[i].Close();
|
sl@0
|
504 |
test.Printf(_L("\n"));
|
sl@0
|
505 |
}
|
sl@0
|
506 |
|
sl@0
|
507 |
GLDEF_C void CallTestsL()
|
sl@0
|
508 |
//
|
sl@0
|
509 |
// Call all tests
|
sl@0
|
510 |
//
|
sl@0
|
511 |
{
|
sl@0
|
512 |
|
sl@0
|
513 |
#if defined(__WINS__)
|
sl@0
|
514 |
if (gSessionPath[0]=='C')
|
sl@0
|
515 |
return;
|
sl@0
|
516 |
#endif
|
sl@0
|
517 |
if (gSessionPath[0]=='C' || gSessionPath[0]=='Y')
|
sl@0
|
518 |
KMaxIteration=100;
|
sl@0
|
519 |
else
|
sl@0
|
520 |
KMaxIteration=100;
|
sl@0
|
521 |
CreateTestDirectory(_L("\\TRAND\\"));
|
sl@0
|
522 |
Test1();
|
sl@0
|
523 |
Test2();
|
sl@0
|
524 |
Test3();
|
sl@0
|
525 |
Test4();
|
sl@0
|
526 |
DeleteTestDirectory();
|
sl@0
|
527 |
}
|