63 TName name = th.Name(); |
63 TName name = th.Name(); |
64 RDebug::Print(_L("*** Thread %S, Line %d Expected error: %d, got: %d\r\n"), &name, aLine, aExpected, aValue); |
64 RDebug::Print(_L("*** Thread %S, Line %d Expected error: %d, got: %d\r\n"), &name, aLine, aExpected, aValue); |
65 } |
65 } |
66 else |
66 else |
67 { |
67 { |
68 RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); |
68 TheTest.Printf(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); |
69 } |
69 } |
70 TheTest(EFalse, aLine); |
70 TheTest(EFalse, aLine); |
71 } |
71 } |
72 } |
72 } |
73 #define TEST(arg) ::Check1((arg), __LINE__) |
73 #define TEST(arg) ::Check1((arg), __LINE__) |
109 RSqlDatabase db1; |
109 RSqlDatabase db1; |
110 TInt err = db1.Create(KTestDbName1); |
110 TInt err = db1.Create(KTestDbName1); |
111 TEST2(err, KErrNone); |
111 TEST2(err, KErrNone); |
112 |
112 |
113 //Create test database |
113 //Create test database |
114 RDebug::Print(_L("###Create test database\r\n")); |
114 TheTest.Printf(_L("###Create test database\r\n")); |
115 _LIT8(KCreateSql, "CREATE TABLE A(Id INTEGER PRIMARY KEY AUTOINCREMENT, Data INTEGER)"); |
115 _LIT8(KCreateSql, "CREATE TABLE A(Id INTEGER PRIMARY KEY AUTOINCREMENT, Data INTEGER)"); |
116 err = db1.Exec(KCreateSql); |
116 err = db1.Exec(KCreateSql); |
117 TEST(err >= 0); |
117 TEST(err >= 0); |
118 |
118 |
119 //Connection 2 |
119 //Connection 2 |
120 RSqlDatabase db2; |
120 RSqlDatabase db2; |
121 err = db2.Open(KTestDbName1); |
121 err = db2.Open(KTestDbName1); |
122 TEST2(err, KErrNone); |
122 TEST2(err, KErrNone); |
123 |
123 |
124 //Insert some records using both connections |
124 //Insert some records using both connections |
125 RDebug::Print(_L("###Insert some records\r\n")); |
125 TheTest.Printf(_L("###Insert some records\r\n")); |
126 const TInt KRecNum = 100; |
126 const TInt KRecNum = 100; |
127 _LIT8(KInsertSql, "INSERT INTO A(Data) VALUES("); |
127 _LIT8(KInsertSql, "INSERT INTO A(Data) VALUES("); |
128 for(TInt i=0;i<KRecNum;++i) |
128 for(TInt i=0;i<KRecNum;++i) |
129 { |
129 { |
130 TBuf8<100> sql(KInsertSql); |
130 TBuf8<100> sql(KInsertSql); |
249 REQ5793 |
249 REQ5793 |
250 */ |
250 */ |
251 void TestMultiConnDiffThread() |
251 void TestMultiConnDiffThread() |
252 { |
252 { |
253 //Create a test database |
253 //Create a test database |
254 RDebug::Print(_L("+++:MainThread: Create test database\r\n")); |
254 TheTest.Printf(_L("+++:MainThread: Create test database\r\n")); |
255 RSqlDatabase db; |
255 RSqlDatabase db; |
256 TInt err = db.Create(KTestDbName1); |
256 TInt err = db.Create(KTestDbName1); |
257 TEST2(err, KErrNone); |
257 TEST2(err, KErrNone); |
258 |
258 |
259 //Create a test table |
259 //Create a test table |
260 RDebug::Print(_L("+++:MainThread: Create a table in the test database\r\n")); |
260 TheTest.Printf(_L("+++:MainThread: Create a table in the test database\r\n")); |
261 _LIT8(KCreateSql, "CREATE TABLE A(Id INTEGER PRIMARY KEY)"); |
261 _LIT8(KCreateSql, "CREATE TABLE A(Id INTEGER PRIMARY KEY)"); |
262 err = db.Exec(KCreateSql); |
262 err = db.Exec(KCreateSql); |
263 TEST(err >= 0); |
263 TEST(err >= 0); |
264 |
264 |
265 const TInt KThreadCnt = 4; |
265 const TInt KThreadCnt = 4; |
344 TEST(val > 0 && val <= (KThreadCnt * KRange)); |
344 TEST(val > 0 && val <= (KThreadCnt * KRange)); |
345 } |
345 } |
346 stmt.Close(); |
346 stmt.Close(); |
347 |
347 |
348 //Prepare for the next test run - delete all records. |
348 //Prepare for the next test run - delete all records. |
349 RDebug::Print(_L("+++:MainThread: Delete all records\r\n")); |
349 TheTest.Printf(_L("+++:MainThread: Delete all records\r\n")); |
350 _LIT8(KDeleteSql, "DELETE FROM A"); |
350 _LIT8(KDeleteSql, "DELETE FROM A"); |
351 err = db.Exec(KDeleteSql); |
351 err = db.Exec(KDeleteSql); |
352 TEST(err >= 0); |
352 TEST(err >= 0); |
353 }//end of "for(TInt isolLevel=0;isolLevel<KIsolationLevelCnt;++isolLevel)" |
353 }//end of "for(TInt isolLevel=0;isolLevel<KIsolationLevelCnt;++isolLevel)" |
354 }//end of "for(TInt transType=0;transType<KTransTypeCnt;++transType)" |
354 }//end of "for(TInt transType=0;transType<KTransTypeCnt;++transType)" |
355 |
355 |
356 db.Close(); |
356 db.Close(); |
357 RDebug::Print(_L("+++:MainThread: Delete the test database\r\n")); |
357 TheTest.Printf(_L("+++:MainThread: Delete the test database\r\n")); |
358 (void)RSqlDatabase::Delete(KTestDbName1); |
358 (void)RSqlDatabase::Delete(KTestDbName1); |
359 } |
359 } |
360 |
360 |
361 /////////////////////////////////////////////////////////////////////////////////////// |
361 /////////////////////////////////////////////////////////////////////////////////////// |
362 |
362 |
426 @SYMREQ REQ5792 |
426 @SYMREQ REQ5792 |
427 REQ5793 |
427 REQ5793 |
428 */ |
428 */ |
429 void TestIsolationLevel() |
429 void TestIsolationLevel() |
430 { |
430 { |
431 RDebug::Print(_L("+++:MainThread: Create critical sections\r\n")); |
431 TheTest.Printf(_L("+++:MainThread: Create critical sections\r\n")); |
432 TEST2(UpdateThreadCrS.CreateLocal(), KErrNone); |
432 TEST2(UpdateThreadCrS.CreateLocal(), KErrNone); |
433 UpdateThreadCrS.Wait(); |
433 UpdateThreadCrS.Wait(); |
434 TEST2(MainThreadCrS.CreateLocal(), KErrNone); |
434 TEST2(MainThreadCrS.CreateLocal(), KErrNone); |
435 MainThreadCrS.Wait(); |
435 MainThreadCrS.Wait(); |
436 |
436 |
437 RDebug::Print(_L("+++:MainThread: Create test database\r\n")); |
437 TheTest.Printf(_L("+++:MainThread: Create test database\r\n")); |
438 RSqlDatabase db; |
438 RSqlDatabase db; |
439 TInt err = db.Create(KTestDbName1); |
439 TInt err = db.Create(KTestDbName1); |
440 TEST2(err, KErrNone); |
440 TEST2(err, KErrNone); |
441 |
441 |
442 RDebug::Print(_L("+++:MainThread: Set the isolation level to \"Read uncommitted\"\r\n")); |
442 TheTest.Printf(_L("+++:MainThread: Set the isolation level to \"Read uncommitted\"\r\n")); |
443 err = db.SetIsolationLevel(RSqlDatabase::EReadUncommitted); |
443 err = db.SetIsolationLevel(RSqlDatabase::EReadUncommitted); |
444 TEST2(err, KErrNone); |
444 TEST2(err, KErrNone); |
445 |
445 |
446 RDebug::Print(_L("+++:MainThread: Create a table in the test database\r\n")); |
446 TheTest.Printf(_L("+++:MainThread: Create a table in the test database\r\n")); |
447 _LIT8(KCreateSql, "CREATE TABLE A(Id INTEGER)"); |
447 _LIT8(KCreateSql, "CREATE TABLE A(Id INTEGER)"); |
448 err = db.Exec(KCreateSql); |
448 err = db.Exec(KCreateSql); |
449 TEST(err >= 0); |
449 TEST(err >= 0); |
450 |
450 |
451 RDebug::Print(_L("+++:MainThread: Insert one record in the table\r\n")); |
451 TheTest.Printf(_L("+++:MainThread: Insert one record in the table\r\n")); |
452 _LIT8(KInsertSql, "INSERT INTO A(Id) VALUES("); |
452 _LIT8(KInsertSql, "INSERT INTO A(Id) VALUES("); |
453 TBuf8<64> sql(KInsertSql); |
453 TBuf8<64> sql(KInsertSql); |
454 sql.AppendNum((TInt64)KInitialValue); |
454 sql.AppendNum((TInt64)KInitialValue); |
455 sql.Append(_L(")")); |
455 sql.Append(_L(")")); |
456 err = db.Exec(sql); |
456 err = db.Exec(sql); |
457 TEST2(err, 1); |
457 TEST2(err, 1); |
458 |
458 |
459 RDebug::Print(_L("+++:MainThread: Create the \"update\" thread\r\n")); |
459 TheTest.Printf(_L("+++:MainThread: Create the \"update\" thread\r\n")); |
460 _LIT(KThreadName, "UpdTh"); |
460 _LIT(KThreadName, "UpdTh"); |
461 RThread thread; |
461 RThread thread; |
462 TEST2(thread.Create(KThreadName, &UpdateThreadFunc, 0x2000, 0x1000, 0x10000, NULL, EOwnerThread), KErrNone); |
462 TEST2(thread.Create(KThreadName, &UpdateThreadFunc, 0x2000, 0x1000, 0x10000, NULL, EOwnerThread), KErrNone); |
463 TRequestStatus status; |
463 TRequestStatus status; |
464 thread.Logon(status); |
464 thread.Logon(status); |
465 TEST2(status.Int(), KRequestPending); |
465 TEST2(status.Int(), KRequestPending); |
466 thread.Resume(); |
466 thread.Resume(); |
467 |
467 |
468 RDebug::Print(_L("+++:MainThread: Wait for record update completion...\r\n")); |
468 TheTest.Printf(_L("+++:MainThread: Wait for record update completion...\r\n")); |
469 MainThreadCrS.Wait(); |
469 MainThreadCrS.Wait(); |
470 |
470 |
471 RDebug::Print(_L("+++:MainThread: Read the record and check the data...\r\n")); |
471 TheTest.Printf(_L("+++:MainThread: Read the record and check the data...\r\n")); |
472 _LIT8(KSelectSql, "SELECT * FROM A"); |
472 _LIT8(KSelectSql, "SELECT * FROM A"); |
473 RSqlStatement stmt; |
473 RSqlStatement stmt; |
474 err = stmt.Prepare(db, KSelectSql); |
474 err = stmt.Prepare(db, KSelectSql); |
475 TEST2(err, KErrNone); |
475 TEST2(err, KErrNone); |
476 err = stmt.Next(); |
476 err = stmt.Next(); |
477 TEST2(err, KSqlAtRow); |
477 TEST2(err, KSqlAtRow); |
478 TInt val = stmt.ColumnInt(0); |
478 TInt val = stmt.ColumnInt(0); |
479 TEST(val == KUpdatedValue); |
479 TEST(val == KUpdatedValue); |
480 stmt.Close(); |
480 stmt.Close(); |
481 |
481 |
482 RDebug::Print(_L("+++:MainThread: Notify the update thread that it can rollback\r\n")); |
482 TheTest.Printf(_L("+++:MainThread: Notify the update thread that it can rollback\r\n")); |
483 UpdateThreadCrS.Signal(); |
483 UpdateThreadCrS.Signal(); |
484 |
484 |
485 RDebug::Print(_L("+++:MainThread: Wait for rollback completion...\r\n")); |
485 TheTest.Printf(_L("+++:MainThread: Wait for rollback completion...\r\n")); |
486 MainThreadCrS.Wait(); |
486 MainThreadCrS.Wait(); |
487 |
487 |
488 RDebug::Print(_L("+++:MainThread: Read the record and check the data...\r\n")); |
488 TheTest.Printf(_L("+++:MainThread: Read the record and check the data...\r\n")); |
489 err = stmt.Prepare(db, KSelectSql); |
489 err = stmt.Prepare(db, KSelectSql); |
490 TEST2(err, KErrNone); |
490 TEST2(err, KErrNone); |
491 err = stmt.Next(); |
491 err = stmt.Next(); |
492 TEST2(err, KSqlAtRow); |
492 TEST2(err, KSqlAtRow); |
493 val = stmt.ColumnInt(0); |
493 val = stmt.ColumnInt(0); |