|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <bautils.h> |
|
18 #include <sqldb.h> |
|
19 #include <stdlib.h> |
|
20 #include "sqlite3.h" |
|
21 #include "SqliteSymbian.h" |
|
22 |
|
23 |
|
24 /////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
|
26 RTest TheTest(_L("t_sqlcompact3 test")); |
|
27 RSqlDatabase TheDb; |
|
28 RSqlStatement TheStmt; |
|
29 |
|
30 _LIT(KTestDir, "c:\\test\\"); |
|
31 _LIT(KTestDbName1, "c:\\test\\t_sqlcompact3_1.db"); |
|
32 _LIT(KTestPrivDbName, "c:\\private\\21212124\\t_sqlcompact3_2.db"); |
|
33 _LIT(KTestPrivDbNameZ,"z:\\private\\21212124\\t_sqldb1.db");//Created outside the test app |
|
34 _LIT(KTestPrivDbNameC,"c:\\private\\21212124\\t_sqldb1.db"); |
|
35 _LIT(KTestSecureDbName, "c:[21212124]t_sqlcompact3_3.db"); |
|
36 _LIT8(KTestFullSecureDbNameZ, "c:\\private\\10281e17\\[21212124]t_sqlcompact3_3.db\x0"); |
|
37 |
|
38 const TInt KAutoVacuum = 1; |
|
39 const TInt KIncrementalVacuum = 2; |
|
40 const TInt KSqlDefaultVacuum = KIncrementalVacuum; |
|
41 |
|
42 //In order to be able to compile the test, the following variables are defined (used inside the OS porting layer, when _SQLPROFILER macro is defined) |
|
43 #ifdef _SQLPROFILER |
|
44 TInt TheSqlSrvProfilerFileRead = 0; |
|
45 TInt TheSqlSrvProfilerFileWrite = 0; |
|
46 TInt TheSqlSrvProfilerFileSync = 0; |
|
47 TInt TheSqlSrvProfilerFileSetSize = 0; |
|
48 #endif |
|
49 |
|
50 /////////////////////////////////////////////////////////////////////////////////////// |
|
51 |
|
52 void DestroyTestEnv() |
|
53 { |
|
54 TheStmt.Close(); |
|
55 TheDb.Close(); |
|
56 (void)RSqlDatabase::Delete(KTestPrivDbNameC); |
|
57 (void)RSqlDatabase::Delete(KTestSecureDbName); |
|
58 (void)RSqlDatabase::Delete(KTestPrivDbName); |
|
59 (void)RSqlDatabase::Delete(KTestDbName1); |
|
60 sqlite3SymbianLibFinalize(); |
|
61 CloseSTDLIB(); |
|
62 } |
|
63 |
|
64 /////////////////////////////////////////////////////////////////////////////////////// |
|
65 /////////////////////////////////////////////////////////////////////////////////////// |
|
66 //Test macros and functions |
|
67 void Check(TInt aValue, TInt aLine) |
|
68 { |
|
69 if(!aValue) |
|
70 { |
|
71 DestroyTestEnv(); |
|
72 TheTest(EFalse, aLine); |
|
73 } |
|
74 } |
|
75 void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
76 { |
|
77 if(aValue != aExpected) |
|
78 { |
|
79 DestroyTestEnv(); |
|
80 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
81 TheTest(EFalse, aLine); |
|
82 } |
|
83 } |
|
84 #define TEST(arg) ::Check((arg), __LINE__) |
|
85 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
86 |
|
87 /////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
89 void CreateTestEnv() |
|
90 { |
|
91 RFs fs; |
|
92 TInt err = fs.Connect(); |
|
93 TEST2(err, KErrNone); |
|
94 |
|
95 err = fs.MkDir(KTestDir); |
|
96 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
97 |
|
98 err = fs.CreatePrivatePath(EDriveC); |
|
99 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
100 |
|
101 fs.Close(); |
|
102 |
|
103 sqlite3SymbianLibInit(); |
|
104 } |
|
105 |
|
106 /////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
108 /** |
|
109 @SYMTestCaseID SYSLIB-SQL-UT-4056 |
|
110 @SYMTestCaseDesc Manual compaction - configuration test. |
|
111 The test creates a database with a manual compaction mode. |
|
112 The test reopens the database and verifies that the compaction mode is persistent and is still manual. |
|
113 Then the test reopens the database using different compaction mode in the configuration string and |
|
114 verifies that the original (manual) compaction mode cannot be changed when the database is opened. |
|
115 @SYMTestPriority Medium |
|
116 @SYMTestActions Manual compaction - configuration test. |
|
117 @SYMTestExpectedResults Test must not fail |
|
118 @SYMREQ REQ10274 |
|
119 REQ10402 |
|
120 */ |
|
121 void CompactConfigTest1L() |
|
122 { |
|
123 //Create a test database with "manual" compaction mode |
|
124 _LIT8(KConfigStr1, "encoding=utf8;compaction=manual"); |
|
125 TInt err = TheDb.Create(KTestDbName1, &KConfigStr1); |
|
126 TEST2(err, KErrNone); |
|
127 //Check the vacuum mode. The SQLite vacuum mode should be "incremental" |
|
128 TSqlScalarFullSelectQuery scalarQuery(TheDb); |
|
129 TInt compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
130 TEST2(compact, KIncrementalVacuum); |
|
131 TheDb.Close(); |
|
132 //Close and open the database again. The SQLite vacuum mode should be "incremental". |
|
133 err = TheDb.Open(KTestDbName1); |
|
134 TEST2(err, KErrNone); |
|
135 scalarQuery.SetDatabase(TheDb); |
|
136 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
137 TEST2(compact, KIncrementalVacuum); |
|
138 TheDb.Close(); |
|
139 //Close and open the database again with a config string with "auto" compaction mode. |
|
140 //The SQLite vacuum mode should stay unchanged. |
|
141 _LIT8(KConfigStr2, "compaction=auto"); |
|
142 err = TheDb.Open(KTestDbName1, &KConfigStr2); |
|
143 TEST2(err, KErrNone); |
|
144 scalarQuery.SetDatabase(TheDb); |
|
145 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
146 TEST2(compact, KIncrementalVacuum); |
|
147 TheDb.Close(); |
|
148 //Delete database |
|
149 err = RSqlDatabase::Delete(KTestDbName1); |
|
150 TEST2(err, KErrNone); |
|
151 } |
|
152 |
|
153 /** |
|
154 @SYMTestCaseID SYSLIB-SQL-UT-4057 |
|
155 @SYMTestCaseDesc Auto compaction - configuration test. |
|
156 The test creates a database with an auto compaction mode. |
|
157 The test reopens the database and verifies that the compaction mode is persistent and is still auto. |
|
158 Then the test reopens the database using different compaction mode in the configuration string and |
|
159 verifies that the original (auto) compaction mode cannot be changed when the database is opened. |
|
160 @SYMTestPriority Medium |
|
161 @SYMTestActions Auto compaction - configuration test. |
|
162 @SYMTestExpectedResults Test must not fail |
|
163 @SYMREQ REQ10274 |
|
164 REQ10400 |
|
165 */ |
|
166 void CompactConfigTest2L() |
|
167 { |
|
168 //Create a test database with "auto" compaction mode |
|
169 _LIT8(KConfigStr1, "encoding=utf8;compaction=auto"); |
|
170 TInt err = TheDb.Create(KTestDbName1, &KConfigStr1); |
|
171 TEST2(err, KErrNone); |
|
172 //Check the vacuum mode. The SQLite vacuum mode should be "auto" |
|
173 TSqlScalarFullSelectQuery scalarQuery(TheDb); |
|
174 TInt compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
175 TEST2(compact, KAutoVacuum); |
|
176 TheDb.Close(); |
|
177 //Create a test database with "synchronous" compaction mode |
|
178 err = RSqlDatabase::Delete(KTestDbName1); |
|
179 TEST2(err, KErrNone); |
|
180 _LIT8(KConfigStr3, "encoding=utf8;compaction=synchronous"); |
|
181 err = TheDb.Create(KTestDbName1, &KConfigStr3); |
|
182 TEST2(err, KErrNone); |
|
183 //Check the vacuum mode. The SQLite vacuum mode should be "auto" |
|
184 scalarQuery.SetDatabase(TheDb); |
|
185 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
186 TEST2(compact, KAutoVacuum); |
|
187 TheDb.Close(); |
|
188 //Close and open the database again. The SQLite vacuum mode should be "auto". |
|
189 err = TheDb.Open(KTestDbName1); |
|
190 TEST2(err, KErrNone); |
|
191 scalarQuery.SetDatabase(TheDb); |
|
192 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
193 TEST2(compact, KAutoVacuum); |
|
194 TheDb.Close(); |
|
195 //Close and open the database again with a config string with "background" compaction mode. |
|
196 //The SQLite vacuum mode should stay unchanged. |
|
197 _LIT8(KConfigStr2, "compaction=background"); |
|
198 err = TheDb.Open(KTestDbName1, &KConfigStr2); |
|
199 TEST2(err, KErrNone); |
|
200 scalarQuery.SetDatabase(TheDb); |
|
201 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
202 TEST2(compact, KAutoVacuum); |
|
203 TheDb.Close(); |
|
204 //Delete database |
|
205 err = RSqlDatabase::Delete(KTestDbName1); |
|
206 TEST2(err, KErrNone); |
|
207 } |
|
208 |
|
209 /** |
|
210 @SYMTestCaseID SYSLIB-SQL-UT-4058 |
|
211 @SYMTestCaseDesc Background compaction - configuration test. |
|
212 The test creates a database with a background compaction mode. |
|
213 The test reopens the database and verifies that the compaction mode is persistent and is still background. |
|
214 Then the test reopens the database using different compaction mode in the configuration string and |
|
215 verifies that the original (background) compaction mode cannot be changed when the database is opened. |
|
216 @SYMTestPriority Medium |
|
217 @SYMTestActions Background compaction - configuration test. |
|
218 @SYMTestExpectedResults Test must not fail |
|
219 @SYMREQ REQ10274 |
|
220 */ |
|
221 void CompactConfigTest3L() |
|
222 { |
|
223 //Create a test database with "background" compaction mode |
|
224 _LIT8(KConfigStr1, "encoding=utf8;compaction=background"); |
|
225 TInt err = TheDb.Create(KTestDbName1, &KConfigStr1); |
|
226 TEST2(err, KErrNone); |
|
227 //Check the vacuum mode. The SQLite vacuum mode should be "incremental" |
|
228 TSqlScalarFullSelectQuery scalarQuery(TheDb); |
|
229 TInt compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
230 TEST2(compact, KIncrementalVacuum); |
|
231 TheDb.Close(); |
|
232 //Close and open the database again. The SQLite vacuum mode should be "incremental". |
|
233 err = TheDb.Open(KTestDbName1); |
|
234 TEST2(err, KErrNone); |
|
235 scalarQuery.SetDatabase(TheDb); |
|
236 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
237 TEST2(compact, KIncrementalVacuum); |
|
238 TheDb.Close(); |
|
239 //Close and open the database again with a config string with "manual" compaction mode. |
|
240 //The SQLite vacuum mode should stay unchanged. |
|
241 _LIT8(KConfigStr2, "compaction=manual"); |
|
242 err = TheDb.Open(KTestDbName1, &KConfigStr2); |
|
243 TEST2(err, KErrNone); |
|
244 scalarQuery.SetDatabase(TheDb); |
|
245 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
246 TEST2(compact, KIncrementalVacuum); |
|
247 TheDb.Close(); |
|
248 //Delete database |
|
249 err = RSqlDatabase::Delete(KTestDbName1); |
|
250 TEST2(err, KErrNone); |
|
251 } |
|
252 |
|
253 /** |
|
254 @SYMTestCaseID SYSLIB-SQL-UT-4059 |
|
255 @SYMTestCaseDesc Background compaction - no configuration string test. |
|
256 The test creates a database without using a configuration string. |
|
257 The database should be created with default compaction mode - background. |
|
258 The test reopens the database and verifies that the compaction mode is persistent and is still background. |
|
259 Then the test reopens the database using different compaction mode in the configuration string and |
|
260 verifies that the original (background) compaction mode cannot be changed when the database is opened. |
|
261 @SYMTestPriority Medium |
|
262 @SYMTestActions Background compaction - no configuration string test. |
|
263 @SYMTestExpectedResults Test must not fail |
|
264 @SYMREQ REQ10273 |
|
265 REQ10274 |
|
266 */ |
|
267 void CompactConfigTest4L() |
|
268 { |
|
269 //Create a test database without configuration string |
|
270 TInt err = TheDb.Create(KTestDbName1); |
|
271 TEST2(err, KErrNone); |
|
272 //Check the vacuum mode. The SQLite vacuum mode should be KSqlDefaultVacuum |
|
273 TSqlScalarFullSelectQuery scalarQuery(TheDb); |
|
274 TInt compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
275 TEST2(compact, KSqlDefaultVacuum); |
|
276 TheDb.Close(); |
|
277 //Delete database |
|
278 err = RSqlDatabase::Delete(KTestDbName1); |
|
279 TEST2(err, KErrNone); |
|
280 //Create a test database with invalid configuration string |
|
281 _LIT8(KConfigStr1, "encoding=utf8;compaction=backgrund"); |
|
282 err = TheDb.Create(KTestDbName1, &KConfigStr1); |
|
283 TEST2(err, KErrNone); |
|
284 //Check the vacuum mode. The SQLite vacuum mode should be KSqlDefaultVacuum |
|
285 scalarQuery.SetDatabase(TheDb); |
|
286 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
287 TEST2(compact, KSqlDefaultVacuum); |
|
288 TheDb.Close(); |
|
289 //Delete database |
|
290 err = RSqlDatabase::Delete(KTestDbName1); |
|
291 TEST2(err, KErrNone); |
|
292 //Create a test database with invalid configuration string |
|
293 _LIT8(KConfigStr2, "compactin=background"); |
|
294 err = TheDb.Create(KTestDbName1, &KConfigStr2); |
|
295 TEST2(err, KErrNone); |
|
296 //Check the vacuum mode. The SQLite vacuum mode should be KSqlDefaultVacuum |
|
297 scalarQuery.SetDatabase(TheDb); |
|
298 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
299 TEST2(compact, KSqlDefaultVacuum); |
|
300 TheDb.Close(); |
|
301 //Delete database |
|
302 err = RSqlDatabase::Delete(KTestDbName1); |
|
303 TEST2(err, KErrNone); |
|
304 } |
|
305 |
|
306 /** |
|
307 @SYMTestCaseID SYSLIB-SQL-UT-4060 |
|
308 @SYMTestCaseDesc Private database and compaction configuration test. |
|
309 The test verifies that a private database can be created using auto, background or |
|
310 manual compaction mode and that the compaction mode does not chage after reopening |
|
311 the database. |
|
312 The test also verifies that if the database is legacy, read-only, then the compaction |
|
313 mode is auto. |
|
314 The test also verifies that if the database is legacy, r/w, then the compaction |
|
315 mode will be changed from auto to background. |
|
316 @SYMTestPriority Medium |
|
317 @SYMTestActions Private database and compaction configuration test. |
|
318 @SYMTestExpectedResults Test must not fail |
|
319 @SYMREQ REQ10273 |
|
320 REQ10274 |
|
321 REQ10400 |
|
322 REQ10402 |
|
323 */ |
|
324 void CompactConfigTest5L() |
|
325 { |
|
326 //Create a private test database with "auto" compaction mode |
|
327 _LIT8(KConfigStr1, "encoding=utf8;compaction=auto"); |
|
328 TInt err = TheDb.Create(KTestPrivDbName, &KConfigStr1); |
|
329 TEST2(err, KErrNone); |
|
330 //Check the vacuum mode. The SQLite vacuum mode should be "auto" |
|
331 TSqlScalarFullSelectQuery scalarQuery(TheDb); |
|
332 TInt compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
333 TEST2(compact, KAutoVacuum); |
|
334 TheDb.Close(); |
|
335 //Close and open the database again. The SQLite vacuum mode should be "auto". |
|
336 err = TheDb.Open(KTestPrivDbName); |
|
337 TEST2(err, KErrNone); |
|
338 scalarQuery.SetDatabase(TheDb); |
|
339 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
340 TEST2(compact, KAutoVacuum); |
|
341 TheDb.Close(); |
|
342 //Close and open the database again with a config string with "background" compaction mode. |
|
343 //The SQLite vacuum mode should stay unchanged. |
|
344 _LIT8(KConfigStr2, "compaction=background"); |
|
345 err = TheDb.Open(KTestPrivDbName, &KConfigStr2); |
|
346 TEST2(err, KErrNone); |
|
347 scalarQuery.SetDatabase(TheDb); |
|
348 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
349 TEST2(compact, KAutoVacuum); |
|
350 TheDb.Close(); |
|
351 //Delete database |
|
352 err = RSqlDatabase::Delete(KTestPrivDbName); |
|
353 TEST2(err, KErrNone); |
|
354 //Create a private test database - no config string |
|
355 err = TheDb.Create(KTestPrivDbName); |
|
356 TEST2(err, KErrNone); |
|
357 //Check the vacuum mode. The SQLite vacuum mode should be KSqlDefaultVacuum |
|
358 scalarQuery.SetDatabase(TheDb); |
|
359 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
360 TEST2(compact, KSqlDefaultVacuum); |
|
361 TheDb.Close(); |
|
362 //Close and open the database again. The SQLite vacuum mode should be KSqlDefaultVacuum. |
|
363 err = TheDb.Open(KTestPrivDbName); |
|
364 TEST2(err, KErrNone); |
|
365 scalarQuery.SetDatabase(TheDb); |
|
366 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
367 TEST2(compact, KSqlDefaultVacuum); |
|
368 TheDb.Close(); |
|
369 //Close and open the database again with a config string with "auto" compaction mode. |
|
370 //The SQLite vacuum mode should stay unchanged. |
|
371 err = TheDb.Open(KTestPrivDbName, &KConfigStr1); |
|
372 TEST2(err, KErrNone); |
|
373 scalarQuery.SetDatabase(TheDb); |
|
374 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
375 TEST2(compact, KSqlDefaultVacuum); |
|
376 TheDb.Close(); |
|
377 //Delete database |
|
378 err = RSqlDatabase::Delete(KTestPrivDbName); |
|
379 TEST2(err, KErrNone); |
|
380 //Open an existing private database that is read-only (on drive Z:) |
|
381 err = TheDb.Open(KTestPrivDbNameZ, &KConfigStr1); |
|
382 TEST2(err, KErrNone); |
|
383 //Check the vacuum mode. The SQLite compact mode should be "auto" (this is an old database (pre-"background compact" era)) |
|
384 scalarQuery.SetDatabase(TheDb); |
|
385 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
386 TEST2(compact, KAutoVacuum); |
|
387 TheDb.Close(); |
|
388 //Open the same database after copying it to drive C: (r/w private database). The compaction mode should change from auto to background. |
|
389 RFs fs; |
|
390 err = fs.Connect(); |
|
391 TEST2(err, KErrNone); |
|
392 CFileMan* fm = CFileMan::NewL(fs); |
|
393 TEST(fm != NULL); |
|
394 err = fm->Copy(KTestPrivDbNameZ, KTestPrivDbNameC); |
|
395 TEST2(err, KErrNone); |
|
396 //"Copy" operation executed without errors. Now it is a time to turn off the read-only |
|
397 //flag of the target file (which may be on if the source file is on a read-only drive) |
|
398 err = fs.SetAtt(KTestPrivDbNameC, 0, KEntryAttReadOnly); |
|
399 TEST2(err, KErrNone); |
|
400 delete fm; |
|
401 fs.Close(); |
|
402 err = TheDb.Open(KTestPrivDbNameC); |
|
403 TEST2(err, KErrNone); |
|
404 scalarQuery.SetDatabase(TheDb); |
|
405 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
406 TEST2(compact, KSqlDefaultVacuum); |
|
407 TheDb.Close(); |
|
408 (void)RSqlDatabase::Delete(KTestPrivDbNameC); |
|
409 } |
|
410 |
|
411 RSqlSecurityPolicy CreateTestSecurityPolicy() |
|
412 { |
|
413 const TSecurityPolicy KDefaultPolicy(TSecurityPolicy::EAlwaysPass); |
|
414 RSqlSecurityPolicy securityPolicy; |
|
415 TInt err = securityPolicy.Create(KDefaultPolicy); |
|
416 TEST2(err, KErrNone); |
|
417 return securityPolicy; |
|
418 } |
|
419 |
|
420 void TestCompactMode(TInt aExpectedCompactMode) |
|
421 { |
|
422 sqlite3 *dbHandle = NULL; |
|
423 TInt rc = sqlite3_open((const char*)KTestFullSecureDbNameZ().Ptr(), &dbHandle); |
|
424 TEST2(rc, SQLITE_OK); |
|
425 |
|
426 sqlite3_stmt* stmtHandle = NULL; |
|
427 const char* stmtTailZ = NULL; |
|
428 rc = sqlite3_prepare_v2(dbHandle, "PRAGMA auto_vacuum", -1, &stmtHandle, &stmtTailZ); |
|
429 TEST2(rc, SQLITE_OK); |
|
430 |
|
431 rc = sqlite3_step(stmtHandle); |
|
432 TEST2(rc, SQLITE_ROW); |
|
433 TInt compact = sqlite3_column_int(stmtHandle, 0); |
|
434 |
|
435 sqlite3_finalize(stmtHandle); |
|
436 sqlite3_close(dbHandle); |
|
437 |
|
438 TEST2(compact, aExpectedCompactMode); |
|
439 } |
|
440 |
|
441 /** |
|
442 @SYMTestCaseID SYSLIB-SQL-UT-4061 |
|
443 @SYMTestCaseDesc Secure shared database and compaction configuration test. |
|
444 The test verifies that a secure shared database can be created using auto, background or |
|
445 manual compaction mode and that the compaction mode does not chage after reopening |
|
446 the database. |
|
447 @SYMTestPriority Medium |
|
448 @SYMTestActions Secure shared database and compaction configuration test. |
|
449 @SYMTestExpectedResults Test must not fail |
|
450 @SYMREQ REQ10273 |
|
451 REQ10274 |
|
452 REQ10400 |
|
453 REQ10402 |
|
454 */ |
|
455 void CompactConfigTest6L() |
|
456 { |
|
457 //Create a secure test database with "auto" compaction mode. |
|
458 RSqlSecurityPolicy securityPolicy = CreateTestSecurityPolicy(); |
|
459 _LIT8(KConfigStr1, "encoding=utf8;compaction=auto"); |
|
460 TInt err = TheDb.Create(KTestSecureDbName, securityPolicy, &KConfigStr1); |
|
461 TEST2(err, KErrNone); |
|
462 securityPolicy.Close(); |
|
463 TheDb.Close(); |
|
464 //Check the vacuum mode. The SQLite vacuum mode should be "auto" |
|
465 TestCompactMode(KAutoVacuum); |
|
466 //Close and open the database again. The SQLite vacuum mode should be "auto". |
|
467 err = TheDb.Open(KTestSecureDbName); |
|
468 TEST2(err, KErrNone); |
|
469 TheDb.Close(); |
|
470 TestCompactMode(KAutoVacuum); |
|
471 //Close and open the database again with a config string with "background" compaction mode. |
|
472 //The SQLite vacuum mode should stay unchanged. |
|
473 _LIT8(KConfigStr2, "compaction=background"); |
|
474 err = TheDb.Open(KTestSecureDbName, &KConfigStr2); |
|
475 TEST2(err, KErrNone); |
|
476 TheDb.Close(); |
|
477 TestCompactMode(KAutoVacuum); |
|
478 //Delete database |
|
479 err = RSqlDatabase::Delete(KTestSecureDbName); |
|
480 TEST2(err, KErrNone); |
|
481 //Create a private test database - no config string |
|
482 securityPolicy = CreateTestSecurityPolicy(); |
|
483 err = TheDb.Create(KTestSecureDbName, securityPolicy); |
|
484 TEST2(err, KErrNone); |
|
485 securityPolicy.Close(); |
|
486 TheDb.Close(); |
|
487 //Check the vacuum mode. The SQLite vacuum mode should be KSqlDefaultVacuum. |
|
488 TestCompactMode(KSqlDefaultVacuum); |
|
489 //Close and open the database again. The SQLite vacuum mode should be KSqlDefaultVacuum. |
|
490 err = TheDb.Open(KTestSecureDbName); |
|
491 TEST2(err, KErrNone); |
|
492 TheDb.Close(); |
|
493 TestCompactMode(KSqlDefaultVacuum); |
|
494 //Close and open the database again with a config string with "auto" compaction mode. |
|
495 //The SQLite vacuum mode should stay unchanged. |
|
496 err = TheDb.Open(KTestSecureDbName, &KConfigStr1); |
|
497 TEST2(err, KErrNone); |
|
498 TheDb.Close(); |
|
499 TestCompactMode(KSqlDefaultVacuum); |
|
500 //Delete database |
|
501 err = RSqlDatabase::Delete(KTestSecureDbName); |
|
502 TEST2(err, KErrNone); |
|
503 } |
|
504 |
|
505 /** |
|
506 @SYMTestCaseID SYSLIB-SQL-UT-4062 |
|
507 @SYMTestCaseDesc Compaction configuration test - multiple connections. |
|
508 The test creates a database with auto or background compaction mode. |
|
509 Then the test opens more connections to the same database. |
|
510 The test verifies that the compaction mode of the connections opened later is |
|
511 the same as the compaction mode of the database that was openen first. |
|
512 The test also verifies that the compactino mode cannot be changed even if the second |
|
513 connection is opened with a configuration string with a specified different compaction mode. |
|
514 @SYMTestPriority Medium |
|
515 @SYMTestActions Compaction configuration test - multiple connections. |
|
516 @SYMTestExpectedResults Test must not fail |
|
517 @SYMREQ REQ10273 |
|
518 REQ10274 |
|
519 REQ10400 |
|
520 */ |
|
521 void CompactConfigTest7L() |
|
522 { |
|
523 //Create a test database with "auto" compaction mode. |
|
524 _LIT8(KConfigStr1, "encoding=utf8;compaction = auto"); |
|
525 TInt err = TheDb.Create(KTestDbName1, &KConfigStr1); |
|
526 TEST2(err, KErrNone); |
|
527 //Check the vacuum mode. The SQLite vacuum mode should be "auto" |
|
528 TSqlScalarFullSelectQuery scalarQuery(TheDb); |
|
529 TInt compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
530 TEST2(compact, KAutoVacuum); |
|
531 //Open a second connection to the same database - no config string |
|
532 RSqlDatabase db2; |
|
533 err = db2.Open(KTestDbName1); |
|
534 TEST2(err, KErrNone); |
|
535 //Check the vacuum mode. The SQLite vacuum mode should be "auto" |
|
536 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
537 TEST2(compact, KAutoVacuum); |
|
538 TSqlScalarFullSelectQuery scalarQuery2(db2); |
|
539 compact = scalarQuery2.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
540 TEST2(compact, KAutoVacuum); |
|
541 //Open a third connection to the same database - "background" compaction mode config string |
|
542 _LIT8(KConfigStr2, " encoding = utf8 ; ; ; compaction = background "); |
|
543 RSqlDatabase db3; |
|
544 err = db3.Open(KTestDbName1, &KConfigStr2); |
|
545 TEST2(err, KErrNone); |
|
546 //Check the vacuum mode. The SQLite vacuum mode should be "auto" |
|
547 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
548 TEST2(compact, KAutoVacuum); |
|
549 compact = scalarQuery2.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
550 TEST2(compact, KAutoVacuum); |
|
551 TSqlScalarFullSelectQuery scalarQuery3(db3); |
|
552 compact = scalarQuery3.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
553 TEST2(compact, KAutoVacuum); |
|
554 //Close & Delete database |
|
555 db3.Close(); |
|
556 db2.Close(); |
|
557 TheDb.Close(); |
|
558 err = RSqlDatabase::Delete(KTestDbName1); |
|
559 TEST2(err, KErrNone); |
|
560 // |
|
561 // |
|
562 //Create a test database with "background" compaction mode |
|
563 _LIT8(KConfigStr3, "compaction = background ;;;;"); |
|
564 err = TheDb.Create(KTestDbName1, &KConfigStr3); |
|
565 TEST2(err, KErrNone); |
|
566 //Check the vacuum mode. The SQLite vacuum mode should be "incremental" |
|
567 scalarQuery.SetDatabase(TheDb); |
|
568 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
569 TEST2(compact, KIncrementalVacuum); |
|
570 //Open a second connection to the same database - no config string |
|
571 err = db2.Open(KTestDbName1); |
|
572 TEST2(err, KErrNone); |
|
573 //Check the vacuum mode. The SQLite vacuum mode should be "incremental" |
|
574 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
575 TEST2(compact, KIncrementalVacuum); |
|
576 scalarQuery2.SetDatabase(db2); |
|
577 compact = scalarQuery2.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
578 TEST2(compact, KIncrementalVacuum); |
|
579 //Open a third connection to the same database - "auto" compaction mode config string |
|
580 _LIT8(KConfigStr4, " encoding = utf16 ; compaction = auto ; ; ; "); |
|
581 err = db3.Open(KTestDbName1, &KConfigStr4); |
|
582 TEST2(err, KErrNone); |
|
583 //Check the vacuum mode. The SQLite vacuum mode should be "incremental" |
|
584 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
585 TEST2(compact, KIncrementalVacuum); |
|
586 compact = scalarQuery2.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
587 TEST2(compact, KIncrementalVacuum); |
|
588 scalarQuery3.SetDatabase(db3); |
|
589 compact = scalarQuery3.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
590 TEST2(compact, KIncrementalVacuum); |
|
591 //Close & Delete database |
|
592 db3.Close(); |
|
593 db2.Close(); |
|
594 TheDb.Close(); |
|
595 err = RSqlDatabase::Delete(KTestDbName1); |
|
596 TEST2(err, KErrNone); |
|
597 } |
|
598 |
|
599 /** |
|
600 @SYMTestCaseID SYSLIB-SQL-UT-4063 |
|
601 @SYMTestCaseDesc Compaction configuration test - attached database. |
|
602 The test creates a database with an auto compaction mode. |
|
603 Then the test attaches the same database. |
|
604 The test verifies that the compaction mode of the main and the attached database is the same - auto. |
|
605 @SYMTestPriority Medium |
|
606 @SYMTestActions Compaction configuration test - attached database. |
|
607 @SYMTestExpectedResults Test must not fail |
|
608 @SYMREQ REQ10273 |
|
609 REQ10274 |
|
610 REQ10400 |
|
611 */ |
|
612 void CompactConfigTest8L() |
|
613 { |
|
614 //Create a test database with "auto" compaction mode |
|
615 _LIT8(KConfigStr1, "; ;; ; compaction = auto; "); |
|
616 TInt err = TheDb.Create(KTestDbName1, &KConfigStr1); |
|
617 TEST2(err, KErrNone); |
|
618 //Attach a database |
|
619 err = TheDb.Attach(KTestDbName1, _L("db2")); |
|
620 TEST2(err, KErrNone); |
|
621 //Check compact for both main and attached database |
|
622 TSqlScalarFullSelectQuery scalarQuery(TheDb); |
|
623 TInt compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
624 TEST2(compact, KAutoVacuum); |
|
625 compact = scalarQuery.SelectIntL(_L("PRAGMA db2.auto_vacuum")); |
|
626 TEST2(compact, KAutoVacuum); |
|
627 //Detach |
|
628 err = TheDb.Detach(_L("db2")); |
|
629 TEST2(err, KErrNone); |
|
630 //Check compact again |
|
631 compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum")); |
|
632 TEST2(compact, KAutoVacuum); |
|
633 // |
|
634 TheDb.Close(); |
|
635 err = RSqlDatabase::Delete(KTestDbName1); |
|
636 TEST2(err, KErrNone); |
|
637 } |
|
638 |
|
639 void DoTestsL() |
|
640 { |
|
641 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4056 Compaction configuration tests 1 - manual compact")); |
|
642 CompactConfigTest1L(); |
|
643 |
|
644 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4057 Compaction configuration tests 2 - auto compact")); |
|
645 CompactConfigTest2L(); |
|
646 |
|
647 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4058 Compaction configuration tests 3 - background compact")); |
|
648 CompactConfigTest3L(); |
|
649 |
|
650 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4059 Compaction configuration tests 4 - invalid compact")); |
|
651 CompactConfigTest4L(); |
|
652 |
|
653 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4060 Compaction configuration tests 5 - private databases")); |
|
654 CompactConfigTest5L(); |
|
655 |
|
656 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4061 Compaction configuration tests 6 - secure databases")); |
|
657 CompactConfigTest6L(); |
|
658 |
|
659 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4062 Compaction configuration tests 7 - multiple connections")); |
|
660 CompactConfigTest7L(); |
|
661 |
|
662 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4063 Compaction configuration tests 8 - attached databases")); |
|
663 CompactConfigTest8L(); |
|
664 } |
|
665 |
|
666 TInt E32Main() |
|
667 { |
|
668 TheTest.Title(); |
|
669 |
|
670 CTrapCleanup* tc = CTrapCleanup::New(); |
|
671 |
|
672 __UHEAP_MARK; |
|
673 |
|
674 DestroyTestEnv(); |
|
675 CreateTestEnv(); |
|
676 TRAPD(err, DoTestsL()); |
|
677 DestroyTestEnv(); |
|
678 TEST2(err, KErrNone); |
|
679 |
|
680 __UHEAP_MARKEND; |
|
681 |
|
682 TheTest.End(); |
|
683 TheTest.Close(); |
|
684 |
|
685 delete tc; |
|
686 |
|
687 User::Heap().Check(); |
|
688 return KErrNone; |
|
689 } |