persistentstorage/sql/TEST/t_sqltrans.cpp
changeset 55 44f437012c90
parent 0 08ec8eefde2f
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
    47 			TName name = th.Name();
    47 			TName name = th.Name();
    48 			RDebug::Print(_L("*** Thread %S, Line %d\r\n"), &name, aLine);
    48 			RDebug::Print(_L("*** Thread %S, Line %d\r\n"), &name, aLine);
    49 			}
    49 			}
    50 		else
    50 		else
    51 			{
    51 			{
    52 			RDebug::Print(_L("*** Line %d\r\n"), aLine);
    52 			TheTest.Printf(_L("*** Line %d. Expresssion evaluated to false\r\n"), aLine);
    53 			}
    53 			}
    54 		TheTest(EFalse, aLine);
    54 		TheTest(EFalse, aLine);
    55 		}
    55 		}
    56 	}
    56 	}
    57 void Check2(TInt aValue, TInt aExpected, TInt aLine, TBool aPrintThreadName = EFalse)
    57 void Check2(TInt aValue, TInt aExpected, TInt aLine, TBool aPrintThreadName = EFalse)
    65 			TName name = th.Name();
    65 			TName name = th.Name();
    66 			RDebug::Print(_L("*** Thread %S, Line %d Expected error: %d, got: %d\r\n"), &name, aLine, aExpected, aValue);
    66 			RDebug::Print(_L("*** Thread %S, Line %d Expected error: %d, got: %d\r\n"), &name, aLine, aExpected, aValue);
    67 			}
    67 			}
    68 		else
    68 		else
    69 			{
    69 			{
    70 			RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
    70 			TheTest.Printf(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
    71 			}
    71 			}
    72 		TheTest(EFalse, aLine);
    72 		TheTest(EFalse, aLine);
    73 		}
    73 		}
    74 	}
    74 	}
    75 #define TEST(arg) ::Check1((arg), __LINE__)
    75 #define TEST(arg) ::Check1((arg), __LINE__)
   166 @SYMREQ					REQ5792
   166 @SYMREQ					REQ5792
   167                         REQ5793
   167                         REQ5793
   168 */	
   168 */	
   169 void TransactionTest1()
   169 void TransactionTest1()
   170 	{
   170 	{
   171 	RDebug::Print(_L("+++:MainThread: Create critical sections\r\n"));
   171 	TheTest.Printf(_L("+++:MainThread: Create critical sections\r\n"));
   172 	TEST2(ThreadCritSect.CreateLocal(), KErrNone);
   172 	TEST2(ThreadCritSect.CreateLocal(), KErrNone);
   173 	ThreadCritSect.Wait();
   173 	ThreadCritSect.Wait();
   174 	TEST2(MainCritSect.CreateLocal(), KErrNone);
   174 	TEST2(MainCritSect.CreateLocal(), KErrNone);
   175 	MainCritSect.Wait();
   175 	MainCritSect.Wait();
   176 	
   176 	
   177 	RDebug::Print(_L("+++:MainThread: Create test database\r\n"));
   177 	TheTest.Printf(_L("+++:MainThread: Create test database\r\n"));
   178 	(void)RSqlDatabase::Delete(KTestDbName);
   178 	(void)RSqlDatabase::Delete(KTestDbName);
   179 	RSqlDatabase db;
   179 	RSqlDatabase db;
   180 	TInt err = db.Create(KTestDbName);
   180 	TInt err = db.Create(KTestDbName);
   181 	TEST2(err, KErrNone);
   181 	TEST2(err, KErrNone);
   182 
   182 
   183 	RDebug::Print(_L("+++:MainThread: Create a table in the test database\r\n"));
   183 	TheTest.Printf(_L("+++:MainThread: Create a table in the test database\r\n"));
   184 	_LIT8(KCreateSql, "CREATE TABLE A(Id INTEGER)");
   184 	_LIT8(KCreateSql, "CREATE TABLE A(Id INTEGER)");
   185 	err = db.Exec(KCreateSql);
   185 	err = db.Exec(KCreateSql);
   186 	TEST(err >= 0);	
   186 	TEST(err >= 0);	
   187 	
   187 	
   188 	db.Close();
   188 	db.Close();
   189 
   189 
   190 	RDebug::Print(_L("+++:MainThread: Create the worker thread\r\n"));
   190 	TheTest.Printf(_L("+++:MainThread: Create the worker thread\r\n"));
   191 	_LIT(KThreadName, "WorkThrd");
   191 	_LIT(KThreadName, "WorkThrd");
   192 	RThread thread;
   192 	RThread thread;
   193 	TheSqlIdx = 0;
   193 	TheSqlIdx = 0;
   194 	TEST2(thread.Create(KThreadName, &ThreadFunc1, 0x2000, 0x1000, 0x10000, NULL, EOwnerProcess), KErrNone);
   194 	TEST2(thread.Create(KThreadName, &ThreadFunc1, 0x2000, 0x1000, 0x10000, NULL, EOwnerProcess), KErrNone);
   195 	TRequestStatus status;
   195 	TRequestStatus status;
   196 	thread.Logon(status);
   196 	thread.Logon(status);
   197 	TEST2(status.Int(), KRequestPending);
   197 	TEST2(status.Int(), KRequestPending);
   198 	thread.Resume();
   198 	thread.Resume();
   199 
   199 
   200 	RDebug::Print(_L("+++:MainThread: Wait SQL statement(s) to be executed...\r\n"));
   200 	TheTest.Printf(_L("+++:MainThread: Wait SQL statement(s) to be executed...\r\n"));
   201 	MainCritSect.Wait();
   201 	MainCritSect.Wait();
   202 
   202 
   203 	RDebug::Print(_L("+++:MainThread: Notify the worker thread to panic...\r\n"));
   203 	TheTest.Printf(_L("+++:MainThread: Notify the worker thread to panic...\r\n"));
   204 	ThreadCritSect.Signal();
   204 	ThreadCritSect.Signal();
   205 	
   205 	
   206 	User::WaitForRequest(status);
   206 	User::WaitForRequest(status);
   207 	User::SetJustInTime(ETrue);	// enable debugger panic handling
   207 	User::SetJustInTime(ETrue);	// enable debugger panic handling
   208 
   208 
   209 	TEST2(thread.ExitType(), EExitPanic);
   209 	TEST2(thread.ExitType(), EExitPanic);
   210 	TEST2(thread.ExitReason(), KPanicCode);
   210 	TEST2(thread.ExitReason(), KPanicCode);
   211 	
   211 	
   212 	thread.Close();
   212 	thread.Close();
   213 
   213 
   214 	RDebug::Print(_L("+++:MainThread: Check the database content...\r\n"));
   214 	TheTest.Printf(_L("+++:MainThread: Check the database content...\r\n"));
   215 	err = db.Open(KTestDbName);
   215 	err = db.Open(KTestDbName);
   216 	TEST2(err, KErrNone);
   216 	TEST2(err, KErrNone);
   217 	_LIT8(KSelectSql, "SELECT COUNT(*) AS CNT FROM A");
   217 	_LIT8(KSelectSql, "SELECT COUNT(*) AS CNT FROM A");
   218 	RSqlStatement stmt;
   218 	RSqlStatement stmt;
   219 	err = stmt.Prepare(db, KSelectSql);
   219 	err = stmt.Prepare(db, KSelectSql);