Update contrib.
1 // Copyright (c) 2009-2010 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 "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 #include "FileBuf64.h"
22 ///////////////////////////////////////////////////////////////////////////////////////
24 TBool TheOsCallTimeDetailedProfileEnabled = ETrue;//Needed because the RFileBuf64 source is included directly into this test
25 //nd the sql profiler is enabled (_SQLPROFILER is defined in the MMP file)
27 static RTest TheTest(_L("t_sqlfilebuf64 test"));
30 _LIT(KTestDir, "c:\\test\\");
31 _LIT(KTestFile, "c:\\test\\t_sqlfilebuf64.bin");
32 _LIT(KTestFile2, "\\test\\t_sqlfilebuf64_2.bin");
33 _LIT(KTestFile3, "c:\\test\\t_sqlfilebuf64_3.bin");
35 static TBuf8<1024> TheBuf;
36 static TFileName TheDbName;
38 static TInt TheProcessHandleCount = 0;
39 static TInt TheThreadHandleCount = 0;
40 static TInt TheAllocatedCellsCount = 0;
43 static const TInt KBurstRate = 100;
53 //Used in read/write OOM tests
54 const TUint8 KChar = 'A';
55 const TInt KPageSize = 32768;
57 ///////////////////////////////////////////////////////////////////////////////////////
59 void DeleteTestFiles()
61 if(TheDbName.Length() > 0)
63 (void)TheFs.Delete(TheDbName);
65 (void)TheFs.Delete(KTestFile3);
66 (void)TheFs.Delete(KTestFile);
75 ///////////////////////////////////////////////////////////////////////////////////////
76 ///////////////////////////////////////////////////////////////////////////////////////
77 //Test macros and functions
78 void Check1(TInt aValue, TInt aLine)
83 RDebug::Print(_L("*** Line %d\r\n"), aLine);
84 TheTest(EFalse, aLine);
87 void Check2(TInt aValue, TInt aExpected, TInt aLine)
89 if(aValue != aExpected)
92 RDebug::Print(_L("*** Line %d, Expected result: %d, got: %d\r\n"), aLine, aExpected, aValue);
93 TheTest(EFalse, aLine);
96 #define TEST(arg) ::Check1((arg), __LINE__)
97 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
99 ///////////////////////////////////////////////////////////////////////////////////////
103 TInt err = TheFs.Connect();
104 TEST2(err, KErrNone);
106 err = TheFs.MkDir(KTestDir);
107 TEST(err == KErrNone || err == KErrAlreadyExists);
110 ///////////////////////////////////////////////////////////////////////////////////////
112 static void MarkHandles()
114 RThread().HandleCount(TheProcessHandleCount, TheThreadHandleCount);
117 static void MarkAllocatedCells()
119 TheAllocatedCellsCount = User::CountAllocCells();
122 static void CheckAllocatedCells()
124 TInt allocatedCellsCount = User::CountAllocCells();
125 TEST2(allocatedCellsCount, TheAllocatedCellsCount);
128 static void CheckHandles()
130 TInt endProcessHandleCount;
131 TInt endThreadHandleCount;
133 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
135 TEST2(TheProcessHandleCount, endProcessHandleCount);
136 TEST2(TheThreadHandleCount, endThreadHandleCount);
139 static void VerifyFileContent(const TDesC8& aPattern)
144 TInt err = file.Open(TheFs, KTestFile, EFileShareReadersOrWriters);
145 TEST2(err, KErrNone);
148 err = file.Size(fsize);
149 TEST2(err, KErrNone);
150 TEST2((TInt)fsize, aPattern.Length());
152 err = file.Read(TheBuf, aPattern.Length());
153 TEST2(err, KErrNone);
157 err = TheBuf.Compare(aPattern);
161 static void VerifyFileContent(const TDesC8& aPattern, TInt64 aFilePos)
163 __ASSERT_DEBUG(aFilePos >= 0, User::Invariant());
168 TInt err = file.Open(TheFs, KTestFile, EFileShareReadersOrWriters);
169 TEST2(err, KErrNone);
171 err = file.Read(aFilePos, TheBuf, aPattern.Length());
172 TEST2(err, KErrNone);
176 err = TheBuf.Compare(aPattern);
181 @SYMTestCaseID PDS-SQL-UT-4132
182 @SYMTestCaseDesc RFileBuf64 write test 1.
183 The test performs file write operations using RFileBuf64 class.
184 The write positions are inside the buffer or right at the end of the buffer.
185 The purpose of the test: to verify the logic of RFileBuf64::Write().
186 @SYMTestActions RFileBuf64 write test 1.
187 @SYMTestExpectedResults Test must not fail
188 @SYMTestPriority High
194 RFileBuf64 fbuf(1024);
195 TInt err = fbuf.Create(TheFs, KTestFile, EFileWrite);
196 TEST2(err, KErrNone);
197 fbuf.ProfilerReset();
200 err = fbuf.Write(0, _L8(""));
201 TEST2(err, KErrNone);
202 TEST2(fbuf.iFileWriteCount, 0);
203 TEST2(fbuf.iFileWriteAmount, 0);
204 TEST2(fbuf.iFileSizeCount, 0);
206 //First write operation. After the operation the file buffer must countain 10 bytes.
207 err = fbuf.Write(0, _L8("A123456789"));
208 TEST2(err, KErrNone);
209 TEST2(fbuf.iFileWriteCount, 0);
210 TEST2(fbuf.iFileWriteAmount, 0);
211 TEST2(fbuf.iFileSizeCount, 1);
213 //Second write operation. The offset is at the middle of the buffer. Data length: 10;
214 err = fbuf.Write(5, _L8("ZZZZZEEEEE"));
215 TEST2(err, KErrNone);
216 TEST2(fbuf.iFileWriteCount, 0);
217 TEST2(fbuf.iFileWriteAmount, 0);
219 //Third write operation. The offset is at the end of the buffer. Data length: 5;
220 err = fbuf.Write(15, _L8("CCCCC"));
221 TEST2(err, KErrNone);
222 TEST2(fbuf.iFileWriteCount, 0);
223 TEST2(fbuf.iFileWriteAmount, 0);
226 TEST2(err, KErrNone);
227 TEST2(fbuf.iFileWriteCount, 1);
228 TEST2(fbuf.iFileFlushCount, 1);
229 TEST2(fbuf.iFileWriteAmount, 20);
230 TEST2(fbuf.iFileSizeCount, 1);
234 VerifyFileContent(_L8("A1234ZZZZZEEEEECCCCC"));
236 (void)TheFs.Delete(KTestFile);
240 @SYMTestCaseID PDS-SQL-UT-4133
241 @SYMTestCaseDesc RFileBuf64 write test 2.
242 The test performs file write operations using RFileBuf64 class.
243 The write positions are beyound the end of the file but within the buffer capacity.
244 The purpose of the test: to verify the logic of RFileBuf64::Write().
245 @SYMTestActions RFileBuf64 write test 2.
246 @SYMTestExpectedResults Test must not fail
247 @SYMTestPriority High
253 RFileBuf64 fbuf(1024);
254 TInt err = fbuf.Create(TheFs, KTestFile, EFileWrite);
255 TEST2(err, KErrNone);
256 fbuf.ProfilerReset();
258 //First write operation. After the operation the file buffer must countain 10 bytes.
259 err = fbuf.Write(0, _L8("A123456789"));
260 TEST2(err, KErrNone);
261 TEST2(fbuf.iFileWriteCount, 0);
262 TEST2(fbuf.iFileWriteAmount, 0);
263 TEST2(fbuf.iFileSizeCount, 1);
265 //Second write operation. After the operation the file buffer must countain 10 + 10 zeros + 10 bytes.
266 err = fbuf.Write(20, _L8("FFGGHHJJKK"));
267 TEST2(err, KErrNone);
268 TEST2(fbuf.iFileWriteCount, 0);
269 TEST2(fbuf.iFileWriteAmount, 0);
270 TEST2(fbuf.iFileSizeCount, 1);
273 TEST2(err, KErrNone);
274 TEST2(fbuf.iFileWriteCount, 1);
275 TEST2(fbuf.iFileFlushCount, 1);
276 TEST2(fbuf.iFileWriteAmount, 30);
277 TEST2(fbuf.iFileSizeCount, 1);
282 pattern.Append(_L8("A123456789"));
283 pattern.AppendFill(TChar(0), 10);
284 pattern.Append(_L8("FFGGHHJJKK"));
285 VerifyFileContent(pattern);
287 (void)TheFs.Delete(KTestFile);
291 @SYMTestCaseID PDS-SQL-UT-4134
292 @SYMTestCaseDesc RFileBuf64 write test 3.
293 The test performs file write operations using RFileBuf64 class.
294 The write position is before the start of the buffer but there is room for move.
295 The purpose of the test: to verify the logic of RFileBuf64::Write().
296 @SYMTestActions RFileBuf64 write test 3.
297 @SYMTestExpectedResults Test must not fail
298 @SYMTestPriority High
304 //Iteration 1: The file length is 0, the first operation is "write beyond the end"
305 //Iteration 2: The file length is 30, the first write operation is within the file.
306 for(TInt i=0;i<2;++i)
308 RFileBuf64 fbuf(1024);
309 TInt err = i == 0 ? fbuf.Create(TheFs, KTestFile, EFileWrite) : fbuf.Open(TheFs, KTestFile, EFileWrite);
310 TEST2(err, KErrNone);
311 fbuf.ProfilerReset();
313 //First write operation. The offset is not 0. Data length: 10;
314 err = fbuf.Write(20, _L8("A123456789"));
315 TEST2(err, KErrNone);
316 TEST2(fbuf.iFileWriteCount, 0);
317 TEST2(fbuf.iFileWriteAmount, 0);
318 TEST2(fbuf.iFileSizeCount, 1);
320 //Second write operation. The offset is 0. Data length: 20;
321 err = fbuf.Write(0, _L8("AASSDDFFRR**********"));
322 TEST2(err, KErrNone);
323 TEST2(fbuf.iFileWriteCount, 0);
324 TEST2(fbuf.iFileWriteAmount, 0);
325 TEST2(fbuf.iFileSizeCount, 1);
328 TEST2(err, KErrNone);
329 TEST2(fbuf.iFileWriteCount, 1);
330 TEST2(fbuf.iFileFlushCount, 1);
331 TEST2(fbuf.iFileWriteAmount, 30);
332 TEST2(fbuf.iFileSizeCount, 1);
336 VerifyFileContent(_L8("AASSDDFFRR**********A123456789"));
338 (void)TheFs.Delete(KTestFile);
342 @SYMTestCaseID PDS-SQL-UT-4135
343 @SYMTestCaseDesc RFileBuf64 write test 4.
344 The test performs file write operations using RFileBuf64 class and verifies that
345 that the pending write data will be stored in the file when the buffer is closed.
346 The purpose of the test: to verify the logic of RFileBuf64::Write().
347 @SYMTestActions RFileBuf64 write test 4.
348 @SYMTestExpectedResults Test must not fail
349 @SYMTestPriority High
355 RFileBuf64 fbuf(1024);
356 TInt err = fbuf.Create(TheFs, KTestFile, EFileWrite);
357 TEST2(err, KErrNone);
358 fbuf.ProfilerReset();
361 err = fbuf.Write(0, _L8("A123456789"));
362 TEST2(err, KErrNone);
363 TEST2(fbuf.iFileWriteCount, 0);
364 TEST2(fbuf.iFileWriteAmount, 0);
365 TEST2(fbuf.iFileSizeCount, 1);
368 err = fbuf.Write(10, _L8(""));
369 TEST2(err, KErrNone);
370 TEST2(fbuf.iFileWriteCount, 0);
371 TEST2(fbuf.iFileWriteAmount, 0);
372 TEST2(fbuf.iFileSizeCount, 1);
376 VerifyFileContent(_L8("A123456789"));
378 (void)TheFs.Delete(KTestFile);
382 @SYMTestCaseID PDS-SQL-UT-4136
383 @SYMTestCaseDesc RFileBuf64 write test 5.
384 The test performs file write operations using RFileBuf64 class.
385 The data is written before the start of the file buffer and is too big to fit in the buffer.
386 The purpose of the test: to verify the logic of RFileBuf64::Write().
387 @SYMTestActions RFileBuf64 write test 5.
388 @SYMTestExpectedResults Test must not fail
389 @SYMTestPriority High
396 TInt err = fbuf.Create(TheFs, KTestFile, EFileWrite);
397 TEST2(err, KErrNone);
398 fbuf.ProfilerReset();
400 //First write operation. The offset is not 0. Data length: 10;
401 err = fbuf.Write(10, _L8("A123456789"));
402 TEST2(err, KErrNone);
403 TEST2(fbuf.iFileWriteCount, 0);
404 TEST2(fbuf.iFileWriteAmount, 0);
405 TEST2(fbuf.iFileSizeCount, 1);
407 //Second write operation. The offset is 0. Data length: 12, i.e. within the buffer - should have no write to the disk.
408 err = fbuf.Write(0, _L8("ZZXXCCVVBBNN"));
409 TEST2(err, KErrNone);
410 TEST2(fbuf.iFileWriteCount, 0);
411 TEST2(fbuf.iFileWriteAmount, 0);
412 TEST2(fbuf.iFileSizeCount, 1);
414 //Third write operation. The offet is 18. Data length: 5. The buffer should be written out to the file
415 // after "ab" is appended to the buffer. The new buffe after being emptied should have data "cde".
416 err = fbuf.Write(18, _L8("abcde"));
417 TEST2(err, KErrNone);
418 TEST2(fbuf.iFileWriteCount, 1);
419 TEST2(fbuf.iFileWriteAmount, 20);
420 TEST2(fbuf.iFileSizeCount, 1);
423 TEST2(err, KErrNone);
424 TEST2(fbuf.iFileWriteCount, 2);
425 TEST2(fbuf.iFileFlushCount, 1);
426 TEST2(fbuf.iFileWriteAmount, 23);
427 TEST2(fbuf.iFileSizeCount, 1);
431 VerifyFileContent(_L8("ZZXXCCVVBBNN234567abcde"));
433 (void)TheFs.Delete(KTestFile);
437 @SYMTestCaseID PDS-SQL-UT-4137
438 @SYMTestCaseDesc RFileBuf64 write test 6.
439 The test performs file write operations using RFileBuf64 class.
440 The data is written before the start of the file buffer and is too big to fit in the buffer.
441 The purpose of the test: to verify the logic of RFileBuf64::Write().
442 @SYMTestActions RFileBuf64 write test 6.
443 @SYMTestExpectedResults Test must not fail
444 @SYMTestPriority High
451 TInt err = fbuf.Create(TheFs, KTestFile, EFileWrite);
452 TEST2(err, KErrNone);
454 err = fbuf.Write(0, _L8("A123456789B123456789C123456789"));
455 TEST2(err, KErrNone);
457 TEST2(err, KErrNone);
459 VerifyFileContent(_L8("A123456789B123456789C123456789"));
461 err = fbuf.Open(TheFs, KTestFile, EFileWrite);
462 TEST2(err, KErrNone);
463 fbuf.ProfilerReset();
465 //First write operation. The offset is not 0. Data length: 10;
466 err = fbuf.Write(15, _L8("OOOOOOOOOO"));
467 TEST2(err, KErrNone);
468 TEST2(fbuf.iFileWriteCount, 0);
469 TEST2(fbuf.iFileWriteAmount, 0);
470 TEST2(fbuf.iFileSizeCount, 1);
472 //Second write operation. The offset is 0. Data length: 15;
473 err = fbuf.Write(0, _L8("TTTTTTTTTTTTTTT"));
474 TEST2(err, KErrNone);
475 TEST2(fbuf.iFileWriteCount, 1);
476 TEST2(fbuf.iFileWriteAmount, 10);
477 TEST2(fbuf.iFileSizeCount, 1);
480 TEST2(err, KErrNone);
481 TEST2(fbuf.iFileWriteCount, 2);
482 TEST2(fbuf.iFileFlushCount, 1);
483 TEST2(fbuf.iFileWriteAmount, 15 + 10);
484 TEST2(fbuf.iFileSizeCount, 1);
488 VerifyFileContent(_L8("TTTTTTTTTTTTTTTOOOOOOOOOO56789"));
490 (void)TheFs.Delete(KTestFile);
493 void PrepareReadTest()
496 TInt err = file.Create(TheFs, KTestFile, EFileWrite);
497 TEST2(err, KErrNone);
498 err = file.Write(_L8("A123456789ZZZZZZZZZZB-B-B-B-B-Y*Y*Y*Y*Y*"));
499 TEST2(err, KErrNone);
501 TEST2(err, KErrNone);
506 @SYMTestCaseID PDS-SQL-UT-4138
507 @SYMTestCaseDesc RFileBuf64 read test 1.
508 The test performs file read operations using RFileBuf64 class.
509 Tested "read" operations:
510 - Zero max length request;
511 - Too big read request;
512 - Read beyond the end of the file;
513 The purpose of the test: to verify the logic of RFileBuf64::Read().
514 @SYMTestActions RFileBuf64 read test 1.
515 @SYMTestExpectedResults Test must not fail
516 @SYMTestPriority High
522 const TInt KBufMaxSize = 20;// This is half the file size
523 RFileBuf64 fbuf(KBufMaxSize);
524 TInt err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead | EFileShareReadersOrWriters);
525 TEST2(err, KErrNone);
526 fbuf.ProfilerReset();
528 //Zero max length request
531 err = fbuf.Read(0, ptr1);
532 TEST2(err, KErrNone);
533 TEST2(fbuf.iFileReadCount, 0);
534 TEST2(fbuf.iFileReadAmount, 0);
535 TEST2(fbuf.iFileSizeCount, 0);
538 TBuf8<KBufMaxSize * 2> buf2;
539 err = fbuf.Read(0, buf2);
540 TEST2(err, KErrNone);
541 TEST2(fbuf.iFileReadCount, 1);
542 TEST2(fbuf.iFileReadAmount, (KBufMaxSize * 2));
543 TEST2(fbuf.iFileSizeCount, 1);
544 VerifyFileContent(buf2);
546 //Read beyond the end of the file
547 err = fbuf.Read(2000, buf2);
548 TEST2(err, KErrNone);
549 TEST2(buf2.Length(), 0);
551 //Write "5678" in the buffer, pos [4..8)
552 err = fbuf.Write(4, _L8("5678"));
553 TEST2(err, KErrNone);
555 //Too big request. There are pending data in the buffer.
556 TBuf8<KBufMaxSize + 2> buf3;
557 err = fbuf.Read(1, buf3);
558 TEST2(err, KErrNone);
559 VerifyFileContent(buf3, 1);
561 //Read from a non-zero file position to move the buffer start pos. The cached file pos will be 35 at the end.
563 err = fbuf.Read(30, buf4);
564 TEST2(err, KErrNone);
565 VerifyFileContent(buf4, 30);
566 err = fbuf.Read(35, buf4);
567 TEST2(err, KErrNone);
568 VerifyFileContent(buf4, 35);
570 //Too big request. No pending data in the buffer. The file read pos is before the position of the cached data in the buffer.
571 err = fbuf.Read(10, buf3);
572 TEST2(err, KErrNone);
573 VerifyFileContent(buf3, 10);
579 @SYMTestCaseID PDS-SQL-UT-4139
580 @SYMTestCaseDesc RFileBuf64 read test 2.
581 The test performs file read operations using RFileBuf64 class.
583 - Non-buffered reads;
585 The purpose of the test: to verify the logic of RFileBuf64::Read().
586 @SYMTestActions RFileBuf64 read test 2.
587 @SYMTestExpectedResults Test must not fail
588 @SYMTestPriority High
594 RFileBuf64 fbuf(1024);
595 TInt err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead | EFileShareReadersOrWriters);
596 TEST2(err, KErrNone);
597 fbuf.ProfilerReset();
599 //1. Read bytes [0..20]
601 err = fbuf.Read(0, buf1);
602 TEST2(err, KErrNone);
603 TEST2(fbuf.iFileReadCount, 1);
604 TEST2(fbuf.iFileReadAmount, 20);
605 TEST2(fbuf.iFileSizeCount, 1);
606 fbuf.ProfilerReset();
607 VerifyFileContent(buf1, 0);
609 //2. Read again, bytes [10..20]. They are not buffered.
611 err = fbuf.Read(10, buf2);
612 TEST2(err, KErrNone);
613 TEST2(fbuf.iFileReadCount, 1);
614 TEST2(fbuf.iFileReadAmount, 10);
615 TEST2(fbuf.iFileSizeCount, 0);
616 fbuf.ProfilerReset();
617 VerifyFileContent(buf2, 10);
619 //3. Read again, bytes [20..30]. They are not buffered. But the file buffer will be populated,
620 // because the file read position matches the guessed file read position from step 2.
621 err = fbuf.Read(20, buf2);
622 TEST2(err, KErrNone);
623 TEST2(fbuf.iFileReadCount, 1);
624 TEST2(fbuf.iFileReadAmount, (10 * 2));
625 TEST2(fbuf.iFileSizeCount, 0);
626 fbuf.ProfilerReset();
627 VerifyFileContent(buf2, 20);
629 //4. Read again, bytes [25..35]. This is a buffered read operation.
630 err = fbuf.Read(25, buf2);
631 TEST2(err, KErrNone);
632 TEST2(fbuf.iFileReadCount, 0);
633 TEST2(fbuf.iFileReadAmount, 0);
634 TEST2(fbuf.iFileSizeCount, 0);
635 fbuf.ProfilerReset();
636 VerifyFileContent(buf2, 25);
638 //5. Read again, bytes [15..25]. This is a non buffered read operation.
639 err = fbuf.Read(15, buf2);
640 TEST2(err, KErrNone);
641 TEST2(fbuf.iFileReadCount, 1);
642 TEST2(fbuf.iFileReadAmount, 10);
643 TEST2(fbuf.iFileSizeCount, 0);
644 fbuf.ProfilerReset();
645 VerifyFileContent(buf2, 15);
647 //6. Read again, bytes [25..35]. This is a buffered read operation. The buffer from step 3 is still there.
648 err = fbuf.Read(25, buf2);
649 TEST2(err, KErrNone);
650 TEST2(fbuf.iFileReadCount, 0);
651 TEST2(fbuf.iFileReadAmount, 0);
652 TEST2(fbuf.iFileSizeCount, 0);
653 fbuf.ProfilerReset();
654 VerifyFileContent(buf2, 25);
656 //7. Read again, bytes [35..45] - beyond the end of the file.
657 // This is a buffered read operation. The buffer from step 3 is still there.
658 err = fbuf.Read(35, buf2);
659 TEST2(err, KErrNone);
660 TEST2(fbuf.iFileReadCount, 0);
661 TEST2(fbuf.iFileReadAmount, 0);
662 TEST2(fbuf.iFileSizeCount, 0);
663 TEST2(buf2.Size(), 5);
664 fbuf.ProfilerReset();
665 VerifyFileContent(buf2, 35);
671 @SYMTestCaseID PDS-SQL-UT-4140
672 @SYMTestCaseDesc RFileBuf64 read test 3.
673 The test performs file read operations using RFileBuf64 class.
675 - Non-buffered reads;
677 - Part- buffered reads;
678 The purpose of the test: to verify the logic of RFileBuf64::Read().
679 @SYMTestActions RFileBuf64 read test 3.
680 @SYMTestExpectedResults Test must not fail
681 @SYMTestPriority High
687 RFileBuf64 fbuf(1024);
688 TInt err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead | EFileShareReadersOrWriters);
689 TEST2(err, KErrNone);
690 fbuf.ProfilerReset();
692 //1. Read bytes [0..10]. Non buffered.
694 err = fbuf.Read(0, buf1);
695 TEST2(err, KErrNone);
696 TEST2(fbuf.iFileReadCount, 1);
697 TEST2(fbuf.iFileReadAmount, 10);
698 TEST2(fbuf.iFileSizeCount, 1);
699 fbuf.ProfilerReset();
700 VerifyFileContent(buf1, 0);
702 //2. Read bytes [10..20]. Non buffered. But the file buffer is populated, bytes [10..40].
703 err = fbuf.Read(10, buf1);
704 TEST2(err, KErrNone);
705 TEST2(fbuf.iFileReadCount, 1);
706 TEST2(fbuf.iFileReadAmount, 30);
707 TEST2(fbuf.iFileSizeCount, 0);
708 fbuf.ProfilerReset();
709 VerifyFileContent(buf1, 10);
711 //3. Read bytes [25..35]. Buffered. Because the previous operation [2] performed a read-ahead operation.
712 err = fbuf.Read(25, buf1);
713 TEST2(err, KErrNone);
714 TEST2(fbuf.iFileReadCount, 0);
715 TEST2(fbuf.iFileReadAmount, 0);
716 TEST2(fbuf.iFileSizeCount, 0);
717 fbuf.ProfilerReset();
718 VerifyFileContent(buf1, 25);
720 //4. Write bytes [20..30]. Buffered. Read buffer is gone, the file buffer contains the [20..30] file area.
721 err = fbuf.Write(20, _L8("IIIIIQQQQQ"));
722 TEST2(err, KErrNone);
723 TEST2(fbuf.iFileReadCount, 0);
724 TEST2(fbuf.iFileReadAmount, 0);
725 TEST2(fbuf.iFileWriteCount, 0);
726 TEST2(fbuf.iFileWriteAmount, 0);
727 TEST2(fbuf.iFileSizeCount, 0);
728 fbuf.ProfilerReset();
730 //5. Read bytes [25..35]. Part-buffered. Part of pending writes picked up. Then the buffer is flushed.
731 err = fbuf.Read(25, buf1);
732 TEST2(err, KErrNone);
733 TEST2(fbuf.iFileReadCount, 1);
734 TEST2(fbuf.iFileReadAmount, 5);
735 TEST2(fbuf.iFileWriteCount, 1);
736 TEST2(fbuf.iFileWriteAmount, 10);
737 TEST2(fbuf.iFileSizeCount, 0);
739 fbuf.ProfilerReset();
741 TEST2(err, KErrNone);
743 //All cached data should have been written to the file before the Flush() call.
744 TEST2(fbuf.iFileReadCount, 0);
745 TEST2(fbuf.iFileReadAmount, 0);
746 TEST2(fbuf.iFileWriteCount, 0);
747 TEST2(fbuf.iFileWriteAmount, 0);
748 TEST2(fbuf.iFileSizeCount, 0);
749 TEST2(fbuf.iFileFlushCount, 1);
751 fbuf.ProfilerReset();
752 VerifyFileContent(buf1, 25);
754 //6. The buffer is empty after the last flush. Write bytes [0..10]. The file buffer contains the [0..10] file area.
755 err = fbuf.Write(0, _L8("PPOOIIUUYY"));
756 TEST2(err, KErrNone);
757 TEST2(fbuf.iFileReadCount, 0);
758 TEST2(fbuf.iFileReadAmount, 0);
759 TEST2(fbuf.iFileWriteCount, 0);
760 TEST2(fbuf.iFileWriteAmount, 0);
761 TEST2(fbuf.iFileSizeCount, 0);
762 fbuf.ProfilerReset();
764 //7. Read bytes [5..15]. Part buffered. Pending writes picked up. The content is written to the file.
765 err = fbuf.Read(5, buf1);
766 TEST2(err, KErrNone);
767 TEST2(fbuf.iFileReadCount, 1);
768 TEST2(fbuf.iFileReadAmount, 5);
769 TEST2(fbuf.iFileWriteCount, 1);
770 TEST2(fbuf.iFileWriteAmount, 10);
771 TEST2(fbuf.iFileSizeCount, 0);
772 fbuf.ProfilerReset();
773 VerifyFileContent(buf1, 5);
779 @SYMTestCaseID PDS-SQL-UT-4141
780 @SYMTestCaseDesc RFileBuf64::SetReadAheadSize() test.
781 The test iterates over all existing drives.
782 For each R/W drive a test file is created using RFileBuf64 class.
783 Then the test collects information regarding the block size, cluster size and
784 read buffer size and calls RFileBuf64::SetReadAheadSize() with these parameters
785 to check how the read-ahead buffer size will be recalculated.
786 @SYMTestActions RFileBuf64::SetReadAheadSize() test.
787 @SYMTestExpectedResults Test must not fail
788 @SYMTestPriority High
792 void SetReadAheadSizeTest()
794 TheTest.Printf(_L("==================\r\n"));
795 _LIT(KType1, "Not present");
796 _LIT(KType2, "Unknown");
797 _LIT(KType3, "Floppy");
798 _LIT(KType4, "Hard disk");
799 _LIT(KType5, "CD ROM");
800 _LIT(KType6, "RAM disk");
801 _LIT(KType7, "Flash");
802 _LIT(KType8, "ROM drive");
803 _LIT(KType9, "Remote drive");
804 _LIT(KType10,"NAND flash");
805 _LIT(KType11,"Rotating media");
807 for(TInt drive=EDriveA;drive<=EDriveZ;++drive)
809 TDriveInfo driveInfo;
810 TInt err = TheFs.Drive(driveInfo, drive);
814 err = TheFs.Volume(vinfo, drive);
817 TVolumeIOParamInfo vparam;
818 err = TheFs.VolumeIOParam(drive, vparam);
819 TEST2(err, KErrNone);
821 err = TheFs.QueryVolumeInfoExt(drive, EFileSystemSubType, vinfoex8);
822 TEST2(err, KErrNone);
823 TPtrC vinfoex((const TUint16*)(vinfoex8.Ptr() + 8), vinfoex8[0]);
824 TPtrC KMediaTypeNames[] = {KType1(), KType2(), KType3(), KType4(), KType5(), KType6(), KType7(), KType8(), KType9(), KType10(), KType11()};
825 TheTest.Printf(_L("Drive: %C:, Type: %16.16S, File System: %8.8S, Size: %d Mb.\r\n"), 'A' + drive, &KMediaTypeNames[driveInfo.iType], &vinfoex, (TInt)(vinfo.iSize / (1024 * 1024)));
826 TheTest.Printf(_L(" Size: %ld bytes.\r\n"), vinfo.iSize);
827 TheTest.Printf(_L(" Block size=%d, Cluster size=%d, Read buffer size=%d.\r\n"), vparam.iBlockSize, vparam.iClusterSize, vparam.iRecReadBufSize);
828 if(driveInfo.iType == EMediaRam || driveInfo.iType == EMediaHardDisk || driveInfo.iType == EMediaFlash || driveInfo.iType == EMediaNANDFlash)
830 TDriveUnit drvUnit(drive);
831 TDriveName drvName = drvUnit.Name();
833 parse.Set(KTestFile2, &drvName, NULL);
834 TheDbName.Copy(parse.FullName());
835 TRAP(err, BaflUtils::EnsurePathExistsL(TheFs, TheDbName));
836 if(err == KErrNone || err == KErrAlreadyExists)
838 (void)TheFs.Delete(TheDbName);
839 RFileBuf64 fbuf64(8 * 1024);
840 err = fbuf64.Create(TheFs, TheDbName, EFileRead | EFileWrite);
841 TEST2(err, KErrNone);
842 TInt readAhead = fbuf64.SetReadAheadSize(vparam.iBlockSize, vparam.iRecReadBufSize);
843 TheTest.Printf(_L(" Read-ahead size=%d.\r\n"), readAhead);
845 (void)TheFs.Delete(TheDbName);
849 TheTest.Printf(_L("Drive %C. BaflUtils::EnsurePathExistsL() has failed with err=%d.\r\n"), 'A' + drive, err);
855 TheTest.Printf(_L("Drive %C. RFs::Volume() has failed with err=%d.\r\n"), 'A' + drive, err);
860 TheTest.Printf(_L("Drive %C. RFs::Drive() has failed with err=%d.\r\n"), 'A' + drive, err);
863 TheTest.Printf(_L("==================\r\n"));
865 RFileBuf64 fbuf64(8 * 1024);//buffer capacity = 8Kb
867 //"ReadRecBufSize" defined and is power of two, the "BlockSize" is also defined and is power of two
868 TInt err2 = fbuf64.Create(TheFs, TheDbName, EFileRead | EFileWrite);
869 TEST2(err2, KErrNone);
870 TInt blockSize = 4096; TInt readRecBufSize = 2048;
871 TInt readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
872 TEST2(readAhead2, readRecBufSize);
875 //"ReadRecBufSize" defined and is power of two but is less than the default read-ahead value
876 err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
877 TEST2(err2, KErrNone);
878 blockSize = 0; readRecBufSize = 128;
879 readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
880 TEST2(readAhead2, RFileBuf64::KDefaultReadAheadSize);
883 //"ReadRecBufSize" defined and is power of two but is bigger than the buffer capacity
884 err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
885 TEST2(err2, KErrNone);
886 blockSize = -10; readRecBufSize = fbuf64.iCapacity * 2;
887 readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
888 TEST2(readAhead2, fbuf64.iCapacity);
891 //"ReadRecBufSize" defined but is not power of two, "BlockSize" defined but is less than the default read-ahead value
892 err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
893 TEST2(err2, KErrNone);
894 blockSize = 512; readRecBufSize = 4000;
895 readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
896 TEST2(readAhead2, RFileBuf64::KDefaultReadAheadSize);
899 //"ReadRecBufSize" defined but is not power of two, "BlockSize" defined and is bigger than the default read-ahead value
900 err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
901 TEST2(err2, KErrNone);
902 blockSize = 4096; readRecBufSize = 4000;
903 readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
904 TEST2(readAhead2, blockSize);
907 //"ReadRecBufSize" defined but is not power of two, "BlockSize" defined and is bigger than the buffer capacity
908 err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
909 TEST2(err2, KErrNone);
910 blockSize = fbuf64.iCapacity * 2; readRecBufSize = 1;
911 readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
912 TEST2(readAhead2, fbuf64.iCapacity);
915 //"ReadRecBufSize" negative, "BlockSize" defined but is not power of two
916 err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
917 TEST2(err2, KErrNone);
918 blockSize = 1000; readRecBufSize = -2;
919 readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
920 TEST2(readAhead2, RFileBuf64::KDefaultReadAheadSize);
923 //"ReadRecBufSize" negative, "BlockSize" negative
924 err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
925 TEST2(err2, KErrNone);
926 blockSize = -1; readRecBufSize = -2;
927 readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
928 TEST2(readAhead2, RFileBuf64::KDefaultReadAheadSize);
931 (void)TheFs.Delete(TheDbName);
935 @SYMTestCaseID PDS-SQL-UT-4142
936 @SYMTestCaseDesc RFileBuf64 OOM test.
937 The test calls RFileBuf64:Create(), RFileBuf64:Open() and RFileBuf64:Temp() in an OOM
938 simulation loop and verifies that no memory is leaked.
939 @SYMTestActions RFileBuf64 OOM test.
940 @SYMTestExpectedResults Test must not fail
941 @SYMTestPriority High
945 void OomTest(TOomTestType aOomTestType)
947 (void)TheFs.Delete(KTestFile);
949 if(aOomTestType == EOomOpenTest)
952 TInt err2 = file.Create(TheFs, KTestFile, EFileWrite | EFileRead);
954 TEST2(err2, KErrNone);
957 TFileName tmpFileName;
958 TInt err = KErrNoMemory;
959 TInt failingAllocationNo = 0;
960 RFileBuf64 fbuf(1024);
961 TheTest.Printf(_L("Iteration:\r\n"));
962 while(err == KErrNoMemory)
964 TheTest.Printf(_L(" %d"), ++failingAllocationNo);
967 MarkAllocatedCells();
970 __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, failingAllocationNo, KBurstRate);
975 err = fbuf.Create(TheFs, KTestFile, EFileWrite | EFileRead);
978 err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead);
982 err = fbuf.Temp(TheFs, KTestDir, tmpFileName, EFileWrite | EFileRead);
994 CheckAllocatedCells();
998 if(err != KErrNoMemory)
1000 TEST2(err, KErrNone);
1002 else if(aOomTestType == EOomCreateTest)
1004 TInt err2 = TheFs.Entry(KTestFile, entry);
1005 TEST2(err2, KErrNotFound);
1007 else if(aOomTestType == EOomTempTest)
1009 if(tmpFileName.Size() > 0)
1011 TInt err2 = TheFs.Entry(tmpFileName, entry);
1012 TEST2(err2, KErrNotFound);
1016 TEST2(err, KErrNone);
1017 TheTest.Printf(_L("\r\n=== OOM Test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
1019 if(aOomTestType == EOomTempTest)
1021 (void)TheFs.Delete(tmpFileName);
1023 (void)TheFs.Delete(KTestFile);
1027 @SYMTestCaseID PDS-SQL-UT-4195
1028 @SYMTestCaseDesc RFileBuf64::Create() file I/O error simulation test.
1029 The test calls RFileBuf64:Create() in a file I/O error simulation loop.
1030 @SYMTestActions RFileBuf64::Create() file I/O error simulation test.
1031 @SYMTestExpectedResults Test must not fail
1032 @SYMTestPriority High
1035 void CreateFileIoErrTest()
1037 TInt err = KErrGeneral;
1039 for(;err<KErrNone;++cnt)
1041 TheTest.Printf(_L("===Iteration %d. Simulated error:\r\n"), cnt);
1042 for (TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError)
1044 TheTest.Printf(_L("%d "), fsError);
1046 (void)TheFs.SetErrorCondition(fsError, cnt);
1047 RFileBuf64 fbuf(1024);//buffer capacity = 1024 bytes
1048 err = fbuf.Create(TheFs, KTestFile3, EFileRead | EFileWrite);
1049 (void)TheFs.SetErrorCondition(KErrNone);
1052 TInt err2 = TheFs.Delete(KTestFile3);
1053 TInt expectedErr = err == KErrNone ? KErrNone : KErrNotFound;
1054 TEST2(err2, expectedErr);
1056 TheTest.Printf(_L("\r\n"));
1058 TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt);
1062 @SYMTestCaseID PDS-SQL-UT-4196
1063 @SYMTestCaseDesc RFileBuf64::Open() file I/O error simulation test.
1064 The test calls RFileBuf64:Open() in a file I/O error simulation loop.
1065 @SYMTestActions RFileBuf64::Open() file I/O error simulation test.
1066 @SYMTestExpectedResults Test must not fail
1067 @SYMTestPriority High
1070 void OpenFileIoErrTest()
1072 RFileBuf64 fbuf(1024);//buffer capacity = 1024 bytes
1073 TInt err = fbuf.Create(TheFs, KTestFile3, EFileRead | EFileWrite);
1075 TEST2(err, KErrNone);
1078 for(;err<KErrNone;++cnt)
1080 TheTest.Printf(_L("===Iteration %d. Simulated error:\r\n"), cnt);
1081 for (TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError)
1083 TheTest.Printf(_L("%d "), fsError);
1085 (void)TheFs.SetErrorCondition(fsError, cnt);
1086 err = fbuf.Open(TheFs, KTestFile3, EFileRead | EFileWrite);
1087 (void)TheFs.SetErrorCondition(KErrNone);
1091 TheTest.Printf(_L("\r\n"));
1093 TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt);
1094 (void)TheFs.Delete(KTestFile3);
1098 @SYMTestCaseID PDS-SQL-UT-4197
1099 @SYMTestCaseDesc RFileBuf64::Temp() file I/O error simulation test.
1100 The test calls RFileBuf64:Temp() in a file I/O error simulation loop.
1101 @SYMTestActions RFileBuf64::temp() file I/O error simulation test.
1102 @SYMTestExpectedResults Test must not fail
1103 @SYMTestPriority High
1106 void TempFileIoErrTest()
1108 TInt err = KErrGeneral;
1110 for(;err<KErrNone;++cnt)
1112 TheTest.Printf(_L("===Iteration %d. Simulated error:\r\n"), cnt);
1113 for (TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError)
1115 TheTest.Printf(_L("%d "), fsError);
1117 (void)TheFs.SetErrorCondition(fsError, cnt);
1118 RFileBuf64 fbuf(1024);//buffer capacity = 1024 bytes
1119 TFileName tmpFileName;
1120 err = fbuf.Temp(TheFs, KTestDir, tmpFileName, EFileWrite | EFileRead);
1121 (void)TheFs.SetErrorCondition(KErrNone);
1124 TInt err2 = TheFs.Delete(tmpFileName);
1125 TInt expectedErr = err == KErrNone ? KErrNone : KErrNotFound;
1126 TEST2(err2, expectedErr);
1128 TheTest.Printf(_L("\r\n"));
1130 TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt);
1134 @SYMTestCaseID PDS-SQL-UT-4207
1135 @SYMTestCaseDesc RFileBuf64::Write() OOM test.
1136 The test calls RFileBuf64:Write() in an OOM
1137 simulation loop and verifies that no memory is leaked.
1138 The test also check that RFileBuf::DoSetCapacity() correctly operates in
1139 "out of memory" situation.
1140 @SYMTestActions RFileBuf64::Write() OOM test.
1141 @SYMTestExpectedResults Test must not fail
1142 @SYMTestPriority High
1147 HBufC8* databuf = HBufC8::New(KPageSize);
1148 TEST(databuf != NULL);
1149 TPtr8 dataptr = databuf->Des();
1150 dataptr.SetLength(KPageSize);
1151 dataptr.Fill(TChar(KChar));
1153 TInt err = KErrNoMemory;
1154 TInt failingAllocationNo = 0;
1155 TheTest.Printf(_L("Iteration:\r\n"));
1156 while(err == KErrNoMemory)
1158 TheTest.Printf(_L(" %d"), ++failingAllocationNo);
1160 (void)TheFs.Delete(KTestFile);
1163 MarkAllocatedCells();
1166 __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, failingAllocationNo, KBurstRate);
1168 const TInt KDefaultBufCapacity = 1024;
1169 RFileBuf64 fbuf(KDefaultBufCapacity);
1170 err = fbuf.Create(TheFs, KTestFile, EFileWrite | EFileRead);
1173 err = fbuf.Write(0LL, dataptr);
1180 CheckAllocatedCells();
1183 TEST2(err, KErrNone);
1185 err = file.Open(TheFs, KTestFile, EFileRead);
1186 TEST2(err, KErrNone);
1188 err = file.Read(dataptr);
1189 TEST2(err, KErrNone);
1191 TEST2(dataptr.Length(), KPageSize);
1192 for(TInt i=0;i<KPageSize;++i)
1194 TEST(dataptr[i] == KChar);
1196 TheTest.Printf(_L("\r\n=== OOM Test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
1198 //The file is left undeleted - to be used in ReadOomTest().
1203 @SYMTestCaseID PDS-SQL-UT-4208
1204 @SYMTestCaseDesc RFileBuf64::Read() OOM test.
1205 The test calls RFileBuf64:Read() in an OOM
1206 simulation loop and verifies that no memory is leaked.
1207 The test also check that RFileBuf::DoSetCapacity() correctly operates in
1208 "out of memory" situation.
1209 @SYMTestActions RFileBuf64::Read() OOM test.
1210 @SYMTestExpectedResults Test must not fail
1211 @SYMTestPriority High
1216 HBufC8* databuf = HBufC8::New(KPageSize);
1217 TEST(databuf != NULL);
1218 TPtr8 dataptr = databuf->Des();
1220 TInt err = KErrNoMemory;
1221 TInt failingAllocationNo = 0;
1222 TheTest.Printf(_L("Iteration:\r\n"));
1223 while(err == KErrNoMemory)
1225 TheTest.Printf(_L(" %d"), ++failingAllocationNo);
1228 MarkAllocatedCells();
1231 __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, failingAllocationNo, KBurstRate);
1233 const TInt KDefaultBufCapacity = 1024;
1234 RFileBuf64 fbuf(KDefaultBufCapacity);
1235 err = fbuf.Open(TheFs, KTestFile, EFileRead);
1238 err = fbuf.Read(0LL, dataptr);
1245 CheckAllocatedCells();
1248 TEST2(err, KErrNone);
1250 err = file.Open(TheFs, KTestFile, EFileRead);
1251 TEST2(err, KErrNone);
1253 err = file.Read(dataptr);
1254 TEST2(err, KErrNone);
1256 TEST2(dataptr.Length(), KPageSize);
1257 for(TInt i=0;i<KPageSize;++i)
1259 TEST(dataptr[i] == KChar);
1261 TheTest.Printf(_L("\r\n=== OOM Test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
1263 (void)TheFs.Delete(KTestFile);
1268 @SYMTestCaseID PDS-SQL-CT-4212
1269 @SYMTestCaseDesc RFileBuf64::Write() test.
1270 The test performs file write operations using RFileBuf64 class.
1271 Teh test sumilates the write operation at the conditions:
1273 1. There are 8 pages to be writted to the file.
1274 2. Each page is 16 bytes
1275 3. The size of RFileBuf64 is 4 pages, i.e. 64 bytes.
1276 4. The order of write is not sequential.
1278 @SYMTestActions Write database pages.
1279 @SYMTestExpectedResults Test must not fail
1280 @SYMTestPriority High
1282 void TestSetSizeCounter()
1284 const TInt KPageSize = 16;
1285 const TInt KBufSize = 4 * KPageSize;
1286 RFileBuf64 fbuf(KBufSize);
1287 (void)TheFs.Delete(KTestFile);
1288 TInt err = fbuf.Create(TheFs, KTestFile, EFileRead | EFileWrite);
1289 TEST2(err, KErrNone);
1290 const TInt KMaxPage = 8;
1291 TUint8 fileData[KMaxPage][KPageSize];
1292 TPtrC8 pageData[KMaxPage];
1293 for(TInt i = 0;i <KMaxPage;++i)
1295 Mem::Fill(fileData[i], KPageSize, TChar('a' + i));
1296 const TUint8* p = fileData[i];
1297 pageData[i].Set(p, KPageSize);
1300 fbuf.ProfilerReset();
1301 //Write the first 4 pages
1302 for (TInt ii = 0; ii < 4; ii++)
1304 err = fbuf.Write(ii * KPageSize, pageData[ii]);
1305 TEST2(err, KErrNone);
1308 err = fbuf.Write(2 * KPageSize, pageData[2]);
1309 TEST2(err, KErrNone);
1311 TEST2(fbuf.iFileWriteCount, 0);
1312 TEST2(fbuf.iFileSetSizeCount, 0);
1313 //Write pages 5, 4, 6, 7
1314 err = fbuf.Write(5 * KPageSize, pageData[5]);
1315 TEST2(err, KErrNone);
1317 TEST2(fbuf.iFileWriteCount, 1);
1318 TEST2(fbuf.iFileSetSizeCount, 0);
1320 err = fbuf.Write(4 * KPageSize, pageData[4]);
1321 TEST2(err, KErrNone);
1322 err = fbuf.Write(6 * KPageSize, pageData[6]);
1323 TEST2(err, KErrNone);
1324 err = fbuf.Write(7 * KPageSize, pageData[7]);
1325 TEST2(err, KErrNone);
1327 TEST2(fbuf.iFileWriteCount, 1);
1328 TEST2(fbuf.iFileSetSizeCount, 0);
1331 TEST2(err, KErrNone);
1333 TEST2(fbuf.iFileWriteCount, 2);
1334 TEST2(fbuf.iFileSetSizeCount, 0);
1337 (void)TheFs.Delete(KTestFile);
1340 ///////////////////////////////////////////////////////////////////////////////////////
1344 //Panic thread function.
1345 //It will cast aData parameter to a TFunctor pointer and call it.
1346 //The expectation is that the called function will panic and kill the panic thread.
1347 TInt ThreadFunc(void* aData)
1349 CTrapCleanup* tc = CTrapCleanup::New();
1352 User::SetJustInTime(EFalse); // disable debugger panic handling
1354 TFunctor* obj = reinterpret_cast<TFunctor*> (aData);
1356 (*obj)();//call the panic function
1364 //PanicTest function will create a new thread - panic thread, giving it a pointer to the function which has to
1365 //be executed and the expectation is that the function will panic and kill the panic thread.
1366 //PanicTest function will check the panic thread exit code, exit category and the panic code.
1367 void PanicTest(TFunctor& aFunctor, TExitType aExpectedExitType, const TDesC& aExpectedCategory, TInt aExpectedPanicCode)
1370 _LIT(KThreadName,"SqlFileBufPanicThread");
1371 TEST2(thread.Create(KThreadName, &ThreadFunc, 0x2000, 0x1000, 0x10000, (void*)&aFunctor, EOwnerThread), KErrNone);
1373 TRequestStatus status;
1374 thread.Logon(status);
1375 TEST2(status.Int(), KRequestPending);
1377 User::WaitForRequest(status);
1378 User::SetJustInTime(ETrue); // enable debugger panic handling
1380 TEST2(thread.ExitType(), aExpectedExitType);
1381 TEST(thread.ExitCategory() == aExpectedCategory);
1382 TEST2(thread.ExitReason(), aExpectedPanicCode);
1384 CLOSE_AND_WAIT(thread);
1387 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
1388 ////////////////////////////// Panic test functions /////////////////////////////////////////////////
1389 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
1391 //Panic when calling RFileBuf64::RFileBuf64() with an invalid buffer capacity value.
1392 class TSqlFileBuf_InvalidCapacity : public TFunctor
1395 virtual void operator()()
1397 RFileBuf64 fbuf(-8192);//panic here - "-8192" - negative buffer capacity
1400 static TSqlFileBuf_InvalidCapacity TheSqlFileBuf_InvalidCapacity;
1402 //Panic when calling RFileBuf64::Create() with an invalid file handle.
1403 class TSqlFileBuf_InvalidFileHandle1 : public TFunctor
1406 virtual void operator()()
1408 RFileBuf64 fbuf(8192);
1410 fbuf.Create(fs, _L("aaa.db"), EFileRead);//panic here - invalid file handle
1413 static TSqlFileBuf_InvalidFileHandle1 TheSqlFileBuf_InvalidFileHandle1;
1415 //Panic when calling RFileBuf64::Create() with an invalid file name.
1416 class TSqlFileBuf_InvalidFileName1 : public TFunctor
1419 virtual void operator()()
1421 RFileBuf64 fbuf(8192);
1423 TInt err = fs.Connect();
1424 TEST2(err, KErrNone);
1425 fbuf.Create(fs, KNullDesC, EFileRead);//panic here - invalid file name
1429 static TSqlFileBuf_InvalidFileName1 TheSqlFileBuf_InvalidFileName1;
1431 //Panic when calling RFileBuf64::Open() with an invalid file handle.
1432 class TSqlFileBuf_InvalidFileHandle2 : public TFunctor
1435 virtual void operator()()
1437 RFileBuf64 fbuf(8192);
1439 fbuf.Open(fs, _L("aaa.db"), EFileRead);//panic here - invalid file handle
1442 static TSqlFileBuf_InvalidFileHandle2 TheSqlFileBuf_InvalidFileHandle2;
1444 //Panic when calling RFileBuf64::Open() with an invalid file name.
1445 class TSqlFileBuf_InvalidFileName2 : public TFunctor
1448 virtual void operator()()
1450 RFileBuf64 fbuf(8192);
1452 TInt err = fs.Connect();
1453 TEST2(err, KErrNone);
1454 fbuf.Open(fs, KNullDesC, EFileRead);//panic here - invalid file name
1458 static TSqlFileBuf_InvalidFileName2 TheSqlFileBuf_InvalidFileName2;
1460 //Panic when calling RFileBuf64::Temp() with an invalid file handle.
1461 class TSqlFileBuf_InvalidFileHandle3 : public TFunctor
1464 virtual void operator()()
1466 RFileBuf64 fbuf(8192);
1469 fbuf.Temp(fs, _L("c:\\test"), fname, EFileRead);//panic here - invalid file handle
1472 static TSqlFileBuf_InvalidFileHandle3 TheSqlFileBuf_InvalidFileHandle3;
1474 //Panic when calling RFileBuf64::AdoptFromClient() with an invalid message handle.
1475 class TSqlFileBuf_InvalidMessageHandle : public TFunctor
1478 virtual void operator()()
1480 RFileBuf64 fbuf(8192);
1482 fbuf.AdoptFromClient(msg, 0, 1);//panic here - invalid message handle
1485 static TSqlFileBuf_InvalidMessageHandle TheSqlFileBuf_InvalidMessageHandle;
1487 //Panic when calling RFileBuf64::Read() with an invalid file position.
1488 class TSqlFileBuf_InvalidReadPos : public TFunctor
1491 virtual void operator()()
1493 RFileBuf64 fbuf(8192);
1495 fbuf.Read(-1024, buf);//panic here - invalid file position
1498 static TSqlFileBuf_InvalidReadPos TheSqlFileBuf_InvalidReadPos;
1500 //Panic when calling RFileBuf64::Write() with an invalid file position.
1501 class TSqlFileBuf_InvalidWritePos : public TFunctor
1504 virtual void operator()()
1506 RFileBuf64 fbuf(8192);
1508 fbuf.Write(-1024, buf);//panic here - invalid file position
1511 static TSqlFileBuf_InvalidWritePos TheSqlFileBuf_InvalidWritePos;
1513 //Panic when calling RFileBuf64::SetSize() with an invalid file size.
1514 class TSqlFileBuf_InvalidSize : public TFunctor
1517 virtual void operator()()
1519 RFileBuf64 fbuf(8192);
1521 fbuf.SetSize(-1024);//panic here - invalid file size
1524 static TSqlFileBuf_InvalidSize TheSqlFileBuf_InvalidSize;
1529 @SYMTestCaseID PDS-SQL-UT-4236
1530 @SYMTestCaseDesc RFileBuf64 panic test.
1531 The test runs a thread. The thread will create a RFileBuf64 object
1532 and put the object in a situation where the file buffer cannot perform
1533 its duties anymore and will raise a panic. The test verifies that the file
1534 buffer implementation properly detects anomalities such as bad parameters,
1535 null handles, etc...
1536 @SYMTestActions RFileBuf64 panic test.
1537 @SYMTestExpectedResults Test must not fail
1538 @SYMTestPriority High
1540 void FileBufPanicTest()
1543 _LIT(KPanicCategory, "FBuf64");
1544 PanicTest(TheSqlFileBuf_InvalidCapacity, EExitPanic, KPanicCategory, 1);
1545 PanicTest(TheSqlFileBuf_InvalidFileHandle1, EExitPanic, KPanicCategory, 7);
1546 PanicTest(TheSqlFileBuf_InvalidFileName1, EExitPanic, KPanicCategory, 10);
1547 PanicTest(TheSqlFileBuf_InvalidFileHandle2, EExitPanic, KPanicCategory, 7);
1548 PanicTest(TheSqlFileBuf_InvalidFileName2, EExitPanic, KPanicCategory, 10);
1549 PanicTest(TheSqlFileBuf_InvalidFileHandle3, EExitPanic, KPanicCategory, 7);
1550 PanicTest(TheSqlFileBuf_InvalidMessageHandle, EExitPanic, KPanicCategory, 8);
1551 PanicTest(TheSqlFileBuf_InvalidReadPos, EExitPanic, KPanicCategory, 4);
1552 PanicTest(TheSqlFileBuf_InvalidWritePos, EExitPanic, KPanicCategory, 4);
1553 PanicTest(TheSqlFileBuf_InvalidSize, EExitPanic, KPanicCategory, 5);
1555 TheTest.Printf(_L("This test can be run in _DEBUG mode only!"));
1561 TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4132 RFileBuf64 write test 1"));
1563 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4133 RFileBuf64 write test 2"));
1565 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4134 RFileBuf64 write test 3"));
1567 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4135 RFileBuf64 write test 4"));
1569 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4136 RFileBuf64 write test 5"));
1571 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4137 RFileBuf64 write test 6"));
1573 TheTest.Next( _L("RFileBuf64 read test - preparation"));
1575 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4138 RFileBuf64 read test 1"));
1577 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4139 RFileBuf64 read test 2"));
1579 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4140 RFileBuf64 read test 3"));
1582 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4141 RFileBuf64::SetReadAheadSize() test"));
1583 SetReadAheadSizeTest();
1585 (void)TheFs.Delete(KTestFile);
1587 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Create() OOM test"));
1588 OomTest(EOomCreateTest);
1589 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Open() OOM test"));
1590 OomTest(EOomOpenTest);
1591 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Temp() OOM test"));
1592 OomTest(EOomTempTest);
1593 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4207 RFileBuf64::Write() OOM test"));
1595 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4208 RFileBuf64::Read() OOM test"));
1598 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4195 RFileBuf64::Create() file I/O error simulation test"));
1599 CreateFileIoErrTest();
1600 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4196 RFileBuf64::Open() file I/O error simulation test"));
1601 OpenFileIoErrTest();
1602 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4197 RFileBuf64::Temp() file I/O error simulation test"));
1603 OpenFileIoErrTest();
1604 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-CT-4212 RFileBuf64::Write() test"));
1605 TestSetSizeCounter();
1607 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4236 RFileBuf64 panic test"));
1615 CTrapCleanup* tc = CTrapCleanup::New();
1616 TheTest(tc != NULL);
1632 User::Heap().Check();
1642 TheTest.Start(_L("This test works only if the test is built with _SQLPROFILER macro defined!"));
1649 #endif//_SQLPROFILER