sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // DBMS security policy - performance tests sl@0: // Please, ensure that t_dbenvcreate test is executed before t_dbplatsec/t_dbplatsecperf tests! sl@0: // Please, ensure that t_dbenvdestroy test is executed after t_dbplatsec/t_dbplatsecperf tests! sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "t_dbplatsecutl.h" sl@0: sl@0: static RTest TheTest(_L("t_dbplatsecperf: DBMS platform security - Performance test")); sl@0: sl@0: static RDbs TheDbs; sl@0: static RDbNamedDatabase TheDb; sl@0: sl@0: const TUid KSecureDbUid = {0x11335579}; sl@0: _LIT(KSecure, "SECURE"); sl@0: _LIT(KDbNameC, "C:TestDB.DB"); sl@0: _LIT(KTblNameA, "A"); sl@0: _LIT(KTblNameB, "B"); sl@0: _LIT(KTblNameC, "C"); sl@0: _LIT(KDbDirNSC, "C:\\DBMS-TST\\"); sl@0: _LIT(KDbNameNSC,"C:\\DBMS-TST\\TestDB.DB"); sl@0: sl@0: static void DeleteNsDb() sl@0: { sl@0: RFs fileSess; sl@0: if(fileSess.Connect() == KErrNone) sl@0: { sl@0: fileSess.Delete(KDbNameNSC); sl@0: } sl@0: fileSess.Close(); sl@0: } sl@0: sl@0: static void CleanupTest() sl@0: { sl@0: ::DeleteNsDb(); sl@0: } sl@0: sl@0: TDBSCUtils TheDbscUtils(TheTest, &CleanupTest); sl@0: sl@0: const TInt KGetPolicyCallCnt = 10000; sl@0: const TInt KInsertRecCnt = 10000; sl@0: sl@0: //Measures the performance of RDbs::GetDatabasePolicy() and RDbs::GetTablePolicy() calls. sl@0: //The DBMS server session kept alive during the test. sl@0: static void GetPolicyTest1() sl@0: { sl@0: TUint time = User::TickCount(); sl@0: RDbs::TPolicyType tblPolicyType[2] = {RDbs::EReadPolicy, RDbs::EWritePolicy}; sl@0: TSecurityPolicy dbPolicy; sl@0: TSecurityPolicy tblPolicy; sl@0: TInt i, k; sl@0: for(i=0,k=0;i format; sl@0: format.Copy(KSecure); sl@0: format.Append(KSecureDbUid.Name()); sl@0: sl@0: CleanupClosePushL(TheDb); sl@0: TInt err = TheDb.Open(TheDbs, KDbNameC, format); sl@0: TEST2(err, KErrNone); sl@0: sl@0: RDbTable tblA; sl@0: CleanupClosePushL(tblA); sl@0: err = tblA.Open(TheDb, KTblNameA); sl@0: TEST2(err, KErrNone); sl@0: sl@0: ::DoInsertRecL(TheDb, tblA); sl@0: sl@0: CleanupStack::PopAndDestroy(&tblA); sl@0: CleanupStack::PopAndDestroy(&TheDb); sl@0: } sl@0: sl@0: //Measures the performance of "Update" SQL operations in a non-secure database. sl@0: static void UpdateRec1L() sl@0: { sl@0: RDbNamedDatabase db; sl@0: CleanupClosePushL(db); sl@0: TInt err = db.Open(TheDbs, KDbNameNSC); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TUint time = User::TickCount(); sl@0: sl@0: err = db.Begin(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TInt cnt = db.Execute(_L("UPDATE A SET DATA1=10, DATA2=20 WHERE ID >= 0")); sl@0: TEST(cnt > 0); sl@0: sl@0: err = db.Commit(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: time = User::TickCount() - time; sl@0: TheTest.Printf(_L("Update. Time=%d\r\n"), time); sl@0: sl@0: CleanupStack::PopAndDestroy(&db); sl@0: } sl@0: sl@0: //Measures the performance of "Update" SQL operations in a secure shared database. sl@0: static void UpdateRec2L() sl@0: { sl@0: TBuf<32> format; sl@0: format.Copy(KSecure); sl@0: format.Append(KSecureDbUid.Name()); sl@0: sl@0: CleanupClosePushL(TheDb); sl@0: TInt err = TheDb.Open(TheDbs, KDbNameC, format); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TUint time = User::TickCount(); sl@0: sl@0: err = TheDb.Begin(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TInt cnt = TheDb.Execute(_L("UPDATE A SET DATA1=10, DATA2=20 WHERE ID >= 0")); sl@0: TEST(cnt > 0); sl@0: sl@0: err = TheDb.Commit(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: time = User::TickCount() - time; sl@0: TheTest.Printf(_L("Update. Time=%d\r\n"), time); sl@0: sl@0: CleanupStack::PopAndDestroy(&TheDb); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-DBMS-CT-0020 sl@0: @SYMTestCaseDesc DBMS security - performance tests. Insert/Update and GetPolicy sl@0: operations performance measured for non-secure and secure shared database. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RDbs::GetDatabasePolicy(), Rdbs::GetTablePolicy() and RDbs::GetTablePolicies() sl@0: calls measured. sl@0: RDBTable: insert operation measured, SQL: update operation measured. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ2429 sl@0: DBMS shall provide an API to apply security policies to database tables. sl@0: */ sl@0: static void DoRunL() sl@0: { sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0020 GetPolicy performance test ")); sl@0: ::GetPolicyTest1(); sl@0: ::GetPolicyTest2(); sl@0: ::GetPolicyTest3(); sl@0: sl@0: ::CreateNonsecureDbL(); sl@0: sl@0: TheTest.Next(_L("Insert records performance test")); sl@0: InsertRec1L(); sl@0: InsertRec2L(); sl@0: sl@0: TheTest.Next(_L("Update records performance test")); sl@0: ::UpdateRec1L(); sl@0: ::UpdateRec2L(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: TEST(tc != NULL); sl@0: sl@0: TInt err = TheDbs.Connect(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: ::DeleteNsDb(); sl@0: sl@0: TRAP(err, ::DoRunL()); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheDb.Close(); sl@0: TheDbs.Close(); sl@0: ::CleanupTest(); sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: delete tc; sl@0: sl@0: __UHEAP_MARKEND; sl@0: User::Heap().Check(); sl@0: return KErrNone; sl@0: }