|
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 // DBMS security policy - testing new APIs - table level. |
|
15 // All tests assume that drive C is presented in the system and is not a ROM drive. |
|
16 // |
|
17 // |
|
18 |
|
19 #include "t_dbplatsecutl.h" |
|
20 #include "t_dbplatsecdef.h" |
|
21 #include "t_dbplatsectbl.h" |
|
22 |
|
23 static TColDef const KColumns[]= |
|
24 { |
|
25 {_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement}, |
|
26 {_S("DATA1"), EDbColInt32, TDbCol::ENotNull}, |
|
27 {_S("DATA2"), EDbColInt32, TDbCol::ENotNull}, |
|
28 {0} |
|
29 }; |
|
30 |
|
31 static TColDef const KColumns2[]= |
|
32 { |
|
33 {_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement}, |
|
34 {_S("DATA1"), EDbColLongBinary}, |
|
35 {0} |
|
36 }; |
|
37 |
|
38 static void TblCallTestL() |
|
39 { |
|
40 TheTest.Next(_L("Open()")); |
|
41 TInt err = TheTbl1.Open(TheDb1, KTableName1); |
|
42 TEST2(err, KErrNone); |
|
43 |
|
44 TheTest.Next(_L("ColSetL()")); |
|
45 CDbColSet* colset = TheTbl1.ColSetL(); |
|
46 TInt cnt = colset->Count(); |
|
47 TInt i; |
|
48 for(i=0;i<cnt;++i) |
|
49 { |
|
50 const TDbCol& dbc = (*colset)[i + 1]; |
|
51 TheTest.Printf(_L("%02d, %S\n"), i + 1, &dbc.iName); |
|
52 } |
|
53 delete colset; |
|
54 |
|
55 TheTest.Next(_L("ColDef()")); |
|
56 TDbCol dbcol = TheTbl1.ColDef(1); |
|
57 TheTest.Printf(_L("%S\n"), &dbcol.iName); |
|
58 |
|
59 TheTest.Next(_L("InsertL()/SetColL()/PutL()")); |
|
60 TheTbl1.InsertL(); |
|
61 TheTbl1.SetColL(2, 1); |
|
62 TheTbl1.SetColL(3, 2); |
|
63 TheTbl1.PutL(); |
|
64 TheTbl1.InsertL(); |
|
65 TheTbl1.SetColL(2, 3); |
|
66 TheTbl1.SetColL(3, 4); |
|
67 TheTbl1.PutL(); |
|
68 |
|
69 TheTest.Next(_L("AtRow()/AtBeginning()/AtEnd()")); |
|
70 (void)TheTbl1.AtRow(); |
|
71 (void)TheTbl1.AtBeginning(); |
|
72 (void)TheTbl1.AtEnd(); |
|
73 |
|
74 TheTest.Next(_L("BeginningL()/EndL()")); |
|
75 TheTbl1.BeginningL(); |
|
76 TheTbl1.EndL(); |
|
77 |
|
78 TheTest.Next(_L("FirstL()/LastL()/PreviousL()/PreviousL()")); |
|
79 TBool res = TheTbl1.FirstL(); |
|
80 TEST(res); |
|
81 TheTbl1.GetL(); |
|
82 TInt32 val1 = TheTbl1.ColInt32(1); |
|
83 TInt32 val2 = TheTbl1.ColInt32(2); |
|
84 TInt32 val3 = TheTbl1.ColInt32(3); |
|
85 TEST(val1 == 0); |
|
86 TEST(val2 == 1); |
|
87 TEST(val3 == 2); |
|
88 |
|
89 res = TheTbl1.LastL(); |
|
90 TEST(res); |
|
91 TheTbl1.GetL(); |
|
92 val1 = TheTbl1.ColInt32(1); |
|
93 val2 = TheTbl1.ColInt32(2); |
|
94 val3 = TheTbl1.ColInt32(3); |
|
95 TEST(val1 == 1); |
|
96 TEST(val2 == 3); |
|
97 TEST(val3 == 4); |
|
98 |
|
99 res = TheTbl1.PreviousL(); |
|
100 TEST(res); |
|
101 TheTbl1.GetL(); |
|
102 val1 = TheTbl1.ColInt32(1); |
|
103 val2 = TheTbl1.ColInt32(2); |
|
104 val3 = TheTbl1.ColInt32(3); |
|
105 TEST(val1 == 0); |
|
106 TEST(val2 == 1); |
|
107 TEST(val3 == 2); |
|
108 |
|
109 res = TheTbl1.NextL(); |
|
110 TEST(res); |
|
111 TheTbl1.GetL(); |
|
112 val1 = TheTbl1.ColInt32(1); |
|
113 val2 = TheTbl1.ColInt32(2); |
|
114 val3 = TheTbl1.ColInt32(3); |
|
115 TEST(val1 == 1); |
|
116 TEST(val2 == 3); |
|
117 TEST(val3 == 4); |
|
118 |
|
119 TheTest.Next(_L("UpdateL()")); |
|
120 TheTbl1.UpdateL(); |
|
121 TheTbl1.SetColL(2, 33); |
|
122 TheTbl1.SetColL(3, 44); |
|
123 TheTbl1.PutL(); |
|
124 |
|
125 TheTest.Next(_L("Cancel()")); |
|
126 TheTbl1.UpdateL(); |
|
127 TheTbl1.SetColL(2, 36); |
|
128 TheTbl1.SetColL(3, 47); |
|
129 TheTbl1.Cancel(); |
|
130 |
|
131 TheTest.Next(_L("DeleteL()")); |
|
132 TheTbl1.DeleteL(); |
|
133 |
|
134 TheTest.Next(_L("IsColNull()")); |
|
135 CDbColSet* colset2 = TDBSCUtils::CreateColSetLC(KColumns2); |
|
136 _LIT(KTempTblName, "TempTbl"); |
|
137 err = TheDb1.CreateTable(KTempTblName, *colset2); |
|
138 TEST2(err, KErrNone); |
|
139 CleanupStack::PopAndDestroy(colset2); |
|
140 |
|
141 err = TheTbl2.Open(TheDb1, KTempTblName); |
|
142 TEST2(err, KErrNone); |
|
143 |
|
144 TheTbl2.InsertL(); |
|
145 _LIT8(KTestData, ""); |
|
146 TheTbl2.SetColL(2, KTestData); |
|
147 TheTbl2.PutL(); |
|
148 |
|
149 TheTbl2.Close(); |
|
150 err = TheTbl2.Open(TheDb1, KTempTblName); |
|
151 TEST2(err, KErrNone); |
|
152 res = TheTbl2.FirstL(); |
|
153 TEST(res); |
|
154 TheTbl2.GetL(); |
|
155 res = TheTbl2.IsColNull(2); |
|
156 TEST(res); |
|
157 TheTbl2.Close(); |
|
158 |
|
159 TheTest.Next(_L("ColSize()")); |
|
160 res = TheTbl1.FirstL(); |
|
161 TEST(res); |
|
162 TheTbl1.GetL(); |
|
163 res = TheTbl1.ColSize(1); |
|
164 TEST(res); |
|
165 |
|
166 TheTest.Next(_L("ColLength()")); |
|
167 TInt len = TheTbl1.ColLength(1); |
|
168 TEST(len > 0); |
|
169 |
|
170 TheTbl1.InsertL(); |
|
171 TheTbl1.SetColL(2, 3); |
|
172 TheTbl1.SetColL(3, 4); |
|
173 TheTbl1.PutL(); |
|
174 |
|
175 TheTest.Next(_L("GotoL(TPosition)")); |
|
176 res = TheTbl1.GotoL(RDbRowSet::EFirst); |
|
177 TEST(res); |
|
178 |
|
179 TheTest.Next(_L("Bookmark()/GotoL(TDbBookmark)")); |
|
180 TDbBookmark bkmk = TheTbl1.Bookmark(); |
|
181 res = TheTbl1.NextL(); |
|
182 TEST(res); |
|
183 TheTbl1.GotoL(bkmk); |
|
184 TheTbl1.GetL(); |
|
185 val1 = TheTbl1.ColInt32(1); |
|
186 TEST(val1 == 0); |
|
187 |
|
188 TheTest.Next(_L("CountL()/IsEmptyL()")); |
|
189 cnt = TheTbl1.CountL(); |
|
190 TEST(cnt == 2); |
|
191 res = TheTbl1.IsEmptyL(); |
|
192 TEST(!res); |
|
193 |
|
194 TheTest.Next(_L("MatchL()")); |
|
195 RDbRowConstraint match; |
|
196 CleanupClosePushL(match); |
|
197 err = match.Open(TheTbl1, TDbQuery(_L("ID > 0"))); |
|
198 TEST2(err, KErrNone); |
|
199 res = EFalse; |
|
200 TheTbl1.BeginningL(); |
|
201 while(TheTbl1.NextL()) |
|
202 { |
|
203 if(TheTbl1.MatchL(match)) |
|
204 { |
|
205 res = ETrue; |
|
206 } |
|
207 } |
|
208 CleanupStack::PopAndDestroy(&match); |
|
209 TEST(res); |
|
210 |
|
211 TheTest.Next(_L("FindL()")); |
|
212 res = TheTbl1.FirstL(); |
|
213 TEST(res); |
|
214 err = TheTbl1.FindL(RDbRowSet::EForwards, TDbQuery(_L("ID <> 0"))); |
|
215 TEST(err >= 0); |
|
216 TheTbl1.GetL(); |
|
217 val1 = TheTbl1.ColInt32(1); |
|
218 TEST(val1 > 0); |
|
219 |
|
220 _LIT8(KTestData2, "0123456789"); |
|
221 HBufC8* buf = HBufC8::NewLC(10000); |
|
222 TPtr8 ptr = buf->Des(); |
|
223 for(i=0;i<1000;++i) |
|
224 { |
|
225 ptr += KTestData2(); |
|
226 } |
|
227 |
|
228 TheTest.Next(_L("RDbColReadStream")); |
|
229 err = TheTbl2.Open(TheDb1, KTempTblName); |
|
230 TEST2(err, KErrNone); |
|
231 |
|
232 TheTbl2.InsertL(); |
|
233 TheTbl2.SetColL(2, *buf); |
|
234 TheTbl2.PutL(); |
|
235 |
|
236 TheTbl2.InsertL(); |
|
237 TheTbl2.SetColL(2, KTestData2); |
|
238 TheTbl2.PutL(); |
|
239 |
|
240 res = TheTbl2.PreviousL(); |
|
241 TEST(res); |
|
242 TheTbl2.GetL(); |
|
243 RDbColReadStream rstream; |
|
244 rstream.OpenLC(TheTbl2, 2); |
|
245 ptr.Zero(); |
|
246 rstream.ReadL(ptr, ptr.MaxLength()); |
|
247 CleanupStack::PopAndDestroy(&rstream); |
|
248 TEST(ptr.Length() == ptr.MaxLength()); |
|
249 |
|
250 TheTest.Next(_L("RDbColWriteStream")); |
|
251 TheTbl2.InsertL(); |
|
252 RDbColWriteStream wstream; |
|
253 wstream.OpenLC(TheTbl2, 2); |
|
254 wstream.WriteL(ptr, ptr.Length()); |
|
255 wstream.CommitL(); |
|
256 CleanupStack::PopAndDestroy(&wstream); |
|
257 TheTbl2.PutL(); |
|
258 |
|
259 TheTbl2.Close(); |
|
260 CleanupStack::PopAndDestroy(buf); |
|
261 |
|
262 TheTbl1.Close(); |
|
263 } |
|
264 |
|
265 static void ViewTestL() |
|
266 { |
|
267 RDbView view; |
|
268 CleanupClosePushL(view); |
|
269 |
|
270 TheTest.Next(_L("Prepare()")); |
|
271 TInt err = view.Prepare(TheDb1, TDbQuery(_L("SELECT * FROM ATbl"))); |
|
272 TEST2(err, KErrNone); |
|
273 |
|
274 TheTest.Next(_L("Update()")); |
|
275 TBool res = view.FirstL(); |
|
276 TEST(res); |
|
277 view.GetL(); |
|
278 view.UpdateL(); |
|
279 view.SetColL(2, 100); |
|
280 view.SetColL(3, 200); |
|
281 view.PutL(); |
|
282 |
|
283 CleanupStack::PopAndDestroy(&view); |
|
284 |
|
285 TheTest.Next(_L("Prepare() with an update sql")); |
|
286 CleanupClosePushL(view); |
|
287 err = view.Prepare(TheDb1, TDbQuery(_L("UPDATE ATbl SET DATA1 = 400 WHERE ID = 0"))); |
|
288 TEST2(err, KErrArgument); |
|
289 CleanupStack::PopAndDestroy(&view); |
|
290 } |
|
291 |
|
292 /** |
|
293 @SYMTestCaseID SYSLIB-DBMS-CT-0021 |
|
294 @SYMTestCaseDesc RDbTable method calls test for a secure shared database. |
|
295 Every method of RDbTable class and its base class too, is called |
|
296 and the result - asserted. |
|
297 @SYMTestPriority High |
|
298 @SYMTestActions RDbTable method calls test. |
|
299 @SYMTestExpectedResults The test must not fail. |
|
300 @SYMREQ REQ2429 |
|
301 DBMS shall provide an API to apply security policies to database tables. |
|
302 */ |
|
303 void DoTblTestL() |
|
304 { |
|
305 TheTest.Next(_L(" @SYMTestCaseID SYSLIB-DBMS-CT-0021 ")); |
|
306 |
|
307 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name); |
|
308 |
|
309 TheDb1.Close(); |
|
310 TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name); |
|
311 |
|
312 CDbColSet* colset = TDBSCUtils::CreateColSetLC(KColumns); |
|
313 TInt err = TheDb1.CreateTable(KTableName1, *colset); |
|
314 TEST2(err, KErrNone); |
|
315 CleanupStack::PopAndDestroy(colset); |
|
316 |
|
317 TheTest.Next(_L("Table calls test")); |
|
318 ::TblCallTestL(); |
|
319 |
|
320 TheTest.Next(_L("View test")); |
|
321 ::ViewTestL(); |
|
322 |
|
323 TheDb1.Close(); |
|
324 } |