|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Secure shared databases failures test |
|
15 // |
|
16 // |
|
17 |
|
18 #include <d32dbms.h> |
|
19 #include <s32file.h> |
|
20 #include <e32test.h> |
|
21 #include "t_dbfail.h" |
|
22 |
|
23 LOCAL_D TBuf<64> TheFormat2; |
|
24 _LIT(KTestDatabase2,"C:t_fail.db"); |
|
25 _LIT(KTestDatabase3,"C:t_fail2.db"); |
|
26 const TUid KPolicyUid = {0x11335579}; |
|
27 |
|
28 GLDEF_C void PrepareDbFmtString() |
|
29 { |
|
30 TheFormat2.Copy(_L("SECURE")); |
|
31 TheFormat2.Append(KPolicyUid.Name()); |
|
32 } |
|
33 |
|
34 LOCAL_C void DbCreate2L() |
|
35 { |
|
36 User::LeaveIfError(TheDatabase.Create(TheDbs, KTestDatabase2, TheFormat2)); |
|
37 RDebug::Print(_L("Secure shared database created.\n")); |
|
38 } |
|
39 |
|
40 LOCAL_C void DbDatabaseNamesL() |
|
41 { |
|
42 CDbDatabaseNames* dbNames = TheDbs.DatabaseNamesL(EDriveC, KPolicyUid); |
|
43 test(dbNames != NULL); |
|
44 TInt cnt = dbNames->Count(); |
|
45 TInt i; |
|
46 for(i=0;i<cnt;++i) |
|
47 { |
|
48 const TDesC& name = (*dbNames)[i]; |
|
49 RDebug::Print(_L("%02d. %S\n"), i + 1, &name); |
|
50 } |
|
51 delete dbNames; |
|
52 RDebug::Print(_L("Secure shared database - DatabaseNamesL().\n")); |
|
53 } |
|
54 |
|
55 LOCAL_C void DbCopyDatabaseL() |
|
56 { |
|
57 User::LeaveIfError(TheDbs.CopyDatabase(KTestDatabase2, KTestDatabase3, KPolicyUid)); |
|
58 RDebug::Print(_L("Secure shared database - CopyDatabase().\n")); |
|
59 } |
|
60 |
|
61 LOCAL_C void DbDeleteDatabaseL() |
|
62 { |
|
63 User::LeaveIfError(TheDbs.DeleteDatabase(KTestDatabase2, KPolicyUid)); |
|
64 RDebug::Print(_L("Secure shared database - DeleteDatabase().\n")); |
|
65 } |
|
66 |
|
67 LOCAL_C void DbOpen2L() |
|
68 { |
|
69 User::LeaveIfError(TheDatabase.Open(TheDbs, KTestDatabase2, TheFormat2)); |
|
70 CleanupClosePushL(TheDatabase); |
|
71 delete TheDatabase.TableNamesL(); // force a schema load |
|
72 CleanupStack::Pop(); |
|
73 RDebug::Print(_L("Secure shared database - Open().\n")); |
|
74 } |
|
75 |
|
76 GLDEF_C void TestOpen2() |
|
77 { |
|
78 _LIT(KFileNotFound2, "C:not a database"); |
|
79 Connect(); |
|
80 TInt r=TheDatabase.Open(TheDbs, KFileNotFound2, TheFormat2); |
|
81 Disconnect(); |
|
82 test (r==KErrPathNotFound || r==KErrNotFound);//There is no secure shared database with name KFileNotFound2 |
|
83 // |
|
84 _LIT(KPathNotFound2, "Z:ddd.db"); |
|
85 Connect(); |
|
86 r=TheDatabase.Open(TheDbs, KPathNotFound2, TheFormat2); |
|
87 Disconnect(); |
|
88 test (r==KErrPathNotFound || r==KErrNotFound);//There is no secure shared database with name KPathNotFound2 |
|
89 // |
|
90 _LIT(KDbName, "C:dddqweuqwe.db"); |
|
91 _LIT(KDbInvalidFmt, "SECURE"); |
|
92 Connect(); |
|
93 r=TheDatabase.Open(TheDbs, KDbName, KDbInvalidFmt); |
|
94 Disconnect(); |
|
95 test (r==KErrArgument);//The format string is invalid, if there is "SECURE" keyword, then a uid has to follw it. |
|
96 // |
|
97 _LIT(KSecureSharedDbName, "C:xfgbdrgui.db"); |
|
98 _LIT(KDbNonSecureValidFmt, "[123456768]"); |
|
99 Connect(); |
|
100 r=TheDatabase.Open(TheDbs, KSecureSharedDbName, KDbNonSecureValidFmt); |
|
101 Disconnect(); |
|
102 test (r==KErrNotFound);//Non-secure, non-existent database |
|
103 } |
|
104 |
|
105 class TFailCreateDatabase2 : public TFail |
|
106 { |
|
107 void RunL() |
|
108 { |
|
109 DbCreate2L(); |
|
110 } |
|
111 void End() |
|
112 { |
|
113 TheDatabase.Close(); |
|
114 (void)TheDbs.DeleteDatabase(KTestDatabase2, KPolicyUid); |
|
115 } |
|
116 }; |
|
117 |
|
118 class TFailOpenDatabase2 : public TFail |
|
119 { |
|
120 void RunL() |
|
121 { |
|
122 DbOpen2L(); |
|
123 } |
|
124 void End() |
|
125 { |
|
126 TheDatabase.Close(); |
|
127 } |
|
128 }; |
|
129 |
|
130 class TFailDatabaseNames : public TFail |
|
131 { |
|
132 void RunL() |
|
133 { |
|
134 DbDatabaseNamesL(); |
|
135 } |
|
136 void End() |
|
137 { |
|
138 } |
|
139 }; |
|
140 |
|
141 class TFailCopyDatabase : public TFail |
|
142 { |
|
143 void RunL() |
|
144 { |
|
145 DbCopyDatabaseL(); |
|
146 } |
|
147 void End() |
|
148 { |
|
149 (void)TheDbs.DeleteDatabase(KTestDatabase3, KPolicyUid); |
|
150 } |
|
151 }; |
|
152 |
|
153 class TFailDeleteDatabase : public TFail |
|
154 { |
|
155 void RunL() |
|
156 { |
|
157 DbDeleteDatabaseL(); |
|
158 } |
|
159 void End() |
|
160 { |
|
161 } |
|
162 }; |
|
163 |
|
164 /** |
|
165 @SYMTestCaseID SYSLIB-DBMS-CT-0022 |
|
166 @SYMTestCaseDesc OOM test for the new "DBMS security" APIs. |
|
167 @SYMTestPriority High |
|
168 @SYMTestActions Calling the new "DBMS security" APIs under OOM conditions. |
|
169 @SYMTestExpectedResults The test must not fail. |
|
170 @SYMREQ REQ2429 |
|
171 DBMS shall provide an API to apply security policies to database tables. |
|
172 */ |
|
173 GLDEF_C void Origins2() |
|
174 { |
|
175 Connect(); |
|
176 (void)TheDbs.DeleteDatabase(KTestDatabase2, KPolicyUid); |
|
177 Disconnect(); |
|
178 |
|
179 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0022 Allocation failures on creating a secure shared database ")); |
|
180 TFailCreateDatabase2 t1; |
|
181 Connect(); |
|
182 (void)TheDbs.DeleteDatabase(KTestDatabase2, KPolicyUid); |
|
183 t1.Test(KClientHeap); |
|
184 t1.Test(KServerHeap); |
|
185 Disconnect(); |
|
186 |
|
187 Connect(); |
|
188 test(TheDatabase.Create(TheDbs, KTestDatabase2, TheFormat2) == KErrNone); |
|
189 (void)TheDatabase.Close(); |
|
190 Disconnect(); |
|
191 |
|
192 Connect(); |
|
193 |
|
194 test.Next(_L("Allocation failures on opening a secure shared database")); |
|
195 TFailOpenDatabase2 t2; |
|
196 t2.Test(KClientHeap); |
|
197 t2.Test(KServerHeap); |
|
198 |
|
199 test.Next(_L("Allocation failures on getting secure shared databases list")); |
|
200 TFailDatabaseNames t_dbNames; |
|
201 t_dbNames.Test(KClientHeap); |
|
202 t_dbNames.Test(KServerHeap); |
|
203 TheDatabase.Close(); |
|
204 |
|
205 test.Next(_L("Allocation failures on copying secure shared databases")); |
|
206 TFailCopyDatabase t_copyDb; |
|
207 t_copyDb.Test(KClientHeap); |
|
208 t_copyDb.Test(KServerHeap); |
|
209 |
|
210 test.Next(_L("Allocation failures on deleting secure shared databases")); |
|
211 TFailDeleteDatabase t_deleteDb; |
|
212 t_deleteDb.Test(KClientHeap); |
|
213 test(TheDatabase.Create(TheDbs, KTestDatabase2, TheFormat2) == KErrNone); |
|
214 (void)TheDatabase.Close(); |
|
215 t_deleteDb.Test(KServerHeap); |
|
216 |
|
217 Disconnect(); |
|
218 |
|
219 test.End(); |
|
220 } |
|
221 |