1017 TEST(err >= 0); |
1017 TEST(err >= 0); |
1018 TheDb.Close(); |
1018 TheDb.Close(); |
1019 (void)RSqlDatabase::Delete(KDbName); |
1019 (void)RSqlDatabase::Delete(KDbName); |
1020 } |
1020 } |
1021 |
1021 |
|
1022 /** |
|
1023 @SYMTestCaseID PDS-SQL-CT-4209 |
|
1024 @SYMTestCaseDesc Corrupted database background compaction test. |
|
1025 The test creates a database, inserts records, then deletes part of the records. |
|
1026 The free pages count should be big enough to kick off the background compaction. |
|
1027 But the database is closed immediatelly and then the db file is corrupted in a such |
|
1028 way that during the "database open" operation the corruption is not detected. |
|
1029 But the corruption is detected during the background compaction. The SQL server |
|
1030 should detect during the compaction that the databas eis corrupted and should |
|
1031 stop compacting the database (and draining the battery). Unfortunatelly, this |
|
1032 cannot be tested automatically, so a breakpoint should be set at the User::After() |
|
1033 call, and then the SQL server side should be debugged in order to berify that the |
|
1034 background compaction is really stopped for that database. |
|
1035 @SYMTestPriority High |
|
1036 @SYMTestActions Corrupted database background compaction test. |
|
1037 @SYMTestExpectedResults Test must not fail |
|
1038 @SYMDEF ou1cimx1#406830 |
|
1039 */ |
|
1040 void CorruptedDbBckgCompactionTest() |
|
1041 { |
|
1042 //Step 1: Create a database with some records |
|
1043 const TInt KOperationCount = 100; |
|
1044 (void)RSqlDatabase::Delete(KDbName); |
|
1045 TInt err = TheDb.Create(KDbName); |
|
1046 TEST2(err, KErrNone); |
|
1047 err = TheDb.Exec(_L("BEGIN")); |
|
1048 TEST(err >= 0); |
|
1049 err = TheDb.Exec(_L("CREATE TABLE A(I INTEGER, T TEXT)")); |
|
1050 TEST2(err, 1); |
|
1051 TheText.SetLength(KTextLen); |
|
1052 TheText.Fill(TChar('A')); |
|
1053 for(TInt i=0;i<=KOperationCount;++i) |
|
1054 { |
|
1055 TheSqlTexLen.Format(_L("INSERT INTO A VALUES(%d, '%S')"), i + 1, &TheText); |
|
1056 err = TheDb.Exec(TheSqlTexLen); |
|
1057 TEST2(err, 1); |
|
1058 } |
|
1059 err = TheDb.Exec(_L("COMMIT")); |
|
1060 TEST(err >= 0); |
|
1061 //Step 2: Delete some records to free some space |
|
1062 err = TheDb.Exec(_L("DELETE FROM A WHERE (I % 2) = 0")); |
|
1063 TEST(err > 0); |
|
1064 //Step 3: Close the database |
|
1065 TheDb.Close(); |
|
1066 //Step 4: Corrupt the database |
|
1067 RFs fs; |
|
1068 err = fs.Connect(); |
|
1069 TEST2(err, KErrNone); |
|
1070 RFile file; |
|
1071 err = file.Open(fs, KDbName, EFileRead | EFileWrite); |
|
1072 TEST2(err, KErrNone); |
|
1073 TInt pos = 5000; |
|
1074 err = file.Seek(ESeekStart, pos); |
|
1075 TEST2(err, KErrNone); |
|
1076 TheSqlQuery.SetLength(1000); |
|
1077 for(TInt i=0;i<30;++i) |
|
1078 { |
|
1079 err = file.Write(TheSqlQuery); |
|
1080 TEST2(err, KErrNone); |
|
1081 } |
|
1082 file.Close(); |
|
1083 //Step 5: Check the background compaction. Wait 10 seconds allowing the SQL server to try to compact the |
|
1084 // database. The SQL server should detect that the SQL database is corrupted and should stop trying to |
|
1085 // compact the database. |
|
1086 err = TheDb.Open(KDbName); |
|
1087 TEST2(err, KErrNone); |
|
1088 User::After(10000000); |
|
1089 // |
|
1090 TheDb.Close(); |
|
1091 (void)RSqlDatabase::Delete(KDbName); |
|
1092 } |
|
1093 |
1022 void DoTestsL() |
1094 void DoTestsL() |
1023 { |
1095 { |
1024 CreateTestDatabase8(); |
1096 CreateTestDatabase8(); |
1025 CalculateMaxCompaction8(); |
1097 CalculateMaxCompaction8(); |
1026 CreateTestDatabase16(); |
1098 CreateTestDatabase16(); |