persistentstorage/sql/TEST/t_sqlload.cpp
branchRCL_3
changeset 14 04ec7606545c
parent 12 6b6fd149daa2
child 15 fcc16690f446
equal deleted inserted replaced
12:6b6fd149daa2 14:04ec7606545c
    67 	RSqlDatabase::Delete(KTestDbName3);
    67 	RSqlDatabase::Delete(KTestDbName3);
    68 	RSqlDatabase::Delete(KTestDbName2);
    68 	RSqlDatabase::Delete(KTestDbName2);
    69 	RSqlDatabase::Delete(KTestDbName1);
    69 	RSqlDatabase::Delete(KTestDbName1);
    70 	}
    70 	}
    71 
    71 
       
    72 void GetHomeTimeAsString(TDes& aStr)
       
    73 	{
       
    74 	TTime time;
       
    75 	time.HomeTime();
       
    76 	TDateTime dt = time.DateTime();
       
    77 	aStr.Format(_L("%02d:%02d:%02d.%06d"), dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond());
       
    78 	}
       
    79 
    72 ///////////////////////////////////////////////////////////////////////////////////////
    80 ///////////////////////////////////////////////////////////////////////////////////////
    73 ///////////////////////////////////////////////////////////////////////////////////////
    81 ///////////////////////////////////////////////////////////////////////////////////////
    74 //Test macros and functions
    82 //Test macros and functions
    75 void Check1(TInt aValue, TInt aLine, TBool aPrintThreadName = EFalse)
    83 void Check1(TInt aValue, TInt aLine, TBool aPrintThreadName = EFalse)
    76 	{
    84 	{
   112 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
   120 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
   113 #define TTEST(arg) ::Check1((arg), __LINE__, ETrue)
   121 #define TTEST(arg) ::Check1((arg), __LINE__, ETrue)
   114 #define TTEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__, ETrue)
   122 #define TTEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__, ETrue)
   115 
   123 
   116 ///////////////////////////////////////////////////////////////////////////////////////
   124 ///////////////////////////////////////////////////////////////////////////////////////
       
   125 
       
   126 //StatementMaxNumberTest() timeouts in WDP builds.
       
   127 //This function is used to check whether the time limit is reaqched or not.
       
   128 TBool IsTimeLimitReached()
       
   129 	{
       
   130 	struct TStartTime
       
   131 		{
       
   132 		TStartTime()
       
   133 			{
       
   134 			iTime.HomeTime();
       
   135 			}
       
   136 		TTime iTime;
       
   137 		};
       
   138 	
       
   139 	static TStartTime startTime; 
       
   140 	const TInt KTestTimeLimit = 500;//seconds
       
   141 	
       
   142 	TTime currTime;
       
   143 	currTime.HomeTime();
       
   144 	
       
   145 	TTimeIntervalSeconds s;
       
   146 	TInt err = currTime.SecondsFrom(startTime.iTime, s);
       
   147 	TEST2(err, KErrNone);
       
   148 	return s.Int() > KTestTimeLimit;
       
   149 	}
   117 
   150 
   118 void CreateTestDir()
   151 void CreateTestDir()
   119     {
   152     {
   120     RFs fs;
   153     RFs fs;
   121 	TInt err = fs.Connect();
   154 	TInt err = fs.Connect();
   538 @SYMTestPriority        High
   571 @SYMTestPriority        High
   539 @SYMTestActions         The test creates a table with couple of records and then
   572 @SYMTestActions         The test creates a table with couple of records and then
   540 						creates as many as possible SQL statements. The expected result is
   573 						creates as many as possible SQL statements. The expected result is
   541 						that either the statement creation process will fail with KErrNoMemory or
   574 						that either the statement creation process will fail with KErrNoMemory or
   542 						the max number of statements to be created is reached (100000).
   575 						the max number of statements to be created is reached (100000).
   543 						Then the test deletes 1/2 of the created statements object and
   576 						Then the test deletes 1/2 of the created statements objects and
   544 						after that attempts to execute Next() on the rest of them.
   577 						after that attempts to execute Next() on the rest of them.
       
   578 						Note that the test has a time limit of 500 seconds. Otherwise on some platforms
       
   579 						with WDP feature switched on the test may timeout.
   545 @SYMTestExpectedResults Test must not fail
   580 @SYMTestExpectedResults Test must not fail
   546 @SYMDEF                 DEF145236
   581 @SYMDEF                 DEF145236
   547 */  
   582 */  
   548 void StatementMaxNumberTest()
   583 void StatementMaxNumberTest()
   549 	{
   584 	{
       
   585 	TBuf<30> time;
       
   586 	GetHomeTimeAsString(time);
       
   587 	TheTest.Printf(_L("=== %S: Create database\r\n"), &time);
       
   588 	
   550 	(void)RSqlDatabase::Delete(KTestDbName1);
   589 	(void)RSqlDatabase::Delete(KTestDbName1);
   551 	RSqlDatabase db;
   590 	RSqlDatabase db;
   552 	TInt err = db.Create(KTestDbName1);
   591 	TInt err = db.Create(KTestDbName1);
   553 	TEST2(err, KErrNone);
   592 	TEST2(err, KErrNone);
   554 	err = db.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A(I) VALUES(1); INSERT INTO A(I) VALUES(2);"));
   593 	err = db.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A(I) VALUES(1); INSERT INTO A(I) VALUES(2);"));
   555 	TEST(err >= 0);
   594 	TEST(err >= 0);
       
   595 
       
   596 	GetHomeTimeAsString(time);
       
   597 	TheTest.Printf(_L("=== %S: Create statements array\r\n"), &time);
   556 	
   598 	
   557 	//Reserve memory for the statement objects
   599 	//Reserve memory for the statement objects
   558 	const TInt KMaxStmtCount = 100000;
   600 	const TInt KMaxStmtCount = 100000;
   559 	RSqlStatement* stmt = new RSqlStatement[KMaxStmtCount];
   601 	RSqlStatement* stmt = new RSqlStatement[KMaxStmtCount];
   560 	TEST(stmt != NULL);
   602 	TEST(stmt != NULL);
   561 	TInt stmtCnt = 0;
   603 	TInt stmtCnt = 0;
   562 	
   604 
   563 	//Create as many statement objects as possible
   605 	//Create as many statement objects as possible
   564 	err = KErrNone;
   606 	err = KErrNone;
   565 	for(TInt i=0;(i<KMaxStmtCount) && (err == KErrNone);++i,++stmtCnt)
   607 	for(TInt i=0;(i<KMaxStmtCount) && (err == KErrNone);++i,++stmtCnt)
   566 		{
   608 		{
   567 		err = stmt[i].Prepare(db, _L("SELECT * FROM A WHERE I>=0 AND I<10"));
   609 		err = stmt[i].Prepare(db, _L("SELECT * FROM A WHERE I>=0 AND I<10"));
       
   610 		if((i % 100) == 0)
       
   611 			{
       
   612 			GetHomeTimeAsString(time);
       
   613 			TheTest.Printf(_L("=== %S: Create % 5d statements\r\n"), &time, i + 1);
       
   614 			if(IsTimeLimitReached())
       
   615 				{
       
   616 				TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time);
       
   617 				break;
       
   618 				}
       
   619 			}
   568 		}
   620 		}
   569 	TheTest.Printf(_L("%d created statement objects. Last error: %d.\r\n"), stmtCnt, err);
   621 	TheTest.Printf(_L("%d created statement objects. Last error: %d.\r\n"), stmtCnt, err);
   570 	TEST(err == KErrNone || err == KErrNoMemory);
   622 	TEST(err == KErrNone || err == KErrNoMemory);
   571 
   623 
   572 	//Close 1/2 of the statements to free some memory
   624 	//Close 1/2 of the statements to free some memory
   573 	for(TInt i=stmtCnt-1;i>=0;i-=2)
   625 	for(TInt i=stmtCnt-1,j=0;i>=0;i-=2,++j)
   574 		{
   626 		{
   575 		stmt[i].Close();
   627 		stmt[i].Close();
       
   628 		if((j % 100) == 0)
       
   629 			{
       
   630 			GetHomeTimeAsString(time);
       
   631 			TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, j + 1);
       
   632 			}
   576 		}
   633 		}
   577 	
   634 	
   578 	//Now, there should be enough memory to be able to execute Next() on the rest of the statements
   635 	//Now, there should be enough memory to be able to execute Next() on the rest of the statements
   579 	for(TInt i=stmtCnt-2;i>=0;i-=2)
   636 	for(TInt i=stmtCnt-2,j=0;i>=0;i-=2,++j)
   580 		{
   637 		{
   581 		err = stmt[i].Next();
   638 		err = stmt[i].Next();
   582 		TEST2(err, KSqlAtRow);
   639 		TEST2(err, KSqlAtRow);
   583 		err = stmt[i].Next();
   640 		err = stmt[i].Next();
   584 		TEST2(err, KSqlAtRow);
   641 		TEST2(err, KSqlAtRow);
   585 		err = stmt[i].Next();
   642 		err = stmt[i].Next();
   586 		TEST2(err, KSqlAtEnd);
   643 		TEST2(err, KSqlAtEnd);
   587 		}
   644 		if((j % 100) == 0)
   588 	
   645 			{
       
   646 			GetHomeTimeAsString(time);
       
   647 			TheTest.Printf(_L("=== %S: % 5d statements processed\r\n"), &time, j + 1);
       
   648 			}
       
   649 		if(IsTimeLimitReached())
       
   650 			{
       
   651 			TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time);
       
   652 			break;
       
   653 			}
       
   654 		}
       
   655 
   589 	//Cleanup
   656 	//Cleanup
   590 	for(TInt i=stmtCnt-1;i>=0;--i)
   657 	for(TInt i=stmtCnt-1,j=0;i>=0;--i,++j)
   591 		{
   658 		{
   592 		stmt[i].Close();
   659 		stmt[i].Close();
       
   660 		if((j % 100) == 0)
       
   661 			{
       
   662 			GetHomeTimeAsString(time);
       
   663 			TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, j + 1);
       
   664 			}
   593 		}
   665 		}
   594 	delete [] stmt;
   666 	delete [] stmt;
   595 	db.Close();
   667 	db.Close();
   596 	(void)RSqlDatabase::Delete(KTestDbName1);
   668 	(void)RSqlDatabase::Delete(KTestDbName1);
   597 	}
   669 	}