persistentstorage/sql/TEST/t_sqlload.cpp
branchRCL_3
changeset 20 04ec7606545c
parent 16 6b6fd149daa2
child 21 fcc16690f446
--- a/persistentstorage/sql/TEST/t_sqlload.cpp	Tue Apr 27 18:25:57 2010 +0300
+++ b/persistentstorage/sql/TEST/t_sqlload.cpp	Tue May 11 17:49:39 2010 +0300
@@ -69,6 +69,14 @@
 	RSqlDatabase::Delete(KTestDbName1);
 	}
 
+void GetHomeTimeAsString(TDes& aStr)
+	{
+	TTime time;
+	time.HomeTime();
+	TDateTime dt = time.DateTime();
+	aStr.Format(_L("%02d:%02d:%02d.%06d"), dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond());
+	}
+
 ///////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////
 //Test macros and functions
@@ -115,6 +123,31 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////
 
+//StatementMaxNumberTest() timeouts in WDP builds.
+//This function is used to check whether the time limit is reaqched or not.
+TBool IsTimeLimitReached()
+	{
+	struct TStartTime
+		{
+		TStartTime()
+			{
+			iTime.HomeTime();
+			}
+		TTime iTime;
+		};
+	
+	static TStartTime startTime; 
+	const TInt KTestTimeLimit = 500;//seconds
+	
+	TTime currTime;
+	currTime.HomeTime();
+	
+	TTimeIntervalSeconds s;
+	TInt err = currTime.SecondsFrom(startTime.iTime, s);
+	TEST2(err, KErrNone);
+	return s.Int() > KTestTimeLimit;
+	}
+
 void CreateTestDir()
     {
     RFs fs;
@@ -540,43 +573,67 @@
 						creates as many as possible SQL statements. The expected result is
 						that either the statement creation process will fail with KErrNoMemory or
 						the max number of statements to be created is reached (100000).
-						Then the test deletes 1/2 of the created statements object and
+						Then the test deletes 1/2 of the created statements objects and
 						after that attempts to execute Next() on the rest of them.
+						Note that the test has a time limit of 500 seconds. Otherwise on some platforms
+						with WDP feature switched on the test may timeout.
 @SYMTestExpectedResults Test must not fail
 @SYMDEF                 DEF145236
 */  
 void StatementMaxNumberTest()
 	{
+	TBuf<30> time;
+	GetHomeTimeAsString(time);
+	TheTest.Printf(_L("=== %S: Create database\r\n"), &time);
+	
 	(void)RSqlDatabase::Delete(KTestDbName1);
 	RSqlDatabase db;
 	TInt err = db.Create(KTestDbName1);
 	TEST2(err, KErrNone);
 	err = db.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A(I) VALUES(1); INSERT INTO A(I) VALUES(2);"));
 	TEST(err >= 0);
+
+	GetHomeTimeAsString(time);
+	TheTest.Printf(_L("=== %S: Create statements array\r\n"), &time);
 	
 	//Reserve memory for the statement objects
 	const TInt KMaxStmtCount = 100000;
 	RSqlStatement* stmt = new RSqlStatement[KMaxStmtCount];
 	TEST(stmt != NULL);
 	TInt stmtCnt = 0;
-	
+
 	//Create as many statement objects as possible
 	err = KErrNone;
 	for(TInt i=0;(i<KMaxStmtCount) && (err == KErrNone);++i,++stmtCnt)
 		{
 		err = stmt[i].Prepare(db, _L("SELECT * FROM A WHERE I>=0 AND I<10"));
+		if((i % 100) == 0)
+			{
+			GetHomeTimeAsString(time);
+			TheTest.Printf(_L("=== %S: Create % 5d statements\r\n"), &time, i + 1);
+			if(IsTimeLimitReached())
+				{
+				TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time);
+				break;
+				}
+			}
 		}
 	TheTest.Printf(_L("%d created statement objects. Last error: %d.\r\n"), stmtCnt, err);
 	TEST(err == KErrNone || err == KErrNoMemory);
 
 	//Close 1/2 of the statements to free some memory
-	for(TInt i=stmtCnt-1;i>=0;i-=2)
+	for(TInt i=stmtCnt-1,j=0;i>=0;i-=2,++j)
 		{
 		stmt[i].Close();
+		if((j % 100) == 0)
+			{
+			GetHomeTimeAsString(time);
+			TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, j + 1);
+			}
 		}
 	
 	//Now, there should be enough memory to be able to execute Next() on the rest of the statements
-	for(TInt i=stmtCnt-2;i>=0;i-=2)
+	for(TInt i=stmtCnt-2,j=0;i>=0;i-=2,++j)
 		{
 		err = stmt[i].Next();
 		TEST2(err, KSqlAtRow);
@@ -584,12 +641,27 @@
 		TEST2(err, KSqlAtRow);
 		err = stmt[i].Next();
 		TEST2(err, KSqlAtEnd);
+		if((j % 100) == 0)
+			{
+			GetHomeTimeAsString(time);
+			TheTest.Printf(_L("=== %S: % 5d statements processed\r\n"), &time, j + 1);
+			}
+		if(IsTimeLimitReached())
+			{
+			TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time);
+			break;
+			}
 		}
-	
+
 	//Cleanup
-	for(TInt i=stmtCnt-1;i>=0;--i)
+	for(TInt i=stmtCnt-1,j=0;i>=0;--i,++j)
 		{
 		stmt[i].Close();
+		if((j % 100) == 0)
+			{
+			GetHomeTimeAsString(time);
+			TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, j + 1);
+			}
 		}
 	delete [] stmt;
 	db.Close();