Update contrib.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // DBMS security policy - testing new APIs - database level.
15 // All tests assume that drive C is presented in the system and is not a ROM drive.
19 #include "t_dbplatsecutl.h"
20 #include "t_dbplatsecdef.h"
21 #include "t_dbplatsecdb.h"
23 static TColDef const KColumns[]=
25 {_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement},
26 {_S("DATA1"), EDbColInt32, TDbCol::ENotNull},
27 {_S("DATA2"), EDbColInt32, TDbCol::ENotNull},
33 static void OpenTestL()
36 CleanupClosePushL(fileSess);
37 TEST2(fileSess.Connect(), KErrNone);
41 fmt.Append(KSecureDbUid.Name());
43 TheTest.Printf(_L("Open secure shared database\n"));
44 TInt err = TheDb1.Open(TheDbs, KDb1Name, fmt);
49 TheTest.Printf(_L("An attempt to open it as a secure shared database - no format string\n"));
50 err = TheDb1.Open(TheDbs, KDb1Name);
52 TEST2(err, KErrNotFound);//Treated as a non-secure, not found database.
54 TheTest.Printf(_L("An attempt to open it as a non-secure shared database\n"));
55 _LIT(KNSDbName, "C:\\PRiVatE\\100012A5\\A.dB");
56 err = TheDb1.Open(TheDbs, KNSDbName);
58 TEST2(err, KErrPermissionDenied);
59 _LIT(KNSDbName2, "C:\\PRiVatE\\100012A5\\DBS_11335577_A.Db");
60 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) &&
61 PlatSec::IsCapabilityEnforced(ECapabilityAllFiles))
63 err = TheDb1.Open(fileSess, KNSDbName2);
65 TEST2(err, KErrPermissionDenied);
67 TheTest.Printf(_L("An attempt to create it as a non-secure shared database\n"));
68 err = TheDb1.Create(fileSess, KNSDbName2);
70 TEST2(err, KErrPermissionDenied);
73 TheTest.Printf(_L("--An attempt to open a database, which security policy cannot be satisfied by the current test application\n"));
75 fmt.Append(KSecureDbUid2.Name());
76 err = TheDb1.Open(TheDbs, KProtDb3CName, fmt);
78 TEST2(err, KErrPermissionDenied);
80 CleanupStack::PopAndDestroy(&fileSess);
83 //RDbDatabase method calls test. All calls have to pass with KErrNone,
84 //because the test application has enough rights to do any R/W/S database operation.
85 static void DbCallTestL()
89 fmt.Append(KSecureDbUid.Name());
91 TheTest.Printf(_L("Open()\n"));
92 TInt err = TheDb1.Open(TheDbs, KDb1Name, fmt);
94 TheTest.Printf(_L("IsDamaged()\n"));
95 TBool res = TheDb1.IsDamaged();
98 TheTest.Printf(_L("Recover()\n"));
99 err = TheDb1.Recover();
100 TEST2(err, KErrNone);
102 TheTest.Printf(_L("UpdateStats()\n"));
103 err = TheDb1.UpdateStats();
104 TEST2(err, KErrNone);
106 TheTest.Printf(_L("Size()\n"));
107 RDbDatabase::TSize size = TheDb1.Size();
109 TheTest.Printf(_L("Compact()\n"));
110 err = TheDb1.Compact();
111 TEST2(err, KErrNone);
114 TheTest.Printf(_L("Begin()/Commit()\n"));
115 err = TheDb1.Begin();
116 TEST2(err, KErrNone);
117 res = TheDb1.InTransaction();
119 err = TheDb1.Commit();
120 TEST2(err, KErrNone);
122 TheTest.Printf(_L("Begin()/Rollback()\n"));
123 err = TheDb1.Begin();
124 TEST2(err, KErrNone);
125 res = TheDb1.InTransaction();
129 TheTest.Printf(_L("CreateTable()\n"));
130 CDbColSet* colset = TDBSCUtils::CreateColSetLC(KColumns);
131 _LIT(KTblName1, "A1");
132 err = TheDb1.CreateTable(KTblName1, *colset);
133 TEST2(err, KErrNone);
134 _LIT(KTblName2, "A2");
135 err = TheDb1.CreateTable(KTblName2, *colset);
136 TEST2(err, KErrNone);
138 TheTest.Printf(_L("DropTable()\n"));
139 err = TheDb1.DropTable(KTblName2);
140 TEST2(err, KErrNone);
142 TheTest.Printf(_L("AlterTable()\n"));
143 err = TheDb1.AlterTable(KTblName1, *colset);
144 TEST2(err, KErrNone);
146 TheTest.Printf(_L("CreateIndex()\n"));
147 CDbKey* key = TDBSCUtils::CreateKeyLC(KCol2);
148 err = TheDb1.CreateIndex(KCol2, KTblName1, *key);
149 TEST2(err, KErrNone);
151 TheTest.Printf(_L("DropIndex()\n"));
152 err = TheDb1.DropIndex(KCol2, KTblName1);
153 TEST2(err, KErrNone);
155 TheTest.Printf(_L("TableNamesL()\n"));
156 _LIT(KTblName3, "DdD");
157 _LIT(KTblName4, "FFf");
158 _LIT(KTblName5, "Ggg");
159 TDBSCUtils::CreateTableL(TheDb1, KTblName3, KColumns);
160 TDBSCUtils::CreateTableL(TheDb1, KTblName4, KColumns);
161 TDBSCUtils::CreateTableL(TheDb1, KTblName5, KColumns);
162 CDbTableNames* tblNames = TheDb1.TableNamesL();
163 TInt cnt = tblNames->Count();
168 const TDesC& name = (*tblNames)[i];
169 TheTest.Printf(_L("%02d, %S\n"), i + 1, &name);
173 TheTest.Printf(_L("ColSetL()\n"));
174 CDbColSet* cs1 = TheDb1.ColSetL(KTblName3);
178 const TDbCol& dbc = (*cs1)[i + 1];
179 TheTest.Printf(_L("%02d, %S\n"), i + 1, &dbc.iName);
183 TheTest.Printf(_L("IndexNamesL()\n"));
184 CDbKey* tblKey1 = TDBSCUtils::CreateKeyLC(KCol2);
185 err = TheDb1.CreateIndex(KCol2, KTblName1, *tblKey1);
186 TEST2(err, KErrNone);
187 CleanupStack::PopAndDestroy(tblKey1);
188 CDbIndexNames* dbiNames = TheDb1.IndexNamesL(KTblName1);
189 cnt = dbiNames->Count();
192 const TDesC& name = (*dbiNames)[i];
193 TheTest.Printf(_L("%02d, %S\n"), i + 1, &name);
197 TheTest.Printf(_L("KeyL()\n"));
198 CDbKey* tblKey2 = TheDb1.KeyL(KCol2, KTblName1);
201 CleanupStack::PopAndDestroy(key);
202 CleanupStack::PopAndDestroy(colset);
206 static void SQLTestL()
208 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
210 TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
212 TheTest.Printf(_L("Create table\n"));
213 TInt err = TheDb1.Execute(_L("crEAte tabLe a (id couNter)"));
214 TEST2(err, KErrNone);
216 TheTest.Printf(_L("Alter table\n"));
217 err = TheDb1.Execute(_L("ALter TablE a aDd DaTA1 CHaR(20)"));
218 TEST2(err, KErrNone);
220 err = TheDb1.Execute(_L("alter table A add DATA2 INTEGER"));
221 TEST2(err, KErrNone);
223 err = TheDb1.Execute(_L("ALTEr tABLe A dROp DaTa1"));
224 TEST2(err, KErrNone);
226 TheTest.Printf(_L("Drop table\n"));
227 err = TheDb1.Execute(_L("DRop tABle a"));
228 TEST2(err, KErrNone);
230 err = TheDb1.Execute(_L("crEAte tabLe a (iD coUNteR)"));
231 TEST2(err, KErrNone);
232 err = TheDb1.Execute(_L("altER taBLe A add daTA2 InteGER"));
233 TEST2(err, KErrNone);
234 err = TheDb1.Execute(_L("creaTE tAblE b (Id counTEr)"));
235 TEST2(err, KErrNone);
236 err = TheDb1.Execute(_L("alter TAbLe B aDd DAtA2 INTEgER"));
237 TEST2(err, KErrNone);
239 TheTest.Printf(_L("Create index\n"));
240 err = TheDb1.Execute(_L("CREAte INdeX idX oN A(dATA2)"));
241 TEST2(err, KErrNone);
243 TheTest.Printf(_L("Drop index\n"));
244 err = TheDb1.Execute(_L("DroP IndEX idx frOm a"));
245 TEST2(err, KErrNone);
247 TheTest.Printf(_L("Insert\n"));
248 TInt cnt = TheDb1.Execute(_L("INSerT IntO A (DATa2) VALuES(45)"));
251 TheTest.Printf(_L("Update\n"));
252 cnt = TheDb1.Execute(_L("UPDATe A SeT DAtA2=56 WheRE iD = 0"));
255 TheTest.Printf(_L("Delete\n"));
256 cnt = TheDb1.Execute(_L("INSErt INtO B (DATA2) VALUES(100)"));
258 cnt = TheDb1.Execute(_L("INSERT INTo b (DATA2) VALUES(200)"));
260 cnt = TheDb1.Execute(_L("delete FROM B where ID = 1"));
266 static void TwoDatabasesTestL()
270 fmt.Append(KSecureDbUid.Name());
272 RDbNamedDatabase db1;
273 TheTest.Printf(_L("Open secure shared database-1\n"));
274 TInt err = db1.Open(TheDbs, KDb1Name, fmt);
275 TEST2(err, KErrNone);
277 RDbNamedDatabase db2;
278 TheTest.Printf(_L("Open secure shared database-2\n"));
279 err = db2.Open(TheDbs, KDb1Name, fmt);
280 TEST2(err, KErrNone);
287 @SYMTestCaseID SYSLIB-DBMS-CT-0019
288 @SYMTestCaseDesc RDbNamedDatabase method calls test for a secure shared database.
289 Every method of RDbNamedDatabase class and its base class too, is called
290 and the result - asserted.
291 @SYMTestPriority High
292 @SYMTestActions RDbNamedDatabase method calls test.
293 @SYMTestExpectedResults The test must not fail.
295 DBMS shall provide an API to apply security policies to database tables.
299 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0019 "));
300 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
301 TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
304 TheTest.Next(_L("Open secure database test"));
307 TheTest.Next(_L("Secure Database calls test"));
310 TheTest.Next(_L("SQL test"));
313 TheTest.Next(_L("Two databases test"));
314 ::TwoDatabasesTestL();