172 static void PrintSqliteErrMsg() |
171 static void PrintSqliteErrMsg() |
173 { |
172 { |
174 if(TheDb) |
173 if(TheDb) |
175 { |
174 { |
176 const char* msg = sqlite3_errmsg(TheDb); |
175 const char* msg = sqlite3_errmsg(TheDb); |
177 TestPrintf("*** SQLite error message:"); |
176 TBuf<200> buf; |
178 TestPrintf(msg); |
177 buf.Copy(TPtrC8((const TUint8*)msg)); |
|
178 TheTest.Printf(_L("*** SQLite error message: \"%S\"\r\n"), &buf); |
179 } |
179 } |
180 } |
180 } |
181 |
181 |
182 //Test macros and functions |
182 //Test macros and functions |
183 static void Check(TInt aValue, TInt aLine) |
183 static void Check(TInt aValue, TInt aLine) |
184 { |
184 { |
185 if(!aValue) |
185 if(!aValue) |
186 { |
186 { |
187 DeleteTestFiles(); |
187 DeleteTestFiles(); |
188 PrintSqliteErrMsg(); |
188 PrintSqliteErrMsg(); |
189 TestTestLine(EFalse, aLine); |
189 TheTest(EFalse, aLine); |
190 } |
190 } |
191 } |
191 } |
192 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
192 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
193 { |
193 { |
194 if(aValue != aExpected) |
194 if(aValue != aExpected) |
195 { |
195 { |
196 DeleteTestFiles(); |
196 DeleteTestFiles(); |
197 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
197 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
198 PrintSqliteErrMsg(); |
198 PrintSqliteErrMsg(); |
199 TestTestLine(EFalse, aLine); |
199 TheTest(EFalse, aLine); |
200 } |
200 } |
201 } |
201 } |
202 #define TEST(arg) ::Check((arg), __LINE__) |
202 #define TEST(arg) ::Check((arg), __LINE__) |
203 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
203 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
204 |
204 |
238 ThePerfTestResult[aType] = (TUint32)diffTicks; |
236 ThePerfTestResult[aType] = (TUint32)diffTicks; |
239 } |
237 } |
240 |
238 |
241 static void PrintPerfTestResults() |
239 static void PrintPerfTestResults() |
242 { |
240 { |
243 TBuf8<256> printString; |
|
244 |
|
245 TInt r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiInsert]); |
241 TInt r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiInsert]); |
246 printString.Format(_L8("###Mutli Insert: %8dus\r\n"), r); |
242 TheTest.Printf(_L("###Mutli Insert: %8dus\r\n"), r); |
247 TestPrintf((const char*)printString.PtrZ()); |
|
248 |
243 |
249 r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiUpdate]); |
244 r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiUpdate]); |
250 printString.Format(_L8("###Mutli Update: %8dus\r\n"), r); |
245 TheTest.Printf(_L("###Mutli Update: %8dus\r\n"), r); |
251 TestPrintf((const char*)printString.PtrZ()); |
|
252 |
246 |
253 r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiSelect]); |
247 r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiSelect]); |
254 printString.Format(_L8("###Mutli Select: %8dus\r\n"), r); |
248 TheTest.Printf(_L("###Mutli Select: %8dus\r\n"), r); |
255 TestPrintf((const char*)printString.PtrZ()); |
|
256 |
249 |
257 r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiDelete]); |
250 r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiDelete]); |
258 printString.Format(_L8("###Mutli Delete: %8dus\r\n"), r); |
251 TheTest.Printf(_L("###Mutli Delete: %8dus\r\n"), r); |
259 TestPrintf((const char*)printString.PtrZ()); |
|
260 |
252 |
261 |
253 |
262 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleInsert]); |
254 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleInsert]); |
263 printString.Format(_L8("##Single Insert: %8dus\r\n"), r); |
255 TheTest.Printf(_L("##Single Insert: %8dus\r\n"), r); |
264 TestPrintf((const char*)printString.PtrZ()); |
|
265 |
256 |
266 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleUpdate]); |
257 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleUpdate]); |
267 printString.Format(_L8("##Single Update: %8dus\r\n"), r); |
258 TheTest.Printf(_L("##Single Update: %8dus\r\n"), r); |
268 TestPrintf((const char*)printString.PtrZ()); |
|
269 |
259 |
270 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleSelect]); |
260 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleSelect]); |
271 printString.Format(_L8("##Single Select: %8dus\r\n"), r); |
261 TheTest.Printf(_L("##Single Select: %8dus\r\n"), r); |
272 TestPrintf((const char*)printString.PtrZ()); |
|
273 |
262 |
274 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleDelete]); |
263 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleDelete]); |
275 printString.Format(_L8("##Single Delete: %8dus\r\n"), r); |
264 TheTest.Printf(_L("##Single Delete: %8dus\r\n"), r); |
276 TestPrintf((const char*)printString.PtrZ()); |
|
277 } |
265 } |
278 |
266 |
279 /////////////////////////////////////////////////////////////////////////////////////// |
267 /////////////////////////////////////////////////////////////////////////////////////// |
280 |
268 |
281 static void CreateTestDir() |
269 static void CreateTestDir() |
287 static void CreateTestDatabase() |
275 static void CreateTestDatabase() |
288 { |
276 { |
289 (void)TheFs.Delete(KTestDbName); |
277 (void)TheFs.Delete(KTestDbName); |
290 |
278 |
291 const char* ver = sqlite3_libversion(); |
279 const char* ver = sqlite3_libversion(); |
292 TestPrintf("*** SQLite library version:"); |
280 TBuf<20> buf; |
293 TestPrintf(ver); |
281 buf.Copy(TPtrC8((const TUint8*)ver)); |
|
282 TheTest.Printf(_L("*** SQLite library version: \"%S\"\r\n"), &buf); |
294 |
283 |
295 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
284 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
296 TEST2(err, SQLITE_OK); |
285 TEST2(err, SQLITE_OK); |
297 |
286 |
298 err = sqlite3_exec(TheDb, "CREATE TABLE Tbl(I INTEGER PRIMARY KEY, I64 BIGINT, D DOUBLE, T TEXT, B BINARY)", 0, 0, 0); |
287 err = sqlite3_exec(TheDb, "CREATE TABLE Tbl(I INTEGER PRIMARY KEY, I64 BIGINT, D DOUBLE, T TEXT, B BINARY)", 0, 0, 0); |
652 |
641 |
653 /////////////////////////////////////////////////////////////////////////////////////// |
642 /////////////////////////////////////////////////////////////////////////////////////// |
654 |
643 |
655 static void DoTests() |
644 static void DoTests() |
656 { |
645 { |
657 TestStart("Get fast counter frequency"); |
646 TheTest.Start(_L("Get fast counter frequency")); |
658 GetFastCounterFrequency(); |
647 GetFastCounterFrequency(); |
659 |
648 |
660 TestNext("SQLite: Create the test database"); |
649 TheTest.Next( _L("SQLite: Create the test database")); |
661 CreateTestDatabase(); |
650 CreateTestDatabase(); |
662 |
651 |
663 TBuf8<100> msgbuf; |
652 TBuf<100> msgbuf; |
664 |
653 |
665 msgbuf.Format(_L8("@SYMTestCaseID:PDS-SQLITE3-UT-4030: Insert %d records in a single transaction"), KInsertRecCnt); |
654 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4030: Insert %d records in a single transaction"), KInsertRecCnt); |
666 TestNext((const char*)msgbuf.PtrZ()); |
655 TheTest.Next(msgbuf); |
667 SqliteMultiInsertTest(); |
656 SqliteMultiInsertTest(); |
668 |
657 |
669 msgbuf.Format(_L8("@SYMTestCaseID:PDS-SQLITE3-UT-4031: Update %d records in a single transaction"), KUpdateRecCnt); |
658 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4031: Update %d records in a single transaction"), KUpdateRecCnt); |
670 TestNext((const char*)msgbuf.PtrZ()); |
659 TheTest.Next(msgbuf); |
671 SqliteMultiUpdateTest(); |
660 SqliteMultiUpdateTest(); |
672 |
661 |
673 msgbuf.Format(_L8("@SYMTestCaseID:PDS-SQLITE3-UT-4032: Select %d records"), KSelectRecCnt); |
662 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4032: Select %d records"), KSelectRecCnt); |
674 TestNext((const char*)msgbuf.PtrZ()); |
663 TheTest.Next(msgbuf); |
675 SqliteMultiSelectTest(); |
664 SqliteMultiSelectTest(); |
676 |
665 |
677 msgbuf.Format(_L8("@SYMTestCaseID:PDS-SQLITE3-UT-4033: Delete %d records in a single transaction"), KDeleteRecCnt); |
666 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4033: Delete %d records in a single transaction"), KDeleteRecCnt); |
678 TestNext((const char*)msgbuf.PtrZ()); |
667 TheTest.Next(msgbuf); |
679 SqliteMultiDeleteTest(); |
668 SqliteMultiDeleteTest(); |
680 |
669 |
681 msgbuf.Format(_L8("@SYMTestCaseID:PDS-SQLITE3-UT-4034: Insert a single record")); |
670 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4034: Insert a single record")); |
682 TestNext((const char*)msgbuf.PtrZ()); |
671 TheTest.Next(msgbuf); |
683 SqliteSingleInsertTest(); |
672 SqliteSingleInsertTest(); |
684 |
673 |
685 msgbuf.Format(_L8("@SYMTestCaseID:PDS-SQLITE3-UT-4035: Update a single record")); |
674 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4035: Update a single record")); |
686 TestNext((const char*)msgbuf.PtrZ()); |
675 TheTest.Next(msgbuf); |
687 SqliteSingleUpdateTest(); |
676 SqliteSingleUpdateTest(); |
688 |
677 |
689 msgbuf.Format(_L8("@SYMTestCaseID:PDS-SQLITE3-UT-4036: Select a single record")); |
678 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4036: Select a single record")); |
690 TestNext((const char*)msgbuf.PtrZ()); |
679 TheTest.Next(msgbuf); |
691 SqliteSingleSelectTest(); |
680 SqliteSingleSelectTest(); |
692 |
681 |
693 msgbuf.Format(_L8("@SYMTestCaseID:PDS-SQLITE3-UT-4037: Delete a single record")); |
682 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4037: Delete a single record")); |
694 TestNext((const char*)msgbuf.PtrZ()); |
683 TheTest.Next(msgbuf); |
695 SqliteSingleDeleteTest(); |
684 SqliteSingleDeleteTest(); |
696 |
685 |
697 (void)TheFs.Delete(KTestDbName); |
686 (void)TheFs.Delete(KTestDbName); |
698 |
687 |
699 PrintPerfTestResults(); |
688 PrintPerfTestResults(); |
700 } |
689 } |
701 |
690 |
702 TInt E32Main() |
691 TInt E32Main() |
703 { |
692 { |
704 TestOpen(KTestName); |
693 TheTest.Title(); |
705 TestTitle(); |
|
706 |
694 |
707 CTrapCleanup* tc = CTrapCleanup::New(); |
695 CTrapCleanup* tc = CTrapCleanup::New(); |
708 |
696 |
709 __UHEAP_MARK; |
697 __UHEAP_MARK; |
710 |
698 |
711 TInt err = TheFs.Connect(); |
699 TInt err = TheFs.Connect(); |
712 TestTest(err == KErrNone); |
700 TheTest(err == KErrNone); |
713 |
701 |
714 CreateTestDir(); |
702 CreateTestDir(); |
715 DeleteTestFiles(); |
703 DeleteTestFiles(); |
716 DoTests(); |
704 DoTests(); |
717 DeleteTestFiles(); |
705 DeleteTestFiles(); |
718 |
706 |
719 __UHEAP_MARKEND; |
707 __UHEAP_MARKEND; |
720 |
708 |
721 TheFs.Close(); |
709 TheFs.Close(); |
722 TestEnd(); |
710 TheTest.End(); |
723 TestClose(); |
711 TheTest.Close(); |
724 |
712 |
725 delete tc; |
713 delete tc; |
726 |
714 |
727 User::Heap().Check(); |
715 User::Heap().Check(); |
728 return KErrNone; |
716 return KErrNone; |