TInt E32Main() { __UHEAP_MARK; CTrapCleanup* tc = CTrapCleanup::New(); TEST(tc != NULL); TInt err = TheDbs.Connect(); TEST2(err, KErrNone); TBuf<32> format; TheTest.Printf(_L("Open database\n")); format.Copy(KSecure); format.Append(KSecureDbUid.Name()); err = TheDb.Open(TheDbs, KDbName, format); TEST2(err, KErrNone); TRAP(err, DoTestL()); TEST2(err, KErrNone); TheView.Close(); TheTbl.Close(); TheDb.Close(); TheDbs.Close(); TheTest.End(); TheTest.Close(); delete tc; __UHEAP_MARKEND; User::Heap().Check(); return KErrNone; }
// --------------------------------------------------------------------------- // CFotaDB::GetAllL // Get all states // --------------------------------------------------------------------------- void CFotaDB::GetAllL(RArray<TInt>& aStates) { RDbView view; CleanupClosePushL(view); TInt err = view.Prepare(iStateDB, TDbQuery(KSelectAll)); __LEAVE_IF_ERROR(err); view.EvaluateAll(); view.FirstL(); FLOG(_L("[fota DB] --- rows ------------------------------------------------------------------- v")); while (view.AtRow()) { view.GetL(); HBufC8* url; TPackageState s = RowToStateL(url, view); aStates.Append(s.iPkgId); CleanupStack::PushL(url); FLOG(_L("[fotaDB] pkgid: %d profid:%d state:%d result:%d \ url: %d chars sessiontype:%d IapId:%d Pkgsize:%d UpdateLtr:%d"), s.iPkgId, s.iProfileId, s.iState, s.iResult, url->Des().Length(), s.iSessionType, s.iIapId, s.iPkgSize, s.iUpdateLtr); CleanupStack::PopAndDestroy(); // url view.NextL(); } FLOG(_L("[fota DB] --- rows ------------------------------------------------------------------- ^")); view.Close(); CleanupStack::PopAndDestroy(); //view }
static void CleanupTest() { TheView.Close(); TheTbl.Close(); TheDb.Close(); TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDbName); TheDbs.Close(); }
/** @SYMTestCaseID SYSLIB-DBMS-CT-0018 @SYMTestCaseDesc Open table test. This test app has no capabilities and it is restricted to be able to open tables B and C in read-only mode. @SYMTestPriority High @SYMTestActions Open table test. @SYMTestExpectedResults The test must not fail. @SYMREQ REQ2429 DBMS shall provide an API to apply security policies to database tables. */ static void Test1L() { TheTest.Printf(_L("An attempt to open tables in update/insert mode\n")); //The test must fail, because the test app cannot satisfy table A, B, C, policy W. TInt err = TheTbl.Open(TheDb, KTblNameA); TEST2(err, KErrPermissionDenied); err = TheTbl.Open(TheDb, KTblNameB); TEST2(err, KErrPermissionDenied); err = TheTbl.Open(TheDb, KTblNameC); TEST2(err, KErrPermissionDenied); TheTest.Printf(_L("An attempt to open tables in read-only mode\n")); //The test must pass for table B & C, but the test app cannot satisfy table A, policy R. err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EReadOnly); TEST2(err, KErrPermissionDenied); err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly); TEST2(err, KErrNone); TheTbl.Close(); err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly); TEST2(err, KErrNone); TheTbl.Close(); TheTest.Printf(_L("An attempt to read tables\n")); //The test must pass for table B & C, but the test app cannot satisfy table A, policy R. err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM A"))); TEST2(err, KErrPermissionDenied); err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM B"))); TEST2(err, KErrNone); TInt cnt = TheView.CountL(); TEST(cnt > 0); TheView.Close(); err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM C"))); TEST2(err, KErrNone); cnt = TheView.CountL(); TEST(cnt > 0); TheView.Close(); }
/** @SYMTestCaseID SYSLIB-DBMS-CT-0011 @SYMTestCaseDesc SQL tests. The caller has a set of capabilities which satisfy database's schema security policy only. The test checks that the capapbility checking on the DBMS server side works properly. Some of the SQL statements won't be executed and the returned error will be KErrPermisssionDenied. @SYMTestPriority High @SYMTestActions Attempts to execute various INSERT/UPDATE/SELECT SQL statements. @SYMTestExpectedResults The test must not fail. @SYMREQ REQ2429 DBMS shall provide an API to apply security policies to database tables. */ static void TblSqlL() { TheTest.Printf(_L("SELECT SQL\n")); //The test must fail, because the test app cannot satisfy table A, policy R. TInt err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM A"))); TEST2(err, KErrPermissionDenied); //The test must pass, because table B has no R policy. err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM B"))); TEST2(err, KErrNone); TheView.Close(); //The test must pass, because table C has no R policy. err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM C"))); TEST2(err, KErrNone); TheView.Close(); TheTest.Printf(_L("INSERT/UPDATE SQL\n")); //The test must fail, because the test app cannot satisfy table A, policy W. err = TheDb.Execute(_L("INSERT INTO A (DATA2) VALUES(45)")); TEST2(err, KErrPermissionDenied); //The test must fail, because the test app cannot satisfy table B, policy W. err = TheDb.Execute(_L("INSERT INTO B (DATA2) VALUES(45)")); TEST2(err, KErrPermissionDenied); //The test must fail, because the test app cannot satisfy table C, policy W. err = TheDb.Execute(_L("INSERT INTO C (DATA2) VALUES(45)")); TEST2(err, KErrPermissionDenied); //The test must fail, because the test app cannot satisfy table A, policy W. err = TheDb.Execute(_L("UPDATE A SET DATA2=56 WHERE ID = 0")); TEST2(err, KErrPermissionDenied); //The test must fail, because the test app cannot satisfy table B, policy W. err = TheDb.Execute(_L("UPDATE B SET DATA2=56 WHERE ID = 0")); TEST2(err, KErrPermissionDenied); //The test must fail, because the test app cannot satisfy table C, policy W. err = TheDb.Execute(_L("UPDATE C SET DATA2=56 WHERE ID = 0")); TEST2(err, KErrPermissionDenied); }
static TInt SearchForL( const TPtrC& aSearchString, RDbNamedDatabase& aDb ) { _LIT( KSQLSearchStatement, "select Notes from CDs where Notes like '%S'" ); TBuf<512> query; query.Format( KSQLSearchStatement, &aSearchString ); // Display query _LIT( KQueryFormatter, "\r\n %S\r\n" ); TBuf<512> msg; msg.Format( KQueryFormatter, &query ); TheTest.Printf( msg ); // create a view on the database RDbView view; // use EDbCompareCollated in order to search case-insensitive __LEAVE_IF_ERROR( view.Prepare( aDb, TDbQuery( query, EDbCompareCollated ) ) ); __LEAVE_IF_ERROR( view.EvaluateAll() ); // iterate across the row set TInt noOfMatches = 0; for ( view.FirstL(); view.AtRow(); view.NextL() ) { // retrieve the row view.GetL(); noOfMatches++; } // Display no of matches _LIT( KNoOfMatchFormatter, " Found %d matches\r\n" ); msg.Format( KNoOfMatchFormatter, noOfMatches ); TheTest.Printf( msg ); // close the view view.Close(); return noOfMatches; }
/** @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(); }
/** @SYMTestCaseID SYSLIB-DBMS-CT-0645 @SYMTestCaseDesc Searching for data from a database @SYMTestPriority Medium @SYMTestActions Tests for EDbColText,EDbColLongText column type @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ static void TestSearchL( TInt aIndex ) { // Default database _LIT( KComposer1, "Elgar" ); _LIT( KCol1, "Artist" ); _LIT( KCol2, "Notes" ); _LIT( KTable, "CDs" ); TInt err = TheFsSession.Delete( KSearchTestDbPath ); if ( ( err != KErrNone ) && ( err != KErrNotFound ) && ( err != KErrPathNotFound ) ) { __LEAVE( err ); } RDbNamedDatabase db; CleanupClosePushL( db ); __LEAVE_IF_ERROR( db.Create( TheFsSession, KSearchTestDbPath ) ); // // Create the database table // // Create a table definition CDbColSet* columns = CDbColSet::NewLC(); // add the columns columns->AddL( TDbCol( KCol1, EDbColText ) ); if ( aIndex == 0 ) columns->AddL( TDbCol( KCol2, EDbColText ) ); else columns->AddL( TDbCol( KCol2, EDbColLongText ) ); // if the column is of type "EDbColText" instead, // all searching is working properly // Create a table __LEAVE_IF_ERROR( db.CreateTable( KTable, *columns ) ); // cleanup the column set CleanupStack::PopAndDestroy( columns ); // // Add data // // create a view on the database _LIT( KSQLStatement, "select Artist,Notes from CDs order by Artist" ); RDbView view; __LEAVE_IF_ERROR( view.Prepare( db, TDbQuery( KSQLStatement, EDbCompareNormal ) ) ); __LEAVE_IF_ERROR( view.EvaluateAll() ); // Get the structure of rowset CDbColSet* colSet = view.ColSetL(); // insert a row view.InsertL(); view.SetColL( colSet->ColNo( KCol1 ), KComposer1 ); // Artist // Use the stream // RDbColWriteStream out; // TDbColNo col = colSet->ColNo( KCol2 ); // Ordinal position of long column // // out.OpenLC( view, col ); // out.WriteL( _L( "Some additional comment here." ) ); // out.Close(); // // CleanupStack::PopAndDestroy(); // out view.SetColL( colSet->ColNo( KCol2 ), _L( "Some additional comment here." ) ); view.PutL(); // close the view view.Close(); delete colSet; // // Display the data // _LIT( KRowFormatter, "\r\n Artist: %S \r\n Notes: %S \r\n" ); __LEAVE_IF_ERROR( view.Prepare( db, TDbQuery( KSQLStatement, EDbCompareNormal ) ) ); __LEAVE_IF_ERROR( view.EvaluateAll() ); // Get the structure of the rowset colSet = view.ColSetL(); // iterate across the row set for ( view.FirstL(); view.AtRow(); view.NextL() ) { // retrieve the row view.GetL(); // while the rowset is on this row, can use a TPtrC to // refer to any text columns TPtrC artist = view.ColDes( colSet->ColNo( KCol1 ) ); // and a stream for long columns RDbColReadStream in; TDbColNo col = colSet->ColNo( KCol2 ); // Ordinal position of long column TBuf<256> notes; // Buffer for out notes in.OpenLC( view, col ); in.ReadL( notes, view.ColLength( col ) ); in.Close(); CleanupStack::PopAndDestroy(); // in // Display the artist and notes TBuf<512> msg; msg.Format( KRowFormatter, &artist, ¬es ); TheTest.Printf( msg ); } // close the view view.Close(); delete colSet; // // Search for the data // TInt result; result = SearchForL( _L( "Some*" ), db ); // matches TEST(result == 1); result = SearchForL( _L( "some*" ), db ); // defect causes no match, should match TEST(result == 1); result = SearchForL( _L( "*some*" ), db ); // matches TEST(result == 1); result = SearchForL( _L( "s?me*" ), db ); // matches TEST(result == 1); result = SearchForL( _L( "Some additional comment here." ), db ); // matches TEST(result == 1); result = SearchForL( _L( "some additional comment here." ), db ); // defect causes no match, should match TEST(result == 1); CleanupStack::PopAndDestroy( &db ); }
/** @SYMTestCaseID SYSLIB-DBMS-CT-0016 @SYMTestCaseDesc R/W operations at a table level. This test app has "PowerMgmt" (TABLE A: READ) capability, which allows it to read data from table A. B and C tables can be read too, because they do not have read security policy. @SYMTestPriority High @SYMTestActions R/W table operations. @SYMTestExpectedResults The test must not fail. @SYMREQ REQ2429 DBMS shall provide an API to apply security policies to database tables. */ static void TblRWL() { TheTest.Printf(_L("Table A - Write\n")); TInt err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EReadOnly); TEST2(err, KErrNone); //The test must fail, because the test app cannot satisfy table A, policy W. TRAP(err, TheTbl.InsertL()); TEST2(err, KErrPermissionDenied); err = TheDb.Execute(_L("UPDATE A SET DATA1 = 400 WHERE ID < 10")); TEST2(err, KErrPermissionDenied); TheTest.Printf(_L("Table A - Read\n")); //The test must pass, because the test app can satisfy table A, policy R. TBool res = EFalse; TRAP(err, res = TheTbl.FirstL()); TEST2(err, KErrNone); TEST(res); TInt cnt = TheTbl.CountL(); TEST(cnt > 0); err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM A"))); TEST2(err, KErrNone); cnt = TheView.CountL(); TEST(cnt > 0); TheView.Close(); TheTbl.Close(); TheTest.Printf(_L("Table B - Write\n")); err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly); TEST2(err, KErrNone); //The test must fail, because the test app cannot satisfy table B, policy W. TRAP(err, TheTbl.InsertL()); TEST2(err, KErrPermissionDenied); err = TheDb.Execute(_L("INSERT INTO B (DATA2) VALUES (45)")); TEST2(err, KErrPermissionDenied); TheTest.Printf(_L("Table B - Read\n")); //The test must pass, because table B has no R policy. TRAP(err, res = TheTbl.FirstL()); TEST2(err, KErrNone); TEST(res); cnt = TheTbl.CountL(); TEST(cnt > 0); err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM B"))); TEST2(err, KErrNone); cnt = TheView.CountL(); TEST(cnt > 0); TheView.Close(); TheTbl.Close(); TheTest.Printf(_L("Table C - Write\n")); err = TheTbl.Open(TheDb, KTblNameC); //The test must fail, because the test app cannot satisfy table C, policy W. TEST2(err, KErrPermissionDenied); err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly); TEST2(err, KErrNone); TRAP(err, TheTbl.InsertL()); TEST2(err, KErrPermissionDenied); err = TheDb.Execute(_L("UPDATE C SET DATA1 = 400 WHERE ID < 10")); TEST2(err, KErrPermissionDenied); TheTest.Printf(_L("Table C - Read\n")); //The test must pass, because table C has no R policy. TRAP(err, res = TheTbl.FirstL()); TEST2(err, KErrNone); TEST(res); cnt = TheTbl.CountL(); TEST(cnt > 0); err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM C"))); TEST2(err, KErrNone); cnt = TheView.CountL(); TEST(cnt > 0); TheView.Close(); TheTbl.Close(); }