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 - testing new APIs - table level. sl@0: // All tests assume that drive C is presented in the system and is not a ROM drive. sl@0: // sl@0: // sl@0: sl@0: #include "t_dbplatsecutl.h" sl@0: #include "t_dbplatsecdef.h" sl@0: #include "t_dbplatsectbl.h" sl@0: sl@0: static TColDef const KColumns[]= sl@0: { sl@0: {_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement}, sl@0: {_S("DATA1"), EDbColInt32, TDbCol::ENotNull}, sl@0: {_S("DATA2"), EDbColInt32, TDbCol::ENotNull}, sl@0: {0} sl@0: }; sl@0: sl@0: static TColDef const KColumns2[]= sl@0: { sl@0: {_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement}, sl@0: {_S("DATA1"), EDbColLongBinary}, sl@0: {0} sl@0: }; sl@0: sl@0: static void TblCallTestL() sl@0: { sl@0: TheTest.Next(_L("Open()")); sl@0: TInt err = TheTbl1.Open(TheDb1, KTableName1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Next(_L("ColSetL()")); sl@0: CDbColSet* colset = TheTbl1.ColSetL(); sl@0: TInt cnt = colset->Count(); sl@0: TInt i; sl@0: for(i=0;i 0); sl@0: sl@0: TheTbl1.InsertL(); sl@0: TheTbl1.SetColL(2, 3); sl@0: TheTbl1.SetColL(3, 4); sl@0: TheTbl1.PutL(); sl@0: sl@0: TheTest.Next(_L("GotoL(TPosition)")); sl@0: res = TheTbl1.GotoL(RDbRowSet::EFirst); sl@0: TEST(res); sl@0: sl@0: TheTest.Next(_L("Bookmark()/GotoL(TDbBookmark)")); sl@0: TDbBookmark bkmk = TheTbl1.Bookmark(); sl@0: res = TheTbl1.NextL(); sl@0: TEST(res); sl@0: TheTbl1.GotoL(bkmk); sl@0: TheTbl1.GetL(); sl@0: val1 = TheTbl1.ColInt32(1); sl@0: TEST(val1 == 0); sl@0: sl@0: TheTest.Next(_L("CountL()/IsEmptyL()")); sl@0: cnt = TheTbl1.CountL(); sl@0: TEST(cnt == 2); sl@0: res = TheTbl1.IsEmptyL(); sl@0: TEST(!res); sl@0: sl@0: TheTest.Next(_L("MatchL()")); sl@0: RDbRowConstraint match; sl@0: CleanupClosePushL(match); sl@0: err = match.Open(TheTbl1, TDbQuery(_L("ID > 0"))); sl@0: TEST2(err, KErrNone); sl@0: res = EFalse; sl@0: TheTbl1.BeginningL(); sl@0: while(TheTbl1.NextL()) sl@0: { sl@0: if(TheTbl1.MatchL(match)) sl@0: { sl@0: res = ETrue; sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(&match); sl@0: TEST(res); sl@0: sl@0: TheTest.Next(_L("FindL()")); sl@0: res = TheTbl1.FirstL(); sl@0: TEST(res); sl@0: err = TheTbl1.FindL(RDbRowSet::EForwards, TDbQuery(_L("ID <> 0"))); sl@0: TEST(err >= 0); sl@0: TheTbl1.GetL(); sl@0: val1 = TheTbl1.ColInt32(1); sl@0: TEST(val1 > 0); sl@0: sl@0: _LIT8(KTestData2, "0123456789"); sl@0: HBufC8* buf = HBufC8::NewLC(10000); sl@0: TPtr8 ptr = buf->Des(); sl@0: for(i=0;i<1000;++i) sl@0: { sl@0: ptr += KTestData2(); sl@0: } sl@0: sl@0: TheTest.Next(_L("RDbColReadStream")); sl@0: err = TheTbl2.Open(TheDb1, KTempTblName); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTbl2.InsertL(); sl@0: TheTbl2.SetColL(2, *buf); sl@0: TheTbl2.PutL(); sl@0: sl@0: TheTbl2.InsertL(); sl@0: TheTbl2.SetColL(2, KTestData2); sl@0: TheTbl2.PutL(); sl@0: sl@0: res = TheTbl2.PreviousL(); sl@0: TEST(res); sl@0: TheTbl2.GetL(); sl@0: RDbColReadStream rstream; sl@0: rstream.OpenLC(TheTbl2, 2); sl@0: ptr.Zero(); sl@0: rstream.ReadL(ptr, ptr.MaxLength()); sl@0: CleanupStack::PopAndDestroy(&rstream); sl@0: TEST(ptr.Length() == ptr.MaxLength()); sl@0: sl@0: TheTest.Next(_L("RDbColWriteStream")); sl@0: TheTbl2.InsertL(); sl@0: RDbColWriteStream wstream; sl@0: wstream.OpenLC(TheTbl2, 2); sl@0: wstream.WriteL(ptr, ptr.Length()); sl@0: wstream.CommitL(); sl@0: CleanupStack::PopAndDestroy(&wstream); sl@0: TheTbl2.PutL(); sl@0: sl@0: TheTbl2.Close(); sl@0: CleanupStack::PopAndDestroy(buf); sl@0: sl@0: TheTbl1.Close(); sl@0: } sl@0: sl@0: static void ViewTestL() sl@0: { sl@0: RDbView view; sl@0: CleanupClosePushL(view); sl@0: sl@0: TheTest.Next(_L("Prepare()")); sl@0: TInt err = view.Prepare(TheDb1, TDbQuery(_L("SELECT * FROM ATbl"))); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Next(_L("Update()")); sl@0: TBool res = view.FirstL(); sl@0: TEST(res); sl@0: view.GetL(); sl@0: view.UpdateL(); sl@0: view.SetColL(2, 100); sl@0: view.SetColL(3, 200); sl@0: view.PutL(); sl@0: sl@0: CleanupStack::PopAndDestroy(&view); sl@0: sl@0: TheTest.Next(_L("Prepare() with an update sql")); sl@0: CleanupClosePushL(view); sl@0: err = view.Prepare(TheDb1, TDbQuery(_L("UPDATE ATbl SET DATA1 = 400 WHERE ID = 0"))); sl@0: TEST2(err, KErrArgument); sl@0: CleanupStack::PopAndDestroy(&view); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-DBMS-CT-0021 sl@0: @SYMTestCaseDesc RDbTable method calls test for a secure shared database. sl@0: Every method of RDbTable class and its base class too, is called sl@0: and the result - asserted. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RDbTable method calls test. 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: void DoTblTestL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID SYSLIB-DBMS-CT-0021 ")); sl@0: sl@0: TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name); sl@0: sl@0: TheDb1.Close(); sl@0: TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name); sl@0: sl@0: CDbColSet* colset = TDBSCUtils::CreateColSetLC(KColumns); sl@0: TInt err = TheDb1.CreateTable(KTableName1, *colset); sl@0: TEST2(err, KErrNone); sl@0: CleanupStack::PopAndDestroy(colset); sl@0: sl@0: TheTest.Next(_L("Table calls test")); sl@0: ::TblCallTestL(); sl@0: sl@0: TheTest.Next(_L("View test")); sl@0: ::ViewTestL(); sl@0: sl@0: TheDb1.Close(); sl@0: }