|
1 // Copyright (c) 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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <s32buf.h> |
|
18 #include <bautils.h> |
|
19 #include <sqldb.h> |
|
20 #include <stdio.h> |
|
21 #include <stdlib.h> |
|
22 #include "SqlResourceTester.h" //TSqlResourceTester |
|
23 #include "sqlite3.h" |
|
24 #include "SqliteSymbian.h" |
|
25 |
|
26 //In order to be able to compile the test, the following variables are defined (used inside the OS porting layer, |
|
27 //when _SQLPROFILER macro is defined) |
|
28 #ifdef _SQLPROFILER |
|
29 TInt TheSqlSrvProfilerFileRead = 0; |
|
30 TInt TheSqlSrvProfilerFileWrite = 0; |
|
31 TInt TheSqlSrvProfilerFileSync = 0; |
|
32 TInt TheSqlSrvProfilerFileSetSize = 0; |
|
33 #endif |
|
34 |
|
35 /////////////////////////////////////////////////////////////////////////////////////// |
|
36 |
|
37 RTest TheTest(_L("t_sqloom6 test")); |
|
38 |
|
39 _LIT(KTestDir, "c:\\test\\"); |
|
40 _LIT(KDbFile, "c:\\test\\t_sqloom6.db"); |
|
41 |
|
42 static RSqlDatabase TheDb; |
|
43 static RSqlStatement TheStmt; |
|
44 |
|
45 static TInt TheProcessHandleCount = 0; |
|
46 static TInt TheThreadHandleCount = 0; |
|
47 static TInt TheAllocatedCellsCount = 0; |
|
48 |
|
49 /////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
51 void DestroyTestEnv() |
|
52 { |
|
53 TheStmt.Close(); |
|
54 TheDb.Close(); |
|
55 (void)RSqlDatabase::Delete(KDbFile); |
|
56 sqlite3SymbianLibFinalize(); |
|
57 CloseSTDLIB(); |
|
58 } |
|
59 |
|
60 /////////////////////////////////////////////////////////////////////////////////////// |
|
61 /////////////////////////////////////////////////////////////////////////////////////// |
|
62 //Test macros and functions |
|
63 void Check(TInt aValue, TInt aLine) |
|
64 { |
|
65 if(!aValue) |
|
66 { |
|
67 DestroyTestEnv(); |
|
68 RDebug::Print(_L("*** Expresssion evaluated to false\r\n")); |
|
69 TheTest(EFalse, aLine); |
|
70 } |
|
71 } |
|
72 void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
73 { |
|
74 if(aValue != aExpected) |
|
75 { |
|
76 DestroyTestEnv(); |
|
77 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
78 TheTest(EFalse, aLine); |
|
79 } |
|
80 } |
|
81 #define TEST(arg) ::Check((arg), __LINE__) |
|
82 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
83 |
|
84 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 |
|
86 static void MarkHandles() |
|
87 { |
|
88 RThread().HandleCount(TheProcessHandleCount, TheThreadHandleCount); |
|
89 } |
|
90 |
|
91 static void MarkAllocatedCells() |
|
92 { |
|
93 TheAllocatedCellsCount = User::CountAllocCells(); |
|
94 } |
|
95 |
|
96 static void CheckAllocatedCells() |
|
97 { |
|
98 TInt allocatedCellsCount = User::CountAllocCells(); |
|
99 TEST2(allocatedCellsCount, TheAllocatedCellsCount); |
|
100 } |
|
101 |
|
102 static void CheckHandles() |
|
103 { |
|
104 TInt endProcessHandleCount; |
|
105 TInt endThreadHandleCount; |
|
106 |
|
107 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
108 |
|
109 TEST2(TheProcessHandleCount, endProcessHandleCount); |
|
110 TEST2(TheThreadHandleCount, endThreadHandleCount); |
|
111 } |
|
112 |
|
113 static void OomPreStep(TInt aFailingAllocationNo) |
|
114 { |
|
115 MarkHandles(); |
|
116 MarkAllocatedCells(); |
|
117 __UHEAP_MARK; |
|
118 TSqlResourceTester::Mark(); |
|
119 TSqlResourceTester::SetHeapFailure(RHeap::EBurstFailNext, aFailingAllocationNo); |
|
120 } |
|
121 |
|
122 static void OomPostStep() |
|
123 { |
|
124 __UHEAP_RESET; |
|
125 TSqlResourceTester::SetHeapFailure(RHeap::ENone, 0); |
|
126 TSqlResourceTester::Check(); |
|
127 CheckAllocatedCells(); |
|
128 CheckHandles(); |
|
129 } |
|
130 |
|
131 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
132 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
133 |
|
134 void CreateTestEnv() |
|
135 { |
|
136 RFs fs; |
|
137 TInt err = fs.Connect(); |
|
138 TEST2(err, KErrNone); |
|
139 |
|
140 err = fs.MkDir(KTestDir); |
|
141 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
142 |
|
143 err = fs.CreatePrivatePath(EDriveC); |
|
144 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
145 |
|
146 fs.Close(); |
|
147 |
|
148 sqlite3SymbianLibInit(); |
|
149 } |
|
150 |
|
151 //Creates a UTF8 encoded database with: |
|
152 // - One table with three colums: A(ColumnName1234567890, Col2, Col3); |
|
153 // - One record in the table with values: ('A1234567890', 'A12345', ''); |
|
154 void CreateTestDb(const TDesC& aDbName) |
|
155 { |
|
156 TBuf8<100> dbName8; |
|
157 dbName8.Copy(aDbName); |
|
158 sqlite3* db = 0; |
|
159 int rc = sqlite3_open((const char*)dbName8.PtrZ(), &db); |
|
160 TEST2(rc, SQLITE_OK); |
|
161 rc = sqlite3_exec(db, "CREATE TABLE A(ColumnName1234567890 TEXT, Col2 LONG TEXT, Col3 SMALL TEXT)", 0, 0, 0); |
|
162 TEST2(rc, SQLITE_OK); |
|
163 rc = sqlite3_exec(db, "INSERT INTO A VALUES('A1234567890', 'A12345', '')", 0, 0, 0); |
|
164 TEST2(rc, SQLITE_OK); |
|
165 sqlite3_close(db); |
|
166 } |
|
167 |
|
168 /** |
|
169 @SYMTestCaseID PDS-SQL-CT-4176 |
|
170 @SYMTestCaseDesc RSqlStatement::ColumnName() OOM test. |
|
171 @SYMTestPriority High |
|
172 @SYMTestActions The test runs RSqlStatement::ColumnName() in an OOM simulation loop. |
|
173 The difference betwee this test case and the similar test case in t_sqloom2 is that here: |
|
174 - burst OOM simulation is used; |
|
175 - UTF8 encoded database is used; |
|
176 - only SQL server side OOM simulation is performed; |
|
177 The purpose of the test is to verify that the ColumnName() call behaves correctly |
|
178 when the related sqlite3_column_name16() call performed by the SQL server fails |
|
179 with "no memory". |
|
180 @SYMTestExpectedResults Test must not fail |
|
181 @SYMDEF DEF145033 |
|
182 */ |
|
183 void ColumnNameOomTest() |
|
184 { |
|
185 //This is not really a full OOM test, because the SQL server counts only the number of active statement and |
|
186 //stream objects, the allocated memory cells are not counted. |
|
187 //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is |
|
188 //because the SQL server can make some per-connection memory allocations (cache pages, etc.) |
|
189 //and they will not be deallocated when the statement object is closed. |
|
190 //But the result of the RSqlStatement::ColumnName() operation is checked. If there is a failed memory |
|
191 //allocation on the server side, the returned column name can be NULL and that will be tested. |
|
192 |
|
193 (void)RSqlDatabase::Delete(KDbFile); |
|
194 |
|
195 TheTest.Printf(_L("Iteration:\r\n")); |
|
196 |
|
197 CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record. |
|
198 |
|
199 TInt err = TheDb.Open(KDbFile); |
|
200 TEST2(err, KErrNone); |
|
201 |
|
202 TInt failingAllocationNo = 0; |
|
203 err = KErrNoMemory; |
|
204 while(err == KErrNoMemory) |
|
205 { |
|
206 TheTest.Printf(_L(" %d"), ++failingAllocationNo); |
|
207 OomPreStep(failingAllocationNo); |
|
208 |
|
209 err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A")); |
|
210 if(err != KErrNone) |
|
211 { |
|
212 goto LabelOomPostStep; |
|
213 } |
|
214 |
|
215 TPtrC name; |
|
216 err = TheStmt.ColumnName(0, name); |
|
217 if(err != KErrNone) |
|
218 { |
|
219 goto LabelStmtClose; |
|
220 } |
|
221 TEST(name == _L("ColumnName1234567890")); |
|
222 |
|
223 err = TheStmt.ColumnName(1, name); |
|
224 if(err != KErrNone) |
|
225 { |
|
226 goto LabelStmtClose; |
|
227 } |
|
228 TEST(name == _L("Col2")); |
|
229 |
|
230 err = TheStmt.ColumnName(2, name); |
|
231 if(err != KErrNone) |
|
232 { |
|
233 goto LabelStmtClose; |
|
234 } |
|
235 TEST(name == _L("Col3")); |
|
236 |
|
237 LabelStmtClose: |
|
238 TheStmt.Close(); |
|
239 |
|
240 LabelOomPostStep: |
|
241 OomPostStep(); |
|
242 } |
|
243 |
|
244 TheDb.Close(); |
|
245 (void)RSqlDatabase::Delete(KDbFile); |
|
246 |
|
247 TEST2(err, KErrNone); |
|
248 TheTest.Printf(_L("\r\n===RSqlStatement::ColumnName() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo); |
|
249 } |
|
250 |
|
251 /** |
|
252 @SYMTestCaseID PDS-SQL-CT-4177 |
|
253 @SYMTestCaseDesc RSqlStatement::ParameterName() OOM test. |
|
254 @SYMTestPriority High |
|
255 @SYMTestActions The test runs RSqlStatement::ParameterName() in an OOM simulation loop. |
|
256 The difference betwee this test case and the similar test case in t_sqloom2 is that here: |
|
257 - burst OOM simulation is used; |
|
258 - UTF8 encoded database is used; |
|
259 - only SQL server side OOM simulation is performed; |
|
260 The purpose of the test is to verify that the ParameterName() call behaves correctly |
|
261 if the related sqlite3_bind_parameter_name() call performed by the SQL server fails |
|
262 with "no memory". |
|
263 @SYMTestExpectedResults Test must not fail |
|
264 @SYMDEF DEF145033 |
|
265 */ |
|
266 void ParameterNameOomTest() |
|
267 { |
|
268 //This is not really a full OOM test, because the SQL server counts only the number of active statement and |
|
269 //stream objects, the allocated memory cells are not counted. |
|
270 //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is |
|
271 //because the SQL server can make some per-connection memory allocations (cache pages, etc.) |
|
272 //and they will not be deallocated when the statement object is closed. |
|
273 //But the result of the RSqlStatement::ParameterName() operation is checked. If there is a failed memory |
|
274 //allocation on the server side, the returned column name can be NULL and that will be tested. |
|
275 |
|
276 (void)RSqlDatabase::Delete(KDbFile); |
|
277 |
|
278 TheTest.Printf(_L("Iteration:\r\n")); |
|
279 |
|
280 CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record. |
|
281 |
|
282 TInt err = TheDb.Open(KDbFile); |
|
283 TEST2(err, KErrNone); |
|
284 |
|
285 TInt failingAllocationNo = 0; |
|
286 err = KErrNoMemory; |
|
287 while(err == KErrNoMemory) |
|
288 { |
|
289 TheTest.Printf(_L(" %d"), ++failingAllocationNo); |
|
290 OomPreStep(failingAllocationNo); |
|
291 |
|
292 err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A WHERE Col2 != :Prm1234567890 AND Col3 != :Prm2 AND ColumnName1234567890 != ?")); |
|
293 if(err != KErrNone) |
|
294 { |
|
295 goto LabelOomPostStep; |
|
296 } |
|
297 |
|
298 TPtrC name; |
|
299 err = TheStmt.ParameterName(0, name); |
|
300 if(err != KErrNone) |
|
301 { |
|
302 goto LabelStmtClose; |
|
303 } |
|
304 TEST(name == _L(":Prm1234567890")); |
|
305 |
|
306 err = TheStmt.ParameterName(1, name); |
|
307 if(err != KErrNone) |
|
308 { |
|
309 goto LabelStmtClose; |
|
310 } |
|
311 TEST(name == _L(":Prm2")); |
|
312 |
|
313 err = TheStmt.ParameterName(2, name); |
|
314 if(err != KErrNone) |
|
315 { |
|
316 goto LabelStmtClose; |
|
317 } |
|
318 TEST(name == _L("?2")); |
|
319 |
|
320 LabelStmtClose: |
|
321 TheStmt.Close(); |
|
322 |
|
323 LabelOomPostStep: |
|
324 OomPostStep(); |
|
325 } |
|
326 |
|
327 TheDb.Close(); |
|
328 (void)RSqlDatabase::Delete(KDbFile); |
|
329 |
|
330 TEST2(err, KErrNone); |
|
331 TheTest.Printf(_L("\r\n===RSqlStatement::ColumnName() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo); |
|
332 } |
|
333 |
|
334 /** |
|
335 @SYMTestCaseID PDS-SQL-CT-4178 |
|
336 @SYMTestCaseDesc RSqlStatement::ColumnText() OOM test. |
|
337 @SYMTestPriority High |
|
338 @SYMTestActions The test runs RSqlStatement::ColumnText() in an OOM simulation loop. |
|
339 The difference betwee this test case and the similar test case in t_sqloom2 is that here: |
|
340 - burst OOM simulation is used; |
|
341 - UTF8 encoded database is used; |
|
342 - only SQL server side OOM simulation is performed; |
|
343 The purpose of the test is to verify that the ColumnText() call behaves correctly |
|
344 when the related sqlite3_column_text16() call performed by the SQL server fails |
|
345 with "no memory" (or the sqlite3_column_bytes16() call). |
|
346 @SYMTestExpectedResults Test must not fail |
|
347 @SYMDEF DEF145033 |
|
348 */ |
|
349 void ColumnTextOomTest() |
|
350 { |
|
351 //This is not really a full OOM test, because the SQL server counts only the number of active statement and |
|
352 //stream objects, the allocated memory cells are not counted. |
|
353 //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is |
|
354 //because the SQL server can make some per-connection memory allocations (cache pages, etc.) |
|
355 //and they will not be deallocated when the statement object is closed. |
|
356 //But the result of the RSqlStatement::ColumnText() operation is checked. If there is a failed memory |
|
357 //allocation on the server side, the returned column name can be NULL and that will be tested. |
|
358 |
|
359 (void)RSqlDatabase::Delete(KDbFile); |
|
360 |
|
361 TheTest.Printf(_L("Iteration:\r\n")); |
|
362 |
|
363 CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record. |
|
364 |
|
365 TInt err = TheDb.Open(KDbFile); |
|
366 TEST2(err, KErrNone); |
|
367 |
|
368 TInt failingAllocationNo = 0; |
|
369 err = KErrNoMemory; |
|
370 while(err == KErrNoMemory) |
|
371 { |
|
372 TheTest.Printf(_L(" %d"), ++failingAllocationNo); |
|
373 OomPreStep(failingAllocationNo); |
|
374 |
|
375 err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A")); |
|
376 if(err != KErrNone) |
|
377 { |
|
378 goto LabelOomPostStep; |
|
379 } |
|
380 err = TheStmt.Next(); |
|
381 if(err != KSqlAtRow) |
|
382 { |
|
383 goto LabelStmtClose; |
|
384 } |
|
385 |
|
386 TPtrC data; |
|
387 err = TheStmt.ColumnText(0, data); |
|
388 if(err != KErrNone) |
|
389 { |
|
390 goto LabelStmtClose; |
|
391 } |
|
392 TEST(data == _L("A1234567890")); |
|
393 |
|
394 err = TheStmt.ColumnText(1, data); |
|
395 if(err != KErrNone) |
|
396 { |
|
397 goto LabelStmtClose; |
|
398 } |
|
399 TEST(data == _L("A12345")); |
|
400 |
|
401 err = TheStmt.ColumnText(2, data); |
|
402 if(err != KErrNone) |
|
403 { |
|
404 goto LabelStmtClose; |
|
405 } |
|
406 TEST(data == _L("")); |
|
407 |
|
408 LabelStmtClose: |
|
409 TheStmt.Close(); |
|
410 |
|
411 LabelOomPostStep: |
|
412 OomPostStep(); |
|
413 } |
|
414 |
|
415 TheDb.Close(); |
|
416 (void)RSqlDatabase::Delete(KDbFile); |
|
417 |
|
418 TEST2(err, KErrNone); |
|
419 TheTest.Printf(_L("\r\n===RSqlStatement::ColumnText() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo); |
|
420 } |
|
421 |
|
422 /** |
|
423 @SYMTestCaseID PDS-SQL-CT-4179 |
|
424 @SYMTestCaseDesc RSqlColumnReadStream OOM test. |
|
425 @SYMTestPriority High |
|
426 @SYMTestActions The test runs RSqlColumnReadStream in an OOM simulation loop. |
|
427 The difference betwee this test case and the similar test case in t_sqloom2 is that here: |
|
428 - burst OOM simulation is used; |
|
429 - UTF8 encoded database is used; |
|
430 - only SQL server side OOM simulation is performed; |
|
431 The purpose of the test is to verify that the RSqlColumnReadStream APIs behave correctly |
|
432 when the related sqlite3_column_text16() call performed by the SQL server fails |
|
433 with "no memory" (or the sqlite3_column_bytes16() call). |
|
434 @SYMTestExpectedResults Test must not fail |
|
435 @SYMDEF DEF145033 |
|
436 */ |
|
437 void TextColumnReadStreamOomTest() |
|
438 { |
|
439 //This is not really a full OOM test, because the SQL server counts only the number of active statement and |
|
440 //stream objects, the allocated memory cells are not counted. |
|
441 //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is |
|
442 //because the SQL server can make some per-connection memory allocations (cache pages, etc.) |
|
443 //and they will not be deallocated when the statement object is closed. |
|
444 //But the result of the RSqlColumnReadStream::ReadL() operation is checked. If there is a failed memory |
|
445 //allocation on the server side, the returned column name can be NULL and that will be tested. |
|
446 |
|
447 (void)RSqlDatabase::Delete(KDbFile); |
|
448 |
|
449 TheTest.Printf(_L("Iteration:\r\n")); |
|
450 |
|
451 CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record. |
|
452 |
|
453 TInt err = TheDb.Open(KDbFile); |
|
454 TEST2(err, KErrNone); |
|
455 |
|
456 TInt failingAllocationNo = 0; |
|
457 err = KErrNoMemory; |
|
458 while(err == KErrNoMemory) |
|
459 { |
|
460 TheTest.Printf(_L(" %d"), ++failingAllocationNo); |
|
461 OomPreStep(failingAllocationNo); |
|
462 |
|
463 err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A")); |
|
464 if(err != KErrNone) |
|
465 { |
|
466 goto LabelOomPostStep; |
|
467 } |
|
468 err = TheStmt.Next(); |
|
469 if(err != KSqlAtRow) |
|
470 { |
|
471 goto LabelCloseStmt; |
|
472 } |
|
473 |
|
474 RSqlColumnReadStream strm; |
|
475 err = strm.ColumnText(TheStmt, 0); |
|
476 if(err != KErrNone) |
|
477 { |
|
478 goto LabelCloseStmt; |
|
479 } |
|
480 TBuf<50> data; |
|
481 TRAP(err, strm.ReadL(data, 11)); |
|
482 strm.Close(); |
|
483 if(err != KErrNone) |
|
484 { |
|
485 goto LabelCloseStmt; |
|
486 } |
|
487 TEST(data == _L("A1234567890")); |
|
488 |
|
489 err = strm.ColumnText(TheStmt, 1); |
|
490 if(err != KErrNone) |
|
491 { |
|
492 goto LabelCloseStmt; |
|
493 } |
|
494 TRAP(err, strm.ReadL(data, 6)); |
|
495 strm.Close(); |
|
496 if(err != KErrNone) |
|
497 { |
|
498 goto LabelCloseStmt; |
|
499 } |
|
500 TEST(data == _L("A12345")); |
|
501 |
|
502 err = strm.ColumnText(TheStmt, 2); |
|
503 if(err != KErrNone) |
|
504 { |
|
505 goto LabelCloseStmt; |
|
506 } |
|
507 TInt len = -1; |
|
508 TRAP(err, len = strm.Source()->SizeL());//The column value is with 0 length |
|
509 strm.Close(); |
|
510 if(err != KErrNone) |
|
511 { |
|
512 goto LabelCloseStmt; |
|
513 } |
|
514 TEST2(len, 0); |
|
515 |
|
516 LabelCloseStmt: |
|
517 TheStmt.Close(); |
|
518 |
|
519 LabelOomPostStep: |
|
520 OomPostStep(); |
|
521 } |
|
522 |
|
523 TheDb.Close(); |
|
524 (void)RSqlDatabase::Delete(KDbFile); |
|
525 |
|
526 TEST2(err, KErrNone); |
|
527 TheTest.Printf(_L("\r\n===RSqlColumnReadStream OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo); |
|
528 } |
|
529 |
|
530 /** |
|
531 @SYMTestCaseID PDS-SQL-CT-4180 |
|
532 @SYMTestCaseDesc TSqlScalarFullSelectQuery::SelectTextL() OOM test. |
|
533 @SYMTestPriority High |
|
534 @SYMTestActions The test runs TSqlScalarFullSelectQuery::SelectTextL() in an OOM simulation loop. |
|
535 The difference betwee this test case and the similar test case in t_sqloom2 is that here: |
|
536 - burst OOM simulation is used; |
|
537 - UTF8 encoded database is used; |
|
538 - only SQL server side OOM simulation is performed; |
|
539 The purpose of the test is to verify that the SelectTextL() call behaves correctly |
|
540 when the related sqlite3_column_text16() call performed by the SQL server fails |
|
541 with "no memory" (or the sqlite3_column_bytes16() call). |
|
542 @SYMTestExpectedResults Test must not fail |
|
543 @SYMDEF DEF145033 |
|
544 */ |
|
545 void ScalarColumnTextOomTest() |
|
546 { |
|
547 //This is not really a full OOM test, because the SQL server counts only the number of active statement and |
|
548 //stream objects, the allocated memory cells are not counted. |
|
549 //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is |
|
550 //because the SQL server can make some per-connection memory allocations (cache pages, etc.) |
|
551 //and they will not be deallocated when the statement object is closed. |
|
552 //But the result of the TSqlScalarFullSelectQuery::SelectTextL() operation is checked. If there is a failed memory |
|
553 //allocation on the server side, the returned column name can be NULL and that will be tested. |
|
554 |
|
555 (void)RSqlDatabase::Delete(KDbFile); |
|
556 |
|
557 TheTest.Printf(_L("Iteration:\r\n")); |
|
558 |
|
559 CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record. |
|
560 |
|
561 TInt err = TheDb.Open(KDbFile); |
|
562 TEST2(err, KErrNone); |
|
563 |
|
564 TInt failingAllocationNo = 0; |
|
565 err = KErrNoMemory; |
|
566 while(err == KErrNoMemory) |
|
567 { |
|
568 TheTest.Printf(_L(" %d"), ++failingAllocationNo); |
|
569 OomPreStep(failingAllocationNo); |
|
570 |
|
571 TSqlScalarFullSelectQuery query(TheDb); |
|
572 TBuf<50> data; |
|
573 TRAP(err, query.SelectTextL(_L("SELECT ColumnName1234567890 FROM A"), data)); |
|
574 if(err != KErrNone) |
|
575 { |
|
576 goto LabelOomPostStep; |
|
577 } |
|
578 TEST(data == _L("A1234567890")); |
|
579 |
|
580 TRAP(err, query.SelectTextL(_L("SELECT Col2 FROM A"), data)); |
|
581 if(err != KErrNone) |
|
582 { |
|
583 goto LabelOomPostStep; |
|
584 } |
|
585 TEST(data == _L("A12345")); |
|
586 |
|
587 TRAP(err, query.SelectTextL(_L("SELECT Col3 FROM A"), data)); |
|
588 if(err != KErrNone) |
|
589 { |
|
590 goto LabelOomPostStep; |
|
591 } |
|
592 TEST(data == _L("")); |
|
593 |
|
594 LabelOomPostStep: |
|
595 OomPostStep(); |
|
596 } |
|
597 |
|
598 TheDb.Close(); |
|
599 (void)RSqlDatabase::Delete(KDbFile); |
|
600 |
|
601 TEST2(err, KErrNone); |
|
602 TheTest.Printf(_L("\r\n===TSqlScalarFullSelectQuery::SelectTextL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo); |
|
603 } |
|
604 |
|
605 /** |
|
606 @SYMTestCaseID PDS-SQL-CT-4181 |
|
607 @SYMTestCaseDesc RSqlStatement::DeclaredColumnType() OOM test. |
|
608 @SYMTestPriority High |
|
609 @SYMTestActions The test runs RSqlStatement::DeclaredColumnType() in an OOM simulation loop. |
|
610 The difference betwee this test case and the similar test case in t_sqloom2 is that here: |
|
611 - burst OOM simulation is used; |
|
612 - UTF8 encoded database is used; |
|
613 - only SQL server side OOM simulation is performed; |
|
614 The purpose of the test is to verify that the DeclaredColumnType() call behaves correctly |
|
615 when the related sqlite3_column_name16() call performed by the SQL server fails |
|
616 with "no memory". |
|
617 @SYMTestExpectedResults Test must not fail |
|
618 @SYMDEF DEF145033 |
|
619 */ |
|
620 void DeclaredColumnTypeOomTest() |
|
621 { |
|
622 //This is not really a full OOM test, because the SQL server counts only the number of active statement and |
|
623 //stream objects, the allocated memory cells are not counted. |
|
624 //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is |
|
625 //because the SQL server can make some per-connection memory allocations (cache pages, etc.) |
|
626 //and they will not be deallocated when the statement object is closed. |
|
627 //But the result of the RSqlStatement::DeclaredColumnType() operation is checked. If there is a failed memory |
|
628 //allocation on the server side, the returned column name can be NULL and that will be tested. |
|
629 |
|
630 (void)RSqlDatabase::Delete(KDbFile); |
|
631 |
|
632 TheTest.Printf(_L("Iteration:\r\n")); |
|
633 |
|
634 CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record. |
|
635 |
|
636 TInt err = TheDb.Open(KDbFile); |
|
637 TEST2(err, KErrNone); |
|
638 |
|
639 TInt failingAllocationNo = 0; |
|
640 err = KErrNoMemory; |
|
641 while(err == KErrNoMemory) |
|
642 { |
|
643 TheTest.Printf(_L(" %d"), ++failingAllocationNo); |
|
644 OomPreStep(failingAllocationNo); |
|
645 |
|
646 err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A")); |
|
647 if(err != KErrNone) |
|
648 { |
|
649 goto LabelOomPostStep; |
|
650 } |
|
651 |
|
652 TSqlColumnType colType = ESqlNull; |
|
653 err = TheStmt.DeclaredColumnType(0, colType); |
|
654 if(err != KErrNone) |
|
655 { |
|
656 goto LabelStmtClose; |
|
657 } |
|
658 TEST2(colType, ESqlText); |
|
659 |
|
660 colType = ESqlNull; |
|
661 err = TheStmt.DeclaredColumnType(1, colType); |
|
662 if(err != KErrNone) |
|
663 { |
|
664 goto LabelStmtClose; |
|
665 } |
|
666 TEST2(colType, ESqlText); |
|
667 |
|
668 colType = ESqlNull; |
|
669 err = TheStmt.DeclaredColumnType(2, colType); |
|
670 if(err != KErrNone) |
|
671 { |
|
672 goto LabelStmtClose; |
|
673 } |
|
674 TEST2(colType, ESqlText); |
|
675 |
|
676 LabelStmtClose: |
|
677 TheStmt.Close(); |
|
678 |
|
679 LabelOomPostStep: |
|
680 OomPostStep(); |
|
681 } |
|
682 |
|
683 TheDb.Close(); |
|
684 (void)RSqlDatabase::Delete(KDbFile); |
|
685 |
|
686 TEST2(err, KErrNone); |
|
687 TheTest.Printf(_L("\r\n===RSqlStatement::DeclaredColumnType() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo); |
|
688 } |
|
689 |
|
690 void DoTests() |
|
691 { |
|
692 TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-CT-4176 RSqlStatement::ColumnName() OOM test")); |
|
693 ColumnNameOomTest(); |
|
694 |
|
695 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4177 RSqlStatement::ParameterName() OOM test")); |
|
696 ParameterNameOomTest(); |
|
697 |
|
698 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4178 RSqlStatement::ColumnText() OOM test")); |
|
699 ColumnTextOomTest(); |
|
700 |
|
701 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4179 RSqlColumnReadStream OOM test")); |
|
702 TextColumnReadStreamOomTest(); |
|
703 |
|
704 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4180 TSqlScalarFullSelectQuery::SelectTextL() OOM test")); |
|
705 ScalarColumnTextOomTest(); |
|
706 |
|
707 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4181 RSqlStatement::DeclaredColumnType() OOM test")); |
|
708 DeclaredColumnTypeOomTest(); |
|
709 } |
|
710 |
|
711 TInt E32Main() |
|
712 { |
|
713 TheTest.Title(); |
|
714 |
|
715 CTrapCleanup* tc = CTrapCleanup::New(); |
|
716 TheTest(tc != NULL); |
|
717 |
|
718 __UHEAP_MARK; |
|
719 |
|
720 CreateTestEnv(); |
|
721 DoTests(); |
|
722 DestroyTestEnv(); |
|
723 |
|
724 __UHEAP_MARKEND; |
|
725 |
|
726 TheTest.End(); |
|
727 TheTest.Close(); |
|
728 |
|
729 delete tc; |
|
730 |
|
731 User::Heap().Check(); |
|
732 return KErrNone; |
|
733 } |