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