|
1 // Copyright (c) 2006-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 // Tests for the blockmap API. The blockmap API enumerates the resources |
|
15 // used by a file depending upon the type of media on which the file |
|
16 // resides. |
|
17 // 002 Test Initialise error checking |
|
18 // 003 Test processing of user-side block map into extent list |
|
19 // 004 Test processing of user-side block map into extent list, block size > read unit size |
|
20 // 005 Test Read error checking |
|
21 // 006 Test Read |
|
22 // Test BlockMap API functionality. |
|
23 // |
|
24 // |
|
25 |
|
26 //! @SYMTestCaseID KBASE-T_BLOCKMAP-0337 |
|
27 //! @SYMTestType UT |
|
28 //! @SYMPREQ PREQ1110 |
|
29 //! @SYMTestCaseDesc Demand Paging Blockmap tests |
|
30 //! @SYMTestActions 001 Unit tests the TKernBlockMap class |
|
31 //! @SYMTestExpectedResults All tests should pass. |
|
32 //! @SYMTestPriority High |
|
33 //! @SYMTestStatus Implemented |
|
34 |
|
35 |
|
36 #include <e32test.h> |
|
37 #include <f32file.h> |
|
38 #include <e32math.h> |
|
39 #include <hal.h> |
|
40 #include "t_server.h" |
|
41 |
|
42 RTest test( _L("T_BLOCKMAP") ); |
|
43 |
|
44 const TInt KReadBufferSize = 1024; |
|
45 const TInt KMaxFragmentSize = 400; |
|
46 const TInt KMaxFileSize = 10000; |
|
47 |
|
48 TInt RamFatDrive = -1; |
|
49 TInt RemovableFatDrive = -1; |
|
50 TInt InternalRemovableFatDrive = -1; |
|
51 TInt NandDrive = -1; |
|
52 TBool Pageable = EFalse; |
|
53 TBool Finished = EFalse; |
|
54 |
|
55 enum DriveType |
|
56 { |
|
57 EDriveNand, |
|
58 EDriveRam, |
|
59 EDriveRemovable, |
|
60 EDriveInternalRemovable |
|
61 }; |
|
62 |
|
63 _LIT( KTestFile, "Z:\\TEST\\T_FILE.CPP"); |
|
64 _LIT( KTestFileFAT, "Z:\\Multiple\\T_file.cpp"); |
|
65 _LIT( KTestFileName, "T_FILE.CPP"); |
|
66 _LIT( KFragmentedFileName1, "FRAG1.TXT"); |
|
67 _LIT( KFragmentedFileName2, "FRAG2.TXT"); |
|
68 _LIT( KDriveBase, " :\\" ); |
|
69 |
|
70 LOCAL_C TInt TestBlockMapNandFATUserData(TInt64 aStartPos, TInt64 aEndPos) |
|
71 { |
|
72 CFileMan* fMan=CFileMan::NewL(TheFs); |
|
73 test(fMan!=NULL); |
|
74 TFileName name(KDriveBase); |
|
75 name[0] = TText('A' + NandDrive); |
|
76 name.Append( KTestFileName ); |
|
77 |
|
78 TInt r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
79 r = fMan->Delete(name); |
|
80 |
|
81 r = fMan->Copy(KTestFile, name); |
|
82 test( r == KErrNone ); |
|
83 |
|
84 TInt localDriveNum = 0; |
|
85 RFile testFile; |
|
86 r = testFile.Open( TheFs, name, EFileRead ); |
|
87 test( r == KErrNone ); |
|
88 |
|
89 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map; |
|
90 SBlockMapInfo info; |
|
91 TInt counter = 0; |
|
92 TInt startPos = aStartPos; |
|
93 TInt bmErr; |
|
94 |
|
95 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned. |
|
96 do |
|
97 { |
|
98 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug); |
|
99 if (bmErr != 0 && bmErr != KErrCompletion) |
|
100 { |
|
101 map.Close(); |
|
102 testFile.Close(); |
|
103 r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
104 test( r == KErrNone ); |
|
105 r = fMan->Delete(name); |
|
106 test( r == KErrNone ); |
|
107 delete fMan; |
|
108 return bmErr; |
|
109 } |
|
110 map.Append(info); |
|
111 if (counter++ == 0) |
|
112 localDriveNum = info.iLocalDriveNumber; |
|
113 } while ( bmErr == 0 && bmErr != KErrCompletion ); |
|
114 test( bmErr == KErrCompletion ); |
|
115 TInt granularity; |
|
116 |
|
117 TInt size; |
|
118 r = testFile.Size(size); |
|
119 test( r == KErrNone ); |
|
120 |
|
121 TBuf8<KReadBufferSize> buf1; |
|
122 TBuf8<KReadBufferSize> buf2; |
|
123 |
|
124 TBool changed; |
|
125 TBusLocalDrive localDrive; |
|
126 |
|
127 UserSvr::UnlockRamDrive(); |
|
128 |
|
129 TBlockMapEntry* myBlockMapEntry; |
|
130 TInt myCounter = 0; |
|
131 TInt totalSegments = 0; |
|
132 TInt remainder = 0; |
|
133 TInt miniLength = 0; |
|
134 TInt amountRead = 0; |
|
135 |
|
136 TInt c; |
|
137 for ( c = 0; c < map.Count(); c++ ) |
|
138 { |
|
139 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
140 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
141 totalSegments += granularity; |
|
142 } |
|
143 |
|
144 const TInt KTotalSegments = totalSegments; |
|
145 r = localDrive.Connect( localDriveNum, changed ); |
|
146 test( r == KErrNone ); |
|
147 |
|
148 // For each SBlockMapInfo object in RArray map |
|
149 for ( c = 0; c < map.Count(); c++ ) |
|
150 { |
|
151 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
152 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
153 TInt length; |
|
154 if ( aEndPos == -1 ) |
|
155 { |
|
156 length = size - startPos; |
|
157 aEndPos = size; |
|
158 } |
|
159 else |
|
160 length = aEndPos - startPos; |
|
161 |
|
162 for ( TInt c2 = 1; c2 <= granularity; c2++) |
|
163 { |
|
164 myCounter = 0; |
|
165 if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 ) |
|
166 remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity; |
|
167 else |
|
168 remainder = 0; |
|
169 miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0); |
|
170 do |
|
171 { |
|
172 if ( miniLength >= KReadBufferSize ) |
|
173 { |
|
174 testFile.Read( startPos + amountRead, buf1, KReadBufferSize ); |
|
175 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2); |
|
176 r = buf1.Compare( buf2 ); |
|
177 test( r == 0 ); |
|
178 buf1.Zero(); |
|
179 buf2.Zero(); |
|
180 myCounter++; |
|
181 miniLength -= KReadBufferSize; |
|
182 length -= KReadBufferSize; |
|
183 amountRead += KReadBufferSize; |
|
184 } |
|
185 else |
|
186 { |
|
187 testFile.Read(startPos + amountRead, buf1, miniLength); |
|
188 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2); |
|
189 r = buf1.Compare( buf2 ); |
|
190 test( r == 0 ); |
|
191 amountRead += miniLength; |
|
192 length -= miniLength; |
|
193 miniLength = 0; |
|
194 } |
|
195 } while ( miniLength != 0 && length != 0); |
|
196 myBlockMapEntry++; |
|
197 } |
|
198 } |
|
199 map.Close(); |
|
200 |
|
201 testFile.Close(); |
|
202 r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
203 test( r == KErrNone ); |
|
204 r = fMan->Delete(name); |
|
205 test( r == KErrNone ); |
|
206 delete fMan; |
|
207 return bmErr; |
|
208 } |
|
209 |
|
210 LOCAL_C TInt TestBlockMapNandFAT(TInt64 aStartPos, TInt64 aEndPos) |
|
211 // |
|
212 // Test BlockMap retrieval on NAND FAT. |
|
213 // |
|
214 { |
|
215 TInt localDriveNum = 0; |
|
216 RFile testFile; |
|
217 TInt r = testFile.Open( TheFs, KTestFileFAT, EFileRead ); |
|
218 test( r == KErrNone ); |
|
219 |
|
220 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map; |
|
221 SBlockMapInfo info; |
|
222 TInt counter = 0; |
|
223 TInt startPos = aStartPos; |
|
224 TInt bmErr; |
|
225 |
|
226 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned. |
|
227 do |
|
228 { |
|
229 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, Pageable?EBlockMapUsagePaging:ETestDebug); |
|
230 if (bmErr != 0 && bmErr != KErrCompletion) |
|
231 { |
|
232 map.Close(); |
|
233 testFile.Close(); |
|
234 return bmErr; |
|
235 } |
|
236 map.Append(info); |
|
237 if (counter++ == 0) |
|
238 localDriveNum = info.iLocalDriveNumber; |
|
239 } while ( bmErr == 0 && bmErr != KErrCompletion ); |
|
240 test( bmErr == KErrCompletion ); |
|
241 TInt granularity; |
|
242 |
|
243 TInt size; |
|
244 r = testFile.Size(size); |
|
245 test( r == KErrNone ); |
|
246 |
|
247 TBuf8<KReadBufferSize> buf1; |
|
248 TBuf8<KReadBufferSize> buf2; |
|
249 |
|
250 TBool changed; |
|
251 TBusLocalDrive localDrive; |
|
252 |
|
253 TBlockMapEntry* myBlockMapEntry; |
|
254 TInt myCounter = 0; |
|
255 TInt totalSegments = 0; |
|
256 TInt remainder = 0; |
|
257 TInt miniLength = 0; |
|
258 TInt amountRead = 0; |
|
259 |
|
260 TInt c; |
|
261 for ( c = 0; c < map.Count(); c++ ) |
|
262 { |
|
263 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
264 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
265 totalSegments += granularity; |
|
266 } |
|
267 |
|
268 const TInt KTotalSegments = totalSegments; |
|
269 r = localDrive.Connect( localDriveNum, changed ); |
|
270 test( r == KErrNone ); |
|
271 |
|
272 // For each SBlockMapInfo object in RArray map |
|
273 for ( c = 0; c < map.Count(); c++ ) |
|
274 { |
|
275 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
276 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
277 |
|
278 TInt length; |
|
279 if ( aEndPos == -1 ) |
|
280 { |
|
281 length = size - startPos; |
|
282 aEndPos = size; |
|
283 } |
|
284 else |
|
285 length = aEndPos - startPos; |
|
286 |
|
287 for ( TInt c2 = 1; c2 <= granularity; c2++) |
|
288 { |
|
289 myCounter = 0; |
|
290 if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 ) |
|
291 remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity; |
|
292 else |
|
293 remainder = 0; |
|
294 miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0); |
|
295 do |
|
296 { |
|
297 if ( miniLength >= KReadBufferSize ) |
|
298 { |
|
299 testFile.Read( startPos + amountRead, buf1, KReadBufferSize ); |
|
300 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2); |
|
301 r = buf1.Compare( buf2 ); |
|
302 test( r == 0 ); |
|
303 buf1.Zero(); |
|
304 buf2.Zero(); |
|
305 myCounter++; |
|
306 miniLength -= KReadBufferSize; |
|
307 length -= KReadBufferSize; |
|
308 amountRead += KReadBufferSize; |
|
309 } |
|
310 else |
|
311 { |
|
312 testFile.Read(startPos + amountRead, buf1, miniLength); |
|
313 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2); |
|
314 r = buf1.Compare( buf2 ); |
|
315 test( r == 0 ); |
|
316 amountRead += miniLength; |
|
317 length -= miniLength; |
|
318 miniLength = 0; |
|
319 } |
|
320 } while ( miniLength != 0 && length != 0); |
|
321 myBlockMapEntry++; |
|
322 } |
|
323 } |
|
324 map.Close(); |
|
325 testFile.Close(); |
|
326 return bmErr; |
|
327 } |
|
328 |
|
329 LOCAL_C TInt TestBlockMapNandROFS(TInt64 aStartPos, TInt64 aEndPos) |
|
330 // |
|
331 // Test BlockMap retrieval on NAND ROFS. |
|
332 // |
|
333 { |
|
334 TInt localDriveNum = 0; |
|
335 RFile testFile; |
|
336 TInt r = testFile.Open( TheFs, KTestFile, EFileRead ); |
|
337 test( r == KErrNone ); |
|
338 |
|
339 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map; |
|
340 SBlockMapInfo info; |
|
341 TInt counter = 0; |
|
342 TInt startPos = aStartPos; |
|
343 TInt bmErr; |
|
344 |
|
345 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned. |
|
346 do |
|
347 { |
|
348 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, Pageable?EBlockMapUsagePaging:ETestDebug); |
|
349 if (bmErr != 0 && bmErr != KErrCompletion) |
|
350 { |
|
351 map.Close(); |
|
352 testFile.Close(); |
|
353 return bmErr; |
|
354 } |
|
355 map.Append(info); |
|
356 if (counter++ == 0) |
|
357 localDriveNum = info.iLocalDriveNumber; |
|
358 } while ( bmErr == 0 && bmErr != KErrCompletion ); |
|
359 test( bmErr == KErrCompletion ); |
|
360 TInt granularity; |
|
361 |
|
362 TInt size; |
|
363 r = testFile.Size(size); |
|
364 test( r == KErrNone ); |
|
365 |
|
366 TBuf8<KReadBufferSize> buf1; |
|
367 TBuf8<KReadBufferSize> buf2; |
|
368 |
|
369 TBool changed; |
|
370 TBusLocalDrive localDrive; |
|
371 |
|
372 TBlockMapEntry* myBlockMapEntry; |
|
373 TInt myCounter = 0; |
|
374 TInt totalSegments = 0; |
|
375 TInt miniLength = 0; |
|
376 TInt amountRead = 0; |
|
377 |
|
378 TInt c; |
|
379 for ( c = 0; c < map.Count(); c++ ) |
|
380 { |
|
381 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
382 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
383 totalSegments += granularity; |
|
384 } |
|
385 r = localDrive.Connect( localDriveNum, changed ); |
|
386 test( r == KErrNone ); |
|
387 |
|
388 // For each SBlockMapInfo object in RArray map |
|
389 for ( c = 0; c < map.Count(); c++ ) |
|
390 { |
|
391 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
392 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
393 |
|
394 TInt length; |
|
395 if ( aEndPos == -1 ) |
|
396 { |
|
397 length = size - startPos; |
|
398 aEndPos = size; |
|
399 } |
|
400 else |
|
401 length = aEndPos - startPos; |
|
402 |
|
403 for ( TInt c2 = 1; c2 <= granularity; c2++) |
|
404 { |
|
405 myCounter = 0; |
|
406 miniLength = length; |
|
407 do |
|
408 { |
|
409 if ( miniLength >= KReadBufferSize ) |
|
410 { |
|
411 testFile.Read( startPos + amountRead, buf1, KReadBufferSize ); |
|
412 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2); |
|
413 r = buf1.Compare( buf2 ); |
|
414 test( r == 0 ); |
|
415 buf1.Zero(); |
|
416 buf2.Zero(); |
|
417 myCounter++; |
|
418 miniLength -= KReadBufferSize; |
|
419 length -= KReadBufferSize; |
|
420 amountRead += KReadBufferSize; |
|
421 } |
|
422 else |
|
423 { |
|
424 testFile.Read(startPos + amountRead, buf1, miniLength); |
|
425 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2); |
|
426 r = buf1.Compare( buf2 ); |
|
427 test( r == 0 ); |
|
428 amountRead += miniLength; |
|
429 length -= miniLength; |
|
430 miniLength = 0; |
|
431 } |
|
432 } while ( miniLength != 0 && length != 0); |
|
433 myBlockMapEntry++; |
|
434 } |
|
435 } |
|
436 map.Close(); |
|
437 |
|
438 testFile.Close(); |
|
439 return bmErr; |
|
440 } |
|
441 |
|
442 LOCAL_C TInt TestBlockMapRamFAT(TInt64 aStartPos, TInt64 aEndPos) |
|
443 // |
|
444 // Test BlockMap retrieval on RAM FAT. |
|
445 // |
|
446 { |
|
447 CFileMan* fMan=CFileMan::NewL(TheFs); |
|
448 test(fMan!=NULL); |
|
449 TFileName name(KDriveBase); |
|
450 name[0] = TText('A' + RamFatDrive); |
|
451 name.Append( KTestFileName ); |
|
452 |
|
453 TInt r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
454 r = fMan->Delete(name); |
|
455 |
|
456 r = fMan->Copy(KTestFile, name); |
|
457 test( r == KErrNone || r == KErrAlreadyExists); |
|
458 |
|
459 TInt localDriveNum = 0; |
|
460 RFile testFile; |
|
461 r = testFile.Open( TheFs, name, EFileRead ); |
|
462 test( r == KErrNone ); |
|
463 |
|
464 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map; |
|
465 SBlockMapInfo info; |
|
466 TInt counter = 0; |
|
467 TInt startPos = aStartPos; |
|
468 TInt bmErr; |
|
469 |
|
470 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned. |
|
471 do |
|
472 { |
|
473 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug); |
|
474 if (bmErr != 0 && bmErr != KErrCompletion) |
|
475 { |
|
476 map.Close(); |
|
477 testFile.Close(); |
|
478 r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
479 test( r == KErrNone ); |
|
480 r = fMan->Delete(name); |
|
481 test( r == KErrNone ); |
|
482 delete fMan; |
|
483 return bmErr; |
|
484 } |
|
485 map.Append(info); |
|
486 if (counter++ == 0) |
|
487 localDriveNum = info.iLocalDriveNumber; |
|
488 } while ( bmErr == 0 && bmErr != KErrCompletion ); |
|
489 test( bmErr == KErrCompletion ); |
|
490 TInt granularity; |
|
491 |
|
492 TInt size; |
|
493 r = testFile.Size(size); |
|
494 test( r == KErrNone ); |
|
495 |
|
496 TBuf8<KReadBufferSize> buf1; |
|
497 TBuf8<KReadBufferSize> buf2; |
|
498 |
|
499 TBool changed; |
|
500 TBusLocalDrive localDrive; |
|
501 |
|
502 UserSvr::UnlockRamDrive(); |
|
503 |
|
504 TBlockMapEntry* myBlockMapEntry; |
|
505 TInt myCounter = 0; |
|
506 TInt totalSegments = 0; |
|
507 TInt remainder = 0; |
|
508 TInt miniLength = 0; |
|
509 TInt amountRead = 0; |
|
510 |
|
511 TInt c; |
|
512 for ( c = 0; c < map.Count(); c++ ) |
|
513 { |
|
514 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
515 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
516 totalSegments += granularity; |
|
517 } |
|
518 |
|
519 const TInt KTotalSegments = totalSegments; |
|
520 |
|
521 r = localDrive.Connect( localDriveNum, changed ); |
|
522 test( r == KErrNone ); |
|
523 |
|
524 // For each SBlockMapInfo object in RArray map |
|
525 for ( c = 0; c < map.Count(); c++ ) |
|
526 { |
|
527 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
528 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
529 |
|
530 TInt length; |
|
531 if ( aEndPos == -1 ) |
|
532 { |
|
533 length = size - startPos; |
|
534 aEndPos = size; |
|
535 } |
|
536 else |
|
537 length = aEndPos - startPos; |
|
538 |
|
539 for ( TInt c2 = 1; c2 <= granularity; c2++) |
|
540 { |
|
541 myCounter = 0; |
|
542 if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 ) |
|
543 remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity; |
|
544 else |
|
545 remainder = 0; |
|
546 miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0); |
|
547 do |
|
548 { |
|
549 if ( miniLength >= KReadBufferSize ) |
|
550 { |
|
551 testFile.Read( startPos + amountRead, buf1, KReadBufferSize ); |
|
552 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2); |
|
553 r = buf1.Compare( buf2 ); |
|
554 test( r == 0 ); |
|
555 buf1.Zero(); |
|
556 buf2.Zero(); |
|
557 myCounter++; |
|
558 miniLength -= KReadBufferSize; |
|
559 length -= KReadBufferSize; |
|
560 amountRead += KReadBufferSize; |
|
561 } |
|
562 else |
|
563 { |
|
564 testFile.Read(startPos + amountRead, buf1, miniLength); |
|
565 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2); |
|
566 r = buf1.Compare( buf2 ); |
|
567 test( r == 0 ); |
|
568 amountRead += miniLength; |
|
569 length -= miniLength; |
|
570 miniLength = 0; |
|
571 } |
|
572 } while ( miniLength != 0 && length != 0); |
|
573 myBlockMapEntry++; |
|
574 } |
|
575 } |
|
576 map.Close(); |
|
577 |
|
578 testFile.Close(); |
|
579 r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
580 test( r == KErrNone ); |
|
581 r = fMan->Delete(name); |
|
582 test( r == KErrNone ); |
|
583 delete fMan; |
|
584 return bmErr; |
|
585 } |
|
586 |
|
587 LOCAL_C TInt TestBlockMapRamFAT2(TInt64 aStartPos, TInt64 aEndPos) |
|
588 // |
|
589 // Test BlockMap retrieval on Ram FAT. |
|
590 // |
|
591 { |
|
592 CFileMan* fMan=CFileMan::NewL(TheFs); |
|
593 test(fMan!=NULL); |
|
594 TFileName name(KDriveBase); |
|
595 name[0] = TText('A' + RamFatDrive); |
|
596 name.Append( KTestFileName ); |
|
597 |
|
598 TInt r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
599 r = fMan->Delete(name); |
|
600 |
|
601 r = fMan->Copy(KTestFile, name); |
|
602 test( r == KErrNone || r == KErrAlreadyExists); |
|
603 |
|
604 RFile testFile; |
|
605 r = testFile.Open( TheFs, name, EFileRead ); |
|
606 test( r == KErrNone ); |
|
607 |
|
608 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map; |
|
609 SBlockMapInfo info; |
|
610 |
|
611 TInt bmErr; |
|
612 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, EBlockMapUsagePaging); |
|
613 |
|
614 map.Close(); |
|
615 |
|
616 testFile.Close(); |
|
617 r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
618 test( r == KErrNone ); |
|
619 r = fMan->Delete(name); |
|
620 test( r == KErrNone ); |
|
621 delete fMan; |
|
622 return bmErr; |
|
623 } |
|
624 |
|
625 LOCAL_C TInt TestBlockMapRemovableFAT(TInt64 aStartPos, TInt64 aEndPos) |
|
626 // |
|
627 // Test BlockMap retrieval on Removable FAT. |
|
628 // |
|
629 { |
|
630 CFileMan* fMan=CFileMan::NewL(TheFs); |
|
631 test(fMan!=NULL); |
|
632 TFileName name(KDriveBase); |
|
633 name[0] = TText('A' + RemovableFatDrive); |
|
634 name.Append( KTestFileName ); |
|
635 |
|
636 TInt r=fMan->Copy(KTestFile, name); |
|
637 test( r == KErrNone || r == KErrAlreadyExists); |
|
638 |
|
639 RFile testFile; |
|
640 r = testFile.Open( TheFs, name, EFileRead ); |
|
641 test( r == KErrNone ); |
|
642 |
|
643 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map; |
|
644 SBlockMapInfo info; |
|
645 TInt bmErr = testFile.BlockMap(info, aStartPos, aEndPos, Pageable?EBlockMapUsagePaging:ETestDebug); |
|
646 map.Close(); |
|
647 |
|
648 testFile.Close(); |
|
649 r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
650 test( r == KErrNone ); |
|
651 r = fMan->Delete(name); |
|
652 test( r == KErrNone ); |
|
653 delete fMan; |
|
654 return bmErr; |
|
655 } |
|
656 |
|
657 LOCAL_C TInt TestBlockMapInternalRemovableFAT(TInt64 aStartPos, TInt64 aEndPos) |
|
658 // |
|
659 // Test BlockMap retrieval on internal removable FAT. |
|
660 // |
|
661 { |
|
662 CFileMan* fMan=CFileMan::NewL(TheFs); |
|
663 test(fMan!=NULL); |
|
664 TFileName name(KDriveBase); |
|
665 name[0] = TText('A' + RamFatDrive); |
|
666 name.Append( KTestFileName ); |
|
667 |
|
668 TInt r=fMan->Copy(KTestFile, name); |
|
669 test( r == KErrNone || r == KErrAlreadyExists); |
|
670 |
|
671 TInt localDriveNum = 0; |
|
672 RFile testFile; |
|
673 r = testFile.Open( TheFs, name, EFileRead ); |
|
674 test( r == KErrNone ); |
|
675 |
|
676 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map; |
|
677 SBlockMapInfo info; |
|
678 TInt counter = 0; |
|
679 TInt startPos = aStartPos; |
|
680 TInt bmErr; |
|
681 |
|
682 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned. |
|
683 do |
|
684 { |
|
685 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug); |
|
686 if (bmErr != 0 && bmErr != KErrCompletion) |
|
687 { |
|
688 map.Close(); |
|
689 testFile.Close(); |
|
690 r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
691 test( r == KErrNone ); |
|
692 r = fMan->Delete(name); |
|
693 test( r == KErrNone ); |
|
694 delete fMan; |
|
695 return bmErr; |
|
696 } |
|
697 map.Append(info); |
|
698 if (counter++ == 0) |
|
699 localDriveNum = info.iLocalDriveNumber; |
|
700 } while ( bmErr == 0 && bmErr != KErrCompletion ); |
|
701 test( bmErr == KErrCompletion ); |
|
702 TInt granularity; |
|
703 |
|
704 TInt size; |
|
705 r = testFile.Size(size); |
|
706 test( r == KErrNone ); |
|
707 |
|
708 TBuf8<KReadBufferSize> buf1; |
|
709 TBuf8<KReadBufferSize> buf2; |
|
710 |
|
711 TBool changed; |
|
712 TBusLocalDrive localDrive; |
|
713 |
|
714 UserSvr::UnlockRamDrive(); |
|
715 |
|
716 TBlockMapEntry* myBlockMapEntry; |
|
717 TInt myCounter = 0; |
|
718 TInt totalSegments = 0; |
|
719 TInt remainder = 0; |
|
720 TInt miniLength = 0; |
|
721 TInt amountRead = 0; |
|
722 |
|
723 TInt c; |
|
724 for ( c = 0; c < map.Count(); c++ ) |
|
725 { |
|
726 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
727 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
728 totalSegments += granularity; |
|
729 } |
|
730 |
|
731 const TInt KTotalSegments = totalSegments; |
|
732 |
|
733 r = localDrive.Connect( localDriveNum, changed ); |
|
734 test( r == KErrNone ); |
|
735 |
|
736 // For each SBlockMapInfo object in RArray map |
|
737 for ( c = 0; c < map.Count(); c++ ) |
|
738 { |
|
739 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
740 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
741 |
|
742 TInt length; |
|
743 if ( aEndPos == -1 ) |
|
744 { |
|
745 length = size - startPos; |
|
746 aEndPos = size; |
|
747 } |
|
748 else |
|
749 length = aEndPos - startPos; |
|
750 |
|
751 for ( TInt c2 = 1; c2 <= granularity; c2++) |
|
752 { |
|
753 myCounter = 0; |
|
754 if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 ) |
|
755 remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity; |
|
756 else |
|
757 remainder = 0; |
|
758 miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0); |
|
759 do |
|
760 { |
|
761 if ( miniLength >= KReadBufferSize ) |
|
762 { |
|
763 testFile.Read( startPos + amountRead, buf1, KReadBufferSize ); |
|
764 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2); |
|
765 r = buf1.Compare( buf2 ); |
|
766 test( r == 0 ); |
|
767 buf1.Zero(); |
|
768 buf2.Zero(); |
|
769 myCounter++; |
|
770 miniLength -= KReadBufferSize; |
|
771 length -= KReadBufferSize; |
|
772 amountRead += KReadBufferSize; |
|
773 } |
|
774 else |
|
775 { |
|
776 testFile.Read(startPos + amountRead, buf1, miniLength); |
|
777 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2); |
|
778 r = buf1.Compare( buf2 ); |
|
779 test( r == 0 ); |
|
780 amountRead += miniLength; |
|
781 length -= miniLength; |
|
782 miniLength = 0; |
|
783 } |
|
784 } while ( miniLength != 0 && length != 0); |
|
785 myBlockMapEntry++; |
|
786 } |
|
787 } |
|
788 map.Close(); |
|
789 |
|
790 testFile.Close(); |
|
791 r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
792 test( r == KErrNone ); |
|
793 r = fMan->Delete(name); |
|
794 test( r == KErrNone ); |
|
795 delete fMan; |
|
796 return bmErr; |
|
797 } |
|
798 |
|
799 LOCAL_C TInt TestBlockMapFragmented(DriveType aDriveType, TInt64 aStartPos, TInt64 aEndPos) |
|
800 { |
|
801 CFileMan* fMan=CFileMan::NewL(TheFs); |
|
802 test(fMan!=NULL); |
|
803 TFileName name(KDriveBase); |
|
804 if (aDriveType==EDriveRam) |
|
805 name[0] = TText('A' + RamFatDrive); |
|
806 else if (aDriveType==EDriveRemovable) |
|
807 name[0] = TText('A' + RemovableFatDrive); |
|
808 else if (aDriveType==EDriveNand) |
|
809 name[0] = TText('A' + NandDrive); |
|
810 else |
|
811 name[0] = TText('A' + InternalRemovableFatDrive); |
|
812 name.Append( KFragmentedFileName1 ); |
|
813 TInt localDriveNum = 0; |
|
814 RFile testFile; |
|
815 TInt r = testFile.Open( TheFs, name, EFileRead ); |
|
816 test( r == KErrNone ); |
|
817 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map; |
|
818 SBlockMapInfo info; |
|
819 TInt counter = 0; |
|
820 TInt startPos = aStartPos; |
|
821 TInt bmErr; |
|
822 |
|
823 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned. |
|
824 do |
|
825 { |
|
826 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug); |
|
827 if (bmErr != 0 && bmErr != KErrCompletion) |
|
828 { |
|
829 map.Close(); |
|
830 testFile.Close(); |
|
831 if ( Finished ) |
|
832 { |
|
833 r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
834 test( r == KErrNone ); |
|
835 r = fMan->Delete(name); |
|
836 test( r == KErrNone ); |
|
837 } |
|
838 delete fMan; |
|
839 return bmErr; |
|
840 } |
|
841 map.Append(info); |
|
842 if (counter++ == 0) |
|
843 localDriveNum = info.iLocalDriveNumber; |
|
844 } while ( bmErr == 0 && bmErr != KErrCompletion ); |
|
845 test( bmErr == KErrCompletion ); |
|
846 TInt granularity; |
|
847 TInt size; |
|
848 r = testFile.Size(size); |
|
849 test( r == KErrNone ); |
|
850 |
|
851 TBuf8<KReadBufferSize> buf1; |
|
852 TBuf8<KReadBufferSize> buf2; |
|
853 |
|
854 TBool changed; |
|
855 TBusLocalDrive localDrive; |
|
856 |
|
857 UserSvr::UnlockRamDrive(); |
|
858 |
|
859 TBlockMapEntry* myBlockMapEntry; |
|
860 TInt myCounter = 0; |
|
861 TInt totalSegments = 0; |
|
862 TInt remainder = 0; |
|
863 TInt miniLength = 0; |
|
864 TInt amountRead = 0; |
|
865 |
|
866 TInt c; |
|
867 for ( c = 0; c < map.Count(); c++ ) |
|
868 { |
|
869 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
870 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
871 totalSegments += granularity; |
|
872 } |
|
873 |
|
874 const TInt KTotalSegments = totalSegments; |
|
875 r = localDrive.Connect( localDriveNum, changed ); |
|
876 test( r == KErrNone ); |
|
877 |
|
878 // For each SBlockMapInfo object in RArray map |
|
879 for ( c = 0; c < map.Count(); c++ ) |
|
880 { |
|
881 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr(); |
|
882 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry); |
|
883 |
|
884 TInt length; |
|
885 if ( aEndPos == -1 ) |
|
886 { |
|
887 length = size - startPos; |
|
888 aEndPos = size; |
|
889 } |
|
890 else |
|
891 length = aEndPos - startPos; |
|
892 |
|
893 for ( TInt c2 = 1; c2 <= granularity; c2++) |
|
894 { |
|
895 myCounter = 0; |
|
896 if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 ) |
|
897 remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity; |
|
898 else |
|
899 remainder = 0; |
|
900 miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0); |
|
901 do |
|
902 { |
|
903 if ( miniLength >= KReadBufferSize ) |
|
904 { |
|
905 testFile.Read( startPos + amountRead, buf1, KReadBufferSize ); |
|
906 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2); |
|
907 r = buf1.Compare( buf2 ); |
|
908 test( r == 0 ); |
|
909 buf1.Zero(); |
|
910 buf2.Zero(); |
|
911 myCounter++; |
|
912 miniLength -= KReadBufferSize; |
|
913 length -= KReadBufferSize; |
|
914 amountRead += KReadBufferSize; |
|
915 } |
|
916 else |
|
917 { |
|
918 testFile.Read(startPos + amountRead, buf1, miniLength ); |
|
919 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2); |
|
920 r = buf1.Compare( buf2 ); |
|
921 test( r == 0 ); |
|
922 amountRead += miniLength; |
|
923 length -= miniLength; |
|
924 miniLength = 0; |
|
925 } |
|
926 } while ( miniLength != 0 && length != 0); |
|
927 myBlockMapEntry++; |
|
928 } |
|
929 } |
|
930 map.Close(); |
|
931 |
|
932 testFile.Close(); |
|
933 if ( Finished ) |
|
934 { |
|
935 r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0); |
|
936 test( r == KErrNone ); |
|
937 r = fMan->Delete(name); |
|
938 test( r == KErrNone ); |
|
939 } |
|
940 delete fMan; |
|
941 return bmErr; |
|
942 } |
|
943 |
|
944 LOCAL_C void GenerateFragmentedFiles(DriveType aDriveType) |
|
945 { |
|
946 TInt r; |
|
947 TFileName name1(KDriveBase); |
|
948 if (aDriveType==EDriveRam) |
|
949 name1[0] = TText('A' + RamFatDrive); |
|
950 else if (aDriveType==EDriveRemovable) |
|
951 name1[0] = TText('A' + RemovableFatDrive); |
|
952 else if (aDriveType==EDriveNand) |
|
953 name1[0] = TText('A' + NandDrive); |
|
954 else |
|
955 name1[0] = TText('A' + InternalRemovableFatDrive); |
|
956 name1.Append( KFragmentedFileName1 ); |
|
957 RFile file1; |
|
958 r = file1.Create(TheFs, name1, EFileWrite); |
|
959 test( r == KErrNone ); |
|
960 file1.Close(); |
|
961 |
|
962 TFileName name2(KDriveBase); |
|
963 if (aDriveType==EDriveRam) |
|
964 name2[0] = TText('A' + RamFatDrive); |
|
965 else if (aDriveType==EDriveRemovable) |
|
966 name2[0] = TText('A' + RemovableFatDrive); |
|
967 else if (aDriveType==EDriveNand) |
|
968 name2[0] = TText('A' + NandDrive); |
|
969 else |
|
970 name2[0] = TText('A' + InternalRemovableFatDrive); |
|
971 name2.Append( KFragmentedFileName2 ); |
|
972 RFile file2; |
|
973 r = file2.Create(TheFs, name2, EFileWrite); |
|
974 test( r == KErrNone ); |
|
975 file2.Close(); |
|
976 TInt64 randomSeed; |
|
977 TBuf8<KMaxFragmentSize> tempBuf; |
|
978 TUint8 *buf; |
|
979 TInt fileSize = 0; |
|
980 TInt fragmentSize; |
|
981 TInt randomLength; |
|
982 TInt pos1; |
|
983 TInt pos2; |
|
984 TInt mycount = 0; |
|
985 do |
|
986 { |
|
987 fragmentSize = 0; |
|
988 pos1 = 0; |
|
989 pos2 = 0; |
|
990 buf = (TUint8*) tempBuf.Ptr(); |
|
991 tempBuf.Zero(); |
|
992 randomLength = Math::Random() % KMaxFragmentSize; |
|
993 randomSeed = Math::Random(); |
|
994 tempBuf.SetLength(randomLength); |
|
995 |
|
996 while (randomLength-- && fragmentSize++ < KMaxFragmentSize && fileSize++ < KMaxFileSize) |
|
997 { |
|
998 *buf++ = (TUint8)('A' + (Math::Rand(randomSeed) % ('Z' - 'A'))); |
|
999 } |
|
1000 r = file1.Open( TheFs, name1, EFileWrite ); |
|
1001 test( r == KErrNone ); |
|
1002 r = file1.Seek( ESeekEnd, pos1 ); |
|
1003 test( r == KErrNone ); |
|
1004 r = file1.Write( pos1, tempBuf ); |
|
1005 test( r == KErrNone ); |
|
1006 r = file1.Flush(); |
|
1007 test( r == KErrNone ); |
|
1008 file1.Close(); |
|
1009 if ( mycount++ < 6 ) |
|
1010 { |
|
1011 r = file2.Open( TheFs, name2, EFileWrite ); |
|
1012 test( r == KErrNone ); |
|
1013 r = file2.Seek( ESeekEnd, pos2 ); |
|
1014 test( r == KErrNone ); |
|
1015 r = file2.Write( pos2, tempBuf ); |
|
1016 test( r == KErrNone ); |
|
1017 r = file2.Flush(); |
|
1018 test( r == KErrNone ); |
|
1019 file2.Close(); |
|
1020 } |
|
1021 } while ( fileSize < KMaxFileSize ); |
|
1022 CFileMan* fMan=CFileMan::NewL(TheFs); |
|
1023 test(fMan!=NULL); |
|
1024 r = fMan->Delete(name2); |
|
1025 test( r == KErrNone ); |
|
1026 delete fMan; |
|
1027 } |
|
1028 |
|
1029 LOCAL_C void FindDrive(DriveType aDriveType) |
|
1030 { |
|
1031 TInt i; |
|
1032 TInt c = 0; |
|
1033 for( i = EDriveA; i < EDriveZ; i++ ) |
|
1034 { |
|
1035 TDriveInfo info; |
|
1036 TInt r = TheFs.Drive(info, i); |
|
1037 if ( r != KErrNone ) |
|
1038 continue; |
|
1039 test( r == KErrNone ); |
|
1040 if ( aDriveType == EDriveNand ) |
|
1041 { |
|
1042 c++ == 0 ? test.Printf( _L("Searching for NAND drive.")) : test.Printf( _L(".")); |
|
1043 if ( info.iType == EMediaNANDFlash && ((info.iMediaAtt & KMediaAttWriteProtected) == 0) ) |
|
1044 { |
|
1045 if ( info.iDriveAtt & KDriveAttPageable ) |
|
1046 Pageable = ETrue; |
|
1047 NandDrive = i; |
|
1048 test.Printf( _L("Found NAND drive: %d\n"), NandDrive ); |
|
1049 break; |
|
1050 } |
|
1051 } |
|
1052 else if ( aDriveType == EDriveRam ) |
|
1053 { |
|
1054 c++ == 0 ? test.Printf( _L("Searching for RAM FAT drive.")) : test.Printf( _L(".")); |
|
1055 if ( (info.iType == EMediaRam) && ( info.iDriveAtt == (KDriveAttLocal|KDriveAttInternal) ) && ( info.iMediaAtt == (KMediaAttVariableSize|KMediaAttFormattable) ) ) |
|
1056 { |
|
1057 if ( info.iDriveAtt & KDriveAttPageable ) |
|
1058 Pageable = ETrue; |
|
1059 RamFatDrive = i; |
|
1060 test.Printf( _L("Found RAM FAT drive: %d\n"), RamFatDrive ); |
|
1061 break; |
|
1062 } |
|
1063 } |
|
1064 else if ( aDriveType == EDriveRemovable ) |
|
1065 { |
|
1066 c++ == 0 ? test.Printf( _L("Searching for removable FAT drive.")) : test.Printf( _L(".")); |
|
1067 if ( info.iType == EMediaHardDisk && ( info.iDriveAtt == (KDriveAttLocal|KDriveAttRemovable) ) ) |
|
1068 { |
|
1069 if ( info.iDriveAtt & KDriveAttPageable ) |
|
1070 Pageable = ETrue; |
|
1071 RemovableFatDrive = i; |
|
1072 test.Printf( _L("Found removable FAT drive: %d\n"), RemovableFatDrive ); |
|
1073 break; |
|
1074 } |
|
1075 } |
|
1076 else if ( aDriveType == EDriveInternalRemovable ) |
|
1077 { |
|
1078 c++ == 0 ? test.Printf( _L("Searching for internal removable FAT drive.")) : test.Printf( _L(".")); |
|
1079 if ( info.iType == EMediaHardDisk && ( info.iDriveAtt == (KDriveAttLocal|KDriveAttInternal) ) ) |
|
1080 { |
|
1081 if ( info.iDriveAtt & KDriveAttPageable ) |
|
1082 Pageable = ETrue; |
|
1083 InternalRemovableFatDrive = i; |
|
1084 test.Printf( _L("Found internal removable FAT drive: %d\n"), InternalRemovableFatDrive ); |
|
1085 break; |
|
1086 } |
|
1087 } |
|
1088 } |
|
1089 if ( i == EDriveZ ) |
|
1090 { |
|
1091 switch(aDriveType) |
|
1092 { |
|
1093 case EDriveNand: |
|
1094 test.Printf( _L("NAND drive not found.\n") ); |
|
1095 break; |
|
1096 case EDriveRam: |
|
1097 test.Printf( _L("RAM FAT drive not found.\n") ); |
|
1098 break; |
|
1099 case EDriveRemovable: |
|
1100 test.Printf( _L("Removable FAT drive not found.\n") ); |
|
1101 break; |
|
1102 case EDriveInternalRemovable: |
|
1103 test.Printf( _L("Internal removable FAT drive not found.\n") ); |
|
1104 break; |
|
1105 default: |
|
1106 test.Printf( _L("Drive not found.\n") ); |
|
1107 } |
|
1108 } |
|
1109 } |
|
1110 |
|
1111 //************************ |
|
1112 // Entry point |
|
1113 |
|
1114 GLDEF_C void CallTestsL(void) |
|
1115 { |
|
1116 test.Title(); |
|
1117 test.Start( _L("BlockMap Test\n") ); |
|
1118 |
|
1119 TInt testFileSize = 0; |
|
1120 RFile testFile; |
|
1121 TInt r = testFile.Open(TheFs, KTestFile, EFileRead); |
|
1122 test(r==KErrNone); |
|
1123 r = testFile.Size(testFileSize); |
|
1124 test(r==KErrNone); |
|
1125 test(testFileSize>16384); |
|
1126 testFile.Close(); |
|
1127 |
|
1128 if ( gDriveToTest == 'C' ) |
|
1129 { |
|
1130 TInt value; |
|
1131 r = HAL::Get( HAL::EMachineUid, value ); |
|
1132 test( r == KErrNone ); |
|
1133 if ( value != HAL::EMachineUid_Lubbock ) // Lubbock cannot run FindDrive as it doesn't support the NAND API |
|
1134 { |
|
1135 test.Next(_L("Test BlockMap retrieval on NAND FAT.")); |
|
1136 FindDrive(EDriveNand); |
|
1137 if ( NandDrive > -1 ) // not finding a NAND drive isn't an error as only NAND builds have one |
|
1138 { |
|
1139 r = TestBlockMapNandFATUserData(0, -1); |
|
1140 test( r == KErrCompletion ); |
|
1141 r = TestBlockMapNandFATUserData(1024, 4096); |
|
1142 test( r == KErrCompletion ); |
|
1143 r = TestBlockMapNandFATUserData(1020, 4100); |
|
1144 test( r == KErrCompletion ); |
|
1145 r = TestBlockMapNandFATUserData(1024, 4100); |
|
1146 test( r == KErrCompletion ); |
|
1147 r = TestBlockMapNandFATUserData(1020, 4096); |
|
1148 test( r == KErrCompletion ); |
|
1149 r = TestBlockMapNandFATUserData(1025, 1200); |
|
1150 test( r == KErrCompletion ); |
|
1151 r = TestBlockMapNandFATUserData(0, testFileSize+100); |
|
1152 test( r == KErrArgument ); |
|
1153 r = TestBlockMapNandFATUserData(-5, -1); |
|
1154 test( r == KErrArgument ); |
|
1155 r = TestBlockMapNandFATUserData(-5, testFileSize+100); |
|
1156 test( r == KErrArgument ); |
|
1157 r = TestBlockMapNandFATUserData(0, 0); |
|
1158 test( r == KErrArgument ); |
|
1159 r = TestBlockMapNandFATUserData(testFileSize, -1); |
|
1160 test( r == KErrArgument ); |
|
1161 r = TestBlockMapNandFATUserData(0, -1); |
|
1162 test( r == KErrCompletion ); |
|
1163 r = TestBlockMapNandFATUserData(2000, 2001); |
|
1164 test( r == KErrCompletion ); |
|
1165 r = TestBlockMapNandFATUserData(0, 0); |
|
1166 test( r == KErrArgument ); |
|
1167 r = TestBlockMapNandFATUserData(2000, 2000); |
|
1168 test( r == KErrArgument ); |
|
1169 r = TestBlockMapNandFATUserData(2048, 2048); |
|
1170 test( r == KErrArgument ); |
|
1171 test.Printf(_L("Generating Fragmented File...")); |
|
1172 GenerateFragmentedFiles(EDriveNand); |
|
1173 test.Printf(_L("Done!\n")); |
|
1174 test.Next(_L("Test BlockMap retrieval on NAND FAT (User area) (fragmented).")); |
|
1175 r = TestBlockMapFragmented(EDriveNand, 0, -1); |
|
1176 test( r == KErrCompletion ); |
|
1177 r = TestBlockMapFragmented(EDriveNand, 1024, 4096); |
|
1178 test( r == KErrCompletion ); |
|
1179 r = TestBlockMapFragmented(EDriveNand, 1020, 4100); |
|
1180 test( r == KErrCompletion ); |
|
1181 r = TestBlockMapFragmented(EDriveNand, 1024, 4100); |
|
1182 test( r == KErrCompletion ); |
|
1183 r = TestBlockMapFragmented(EDriveNand, 1020, 4096); |
|
1184 test( r == KErrCompletion ); |
|
1185 r = TestBlockMapFragmented(EDriveNand, 1025, 1200); |
|
1186 test( r == KErrCompletion ); |
|
1187 r = TestBlockMapFragmented(EDriveNand, 0, testFileSize+100); |
|
1188 test( r == KErrArgument ); |
|
1189 r = TestBlockMapFragmented(EDriveNand, -5, -1); |
|
1190 test( r == KErrArgument ); |
|
1191 r = TestBlockMapFragmented(EDriveNand, -5, testFileSize+100); |
|
1192 test( r == KErrArgument ); |
|
1193 r = TestBlockMapFragmented(EDriveNand, 0, 0); |
|
1194 test( r == KErrArgument ); |
|
1195 r = TestBlockMapFragmented(EDriveNand, testFileSize, -1); |
|
1196 test( r == KErrArgument ); |
|
1197 r = TestBlockMapFragmented(EDriveNand, 0, -1); |
|
1198 test( r == KErrCompletion ); |
|
1199 r = TestBlockMapFragmented(EDriveNand, 2000, 2001); |
|
1200 test( r == KErrCompletion ); |
|
1201 r = TestBlockMapFragmented(EDriveNand, 0, 0); |
|
1202 test( r == KErrArgument ); |
|
1203 r = TestBlockMapFragmented(EDriveNand, 2000, 2000); |
|
1204 test( r == KErrArgument ); |
|
1205 Finished = ETrue; |
|
1206 r = TestBlockMapFragmented(EDriveNand, 2048, 2048); |
|
1207 test( r == KErrArgument ); |
|
1208 test.Next(_L("Test BlockMap retrieval on NAND FAT.")); |
|
1209 r = TestBlockMapNandFAT(0, -1); |
|
1210 test( r == KErrCompletion ); |
|
1211 r = TestBlockMapNandFAT(1024, 4096); |
|
1212 test( r == KErrCompletion ); |
|
1213 r = TestBlockMapNandFAT(1020, 4100); |
|
1214 test( r == KErrCompletion ); |
|
1215 r = TestBlockMapNandFAT(1024, 4100); |
|
1216 test( r == KErrCompletion ); |
|
1217 r = TestBlockMapNandFAT(1020, 4096); |
|
1218 test( r == KErrCompletion ); |
|
1219 r = TestBlockMapNandFAT(1025, 1200); |
|
1220 test( r == KErrCompletion ); |
|
1221 r = TestBlockMapNandFAT(0, testFileSize+100); |
|
1222 test( r == KErrArgument ); |
|
1223 r = TestBlockMapNandFAT(-5, -1); |
|
1224 test( r == KErrArgument ); |
|
1225 r = TestBlockMapNandFAT(-5, testFileSize+100); |
|
1226 test( r == KErrArgument ); |
|
1227 r = TestBlockMapNandFAT(0, 0); |
|
1228 test( r == KErrArgument ); |
|
1229 r = TestBlockMapNandFAT(testFileSize, -1); |
|
1230 test( r == KErrArgument ); |
|
1231 r = TestBlockMapNandFAT(0, -1); |
|
1232 test( r == KErrCompletion ); |
|
1233 r = TestBlockMapNandFAT(2000, 2001); |
|
1234 test( r == KErrCompletion ); |
|
1235 r = TestBlockMapNandFAT(0, 0); |
|
1236 test( r == KErrArgument ); |
|
1237 r = TestBlockMapNandFAT(2000, 2000); |
|
1238 test( r == KErrArgument ); |
|
1239 r = TestBlockMapNandFAT(2048, 2048); |
|
1240 test( r == KErrArgument ); |
|
1241 test.Next(_L("Test BlockMap retrieval on NAND ROFS.")); |
|
1242 r = TestBlockMapNandROFS(0, -1); |
|
1243 test( r == KErrCompletion ); |
|
1244 r = TestBlockMapNandROFS(1024, 4096); |
|
1245 test( r == KErrCompletion ); |
|
1246 r = TestBlockMapNandROFS(1020, 4100); |
|
1247 test( r == KErrCompletion ); |
|
1248 r = TestBlockMapNandROFS(1024, 4100); |
|
1249 test( r == KErrCompletion ); |
|
1250 r = TestBlockMapNandROFS(1020, 4096); |
|
1251 test( r == KErrCompletion ); |
|
1252 r = TestBlockMapNandROFS(1025, 1200); |
|
1253 test( r == KErrCompletion ); |
|
1254 r = TestBlockMapNandROFS(0, testFileSize+100); |
|
1255 test( r == KErrArgument ); |
|
1256 r = TestBlockMapNandROFS(-5, -1); |
|
1257 test( r == KErrArgument ); |
|
1258 r = TestBlockMapNandROFS(-5, testFileSize+100); |
|
1259 test( r == KErrArgument ); |
|
1260 r = TestBlockMapNandROFS(0, 0); |
|
1261 test( r == KErrArgument ); |
|
1262 r = TestBlockMapNandROFS(testFileSize, -1); |
|
1263 test( r == KErrArgument ); |
|
1264 r = TestBlockMapNandROFS(0, -1); |
|
1265 test( r == KErrCompletion ); |
|
1266 r = TestBlockMapNandROFS(2000, 2001); |
|
1267 test( r == KErrCompletion ); |
|
1268 r = TestBlockMapNandROFS(0, 0); |
|
1269 test( r == KErrArgument ); |
|
1270 r = TestBlockMapNandROFS(2000, 2000); |
|
1271 test( r == KErrArgument ); |
|
1272 r = TestBlockMapNandROFS(2048, 2048); |
|
1273 test( r == KErrArgument ); |
|
1274 test.Next(_L("Test BlockMap retrieval on RAM FAT.")); |
|
1275 FindDrive(EDriveRam); |
|
1276 test( RamFatDrive > -1 ); |
|
1277 r = TestBlockMapRamFAT(0, -1); |
|
1278 test( r == KErrCompletion ); |
|
1279 r = TestBlockMapRamFAT(1024, 4096); |
|
1280 test( r == KErrCompletion ); |
|
1281 r = TestBlockMapRamFAT(1020, 4100); |
|
1282 test( r == KErrCompletion ); |
|
1283 r = TestBlockMapRamFAT(1024, 4100); |
|
1284 test( r == KErrCompletion ); |
|
1285 r = TestBlockMapRamFAT(1020, 4096); |
|
1286 test( r == KErrCompletion ); |
|
1287 r = TestBlockMapRamFAT(1025, 1200); |
|
1288 test( r == KErrCompletion ); |
|
1289 r = TestBlockMapRamFAT(0, testFileSize+100); |
|
1290 test( r == KErrArgument ); |
|
1291 r = TestBlockMapRamFAT(-5, -1); |
|
1292 test( r == KErrArgument ); |
|
1293 r = TestBlockMapRamFAT(-5, testFileSize+100); |
|
1294 test( r == KErrArgument ); |
|
1295 r = TestBlockMapRamFAT(0, 0); |
|
1296 test( r == KErrArgument ); |
|
1297 r = TestBlockMapRamFAT(testFileSize, -1); |
|
1298 test( r == KErrArgument ); |
|
1299 r = TestBlockMapRamFAT(0, -1); |
|
1300 test( r == KErrCompletion ); |
|
1301 r = TestBlockMapRamFAT(2000, 2001); |
|
1302 test( r == KErrCompletion ); |
|
1303 r = TestBlockMapRamFAT(0, 0); |
|
1304 test( r == KErrArgument ); |
|
1305 r = TestBlockMapRamFAT(2000, 2000); |
|
1306 test( r == KErrArgument ); |
|
1307 r = TestBlockMapRamFAT(2048, 2048); |
|
1308 test( r == KErrArgument ); |
|
1309 test.Next(_L("Test BlockMap retrieval on Ram FAT (2).")); |
|
1310 r = TestBlockMapRamFAT2(0, -1); |
|
1311 test( r == KErrNotSupported ); |
|
1312 FindDrive(EDriveRemovable); |
|
1313 if ( RemovableFatDrive > -1) |
|
1314 { |
|
1315 test.Next(_L("Test BlockMap retrieval on removable FAT.")); |
|
1316 r = TestBlockMapRemovableFAT(0, -1); |
|
1317 Pageable?test( r == KErrNotSupported ):test( r == KErrCompletion ); |
|
1318 } |
|
1319 else |
|
1320 { |
|
1321 test.Next(_L("Test BlockMap retrieval on internal removable FAT.")); |
|
1322 FindDrive(EDriveInternalRemovable); |
|
1323 test( InternalRemovableFatDrive > -1); |
|
1324 r = TestBlockMapInternalRemovableFAT(0, -1); |
|
1325 test( r == KErrCompletion ); |
|
1326 r = TestBlockMapInternalRemovableFAT(1024, 4096); |
|
1327 test( r == KErrCompletion ); |
|
1328 r = TestBlockMapInternalRemovableFAT(1020, 4100); |
|
1329 test( r == KErrCompletion ); |
|
1330 r = TestBlockMapInternalRemovableFAT(1024, 4100); |
|
1331 test( r == KErrCompletion ); |
|
1332 r = TestBlockMapInternalRemovableFAT(1020, 4096); |
|
1333 test( r == KErrCompletion ); |
|
1334 r = TestBlockMapInternalRemovableFAT(1025, 1200); |
|
1335 test( r == KErrCompletion ); |
|
1336 r = TestBlockMapInternalRemovableFAT(0, testFileSize+100); |
|
1337 test( r == KErrArgument ); |
|
1338 r = TestBlockMapInternalRemovableFAT(-5, -1); |
|
1339 test( r == KErrArgument ); |
|
1340 r = TestBlockMapInternalRemovableFAT(-5, testFileSize+100); |
|
1341 test( r == KErrArgument ); |
|
1342 r = TestBlockMapInternalRemovableFAT(0, 0); |
|
1343 test( r == KErrArgument ); |
|
1344 r = TestBlockMapInternalRemovableFAT(testFileSize, -1); |
|
1345 test( r == KErrArgument ); |
|
1346 r = TestBlockMapInternalRemovableFAT(0, -1); |
|
1347 test( r == KErrCompletion ); |
|
1348 r = TestBlockMapInternalRemovableFAT(2000, 2001); |
|
1349 test( r == KErrCompletion ); |
|
1350 r = TestBlockMapInternalRemovableFAT(0, 0); |
|
1351 test( r == KErrArgument ); |
|
1352 r = TestBlockMapInternalRemovableFAT(2000, 2000); |
|
1353 test( r == KErrArgument ); |
|
1354 r = TestBlockMapInternalRemovableFAT(2048, 2048); |
|
1355 test( r == KErrArgument ); |
|
1356 } |
|
1357 test.Next(_L("Test BlockMap retrieval on Ram FAT (fragmented).")); |
|
1358 test.Printf(_L("Generating Fragmented File...")); |
|
1359 GenerateFragmentedFiles(EDriveRam); |
|
1360 test.Printf(_L("Done!\n")); |
|
1361 Finished = EFalse; |
|
1362 r = TestBlockMapFragmented(EDriveRam, 0, -1); |
|
1363 test( r == KErrCompletion ); |
|
1364 r = TestBlockMapFragmented(EDriveRam, 1020, 4100); |
|
1365 test( r == KErrCompletion ); |
|
1366 r = TestBlockMapFragmented(EDriveRam, 2049, 4096); |
|
1367 test( r == KErrCompletion ); |
|
1368 r = TestBlockMapFragmented(EDriveRam, 1024, 4100); |
|
1369 test( r == KErrCompletion ); |
|
1370 r = TestBlockMapFragmented(EDriveRam, 1020, 4096); |
|
1371 test( r == KErrCompletion ); |
|
1372 r = TestBlockMapFragmented(EDriveRam, 1025, 1200); |
|
1373 test( r == KErrCompletion ); |
|
1374 r = TestBlockMapFragmented(EDriveRam, 0, testFileSize+100); |
|
1375 test( r == KErrArgument ); |
|
1376 r = TestBlockMapFragmented(EDriveRam, -5, -1); |
|
1377 test( r == KErrArgument ); |
|
1378 r = TestBlockMapFragmented(EDriveRam, -5, testFileSize+100); |
|
1379 test( r == KErrArgument ); |
|
1380 r = TestBlockMapFragmented(EDriveRam, 0, 0); |
|
1381 test( r == KErrArgument ); |
|
1382 r = TestBlockMapFragmented(EDriveRam, testFileSize, -1); |
|
1383 test( r == KErrArgument ); |
|
1384 r = TestBlockMapFragmented(EDriveRam, 0, -1); |
|
1385 test( r == KErrCompletion ); |
|
1386 r = TestBlockMapFragmented(EDriveRam, 2000, 2001); |
|
1387 test( r == KErrCompletion ); |
|
1388 r = TestBlockMapFragmented(EDriveRam, 0, 0); |
|
1389 test( r == KErrArgument ); |
|
1390 r = TestBlockMapFragmented(EDriveRam, 2000, 2000); |
|
1391 test( r == KErrArgument ); |
|
1392 Finished = ETrue; |
|
1393 r = TestBlockMapFragmented(EDriveRam, 2048, 2048); |
|
1394 test( r == KErrArgument ); |
|
1395 } |
|
1396 else |
|
1397 { |
|
1398 test.Printf( _L("NAND drive not found, skipping test.\n") ); |
|
1399 } |
|
1400 } |
|
1401 } |
|
1402 test.End(); |
|
1403 test.Close(); |
|
1404 } |