First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include "SqlSrvMain.h"
19 #include "SqlSrvStartup.h"
20 #include "SqlSrvUtil.h"
21 #include "SqlSrvDatabase.h"
22 #include "SqlSrvFileData.h"
24 ///////////////////////////////////////////////////////////////////////////////////////
26 RTest TheTest(_L("t_sqloom5 test"));
29 _LIT(KTestDir, "c:\\test\\");
30 _LIT(KDbFile, "c:\\test\\t_sqloom5.db");
31 _LIT(KDbFile2, "c:[10281E17]t_sqloom5.db");
32 _LIT(KDbFile3, "c:[10281E17]t_sqloom5_2.db");
33 _LIT(KDbFile4, "c:[10281E17]t_sqloom5_3.db");
35 _LIT8(KConfig, "encoding=UTF-8");
37 extern CSqlServer* TheServer;
39 static TInt TheProcessHandleCount = 0;
40 static TInt TheThreadHandleCount = 0;
41 static TInt TheAllocatedCellsCount = 0;
44 static const TInt KBurstRate = 20;
53 ///////////////////////////////////////////////////////////////////////////////////////
57 (void)TheFs.Delete(KDbFile4);
58 (void)TheFs.Delete(KDbFile3);
59 (void)TheFs.Delete(KDbFile2);
60 (void)TheFs.Delete(KDbFile);
64 ///////////////////////////////////////////////////////////////////////////////////////
65 ///////////////////////////////////////////////////////////////////////////////////////
66 //Test macros and functions
67 void Check(TInt aValue, TInt aLine)
72 RDebug::Print(_L("*** Expresssion evaluated to false\r\n"));
73 TheTest(EFalse, aLine);
76 void Check(TInt aValue, TInt aExpected, TInt aLine)
78 if(aValue != aExpected)
81 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
82 TheTest(EFalse, aLine);
85 #define TEST(arg) ::Check((arg), __LINE__)
86 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
88 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
90 static void MarkHandles()
92 RThread().HandleCount(TheProcessHandleCount, TheThreadHandleCount);
95 static void MarkAllocatedCells()
97 TheAllocatedCellsCount = User::CountAllocCells();
100 static void CheckAllocatedCells()
102 TInt allocatedCellsCount = User::CountAllocCells();
103 TEST2(allocatedCellsCount, TheAllocatedCellsCount);
106 static void CheckHandles()
108 TInt endProcessHandleCount;
109 TInt endThreadHandleCount;
111 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
113 TEST2(TheProcessHandleCount, endProcessHandleCount);
114 TEST2(TheThreadHandleCount, endThreadHandleCount);
117 static void OomPreStep(TInt
124 MarkAllocatedCells();
126 __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, aFailingAllocationNo, KBurstRate);
129 static void OomPostStep()
133 CheckAllocatedCells();
137 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
138 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
142 TInt err = TheFs.Connect();
143 TEST2(err, KErrNone);
145 err = TheFs.MkDir(KTestDir);
146 TEST(err == KErrNone || err == KErrAlreadyExists);
148 err = TheFs.CreatePrivatePath(EDriveC);
149 TEST(err == KErrNone || err == KErrAlreadyExists);
152 static CSqlServer* CreateSqlServerL()
154 CSqlServer* server = CSqlServer::NewLC();
155 CleanupStack::Pop(server);
159 void CreateDatabaseOomTest(TSqlDbEncoding aEncoding)
161 (void)TheFs.Delete(KDbFile);
162 TInt failingAllocationNo = 0;
163 TheTest.Printf(_L("Iteration:\r\n"));
166 TRAPD(err, TheServer = CreateSqlServerL());
167 TEST2(err, KErrNone);
170 while(err == KErrNoMemory)
172 TheTest.Printf(_L(" %d"), ++failingAllocationNo);
173 OomPreStep(failingAllocationNo);
175 TSqlSrvFileData& fdata = TheServer->FileData();
177 TRAP(err, fdata.SetL(msg, KDbFile().Length(), 0, KDbFile, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
180 CSqlSrvDatabase* db = NULL;
181 TRAP(err, db = CSqlSrvDatabase::CreateL(fdata));
190 TEST2(err, KErrNone);
191 TheTest.Printf(_L("\r\n===CSqlSrvDatabase::CreateL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
195 @SYMTestCaseID PDS-SQL-UT-4167
196 @SYMTestCaseDesc CSqlSrvDatabase::CreateL() OOM test.
197 @SYMTestPriority High
198 @SYMTestActions The test runs CSqlSrvDatabase::CreateL() in an OOM loop.
199 UTF16 encoded database is used.
200 @SYMTestExpectedResults Test must not fail
203 void Utf16CreateDatabaseOomTest()
205 CreateDatabaseOomTest(ESqlDbUtf16);
209 @SYMTestCaseID PDS-SQL-UT-4182
210 @SYMTestCaseDesc CSqlSrvDatabase::CreateL() OOM test.
211 @SYMTestPriority High
212 @SYMTestActions The test runs CSqlSrvDatabase::CreateL() in an OOM loop.
213 UTF8 encoded database is used.
214 @SYMTestExpectedResults Test must not fail
217 void Utf8CreateDatabaseOomTest()
219 CreateDatabaseOomTest(ESqlDbUtf8);
222 void OpenDatabaseOomTest()
224 //The database is created by the previous test: CreateDatabaseOomTest().
226 TInt failingAllocationNo = 0;
227 TheTest.Printf(_L("Iteration:\r\n"));
230 TRAPD(err, TheServer = CreateSqlServerL());
231 TEST2(err, KErrNone);
234 while(err == KErrNoMemory)
236 TheTest.Printf(_L(" %d"), ++failingAllocationNo);
237 OomPreStep(failingAllocationNo);
239 TSqlSrvFileData& fdata = TheServer->FileData();
241 TRAP(err, fdata.SetL(msg, KDbFile().Length(), 0, KDbFile));
244 CSqlSrvDatabase* db = NULL;
245 TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
255 TEST2(err, KErrNone);
256 TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() [non-secure db] OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
260 @SYMTestCaseID PDS-SQL-UT-4168
261 @SYMTestCaseDesc CSqlSrvDatabase::OpenL() OOM test - non-secure database.
262 @SYMTestPriority High
263 @SYMTestActions The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
264 UTF16 encoded database is used.
265 @SYMTestExpectedResults Test must not fail
268 void Utf16OpenDatabaseOomTest()
270 OpenDatabaseOomTest();
274 @SYMTestCaseID PDS-SQL-UT-4183
275 @SYMTestCaseDesc CSqlSrvDatabase::OpenL() OOM test - non-secure database.
276 @SYMTestPriority High
277 @SYMTestActions The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
278 UTF8 encoded database is used.
279 @SYMTestExpectedResults Test must not fail
282 void Utf8OpenDatabaseOomTest()
284 OpenDatabaseOomTest();
287 void CreateSecureDatabaseOomTest(TSqlDbEncoding aEncoding)
289 (void)TheFs.Delete(KDbFile2);
290 TInt failingAllocationNo = 0;
291 TheTest.Printf(_L("Iteration:\r\n"));
294 TRAPD(err, TheServer = CreateSqlServerL());
295 TEST2(err, KErrNone);
298 while(err == KErrNoMemory)
300 TheTest.Printf(_L(" %d"), ++failingAllocationNo);
301 OomPreStep(failingAllocationNo);
303 TSqlSrvFileData& fdata = TheServer->FileData();
305 TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
308 TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
309 CSqlSecurityPolicy* policy = NULL;
310 TRAP(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
313 CSqlSrvDatabase* db = NULL;
314 TRAP(err, db = CSqlSrvDatabase::CreateSecureL(fdata, policy));
324 TEST2(err, KErrNone);
325 TheTest.Printf(_L("\r\n===CSqlSrvDatabase::CreateSecureL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
329 @SYMTestCaseID PDS-SQL-UT-4169
330 @SYMTestCaseDesc CSqlSrvDatabase::CreateSecureL() OOM test.
331 @SYMTestPriority High
332 @SYMTestActions The test runs CSqlSrvDatabase::CreateSecureL() in an OOM loop.
333 UTF16 encoded database is used.
334 @SYMTestExpectedResults Test must not fail
337 void Utf16CreateSecureDatabaseOomTest()
339 CreateSecureDatabaseOomTest(ESqlDbUtf16);
343 @SYMTestCaseID PDS-SQL-UT-4184
344 @SYMTestCaseDesc CSqlSrvDatabase::CreateSecureL() OOM test.
345 @SYMTestPriority High
346 @SYMTestActions The test runs CSqlSrvDatabase::CreateSecureL() in an OOM loop.
347 UTF8 encoded database is used.
348 @SYMTestExpectedResults Test must not fail
351 void Utf8CreateSecureDatabaseOomTest()
353 CreateSecureDatabaseOomTest(ESqlDbUtf8);
356 void OpenSecureDatabaseOomTest()
358 //The database is created by the previous test: CreateSecureDatabaseOomTest().
360 TInt failingAllocationNo = 0;
361 TheTest.Printf(_L("Iteration:\r\n"));
364 TRAPD(err, TheServer = CreateSqlServerL());
365 TEST2(err, KErrNone);
368 while(err == KErrNoMemory)
370 TheTest.Printf(_L(" %d"), ++failingAllocationNo);
371 OomPreStep(failingAllocationNo);
373 TSqlSrvFileData& fdata = TheServer->FileData();
375 TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2));
378 CSqlSrvDatabase* db = NULL;
379 TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
389 TEST2(err, KErrNone);
390 TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() [secure db] OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
394 @SYMTestCaseID PDS-SQL-UT-4170
395 @SYMTestCaseDesc CSqlSrvDatabase::OpenL() OOM test - secure database.
396 @SYMTestPriority High
397 @SYMTestActions The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
398 UTF16 encoded database is used.
399 @SYMTestExpectedResults Test must not fail
400 @SYMDEF DEF144577, PDEF44845
402 void Utf16OpenSecureDatabaseOomTest()
404 OpenSecureDatabaseOomTest();
408 @SYMTestCaseID PDS-SQL-UT-4185
409 @SYMTestCaseDesc CSqlSrvDatabase::OpenL() OOM test - secure database.
410 @SYMTestPriority High
411 @SYMTestActions The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
412 UTF8 encoded database is used.
413 @SYMTestExpectedResults Test must not fail
416 void Utf8OpenSecureDatabaseOomTest()
418 OpenSecureDatabaseOomTest();
421 /////////////////////////////////////////////////////////////
423 const TInt KDbConnCount = 7;
425 const TInt KDbAttachedCount = 10;
427 TBuf<10> TheAttachedDbName;
429 //Declares KDbConnCount "CSqlSrvDatabase*" variables.
430 #define TEST_DECLARE_DB_VARS() \
431 CSqlSrvDatabase* db[KDbConnCount]; \
432 Mem::FillZ(db, sizeof(db));
434 //Declares all KDbConnCount "CSqlSrvDatabase*" objects.
435 #define TEST_DELETE_DB() \
436 for(TInt i=0;i<KDbConnCount;++i) \
441 //Creates CSqlSrvDatabase object where the database file is dbFile (the second macro parameter).
442 //The CSqlSrvDatabase pointer db[N - 1] (N is the first macro parameter) will be set to point to
443 //the created CSqlSrvDatabase object.
444 //N is the number of the database to be opened, between 1 and KDbConnCount.
445 #define TEST_OPEN_DB(N, dbFile) \
446 __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
447 TRAP(err, fdata.SetL(msg, dbFile.Length(), 0, dbFile)); \
448 if(err != KErrNone) \
453 TRAP(err, db[N - 1] = CSqlSrvDatabase::OpenL(fdata)); \
454 if(err != KErrNone) \
459 //Attaches the "dbFile" database to the database number specified by the first macro parameter.
460 //The attached database name is "A<M>", where M is the third macro parameter.
461 //N is the number of the database connection, between 1 and KDbConnCount.
462 //M is the number of the database to be attached, between 1 and KDbAttachedCount.
463 #define TEST_ATTACH_DB(N, dbFile, M) \
464 __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
465 __ASSERT_DEBUG(M > 0 && M <= KDbAttachedCount, User::Invariant()); \
466 TRAP(err, fdata.SetL(msg, dbFile.Length(), 0, dbFile)); \
467 if(err != KErrNone) \
471 TheAttachedDbName.Copy(_L("A")); \
472 TheAttachedDbName.AppendNum(M); \
473 TRAP(err, db[N - 1]->AttachDbL(fdata, TheAttachedDbName)); \
474 if(err != KErrNone) \
479 //Detaches database "A<M>" (M is the second macro parameter) from the database identified
480 //by the number N - the first macro parameter.
481 //N is the number of the database connection, between 1 and KDbConnCount.
482 //M is the number of the database to be detached, between 1 and KDbAttachedCount.
483 #define TEST_DETACH_DB(N, M) \
484 __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
485 __ASSERT_DEBUG(M > 0 && M <= KDbAttachedCount, User::Invariant()); \
488 TheAttachedDbName.Copy(_L("A")); \
489 TheAttachedDbName.AppendNum(M); \
490 TRAP_IGNORE(db[N - 1]->DetachDbL(TheAttachedDbName)); \
493 /////////////////////////////////////////////////////////////
495 void CreateSecureTestDb(const TDesC& aDbFile, TSqlDbEncoding aEncoding)
497 (void)TheFs.Delete(aDbFile);
499 TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
500 CSqlSecurityPolicy* policy = NULL;
501 TRAPD(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
502 TEST2(err, KErrNone);
504 TSqlSrvFileData& fdata = TheServer->FileData();
506 TRAP(err, fdata.SetL(msg, aDbFile.Length(), 0, aDbFile, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
508 CSqlSrvDatabase* db = NULL;
509 TRAP(err, db = CSqlSrvDatabase::CreateSecureL(fdata, policy));
511 TEST2(err, KErrNone);
514 void OpenAttachDatabaseOomTest(TSqlDbEncoding aEncoding)
516 //Part of the databases are created by the previous tests.
518 TInt failingAllocationNo = 0;
519 TheTest.Printf(_L("Iteration:\r\n"));
522 TRAPD(err, TheServer = CreateSqlServerL());
523 TEST2(err, KErrNone);
525 CreateSecureTestDb(KDbFile3, aEncoding);
526 CreateSecureTestDb(KDbFile4, aEncoding);
528 //The following 2 declarations are used by the macros in the OOM loop
530 TSqlSrvFileData& fdata = TheServer->FileData();
533 while(err == KErrNoMemory)
535 TheTest.Printf(_L(" %d"), ++failingAllocationNo);
536 OomPreStep(failingAllocationNo);
537 //Declare KDbConnCount "CSqlSrvDatabase*" variables.
538 TEST_DECLARE_DB_VARS();
539 //Create CSqlSrvDatabase object, the database name is the second parameter of the macro.
540 //The related db[N - 1] variable will be set to point to the created object.
541 TEST_OPEN_DB(1, KDbFile2());
542 TEST_OPEN_DB(2, KDbFile2());
543 TEST_OPEN_DB(3, KDbFile3());
544 TEST_OPEN_DB(4, KDbFile3());
545 TEST_OPEN_DB(5, KDbFile3());
546 TEST_OPEN_DB(6, KDbFile());
547 TEST_OPEN_DB(7, KDbFile());
548 //Attach to the database with the number specified as first macro parameter, the database file, specified
549 //as second macro parameter. The logical name of the attached database is "A<M>", where M is the third macro parameter.
550 TEST_ATTACH_DB(1, KDbFile(), 1);
551 TEST_ATTACH_DB(2, KDbFile(), 2);
552 TEST_ATTACH_DB(2, KDbFile(), 3);
553 TEST_ATTACH_DB(5, KDbFile4(), 4);
554 TEST_ATTACH_DB(2, KDbFile4(), 5);
555 TEST_ATTACH_DB(2, KDbFile4(), 6);
556 TEST_ATTACH_DB(5, KDbFile4(), 7);
557 TEST_ATTACH_DB(5, KDbFile4(), 8);
558 TEST_ATTACH_DB(1, KDbFile4(), 9);
559 TEST_ATTACH_DB(1, KDbFile(), 10);
561 __UHEAP_SETBURSTFAIL(RAllocator::ENone, 0, 0);
562 //Detach from the database with the number specified as first macro parameter, the database
563 //with name "A<M>", where M is the second macro parameter.
564 TEST_DETACH_DB(1, 9);
565 TEST_DETACH_DB(1, 1);
566 TEST_DETACH_DB(1, 10);
567 TEST_DETACH_DB(2, 2);
568 TEST_DETACH_DB(2, 3);
569 TEST_DETACH_DB(2, 5);
570 TEST_DETACH_DB(2, 6);
571 TEST_DETACH_DB(5, 4);
572 TEST_DETACH_DB(5, 7);
573 TEST_DETACH_DB(5, 8);
574 //Delete all created CSqlSrvDatabase objects.
583 (void)TheFs.Delete(KDbFile4);
584 (void)TheFs.Delete(KDbFile3);
586 TEST2(err, KErrNone);
587 TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
591 @SYMTestCaseID PDS-SQL-UT-4171
592 @SYMTestCaseDesc CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
593 @SYMTestPriority High
594 @SYMTestActions The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
595 The test is a complex one - 7 (KDbConnCount constant) databases opened
596 (secure and non-secure), 10 (KDbAttachedCount constant) databases
597 attached (secure and non-secure).
598 UTF16 encoded database is used.
599 @SYMTestExpectedResults Test must not fail
600 @SYMDEF DEF144577, DEF144603
602 void Utf16OpenAttachDatabaseOomTest()
604 OpenAttachDatabaseOomTest(ESqlDbUtf16);
608 @SYMTestCaseID PDS-SQL-UT-4186
609 @SYMTestCaseDesc CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
610 @SYMTestPriority High
611 @SYMTestActions The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
612 The test is a complex one - 7 (KDbConnCount constant) databases opened
613 (secure and non-secure), 10 (KDbAttachedCount constant) databases
614 attached (secure and non-secure).
615 UTF8 encoded database is used.
616 @SYMTestExpectedResults Test must not fail
619 void Utf8OpenAttachDatabaseOomTest()
621 OpenAttachDatabaseOomTest(ESqlDbUtf8);
624 void OpenAttachDatabaseOomTest2(TSqlDbEncoding aEncoding)
627 TRAPD(err, TheServer = CreateSqlServerL());
628 TEST2(err, KErrNone);
630 CreateSecureTestDb(KDbFile3, aEncoding);
631 CreateSecureTestDb(KDbFile4, aEncoding);
633 TInt failingAllocationNo = 0;
634 TheTest.Printf(_L("Iteration:\r\n"));
637 TSqlSrvFileData& fdata = TheServer->FileData();
640 while(err == KErrNoMemory)
642 TheTest.Printf(_L(" %d"), ++failingAllocationNo);
643 OomPreStep(failingAllocationNo);
645 TRAP(err, fdata.SetL(msg, KDbFile3().Length(), 0, KDbFile3));
648 CSqlSrvDatabase* db = NULL;
649 TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
652 TRAP(err, fdata.SetL(msg, KDbFile4().Length(), 0, KDbFile4));
655 TRAP(err, db->AttachDbL(fdata, _L("db2")));
658 TRAP(err, db->DetachDbL(_L("db2")));
667 (void)TheFs.Delete(KDbFile4);
668 (void)TheFs.Delete(KDbFile3);
673 TEST2(err, KErrNone);
674 TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test 2 succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
678 @SYMTestCaseID PDS-SQL-UT-4172
679 @SYMTestCaseDesc CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
680 @SYMTestPriority High
681 @SYMTestActions The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
682 Two secure databases are created and then, in an OOM loop, the test executes this sequence of
683 commands: open first database, attach the second database, detach the attached database,
684 close the first database.
685 UTF16 encoded database is used.
686 @SYMTestExpectedResults Test must not fail
687 @SYMDEF DEF144577, PDEF44845
689 void Utf16OpenAttachDatabaseOomTest2()
691 OpenAttachDatabaseOomTest2(ESqlDbUtf16);
695 @SYMTestCaseID PDS-SQL-UT-4187
696 @SYMTestCaseDesc CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
697 @SYMTestPriority High
698 @SYMTestActions The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
699 Two secure databases are created and then, in an OOM loop, the test executes this sequence of
700 commands: open first database, attach the second database, detach the attached database,
701 close the first database.
702 UTF8 encoded database is used.
703 @SYMTestExpectedResults Test must not fail
706 void Utf8OpenAttachDatabaseOomTest2()
708 OpenAttachDatabaseOomTest2(ESqlDbUtf8);
711 void OpenCreateDatabaseOomTest(TSqlDbEncoding aEncoding)
714 TRAPD(err, TheServer = CreateSqlServerL());
715 TEST2(err, KErrNone);
717 (void)TheFs.Delete(KDbFile2);
718 CreateSecureTestDb(KDbFile2, aEncoding);
720 TheTest.Printf(_L("Iteration:\r\n"));
723 TInt failingAllocationNo = 0;
725 while(err == KErrNoMemory)
727 TheTest.Printf(_L(" %d"), ++failingAllocationNo);
728 OomPreStep(failingAllocationNo);
731 TSqlSrvFileData& fdata = TheServer->FileData();
732 TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2));
735 CSqlSrvDatabase* db = NULL;
736 TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
748 TEST2(err, KErrNone);
749 err = TheFs.Delete(KDbFile2);
750 TEST2(err, KErrNone);
751 //Create the database
752 TInt failingAllocationNo2 = 0;
754 while(err == KErrNoMemory)
756 TheTest.Printf(_L(" %d"), ++failingAllocationNo2);
757 OomPreStep(failingAllocationNo2);
759 TSqlSrvFileData& fdata = TheServer->FileData();
760 TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
763 TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
764 CSqlSecurityPolicy* policy = NULL;
765 TRAP(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
768 CSqlSrvDatabase* db = NULL;
769 TRAP(err, db = CSqlSrvDatabase::CreateSecureL(fdata, policy));
783 (void)TheFs.Delete(KDbFile2);
788 TEST2(err, KErrNone);
789 TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateSecureL() OOM test succeeded at heap failure rate of %d ===\r\n"),
790 failingAllocationNo + failingAllocationNo2);
794 @SYMTestCaseID PDS-SQL-UT-4173
795 @SYMTestCaseDesc CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateSecureL() OOM test.
796 @SYMTestPriority High
797 @SYMTestActions The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::CreateSecureL() in an OOM test.
798 The test creates a secure database then executes CSqlSrvDatabase::OpenL() in an OOM loop.
799 After that the database is deleted and the test executes CSqlSrvDatabase::CreateSecureL() in an OOM loop.
800 The purpose of the test is to check that the CSqlSrver maps are properly updated when
801 the database is closed.
802 UTF16 encoded database is used.
803 @SYMTestExpectedResults Test must not fail
804 @SYMDEF DEF144577, PDEF44845
806 void Utf16OpenCreateDatabaseOomTest()
808 OpenCreateDatabaseOomTest(ESqlDbUtf16);
812 @SYMTestCaseID PDS-SQL-UT-4188
813 @SYMTestCaseDesc CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateSecureL() OOM test.
814 @SYMTestPriority High
815 @SYMTestActions The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::CreateSecureL() in an OOM test.
816 The test creates a secure database then executes CSqlSrvDatabase::OpenL() in an OOM loop.
817 After that the database is deleted and the test executes CSqlSrvDatabase::CreateSecureL() in an OOM loop.
818 The purpose of the test is to check that the CSqlSrver maps are properly updated when
819 the database is closed.
820 UTF8 encoded database is used.
821 @SYMTestExpectedResults Test must not fail
824 void Utf8OpenCreateDatabaseOomTest()
826 OpenCreateDatabaseOomTest(ESqlDbUtf8);
832 TheTest.Start(_L("This test can be run only in debug mode!"));
834 CActiveScheduler* scheduler = new CActiveScheduler;
835 TEST(scheduler != NULL);
836 CActiveScheduler::Install(scheduler);
838 TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4167 CSqlSrvDatabase::CreateL() OOM unit test"));
839 Utf16CreateDatabaseOomTest();
841 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4168 CSqlSrvDatabase::OpenL() OOM unit test - non-secure database"));
842 Utf16OpenDatabaseOomTest();
844 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4169 CSqlSrvDatabase::CreateSecureL() OOM unit test"));
845 Utf16CreateSecureDatabaseOomTest();
847 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4170 CSqlSrvDatabase::OpenL() OOM unit test - secure database"));
848 Utf16OpenSecureDatabaseOomTest();
850 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4171 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test"));
851 Utf16OpenAttachDatabaseOomTest();
853 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4172 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test - 2"));
854 Utf16OpenAttachDatabaseOomTest2();
856 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4173 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateL() OOM unit test"));
857 Utf16OpenCreateDatabaseOomTest();
859 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4182 CSqlSrvDatabase::CreateL() OOM unit test, UTF8 database"));
860 Utf8CreateDatabaseOomTest();
862 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4183 CSqlSrvDatabase::OpenL() OOM unit test - non-secure UTF8 database"));
863 Utf8OpenDatabaseOomTest();
865 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4184 CSqlSrvDatabase::CreateSecureL() OOM unit test, UTF8 database"));
866 Utf8CreateSecureDatabaseOomTest();
868 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4185 CSqlSrvDatabase::OpenL() OOM unit test - secure UTF8 database"));
869 Utf8OpenSecureDatabaseOomTest();
871 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4186 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test, UTF8 database"));
872 Utf8OpenAttachDatabaseOomTest();
874 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4187 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test 2, UTF8 database"));
875 Utf8OpenAttachDatabaseOomTest2();
877 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4188 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateL() OOM unit test, UTF8 database"));
878 Utf8OpenCreateDatabaseOomTest();
888 CTrapCleanup* tc = CTrapCleanup::New();
904 User::Heap().Check();