diff -r b8bdbc8f59c7 -r 7d4490026038 persistentstorage/sql/TEST/t_sqlcompact2.cpp --- a/persistentstorage/sql/TEST/t_sqlcompact2.cpp Thu Aug 12 11:53:23 2010 +0100 +++ b/persistentstorage/sql/TEST/t_sqlcompact2.cpp Mon Sep 27 11:59:56 2010 +0100 @@ -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 aNewDb); void InsertTestRecords(TInt aOpCount = KOperationCount); void UpdateTestRecords(TInt aOpCount = KOperationCount); void DeleteTestRecords(TInt aOpCount = KOperationCount); @@ -244,7 +248,6 @@ void DeleteTestEnd(); void SingleOpCompactTestBegin(); void SingleOpCompactTestEnd(); - void DoOomTest1(); void DoOomTest2(); void DoOomTest3(); @@ -391,6 +394,51 @@ } } +//Creates a test database (with KDbName name). +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); + } + +//Insert 1000 records. The record size is such that there is 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); + + 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 +1031,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();