persistentstorage/sql/TEST/t_sqldefect.cpp
branchRCL_3
changeset 8 fa9941cf3867
parent 6 5ffdb8f2067f
child 11 211563e4b919
equal deleted inserted replaced
6:5ffdb8f2067f 8:fa9941cf3867
    34 _LIT(KSecureTestDb1, "c:[21212122]BBDb2.db");		//Created outside this test app
    34 _LIT(KSecureTestDb1, "c:[21212122]BBDb2.db");		//Created outside this test app
    35 _LIT(KTestDatabase3, "c:\\test\\t_sqldefect_3.db");
    35 _LIT(KTestDatabase3, "c:\\test\\t_sqldefect_3.db");
    36 _LIT(KTestDatabase4, "z:\\test\\t_inc095412.db");	//Created outside this test app
    36 _LIT(KTestDatabase4, "z:\\test\\t_inc095412.db");	//Created outside this test app
    37 _LIT(KTestDatabase5, "c:\\test\\t_sqldefect_5.db");
    37 _LIT(KTestDatabase5, "c:\\test\\t_sqldefect_5.db");
    38 _LIT(KTestDatabase6, "c:\\test\\t_def120237.db");
    38 _LIT(KTestDatabase6, "c:\\test\\t_def120237.db");
    39 
    39 _LIT(KTestDatabase7, "c:\\test\\t_def144027.db");
       
    40 _LIT(KTestDatabase7Journal, "c:\\test\\t_def144027.db-journal");
    40 
    41 
    41 // This value has been found by performing the OOM test
    42 // This value has been found by performing the OOM test
    42 // with an allocation limit of 2000 and then taking a value
    43 // with an allocation limit of 2000 and then taking a value
    43 // which is just above the allocation failure rate.
    44 // which is just above the allocation failure rate.
    44 const TInt KDEF115954MaxAllocLimit = 1300;
    45 const TInt KDEF115954MaxAllocLimit = 1300;
    47 
    48 
    48 //Deletes all created test files.
    49 //Deletes all created test files.
    49 void DeleteTestFiles()
    50 void DeleteTestFiles()
    50 	{
    51 	{
    51 	TheDb.Close();
    52 	TheDb.Close();
       
    53 	(void)TheFs.Delete(KTestDatabase7Journal);
       
    54 	(void)RSqlDatabase::Delete(KTestDatabase7);
    52 	(void)RSqlDatabase::Delete(KTestDatabase6);
    55 	(void)RSqlDatabase::Delete(KTestDatabase6);
    53 	(void)RSqlDatabase::Delete(KTestDatabase5);
    56 	(void)RSqlDatabase::Delete(KTestDatabase5);
    54 	(void)RSqlDatabase::Delete(KTestDatabase3);
    57 	(void)RSqlDatabase::Delete(KTestDatabase3);
    55 	(void)RSqlDatabase::Delete(KTestDatabase2);
    58 	(void)RSqlDatabase::Delete(KTestDatabase2);
    56 	(void)RSqlDatabase::Delete(KTestDatabase1);
    59 	(void)RSqlDatabase::Delete(KTestDatabase1);
  1580         }
  1583         }
  1581     while (err == KErrNoMemory);
  1584     while (err == KErrNoMemory);
  1582     TEST2(err, 1);
  1585     TEST2(err, 1);
  1583     }
  1586     }
  1584 
  1587 
       
  1588 /**
       
  1589 @SYMTestCaseID          PDS-SQL-CT-4166
       
  1590 @SYMTestCaseDesc        Tests for DEF144027: SQL Open returns error if the reported and actual file size are different
       
  1591 @SYMTestPriority        Medium
       
  1592 @SYMTestActions         1) Create a simple database and close it (this will automatically delete the journal file
       
  1593                         2) Create a 15 bytes garbage journal file which is just less than the minimum file size allowed.
       
  1594                         3) Reopen the database and checks that the open operation does not fail even thou we've used a 
       
  1595                         garbage journal file which is too small
       
  1596 @SYMTestExpectedResults The RSqlDatabase::Open operation should not fail
       
  1597 @SYMDEF                 DEF144027
       
  1598                         DEF144238
       
  1599 */
       
  1600 void DEF144027()
       
  1601     {
       
  1602     (void) RSqlDatabase::Delete(KTestDatabase7);
       
  1603     (void) TheFs.Delete(KTestDatabase7Journal);
       
  1604     
       
  1605     TInt err = TheDb.Create(KTestDatabase7);
       
  1606     TEST2(err, KErrNone);
       
  1607     
       
  1608     err = TheDb.Exec(_L("CREATE TABLE t1(NUM INTEGER)"));
       
  1609     TEST2(err, 1);
       
  1610     
       
  1611     err = TheDb.Exec(_L("INSERT INTO t1(NUM) VALUES (1)"));
       
  1612     TEST2(err, 1);
       
  1613     
       
  1614     TheDb.Close();
       
  1615     
       
  1616     //Created a garbage 15 bytes journal file 
       
  1617     RFile file;
       
  1618     err = file.Create(TheFs, KTestDatabase7Journal, EFileWrite);
       
  1619     TEST2(err, KErrNone);
       
  1620     
       
  1621     _LIT8(KJournalJunkData, "A123456789B1234");//15 bytes
       
  1622     err = file.Write(0, KJournalJunkData);
       
  1623     TEST2(err, KErrNone);
       
  1624     
       
  1625     file.Flush();
       
  1626     file.Close();
       
  1627     
       
  1628     //Here we check the open operation does not return an error, 
       
  1629     //even though there is a journal file less than 16 bytes
       
  1630     err = TheDb.Open(KTestDatabase7);
       
  1631     TEST2(err, KErrNone);
       
  1632     TheDb.Close();
       
  1633     }
       
  1634 
  1585 void DoTestsL()
  1635 void DoTestsL()
  1586 	{
  1636 	{
  1587 	
       
  1588 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1763 \"SQL against a detached db\" test "));
  1637 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1763 \"SQL against a detached db\" test "));
  1589 	SqlDetachedDbTest();	
  1638 	SqlDetachedDbTest();	
  1590 
  1639 
  1591 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4034 Corrupted db file (file length too short)"));
  1640 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4034 Corrupted db file (file length too short)"));
  1592 	CorruptDbFileTest();	
  1641 	CorruptDbFileTest();	
  1663     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4153 DEF143047: SQL, default \"max parameter count\" value, compatibility problem."));
  1712     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4153 DEF143047: SQL, default \"max parameter count\" value, compatibility problem."));
  1664     DEF143047();
  1713     DEF143047();
  1665     
  1714     
  1666     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4157 PDEF143461 : CSqlSrvDatabase::LastErrorMessage() alignment problem"));
  1715     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4157 PDEF143461 : CSqlSrvDatabase::LastErrorMessage() alignment problem"));
  1667     PDEF143461L();
  1716     PDEF143461L();
       
  1717     
       
  1718     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4166 DEF144027: SQL Open returns error if the reported and actual file size are different"));
       
  1719     DEF144027();
  1668 	}
  1720 	}
  1669 
  1721 
  1670 TInt E32Main()
  1722 TInt E32Main()
  1671 	{
  1723 	{
  1672 	TheTest.Title();
  1724 	TheTest.Title();