persistentstorage/sql/TEST/t_sqldefect.cpp
branchRCL_3
changeset 6 5ffdb8f2067f
parent 0 08ec8eefde2f
child 8 fa9941cf3867
equal deleted inserted replaced
2:6862383cf555 6:5ffdb8f2067f
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   731 @SYMTestCaseDesc		Test for DEF106391 - SQL server does not deallocate the already allocated memory.
   731 @SYMTestCaseDesc		Test for DEF106391 - SQL server does not deallocate the already allocated memory.
   732 						The test is executed only on the Emulator, because its execution depends on the amount
   732 						The test is executed only on the Emulator, because its execution depends on the amount
   733 						of the available memory and the amount of free disk space - factors which cannot be easily 
   733 						of the available memory and the amount of free disk space - factors which cannot be easily 
   734 						resolved on target hardware.
   734 						resolved on target hardware.
   735 						The test creates a database with a table: T(Id INTEGER, Data BLOB). 
   735 						The test creates a database with a table: T(Id INTEGER, Data BLOB). 
   736 						One record with a BLOB (0.9Mb size) is inserted using RSqlDatabase::Exec().
   736 						One record with a BLOB (either 0.79Mb or 0.9Mb) is inserted using RSqlDatabase::Exec().
   737 						Another record with a BLOB (1.8Mb size) is inserted using RSqlStatement and BLOB parameter.
   737 						Another record with a BLOB (either 1.58 or 1.8Mb) is inserted using RSqlStatement and BLOB parameter.
   738 						If the defect is not fixed, after the first INSERT the SQL server will not free occupied by
   738 						If the defect is not fixed, after the first INSERT the SQL server will not free occupied by
   739 						the statement memory. The available heap memory won't be enough for the execution of the second INSERT statement.
   739 						the statement memory. The available heap memory won't be enough for the execution of the second INSERT statement.
   740 						The second INSERT will fail with KErrNoMemory.
   740 						The second INSERT will fail with KErrNoMemory.
   741 @SYMTestPriority		High
   741 @SYMTestPriority		High
   742 @SYMTestActions			Test for DEF106391 - SQL server does not deallocate the already allocated memory.
   742 @SYMTestActions			Test for DEF106391 - SQL server does not deallocate the already allocated memory.
   744 @SYMDEF					DEF106391
   744 @SYMDEF					DEF106391
   745 */
   745 */
   746 void DEF106391()
   746 void DEF106391()
   747 	{
   747 	{
   748 #if defined __WINS__ ||	defined __WINSCW__
   748 #if defined __WINS__ ||	defined __WINSCW__
   749 	const TInt KBlobSize = 900 * 1024;
   749 #ifndef SYMBIAN_USE_SQLITE_VERSION_3_6_4
       
   750     const TInt KBlobSize = 900 * 1024;
       
   751 #else
       
   752     const TInt KBlobSize = 790 * 1024;
       
   753 #endif    
       
   754 
   750 	_LIT8(KConfigStr, "encoding=UTF-8");
   755 	_LIT8(KConfigStr, "encoding=UTF-8");
   751 
   756 
   752 	HBufC8* sqlBuf = HBufC8::New(KBlobSize * 2 + 200);//"+ 200" - for the SQL INSERT statement
   757 	HBufC8* sqlBuf = HBufC8::New(KBlobSize * 2 + 200);//"+ 200" - for the SQL INSERT statement
   753 	TEST(sqlBuf != NULL);
   758 	TEST(sqlBuf != NULL);
   754 
   759 
  1502     delete buf;
  1507     delete buf;
  1503     TheDb.Close();
  1508     TheDb.Close();
  1504     (void)RSqlDatabase::Delete(KTestDatabase1);
  1509     (void)RSqlDatabase::Delete(KTestDatabase1);
  1505     }
  1510     }
  1506 
  1511 
       
  1512 /**
       
  1513 @SYMTestCaseID          PDS-SQL-UT-4157
       
  1514 @SYMTestCaseDesc        Test for PDEF143461  Calling CSqlSrvDatabase::LastErrorMessage() does not panic with the descriptor alignment error
       
  1515 @SYMTestPriority        Normal
       
  1516 @SYMTestActions         Test for PDEF143461  - CSqlSrvDatabase::LastErrorMessage() alignment problem.
       
  1517                         This tests the following SQLite Error messages to make sure it doesn't panic:
       
  1518                         1)library routine called out of sequence
       
  1519                         2)out of memory
       
  1520 @SYMTestExpectedResults Test must not fail
       
  1521 @SYMDEF                 PDEF143461 
       
  1522 */
       
  1523 void PDEF143461L()
       
  1524     {
       
  1525     (void) RSqlDatabase::Delete(KTestDatabase6);
       
  1526     
       
  1527     //Create and setup the database file
       
  1528     RSqlDatabase db;
       
  1529     TInt err =0;
       
  1530     err = db.Create(KTestDatabase6);
       
  1531     TEST2(err, KErrNone);
       
  1532     err = db.Exec(_L("CREATE TABLE t(num INTEGER)"));
       
  1533     TEST2(err, 1);
       
  1534     err = db.Exec(_L("INSERT INTO t VALUES(1)"));
       
  1535     TEST2(err, 1);
       
  1536     err = db.Exec(_L("INSERT INTO t VALUES(2)"));
       
  1537     TEST2(err, 1);
       
  1538 
       
  1539     
       
  1540     //Purposely commit an error so LastErrorMessage can be called 
       
  1541     RSqlStatement stmt;
       
  1542     err = stmt.Prepare(db, _L("DELETE FROM t WHERE ROWID=?"));
       
  1543     TEST2(err, KErrNone);
       
  1544     err = stmt.BindInt(0, 1);
       
  1545     TEST2(err, KErrNone);        
       
  1546     err = stmt.Exec();
       
  1547     TEST2(err, 1);
       
  1548     
       
  1549     //Should have reset stmt here
       
  1550     err = stmt.BindInt(0, 2);
       
  1551     TEST2(err, KErrNone); 
       
  1552     err = stmt.Exec();
       
  1553     TEST2(err, KSqlErrMisuse);
       
  1554     
       
  1555     //Test "library routine called out of sequence" error message 
       
  1556     //If the defect is not fixed then it will panic here   
       
  1557     TPtrC errMsg = db.LastErrorMessage();
       
  1558     RDebug::Print(_L("errMsg=%S\r\n"), &errMsg);
       
  1559 
       
  1560     stmt.Close();
       
  1561     db.Close();
       
  1562     
       
  1563     TInt allocationNo = 0;
       
  1564     //The mask allows the out of memory simulation of the SQL Server to be delayed until the database is opened
       
  1565     const TInt KDelayedDbHeapFailureMask = 0x1000;
       
  1566     
       
  1567     do
       
  1568         {
       
  1569         TSqlResourceTester::SetDbHeapFailure(RHeap::EDeterministic |KDelayedDbHeapFailureMask, ++allocationNo);
       
  1570         err = db.Open(KTestDatabase6);
       
  1571         TEST2(err, KErrNone);
       
  1572         err = db.Exec(_L("INSERT INTO t VALUES(3)"));
       
  1573         TSqlResourceTester::SetDbHeapFailure(RHeap::ENone, 0);
       
  1574         
       
  1575         TheTest.Printf(_L("%d    \r"), allocationNo);
       
  1576         //Test "out of memory" error message, if the defect is not fixed then it will panic here   
       
  1577         TPtrC errMsg = db.LastErrorMessage();
       
  1578         RDebug::Print(_L("errMsg=%S\r\n"), &errMsg);
       
  1579         db.Close();
       
  1580         }
       
  1581     while (err == KErrNoMemory);
       
  1582     TEST2(err, 1);
       
  1583     }
       
  1584 
  1507 void DoTestsL()
  1585 void DoTestsL()
  1508 	{
  1586 	{
  1509 	
  1587 	
  1510 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1763 \"SQL against a detached db\" test "));
  1588 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1763 \"SQL against a detached db\" test "));
  1511 	SqlDetachedDbTest();	
  1589 	SqlDetachedDbTest();	
  1582     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4128 DEF129581: All Pragmas are allowed to be executed on non-secure SQL databases."));
  1660     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4128 DEF129581: All Pragmas are allowed to be executed on non-secure SQL databases."));
  1583     DEF129581();
  1661     DEF129581();
  1584     
  1662     
  1585     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4153 DEF143047: SQL, default \"max parameter count\" value, compatibility problem."));
  1663     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4153 DEF143047: SQL, default \"max parameter count\" value, compatibility problem."));
  1586     DEF143047();
  1664     DEF143047();
       
  1665     
       
  1666     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4157 PDEF143461 : CSqlSrvDatabase::LastErrorMessage() alignment problem"));
       
  1667     PDEF143461L();
  1587 	}
  1668 	}
  1588 
  1669 
  1589 TInt E32Main()
  1670 TInt E32Main()
  1590 	{
  1671 	{
  1591 	TheTest.Title();
  1672 	TheTest.Title();