persistentstorage/sql/TEST/t_sqloom5.cpp
branchRCL_3
changeset 13 211563e4b919
parent 12 31a8f755b7fe
child 16 6b6fd149daa2
equal deleted inserted replaced
12:31a8f755b7fe 13:211563e4b919
    30 _LIT(KDbFile, "c:\\test\\t_sqloom5.db");
    30 _LIT(KDbFile, "c:\\test\\t_sqloom5.db");
    31 _LIT(KDbFile2, "c:[10281E17]t_sqloom5.db");
    31 _LIT(KDbFile2, "c:[10281E17]t_sqloom5.db");
    32 _LIT(KDbFile3, "c:[10281E17]t_sqloom5_2.db");
    32 _LIT(KDbFile3, "c:[10281E17]t_sqloom5_2.db");
    33 _LIT(KDbFile4, "c:[10281E17]t_sqloom5_3.db");
    33 _LIT(KDbFile4, "c:[10281E17]t_sqloom5_3.db");
    34 
    34 
       
    35 _LIT8(KConfig, "encoding=UTF-8");
       
    36 
    35 extern CSqlServer* TheServer;
    37 extern CSqlServer* TheServer;
    36 
    38 
    37 static TInt TheProcessHandleCount = 0;
    39 static TInt TheProcessHandleCount = 0;
    38 static TInt TheThreadHandleCount = 0;
    40 static TInt TheThreadHandleCount = 0;
    39 static TInt TheAllocatedCellsCount = 0;
    41 static TInt TheAllocatedCellsCount = 0;
    40 
    42 
    41 #ifdef _DEBUG
    43 #ifdef _DEBUG
    42 static const TInt KBurstRate = 20;
    44 static const TInt KBurstRate = 20;
    43 #endif
    45 #endif
       
    46 
       
    47 enum TSqlDbEncoding
       
    48     {
       
    49     ESqlDbUtf16,
       
    50     ESqlDbUtf8
       
    51     };
    44 
    52 
    45 ///////////////////////////////////////////////////////////////////////////////////////
    53 ///////////////////////////////////////////////////////////////////////////////////////
    46 
    54 
    47 void DestroyTestEnv()
    55 void DestroyTestEnv()
    48 	{
    56 	{
   146     CSqlServer* server = CSqlServer::NewLC();
   154     CSqlServer* server = CSqlServer::NewLC();
   147     CleanupStack::Pop(server);
   155     CleanupStack::Pop(server);
   148     return server;
   156     return server;
   149     }
   157     }
   150 
   158 
   151 /**
   159 void CreateDatabaseOomTest(TSqlDbEncoding aEncoding)
   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     {
   160     {
   161     (void)TheFs.Delete(KDbFile);
   161     (void)TheFs.Delete(KDbFile);
   162     TInt failingAllocationNo = 0;
   162     TInt failingAllocationNo = 0;
   163     TheTest.Printf(_L("Iteration:\r\n"));
   163     TheTest.Printf(_L("Iteration:\r\n"));
   164     
   164     
   172         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   172         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   173         OomPreStep(failingAllocationNo);
   173         OomPreStep(failingAllocationNo);
   174         
   174         
   175         TSqlSrvFileData& fdata = TheServer->FileData();
   175         TSqlSrvFileData& fdata = TheServer->FileData();
   176         RMessage2 msg;
   176         RMessage2 msg;
   177         TRAP(err, fdata.SetL(msg, KDbFile().Length(), 0, (const TDesC8*)&KDbFile));
   177         TRAP(err, fdata.SetL(msg, KDbFile().Length(), 0, KDbFile, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
   178         if(err == KErrNone)
   178         if(err == KErrNone)
   179             {
   179             {
   180             CSqlSrvDatabase* db = NULL;
   180             CSqlSrvDatabase* db = NULL;
   181             TRAP(err, db = CSqlSrvDatabase::CreateL(fdata));
   181             TRAP(err, db = CSqlSrvDatabase::CreateL(fdata));
   182             delete db;
   182             delete db;
   190     TEST2(err, KErrNone);   
   190     TEST2(err, KErrNone);   
   191     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::CreateL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   191     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::CreateL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   192     }
   192     }
   193 
   193 
   194 /**
   194 /**
   195 @SYMTestCaseID          PDS-SQL-UT-4168
   195 @SYMTestCaseID          PDS-SQL-UT-4167
   196 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() OOM test - non-secure database.
   196 @SYMTestCaseDesc        CSqlSrvDatabase::CreateL() OOM test.
   197 @SYMTestPriority        High
   197 @SYMTestPriority        High
   198 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
   198 @SYMTestActions         The test runs CSqlSrvDatabase::CreateL() in an OOM loop.
       
   199                         UTF16 encoded database is used.
   199 @SYMTestExpectedResults Test must not fail
   200 @SYMTestExpectedResults Test must not fail
   200 @SYMDEF                 DEF144577
   201 @SYMDEF                 DEF144577
   201 */  
   202 */  
       
   203 void Utf16CreateDatabaseOomTest()
       
   204     {
       
   205     CreateDatabaseOomTest(ESqlDbUtf16);
       
   206     }
       
   207 
       
   208 /**
       
   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
       
   215 @SYMDEF                 DEF145047
       
   216 */  
       
   217 void Utf8CreateDatabaseOomTest()
       
   218     {
       
   219     CreateDatabaseOomTest(ESqlDbUtf8);
       
   220     }
       
   221 
   202 void OpenDatabaseOomTest()
   222 void OpenDatabaseOomTest()
   203     {
   223     {
   204     //The database is created by the previous test: CreateDatabaseOomTest().
   224     //The database is created by the previous test: CreateDatabaseOomTest().
   205     
   225     
   206     TInt failingAllocationNo = 0;
   226     TInt failingAllocationNo = 0;
   216         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   236         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   217         OomPreStep(failingAllocationNo);
   237         OomPreStep(failingAllocationNo);
   218         
   238         
   219         TSqlSrvFileData& fdata = TheServer->FileData();
   239         TSqlSrvFileData& fdata = TheServer->FileData();
   220         RMessage2 msg;
   240         RMessage2 msg;
   221         TRAP(err, fdata.SetL(msg, KDbFile().Length(), 0, (const TDesC8*)&KDbFile));
   241         TRAP(err, fdata.SetL(msg, KDbFile().Length(), 0, KDbFile));
   222         if(err == KErrNone)
   242         if(err == KErrNone)
   223             {
   243             {
   224             CSqlSrvDatabase* db = NULL;
   244             CSqlSrvDatabase* db = NULL;
   225             TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   245             TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   226             delete db;
   246             delete db;
   235     TEST2(err, KErrNone);   
   255     TEST2(err, KErrNone);   
   236     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() [non-secure db] OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   256     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() [non-secure db] OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   237     }
   257     }
   238 
   258 
   239 /**
   259 /**
   240 @SYMTestCaseID          PDS-SQL-UT-4169
   260 @SYMTestCaseID          PDS-SQL-UT-4168
   241 @SYMTestCaseDesc        CSqlSrvDatabase::CreateSecureL() OOM test.
   261 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() OOM test - non-secure database.
   242 @SYMTestPriority        High
   262 @SYMTestPriority        High
   243 @SYMTestActions         The test runs CSqlSrvDatabase::CreateSecureL() in an OOM loop.
   263 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
       
   264                         UTF16 encoded database is used.
   244 @SYMTestExpectedResults Test must not fail
   265 @SYMTestExpectedResults Test must not fail
   245 @SYMDEF                 DEF144577
   266 @SYMDEF                 DEF144577
   246 */  
   267 */  
   247 void CreateSecureDatabaseOomTest()
   268 void Utf16OpenDatabaseOomTest()
       
   269     {
       
   270     OpenDatabaseOomTest();
       
   271     }
       
   272 
       
   273 /**
       
   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
       
   280 @SYMDEF                 DEF145047
       
   281 */  
       
   282 void Utf8OpenDatabaseOomTest()
       
   283     {
       
   284     OpenDatabaseOomTest();
       
   285     }
       
   286 
       
   287 void CreateSecureDatabaseOomTest(TSqlDbEncoding aEncoding)
   248     {
   288     {
   249     (void)TheFs.Delete(KDbFile2);
   289     (void)TheFs.Delete(KDbFile2);
   250     TInt failingAllocationNo = 0;
   290     TInt failingAllocationNo = 0;
   251     TheTest.Printf(_L("Iteration:\r\n"));
   291     TheTest.Printf(_L("Iteration:\r\n"));
   252     
   292     
   260         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   300         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   261         OomPreStep(failingAllocationNo);
   301         OomPreStep(failingAllocationNo);
   262         
   302         
   263         TSqlSrvFileData& fdata = TheServer->FileData();
   303         TSqlSrvFileData& fdata = TheServer->FileData();
   264         RMessage2 msg;
   304         RMessage2 msg;
   265         TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, (const TDesC8*)&KDbFile2));
   305         TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
   266         if(err == KErrNone)
   306         if(err == KErrNone)
   267             {
   307             {
   268             TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
   308             TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
   269             CSqlSecurityPolicy* policy = NULL;
   309             CSqlSecurityPolicy* policy = NULL;
   270             TRAP(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
   310             TRAP(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
   284     TEST2(err, KErrNone);   
   324     TEST2(err, KErrNone);   
   285     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::CreateSecureL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   325     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::CreateSecureL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   286     }
   326     }
   287 
   327 
   288 /**
   328 /**
   289 @SYMTestCaseID          PDS-SQL-UT-4170
   329 @SYMTestCaseID          PDS-SQL-UT-4169
   290 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() OOM test - secure database.
   330 @SYMTestCaseDesc        CSqlSrvDatabase::CreateSecureL() OOM test.
   291 @SYMTestPriority        High
   331 @SYMTestPriority        High
   292 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
   332 @SYMTestActions         The test runs CSqlSrvDatabase::CreateSecureL() in an OOM loop.
       
   333                         UTF16 encoded database is used.
   293 @SYMTestExpectedResults Test must not fail
   334 @SYMTestExpectedResults Test must not fail
   294 @SYMDEF                 DEF144577
   335 @SYMDEF                 DEF144577
   295 */  
   336 */  
       
   337 void Utf16CreateSecureDatabaseOomTest()
       
   338     {
       
   339     CreateSecureDatabaseOomTest(ESqlDbUtf16);
       
   340     }
       
   341 
       
   342 /**
       
   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
       
   349 @SYMDEF                 DEF145047
       
   350 */  
       
   351 void Utf8CreateSecureDatabaseOomTest()
       
   352     {
       
   353     CreateSecureDatabaseOomTest(ESqlDbUtf8);
       
   354     }
       
   355 
   296 void OpenSecureDatabaseOomTest()
   356 void OpenSecureDatabaseOomTest()
   297     {
   357     {
   298     //The database is created by the previous test: CreateSecureDatabaseOomTest().
   358     //The database is created by the previous test: CreateSecureDatabaseOomTest().
   299     
   359     
   300     TInt failingAllocationNo = 0;
   360     TInt failingAllocationNo = 0;
   310         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   370         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   311         OomPreStep(failingAllocationNo);
   371         OomPreStep(failingAllocationNo);
   312         
   372         
   313         TSqlSrvFileData& fdata = TheServer->FileData();
   373         TSqlSrvFileData& fdata = TheServer->FileData();
   314         RMessage2 msg;
   374         RMessage2 msg;
   315         TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, (const TDesC8*)&KDbFile2));
   375         TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2));
   316         if(err == KErrNone)
   376         if(err == KErrNone)
   317             {
   377             {
   318             CSqlSrvDatabase* db = NULL;
   378             CSqlSrvDatabase* db = NULL;
   319             TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   379             TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   320             delete db;
   380             delete db;
   328     
   388     
   329     TEST2(err, KErrNone);   
   389     TEST2(err, KErrNone);   
   330     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() [secure db] OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   390     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() [secure db] OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   331     }
   391     }
   332 
   392 
       
   393 /**
       
   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
       
   401 */  
       
   402 void Utf16OpenSecureDatabaseOomTest()
       
   403     {
       
   404     OpenSecureDatabaseOomTest();
       
   405     }
       
   406 
       
   407 /**
       
   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
       
   414 @SYMDEF                 DEF145047
       
   415 */  
       
   416 void Utf8OpenSecureDatabaseOomTest()
       
   417     {
       
   418     OpenSecureDatabaseOomTest();
       
   419     }
       
   420 
   333 /////////////////////////////////////////////////////////////
   421 /////////////////////////////////////////////////////////////
   334 
   422 
   335 const TInt KDbConnCount = 7; 
   423 const TInt KDbConnCount = 7; 
   336 #ifdef _DEBUG
   424 #ifdef _DEBUG
   337 const TInt KDbAttachedCount = 10;
   425 const TInt KDbAttachedCount = 10;
   354 //The CSqlSrvDatabase pointer db[N - 1] (N is the first macro parameter) will be set to point to 
   442 //The CSqlSrvDatabase pointer db[N - 1] (N is the first macro parameter) will be set to point to 
   355 //the created CSqlSrvDatabase object. 
   443 //the created CSqlSrvDatabase object. 
   356 //N is the number of the database to be opened, between 1 and KDbConnCount.
   444 //N is the number of the database to be opened, between 1 and KDbConnCount.
   357 #define TEST_OPEN_DB(N, dbFile) \
   445 #define TEST_OPEN_DB(N, dbFile) \
   358     __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
   446     __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
   359     TRAP(err, fdata.SetL(msg, dbFile.Length(), 0, (const TDesC8*)&dbFile)); \
   447     TRAP(err, fdata.SetL(msg, dbFile.Length(), 0, dbFile)); \
   360     if(err != KErrNone) \
   448     if(err != KErrNone) \
   361         { \
   449         { \
   362         goto Cleanup; \
   450         goto Cleanup; \
   363         } \
   451         } \
   364     db[N - 1] = NULL; \
   452     db[N - 1] = NULL; \
   373 //N is the number of the database connection, between 1 and KDbConnCount.
   461 //N is the number of the database connection, between 1 and KDbConnCount.
   374 //M is the number of the database to be attached, between 1 and KDbAttachedCount.
   462 //M is the number of the database to be attached, between 1 and KDbAttachedCount.
   375 #define TEST_ATTACH_DB(N, dbFile, M) \
   463 #define TEST_ATTACH_DB(N, dbFile, M) \
   376     __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
   464     __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
   377     __ASSERT_DEBUG(M > 0 && M <= KDbAttachedCount, User::Invariant()); \
   465     __ASSERT_DEBUG(M > 0 && M <= KDbAttachedCount, User::Invariant()); \
   378     TRAP(err, fdata.SetL(msg, dbFile.Length(), 0, (const TDesC8*)&dbFile)); \
   466     TRAP(err, fdata.SetL(msg, dbFile.Length(), 0, dbFile)); \
   379     if(err != KErrNone) \
   467     if(err != KErrNone) \
   380         { \
   468         { \
   381         goto Cleanup; \
   469         goto Cleanup; \
   382         } \
   470         } \
   383     TheAttachedDbName.Copy(_L("A")); \
   471     TheAttachedDbName.Copy(_L("A")); \
   402         TRAP_IGNORE(db[N - 1]->DetachDbL(TheAttachedDbName)); \
   490         TRAP_IGNORE(db[N - 1]->DetachDbL(TheAttachedDbName)); \
   403         }
   491         }
   404 
   492 
   405 /////////////////////////////////////////////////////////////
   493 /////////////////////////////////////////////////////////////
   406 
   494 
   407 void CreateSecureTestDb(const TDesC& aDbFile)
   495 void CreateSecureTestDb(const TDesC& aDbFile, TSqlDbEncoding aEncoding)
   408     {
   496     {
   409     (void)TheFs.Delete(aDbFile);
   497     (void)TheFs.Delete(aDbFile);
   410     
   498     
   411     TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
   499     TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
   412     CSqlSecurityPolicy* policy = NULL;
   500     CSqlSecurityPolicy* policy = NULL;
   413     TRAPD(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
   501     TRAPD(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
   414     TEST2(err, KErrNone);
   502     TEST2(err, KErrNone);
   415     
   503     
   416     TSqlSrvFileData& fdata = TheServer->FileData();
   504     TSqlSrvFileData& fdata = TheServer->FileData();
   417     RMessage2 msg;
   505     RMessage2 msg;
   418     TRAP(err, fdata.SetL(msg, aDbFile.Length(), 0, (const TDesC8*)&aDbFile));
   506     TRAP(err, fdata.SetL(msg, aDbFile.Length(), 0, aDbFile, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
   419     
   507     
   420     CSqlSrvDatabase* db = NULL;
   508     CSqlSrvDatabase* db = NULL;
   421     TRAP(err, db = CSqlSrvDatabase::CreateSecureL(fdata, policy));
   509     TRAP(err, db = CSqlSrvDatabase::CreateSecureL(fdata, policy));
   422     delete db;
   510     delete db;
   423     TEST2(err, KErrNone);
   511     TEST2(err, KErrNone);
   424     }
   512     }
   425     
   513     
   426 /**
   514 void OpenAttachDatabaseOomTest(TSqlDbEncoding aEncoding)
   427 @SYMTestCaseID          PDS-SQL-UT-4171
       
   428 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
       
   429 @SYMTestPriority        High
       
   430 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
       
   431                         The test is a complex one - 7 (KDbConnCount constant) databases opened 
       
   432                         (secure and non-secure), 10 (KDbAttachedCount constant) databases
       
   433                         attached (secure and non-secure).
       
   434 @SYMTestExpectedResults Test must not fail
       
   435 @SYMDEF                 DEF144577, DEF144603
       
   436 */  
       
   437 void OpenAttachDatabaseOomTest()
       
   438     {
   515     {
   439     //Part of the databases are created by the previous tests.
   516     //Part of the databases are created by the previous tests.
   440         
   517         
   441     TInt failingAllocationNo = 0;
   518     TInt failingAllocationNo = 0;
   442     TheTest.Printf(_L("Iteration:\r\n"));
   519     TheTest.Printf(_L("Iteration:\r\n"));
   443     
   520     
   444     TheServer = NULL; 
   521     TheServer = NULL; 
   445     TRAPD(err, TheServer = CreateSqlServerL());
   522     TRAPD(err, TheServer = CreateSqlServerL());
   446     TEST2(err, KErrNone);
   523     TEST2(err, KErrNone);
   447 
   524 
   448     CreateSecureTestDb(KDbFile3);
   525     CreateSecureTestDb(KDbFile3, aEncoding);
   449     CreateSecureTestDb(KDbFile4);
   526     CreateSecureTestDb(KDbFile4, aEncoding);
   450     
   527     
   451     //The following 2 declarations are used by the macros in the OOM loop
   528     //The following 2 declarations are used by the macros in the OOM loop
   452     RMessage2 msg;
   529     RMessage2 msg;
   453     TSqlSrvFileData& fdata = TheServer->FileData();
   530     TSqlSrvFileData& fdata = TheServer->FileData();
   454     
   531     
   509     TEST2(err, KErrNone);   
   586     TEST2(err, KErrNone);   
   510     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   587     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   511     }
   588     }
   512 
   589 
   513 /**
   590 /**
   514 @SYMTestCaseID          PDS-SQL-UT-4172
   591 @SYMTestCaseID          PDS-SQL-UT-4171
   515 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
   592 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
   516 @SYMTestPriority        High
   593 @SYMTestPriority        High
   517 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
   594 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
   518                         Two secure databases are created and then, in an OOM loop, the test executes this sequence of
   595                         The test is a complex one - 7 (KDbConnCount constant) databases opened 
   519                         commands: open first database, attach the second database, detach the attached database,
   596                         (secure and non-secure), 10 (KDbAttachedCount constant) databases
   520                         close the first database. 
   597                         attached (secure and non-secure).
   521 @SYMTestExpectedResults Test must not fail
   598                         UTF16 encoded database is used.
   522 @SYMDEF                 DEF144577, PDEF44845
   599 @SYMTestExpectedResults Test must not fail
   523 */  
   600 @SYMDEF                 DEF144577, DEF144603
   524 void OpenAttachDatabaseOomTest2()
   601 */  
       
   602 void Utf16OpenAttachDatabaseOomTest()
       
   603     {
       
   604     OpenAttachDatabaseOomTest(ESqlDbUtf16);
       
   605     }
       
   606 
       
   607 /**
       
   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
       
   617 @SYMDEF                 DEF????
       
   618 */  
       
   619 void Utf8OpenAttachDatabaseOomTest()
       
   620     {
       
   621     OpenAttachDatabaseOomTest(ESqlDbUtf8);
       
   622     }
       
   623 
       
   624 void OpenAttachDatabaseOomTest2(TSqlDbEncoding aEncoding)
   525     {
   625     {
   526     TheServer = NULL; 
   626     TheServer = NULL; 
   527     TRAPD(err, TheServer = CreateSqlServerL());
   627     TRAPD(err, TheServer = CreateSqlServerL());
   528     TEST2(err, KErrNone);
   628     TEST2(err, KErrNone);
   529     
   629     
   530     CreateSecureTestDb(KDbFile3);
   630     CreateSecureTestDb(KDbFile3, aEncoding);
   531     CreateSecureTestDb(KDbFile4);
   631     CreateSecureTestDb(KDbFile4, aEncoding);
   532     
   632     
   533     TInt failingAllocationNo = 0;
   633     TInt failingAllocationNo = 0;
   534     TheTest.Printf(_L("Iteration:\r\n"));
   634     TheTest.Printf(_L("Iteration:\r\n"));
   535     
   635     
   536     RMessage2 msg;
   636     RMessage2 msg;
   540     while(err == KErrNoMemory)
   640     while(err == KErrNoMemory)
   541         {
   641         {
   542         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   642         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   543         OomPreStep(failingAllocationNo);
   643         OomPreStep(failingAllocationNo);
   544         
   644         
   545         TRAP(err, fdata.SetL(msg, KDbFile3().Length(), 0, (const TDesC8*)&KDbFile3));
   645         TRAP(err, fdata.SetL(msg, KDbFile3().Length(), 0, KDbFile3));
   546         if(err == KErrNone)
   646         if(err == KErrNone)
   547             {
   647             {
   548             CSqlSrvDatabase* db = NULL;
   648             CSqlSrvDatabase* db = NULL;
   549             TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   649             TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   550             if(err == KErrNone)
   650             if(err == KErrNone)
   551                 {
   651                 {
   552                 TRAP(err, fdata.SetL(msg, KDbFile4().Length(), 0, (const TDesC8*)&KDbFile4));
   652                 TRAP(err, fdata.SetL(msg, KDbFile4().Length(), 0, KDbFile4));
   553                 if(err == KErrNone)
   653                 if(err == KErrNone)
   554                     {
   654                     {
   555                     TRAP(err, db->AttachDbL(fdata, _L("db2")));
   655                     TRAP(err, db->AttachDbL(fdata, _L("db2")));
   556                     if(err == KErrNone)
   656                     if(err == KErrNone)
   557                         {
   657                         {
   573     TEST2(err, KErrNone);   
   673     TEST2(err, KErrNone);   
   574     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test 2 succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   674     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test 2 succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   575     }
   675     }
   576 
   676 
   577 /**
   677 /**
   578 @SYMTestCaseID          PDS-SQL-UT-4173
   678 @SYMTestCaseID          PDS-SQL-UT-4172
   579 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateSecureL() OOM test.
   679 @SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
   580 @SYMTestPriority        High
   680 @SYMTestPriority        High
   581 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::CreateSecureL() in an OOM test.
   681 @SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
   582                         The test creates a secure database then executes CSqlSrvDatabase::OpenL() in an OOM loop.
   682                         Two secure databases are created and then, in an OOM loop, the test executes this sequence of
   583                         After that the database is deleted and the test executes CSqlSrvDatabase::CreateSecureL() in an OOM loop.
   683                         commands: open first database, attach the second database, detach the attached database,
   584                         The purpose of the test is to check that the CSqlSrver maps are properly updated when
   684                         close the first database. 
   585                         the database is closed.
   685                         UTF16 encoded database is used.
   586 @SYMTestExpectedResults Test must not fail
   686 @SYMTestExpectedResults Test must not fail
   587 @SYMDEF                 DEF144577, PDEF44845
   687 @SYMDEF                 DEF144577, PDEF44845
   588 */  
   688 */  
   589 void OpenCreateDatabaseOomTest()
   689 void Utf16OpenAttachDatabaseOomTest2()
       
   690     {
       
   691     OpenAttachDatabaseOomTest2(ESqlDbUtf16);
       
   692     }
       
   693 
       
   694 /**
       
   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
       
   704 @SYMDEF                 DEF145047
       
   705 */  
       
   706 void Utf8OpenAttachDatabaseOomTest2()
       
   707     {
       
   708     OpenAttachDatabaseOomTest2(ESqlDbUtf8);
       
   709     }
       
   710 
       
   711 void OpenCreateDatabaseOomTest(TSqlDbEncoding aEncoding)
   590     {
   712     {
   591     TheServer = NULL; 
   713     TheServer = NULL; 
   592     TRAPD(err, TheServer = CreateSqlServerL());
   714     TRAPD(err, TheServer = CreateSqlServerL());
   593     TEST2(err, KErrNone);
   715     TEST2(err, KErrNone);
   594     
   716     
   595     (void)TheFs.Delete(KDbFile2);
   717     (void)TheFs.Delete(KDbFile2);
   596     CreateSecureTestDb(KDbFile2);
   718     CreateSecureTestDb(KDbFile2, aEncoding);
   597     
   719     
   598     TheTest.Printf(_L("Iteration:\r\n"));
   720     TheTest.Printf(_L("Iteration:\r\n"));
   599 
   721 
   600     //Open the database
   722     //Open the database
   601     TInt failingAllocationNo = 0;
   723     TInt failingAllocationNo = 0;
   605         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   727         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   606         OomPreStep(failingAllocationNo);
   728         OomPreStep(failingAllocationNo);
   607         
   729         
   608         RMessage2 msg;
   730         RMessage2 msg;
   609         TSqlSrvFileData& fdata = TheServer->FileData();
   731         TSqlSrvFileData& fdata = TheServer->FileData();
   610         TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, (const TDesC8*)&KDbFile2));
   732         TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2));
   611         if(err == KErrNone)
   733         if(err == KErrNone)
   612             {
   734             {
   613             CSqlSrvDatabase* db = NULL;
   735             CSqlSrvDatabase* db = NULL;
   614             TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   736             TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   615             if(err == KErrNone)
   737             if(err == KErrNone)
   633         {
   755         {
   634         TheTest.Printf(_L(" %d"), ++failingAllocationNo2);
   756         TheTest.Printf(_L(" %d"), ++failingAllocationNo2);
   635         OomPreStep(failingAllocationNo2);
   757         OomPreStep(failingAllocationNo2);
   636         RMessage2 msg;
   758         RMessage2 msg;
   637         TSqlSrvFileData& fdata = TheServer->FileData();
   759         TSqlSrvFileData& fdata = TheServer->FileData();
   638         TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, (const TDesC8*)&KDbFile2));
   760         TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
   639         if(err == KErrNone)
   761         if(err == KErrNone)
   640             {
   762             {
   641             TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
   763             TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
   642             CSqlSecurityPolicy* policy = NULL;
   764             CSqlSecurityPolicy* policy = NULL;
   643             TRAP(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
   765             TRAP(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
   666     TEST2(err, KErrNone);   
   788     TEST2(err, KErrNone);   
   667     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateSecureL() OOM test succeeded at heap failure rate of %d ===\r\n"), 
   789     TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateSecureL() OOM test succeeded at heap failure rate of %d ===\r\n"), 
   668                    failingAllocationNo + failingAllocationNo2);
   790                    failingAllocationNo + failingAllocationNo2);
   669     }
   791     }
   670 
   792 
       
   793 /**
       
   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
       
   805 */  
       
   806 void Utf16OpenCreateDatabaseOomTest()
       
   807     {
       
   808     OpenCreateDatabaseOomTest(ESqlDbUtf16);
       
   809     }
       
   810 
       
   811 /**
       
   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
       
   822 @SYMDEF                 DEF145047
       
   823 */  
       
   824 void Utf8OpenCreateDatabaseOomTest()
       
   825     {
       
   826     OpenCreateDatabaseOomTest(ESqlDbUtf8);
       
   827     }
       
   828 
   671 void DoTests()
   829 void DoTests()
   672 	{
   830 	{
   673 #ifndef _DEBUG
   831 #ifndef _DEBUG
   674     TheTest.Start(_L("This test can be run only in debug mode!"));
   832     TheTest.Start(_L("This test can be run only in debug mode!"));
   675 #else	
   833 #else	
   676     CActiveScheduler* scheduler = new CActiveScheduler;
   834     CActiveScheduler* scheduler = new CActiveScheduler;
   677     TEST(scheduler != NULL);
   835     TEST(scheduler != NULL);
   678     CActiveScheduler::Install(scheduler);
   836     CActiveScheduler::Install(scheduler);
   679 	
   837 	
   680     TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4167 CSqlSrvDatabase::CreateL() OOM unit test"));
   838     TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4167 CSqlSrvDatabase::CreateL() OOM unit test"));
   681     CreateDatabaseOomTest();
   839     Utf16CreateDatabaseOomTest();
   682 
   840 
   683     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4168 CSqlSrvDatabase::OpenL() OOM unit test - non-secure database"));
   841     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4168 CSqlSrvDatabase::OpenL() OOM unit test - non-secure database"));
   684     OpenDatabaseOomTest();
   842     Utf16OpenDatabaseOomTest();
   685 
   843 
   686     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4169 CSqlSrvDatabase::CreateSecureL() OOM unit test"));
   844     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4169 CSqlSrvDatabase::CreateSecureL() OOM unit test"));
   687     CreateSecureDatabaseOomTest();
   845     Utf16CreateSecureDatabaseOomTest();
   688 
   846 
   689     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4170 CSqlSrvDatabase::OpenL() OOM unit test - secure database"));
   847     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4170 CSqlSrvDatabase::OpenL() OOM unit test - secure database"));
   690     OpenSecureDatabaseOomTest();
   848     Utf16OpenSecureDatabaseOomTest();
   691     
   849     
   692     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4171 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test"));
   850     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4171 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test"));
   693     OpenAttachDatabaseOomTest();
   851     Utf16OpenAttachDatabaseOomTest();
   694 
   852 
   695     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4172 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test - 2"));
   853     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4172 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test - 2"));
   696     OpenAttachDatabaseOomTest2();
   854     Utf16OpenAttachDatabaseOomTest2();
   697 
   855 
   698     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4173 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateL() OOM unit test"));
   856     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4173 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateL() OOM unit test"));
   699     OpenCreateDatabaseOomTest();
   857     Utf16OpenCreateDatabaseOomTest();
   700 
   858 
       
   859     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4182 CSqlSrvDatabase::CreateL() OOM unit test, UTF8 database"));
       
   860     Utf8CreateDatabaseOomTest();
       
   861 
       
   862     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4183 CSqlSrvDatabase::OpenL() OOM unit test - non-secure UTF8 database"));
       
   863     Utf8OpenDatabaseOomTest();
       
   864 
       
   865     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4184 CSqlSrvDatabase::CreateSecureL() OOM unit test, UTF8 database"));
       
   866     Utf8CreateSecureDatabaseOomTest();
       
   867 
       
   868     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4185 CSqlSrvDatabase::OpenL() OOM unit test - secure UTF8 database"));
       
   869     Utf8OpenSecureDatabaseOomTest();
       
   870 
       
   871     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4186 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test, UTF8 database"));
       
   872     Utf8OpenAttachDatabaseOomTest();
       
   873 
       
   874     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4187 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test 2, UTF8 database"));
       
   875     Utf8OpenAttachDatabaseOomTest2();
       
   876 
       
   877     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4188 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateL() OOM unit test, UTF8 database"));
       
   878     Utf8OpenCreateDatabaseOomTest();
       
   879     
   701     delete scheduler;
   880     delete scheduler;
   702 #endif //_DEBUG    
   881 #endif //_DEBUG    
   703 	}
   882 	}
   704 
   883 
   705 TInt E32Main()
   884 TInt E32Main()