changeset 17 | 55f2396f6d25 |
parent 0 | 08ec8eefde2f |
child 22 | a7ba600cb39d |
15:3eacc0623088 | 17:55f2396f6d25 |
---|---|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
20 #include <sqldb.h> |
20 #include <sqldb.h> |
21 #include "sqlite3.h" |
21 #include "sqlite3.h" |
22 #include "SqliteSymbian.h" |
22 #include "SqliteSymbian.h" |
23 #include "SqlResourceTester.h" |
23 #include "SqlResourceTester.h" |
24 |
24 |
25 //In order to be able to compile the test, the following variables are defined (used inside the OS porting layer, |
|
26 //when _SQLPROFILER macro is defined) |
|
27 #ifdef _SQLPROFILER |
|
28 TInt TheSqlSrvProfilerFileRead = 0; |
|
29 TInt TheSqlSrvProfilerFileWrite = 0; |
|
30 TInt TheSqlSrvProfilerFileSync = 0; |
|
31 TInt TheSqlSrvProfilerFileSetSize = 0; |
|
32 #endif |
|
33 |
|
25 ///////////////////////////////////////////////////////////////////////////////////////////////// |
34 ///////////////////////////////////////////////////////////////////////////////////////////////// |
26 /// This test works only if the whole SQL component is built with SYSLIBS_TEST macro defined! /// |
35 /// This test works only if the whole SQL component is built with SYSLIBS_TEST macro defined! /// |
27 ///////////////////////////////////////////////////////////////////////////////////////////////// |
36 ///////////////////////////////////////////////////////////////////////////////////////////////// |
28 |
37 |
29 RTest TheTest(_L("t_sqldbconfigfile test")); |
38 RTest TheTest(_L("t_sqldbconfigfile test")); |
33 extern TBool IsStatementSupported(const TDesC& aStatementIn, const TDesC& aDbName, TDes& aStatementOut); |
42 extern TBool IsStatementSupported(const TDesC& aStatementIn, const TDesC& aDbName, TDes& aStatementOut); |
34 |
43 |
35 RFs TheFs; |
44 RFs TheFs; |
36 RSqlDatabase TheDb; |
45 RSqlDatabase TheDb; |
37 sqlite3 *TheDbHandle = NULL; |
46 sqlite3 *TheDbHandle = NULL; |
38 |
|
39 _LIT(KTestDir, "c:\\test\\"); |
|
40 _LIT(KSqlSrvName, "sqlsrv.exe"); |
|
41 |
|
42 enum TConfigParamType {EPrmCacheSize, EPrmPageSize, EPrmDbEncoding}; |
|
43 |
|
44 TInt KillProcess(const TDesC& aProcessName); |
|
45 |
47 |
46 _LIT(KCfgDb1, "c:[1111C1C1]a.db"); // shared, secure db |
48 _LIT(KCfgDb1, "c:[1111C1C1]a.db"); // shared, secure db |
47 _LIT(KCfgDb2, "c:[1111C1C1]b.db"); // shared, secure db (no config file for it) |
49 _LIT(KCfgDb2, "c:[1111C1C1]b.db"); // shared, secure db (no config file for it) |
48 _LIT(KCfgDb3, "c:\\private\\1111C1C1\\c.db"); // private, secure db |
50 _LIT(KCfgDb3, "c:\\private\\1111C1C1\\c.db"); // private, secure db |
49 _LIT(KCfgDb4, "c:\\test\\d.db"); // public db |
51 _LIT(KCfgDb4, "c:\\test\\d.db"); // public db |
53 _LIT(KCfgDb3ConfigFileV01Path, "c:\\private\\10281e17\\cfgc.db.01"); // config file v01 for c.db (unsupported) |
55 _LIT(KCfgDb3ConfigFileV01Path, "c:\\private\\10281e17\\cfgc.db.01"); // config file v01 for c.db (unsupported) |
54 _LIT(KCfgDb4ConfigFileV01Path, "c:\\private\\10281e17\\cfgd.db.01"); // config file v01 for d.db (unsupported) |
56 _LIT(KCfgDb4ConfigFileV01Path, "c:\\private\\10281e17\\cfgd.db.01"); // config file v01 for d.db (unsupported) |
55 _LIT(KCfgDb5ConfigFileV01Path, "c:\\private\\10281e17\\cfg[1111C1C1]e.db.01"); // config file v01 for e.db |
57 _LIT(KCfgDb5ConfigFileV01Path, "c:\\private\\10281e17\\cfg[1111C1C1]e.db.01"); // config file v01 for e.db |
56 _LIT(KCfgDb1CorruptConfigFilePath, "c:\\private\\10281e17\\cfg[1111C1C1]a.db.invalidextension"); // invalid config file name syntax |
58 _LIT(KCfgDb1CorruptConfigFilePath, "c:\\private\\10281e17\\cfg[1111C1C1]a.db.invalidextension"); // invalid config file name syntax |
57 |
59 |
58 // config file v01 contents for db1 (also tests that upper and lower case statements are both supported) |
|
59 _LIT8(KCfgDb1ConfigFile01Stmts, "CREATE INDEX idx ON table1(i1);CREATE INDEX idx2 ON table1(i2);INSERT INTO table1 (i1,i2,i3) values(5,8,9);DELETE FROM table1;create index multiidx ON TABLE1(i2,i3)"); |
|
60 // config file v01 contents for db3 (will not be processed as db3 is not a shared, secure db) |
|
61 _LIT8(KCfgDb3ConfigFile01Stmts, "CREATE INDEX idx ON table3(i1)"); |
|
62 // config file v01 contents for db4 (will not be processed as db4 is not a shared, secure db) |
|
63 _LIT8(KCfgDb4ConfigFile01Stmts, "CREATE INDEX idx ON table4(i1)"); |
|
64 // config file v01 contents for db5 (will eventually be processed after db5 itself is created) |
|
65 _LIT8(KCfgDb5ConfigFile01Stmts, "CREATE INDEX idx ON table5(i1);\r\n"); |
|
66 // config file valid contents (used for v02 and others) |
60 // config file valid contents (used for v02 and others) |
67 _LIT8(KCfgConfigFileValidStmt, "CREATE INDEX newIdx ON table1(i3) ;"); |
61 _LIT8(KCfgConfigFileValidStmt, "CREATE INDEX newIdx ON table1(i3) ;"); |
68 // config file v03 empty contents |
62 // config file v03 empty contents |
69 _LIT8(KCfgDb1ConfigFileV03EmptyStmt, ""); |
63 _LIT8(KCfgDb1ConfigFileV03EmptyStmt, ""); |
70 // config file v04 unsupported contents |
64 // config file v04 unsupported contents |
93 //KLongDbName1 is "long" enough to allow "-journal" to be added at the end. |
87 //KLongDbName1 is "long" enough to allow "-journal" to be added at the end. |
94 _LIT(KLongDbName1, "c:[1111C1C1]a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a1234.db"); |
88 _LIT(KLongDbName1, "c:[1111C1C1]a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a1234.db"); |
95 _LIT(KLongCfgName1, "c:\\private\\10281e17\\cfg[1111C1C1]a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a1234.db.01"); |
89 _LIT(KLongCfgName1, "c:\\private\\10281e17\\cfg[1111C1C1]a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a1234.db.01"); |
96 |
90 |
97 _LIT(KSqlSrvPrivatePath, "\\private\\10281e17\\"); |
91 _LIT(KSqlSrvPrivatePath, "\\private\\10281e17\\"); |
98 _LIT(KGetSettingsSql, "SELECT * FROM symbian_settings WHERE Reserved==%d"); |
|
99 _LIT(KResetCollationDllSql, "UPDATE symbian_settings SET CollationDllName='hjagafsff'"); |
92 _LIT(KResetCollationDllSql, "UPDATE symbian_settings SET CollationDllName='hjagafsff'"); |
100 _LIT(KGetCollationDllSql, "SELECT CollationDllName FROM symbian_settings"); |
|
101 |
93 |
102 _LIT(KAttachDb1, "Db1"); |
94 _LIT(KAttachDb1, "Db1"); |
103 _LIT(KAttachDb2, "Db2"); |
95 _LIT(KAttachDb2, "Db2"); |
104 _LIT(KAttachDb5, "Db5"); |
96 _LIT(KAttachDb5, "Db5"); |
105 |
97 |
106 _LIT(KDb1CheckNumRecords, "SELECT * FROM table1"); |
|
107 _LIT(KDb2CheckNumRecords, "SELECT * FROM table2"); |
|
108 _LIT(KDb3CheckNumRecords, "SELECT * FROM table3"); |
|
109 _LIT(KDb4CheckNumRecords, "SELECT * FROM table4"); |
|
110 _LIT(KDb5CheckNumRecords, "SELECT * FROM table5"); |
|
111 _LIT(KDbCheckNumIndices, "SELECT name FROM sqlite_master WHERE type = 'index'"); |
|
112 |
|
113 /////////////////////////////////////////////////////////////////////////////////////// |
98 /////////////////////////////////////////////////////////////////////////////////////// |
114 // Destroy functions |
99 // Destroy functions |
115 |
100 |
116 TInt KillProcess(const TDesC& aProcessName) |
101 void KillSqlServer() |
117 { |
102 { |
103 _LIT(KSqlSrvName, "sqlsrv.exe"); |
|
118 TFullName name; |
104 TFullName name; |
119 //RDebug::Print(_L("Find and kill \"%S\" process.\n"), &aProcessName); |
105 //RDebug::Print(_L("Find and kill \"%S\" process.\n"), &aProcessName); |
120 TBuf<64> pattern(aProcessName); |
106 TBuf<64> pattern(KSqlSrvName); |
121 TInt length = pattern.Length(); |
107 TInt length = pattern.Length(); |
122 pattern += _L("*"); |
108 pattern += _L("*"); |
123 TFindProcess procFinder(pattern); |
109 TFindProcess procFinder(pattern); |
124 |
110 |
125 while (procFinder.Next(name) == KErrNone) |
111 while (procFinder.Next(name) == KErrNone) |
143 proc.Kill(0); |
129 proc.Kill(0); |
144 //RDebug::Print(_L("\"%S\" process killed.\n"), &name); |
130 //RDebug::Print(_L("\"%S\" process killed.\n"), &name); |
145 } |
131 } |
146 proc.Close(); |
132 proc.Close(); |
147 } |
133 } |
148 return KErrNone; |
|
149 } |
134 } |
150 |
135 |
151 void DeleteCfgFilesAndDbs() |
136 void DeleteCfgFilesAndDbs() |
152 { |
137 { |
153 (void)RSqlDatabase::Delete(KLongDbName1); |
138 (void)RSqlDatabase::Delete(KLongDbName1); |
175 { |
160 { |
176 sqlite3_close(TheDbHandle); |
161 sqlite3_close(TheDbHandle); |
177 TheDbHandle = NULL; |
162 TheDbHandle = NULL; |
178 } |
163 } |
179 TheDb.Close(); |
164 TheDb.Close(); |
180 (void)KillProcess(KSqlSrvName); |
165 KillSqlServer(); |
181 DeleteCfgFilesAndDbs(); |
166 DeleteCfgFilesAndDbs(); |
182 TheFs.Close(); |
167 TheFs.Close(); |
183 } |
168 } |
184 |
169 |
185 /////////////////////////////////////////////////////////////////////////////////////// |
170 /////////////////////////////////////////////////////////////////////////////////////// |
221 TInt endHandleCount1; |
206 TInt endHandleCount1; |
222 TInt endHandleCount2; |
207 TInt endHandleCount2; |
223 |
208 |
224 RThread().HandleCount(endHandleCount1, endHandleCount2); |
209 RThread().HandleCount(endHandleCount1, endHandleCount2); |
225 |
210 |
226 TEST(TheHandleCount1 == endHandleCount1); |
211 TEST2(TheHandleCount1, endHandleCount1); |
227 TEST(TheHandleCount2 == endHandleCount2); |
212 TEST2(TheHandleCount2, endHandleCount2); |
228 } |
213 } |
229 |
214 |
230 void MarkAllocatedCells() |
215 void MarkAllocatedCells() |
231 { |
216 { |
232 TheAllocatedCellsCount = User::CountAllocCells(); |
217 TheAllocatedCellsCount = User::CountAllocCells(); |
233 } |
218 } |
234 |
219 |
235 void CheckAllocatedCells() |
220 void CheckAllocatedCells() |
236 { |
221 { |
237 TInt allocatedCellsCount = User::CountAllocCells(); |
222 TInt allocatedCellsCount = User::CountAllocCells(); |
238 TEST(allocatedCellsCount == TheAllocatedCellsCount); |
223 TEST2(allocatedCellsCount, TheAllocatedCellsCount); |
239 } |
224 } |
240 |
225 |
241 /////////////////////////////////////////////////////////////////////////////////////// |
226 /////////////////////////////////////////////////////////////////////////////////////// |
242 // Set up functions |
227 // Set up functions |
243 |
228 |
244 TInt DoCreateSecurityPolicy(RSqlSecurityPolicy& securityPolicy) |
229 RSqlSecurityPolicy CreateSecurityPolicy() |
245 { |
230 { |
246 const TSecurityPolicy KDefaultPolicy(TSecurityPolicy::EAlwaysPass); |
231 const TSecurityPolicy KDefaultPolicy(TSecurityPolicy::EAlwaysPass); |
247 if((KErrNone != securityPolicy.Create(KDefaultPolicy)) |
232 RSqlSecurityPolicy policy; |
248 || |
233 TInt err = policy.Create(KDefaultPolicy); |
249 (KErrNone != securityPolicy.SetDbPolicy(RSqlSecurityPolicy::ESchemaPolicy, KDefaultPolicy)) |
234 TEST2(err, KErrNone); |
250 || |
235 err = policy.SetDbPolicy(RSqlSecurityPolicy::ESchemaPolicy, KDefaultPolicy); |
251 (KErrNone != securityPolicy.SetDbPolicy(RSqlSecurityPolicy::EWritePolicy, KDefaultPolicy)) |
236 TEST2(err, KErrNone); |
252 || |
237 err = policy.SetDbPolicy(RSqlSecurityPolicy::EWritePolicy, KDefaultPolicy); |
253 (KErrNone != securityPolicy.SetDbPolicy(RSqlSecurityPolicy::EReadPolicy, KDefaultPolicy))) |
238 TEST2(err, KErrNone); |
254 { |
239 err = policy.SetDbPolicy(RSqlSecurityPolicy::EReadPolicy, KDefaultPolicy); |
255 return KErrGeneral; |
240 TEST2(err, KErrNone); |
256 } |
241 return policy; |
257 |
242 } |
258 return KErrNone; |
243 |
259 } |
244 void DoCreateCfgFile(const TDesC& aFileName, const TDesC8& aData) |
260 |
245 { |
246 RFile file; |
|
247 TInt err = file.Create(TheFs, aFileName, EFileRead | EFileWrite); |
|
248 TEST2(err, KErrNone); |
|
249 err = file.Write(aData); |
|
250 file.Close(); |
|
251 TEST2(err, KErrNone); |
|
252 } |
|
253 |
|
254 // Create v01 of the test config files |
|
261 void CreateCfgFiles() |
255 void CreateCfgFiles() |
262 { |
256 { |
263 // Create v01 of the test config files |
|
264 |
|
265 RFile file; |
|
266 TFileName fileName; |
257 TFileName fileName; |
267 TInt v1 = 1; |
258 TInt v1 = 1; |
268 fileName.Format(KCfgDb1ConfigFilePath(), v1); |
259 fileName.Format(KCfgDb1ConfigFilePath, v1); |
269 TInt err = file.Create(TheFs, fileName, EFileRead | EFileWrite); |
260 |
270 TEST2(err, KErrNone); |
261 // config file v01 contents for db1 (also tests that upper and lower case statements are both supported) |
271 TPtrC8 pDb1((const TUint8*)KCfgDb1ConfigFile01Stmts().Ptr(), KCfgDb1ConfigFile01Stmts().Length()); |
262 _LIT8(KCfgDb1ConfigFile01Stmts, "CREATE INDEX idx ON table1(i1);CREATE INDEX idx2 ON table1(i2);INSERT INTO table1 (i1,i2,i3) values(5,8,9);DELETE FROM table1;create index multiidx ON TABLE1(i2,i3)"); |
272 err = file.Write(pDb1); |
263 DoCreateCfgFile(fileName, KCfgDb1ConfigFile01Stmts); |
273 file.Close(); |
264 |
274 TEST2(err, KErrNone); |
265 // config file v01 contents for db3 (will not be processed as db3 is not a shared, secure db) |
275 |
266 _LIT8(KCfgDb3ConfigFile01Stmts, "CREATE INDEX idx ON table3(i1)"); |
276 fileName.Copy(KCfgDb3ConfigFileV01Path); |
267 DoCreateCfgFile(KCfgDb3ConfigFileV01Path, KCfgDb3ConfigFile01Stmts); |
277 err = file.Create(TheFs, fileName, EFileRead | EFileWrite); |
268 |
278 TEST2(err, KErrNone); |
269 // config file v01 contents for db4 (will not be processed as db4 is not a shared, secure db) |
279 TPtrC8 pDb3((const TUint8*)KCfgDb3ConfigFile01Stmts().Ptr(), KCfgDb3ConfigFile01Stmts().Length()); |
270 _LIT8(KCfgDb4ConfigFile01Stmts, "CREATE INDEX idx ON table4(i1)"); |
280 err = file.Write(pDb3); |
271 DoCreateCfgFile(KCfgDb4ConfigFileV01Path, KCfgDb4ConfigFile01Stmts); |
281 file.Close(); |
272 |
282 TEST2(err, KErrNone); |
273 // create the config file for Db5 before the database has been created |
283 |
274 // config file v01 contents for db5 (will eventually be processed after db5 itself is created) |
284 fileName.Copy(KCfgDb4ConfigFileV01Path); |
275 _LIT8(KCfgDb5ConfigFile01Stmts, "CREATE INDEX idx ON table5(i1);\r\n"); |
285 err = file.Create(TheFs, fileName, EFileRead | EFileWrite); |
276 DoCreateCfgFile(KCfgDb5ConfigFileV01Path, KCfgDb5ConfigFile01Stmts); |
286 TEST2(err, KErrNone); |
277 } |
287 TPtrC8 pDb4((const TUint8*)KCfgDb4ConfigFile01Stmts().Ptr(), KCfgDb4ConfigFile01Stmts().Length()); |
278 |
288 err = file.Write(pDb4); |
279 void DoCreateCfgDb(const TDesC& aFileName, const TDesC& aCreateTblSql, const TDesC& aInsertSql, |
289 file.Close(); |
280 RSqlSecurityPolicy* aPolicy = NULL) |
290 TEST2(err, KErrNone); |
281 { |
291 |
282 TInt err = aPolicy ? TheDb.Create(aFileName, *aPolicy) : TheDb.Create(aFileName); |
292 fileName.Copy(KCfgDb5ConfigFileV01Path); // create the config file for Db5 before the database has been created |
283 TEST2(err, KErrNone); |
293 err = file.Create(TheFs, fileName, EFileRead | EFileWrite); |
284 err = TheDb.Exec(aCreateTblSql); |
294 TEST2(err, KErrNone); |
285 TEST(err >= 0); |
295 TPtrC8 pDb5((const TUint8*)KCfgDb5ConfigFile01Stmts().Ptr(), KCfgDb5ConfigFile01Stmts().Length()); |
286 err = TheDb.Exec(aInsertSql); |
296 err = file.Write(pDb5); |
287 TEST(err == 1); |
297 file.Close(); |
288 TheDb.Close(); |
298 TEST2(err, KErrNone); |
289 } |
299 } |
290 |
300 |
291 // Create the test databases |
301 void CreateCfgDbs() |
292 void CreateCfgDbs() |
302 { |
293 { |
303 // Create the test databases |
294 RSqlSecurityPolicy securityPolicy = CreateSecurityPolicy(); |
304 |
295 DoCreateCfgDb(KCfgDb1, _L("CREATE TABLE table1(i1 INTEGER, i2 INTEGER, i3 INTEGER)"), |
305 TBuf<100> sql; |
296 _L("INSERT INTO table1 (i1,i2,i3) values(1,2,3)"), &securityPolicy); |
306 |
297 DoCreateCfgDb(KCfgDb2, _L("CREATE TABLE table2(i1 INTEGER, i2 INTEGER, i3 INTEGER)"), |
307 RSqlSecurityPolicy securityPolicy; |
298 _L("INSERT INTO table2 (i1,i2,i3) values(4,5,6)"), &securityPolicy); |
308 TInt err = DoCreateSecurityPolicy(securityPolicy); |
299 securityPolicy.Close(); |
309 TEST2(err, KErrNone); |
300 DoCreateCfgDb(KCfgDb3, _L("CREATE TABLE table3(i1 INTEGER, i2 INTEGER)"), |
310 |
301 _L("INSERT INTO table3 (i1,i2) values(7,8)")); |
311 err = TheDb.Create(KCfgDb1, securityPolicy); |
302 DoCreateCfgDb(KCfgDb4, _L("CREATE TABLE table4(i1 INTEGER, i2 INTEGER, i3 INTEGER)"), |
312 TEST2(err, KErrNone); |
303 _L("INSERT INTO table4 (i1,i2,i3) values(9,10,11)")); |
313 sql.Copy(_L("CREATE TABLE table1(i1 INTEGER, i2 INTEGER, i3 INTEGER)")); |
|
314 err = TheDb.Exec(sql); |
|
315 TEST(err >= 0); |
|
316 sql.Copy(_L("INSERT INTO table1 (i1,i2,i3) values(1,2,3)")); |
|
317 err = TheDb.Exec(sql); |
|
318 TEST(err == 1); |
|
319 TheDb.Close(); |
|
320 |
|
321 err = TheDb.Create(KCfgDb2, securityPolicy); |
|
322 TEST2(err, KErrNone); |
|
323 sql.Copy(_L("CREATE TABLE table2(i1 INTEGER, i2 INTEGER, i3 INTEGER)")); |
|
324 err = TheDb.Exec(sql); |
|
325 TEST(err >= 0); |
|
326 sql.Copy(_L("INSERT INTO table2 (i1,i2,i3) values(4,5,6)")); |
|
327 err = TheDb.Exec(sql); |
|
328 TEST(err == 1); |
|
329 TheDb.Close(); |
|
330 |
|
331 securityPolicy.Close(); |
|
332 |
|
333 err = TheDb.Create(KCfgDb3); |
|
334 TEST2(err, KErrNone); |
|
335 sql.Copy(_L("CREATE TABLE table3(i1 INTEGER, i2 INTEGER)")); |
|
336 err = TheDb.Exec(sql); |
|
337 TEST(err >= 0); |
|
338 sql.Copy(_L("INSERT INTO table3 (i1,i2) values(7,8)")); |
|
339 err = TheDb.Exec(sql); |
|
340 TEST(err == 1); |
|
341 TheDb.Close(); |
|
342 |
|
343 err = TheDb.Create(KCfgDb4); |
|
344 TEST2(err, KErrNone); |
|
345 sql.Copy(_L("CREATE TABLE table4(i1 INTEGER, i2 INTEGER, i3 INTEGER)")); |
|
346 err = TheDb.Exec(sql); |
|
347 TEST(err >= 0); |
|
348 sql.Copy(_L("INSERT INTO table4 (i1,i2,i3) values(9,10,11)")); |
|
349 err = TheDb.Exec(sql); |
|
350 TEST(err == 1); |
|
351 TheDb.Close(); |
|
352 } |
304 } |
353 |
305 |
354 void CreateCfgFilesAndDbs() |
306 void CreateCfgFilesAndDbs() |
355 { |
307 { |
356 CreateCfgFiles(); |
308 CreateCfgFiles(); |
357 CreateCfgDbs(); |
309 CreateCfgDbs(); |
358 |
310 |
359 // Must now kill the SQL Server so that the config files |
311 // Must now kill the SQL Server so that the config files |
360 // created above are found and processed when it restarts |
312 // created above are found and processed when it restarts |
361 (void)KillProcess(KSqlSrvName); |
313 KillSqlServer(); |
362 } |
314 } |
363 |
315 |
316 // Create the Db5 test database (a config file for it already exists) |
|
364 void CreateDb5() |
317 void CreateDb5() |
365 { |
318 { |
366 // Create the Db5 test database (a config file for it already exists) |
319 RSqlSecurityPolicy securityPolicy = CreateSecurityPolicy(); |
367 |
320 DoCreateCfgDb(KCfgDb5, _L("CREATE TABLE table5(i1 INTEGER, i2 INTEGER, i3 INTEGER)"), |
368 TBuf<100> sql; |
321 _L("INSERT INTO table5 (i1,i2,i3) values(1,2,3)"), &securityPolicy); |
369 |
|
370 RSqlSecurityPolicy securityPolicy; |
|
371 TInt err = DoCreateSecurityPolicy(securityPolicy); |
|
372 TEST2(err, KErrNone); |
|
373 |
|
374 err = TheDb.Create(KCfgDb5, securityPolicy); |
|
375 TEST2(err, KErrNone); |
|
376 sql.Copy(_L("CREATE TABLE table5(i1 INTEGER, i2 INTEGER, i3 INTEGER)")); |
|
377 err = TheDb.Exec(sql); |
|
378 TEST(err >= 0); |
|
379 sql.Copy(_L("INSERT INTO table5 (i1,i2,i3) values(1,2,3)")); |
|
380 err = TheDb.Exec(sql); |
|
381 TEST(err == 1); |
|
382 |
|
383 TheDb.Close(); |
|
384 securityPolicy.Close(); |
322 securityPolicy.Close(); |
385 } |
323 } |
386 |
324 |
387 void SetupTestEnv() |
325 void SetupTestEnv() |
388 { |
326 { |
389 TInt err = TheFs.Connect(); |
327 TInt err = TheFs.Connect(); |
390 TEST2(err, KErrNone); |
328 TEST2(err, KErrNone); |
391 |
329 |
330 _LIT(KTestDir, "c:\\test\\"); |
|
392 err = TheFs.MkDir(KTestDir); |
331 err = TheFs.MkDir(KTestDir); |
393 TEST(err == KErrNone || err == KErrAlreadyExists); |
332 TEST(err == KErrNone || err == KErrAlreadyExists); |
394 |
333 |
395 err = TheFs.CreatePrivatePath(EDriveC); |
334 err = TheFs.CreatePrivatePath(EDriveC); |
396 TEST(err == KErrNone || err == KErrAlreadyExists); |
335 TEST(err == KErrNone || err == KErrAlreadyExists); |
420 } |
359 } |
421 |
360 |
422 /////////////////////////////////////////////////////////////////////////////////////// |
361 /////////////////////////////////////////////////////////////////////////////////////// |
423 // Config file replacement functions |
362 // Config file replacement functions |
424 |
363 |
425 void UpgradeDbConfigFile(const TInt aCurrentVersion) |
364 void UpgradeDbConfigFile(TInt aCurrentVersion) |
426 { |
365 { |
427 (void)KillProcess(KSqlSrvName); |
366 TInt newVersion = aCurrentVersion + 1; |
428 TFileName oldFile; |
367 TEST(newVersion != 0 && newVersion != 1 && newVersion != 10 && newVersion != 11 && newVersion < 15); |
429 oldFile.Format(KCfgDb1ConfigFilePath(), aCurrentVersion); |
368 |
430 TInt err = TheFs.Delete(oldFile); |
369 KillSqlServer(); |
431 TEST2(err, KErrNone); |
370 |
432 RFile file; |
371 TFileName fname; |
433 TFileName newFile; |
372 fname.Format(KCfgDb1ConfigFilePath, aCurrentVersion); |
434 TInt newVersion = aCurrentVersion+1; |
373 TInt err = TheFs.Delete(fname); |
435 newFile.Format(KCfgDb1ConfigFilePath(), newVersion); |
374 TEST2(err, KErrNone); |
436 err = file.Create(TheFs, newFile, EFileRead | EFileWrite); |
375 |
437 TEST2(err, KErrNone); |
376 if(newVersion == 12) |
438 |
377 { |
439 switch(newVersion) |
378 // also delete version 10 of file |
440 { |
379 fname.Format(KCfgDb1ConfigFilePath, 10); |
441 case 2: |
380 err = TheFs.Delete(fname); |
442 { |
381 TEST2(err, KErrNone); |
443 TPtrC8 p((const TUint8*)KCfgConfigFileValidStmt().Ptr(), KCfgConfigFileValidStmt().Length()); |
382 } |
444 err = file.Write(p); |
383 |
445 break; |
384 const TPtrC8 stmts[] = {KNullDesC8(), KNullDesC8(), |
446 } |
385 KCfgConfigFileValidStmt(), |
447 case 3: |
386 KCfgDb1ConfigFileV03EmptyStmt(), |
448 { |
387 KCfgDb1ConfigFileV04UnsupportedStmt(), |
449 TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV03EmptyStmt().Ptr(), KCfgDb1ConfigFileV03EmptyStmt().Length()); |
388 KCfgDb1ConfigFileV05OnlyWhitespaceStmt(), |
450 err = file.Write(p); |
389 KCfgDb1ConfigFileV06InvalidSchemaStmt(), |
451 break; |
390 KCfgDb1ConfigFileV07InvalidCommentedStmt(), |
452 } |
391 KCfgDb1ConfigFileV08SeqStmt(), |
453 case 4: |
392 KCfgDb1ConfigFileV09WhitespacePreAndPostStmt(), |
454 { |
393 KNullDesC8(), KNullDesC8(), |
455 TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV04UnsupportedStmt().Ptr(), KCfgDb1ConfigFileV04UnsupportedStmt().Length()); |
394 KCfgDb1ConfigFileV12InvalidPlusValidStmt(), |
456 err = file.Write(p); |
395 KCfgDb1ConfigFileV13SQLCommentStmt(), |
457 break; |
396 KCfgDb1ConfigFileV14CCommentStmt()}; |
458 } |
397 |
459 case 5: |
398 fname.Format(KCfgDb1ConfigFilePath, newVersion); |
460 { |
399 DoCreateCfgFile(fname, stmts[newVersion]); |
461 TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV05OnlyWhitespaceStmt().Ptr(), KCfgDb1ConfigFileV05OnlyWhitespaceStmt().Length()); |
|
462 err = file.Write(p); |
|
463 break; |
|
464 } |
|
465 case 6: |
|
466 { |
|
467 TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV06InvalidSchemaStmt().Ptr(), KCfgDb1ConfigFileV06InvalidSchemaStmt().Length()); |
|
468 err = file.Write(p); |
|
469 break; |
|
470 } |
|
471 case 7: |
|
472 { |
|
473 TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV07InvalidCommentedStmt().Ptr(), KCfgDb1ConfigFileV07InvalidCommentedStmt().Length()); |
|
474 err = file.Write(p); |
|
475 break; |
|
476 } |
|
477 case 8: |
|
478 { |
|
479 TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV08SeqStmt().Ptr(), KCfgDb1ConfigFileV08SeqStmt().Length()); |
|
480 err = file.Write(p); |
|
481 break; |
|
482 } |
|
483 case 9: |
|
484 { |
|
485 TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV09WhitespacePreAndPostStmt().Ptr(), KCfgDb1ConfigFileV09WhitespacePreAndPostStmt().Length()); |
|
486 err = file.Write(p); |
|
487 break; |
|
488 } |
|
489 case 12: |
|
490 { |
|
491 // also delete version 10 of file |
|
492 oldFile.Format(KCfgDb1ConfigFilePath(), 10); |
|
493 err = TheFs.Delete(oldFile); |
|
494 TEST2(err, KErrNone); |
|
495 |
|
496 TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV12InvalidPlusValidStmt().Ptr(), KCfgDb1ConfigFileV12InvalidPlusValidStmt().Length()); |
|
497 err = file.Write(p); |
|
498 break; |
|
499 } |
|
500 case 13: |
|
501 { |
|
502 TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV13SQLCommentStmt().Ptr(), KCfgDb1ConfigFileV13SQLCommentStmt().Length()); |
|
503 err = file.Write(p); |
|
504 break; |
|
505 } |
|
506 case 14: |
|
507 { |
|
508 TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV14CCommentStmt().Ptr(), KCfgDb1ConfigFileV14CCommentStmt().Length()); |
|
509 err = file.Write(p); |
|
510 break; |
|
511 } |
|
512 default: |
|
513 { |
|
514 err = KErrArgument; |
|
515 break; |
|
516 } |
|
517 } |
|
518 file.Close(); |
|
519 TEST2(err, KErrNone); |
|
520 } |
400 } |
521 |
401 |
522 void DowngradeDbConfigFile(const TInt aCurrentVersion) |
402 void DowngradeDbConfigFile(TInt aCurrentVersion) |
523 { |
403 { |
524 (void)KillProcess(KSqlSrvName); |
404 TEST(aCurrentVersion > 1); |
525 TFileName oldFile; |
405 |
526 oldFile.Format(KCfgDb1ConfigFilePath(), aCurrentVersion); |
406 KillSqlServer(); |
527 TInt err = TheFs.Delete(oldFile); |
407 |
528 TEST2(err, KErrNone); |
408 TFileName fname; |
529 RFile file; |
409 fname.Format(KCfgDb1ConfigFilePath, aCurrentVersion); |
530 TFileName newFile; |
410 TInt err = TheFs.Delete(fname); |
531 TInt previousVersion = aCurrentVersion-1; |
411 TEST2(err, KErrNone); |
532 TEST(previousVersion > 0); |
412 |
533 newFile.Format(KCfgDb1ConfigFilePath(), previousVersion); |
413 fname.Format(KCfgDb1ConfigFilePath, aCurrentVersion - 1); |
534 err = file.Create(TheFs, newFile, EFileRead | EFileWrite); |
414 DoCreateCfgFile(fname, KCfgConfigFileValidStmt); |
535 TEST2(err, KErrNone); |
415 } |
536 TPtrC8 p((const TUint8*)KCfgConfigFileValidStmt().Ptr(), KCfgConfigFileValidStmt().Length()); |
416 |
537 err = file.Write(p); |
417 void CreateCorruptDbConfigFile(TInt aCurrentVersion) |
538 file.Close(); |
418 { |
539 TEST2(err, KErrNone); |
419 KillSqlServer(); |
540 } |
420 |
541 |
421 TFileName fname; |
542 void CreateCorruptDbConfigFile(const TInt aCurrentVersion) |
422 fname.Format(KCfgDb1ConfigFilePath, aCurrentVersion); |
543 { |
423 TInt err = TheFs.Delete(fname); |
544 (void)KillProcess(KSqlSrvName); |
424 TEST2(err, KErrNone); |
545 TFileName oldFile; |
425 |
546 oldFile.Format(KCfgDb1ConfigFilePath(), aCurrentVersion); |
426 DoCreateCfgFile(KCfgDb1CorruptConfigFilePath, KCfgConfigFileValidStmt); |
547 TInt err = TheFs.Delete(oldFile); |
|
548 TEST2(err, KErrNone); |
|
549 RFile file; |
|
550 err = file.Create(TheFs, KCfgDb1CorruptConfigFilePath(), EFileRead | EFileWrite); |
|
551 TEST2(err, KErrNone); |
|
552 TPtrC8 p((const TUint8*)KCfgConfigFileValidStmt().Ptr(), KCfgConfigFileValidStmt().Length()); |
|
553 err = file.Write(p); |
|
554 file.Close(); |
|
555 TEST2(err, KErrNone); |
|
556 } |
427 } |
557 |
428 |
558 void CreateTwoVersionsOfConfigFile() |
429 void CreateTwoVersionsOfConfigFile() |
559 { |
430 { |
560 (void)KillProcess(KSqlSrvName); |
431 KillSqlServer(); |
432 |
|
561 TInt err = TheFs.Delete(KCfgDb1CorruptConfigFilePath); |
433 TInt err = TheFs.Delete(KCfgDb1CorruptConfigFilePath); |
562 TEST2(err, KErrNone); |
434 TEST2(err, KErrNone); |
563 RFile file; |
435 |
564 TFileName newFile; |
436 TInt nextVersion = 10; |
565 TInt nextVersion = 10; |
437 TFileName fname; |
566 newFile.Format(KCfgDb1ConfigFilePath(), nextVersion); |
438 fname.Format(KCfgDb1ConfigFilePath, nextVersion); |
567 err = file.Create(TheFs, newFile, EFileRead | EFileWrite); |
439 DoCreateCfgFile(fname, KCfgDb1ConfigFileV10ValidStmt); |
568 TEST2(err, KErrNone); |
440 |
569 TPtrC8 p10((const TUint8*)KCfgDb1ConfigFileV10ValidStmt().Ptr(), KCfgDb1ConfigFileV10ValidStmt().Length()); |
|
570 err = file.Write(p10); |
|
571 file.Close(); |
|
572 TEST2(err, KErrNone); |
|
573 ++nextVersion; |
441 ++nextVersion; |
574 newFile.Format(KCfgDb1ConfigFilePath(), nextVersion); |
442 fname.Format(KCfgDb1ConfigFilePath, nextVersion); |
575 err = file.Create(TheFs, newFile, EFileRead | EFileWrite); |
443 DoCreateCfgFile(fname, KCfgDb1ConfigFileV11ValidStmt); |
576 TEST2(err, KErrNone); |
|
577 TPtrC8 p11((const TUint8*)KCfgDb1ConfigFileV11ValidStmt().Ptr(), KCfgDb1ConfigFileV11ValidStmt().Length()); |
|
578 err = file.Write(p11); |
|
579 file.Close(); |
|
580 TEST2(err, KErrNone); |
|
581 } |
444 } |
582 |
445 |
583 /////////////////////////////////////////////////////////////////////////////////////// |
446 /////////////////////////////////////////////////////////////////////////////////////// |
584 // DoDbCfgTests() functions |
447 // DoDbCfgTests() functions |
585 |
448 |
449 TInt GetDbCfgVersion(const TDesC& aDbName) |
|
450 { |
|
451 // Note: We have to use SQLite directly to access the settings |
|
452 // table as the SQL Server denies permission to access this table |
|
453 // as it is in a shared, secure database |
|
454 |
|
455 TParse parse; |
|
456 TInt err = parse.Set(aDbName, &KSqlSrvPrivatePath, 0); |
|
457 TEST2(err, KErrNone); |
|
458 |
|
459 TBuf8<KMaxFileName + 1> dbFileName; |
|
460 dbFileName.Copy(parse.FullName()); |
|
461 |
|
462 sqlite3 *dbHandle = NULL; |
|
463 TInt rc = sqlite3_open((const char*)dbFileName.PtrZ(), &dbHandle); |
|
464 TEST2(rc, SQLITE_OK); |
|
465 |
|
466 _LIT(KGetDbCfgVersionSql, "SELECT Reserved AS DbCfgVersion FROM symbian_settings"); |
|
467 TBuf<100> queryBuf; |
|
468 queryBuf.Copy(KGetDbCfgVersionSql); |
|
469 |
|
470 sqlite3_stmt* stmtHandle = NULL; |
|
471 const void* stmtTailZ = NULL; |
|
472 rc = sqlite3_prepare16_v2(dbHandle, queryBuf.PtrZ(), -1, &stmtHandle, &stmtTailZ); |
|
473 TEST2(rc, SQLITE_OK); |
|
474 |
|
475 rc = sqlite3_step(stmtHandle); |
|
476 TEST2(rc, SQLITE_ROW); |
|
477 |
|
478 TInt version = sqlite3_column_int(stmtHandle, 0); |
|
479 |
|
480 rc = sqlite3_step(stmtHandle); |
|
481 TEST2(rc, SQLITE_DONE); |
|
482 |
|
483 sqlite3_finalize(stmtHandle); |
|
484 sqlite3_close(dbHandle); |
|
485 |
|
486 return version; |
|
487 } |
|
488 |
|
586 TBool GuessSystemSettingsTable(const TDesC& aDbName, TInt aVersion) |
489 TBool GuessSystemSettingsTable(const TDesC& aDbName, TInt aVersion) |
587 { |
490 { |
588 // Note: We have to use SQLite directly to access the settings |
491 TInt dbCfgVersion = GetDbCfgVersion(aDbName); |
589 // table as the SQL Server denies permission to access this table |
492 return dbCfgVersion == aVersion; |
590 // as it is in a shared, secure database |
|
591 |
|
592 TBool guessIsCorrect = EFalse; |
|
593 |
|
594 TParse parse; |
|
595 parse.Set(aDbName, &KSqlSrvPrivatePath, 0); |
|
596 |
|
597 TBuf8<KMaxFileName + 1> dbFileName; |
|
598 dbFileName.Copy(parse.FullName()); |
|
599 |
|
600 TheDbHandle = NULL; |
|
601 TInt rc = sqlite3_open((const char*)dbFileName.PtrZ(), &TheDbHandle); |
|
602 TEST2(rc, SQLITE_OK); |
|
603 |
|
604 TBuf<100> queryBuf; |
|
605 queryBuf.Format(KGetSettingsSql(), aVersion); |
|
606 |
|
607 sqlite3_stmt* stmtHandle = NULL; |
|
608 const void* stmtTailZ = NULL; |
|
609 rc = sqlite3_prepare16_v2(TheDbHandle, queryBuf.PtrZ(), -1, &stmtHandle, &stmtTailZ); |
|
610 TEST2(rc, SQLITE_OK); |
|
611 |
|
612 rc = sqlite3_step(stmtHandle); |
|
613 if(SQLITE_ROW == rc) |
|
614 { |
|
615 guessIsCorrect = ETrue; |
|
616 rc = sqlite3_step(stmtHandle); |
|
617 TEST2(rc, SQLITE_DONE); |
|
618 } |
|
619 |
|
620 sqlite3_finalize(stmtHandle); |
|
621 sqlite3_close(TheDbHandle); |
|
622 TheDbHandle = NULL; |
|
623 |
|
624 return guessIsCorrect; |
|
625 } |
493 } |
626 |
494 |
627 void CheckSystemSettingsTable(const TDesC& aDbName, TInt aVersion) |
495 void CheckSystemSettingsTable(const TDesC& aDbName, TInt aVersion) |
628 { |
496 { |
629 // Note: We have to use SQLite directly to access the settings |
497 TInt dbCfgVersion = GetDbCfgVersion(aDbName); |
630 // table as the SQL Server denies permission to access this table |
498 TEST2(dbCfgVersion, aVersion); |
631 // as it is in a shared, secure database |
499 } |
632 |
500 |
633 TParse parse; |
501 void CheckRecordCount(const TDesC& aTable) |
634 parse.Set(aDbName, &KSqlSrvPrivatePath, 0); |
|
635 |
|
636 TBuf8<KMaxFileName + 1> dbFileName; |
|
637 dbFileName.Copy(parse.FullName()); |
|
638 |
|
639 sqlite3 *dbHandle = NULL; |
|
640 TInt rc = sqlite3_open((const char*)dbFileName.PtrZ(), &dbHandle); |
|
641 TEST2(rc, SQLITE_OK); |
|
642 |
|
643 TBuf<100> queryBuf; |
|
644 queryBuf.Format(KGetSettingsSql(), aVersion); |
|
645 |
|
646 sqlite3_stmt* stmtHandle = NULL; |
|
647 const void* stmtTailZ = NULL; |
|
648 rc = sqlite3_prepare16_v2(dbHandle, queryBuf.PtrZ(), -1, &stmtHandle, &stmtTailZ); |
|
649 TEST2(rc, SQLITE_OK); |
|
650 |
|
651 rc = sqlite3_step(stmtHandle); |
|
652 TEST2(rc, SQLITE_ROW); |
|
653 |
|
654 rc = sqlite3_step(stmtHandle); |
|
655 TEST2(rc, SQLITE_DONE); |
|
656 |
|
657 sqlite3_finalize(stmtHandle); |
|
658 sqlite3_close(dbHandle); |
|
659 } |
|
660 |
|
661 void CheckNumberRecordsL(const TDesC& aStmt) |
|
662 { |
502 { |
663 // There should always be only 1 record in the table |
503 // There should always be only 1 record in the table |
664 // in each database as INSERT and DELETE statements are |
504 // in each database as INSERT and DELETE statements are |
665 // not supported in the config files |
505 // not supported in the config files |
666 |
506 TBuf<50> sql; |
667 // Prepare stmt |
507 sql.Format(_L("SELECT COUNT(*) FROM %S"), &aTable); |
668 RSqlStatement stmt; |
508 TSqlScalarFullSelectQuery q(TheDb); |
669 stmt.PrepareL(TheDb, aStmt); |
509 TInt count = 0; |
670 |
510 TRAPD(err, count = q.SelectIntL(sql)); |
671 // Get each row |
511 TEST2(err, KErrNone); |
672 TUint numRows = 0; |
512 TEST2(count, 1); |
673 TInt err = stmt.Next(); |
513 } |
674 while(KSqlAtRow == err) |
514 |
675 { |
515 TInt ExpectedDb1IndexCount(TInt aExpectedStoredVersion) |
676 numRows++; |
516 { |
677 err = stmt.Next(); |
517 TEST(aExpectedStoredVersion >= 0 && aExpectedStoredVersion < 15); |
678 } |
518 const TInt KIdxCnt[] = { |
679 |
519 -1, |
680 if (KSqlAtEnd != err) |
520 3, // Only files 01 - 04, 09 and 11 will be successfully processed and so stored in the settings table |
681 { |
521 4, // 1 more index should be added to db1 based on config file 02 |
682 User::Leave(KErrCorrupt); |
522 4, 4, 4, 4, 4, // no more indices should be added to db1 based on config file 03 - 07 |
683 } |
523 6, // 2 more indices should be added to db1 based on config file 08 |
524 7, // 1 more index should be added to db1 based on config file 09 |
|
525 -1, |
|
526 9, // 2 more indices should be added to db1 based on config file 11 |
|
527 10, // 1 more index should be added to db1 based on config file 12 |
|
528 11, // 1 more index should be added to db1 based on config file 13 |
|
529 12}; // 1 more index should be added to db1 based on config file 14 |
|
530 return KIdxCnt[aExpectedStoredVersion]; |
|
531 } |
|
532 |
|
533 void CheckIndexCount(TInt aExpectedIndexCount) |
|
534 { |
|
535 _LIT(KDbCheckNumIndices, "SELECT COUNT(*) FROM sqlite_master WHERE type = 'index'"); |
|
536 TSqlScalarFullSelectQuery q(TheDb); |
|
537 TInt count = 0; |
|
538 TRAPD(err, count = q.SelectIntL(KDbCheckNumIndices)); |
|
539 TEST2(err, KErrNone); |
|
540 TEST2(count, aExpectedIndexCount); |
|
541 } |
|
542 |
|
543 void DoCfgOpenTest(TInt aExpectedStoredVersion, const TDesC& aDbFileName, const TDesC& aTblName, TInt aExpectedIndexCnt) |
|
544 { |
|
545 TInt err = TheDb.Open(aDbFileName); |
|
546 TEST2(err, KErrNone); |
|
547 CheckRecordCount(aTblName); |
|
548 CheckIndexCount(aExpectedIndexCnt); |
|
549 TheDb.Close(); |
|
550 // Check that the ops in the specified config file have been applied. |
|
551 CheckSystemSettingsTable(aDbFileName, aExpectedStoredVersion); |
|
552 } |
|
553 |
|
554 void DoCfgOpenTests(TInt aExpectedStoredVersion) |
|
555 { |
|
556 // Open a shared, secure database - config ops should be applied on it. |
|
557 // There should still be only 1 record and 3 indices in the table. |
|
558 TheTest.Printf(_L("===CfgOpen: Open shared, secure database\r\n")); |
|
559 DoCfgOpenTest(aExpectedStoredVersion, KCfgDb1, _L("table1"), ExpectedDb1IndexCount(aExpectedStoredVersion)); |
|
684 |
560 |
685 if (numRows != 1) |
561 // Open again the same shared, secure database - no config should occur (it has already been done). |
686 { |
|
687 User::Leave(KErrArgument); |
|
688 } |
|
689 |
|
690 // Close stmt |
|
691 stmt.Close(); |
|
692 } |
|
693 |
|
694 TInt NumberIndicesExpectedInDb1(const TInt aExpectedStoredVersion) |
|
695 { |
|
696 TInt numIndices = -1; |
|
697 |
|
698 switch(aExpectedStoredVersion) |
|
699 { |
|
700 // Only files 01 - 04, 09 and 11 will be successfully processed and so stored in the settings table |
|
701 case 1: |
|
702 { |
|
703 numIndices = 3; // 3 indices should be added to db1 based on config file 01 |
|
704 break; |
|
705 } |
|
706 case 2: |
|
707 { |
|
708 numIndices = 4; // 1 more index should be added to db1 based on config file 02 |
|
709 break; |
|
710 } |
|
711 case 3: |
|
712 case 4: |
|
713 case 5: |
|
714 case 6: |
|
715 case 7: |
|
716 { |
|
717 numIndices = 4; // no more indices should be added to db1 based on config file 03 - 07 |
|
718 break; |
|
719 } |
|
720 case 8: |
|
721 { |
|
722 numIndices = 6; // 2 more indices should be added to db1 based on config file 08 |
|
723 break; |
|
724 } |
|
725 case 9: |
|
726 { |
|
727 numIndices = 7; // 1 more index should be added to db1 based on config file 09 |
|
728 break; |
|
729 } |
|
730 case 11: |
|
731 { |
|
732 numIndices = 9; // 2 more indices should be added to db1 based on config file 11 |
|
733 break; |
|
734 } |
|
735 case 12: |
|
736 { |
|
737 numIndices = 10; // 1 more index should be added to db1 based on config file 12 |
|
738 break; |
|
739 } |
|
740 case 13: |
|
741 { |
|
742 numIndices = 11; // 1 more index should be added to db1 based on config file 13 |
|
743 break; |
|
744 } |
|
745 case 14: |
|
746 { |
|
747 numIndices = 12; // 1 more index should be added to db1 based on config file 14 |
|
748 break; |
|
749 } |
|
750 } |
|
751 |
|
752 return numIndices; |
|
753 } |
|
754 |
|
755 void CheckNumberIndicesL(const TInt aNumIndicesExpected) |
|
756 { |
|
757 // Prepare stmt |
|
758 RSqlStatement stmt; |
|
759 stmt.PrepareL(TheDb, KDbCheckNumIndices); |
|
760 |
|
761 // Get each entry of type 'index' in the 'sqlite_master' table |
|
762 TUint numEntries = 0; |
|
763 TInt err = stmt.Next(); |
|
764 while(KSqlAtRow == err) |
|
765 { |
|
766 numEntries++; |
|
767 err = stmt.Next(); |
|
768 } |
|
769 |
|
770 if (KSqlAtEnd != err) |
|
771 { |
|
772 User::Leave(KErrCorrupt); |
|
773 } |
|
774 |
|
775 if (numEntries != aNumIndicesExpected) |
|
776 { |
|
777 User::Leave(KErrArgument); |
|
778 } |
|
779 |
|
780 // Close stmt |
|
781 stmt.Close(); |
|
782 } |
|
783 |
|
784 void DoCfgOpenTests(TInt aExpectedStoredVersion = 1) |
|
785 { |
|
786 // Open a shared, secure database - config ops should be applied on it |
|
787 TheTest.Printf(_L("===CfgOpen: Open shared, secure database\r\n")); |
|
788 TInt err = TheDb.Open(KCfgDb1); |
|
789 TEST2(err, KErrNone); |
|
790 TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords)); // there should still be only 1 record in the table |
|
791 TEST2(err, KErrNone); |
|
792 TRAP(err, CheckNumberIndicesL(NumberIndicesExpectedInDb1(aExpectedStoredVersion))); // there should now be 3 indices in the table |
|
793 TEST2(err, KErrNone); |
|
794 TheDb.Close(); |
|
795 CheckSystemSettingsTable(KCfgDb1, aExpectedStoredVersion); // check that the ops in the specified config file have been applied |
|
796 |
|
797 // Open again the same shared, secure database - no config should occur (it has already been done) |
|
798 TheTest.Printf(_L("===CfgOpen: Open shared, secure database again\r\n")); |
562 TheTest.Printf(_L("===CfgOpen: Open shared, secure database again\r\n")); |
799 err = TheDb.Open(KCfgDb1); |
563 DoCfgOpenTest(aExpectedStoredVersion, KCfgDb1, _L("table1"), ExpectedDb1IndexCount(aExpectedStoredVersion)); |
800 TEST2(err, KErrNone); |
|
801 TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords)); |
|
802 TEST2(err, KErrNone); |
|
803 TRAP(err, CheckNumberIndicesL(NumberIndicesExpectedInDb1(aExpectedStoredVersion))); |
|
804 TEST2(err, KErrNone); |
|
805 TheDb.Close(); |
|
806 CheckSystemSettingsTable(KCfgDb1, aExpectedStoredVersion); |
|
807 |
564 |
808 // Open a shared, secure database - no config should occur (there is no config file for this database) |
565 // Open a shared, secure database - no config should occur (there is no config file for this database) |
809 TheTest.Printf(_L("===CfgOpen: Open shared, secure database (that has no config file)\r\n")); |
566 TheTest.Printf(_L("===CfgOpen: Open shared, secure database (that has no config file)\r\n")); |
810 err = TheDb.Open(KCfgDb2); |
567 DoCfgOpenTest(0, KCfgDb2, _L("table2"), 0); |
811 TEST2(err, KErrNone); |
|
812 TRAP(err, CheckNumberRecordsL(KDb2CheckNumRecords)); |
|
813 TEST2(err, KErrNone); |
|
814 TRAP(err, CheckNumberIndicesL(0)); |
|
815 TEST2(err, KErrNone); |
|
816 TheDb.Close(); |
|
817 CheckSystemSettingsTable(KCfgDb2, 0); |
|
818 |
568 |
819 // Open a private, secure database - no config should occur |
569 // Open a private, secure database - no config should occur |
820 TheTest.Printf(_L("===CfgOpen: Open private, secure database\r\n")); |
570 TheTest.Printf(_L("===CfgOpen: Open private, secure database\r\n")); |
821 err = TheDb.Open(KCfgDb3); |
571 DoCfgOpenTest(0, KCfgDb3, _L("table3"), 0); |
822 TEST2(err, KErrNone); |
|
823 TRAP(err, CheckNumberRecordsL(KDb3CheckNumRecords)); |
|
824 TEST2(err, KErrNone); |
|
825 TRAP(err, CheckNumberIndicesL(0)); |
|
826 TEST2(err, KErrNone); |
|
827 TheDb.Close(); |
|
828 CheckSystemSettingsTable(KCfgDb3, 0); |
|
829 |
572 |
830 // Open a public database - no config should occur |
573 // Open a public database - no config should occur |
831 TheTest.Printf(_L("===CfgOpen: Open public database\r\n")); |
574 TheTest.Printf(_L("===CfgOpen: Open public database\r\n")); |
832 err = TheDb.Open(KCfgDb4); |
575 DoCfgOpenTest(0, KCfgDb4, _L("table4"), 0); |
833 TEST2(err, KErrNone); |
|
834 TRAP(err, CheckNumberRecordsL(KDb4CheckNumRecords)); |
|
835 TEST2(err, KErrNone); |
|
836 TRAP(err, CheckNumberIndicesL(0)); |
|
837 TEST2(err, KErrNone); |
|
838 TheDb.Close(); |
|
839 CheckSystemSettingsTable(KCfgDb4, 0); |
|
840 } |
576 } |
841 |
577 |
842 void DoUpgradedCfgOpenTest() |
578 void DoUpgradedCfgOpenTest() |
843 { |
579 { |
844 // Upgrade the config file for KCfgDb1, i.e. replace v1 file with v2 file |
580 // Upgrade the config file for KCfgDb1, i.e. replace v1 file with v2 file |
904 void DoNewDbCfgOpenTest() |
640 void DoNewDbCfgOpenTest() |
905 { |
641 { |
906 // Create Db5 - a config file already exists for this database |
642 // Create Db5 - a config file already exists for this database |
907 CreateDb5(); |
643 CreateDb5(); |
908 |
644 |
909 // Open the shared, secure database Db5 - config ops should be applied on it |
645 // Open the shared, secure database Db5 - config ops should be applied on it. |
646 // There should now be 1 index in the table. |
|
910 TheTest.Printf(_L("===NewDbCfg: Open shared, secure database\r\n")); |
647 TheTest.Printf(_L("===NewDbCfg: Open shared, secure database\r\n")); |
911 TInt err = TheDb.Open(KCfgDb5); |
648 DoCfgOpenTest(1, KCfgDb5, _L("table5"), 1); |
912 TEST2(err, KErrNone); |
|
913 TRAP(err, CheckNumberRecordsL(KDb5CheckNumRecords)); // there should still be only 1 record in the table |
|
914 TEST2(err, KErrNone); |
|
915 TRAP(err, CheckNumberIndicesL(1)); // there should now be 1 index in the table |
|
916 TEST2(err, KErrNone); |
|
917 TheDb.Close(); |
|
918 CheckSystemSettingsTable(KCfgDb5, 1); // check that the ops in the specified config file have been applied |
|
919 |
649 |
920 // Open again the same shared, secure database - no config should occur (it has already been done) |
650 // Open again the same shared, secure database - no config should occur (it has already been done) |
921 TheTest.Printf(_L("===NewDbCfg: Open shared, secure database again\r\n")); |
651 TheTest.Printf(_L("===NewDbCfg: Open shared, secure database again\r\n")); |
922 err = TheDb.Open(KCfgDb5); |
652 DoCfgOpenTest(1, KCfgDb5, _L("table5"), 1); |
923 TEST2(err, KErrNone); |
|
924 TRAP(err, CheckNumberRecordsL(KDb5CheckNumRecords)); |
|
925 TEST2(err, KErrNone); |
|
926 TRAP(err, CheckNumberIndicesL(1)); |
|
927 TEST2(err, KErrNone); |
|
928 TheDb.Close(); |
|
929 CheckSystemSettingsTable(KCfgDb5, 1); |
|
930 } |
653 } |
931 |
654 |
932 void DoCfgAttachTests(TInt aExpectedStoredVersion = 0) |
655 void DoCfgAttachTests(TInt aExpectedStoredVersion = 0) |
933 { |
656 { |
934 // Open a private, secure database - no config should occur |
657 // Open a private, secure database - no config should occur |
1025 |
748 |
1026 // Open a private, secure database - no config should occur |
749 // Open a private, secure database - no config should occur |
1027 TheTest.Printf(_L("===NewDbCfgAttach: Open private, secure database\r\n")); |
750 TheTest.Printf(_L("===NewDbCfgAttach: Open private, secure database\r\n")); |
1028 TInt err = TheDb.Open(KCfgDb3); |
751 TInt err = TheDb.Open(KCfgDb3); |
1029 TEST2(err, KErrNone); |
752 TEST2(err, KErrNone); |
1030 TRAP(err, CheckNumberRecordsL(KDb3CheckNumRecords)); |
753 CheckRecordCount(_L("table3")); |
1031 TEST2(err, KErrNone); |
754 CheckIndexCount(0); |
1032 TRAP(err, CheckNumberIndicesL(0)); |
|
1033 TEST2(err, KErrNone); |
|
1034 |
755 |
1035 // Attach a shared, secure database - the db5 config file should not be processed |
756 // Attach a shared, secure database - the db5 config file should not be processed |
1036 TheTest.Printf(_L("===NewDbCfgAttach: Attach shared, secure database\r\n")); |
757 TheTest.Printf(_L("===NewDbCfgAttach: Attach shared, secure database\r\n")); |
1037 err = TheDb.Attach(KCfgDb5, KAttachDb5); |
758 err = TheDb.Attach(KCfgDb5, KAttachDb5); |
1038 TEST2(err, KErrNone); |
759 TEST2(err, KErrNone); |
1039 TRAP(err, CheckNumberRecordsL(KDb5CheckNumRecords)); // there should still be only 1 record in the table |
760 CheckRecordCount(_L("table5")); |
1040 TEST2(err, KErrNone); |
761 CheckIndexCount(0); // there should still be no indices in the table |
1041 TRAP(err, CheckNumberIndicesL(0)); // there should still be no indices in the table |
|
1042 TEST2(err, KErrNone); |
|
1043 TheDb.Close(); |
762 TheDb.Close(); |
1044 CheckSystemSettingsTable(KCfgDb5, 1); // check that the config file has been processed for db1 |
763 CheckSystemSettingsTable(KCfgDb5, 1); // check that the config file has been processed for db1 |
1045 CheckSystemSettingsTable(KCfgDb3, 0); |
764 CheckSystemSettingsTable(KCfgDb3, 0); |
1046 } |
765 } |
1047 |
766 |
1090 |
809 |
1091 sqlite3 *dbHandle = NULL; |
810 sqlite3 *dbHandle = NULL; |
1092 TInt rc = sqlite3_open((const char*)dbFileName.PtrZ(), &dbHandle); |
811 TInt rc = sqlite3_open((const char*)dbFileName.PtrZ(), &dbHandle); |
1093 TEST2(rc, SQLITE_OK); |
812 TEST2(rc, SQLITE_OK); |
1094 |
813 |
1095 TBuf<100> queryBuf; |
814 _LIT(KGetCollationDllSql, "SELECT CollationDllName FROM symbian_settings"); |
815 TBuf<100> queryBuf; |
|
1096 queryBuf.Append(KGetCollationDllSql()); |
816 queryBuf.Append(KGetCollationDllSql()); |
1097 |
817 |
1098 sqlite3_stmt* stmtHandle = NULL; |
818 sqlite3_stmt* stmtHandle = NULL; |
1099 const void* stmtTailZ = NULL; |
819 const void* stmtTailZ = NULL; |
1100 rc = sqlite3_prepare16_v2(dbHandle, queryBuf.PtrZ(), -1, &stmtHandle, &stmtTailZ); |
820 rc = sqlite3_prepare16_v2(dbHandle, queryBuf.PtrZ(), -1, &stmtHandle, &stmtTailZ); |
1135 @SYMTestExpectedResults The test must not fail |
855 @SYMTestExpectedResults The test must not fail |
1136 @SYMCR LMAN-79SJ7L |
856 @SYMCR LMAN-79SJ7L |
1137 */ |
857 */ |
1138 void DoDbCfgTests() |
858 void DoDbCfgTests() |
1139 { |
859 { |
1140 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4010 DoDbCfgTests ")); |
|
1141 |
|
1142 // Do 'open' tests for new db config file feature |
860 // Do 'open' tests for new db config file feature |
1143 DoCfgOpenTests(); // open the test databases |
861 DoCfgOpenTests(1); // open the test databases |
1144 DoUpgradedCfgOpenTest(); // upgrade the config file for db1 and reopen the test databases |
862 DoUpgradedCfgOpenTest(); // upgrade the config file for db1 and reopen the test databases |
1145 DoBadCfgOpenTests(); // corrupt the config file for db1 (in a variety of ways) and reopen the test databases |
863 DoBadCfgOpenTests(); // corrupt the config file for db1 (in a variety of ways) and reopen the test databases |
1146 DoNewDbCfgOpenTest(); // create a db for which a config file already exists and then open the db |
864 DoNewDbCfgOpenTest(); // create a db for which a config file already exists and then open the db |
1147 |
865 |
1148 // Recreate the original dbs and config files |
866 // Recreate the original dbs and config files |
1159 DeleteCfgFilesAndDbs(); |
877 DeleteCfgFilesAndDbs(); |
1160 CreateCfgFilesAndDbs(); |
878 CreateCfgFilesAndDbs(); |
1161 |
879 |
1162 // Do the test that causes both reindexing and db configuration to occur when db1 is opened |
880 // Do the test that causes both reindexing and db configuration to occur when db1 is opened |
1163 ResetStoredCollationDll(); |
881 ResetStoredCollationDll(); |
1164 DoCfgOpenTests(); |
882 DoCfgOpenTests(1); |
1165 CheckCollationDllUpdated(); |
883 CheckCollationDllUpdated(); |
1166 |
884 |
1167 // Recreate the original dbs and config files |
885 // Recreate the original dbs and config files |
1168 DeleteCfgFilesAndDbs(); |
886 DeleteCfgFilesAndDbs(); |
1169 CreateCfgFilesAndDbs(); |
887 CreateCfgFilesAndDbs(); |
1189 @SYMTestExpectedResults The test must not fail |
907 @SYMTestExpectedResults The test must not fail |
1190 @SYMCR LMAN-79SJ7L |
908 @SYMCR LMAN-79SJ7L |
1191 */ |
909 */ |
1192 void DoDbCfgOOMTests() |
910 void DoDbCfgOOMTests() |
1193 { |
911 { |
1194 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4013 DoDbCfgOOMTests ")); |
|
1195 |
|
1196 // Recreate the original dbs and config files |
912 // Recreate the original dbs and config files |
1197 DeleteCfgFilesAndDbs(); |
913 DeleteCfgFilesAndDbs(); |
1198 CreateCfgFilesAndDbs(); |
914 CreateCfgFilesAndDbs(); |
1199 |
915 |
1200 // The server is stopped at the end of CreateCfgFilesAndDbs(). |
916 // The server is stopped at the end of CreateCfgFilesAndDbs(). |
1266 @SYMTestExpectedResults The test must not fail |
982 @SYMTestExpectedResults The test must not fail |
1267 @SYMCR LMAN-79SJ7L |
983 @SYMCR LMAN-79SJ7L |
1268 */ |
984 */ |
1269 void DoDbCfgFileIOFailuresTests() |
985 void DoDbCfgFileIOFailuresTests() |
1270 { |
986 { |
1271 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4014 DoDbCfgFileIOFailuresTests ")); |
|
1272 |
|
1273 // Recreate the original dbs and config files |
987 // Recreate the original dbs and config files |
1274 DeleteCfgFilesAndDbs(); |
988 DeleteCfgFilesAndDbs(); |
1275 CreateCfgFilesAndDbs(); |
989 CreateCfgFilesAndDbs(); |
1276 |
990 |
1277 // The server is stopped at the end of CreateCfgFilesAndDbs(). |
991 // The server is stopped at the end of CreateCfgFilesAndDbs(). |
1344 @SYMTestExpectedResults The test must not fail |
1058 @SYMTestExpectedResults The test must not fail |
1345 @SYMCR LMAN-79SJ7L |
1059 @SYMCR LMAN-79SJ7L |
1346 */ |
1060 */ |
1347 void DoDbCfgPerfTests() |
1061 void DoDbCfgPerfTests() |
1348 { |
1062 { |
1349 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4015 DoDbCfgPerfTests ")); |
|
1350 |
|
1351 // Recreate the original dbs |
1063 // Recreate the original dbs |
1352 DeleteCfgFilesAndDbs(); |
1064 DeleteCfgFilesAndDbs(); |
1353 CreateCfgDbs(); |
1065 CreateCfgDbs(); |
1354 (void)KillProcess(KSqlSrvName); // stop the server |
1066 KillSqlServer(); |
1355 |
1067 |
1356 // Measure the start up time of the server when |
1068 // Measure the start up time of the server when |
1357 // there are no database configuration files to be cached. |
1069 // there are no database configuration files to be cached. |
1358 // Open Db4 (public db): |
1070 // Open Db4 (public db): |
1359 // No reindexing required |
1071 // No reindexing required |
1360 // Database configuration is not considered |
1072 // Database configuration is not considered |
1361 TUint32 start = User::FastCounter(); |
1073 TUint32 start = User::FastCounter(); |
1362 TInt err = TheDb.Open(KCfgDb4); |
1074 TInt err = TheDb.Open(KCfgDb4); |
1363 TUint32 end = User::FastCounter(); |
1075 TUint32 end = User::FastCounter(); |
1364 TEST2(err, KErrNone); |
1076 TEST2(err, KErrNone); |
1365 TRAP(err, CheckNumberRecordsL(KDb4CheckNumRecords)); |
1077 CheckRecordCount(_L("table4")); |
1366 TEST2(err, KErrNone); |
1078 CheckIndexCount(0); |
1367 TRAP(err, CheckNumberIndicesL(0)); |
|
1368 TEST2(err, KErrNone); |
|
1369 TheDb.Close(); |
1079 TheDb.Close(); |
1370 CheckSystemSettingsTable(KCfgDb4, 0); |
1080 CheckSystemSettingsTable(KCfgDb4, 0); |
1371 TInt ms = CalcTimeMs(start, end); |
1081 TInt ms = CalcTimeMs(start, end); |
1372 TheTest.Printf(_L("Execution time: Server startup (via Open call) - no database config files to cache: %d ms\r\n"), ms); |
1082 TheTest.Printf(_L("Execution time: Server startup (via Open call) - no database config files to cache: %d ms\r\n"), ms); |
1373 |
1083 |
1378 // Database configuration is considered but no config file is found |
1088 // Database configuration is considered but no config file is found |
1379 start = User::FastCounter(); |
1089 start = User::FastCounter(); |
1380 err = TheDb.Open(KCfgDb1); |
1090 err = TheDb.Open(KCfgDb1); |
1381 end = User::FastCounter(); |
1091 end = User::FastCounter(); |
1382 TEST2(err, KErrNone); |
1092 TEST2(err, KErrNone); |
1383 TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords)); |
1093 CheckRecordCount(_L("table1")); |
1384 TEST2(err, KErrNone); |
1094 CheckIndexCount(0); |
1385 TRAP(err, CheckNumberIndicesL(0)); |
|
1386 TEST2(err, KErrNone); |
|
1387 TheDb.Close(); |
1095 TheDb.Close(); |
1388 CheckSystemSettingsTable(KCfgDb1, 0); |
1096 CheckSystemSettingsTable(KCfgDb1, 0); |
1389 ms = CalcTimeMs(start, end); |
1097 ms = CalcTimeMs(start, end); |
1390 TheTest.Printf(_L("Execution time: Open shared, secure Db1 - no config file is found: %d ms\r\n"), ms); |
1098 TheTest.Printf(_L("Execution time: Open shared, secure Db1 - no config file is found: %d ms\r\n"), ms); |
1391 |
1099 |
1405 ms = CalcTimeMs(start, end); |
1113 ms = CalcTimeMs(start, end); |
1406 TheTest.Printf(_L("Execution time: Attach shared, secure Db1 - database config is not considered: %d ms\r\n"), ms); |
1114 TheTest.Printf(_L("Execution time: Attach shared, secure Db1 - database config is not considered: %d ms\r\n"), ms); |
1407 |
1115 |
1408 // Create the 4 version 01 config files now |
1116 // Create the 4 version 01 config files now |
1409 CreateCfgFiles(); |
1117 CreateCfgFiles(); |
1410 (void)KillProcess(KSqlSrvName); // stop the server so that the files are found when it is restarted |
1118 KillSqlServer(); // stop the server so that the files are found when it is restarted |
1411 |
1119 |
1412 // Measure the start up time of the server when |
1120 // Measure the start up time of the server when |
1413 // there are 4 database configuration files to be cached. |
1121 // there are 4 database configuration files to be cached. |
1414 // Open Db4 (public db): |
1122 // Open Db4 (public db): |
1415 // No reindexing required |
1123 // No reindexing required |
1416 // Database configuration is not considered |
1124 // Database configuration is not considered |
1417 start = User::FastCounter(); |
1125 start = User::FastCounter(); |
1418 err = TheDb.Open(KCfgDb4); |
1126 err = TheDb.Open(KCfgDb4); |
1419 end = User::FastCounter(); |
1127 end = User::FastCounter(); |
1420 TEST2(err, KErrNone); |
1128 TEST2(err, KErrNone); |
1421 TRAP(err, CheckNumberRecordsL(KDb4CheckNumRecords)); |
1129 CheckRecordCount(_L("table4")); |
1422 TEST2(err, KErrNone); |
1130 CheckIndexCount(0); |
1423 TRAP(err, CheckNumberIndicesL(0)); |
|
1424 TEST2(err, KErrNone); |
|
1425 TheDb.Close(); |
1131 TheDb.Close(); |
1426 CheckSystemSettingsTable(KCfgDb4, 0); |
1132 CheckSystemSettingsTable(KCfgDb4, 0); |
1427 ms = CalcTimeMs(start, end); |
1133 ms = CalcTimeMs(start, end); |
1428 TheTest.Printf(_L("Execution time: Server startup (via Open call) - 4 database config files to cache: %d ms\r\n"), ms); |
1134 TheTest.Printf(_L("Execution time: Server startup (via Open call) - 4 database config files to cache: %d ms\r\n"), ms); |
1429 |
1135 |
1434 // Database configuration is considered, a file is found and config is applied (3 indices are created) |
1140 // Database configuration is considered, a file is found and config is applied (3 indices are created) |
1435 start = User::FastCounter(); |
1141 start = User::FastCounter(); |
1436 err = TheDb.Open(KCfgDb1); |
1142 err = TheDb.Open(KCfgDb1); |
1437 end = User::FastCounter(); |
1143 end = User::FastCounter(); |
1438 TEST2(err, KErrNone); |
1144 TEST2(err, KErrNone); |
1439 TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords)); |
1145 CheckRecordCount(_L("table1")); |
1440 TEST2(err, KErrNone); |
1146 CheckIndexCount(3); |
1441 TRAP(err, CheckNumberIndicesL(3)); |
|
1442 TEST2(err, KErrNone); |
|
1443 TheDb.Close(); |
1147 TheDb.Close(); |
1444 CheckSystemSettingsTable(KCfgDb1, 1); |
1148 CheckSystemSettingsTable(KCfgDb1, 1); |
1445 ms = CalcTimeMs(start, end); |
1149 ms = CalcTimeMs(start, end); |
1446 TheTest.Printf(_L("Execution time: Open shared, secure Db1 - config file is found and applied: %d ms\r\n"), ms); |
1150 TheTest.Printf(_L("Execution time: Open shared, secure Db1 - config file is found and applied: %d ms\r\n"), ms); |
1447 |
1151 |
1452 // Database configuration is considered, a file is found but it has already been processed |
1156 // Database configuration is considered, a file is found but it has already been processed |
1453 start = User::FastCounter(); |
1157 start = User::FastCounter(); |
1454 err = TheDb.Open(KCfgDb1); |
1158 err = TheDb.Open(KCfgDb1); |
1455 end = User::FastCounter(); |
1159 end = User::FastCounter(); |
1456 TEST2(err, KErrNone); |
1160 TEST2(err, KErrNone); |
1457 TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords)); |
1161 CheckRecordCount(_L("table1")); |
1458 TEST2(err, KErrNone); |
1162 CheckIndexCount(3); |
1459 TRAP(err, CheckNumberIndicesL(3)); |
|
1460 TEST2(err, KErrNone); |
|
1461 TheDb.Close(); |
1163 TheDb.Close(); |
1462 CheckSystemSettingsTable(KCfgDb1, 1); |
1164 CheckSystemSettingsTable(KCfgDb1, 1); |
1463 ms = CalcTimeMs(start, end); |
1165 ms = CalcTimeMs(start, end); |
1464 TheTest.Printf(_L("Execution time: Open shared, secure Db1 - config file is found but already processed: %d ms\r\n"), ms); |
1166 TheTest.Printf(_L("Execution time: Open shared, secure Db1 - config file is found but already processed: %d ms\r\n"), ms); |
1465 |
1167 |
1478 CheckSystemSettingsTable(KCfgDb1, 1); |
1180 CheckSystemSettingsTable(KCfgDb1, 1); |
1479 ms = CalcTimeMs(start, end); |
1181 ms = CalcTimeMs(start, end); |
1480 TheTest.Printf(_L("Execution time: Attach shared, secure Db1 - database config is not considered: %d ms\r\n"), ms); |
1182 TheTest.Printf(_L("Execution time: Attach shared, secure Db1 - database config is not considered: %d ms\r\n"), ms); |
1481 } |
1183 } |
1482 |
1184 |
1483 void TestStatementsL() |
1185 void TestStatements() |
1484 { |
1186 { |
1485 _LIT(KDbName, "attachDb"); |
1187 _LIT(KDbName, "attachDb"); |
1486 _LIT(KCreateIndex, "CREATE INDEX idx ON tbl(ColA)"); |
|
1487 _LIT(KCreateIndexIfNotExists, "CREATE INDEX IF NOT EXISTS idx ON tbl(ColA)"); |
|
1488 _LIT(KCreateUniqueIndex, "CREATE UNIQUE INDEX idx ON tbl(ColA)"); |
|
1489 _LIT(KNonSupported, "CREATE idx ON tbl(ColA)"); |
|
1490 TBuf<200> buf; |
1188 TBuf<200> buf; |
1491 |
1189 |
1492 // supported statements |
1190 // supported statements |
1493 |
1191 TBool rc = IsStatementSupported(_L("CREATE INDEX idx ON tbl(ColA)"), KDbName, buf); |
1494 TBool rc = IsStatementSupported(KCreateIndex, KDbName, buf); |
|
1495 TEST(rc); |
1192 TEST(rc); |
1496 |
1193 rc = IsStatementSupported(_L("CREATE INDEX IF NOT EXISTS idx ON tbl(ColA)"), KDbName, buf); |
1497 rc = IsStatementSupported(KCreateIndexIfNotExists, KDbName, buf); |
|
1498 TEST(rc); |
1194 TEST(rc); |
1499 |
1195 |
1500 // unsupported statements |
1196 // unsupported statements |
1501 rc = IsStatementSupported(KCreateUniqueIndex, KDbName, buf); |
1197 rc = IsStatementSupported(_L("CREATE UNIQUE INDEX idx ON tbl(ColA)"), KDbName, buf); |
1502 TEST(!rc); |
1198 TEST(!rc); |
1503 |
1199 rc = IsStatementSupported(_L("CREATE idx ON tbl(ColA)"), KDbName, buf); |
1504 rc = IsStatementSupported(KNonSupported, KDbName, buf); |
|
1505 TEST(!rc); |
1200 TEST(!rc); |
1506 } |
1201 } |
1507 |
1202 |
1508 /** |
1203 /** |
1509 @SYMTestCaseID SYSLIB-SQL-UT-4030 |
1204 @SYMTestCaseID SYSLIB-SQL-UT-4030 |
1516 @SYMTestExpectedResults The test must not fail |
1211 @SYMTestExpectedResults The test must not fail |
1517 @SYMDEF DEF118058 |
1212 @SYMDEF DEF118058 |
1518 */ |
1213 */ |
1519 void DoIsStatementSupportedTests() |
1214 void DoIsStatementSupportedTests() |
1520 { |
1215 { |
1521 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4030 DoIsStatementSupportedTests ")); |
1216 TestStatements(); |
1522 TInt err = KErrNone; |
|
1523 TRAP(err, TestStatementsL()); |
|
1524 TEST2(err, KErrNone); |
|
1525 } |
1217 } |
1526 |
1218 |
1527 void DoLongDbNameTest() |
1219 void DoLongDbNameTest() |
1528 { |
1220 { |
1529 TheTest.Next(_L("'Long database name' tests")); |
|
1530 //Create the database |
1221 //Create the database |
1531 RSqlSecurityPolicy securityPolicy; |
1222 RSqlSecurityPolicy securityPolicy = CreateSecurityPolicy(); |
1532 TInt err = DoCreateSecurityPolicy(securityPolicy); |
1223 |
1533 TEST2(err, KErrNone); |
1224 TInt err = TheDb.Create(KLongDbName1, securityPolicy); |
1534 err = TheDb.Create(KLongDbName1, securityPolicy); |
|
1535 TEST2(err, KErrNone); |
1225 TEST2(err, KErrNone); |
1536 err = TheDb.Exec(_L("CREATE TABLE table1(i1 INTEGER, i2 INTEGER, i3 INTEGER)")); |
1226 err = TheDb.Exec(_L("CREATE TABLE table1(i1 INTEGER, i2 INTEGER, i3 INTEGER)")); |
1537 TEST(err >= 0); |
1227 TEST(err >= 0); |
1538 err = TheDb.Exec(_L("INSERT INTO table1 (i1,i2,i3) values(1,2,3)")); |
1228 err = TheDb.Exec(_L("INSERT INTO table1 (i1,i2,i3) values(1,2,3)")); |
1539 TEST(err == 1); |
1229 TEST(err == 1); |
1540 TheDb.Close(); |
1230 TheDb.Close(); |
1541 //Kill the server (to reload config file names at the server startup) |
1231 //Kill the server (to reload config file names at the server startup) |
1542 (void)KillProcess(KSqlSrvName); |
1232 KillSqlServer(); |
1543 /////////////////////////////////////////////////////////////////////// |
1233 /////////////////////////////////////////////////////////////////////// |
1544 TheTest.Printf(_L("Open a database with a long name\r\n")); |
1234 TheTest.Printf(_L("Open a database with a long name\r\n")); |
1545 //Create cfg file |
1235 //Create cfg file |
1546 RFile file; |
1236 RFile file; |
1547 TFileName fileName; |
1237 TFileName fileName; |
1552 file.Close(); |
1242 file.Close(); |
1553 TEST2(err, KErrNone); |
1243 TEST2(err, KErrNone); |
1554 //Open the database |
1244 //Open the database |
1555 err = TheDb.Open(KLongDbName1); |
1245 err = TheDb.Open(KLongDbName1); |
1556 TEST2(err, KErrNone); |
1246 TEST2(err, KErrNone); |
1557 TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords)); // there should still be only 1 record in the table |
1247 CheckRecordCount(_L("table1")); |
1558 TEST2(err, KErrNone); |
1248 CheckIndexCount(1); // there should now be 1 index in the table |
1559 TRAP(err, CheckNumberIndicesL(1)); // there should now be 1 index in the table |
|
1560 TEST2(err, KErrNone); |
|
1561 TheDb.Close(); |
1249 TheDb.Close(); |
1562 const TInt KVersion = 1; |
1250 const TInt KVersion = 1; |
1563 CheckSystemSettingsTable(KLongDbName1, KVersion); // check that the ops in the specified config file have been applied |
1251 CheckSystemSettingsTable(KLongDbName1, KVersion); // check that the ops in the specified config file have been applied |
1564 /////////////////////////////////////////////////////////////////////// |
1252 /////////////////////////////////////////////////////////////////////// |
1565 TheTest.Printf(_L("Attach a database with a long logical name\r\n")); |
1253 TheTest.Printf(_L("Attach a database with a long logical name\r\n")); |
1572 TEST(err >= 0); |
1260 TEST(err >= 0); |
1573 err = TheDb.Exec(_L("INSERT INTO table1 (i1,i2,i3) values(1,2,3)")); |
1261 err = TheDb.Exec(_L("INSERT INTO table1 (i1,i2,i3) values(1,2,3)")); |
1574 TEST(err == 1); |
1262 TEST(err == 1); |
1575 TheDb.Close(); |
1263 TheDb.Close(); |
1576 //Kill the server (to reload config file names at the server startup) |
1264 //Kill the server (to reload config file names at the server startup) |
1577 (void)KillProcess(KSqlSrvName); |
1265 KillSqlServer(); |
1578 //Open the main database |
1266 //Open the main database |
1579 err = TheDb.Open(KCfgDb1); |
1267 err = TheDb.Open(KCfgDb1); |
1580 securityPolicy.Close(); |
1268 securityPolicy.Close(); |
1581 TEST2(err, KErrNone); |
1269 TEST2(err, KErrNone); |
1582 //Attach a database with a very long logical name |
1270 //Attach a database with a very long logical name |
1591 CheckSystemSettingsTable(KLongDbName1, KVersion); // check that the ops in the specified config file have been applied |
1279 CheckSystemSettingsTable(KLongDbName1, KVersion); // check that the ops in the specified config file have been applied |
1592 //Cleanup |
1280 //Cleanup |
1593 (void)RSqlDatabase::Delete(KLongDbName1); |
1281 (void)RSqlDatabase::Delete(KLongDbName1); |
1594 } |
1282 } |
1595 |
1283 |
1284 void DoTests() |
|
1285 { |
|
1286 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4010 Database config files test")); |
|
1287 DoDbCfgTests(); |
|
1288 |
|
1289 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4013 Database config files OOM test")); |
|
1290 DoDbCfgOOMTests(); |
|
1291 |
|
1292 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4014 Database config files file I/O error simulation test")); |
|
1293 DoDbCfgFileIOFailuresTests(); |
|
1294 |
|
1295 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4015 Database config files performance test")); |
|
1296 DoDbCfgPerfTests(); |
|
1297 |
|
1298 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4030 Database config files - supported SQl statements test")); |
|
1299 DoIsStatementSupportedTests(); |
|
1300 |
|
1301 TheTest.Next(_L("'Long database name' tests")); |
|
1302 DoLongDbNameTest(); |
|
1303 } |
|
1304 |
|
1596 #endif //SYSLIBS_TEST |
1305 #endif //SYSLIBS_TEST |
1597 |
1306 |
1598 TInt E32Main() |
1307 TInt E32Main() |
1599 { |
1308 { |
1600 TheTest.Title(); |
1309 TheTest.Title(); |
1603 TheTest(tc != NULL); |
1312 TheTest(tc != NULL); |
1604 |
1313 |
1605 __UHEAP_MARK; |
1314 __UHEAP_MARK; |
1606 |
1315 |
1607 #ifdef SYSLIBS_TEST |
1316 #ifdef SYSLIBS_TEST |
1608 TheTest.Start(_L("t_sqldbconfigfile tests")); |
1317 TheTest.Start(_L("Setting up the test environment")); |
1609 |
|
1610 // Set up the test environment |
|
1611 SetupTestEnv(); |
1318 SetupTestEnv(); |
1612 //Init sqlite library |
|
1613 sqlite3SymbianLibInit(); |
1319 sqlite3SymbianLibInit(); |
1614 |
1320 DoTests(); |
1615 // Do tests for database config files |
|
1616 DoDbCfgTests(); |
|
1617 |
|
1618 // Do OOM tests for database config files |
|
1619 DoDbCfgOOMTests(); |
|
1620 |
|
1621 // Do file I/O failure tests for database config files |
|
1622 DoDbCfgFileIOFailuresTests(); |
|
1623 |
|
1624 // Do performance tests for database config files |
|
1625 DoDbCfgPerfTests(); |
|
1626 |
|
1627 // Test IsStatementSupportedLC function |
|
1628 DoIsStatementSupportedTests(); |
|
1629 |
|
1630 //Test with a very long database file (and config file) name |
|
1631 DoLongDbNameTest(); |
|
1632 |
|
1633 // Destroy the test environment |
|
1634 DestroyTestEnv(); |
1321 DestroyTestEnv(); |
1635 sqlite3SymbianLibFinalize(); |
1322 sqlite3SymbianLibFinalize(); |
1636 CloseSTDLIB(); |
1323 CloseSTDLIB(); |
1637 |
|
1638 TheTest.End(); |
1324 TheTest.End(); |
1639 #else |
1325 #else |
1640 TheTest.Start(_L("This test works only if the whole SQL component is built with SYSLIBS_TEST macro defined!")); |
1326 TheTest.Start(_L("This test works only if the whole SQL component is built with SYSLIBS_TEST macro defined!")); |
1641 TheTest.End(); |
1327 TheTest.End(); |
1642 #endif |
1328 #endif |