Update contrib.
1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #include "SqlSrvConfig.h"
21 ///////////////////////////////////////////////////////////////////////////////////////
23 RTest TheTest(_L("t_sqlconfig test"));
24 _LIT(KTestDir, "c:\\test\\");
25 _LIT(KTestDbName, "c:\\test\\t_sqlconfig_1.db");
26 _LIT(KTestDbName2, "c:\\test\\t_sqlconfig_2.db");
27 _LIT(KTestDbName3, "c:[1111C1C1]t_sqlconfig_3.db");
28 _LIT(KTestDbName4, "c:\\private\\1111C1C1\\t_sqlconfig_4.db");
29 _LIT(KSqlSrvConfigFile, "c:\\test\\t_sqlserver.cfg");
34 enum TConfigParamType {EPrmCacheSize, EPrmPageSize, EPrmDbEncoding};
36 //Default (build-time) configuration parameter values
37 const TInt KDefaultPageSize = 1024;
38 const TInt KDefaultCacheSize = (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / KDefaultPageSize;
39 const TSqlSrvConfigParams::TDbEncoding KDefaultEncoding = TSqlSrvConfigParams::EEncUtf16;
41 ///////////////////////////////////////////////////////////////////////////////////////
47 (void)RSqlDatabase::Delete(KTestDbName4);
48 (void)RSqlDatabase::Delete(KTestDbName3);
49 (void)RSqlDatabase::Delete(KTestDbName2);
50 (void)RSqlDatabase::Delete(KTestDbName);
51 (void)TheFs.Delete(KSqlSrvConfigFile);
55 ///////////////////////////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////////////////////////
57 //Test macros and functions
58 void Check(TInt aValue, TInt aLine)
63 TheTest(EFalse, aLine);
66 void Check(TInt aValue, TInt aExpected, TInt aLine)
68 if(aValue != aExpected)
71 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
72 TheTest(EFalse, aLine);
75 #define TEST(arg) ::Check((arg), __LINE__)
76 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
78 ///////////////////////////////////////////////////////////////////////////////////////
82 TInt err = TheFs.Connect();
85 err = TheFs.MkDir(KTestDir);
86 TEST(err == KErrNone || err == KErrAlreadyExists);
88 err = TheFs.CreatePrivatePath(EDriveC);
89 TEST(err == KErrNone || err == KErrAlreadyExists);
91 (void)RSqlDatabase::Delete(KTestDbName3);
92 (void)RSqlDatabase::Delete(KTestDbName2);
93 (void)RSqlDatabase::Delete(KTestDbName);
94 (void)TheFs.Delete(KSqlSrvConfigFile);//The test does not work if there is a test config file.
97 TInt DoGetConfigParamValueL(RSqlDatabase& aDb, TConfigParamType aPrmType, const TDesC& aLogicalDbName = KNullDesC)
100 sql.Copy(_L("PRAGMA "));
101 if(aLogicalDbName.Length() > 0)
103 sql.Append(aLogicalDbName);
107 TSqlScalarFullSelectQuery q(aDb);
112 sql.Append(_L("cache_size"));
113 res = q.SelectIntL(sql);
116 sql.Append(_L("page_size"));
117 res = q.SelectIntL(sql);
121 sql.Append(_L("encoding"));
122 TBuf<20> dbEncodingText;
123 res = q.SelectTextL(sql, dbEncodingText);
124 TEST2(res, KErrNone);
125 if(dbEncodingText.FindF(_L("UTF-16")) >= 0)
127 res = TSqlSrvConfigParams::EEncUtf16;
129 else if(dbEncodingText.FindF(_L("UTF-8")) >= 0)
131 res = TSqlSrvConfigParams::EEncUtf8;
146 TInt GetConfigParamValue(RSqlDatabase& aDb, TConfigParamType aPrmType, const TDesC& aLogicalDbName = KNullDesC)
149 TRAPD(err, res = DoGetConfigParamValueL(aDb, aPrmType, aLogicalDbName));
150 TEST2(err, KErrNone);
154 void AssertConfigPrmValues(RSqlDatabase& aDb, TInt aExpectedCacheSize, TInt aExpectedPageSize, TInt aExpectedDbEncoding,
155 const TDesC& aLogicalDbName = KNullDesC)
157 TInt cacheSize = GetConfigParamValue(aDb, EPrmCacheSize, aLogicalDbName);
158 TInt pageSize = GetConfigParamValue(aDb, EPrmPageSize ,aLogicalDbName);
159 TInt dbEncoding = GetConfigParamValue(aDb, EPrmDbEncoding, aLogicalDbName);
160 TEST2(cacheSize, aExpectedCacheSize);
161 TEST2(pageSize, aExpectedPageSize);
162 TEST2(dbEncoding, aExpectedDbEncoding);
165 ///////////////////////////////////////////////////////////////////////////////////////
168 @SYMTestCaseID SYSLIB-SQL-UT-3436
169 @SYMTestCaseDesc Test for DEF105928 "SQL server ignores config string parameters".
170 The test attempts to create/open a database using different cache size/page size/
171 database encoding configurations and then checks that the configuration parameters
172 have been set properly and have the expected values.
173 @SYMTestPriority High
174 @SYMTestActions Test for DEF105928 "SQL server ignores config string parameters".
175 @SYMTestExpectedResults The test must not fail
178 void CfgFunctionalTest()
180 (void)RSqlDatabase::Delete(KTestDbName);
181 //Create a database. No config string. The default config parameters will be used.
182 TInt err = TheDb.Create(KTestDbName);
183 TEST2(err, KErrNone);
184 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
186 (void)RSqlDatabase::Delete(KTestDbName);
187 //Create a database. Cache size set.
188 _LIT8(KCfgStr1, "cache_size=32");
189 err = TheDb.Create(KTestDbName, &KCfgStr1);
190 TEST2(err, KErrNone);
191 AssertConfigPrmValues(TheDb, 32, KDefaultPageSize, KDefaultEncoding);
193 (void)RSqlDatabase::Delete(KTestDbName);
194 //Create a database. Page size set.
195 _LIT8(KCfgStr2, "page_size=2048");
196 err = TheDb.Create(KTestDbName, &KCfgStr2);
197 TEST2(err, KErrNone);
198 AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 2048, 2048, KDefaultEncoding);
200 (void)RSqlDatabase::Delete(KTestDbName);
201 //Create a database. Cache & Page size set.
202 _LIT8(KCfgStr3, "cache_size=256;page_size=4096");
203 err = TheDb.Create(KTestDbName, &KCfgStr3);
204 TEST2(err, KErrNone);
205 AssertConfigPrmValues(TheDb, 256, 4096, KDefaultEncoding);
207 (void)RSqlDatabase::Delete(KTestDbName);
208 //Create a database. Cache size & Page size & db encoding set.
209 _LIT8(KCfgStr4, "cache_size=512;page_size=512;encoding=UTF-8");
210 err = TheDb.Create(KTestDbName, &KCfgStr4);
211 TEST2(err, KErrNone);
212 AssertConfigPrmValues(TheDb, 512, 512, TSqlSrvConfigParams::EEncUtf8);
214 (void)RSqlDatabase::Delete(KTestDbName);
215 //Create a database. Cache size & Page size & db encoding set.
216 _LIT8(KCfgStr5, "cache_size=16;page_size=1024;encoding=UTF-16");
217 err = TheDb.Create(KTestDbName, &KCfgStr5);
218 TEST2(err, KErrNone);
219 AssertConfigPrmValues(TheDb, 16, 1024, TSqlSrvConfigParams::EEncUtf16);
221 //Open the database. Cache size set. The rest of parameter values must be the same as for KCfgStr5.
222 _LIT8(KCfgStr6, "cache_size=80");
223 err = TheDb.Open(KTestDbName, &KCfgStr6);
224 TEST2(err, KErrNone);
225 AssertConfigPrmValues(TheDb, 80, 1024, TSqlSrvConfigParams::EEncUtf16);
227 //Open the database. Attempt to set the page size (impossible when opening a database).
228 _LIT8(KCfgStr7, "page_size=2048");
229 err = TheDb.Open(KTestDbName, &KCfgStr7);
230 TEST2(err, KErrNone);
231 AssertConfigPrmValues(TheDb, KDefaultCacheSize, 1024, TSqlSrvConfigParams::EEncUtf16);
233 //Open the database. Attempt to set the encoding (impossible when opening a database).
234 _LIT8(KCfgStr8, "encoding=UTF-8");
235 err = TheDb.Open(KTestDbName, &KCfgStr8);
236 TEST2(err, KErrNone);
237 AssertConfigPrmValues(TheDb, KDefaultCacheSize, 1024, TSqlSrvConfigParams::EEncUtf16);
239 (void)RSqlDatabase::Delete(KTestDbName);
240 //Create a database. Empty config string - 1
242 err = TheDb.Create(KTestDbName, &KCfgStr9);
243 TEST2(err, KErrNone);
244 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
246 (void)RSqlDatabase::Delete(KTestDbName);
247 //Create a database. Empty config string - 2
248 _LIT8(KCfgStr10, " ");
249 err = TheDb.Create(KTestDbName, &KCfgStr10);
250 TEST2(err, KErrNone);
251 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
253 (void)RSqlDatabase::Delete(KTestDbName);
254 //Create a database. Empty config string - 3
255 _LIT8(KCfgStr11, " ; ; ;; ");
256 err = TheDb.Create(KTestDbName, &KCfgStr11);
257 TEST2(err, KErrNone);
258 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
260 (void)RSqlDatabase::Delete(KTestDbName);
264 @SYMTestCaseID SYSLIB-SQL-UT-3437
265 @SYMTestCaseDesc Test for DEF105928 "SQL server ignores config string parameters".
266 The test attempts to create/open a database using invalid configuration strings,
267 too long configuration string, string with missing parameter values, string with
268 invalid database encodings. The test expects the SQL server will report a failure
269 and will refuse to execute the operation.
270 @SYMTestPriority High
271 @SYMTestActions Test for DEF105928 "SQL server ignores config string parameters".
272 @SYMTestExpectedResults The test must not fail
275 void CfgNegativeTest()
277 //Create a database. Spelling problem in the parameter name. This is not reported as an error by the SQL server
278 //(treated as unknown parameter)
279 _LIT8(KCfgStr1, "casche_size = 32");
280 TInt err = TheDb.Create(KTestDbName, &KCfgStr1);
281 TEST2(err, KErrNone);
283 (void)RSqlDatabase::Delete(KTestDbName);
284 //Create a database. Spelling problem in the parameter value.
285 _LIT8(KCfgStr2, "encoding = UTF-32");
286 err = TheDb.Create(KTestDbName, &KCfgStr2);
287 TEST2(err, KErrNone);//Invalid encoding: KErrNone, but the encoding will not be used
288 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
290 (void)RSqlDatabase::Delete(KTestDbName);
291 //Create a database. Invalid config string.
292 _LIT8(KCfgStr3, "dfgjkdfgkdfk; sfkgjhdfgjkdfk; dfgdfetrwer");
293 err = TheDb.Create(KTestDbName, &KCfgStr3);
294 TEST2(err, KErrArgument);
296 (void)RSqlDatabase::Delete(KTestDbName);
297 //Create a database. Too long and invalid config string.
298 _LIT8(KCfgStr4, "A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789M123456789N123456789O123456789");
299 err = TheDb.Create(KTestDbName, &KCfgStr4);
300 TEST2(err, KErrArgument);
302 (void)RSqlDatabase::Delete(KTestDbName);
303 //Create a database. No parameter value - 1.
304 _LIT8(KCfgStr5, "page_size=");
305 err = TheDb.Create(KTestDbName, &KCfgStr5);
306 TEST2(err, KErrArgument);
308 (void)RSqlDatabase::Delete(KTestDbName);
309 //Create a database. No parameter value - 2.
310 _LIT8(KCfgStr6, "page_size=;");
311 err = TheDb.Create(KTestDbName, &KCfgStr6);
312 TEST2(err, KErrArgument);
314 (void)RSqlDatabase::Delete(KTestDbName);
315 //Create a database. Non-number parameter value - 1.
316 _LIT8(KCfgStr7, "page_size=aaa;");
317 err = TheDb.Create(KTestDbName, &KCfgStr7);
318 TEST2(err, KErrArgument);
320 (void)RSqlDatabase::Delete(KTestDbName);
321 //Create a database. Non-number parameter value - 2.
322 _LIT8(KCfgStr8, "cache_size=weyu34;");
323 err = TheDb.Create(KTestDbName, &KCfgStr8);
324 TEST2(err, KErrArgument);
326 (void)RSqlDatabase::Delete(KTestDbName);
327 //Create a database. "soft_heap_limit_kb" in the config string.
328 _LIT8(KCfgStr9, "soft_heap_limit_kb=512;");
329 err = TheDb.Create(KTestDbName, &KCfgStr9);
330 TEST2(err, KErrArgument);
332 (void)RSqlDatabase::Delete(KTestDbName);
333 //Create a database. "free_space_threshold_kb" in the config string.
334 _LIT8(KCfgStr10, "free_space_threshold_kb=256;");
335 err = TheDb.Create(KTestDbName, &KCfgStr10);
336 TEST2(err, KErrArgument);
338 (void)RSqlDatabase::Delete(KTestDbName);
342 @SYMTestCaseID SYSLIB-SQL-UT-3438
343 @SYMTestCaseDesc Test for DEF105928 "SQL server ignores config string parameters".
344 The test attempts to create a database with configuration string containing:
345 negative or zero page size and cache size, too small or too big page size,
346 page size, not power of two. The test expects the SQL server will detect those
347 invalid page size and cache size values and will refuse to execute the operation.
348 @SYMTestPriority High
349 @SYMTestActions Test for DEF105928 "SQL server ignores config string parameters".
350 @SYMTestExpectedResults The test must not fail
353 void CfgInvalidCacheAndPageSizeTest()
355 //Create a database. Page size < 512.
356 _LIT8(KCfgStr1, "page_size=128;");
357 TInt err = TheDb.Create(KTestDbName, &KCfgStr1);
358 TEST2(err, KErrNone);//Invalid page size: KErrNone expected, but the page size will not be set
359 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
361 (void)RSqlDatabase::Delete(KTestDbName);
362 //Create a database. Page size > 32768.
363 _LIT8(KCfgStr2, "page_size=65535;");
364 err = TheDb.Create(KTestDbName, &KCfgStr2);
365 TEST2(err, KErrNone);//Invalid page size: KErrNone expected, but the page size will not be set
366 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
368 (void)RSqlDatabase::Delete(KTestDbName);
369 //Create a database. Page size is not power of two.
370 _LIT8(KCfgStr3, "page_size=5000;");
371 err = TheDb.Create(KTestDbName, &KCfgStr3);
372 TEST2(err, KErrNone);//Invalid page size: KErrNone expected, but the page size will not be set
373 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
375 (void)RSqlDatabase::Delete(KTestDbName);
376 //Create a database. Zero cache size.
377 _LIT8(KCfgStr4, "cache_size=0");
378 err = TheDb.Create(KTestDbName, &KCfgStr4);
379 TEST2(err, KErrNone);
380 AssertConfigPrmValues(TheDb, 0, KDefaultPageSize, KDefaultEncoding);
382 (void)RSqlDatabase::Delete(KTestDbName);
383 //Create a database. Negative cache size.
384 _LIT8(KCfgStr5, "cache_size=-32");
385 err = TheDb.Create(KTestDbName, &KCfgStr5);
386 TEST2(err, KErrArgument);
388 (void)RSqlDatabase::Delete(KTestDbName);
389 //Create a database. Zero page size.
390 _LIT8(KCfgStr6, "page_size=0");
391 err = TheDb.Create(KTestDbName, &KCfgStr6);
392 TEST2(err, KErrNone);//Invalid page size: KErrNone expected, but the page size will not be set
393 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
395 (void)RSqlDatabase::Delete(KTestDbName);
396 //Create a database. Negative page size.
397 _LIT8(KCfgStr7, "page_size=-1024");
398 err = TheDb.Create(KTestDbName, &KCfgStr7);
399 TEST2(err, KErrArgument);
401 (void)RSqlDatabase::Delete(KTestDbName);
405 @SYMTestCaseID SYSLIB-SQL-UT-3439
406 @SYMTestCaseDesc Test for DEF105928 "SQL server ignores config string parameters".
407 The test creates two databases using configuration strings and checks that database 1
408 configuration has no impact on database 2 configuration.
409 @SYMTestPriority High
410 @SYMTestActions Test for DEF105928 "SQL server ignores config string parameters".
411 @SYMTestExpectedResults The test must not fail
414 void CfgCrossConnectionTest()
416 //Create database 1 with cache size = 40, page size = 2048.
417 _LIT8(KCfgStr1, "cache_size = 40; page_size = 2048");
418 TInt err = TheDb.Create(KTestDbName, &KCfgStr1);
419 TEST2(err, KErrNone);
420 AssertConfigPrmValues(TheDb, 40, 2048, KDefaultEncoding);
421 //Without closing database 1, create database 2 without a configuration string.
422 //Check that database 2 uses the default configuration parameters
423 err = TheDb2.Create(KTestDbName2);
424 TEST2(err, KErrNone);
425 AssertConfigPrmValues(TheDb2, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
426 //Close database 2. Check the configuration parameters of database 1
428 AssertConfigPrmValues(TheDb, 40, 2048, KDefaultEncoding);
430 (void)RSqlDatabase::Delete(KTestDbName2);
431 (void)RSqlDatabase::Delete(KTestDbName);
432 //Create 2 databases with different configuration parameters
433 _LIT8(KCfgStr2_1, "cache_size = 50; page_size = 512; encoding = \"UTF-16\"");
434 _LIT8(KCfgStr2_2, "cache_size = 80; page_size = 4096; encoding = \"UTF-8\"");
435 err = TheDb.Create(KTestDbName, &KCfgStr2_1);
436 TEST2(err, KErrNone);
437 err = TheDb2.Create(KTestDbName2, &KCfgStr2_2);
438 TEST2(err, KErrNone);
439 AssertConfigPrmValues(TheDb, 50, 512, TSqlSrvConfigParams::EEncUtf16);
440 AssertConfigPrmValues(TheDb2, 80, 4096, TSqlSrvConfigParams::EEncUtf8);
443 //Reopen the databases and check the configuration parameters
444 err = TheDb.Open(KTestDbName);
445 TEST2(err, KErrNone);
446 err = TheDb2.Open(KTestDbName2);
447 TEST2(err, KErrNone);
448 AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 512, 512, TSqlSrvConfigParams::EEncUtf16);
449 AssertConfigPrmValues(TheDb2, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 4096, 4096, TSqlSrvConfigParams::EEncUtf8);
452 (void)RSqlDatabase::Delete(KTestDbName2);
453 (void)RSqlDatabase::Delete(KTestDbName);
457 @SYMTestCaseID SYSLIB-SQL-UT-3440
458 @SYMTestCaseDesc Test for DEF105928 "SQL server ignores config string parameters".
459 The test creates a secure database with a configuration string. The test must not fail.
460 @SYMTestPriority High
461 @SYMTestActions Test for DEF105928 "SQL server ignores config string parameters".
462 @SYMTestExpectedResults The test must not fail
465 void CfgSecureDbTest()
468 TSecurityPolicy policy(TSecurityPolicy::EAlwaysPass);
469 RSqlSecurityPolicy dbPolicy;
470 TInt err = dbPolicy.Create(policy);
471 TEST2(err, KErrNone);
472 _LIT8(KCfgStr1, "cache_size = 80; page_size = 4096; encoding = UTF-8");
473 err = TheDb.Create(KTestDbName3, dbPolicy, &KCfgStr1);
474 TEST2(err, KErrNone);
475 //Since it is a secure database, PRAGMAs cannot be executed (in order to assert the parameter values)
476 //AssertConfigPrmValues(TheDb, 80, 4096, TSqlSrvConfig::EEncUtf8);
480 _LIT8(KCfgStr2, "cache_size = 100");
481 err = TheDb.Open(KTestDbName3, &KCfgStr2);
482 TEST2(err, KErrNone);
484 (void)RSqlDatabase::Delete(KTestDbName3);
488 @SYMTestCaseID SYSLIB-SQL-UT-3441
489 @SYMTestCaseDesc Test for DEF105928 "SQL server ignores config string parameters".
490 The test creates a private database with a configuration string. The test must not fail.
491 @SYMTestPriority High
492 @SYMTestActions Test for DEF105928 "SQL server ignores config string parameters".
493 @SYMTestExpectedResults The test must not fail
496 void CfgPrivateDbTest()
499 _LIT8(KCfgStr1, "cache_size = 80; page_size = 4096; encoding = UTF-8");
500 TInt err = TheDb.Create(KTestDbName4, &KCfgStr1);
501 TEST2(err, KErrNone);
502 AssertConfigPrmValues(TheDb, 80, 4096, TSqlSrvConfigParams::EEncUtf8);
504 //Open-1. The cache size can be changed.
505 _LIT8(KCfgStr2, "cache_size = 100");
506 err = TheDb.Open(KTestDbName4, &KCfgStr2);
507 TEST2(err, KErrNone);
508 AssertConfigPrmValues(TheDb, 100, 4096, TSqlSrvConfigParams::EEncUtf8);
510 //Open-2. The page size cannot be changed if the database does exist already.
511 _LIT8(KCfgStr3, "page_size = 512");
512 err = TheDb.Open(KTestDbName4, &KCfgStr3);
513 TEST2(err, KErrNone);
514 AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 4096, 4096, TSqlSrvConfigParams::EEncUtf8);
516 (void)RSqlDatabase::Delete(KTestDbName4);
520 @SYMTestCaseID SYSLIB-SQL-CT-3480
521 @SYMTestCaseDesc Test for INC106788 - Cannot set SQLite page_size bigger than 4k (4096).
522 The test attempts to create a database with page size 8K, 16K or 32K, which was not
523 possible before (the default page size (1K) has been used).
524 @SYMTestPriority High
525 @SYMTestActions Test for INC106788 - Cannot set SQLite page_size bigger than 4k (4096).
526 @SYMTestExpectedResults The test should not fail or panic.
531 //Create a database with page size = 8192.
532 (void)RSqlDatabase::Delete(KTestDbName);
533 _LIT8(KCfgStr1, "page_size = 8192");
534 TInt err = TheDb.Create(KTestDbName, &KCfgStr1);
535 TEST2(err, KErrNone);
536 AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 8192, 8192, KDefaultEncoding);
539 //Create a database with page size = 16384.
540 (void)RSqlDatabase::Delete(KTestDbName);
541 _LIT8(KCfgStr2, "page_size = 16384");
542 err = TheDb.Create(KTestDbName, &KCfgStr2);
543 TEST2(err, KErrNone);
544 AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 16384, 16384, KDefaultEncoding);
547 //Create a database with page size = 32768.
548 (void)RSqlDatabase::Delete(KTestDbName);
549 _LIT8(KCfgStr3, "page_size = 32768");
550 err = TheDb.Create(KTestDbName, &KCfgStr3);
551 TEST2(err, KErrNone);
552 AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 32768, 32768, KDefaultEncoding);
555 (void)RSqlDatabase::Delete(KTestDbName);
559 @SYMTestCaseID SYSLIB-SQL-UT-4049
560 @SYMTestCaseDesc Database configuration string - injection test.
561 The test attempts to create a database using a configuration string
562 and passing a DELETE SQL statement as a compaction mode name.
563 The database should be created successfully, the invalid compaction mode - ignored,
564 the database system tables content shoud not be corrupted by the call.
565 @SYMTestPriority High
566 @SYMTestActions Database configuration string - injection test.
567 @SYMTestExpectedResults Test must not fail
572 (void)RSqlDatabase::Delete(KTestDbName);
573 TInt err = TheDb.Create(KTestDbName);
574 TEST2(err, KErrNone);
575 err = TheDb.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A(I) VALUES(1);"));
579 _LIT8(KConfig1, "cache_size=128;DELETE FROM A");
580 err = TheDb.Open(KTestDbName, &KConfig1);
581 TEST2(err, KErrArgument);
582 err = TheDb.Open(KTestDbName);
583 TEST2(err, KErrNone);
584 TSqlScalarFullSelectQuery query(TheDb);
586 TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM A")));
587 TEST2(err, KErrNone);
591 _LIT8(KConfig2, "cache_size=256;compaction=DELETE FROM A;");
592 err = TheDb.Open(KTestDbName, &KConfig2);
593 TEST2(err, KErrNone);
594 query.SetDatabase(TheDb);
596 TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM A")));
597 TEST2(err, KErrNone);
600 (void)RSqlDatabase::Delete(KTestDbName);
602 _LIT8(KConfig3, "cache_size=256;compaction=DELETE FROM symbian_settings;");
603 err = TheDb.Create(KTestDbName, &KConfig3);
604 TEST2(err, KErrNone);
605 query.SetDatabase(TheDb);
607 TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM symbian_settings")));
608 TEST2(err, KErrNone);
611 (void)RSqlDatabase::Delete(KTestDbName);
615 @SYMTestCaseID PDS-SQL-UT-4152
616 @SYMTestCaseDesc Test for DEF142305 - RSqlDatabase::Attach does not use cache_size configuration parameters.
617 The test verifies that when a database is attached, the attached database cache size will be set
618 based on the page size, soft heap limit and default cache size.
619 @SYMTestPriority High
620 @SYMTestActions Test for DEF142305 - RSqlDatabase::Attach does not use cache_size configuration parameters.
621 @SYMTestExpectedResults The test must not fail.
626 _LIT8(KConfig, "cache_size=500");
629 TInt err = TheDb.Create(KTestDbName, &KConfig);
630 TEST2(err, KErrNone);
631 AssertConfigPrmValues(TheDb, 500, KDefaultPageSize, KDefaultEncoding);
634 //Create non-secure db that will be attached
635 err = TheDb.Create(KTestDbName2, &KConfig);
636 TEST2(err, KErrNone);
637 AssertConfigPrmValues(TheDb, 500, KDefaultPageSize, KDefaultEncoding);
640 //Create private db that will be attached
641 _LIT8(KConfig2, "page_size=2048");
642 err = TheDb.Create(KTestDbName4, &KConfig2);
643 TEST2(err, KErrNone);
644 AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 2048, 2048, KDefaultEncoding);//2048? - see KConfig2 string
647 _LIT(KAttachDbName, "Attached");
649 //Attach non-secure db
650 err = TheDb.Open(KTestDbName, &KConfig);
651 TEST2(err, KErrNone);
652 AssertConfigPrmValues(TheDb, 500, KDefaultPageSize, KDefaultEncoding);
653 err = TheDb.Attach(KTestDbName2, KAttachDbName);
654 TEST2(err, KErrNone);
655 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding, KAttachDbName);
656 err = TheDb.Detach(KAttachDbName);
657 TEST2(err, KErrNone);
661 err = TheDb.Open(KTestDbName, &KConfig);
662 TEST2(err, KErrNone);
663 AssertConfigPrmValues(TheDb, 500, KDefaultPageSize, KDefaultEncoding);
664 err = TheDb.Attach(KTestDbName4, KAttachDbName);
665 TEST2(err, KErrNone);
666 AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 2048, 2048, KDefaultEncoding, KAttachDbName);//2048? - see KConfig2 string
667 err = TheDb.Detach(KAttachDbName);
668 TEST2(err, KErrNone);
671 (void)RSqlDatabase::Delete(KTestDbName4);
672 (void)RSqlDatabase::Delete(KTestDbName2);
673 (void)RSqlDatabase::Delete(KTestDbName);
678 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3436 Sql config string - functional test "));
680 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3437 Sql config string - negative test "));
682 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3438 Sql config string - invalid cache size and page size test "));
683 CfgInvalidCacheAndPageSizeTest();
684 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3439 Sql config string - cross connection test "));
685 CfgCrossConnectionTest();
686 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3440 Sql config string - secure database test "));
688 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3441 Sql config string - private database test "));
690 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-3480 INC106788 - Cannot set SQLite page_size bigger than 4k (4096) "));
692 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4049 Config string - injection tests"));
694 TheTest.Next(_L("@SYMTestCaseID:PDS-SQL-UT-4152: DEF142305 RSqlDatabase::Attach does not use cache_size configuration parameters"));
702 CTrapCleanup* tc = CTrapCleanup::New();
718 User::Heap().Check();