persistentstorage/sql/TEST/t_sqloom5.cpp
branchRCL_3
changeset 9 667e88a979d7
child 10 31a8f755b7fe
equal deleted inserted replaced
8:fa9941cf3867 9:667e88a979d7
       
     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 <bautils.h>
       
    18 #include "SqlSrvMain.h"
       
    19 #include "SqlSrvStartup.h"
       
    20 #include "SqlSrvUtil.h"
       
    21 #include "SqlSrvDatabase.h"
       
    22 #include "SqlSrvFileData.h"
       
    23 
       
    24 ///////////////////////////////////////////////////////////////////////////////////////
       
    25 
       
    26 RTest TheTest(_L("t_sqloom5 test"));
       
    27 RFs TheFs;
       
    28 
       
    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");
       
    34 
       
    35 extern CSqlServer* TheServer;
       
    36 
       
    37 static TInt TheProcessHandleCount = 0;
       
    38 static TInt TheThreadHandleCount = 0;
       
    39 static TInt TheAllocatedCellsCount = 0;
       
    40 
       
    41 #ifdef _DEBUG
       
    42 static const TInt KBurstRate = 20;
       
    43 #endif
       
    44 
       
    45 ///////////////////////////////////////////////////////////////////////////////////////
       
    46 
       
    47 void DestroyTestEnv()
       
    48 	{
       
    49     (void)TheFs.Delete(KDbFile4);
       
    50     (void)TheFs.Delete(KDbFile3);
       
    51     (void)TheFs.Delete(KDbFile2);
       
    52     (void)TheFs.Delete(KDbFile);
       
    53 	TheFs.Close();
       
    54 	}
       
    55 
       
    56 ///////////////////////////////////////////////////////////////////////////////////////
       
    57 ///////////////////////////////////////////////////////////////////////////////////////
       
    58 //Test macros and functions
       
    59 void Check(TInt aValue, TInt aLine)
       
    60 	{
       
    61 	if(!aValue)
       
    62 		{
       
    63 		DestroyTestEnv();
       
    64 		RDebug::Print(_L("*** Expresssion evaluated to false\r\n"));
       
    65 		TheTest(EFalse, aLine);
       
    66 		}
       
    67 	}
       
    68 void Check(TInt aValue, TInt aExpected, TInt aLine)
       
    69 	{
       
    70 	if(aValue != aExpected)
       
    71 		{
       
    72 		DestroyTestEnv();
       
    73 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    74 		TheTest(EFalse, aLine);
       
    75 		}
       
    76 	}
       
    77 #define TEST(arg) ::Check((arg), __LINE__)
       
    78 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    79 
       
    80 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    81 
       
    82 static void MarkHandles()
       
    83     {
       
    84     RThread().HandleCount(TheProcessHandleCount, TheThreadHandleCount);
       
    85     }
       
    86 
       
    87 static void MarkAllocatedCells()
       
    88     {
       
    89     TheAllocatedCellsCount = User::CountAllocCells();
       
    90     }
       
    91 
       
    92 static void CheckAllocatedCells()
       
    93     {
       
    94     TInt allocatedCellsCount = User::CountAllocCells();
       
    95     TEST2(allocatedCellsCount, TheAllocatedCellsCount);
       
    96     }
       
    97 
       
    98 static void CheckHandles()
       
    99     {
       
   100     TInt endProcessHandleCount;
       
   101     TInt endThreadHandleCount;
       
   102     
       
   103     RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   104 
       
   105     TEST2(TheProcessHandleCount, endProcessHandleCount);
       
   106     TEST2(TheThreadHandleCount, endThreadHandleCount);
       
   107     }
       
   108 
       
   109 static void OomPreStep(TInt
       
   110                         #ifdef _DEBUG        
       
   111                             aFailingAllocationNo
       
   112                         #endif
       
   113                       )
       
   114     {
       
   115     MarkHandles();
       
   116     MarkAllocatedCells();
       
   117     __UHEAP_MARK;
       
   118     __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, aFailingAllocationNo, KBurstRate);
       
   119     }
       
   120 
       
   121 static void OomPostStep()
       
   122     {
       
   123     __UHEAP_RESET;
       
   124     __UHEAP_MARKEND;
       
   125     CheckAllocatedCells();
       
   126     CheckHandles();
       
   127     }
       
   128 
       
   129 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   130 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   131 
       
   132 void CreateTestEnv()
       
   133     {
       
   134     TInt err = TheFs.Connect();
       
   135     TEST2(err, KErrNone);
       
   136 
       
   137     err = TheFs.MkDir(KTestDir);
       
   138     TEST(err == KErrNone || err == KErrAlreadyExists);
       
   139 
       
   140     err = TheFs.CreatePrivatePath(EDriveC);
       
   141     TEST(err == KErrNone || err == KErrAlreadyExists);
       
   142     }
       
   143 
       
   144 static CSqlServer* CreateSqlServerL()
       
   145     {
       
   146     CSqlServer* server = CSqlServer::NewLC();
       
   147     CleanupStack::Pop(server);
       
   148     return server;
       
   149     }
       
   150 
       
   151 /**
       
   152 @SYMTestCaseID          PDS-SQL-UT-4167
       
   153 @SYMTestCaseDesc        CSqlSrvDatabase::CreateL() OOM test.
       
   154 @SYMTestPriority        High
       
   155 @SYMTestActions         The test runs CSqlSrvDatabase::CreateL() in an OOM loop.
       
   156 @SYMTestExpectedResults Test must not fail
       
   157 @SYMDEF                 DEF144577
       
   158 */  
       
   159 void CreateDatabaseOomTest()
       
   160     {
       
   161     (void)TheFs.Delete(KDbFile);
       
   162     TInt failingAllocationNo = 0;
       
   163     TheTest.Printf(_L("Iteration:\r\n"));
       
   164     
       
   165     TheServer = NULL; 
       
   166     TRAPD(err, TheServer = CreateSqlServerL());
       
   167     TEST2(err, KErrNone);
       
   168     
       
   169     err = KErrNoMemory;
       
   170     while(err == KErrNoMemory)
       
   171         {
       
   172         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
       
   173         OomPreStep(failingAllocationNo);
       
   174         
       
   175         TSqlSrvFileData& fdata = TheServer->FileData();
       
   176         RMessage2 msg;
       
   177         TRAP(err, fdata.SetL(msg, KDbFile().Length(), 0, (const TDesC8*)&KDbFile));
       
   178         if(err == KErrNone)
       
   179             {
       
   180             CSqlSrvDatabase* db = NULL;
       
   181             TRAP(err, db = CSqlSrvDatabase::CreateL(fdata));
       
   182             delete db;
       
   183             }
       
   184         OomPostStep();
       
   185         }
       
   186 
       
   187     delete TheServer;
       
   188     TheServer = NULL;
       
   189     
       
   190     if(err != KErrNoMemory)
       
   191         {
       
   192         TEST2(err, KErrNone);   
       
   193         }
       
   194     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::CreateL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
       
   195     }
       
   196 
       
   197 /**
       
   198 @SYMTestCaseID          PDS-SQL-UT-4168
       
   199 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() OOM test - non-secure database.
       
   200 @SYMTestPriority        High
       
   201 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
       
   202 @SYMTestExpectedResults Test must not fail
       
   203 @SYMDEF                 DEF144577
       
   204 */  
       
   205 void OpenDatabaseOomTest()
       
   206     {
       
   207     //The database is created by the previous test: CreateDatabaseOomTest().
       
   208     
       
   209     TInt failingAllocationNo = 0;
       
   210     TheTest.Printf(_L("Iteration:\r\n"));
       
   211     
       
   212     TheServer = NULL; 
       
   213     TRAPD(err, TheServer = CreateSqlServerL());
       
   214     TEST2(err, KErrNone);
       
   215     
       
   216     err = KErrNoMemory;
       
   217     while(err == KErrNoMemory)
       
   218         {
       
   219         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
       
   220         OomPreStep(failingAllocationNo);
       
   221         
       
   222         TSqlSrvFileData& fdata = TheServer->FileData();
       
   223         RMessage2 msg;
       
   224         TRAP(err, fdata.SetL(msg, KDbFile().Length(), 0, (const TDesC8*)&KDbFile));
       
   225         if(err == KErrNone)
       
   226             {
       
   227             CSqlSrvDatabase* db = NULL;
       
   228             TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
       
   229             delete db;
       
   230             }
       
   231         
       
   232         OomPostStep();
       
   233         }
       
   234     
       
   235     delete TheServer;
       
   236     TheServer = NULL;
       
   237     
       
   238     if(err != KErrNoMemory)
       
   239         {
       
   240         TEST2(err, KErrNone);   
       
   241         }
       
   242     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() [non-secure db] OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
       
   243     }
       
   244 
       
   245 /**
       
   246 @SYMTestCaseID          PDS-SQL-UT-4169
       
   247 @SYMTestCaseDesc        CSqlSrvDatabase::CreateSecureL() OOM test.
       
   248 @SYMTestPriority        High
       
   249 @SYMTestActions         The test runs CSqlSrvDatabase::CreateSecureL() in an OOM loop.
       
   250 @SYMTestExpectedResults Test must not fail
       
   251 @SYMDEF                 DEF144577
       
   252 */  
       
   253 void CreateSecureDatabaseOomTest()
       
   254     {
       
   255     (void)TheFs.Delete(KDbFile2);
       
   256     TInt failingAllocationNo = 0;
       
   257     TheTest.Printf(_L("Iteration:\r\n"));
       
   258     
       
   259     TheServer = NULL; 
       
   260     TRAPD(err, TheServer = CreateSqlServerL());
       
   261     TEST2(err, KErrNone);
       
   262         
       
   263     err = KErrNoMemory;
       
   264     while(err == KErrNoMemory)
       
   265         {
       
   266         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
       
   267         OomPreStep(failingAllocationNo);
       
   268         
       
   269         TSqlSrvFileData& fdata = TheServer->FileData();
       
   270         RMessage2 msg;
       
   271         TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, (const TDesC8*)&KDbFile2));
       
   272         if(err == KErrNone)
       
   273             {
       
   274             TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
       
   275             CSqlSecurityPolicy* policy = NULL;
       
   276             TRAP(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
       
   277             if(err == KErrNone)
       
   278                 {
       
   279                 CSqlSrvDatabase* db = NULL;
       
   280                 TRAP(err, db = CSqlSrvDatabase::CreateSecureL(fdata, policy));
       
   281                 delete db;
       
   282                 }
       
   283             }
       
   284         OomPostStep();
       
   285         }
       
   286 
       
   287     delete TheServer;
       
   288     TheServer = NULL;
       
   289     
       
   290     if(err != KErrNoMemory)
       
   291         {
       
   292         TEST2(err, KErrNone);   
       
   293         }
       
   294     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::CreateSecureL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
       
   295     }
       
   296 
       
   297 /**
       
   298 @SYMTestCaseID          PDS-SQL-UT-4170
       
   299 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() OOM test - secure database.
       
   300 @SYMTestPriority        High
       
   301 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
       
   302 @SYMTestExpectedResults Test must not fail
       
   303 @SYMDEF                 DEF144577
       
   304 */  
       
   305 void OpenSecureDatabaseOomTest()
       
   306     {
       
   307     //The database is created by the previous test: CreateSecureDatabaseOomTest().
       
   308     
       
   309     TInt failingAllocationNo = 0;
       
   310     TheTest.Printf(_L("Iteration:\r\n"));
       
   311     
       
   312     TheServer = NULL; 
       
   313     TRAPD(err, TheServer = CreateSqlServerL());
       
   314     TEST2(err, KErrNone);
       
   315     
       
   316     err = KErrNoMemory;
       
   317     while(err == KErrNoMemory)
       
   318         {
       
   319         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
       
   320         OomPreStep(failingAllocationNo);
       
   321         
       
   322         TSqlSrvFileData& fdata = TheServer->FileData();
       
   323         RMessage2 msg;
       
   324         TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, (const TDesC8*)&KDbFile2));
       
   325         if(err == KErrNone)
       
   326             {
       
   327             CSqlSrvDatabase* db = NULL;
       
   328             TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
       
   329             delete db;
       
   330             }
       
   331         
       
   332         OomPostStep();
       
   333         }
       
   334     
       
   335     delete TheServer;
       
   336     TheServer = NULL;
       
   337     
       
   338     if(err != KErrNoMemory)
       
   339         {
       
   340         TEST2(err, KErrNone);   
       
   341         }
       
   342     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() [secure db] OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
       
   343     }
       
   344 
       
   345 /////////////////////////////////////////////////////////////
       
   346 
       
   347 const TInt KDbConnCount = 7; 
       
   348 #ifdef _DEBUG
       
   349 const TInt KDbAttachedCount = 10;
       
   350 #endif
       
   351 TBuf<10> TheAttachedDbName;
       
   352 
       
   353 //Declares KDbConnCount "CSqlSrvDatabase*" variables.  
       
   354 #define TEST_DECLARE_DB_VARS() \
       
   355     CSqlSrvDatabase* db[KDbConnCount]; \
       
   356     Mem::FillZ(db, sizeof(db));
       
   357 
       
   358 //Declares all KDbConnCount "CSqlSrvDatabase*" objects.  
       
   359 #define TEST_DELETE_DB() \
       
   360     for(TInt i=0;i<KDbConnCount;++i) \
       
   361         { \
       
   362         delete db[i]; \
       
   363         }
       
   364 
       
   365 //Creates CSqlSrvDatabase object where the database file is dbFile (the second macro parameter).
       
   366 //The CSqlSrvDatabase pointer db[N - 1] (N is the first macro parameter) will be set to point to 
       
   367 //the created CSqlSrvDatabase object. 
       
   368 //N is the number of the database to be opened, between 1 and KDbConnCount.
       
   369 #define TEST_OPEN_DB(N, dbFile) \
       
   370     __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
       
   371     TRAP(err, fdata.SetL(msg, dbFile.Length(), 0, (const TDesC8*)&dbFile)); \
       
   372     if(err != KErrNone) \
       
   373         { \
       
   374         goto Cleanup; \
       
   375         } \
       
   376     db[N - 1] = NULL; \
       
   377     TRAP(err, db[N - 1] = CSqlSrvDatabase::OpenL(fdata)); \
       
   378     if(err != KErrNone) \
       
   379         { \
       
   380         goto Cleanup; \
       
   381         }
       
   382 
       
   383 //Attaches the "dbFile" database to the database number specified by the first macro parameter.
       
   384 //The attached database name is "A<M>", where M is the third macro parameter.
       
   385 //N is the number of the database connection, between 1 and KDbConnCount.
       
   386 //M is the number of the database to be attached, between 1 and KDbAttachedCount.
       
   387 #define TEST_ATTACH_DB(N, dbFile, M) \
       
   388     __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
       
   389     __ASSERT_DEBUG(M > 0 && M <= KDbAttachedCount, User::Invariant()); \
       
   390     TRAP(err, fdata.SetL(msg, dbFile.Length(), 0, (const TDesC8*)&dbFile)); \
       
   391     if(err != KErrNone) \
       
   392         { \
       
   393         goto Cleanup; \
       
   394         } \
       
   395     TheAttachedDbName.Copy(_L("A")); \
       
   396     TheAttachedDbName.AppendNum(M); \
       
   397     TRAP(err, db[N - 1]->AttachDbL(fdata, TheAttachedDbName)); \
       
   398     if(err != KErrNone) \
       
   399         { \
       
   400         goto Cleanup; \
       
   401         }
       
   402 
       
   403 //Detaches database "A<M>" (M is the second macro parameter) from the database identified
       
   404 //by the number N - the first macro parameter.
       
   405 //N is the number of the database connection, between 1 and KDbConnCount.
       
   406 //M is the number of the database to be detached, between 1 and KDbAttachedCount.
       
   407 #define TEST_DETACH_DB(N, M) \
       
   408     __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
       
   409     __ASSERT_DEBUG(M > 0 && M <= KDbAttachedCount, User::Invariant()); \
       
   410     if(db[N - 1]) \
       
   411         { \
       
   412         TheAttachedDbName.Copy(_L("A")); \
       
   413         TheAttachedDbName.AppendNum(M); \
       
   414         TRAP_IGNORE(db[N - 1]->DetachDbL(TheAttachedDbName)); \
       
   415         }
       
   416 
       
   417 /////////////////////////////////////////////////////////////
       
   418 
       
   419 void CreateSecureTestDb(const TDesC& aDbFile)
       
   420     {
       
   421     (void)TheFs.Delete(aDbFile);
       
   422     
       
   423     TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
       
   424     CSqlSecurityPolicy* policy = NULL;
       
   425     TRAPD(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
       
   426     TEST2(err, KErrNone);
       
   427     
       
   428     TSqlSrvFileData& fdata = TheServer->FileData();
       
   429     RMessage2 msg;
       
   430     TRAP(err, fdata.SetL(msg, aDbFile.Length(), 0, (const TDesC8*)&aDbFile));
       
   431     
       
   432     CSqlSrvDatabase* db = NULL;
       
   433     TRAP(err, db = CSqlSrvDatabase::CreateSecureL(fdata, policy));
       
   434     delete db;
       
   435     TEST2(err, KErrNone);
       
   436     }
       
   437     
       
   438 /**
       
   439 @SYMTestCaseID          PDS-SQL-UT-4171
       
   440 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
       
   441 @SYMTestPriority        High
       
   442 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
       
   443                         The test is a complex one - 7 (KDbConnCount constant) databases opened 
       
   444                         (secure and non-secure), 10 (KDbAttachedCount constant) databases
       
   445                         attached (secure and non-secure).
       
   446 @SYMTestExpectedResults Test must not fail
       
   447 @SYMDEF                 DEF144577, DEF144603
       
   448 */  
       
   449 void OpenAttachDatabaseOomTest()
       
   450     {
       
   451     //Part of the databases are created by the previous tests.
       
   452         
       
   453     TInt failingAllocationNo = 0;
       
   454     TheTest.Printf(_L("Iteration:\r\n"));
       
   455     
       
   456     TheServer = NULL; 
       
   457     TRAPD(err, TheServer = CreateSqlServerL());
       
   458     TEST2(err, KErrNone);
       
   459 
       
   460     CreateSecureTestDb(KDbFile3);
       
   461     CreateSecureTestDb(KDbFile4);
       
   462     
       
   463     //The following 2 declarations are used by the macros in the OOM loop
       
   464     RMessage2 msg;
       
   465     TSqlSrvFileData& fdata = TheServer->FileData();
       
   466     
       
   467     err = KErrNoMemory;
       
   468     while(err == KErrNoMemory)
       
   469         {
       
   470         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
       
   471         OomPreStep(failingAllocationNo);
       
   472         //Declare KDbConnCount "CSqlSrvDatabase*" variables.
       
   473         TEST_DECLARE_DB_VARS();
       
   474         //Create CSqlSrvDatabase object, the database name is the second parameter of the macro. 
       
   475         //The related db[N - 1] variable will be set to point to the created object.
       
   476         TEST_OPEN_DB(1, KDbFile2());
       
   477         TEST_OPEN_DB(2, KDbFile2());
       
   478         TEST_OPEN_DB(3, KDbFile3());
       
   479         TEST_OPEN_DB(4, KDbFile3());
       
   480         TEST_OPEN_DB(5, KDbFile3());
       
   481         TEST_OPEN_DB(6, KDbFile());
       
   482         TEST_OPEN_DB(7, KDbFile());
       
   483         //Attach to the database with the number specified as first macro parameter, the database file, specified
       
   484         //as second macro parameter. The logical name of the attached database is "A<M>", where M is the third macro parameter.
       
   485         TEST_ATTACH_DB(1, KDbFile(), 1);
       
   486         TEST_ATTACH_DB(2, KDbFile(), 2);
       
   487         TEST_ATTACH_DB(2, KDbFile(), 3);
       
   488         TEST_ATTACH_DB(5, KDbFile4(), 4);
       
   489         TEST_ATTACH_DB(2, KDbFile4(), 5);
       
   490         TEST_ATTACH_DB(2, KDbFile4(), 6);
       
   491         TEST_ATTACH_DB(5, KDbFile4(), 7);
       
   492         TEST_ATTACH_DB(5, KDbFile4(), 8);
       
   493         TEST_ATTACH_DB(1, KDbFile4(), 9);
       
   494         TEST_ATTACH_DB(1, KDbFile(), 10);
       
   495 Cleanup:
       
   496         __UHEAP_SETBURSTFAIL(RAllocator::ENone, 0, 0);
       
   497         //Detach from the database with the number specified as first macro parameter, the database         
       
   498         //with name "A<M>", where M is the second macro parameter.
       
   499         TEST_DETACH_DB(1, 9);
       
   500         TEST_DETACH_DB(1, 1);
       
   501         TEST_DETACH_DB(1, 10);
       
   502         TEST_DETACH_DB(2, 2);
       
   503         TEST_DETACH_DB(2, 3);
       
   504         TEST_DETACH_DB(2, 5);
       
   505         TEST_DETACH_DB(2, 6);
       
   506         TEST_DETACH_DB(5, 4);
       
   507         TEST_DETACH_DB(5, 7);
       
   508         TEST_DETACH_DB(5, 8);
       
   509         //Delete all created CSqlSrvDatabase objects.
       
   510         TEST_DELETE_DB();        
       
   511         
       
   512         OomPostStep();
       
   513         }
       
   514     
       
   515     delete TheServer;
       
   516     TheServer = NULL;
       
   517     
       
   518     if(err != KErrNoMemory)
       
   519         {
       
   520         TEST2(err, KErrNone);   
       
   521         }
       
   522     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
       
   523     }
       
   524 
       
   525 void DoTests()
       
   526 	{
       
   527 #ifndef _DEBUG
       
   528     TheTest.Start(_L("This test can be run only in debug mode!"));
       
   529 #else	
       
   530     CActiveScheduler* scheduler = new CActiveScheduler;
       
   531     TEST(scheduler != NULL);
       
   532     CActiveScheduler::Install(scheduler);
       
   533 	
       
   534     TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4167 CSqlSrvDatabase::CreateL() OOM unit test"));
       
   535     CreateDatabaseOomTest();
       
   536 
       
   537     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4168 CSqlSrvDatabase::OpenL() OOM unit test - non-secure database"));
       
   538     OpenDatabaseOomTest();
       
   539 
       
   540     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4169 CSqlSrvDatabase::CreateSecureL() OOM unit test"));
       
   541     CreateSecureDatabaseOomTest();
       
   542 
       
   543     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4170 CSqlSrvDatabase::OpenL() OOM unit test - secure database"));
       
   544     OpenSecureDatabaseOomTest();
       
   545     
       
   546     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4171 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test"));
       
   547     OpenAttachDatabaseOomTest();
       
   548     
       
   549     delete scheduler;
       
   550 #endif //_DEBUG    
       
   551 	}
       
   552 
       
   553 TInt E32Main()
       
   554 	{
       
   555 	TheTest.Title();
       
   556 	
       
   557 	CTrapCleanup* tc = CTrapCleanup::New();
       
   558 	TheTest(tc != NULL);
       
   559 	
       
   560 	__UHEAP_MARK;
       
   561 	
       
   562 	CreateTestEnv();
       
   563 	DoTests();
       
   564 	DestroyTestEnv();
       
   565 
       
   566 	__UHEAP_MARKEND;
       
   567 	
       
   568 	TheTest.End();
       
   569 	TheTest.Close();
       
   570 	
       
   571 	delete tc;
       
   572 
       
   573 	User::Heap().Check();
       
   574 	return KErrNone;
       
   575 	}