|
1 // Copyright (c) 2007-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 "SqlSrvConfig.h" |
|
20 |
|
21 /////////////////////////////////////////////////////////////////////////////////////// |
|
22 |
|
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"); |
|
30 RFs TheFs; |
|
31 RSqlDatabase TheDb; |
|
32 RSqlDatabase TheDb2; |
|
33 |
|
34 enum TConfigParamType {EPrmCacheSize, EPrmPageSize, EPrmDbEncoding}; |
|
35 |
|
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; |
|
40 |
|
41 /////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
43 void DestroyTestEnv() |
|
44 { |
|
45 TheDb2.Close(); |
|
46 TheDb.Close(); |
|
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); |
|
52 TheFs.Close(); |
|
53 } |
|
54 |
|
55 /////////////////////////////////////////////////////////////////////////////////////// |
|
56 /////////////////////////////////////////////////////////////////////////////////////// |
|
57 //Test macros and functions |
|
58 void Check(TInt aValue, TInt aLine) |
|
59 { |
|
60 if(!aValue) |
|
61 { |
|
62 DestroyTestEnv(); |
|
63 TheTest(EFalse, aLine); |
|
64 } |
|
65 } |
|
66 void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
67 { |
|
68 if(aValue != aExpected) |
|
69 { |
|
70 DestroyTestEnv(); |
|
71 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
72 TheTest(EFalse, aLine); |
|
73 } |
|
74 } |
|
75 #define TEST(arg) ::Check((arg), __LINE__) |
|
76 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
77 |
|
78 /////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
80 void SetupTestEnv() |
|
81 { |
|
82 TInt err = TheFs.Connect(); |
|
83 TEST2(err, KErrNone); |
|
84 |
|
85 err = TheFs.MkDir(KTestDir); |
|
86 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
87 |
|
88 err = TheFs.CreatePrivatePath(EDriveC); |
|
89 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
90 |
|
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. |
|
95 } |
|
96 |
|
97 TInt DoGetConfigParamValueL(RSqlDatabase& aDb, TConfigParamType aPrmType, const TDesC& aLogicalDbName = KNullDesC) |
|
98 { |
|
99 TBuf<100> sql; |
|
100 sql.Copy(_L("PRAGMA ")); |
|
101 if(aLogicalDbName.Length() > 0) |
|
102 { |
|
103 sql.Append(aLogicalDbName); |
|
104 sql.Append(_L(".")); |
|
105 } |
|
106 |
|
107 TSqlScalarFullSelectQuery q(aDb); |
|
108 TInt res = 0; |
|
109 switch(aPrmType) |
|
110 { |
|
111 case EPrmCacheSize: |
|
112 sql.Append(_L("cache_size")); |
|
113 res = q.SelectIntL(sql); |
|
114 break; |
|
115 case EPrmPageSize: |
|
116 sql.Append(_L("page_size")); |
|
117 res = q.SelectIntL(sql); |
|
118 break; |
|
119 case EPrmDbEncoding: |
|
120 { |
|
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) |
|
126 { |
|
127 res = TSqlSrvConfigParams::EEncUtf16; |
|
128 } |
|
129 else if(dbEncodingText.FindF(_L("UTF-8")) >= 0) |
|
130 { |
|
131 res = TSqlSrvConfigParams::EEncUtf8; |
|
132 } |
|
133 else |
|
134 { |
|
135 TEST2(0, 1); |
|
136 } |
|
137 } |
|
138 break; |
|
139 default: |
|
140 TEST2(0, 1); |
|
141 break; |
|
142 } |
|
143 return res; |
|
144 } |
|
145 |
|
146 TInt GetConfigParamValue(RSqlDatabase& aDb, TConfigParamType aPrmType, const TDesC& aLogicalDbName = KNullDesC) |
|
147 { |
|
148 TInt res = 0; |
|
149 TRAPD(err, res = DoGetConfigParamValueL(aDb, aPrmType, aLogicalDbName)); |
|
150 TEST2(err, KErrNone); |
|
151 return res; |
|
152 } |
|
153 |
|
154 void AssertConfigPrmValues(RSqlDatabase& aDb, TInt aExpectedCacheSize, TInt aExpectedPageSize, TInt aExpectedDbEncoding, |
|
155 const TDesC& aLogicalDbName = KNullDesC) |
|
156 { |
|
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); |
|
163 } |
|
164 |
|
165 /////////////////////////////////////////////////////////////////////////////////////// |
|
166 |
|
167 /** |
|
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 |
|
176 @SYMDEF DEF105928 |
|
177 */ |
|
178 void CfgFunctionalTest() |
|
179 { |
|
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); |
|
185 TheDb.Close(); |
|
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); |
|
192 TheDb.Close(); |
|
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); |
|
199 TheDb.Close(); |
|
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); |
|
206 TheDb.Close(); |
|
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); |
|
213 TheDb.Close(); |
|
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); |
|
220 TheDb.Close(); |
|
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); |
|
226 TheDb.Close(); |
|
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); |
|
232 TheDb.Close(); |
|
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); |
|
238 TheDb.Close(); |
|
239 (void)RSqlDatabase::Delete(KTestDbName); |
|
240 //Create a database. Empty config string - 1 |
|
241 _LIT8(KCfgStr9, ""); |
|
242 err = TheDb.Create(KTestDbName, &KCfgStr9); |
|
243 TEST2(err, KErrNone); |
|
244 AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding); |
|
245 TheDb.Close(); |
|
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); |
|
252 TheDb.Close(); |
|
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); |
|
259 TheDb.Close(); |
|
260 (void)RSqlDatabase::Delete(KTestDbName); |
|
261 } |
|
262 |
|
263 /** |
|
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 |
|
273 @SYMDEF DEF105928 |
|
274 */ |
|
275 void CfgNegativeTest() |
|
276 { |
|
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); |
|
282 TheDb.Close(); |
|
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); |
|
289 TheDb.Close(); |
|
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); |
|
295 TheDb.Close(); |
|
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); |
|
301 TheDb.Close(); |
|
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); |
|
307 TheDb.Close(); |
|
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); |
|
313 TheDb.Close(); |
|
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); |
|
319 TheDb.Close(); |
|
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); |
|
325 TheDb.Close(); |
|
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); |
|
331 TheDb.Close(); |
|
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); |
|
337 TheDb.Close(); |
|
338 (void)RSqlDatabase::Delete(KTestDbName); |
|
339 } |
|
340 |
|
341 /** |
|
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 |
|
351 @SYMDEF DEF105928 |
|
352 */ |
|
353 void CfgInvalidCacheAndPageSizeTest() |
|
354 { |
|
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); |
|
360 TheDb.Close(); |
|
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); |
|
367 TheDb.Close(); |
|
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); |
|
374 TheDb.Close(); |
|
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); |
|
381 TheDb.Close(); |
|
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); |
|
387 TheDb.Close(); |
|
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); |
|
394 TheDb.Close(); |
|
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); |
|
400 TheDb.Close(); |
|
401 (void)RSqlDatabase::Delete(KTestDbName); |
|
402 } |
|
403 |
|
404 /** |
|
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 |
|
412 @SYMDEF DEF105928 |
|
413 */ |
|
414 void CfgCrossConnectionTest() |
|
415 { |
|
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 |
|
427 TheDb2.Close(); |
|
428 AssertConfigPrmValues(TheDb, 40, 2048, KDefaultEncoding); |
|
429 TheDb.Close(); |
|
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); |
|
441 TheDb2.Close(); |
|
442 TheDb.Close(); |
|
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); |
|
450 TheDb2.Close(); |
|
451 TheDb.Close(); |
|
452 (void)RSqlDatabase::Delete(KTestDbName2); |
|
453 (void)RSqlDatabase::Delete(KTestDbName); |
|
454 } |
|
455 |
|
456 /** |
|
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 |
|
463 @SYMDEF DEF105928 |
|
464 */ |
|
465 void CfgSecureDbTest() |
|
466 { |
|
467 //Create |
|
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); |
|
477 TheDb.Close(); |
|
478 dbPolicy.Close(); |
|
479 //Open |
|
480 _LIT8(KCfgStr2, "cache_size = 100"); |
|
481 err = TheDb.Open(KTestDbName3, &KCfgStr2); |
|
482 TEST2(err, KErrNone); |
|
483 TheDb.Close(); |
|
484 (void)RSqlDatabase::Delete(KTestDbName3); |
|
485 } |
|
486 |
|
487 /** |
|
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 |
|
494 @SYMDEF DEF105928 |
|
495 */ |
|
496 void CfgPrivateDbTest() |
|
497 { |
|
498 //Create |
|
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); |
|
503 TheDb.Close(); |
|
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); |
|
509 TheDb.Close(); |
|
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); |
|
515 TheDb.Close(); |
|
516 (void)RSqlDatabase::Delete(KTestDbName4); |
|
517 } |
|
518 |
|
519 /** |
|
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. |
|
527 @SYMDEF INC106788 |
|
528 */ |
|
529 void INC106788() |
|
530 { |
|
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); |
|
537 TheDb.Close(); |
|
538 |
|
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); |
|
545 TheDb.Close(); |
|
546 |
|
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); |
|
553 TheDb.Close(); |
|
554 |
|
555 (void)RSqlDatabase::Delete(KTestDbName); |
|
556 } |
|
557 |
|
558 /** |
|
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 |
|
568 @SYMREQ REQ10405 |
|
569 */ |
|
570 void InjectionTest() |
|
571 { |
|
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);")); |
|
576 TEST(err > 0); |
|
577 TheDb.Close(); |
|
578 |
|
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); |
|
585 TInt recCount = 0; |
|
586 TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM A"))); |
|
587 TEST2(err, KErrNone); |
|
588 TEST2(recCount, 1); |
|
589 TheDb.Close(); |
|
590 |
|
591 _LIT8(KConfig2, "cache_size=256;compaction=DELETE FROM A;"); |
|
592 err = TheDb.Open(KTestDbName, &KConfig2); |
|
593 TEST2(err, KErrNone); |
|
594 query.SetDatabase(TheDb); |
|
595 recCount = 0; |
|
596 TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM A"))); |
|
597 TEST2(err, KErrNone); |
|
598 TEST2(recCount, 1); |
|
599 TheDb.Close(); |
|
600 (void)RSqlDatabase::Delete(KTestDbName); |
|
601 |
|
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); |
|
606 recCount = 0; |
|
607 TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM symbian_settings"))); |
|
608 TEST2(err, KErrNone); |
|
609 TEST2(recCount, 1); |
|
610 TheDb.Close(); |
|
611 (void)RSqlDatabase::Delete(KTestDbName); |
|
612 } |
|
613 |
|
614 /** |
|
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. |
|
622 @SYMDEF INC106788 |
|
623 */ |
|
624 void DEF142305() |
|
625 { |
|
626 _LIT8(KConfig, "cache_size=500"); |
|
627 |
|
628 //Create main db |
|
629 TInt err = TheDb.Create(KTestDbName, &KConfig); |
|
630 TEST2(err, KErrNone); |
|
631 AssertConfigPrmValues(TheDb, 500, KDefaultPageSize, KDefaultEncoding); |
|
632 TheDb.Close(); |
|
633 |
|
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); |
|
638 TheDb.Close(); |
|
639 |
|
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 |
|
645 TheDb.Close(); |
|
646 |
|
647 _LIT(KAttachDbName, "Attached"); |
|
648 |
|
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); |
|
658 TheDb.Close(); |
|
659 |
|
660 //Attach private db |
|
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); |
|
669 TheDb.Close(); |
|
670 |
|
671 (void)RSqlDatabase::Delete(KTestDbName4); |
|
672 (void)RSqlDatabase::Delete(KTestDbName2); |
|
673 (void)RSqlDatabase::Delete(KTestDbName); |
|
674 } |
|
675 |
|
676 void DoTests() |
|
677 { |
|
678 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3436 Sql config string - functional test ")); |
|
679 CfgFunctionalTest(); |
|
680 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3437 Sql config string - negative test ")); |
|
681 CfgNegativeTest(); |
|
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 ")); |
|
687 CfgSecureDbTest(); |
|
688 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3441 Sql config string - private database test ")); |
|
689 CfgPrivateDbTest(); |
|
690 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-3480 INC106788 - Cannot set SQLite page_size bigger than 4k (4096) ")); |
|
691 INC106788(); |
|
692 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4049 Config string - injection tests")); |
|
693 InjectionTest(); |
|
694 TheTest.Next(_L("@SYMTestCaseID:PDS-SQL-UT-4152: DEF142305 RSqlDatabase::Attach does not use cache_size configuration parameters")); |
|
695 DEF142305(); |
|
696 } |
|
697 |
|
698 TInt E32Main() |
|
699 { |
|
700 TheTest.Title(); |
|
701 |
|
702 CTrapCleanup* tc = CTrapCleanup::New(); |
|
703 TheTest(tc != NULL); |
|
704 |
|
705 __UHEAP_MARK; |
|
706 |
|
707 SetupTestEnv(); |
|
708 DoTests(); |
|
709 DestroyTestEnv(); |
|
710 |
|
711 __UHEAP_MARKEND; |
|
712 |
|
713 TheTest.End(); |
|
714 TheTest.Close(); |
|
715 |
|
716 delete tc; |
|
717 |
|
718 User::Heap().Check(); |
|
719 return KErrNone; |
|
720 } |