diff -r 8dc8494f1e0e -r 839ea9debada persistentstorage/sql/TEST/t_sqlcompact2.cpp --- a/persistentstorage/sql/TEST/t_sqlcompact2.cpp Wed Sep 15 14:05:58 2010 +0300 +++ b/persistentstorage/sql/TEST/t_sqlcompact2.cpp Wed Oct 13 16:30:44 2010 +0300 @@ -25,6 +25,7 @@ #include "SqlCompact.h" #include "SqlCompactConn.h" #include "SqlCompactEntry.h" +#include "SqlUtil.h" const TInt KOperationCount = 20; const TInt KFreePageThresholdKb = 5; @@ -220,6 +221,7 @@ void OomTest(); void FileIoErrTest(); void PerformanceTest(); + void FreePageUpdateTest(); protected: virtual void DoCancel(); @@ -232,6 +234,8 @@ void Schedule(TCommand aNextCommand, TTimeIntervalMicroSeconds32 aInterval); void CreateTestDatabase(); + void CreateTestDatabase2(); + void PrepareDb(TBool aDeleteRecords); void InsertTestRecords(TInt aOpCount = KOperationCount); void UpdateTestRecords(TInt aOpCount = KOperationCount); void DeleteTestRecords(TInt aOpCount = KOperationCount); @@ -390,6 +394,52 @@ ::FinalizeStmtHandle(stmtHandle); } } + +//Creates a test database (with KDbName name). The page size is 1KB. +void CSqlCompactTestActive::CreateTestDatabase2() + { + //Create the database + const TInt KPageSize = 1024; + _LIT8(KConfigStr, "page_size="); + TBuf8<100> config; + config.Copy(KConfigStr); + config.AppendNum(KPageSize); + TInt err = KErrNone; + err = ::CreateDbHandle8(::FileNameZ8(TheDbName), TheDbHandle); + TEST2(err, KErrNone); + _LIT8(KCreateTableSql, "CREATE TABLE A(I INTEGER, T TEXT)\x0"); + err = ::DbExecStmt8(TheDbHandle, KCreateTableSql); + TEST2(err, KErrNone); + } + +// Inserts 1000 records. +// The record size is such that there are only two records per page. +void CSqlCompactTestActive::PrepareDb(TBool aDeleteRecords) + { + //Insert records + const TInt KRecordCount = 1000; + const TInt KTextLen = 400; + TBuf TheText; + TBuf TheSqlBuf; + TheText.SetLength(TheText.MaxLength()); + TheText.Fill(TChar('A')); + for(TInt i=0;iAddEntryL(TheDbName, TheCompactionSettings)); + TEST2(err, KErrNone); + + //Insert 1000 records and then delete all of them + PrepareDb(ETrue); + TInt freePageCount = ::FreePageCount(); + TEST(freePageCount > KSqlCompactFreePageThresholdKb); + TheTest.Printf(_L(" Free pages count = %d\r\n"), freePageCount); + + //Refill the database + PrepareDb(EFalse); + + CSqlCompactEntry* impl = compactor->iEntries[0]; + impl->iPageCount = freePageCount; + err = impl->Compact(); + TEST2(err, KErrNone); + TEST2(impl->iPageCount, 0); + + compactor->ReleaseEntry(TheDbName); + delete compactor; + ::CloseDbHandle(TheDbHandle); + TheDbHandle = NULL; + (void)TheFs.Delete(TheDbName); + } + ////////////////////////////////////////////////////////////////////////////////////////////////// void DoTests() @@ -939,6 +1034,9 @@ TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4052 Compaction - performance test")); TheTestActive->PerformanceTest(); + + TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4239 Free page update test")); + TheTestActive->FreePageUpdateTest(); CActiveScheduler::Start();