persistentstorage/sql/TEST/t_sqlfserr.cpp
branchRCL_3
changeset 11 211563e4b919
parent 8 fa9941cf3867
child 12 6b6fd149daa2
equal deleted inserted replaced
10:31a8f755b7fe 11:211563e4b919
   282     TEST2(err, KErrNone);
   282     TEST2(err, KErrNone);
   283     err = aSecurityPolicy.SetDbPolicy(RSqlSecurityPolicy::EReadPolicy, alwaysPassPolicy);
   283     err = aSecurityPolicy.SetDbPolicy(RSqlSecurityPolicy::EReadPolicy, alwaysPassPolicy);
   284     TEST2(err, KErrNone);
   284     TEST2(err, KErrNone);
   285     }
   285     }
   286 
   286 
       
   287 //Creates public shared, private secure and public secure databases.
       
   288 void DoCreateTestDatabases(const TPtrC aDbName[], TInt aCount)
       
   289     {
       
   290     TEST(aCount > 0);
       
   291     for(TInt i=0;i<aCount;++i)
       
   292         {
       
   293         TheTest.Printf(_L("Database: \"%S\"\r\n"), &aDbName[i]);       
       
   294         (void)RSqlDatabase::Delete(aDbName[i]);
       
   295         TInt err = KErrGeneral;
       
   296         if(i == (aCount - 1))
       
   297             {
       
   298             RSqlSecurityPolicy policy;
       
   299             CreateTestSecurityPolicy(policy);
       
   300             err = TheDb.Create(aDbName[i], policy);
       
   301             policy.Close();
       
   302             }
       
   303         else
       
   304             {
       
   305             err = TheDb.Create(aDbName[i]);
       
   306             }
       
   307         TEST2(err, KErrNone);
       
   308         err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER,Name TEXT)"));
       
   309         TEST(err >= 0);
       
   310         err = TheDb.Exec(_L("INSERT INTO A(Id,Name) VALUES(1,'Name')"));
       
   311         TEST2(err, 1);
       
   312         TheDb.Close();
       
   313         }
       
   314     }
       
   315 
   287 /**
   316 /**
   288 @SYMTestCaseID			SYSLIB-SQL-UT-3421
   317 @SYMTestCaseID			SYSLIB-SQL-UT-3421
   289 @SYMTestCaseDesc		Test for DEF103859 "SQLITE panic, _DEBUG mode, persistent file I/O error simulation".
   318 @SYMTestCaseDesc		Test for DEF103859 "SQLITE panic, _DEBUG mode, persistent file I/O error simulation".
   290 						The test creates a test database with one table, inserts one record.
   319 						The test creates a test database with one table, inserts one record.
   291 						Then the test attempts to open the database while simulating file I/O failures.
   320 						Then the test attempts to open the database while simulating file I/O failures.
   298 */
   327 */
   299 void OpenDatabaseTest()
   328 void OpenDatabaseTest()
   300 	{
   329 	{
   301     TPtrC dbName[] = {KTestDbName(), KPrivateTestDbName(), KSecureTestDbName()};
   330     TPtrC dbName[] = {KTestDbName(), KPrivateTestDbName(), KSecureTestDbName()};
   302     const TInt KDbNameCnt = sizeof(dbName) / sizeof(dbName[0]);
   331     const TInt KDbNameCnt = sizeof(dbName) / sizeof(dbName[0]);
       
   332     DoCreateTestDatabases(dbName, KDbNameCnt);
   303     for(TInt k=0;k<KDbNameCnt;++k)
   333     for(TInt k=0;k<KDbNameCnt;++k)
   304         {	
   334         {	
   305         TheTest.Printf(_L("Database: \"%S\"\r\n"), &dbName[k]);       
   335         TheTest.Printf(_L("Database: \"%S\"\r\n"), &dbName[k]);       
   306         (void)RSqlDatabase::Delete(dbName[k]);
   336         TInt err = KErrNotFound;
   307         TInt err = KErrGeneral;
       
   308         if(k == (KDbNameCnt - 1))
       
   309             {
       
   310             RSqlSecurityPolicy policy;
       
   311             CreateTestSecurityPolicy(policy);
       
   312             err = TheDb.Create(dbName[k], policy);
       
   313             policy.Close();
       
   314             }
       
   315         else
       
   316             {
       
   317             err = TheDb.Create(dbName[k]);
       
   318             }
       
   319         TEST2(err, KErrNone);
       
   320         err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER,Name TEXT)"));
       
   321         TEST(err >= 0);
       
   322         err = TheDb.Exec(_L("INSERT INTO A(Id,Name) VALUES(1,'Name')"));
       
   323         TEST2(err, 1);
       
   324         TheDb.Close();
       
   325     
       
   326         err = KErrNotFound;
       
   327         for(TInt cnt=1;err<KErrNone;++cnt)
   337         for(TInt cnt=1;err<KErrNone;++cnt)
   328             {		
   338             {		
   329             TheTest.Printf(_L("%d \r"), cnt);		
   339             TheTest.Printf(_L("%d \r"), cnt);		
   330             for (TInt fsError=KErrNotFound;fsError>=KErrDied;--fsError)
   340             for (TInt fsError=KErrNotFound;fsError>=KErrDied;--fsError)
   331                 {
   341                 {
   352         //check the database content is the same as before the operation, after reopening the database.
   362         //check the database content is the same as before the operation, after reopening the database.
   353         TEST(CheckRecord(dbName[k], 1, _L("Name")));
   363         TEST(CheckRecord(dbName[k], 1, _L("Name")));
   354         err = RSqlDatabase::Delete(dbName[k]);
   364         err = RSqlDatabase::Delete(dbName[k]);
   355         TEST2(err, KErrNone);
   365         TEST2(err, KErrNone);
   356         TheTest.Printf(_L("\r\n"));
   366         TheTest.Printf(_L("\r\n"));
   357         }
   367         }//end of: for(TInt k=0;k<KDbNameCnt;++k)
   358 	}
   368 	}
   359 
   369 
   360 /**
   370 /**
   361 @SYMTestCaseID			SYSLIB-SQL-UT-3434
   371 @SYMTestCaseID			SYSLIB-SQL-UT-3434
   362 @SYMTestCaseDesc		Test for DEF104820 "SQL, RSqlDatabase::Create() does not delete the file if fails".
   372 @SYMTestCaseDesc		Test for DEF104820 "SQL, RSqlDatabase::Create() does not delete the file if fails".
   411 	    }
   421 	    }
   412 	policy.Close();
   422 	policy.Close();
   413 	}
   423 	}
   414 
   424 
   415 /**
   425 /**
       
   426 @SYMTestCaseID          PDS-SQL-UT-4189
       
   427 @SYMTestCaseDesc        Test for DEF145125 "SQL, low code coverage".
       
   428                         The test creates public shared, private secure and public secure test databases.
       
   429                         Then the test opens the publich shared database and attempts to attach one of the other two
       
   430                         in a file I/O error simulation loop.
       
   431 @SYMTestPriority        High
       
   432 @SYMTestActions         Test for DEF145125 - "SQL, low code coverage".
       
   433 @SYMTestExpectedResults The test must not fail
       
   434 @SYMDEF                 DEF145125 
       
   435 */
       
   436 void AttachDatabaseTest()
       
   437     {
       
   438     TPtrC dbName[] = {KTestDbName(), KPrivateTestDbName(), KSecureTestDbName()};
       
   439     const TInt KDbNameCnt = sizeof(dbName) / sizeof(dbName[0]);
       
   440     DoCreateTestDatabases(dbName, KDbNameCnt);
       
   441     for(TInt k=1;k<KDbNameCnt;++k)
       
   442         {
       
   443         TheTest.Printf(_L("Database: \"%S\"\r\n"), &dbName[k]);       
       
   444         TInt err = KErrGeneral;
       
   445         for(TInt cnt=1;err<KErrNone;++cnt)
       
   446             {
       
   447             TheTest.Printf(_L("%d \r"), cnt);       
       
   448             for(TInt fsError=KErrNotFound;fsError>=KErrDied;--fsError)
       
   449                 {
       
   450                 err = TheDb.Open(KTestDbName);
       
   451                 TEST2(err, KErrNone);
       
   452                 (void)TheFs.SetErrorCondition(fsError, cnt);
       
   453                 err = TheDb.Attach(dbName[k], _L("DB2"));
       
   454                 (void)TheFs.SetErrorCondition(KErrNone);
       
   455                 (void)TheDb.Detach(_L("DB2"));
       
   456                 TheDb.Close();//close the database to recover from the last error
       
   457                 }
       
   458             }
       
   459         TEST2(err, KErrNone);
       
   460         err = RSqlDatabase::Delete(dbName[k]);
       
   461         TEST2(err, KErrNone);
       
   462         TheTest.Printf(_L("\r\n"));
       
   463         }
       
   464     }
       
   465 
       
   466 /**
       
   467 @SYMTestCaseID          PDS-SQL-UT-4190
       
   468 @SYMTestCaseDesc        Test for DEF145125 "SQL, low code coverage".
       
   469                         The tests attempts to delete a database in a file I/O error simulation loop.
       
   470 @SYMTestPriority        High
       
   471 @SYMTestActions         Test for DEF145125 - "SQL, low code coverage".
       
   472 @SYMTestExpectedResults The test must not fail
       
   473 @SYMDEF                 DEF145125 
       
   474 */
       
   475 void DeleteDatabaseTest()
       
   476     {
       
   477     TPtrC dbName[] = {KTestDbName(), KPrivateTestDbName(), KSecureTestDbName()};
       
   478     const TInt KDbNameCnt = sizeof(dbName) / sizeof(dbName[0]);
       
   479     DoCreateTestDatabases(dbName, KDbNameCnt);
       
   480     for(TInt k=0;k<KDbNameCnt;++k)
       
   481         {   
       
   482         TheTest.Printf(_L("Database: \"%S\"\r\n"), &dbName[k]);       
       
   483         TInt err = KErrGeneral;
       
   484         for(TInt cnt=1;err<KErrNone;++cnt)
       
   485             {
       
   486             TheTest.Printf(_L("%d \r"), cnt);
       
   487             (void)TheFs.SetErrorCondition(KErrGeneral, cnt);
       
   488             err = RSqlDatabase::Delete(dbName[k]);
       
   489             (void)TheFs.SetErrorCondition(KErrNone);
       
   490             }
       
   491         TEST2(err, KErrNone);
       
   492         err = RSqlDatabase::Delete(KTestDbName);
       
   493         TEST2(err, KErrNotFound);
       
   494         }    
       
   495     }
       
   496 
       
   497 /**
   416 @SYMTestCaseID			SYSLIB-SQL-UT-3462
   498 @SYMTestCaseID			SYSLIB-SQL-UT-3462
   417 @SYMTestCaseDesc		Test for DEF105434 "SQL, persistent file I/O simulation, COMMIT problem".
   499 @SYMTestCaseDesc		Test for DEF105434 "SQL, persistent file I/O simulation, COMMIT problem".
   418 						The test creates a test database with one table, inserts one record.
   500 						The test creates a test database with one table, inserts one record.
   419 						Then the test attempts to retrieve the existing record while simulating file I/O failures.
   501 						Then the test attempts to retrieve the existing record while simulating file I/O failures.
   420 						After each iteration, the database content is tested, that it has not been modified by the operation.
   502 						After each iteration, the database content is tested, that it has not been modified by the operation.
  1131 	AlterDatabaseTest2();
  1213 	AlterDatabaseTest2();
  1132 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3421 Open database during file I/O error "));
  1214 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3421 Open database during file I/O error "));
  1133 	OpenDatabaseTest();
  1215 	OpenDatabaseTest();
  1134 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3434 Create database during file I/O error "));
  1216 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3434 Create database during file I/O error "));
  1135 	CreateDatabaseTest();
  1217 	CreateDatabaseTest();
       
  1218     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4189 Attach database during file I/O error "));
       
  1219     AttachDatabaseTest();
       
  1220     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4190 Delete database during file I/O error "));
       
  1221     DeleteDatabaseTest();
  1136 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3462 Select record test during file I/O error "));
  1222 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3462 Select record test during file I/O error "));
  1137 	SelectRecordTest();
  1223 	SelectRecordTest();
  1138 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3463 Insert record test during file I/O error "));
  1224 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3463 Insert record test during file I/O error "));
  1139 	InsertRecordTest();
  1225 	InsertRecordTest();
  1140 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3516 Removable Media robustness test "));
  1226 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3516 Removable Media robustness test "));