コード例 #1
0
/**
@SYMTestCaseID			SYSLIB-DBMS-CT-3407
@SYMTestCaseDesc		Test for defect DEF103023 - DBMS requires ReadDeviceData and WriteDeviceData capability to read from the db.
 						The current test application has no capabilities at all.
 						"C:TestDB.DB" database is a secure shared database with:
 							- no "READ" polycy (no restrictions apply to the database read operations);
 							- "WRITE" policy with "WriteUserData" capability defined;
 							- "SCHEMA" policy with "NetworkServices" capability defined;
 							- table C has no defined securoty policy, so the database security policy will be used;
 						The current test application should be able to:
 							- begin/commit/rollback a "read-only" transaction;
 						But should fail if:
 							- begin a transaction and try to modify the database within the transaction;
 						This test function asserts the test cases described above.
@SYMTestPriority		High
@SYMTestActions			Test for defect DEF103023 - DBMS requires ReadDeviceData and WriteDeviceData capability to read from the db.
@SYMTestExpectedResults Test must not fail
@SYMDEF					DEF103023
*/
void DEF103023L()
	{
	TheTest.Printf(_L("Begin a transaction. Read-only operations tested\n"));
	TInt err = TheDb.Begin();
	TEST2(err, KErrNone);
	TheTest.Printf(_L("Perform some read-only operations inside the transaction\n"));
	err = TheView.Prepare(TheDb, _L("SELECT * FROM C"));
	TEST2(err, KErrNone);
	err = TheView.EvaluateAll();
	TEST2(err, KErrNone);
	TInt cnt = TheView.CountL();
	TEST(cnt > 0);
	TBool rc = TheView.FirstL();
	TEST(rc);
	TheView.GetL();
	TInt val = TheView.ColInt32(1);
	rc = TheView.LastL();
	TEST(rc);
	rc = TheView.NextL();
	TEST(!rc);
	rc = TheView.PreviousL();
	TEST(rc);
	TheView.BeginningL();
	TheView.EndL();
	TheView.Close();
	TheTest.Printf(_L("Commit a transaction\n"));
	err = TheDb.Commit();
	TEST2(err, KErrNone);
	//
	TheTest.Printf(_L("Begin a transaction. Read-only operations tested\n"));
	err = TheDb.Begin();
	TEST2(err, KErrNone);
	err = TheView.Prepare(TheDb, _L("SELECT * FROM C"));
	TEST2(err, KErrNone);
	err = TheView.EvaluateAll();
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();
	TheTest.Printf(_L("Rollback a transaction\n"));
	TheDb.Rollback();
	//
	TheTest.Printf(_L("Begin a transaction. Tested operations violate the database security\n"));
	err = TheDb.Begin();
	TEST2(err, KErrNone);
	err = TheView.Prepare(TheDb, _L("SELECT * FROM C"));
	TEST2(err, KErrNone);
	err = TheView.EvaluateAll();
	TEST2(err, KErrNone);
	rc = TheView.FirstL();
	TEST(rc);
	TheView.GetL();
	TheTest.Printf(_L("An attempt to update a record within the transaction\n"));
	TRAP(err, TheView.UpdateL());
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to delete a record within the transaction\n"));
	TRAP(err, TheView.DeleteL());
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to insert a record within the transaction\n"));
	TRAP(err, TheView.InsertL());
	TEST2(err, KErrPermissionDenied);
	TheView.Close();
	TheTest.Printf(_L("An attempt to modify the database schema within the transaction\n"));
	err = TheDb.Execute(_L("CREATE TABLE C2(Id INTEGER, Z INTEGER)"));
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to execute an INSERT statement within the transaction\n"));
	err = TheDb.Execute(_L("INSERT INTO C VALUES(100)"));
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to modify the database within the transaction using RDbUpdate\n"));
	RDbUpdate update;
	err = update.Execute(TheDb, _L("INSERT INTO C VALUES(200)"));
	TEST2(err, KErrPermissionDenied);
	update.Close();
	TheTest.Printf(_L("Rollback a transaction\n"));
	TheDb.Rollback();
	}