os/persistentdata/persistentstorage/sql/TEST/t_sqloom5.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sql/TEST/t_sqloom5.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,906 @@
     1.4 +// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <e32test.h>
    1.20 +#include <bautils.h>
    1.21 +#include "SqlSrvMain.h"
    1.22 +#include "SqlSrvStartup.h"
    1.23 +#include "SqlSrvUtil.h"
    1.24 +#include "SqlSrvDatabase.h"
    1.25 +#include "SqlSrvFileData.h"
    1.26 +
    1.27 +///////////////////////////////////////////////////////////////////////////////////////
    1.28 +
    1.29 +RTest TheTest(_L("t_sqloom5 test"));
    1.30 +RFs TheFs;
    1.31 +
    1.32 +_LIT(KTestDir, "c:\\test\\");
    1.33 +_LIT(KDbFile, "c:\\test\\t_sqloom5.db");
    1.34 +_LIT(KDbFile2, "c:[10281E17]t_sqloom5.db");
    1.35 +_LIT(KDbFile3, "c:[10281E17]t_sqloom5_2.db");
    1.36 +_LIT(KDbFile4, "c:[10281E17]t_sqloom5_3.db");
    1.37 +
    1.38 +_LIT8(KConfig, "encoding=UTF-8");
    1.39 +
    1.40 +extern CSqlServer* TheServer;
    1.41 +
    1.42 +static TInt TheProcessHandleCount = 0;
    1.43 +static TInt TheThreadHandleCount = 0;
    1.44 +static TInt TheAllocatedCellsCount = 0;
    1.45 +
    1.46 +#ifdef _DEBUG
    1.47 +static const TInt KBurstRate = 20;
    1.48 +#endif
    1.49 +
    1.50 +enum TSqlDbEncoding
    1.51 +    {
    1.52 +    ESqlDbUtf16,
    1.53 +    ESqlDbUtf8
    1.54 +    };
    1.55 +
    1.56 +///////////////////////////////////////////////////////////////////////////////////////
    1.57 +
    1.58 +void DestroyTestEnv()
    1.59 +	{
    1.60 +    (void)TheFs.Delete(KDbFile4);
    1.61 +    (void)TheFs.Delete(KDbFile3);
    1.62 +    (void)TheFs.Delete(KDbFile2);
    1.63 +    (void)TheFs.Delete(KDbFile);
    1.64 +	TheFs.Close();
    1.65 +	}
    1.66 +
    1.67 +///////////////////////////////////////////////////////////////////////////////////////
    1.68 +///////////////////////////////////////////////////////////////////////////////////////
    1.69 +//Test macros and functions
    1.70 +void Check(TInt aValue, TInt aLine)
    1.71 +	{
    1.72 +	if(!aValue)
    1.73 +		{
    1.74 +		DestroyTestEnv();
    1.75 +		RDebug::Print(_L("*** Expresssion evaluated to false\r\n"));
    1.76 +		TheTest(EFalse, aLine);
    1.77 +		}
    1.78 +	}
    1.79 +void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.80 +	{
    1.81 +	if(aValue != aExpected)
    1.82 +		{
    1.83 +		DestroyTestEnv();
    1.84 +		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.85 +		TheTest(EFalse, aLine);
    1.86 +		}
    1.87 +	}
    1.88 +#define TEST(arg) ::Check((arg), __LINE__)
    1.89 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    1.90 +
    1.91 +////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1.92 +
    1.93 +static void MarkHandles()
    1.94 +    {
    1.95 +    RThread().HandleCount(TheProcessHandleCount, TheThreadHandleCount);
    1.96 +    }
    1.97 +
    1.98 +static void MarkAllocatedCells()
    1.99 +    {
   1.100 +    TheAllocatedCellsCount = User::CountAllocCells();
   1.101 +    }
   1.102 +
   1.103 +static void CheckAllocatedCells()
   1.104 +    {
   1.105 +    TInt allocatedCellsCount = User::CountAllocCells();
   1.106 +    TEST2(allocatedCellsCount, TheAllocatedCellsCount);
   1.107 +    }
   1.108 +
   1.109 +static void CheckHandles()
   1.110 +    {
   1.111 +    TInt endProcessHandleCount;
   1.112 +    TInt endThreadHandleCount;
   1.113 +    
   1.114 +    RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   1.115 +
   1.116 +    TEST2(TheProcessHandleCount, endProcessHandleCount);
   1.117 +    TEST2(TheThreadHandleCount, endThreadHandleCount);
   1.118 +    }
   1.119 +
   1.120 +static void OomPreStep(TInt
   1.121 +                        #ifdef _DEBUG        
   1.122 +                            aFailingAllocationNo
   1.123 +                        #endif
   1.124 +                      )
   1.125 +    {
   1.126 +    MarkHandles();
   1.127 +    MarkAllocatedCells();
   1.128 +    __UHEAP_MARK;
   1.129 +    __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, aFailingAllocationNo, KBurstRate);
   1.130 +    }
   1.131 +
   1.132 +static void OomPostStep()
   1.133 +    {
   1.134 +    __UHEAP_RESET;
   1.135 +    __UHEAP_MARKEND;
   1.136 +    CheckAllocatedCells();
   1.137 +    CheckHandles();
   1.138 +    }
   1.139 +
   1.140 +////////////////////////////////////////////////////////////////////////////////////////////////////////////
   1.141 +////////////////////////////////////////////////////////////////////////////////////////////////////////////
   1.142 +
   1.143 +void CreateTestEnv()
   1.144 +    {
   1.145 +    TInt err = TheFs.Connect();
   1.146 +    TEST2(err, KErrNone);
   1.147 +
   1.148 +    err = TheFs.MkDir(KTestDir);
   1.149 +    TEST(err == KErrNone || err == KErrAlreadyExists);
   1.150 +
   1.151 +    err = TheFs.CreatePrivatePath(EDriveC);
   1.152 +    TEST(err == KErrNone || err == KErrAlreadyExists);
   1.153 +    }
   1.154 +
   1.155 +static CSqlServer* CreateSqlServerL()
   1.156 +    {
   1.157 +    CSqlServer* server = CSqlServer::NewLC();
   1.158 +    CleanupStack::Pop(server);
   1.159 +    return server;
   1.160 +    }
   1.161 +
   1.162 +void CreateDatabaseOomTest(TSqlDbEncoding aEncoding)
   1.163 +    {
   1.164 +    (void)TheFs.Delete(KDbFile);
   1.165 +    TInt failingAllocationNo = 0;
   1.166 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.167 +    
   1.168 +    TheServer = NULL; 
   1.169 +    TRAPD(err, TheServer = CreateSqlServerL());
   1.170 +    TEST2(err, KErrNone);
   1.171 +    
   1.172 +    err = KErrNoMemory;
   1.173 +    while(err == KErrNoMemory)
   1.174 +        {
   1.175 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.176 +        OomPreStep(failingAllocationNo);
   1.177 +        
   1.178 +        TSqlSrvFileData& fdata = TheServer->FileData();
   1.179 +        RMessage2 msg;
   1.180 +        TRAP(err, fdata.SetL(msg, KDbFile().Length(), 0, KDbFile, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
   1.181 +        if(err == KErrNone)
   1.182 +            {
   1.183 +            CSqlSrvDatabase* db = NULL;
   1.184 +            TRAP(err, db = CSqlSrvDatabase::CreateL(fdata));
   1.185 +            delete db;
   1.186 +            }
   1.187 +        OomPostStep();
   1.188 +        }
   1.189 +
   1.190 +    delete TheServer;
   1.191 +    TheServer = NULL;
   1.192 +    
   1.193 +    TEST2(err, KErrNone);   
   1.194 +    TheTest.Printf(_L("\r\n===CSqlSrvDatabase::CreateL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.195 +    }
   1.196 +
   1.197 +/**
   1.198 +@SYMTestCaseID          PDS-SQL-UT-4167
   1.199 +@SYMTestCaseDesc        CSqlSrvDatabase::CreateL() OOM test.
   1.200 +@SYMTestPriority        High
   1.201 +@SYMTestActions         The test runs CSqlSrvDatabase::CreateL() in an OOM loop.
   1.202 +                        UTF16 encoded database is used.
   1.203 +@SYMTestExpectedResults Test must not fail
   1.204 +@SYMDEF                 DEF144577
   1.205 +*/  
   1.206 +void Utf16CreateDatabaseOomTest()
   1.207 +    {
   1.208 +    CreateDatabaseOomTest(ESqlDbUtf16);
   1.209 +    }
   1.210 +
   1.211 +/**
   1.212 +@SYMTestCaseID          PDS-SQL-UT-4182
   1.213 +@SYMTestCaseDesc        CSqlSrvDatabase::CreateL() OOM test.
   1.214 +@SYMTestPriority        High
   1.215 +@SYMTestActions         The test runs CSqlSrvDatabase::CreateL() in an OOM loop.
   1.216 +                        UTF8 encoded database is used.
   1.217 +@SYMTestExpectedResults Test must not fail
   1.218 +@SYMDEF                 DEF145047
   1.219 +*/  
   1.220 +void Utf8CreateDatabaseOomTest()
   1.221 +    {
   1.222 +    CreateDatabaseOomTest(ESqlDbUtf8);
   1.223 +    }
   1.224 +
   1.225 +void OpenDatabaseOomTest()
   1.226 +    {
   1.227 +    //The database is created by the previous test: CreateDatabaseOomTest().
   1.228 +    
   1.229 +    TInt failingAllocationNo = 0;
   1.230 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.231 +    
   1.232 +    TheServer = NULL; 
   1.233 +    TRAPD(err, TheServer = CreateSqlServerL());
   1.234 +    TEST2(err, KErrNone);
   1.235 +    
   1.236 +    err = KErrNoMemory;
   1.237 +    while(err == KErrNoMemory)
   1.238 +        {
   1.239 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.240 +        OomPreStep(failingAllocationNo);
   1.241 +        
   1.242 +        TSqlSrvFileData& fdata = TheServer->FileData();
   1.243 +        RMessage2 msg;
   1.244 +        TRAP(err, fdata.SetL(msg, KDbFile().Length(), 0, KDbFile));
   1.245 +        if(err == KErrNone)
   1.246 +            {
   1.247 +            CSqlSrvDatabase* db = NULL;
   1.248 +            TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   1.249 +            delete db;
   1.250 +            }
   1.251 +        
   1.252 +        OomPostStep();
   1.253 +        }
   1.254 +    
   1.255 +    delete TheServer;
   1.256 +    TheServer = NULL;
   1.257 +    
   1.258 +    TEST2(err, KErrNone);   
   1.259 +    TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() [non-secure db] OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.260 +    }
   1.261 +
   1.262 +/**
   1.263 +@SYMTestCaseID          PDS-SQL-UT-4168
   1.264 +@SYMTestCaseDesc        CSqlSrvDatabase::OpenL() OOM test - non-secure database.
   1.265 +@SYMTestPriority        High
   1.266 +@SYMTestActions         The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
   1.267 +                        UTF16 encoded database is used.
   1.268 +@SYMTestExpectedResults Test must not fail
   1.269 +@SYMDEF                 DEF144577
   1.270 +*/  
   1.271 +void Utf16OpenDatabaseOomTest()
   1.272 +    {
   1.273 +    OpenDatabaseOomTest();
   1.274 +    }
   1.275 +
   1.276 +/**
   1.277 +@SYMTestCaseID          PDS-SQL-UT-4183
   1.278 +@SYMTestCaseDesc        CSqlSrvDatabase::OpenL() OOM test - non-secure database.
   1.279 +@SYMTestPriority        High
   1.280 +@SYMTestActions         The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
   1.281 +                        UTF8 encoded database is used.
   1.282 +@SYMTestExpectedResults Test must not fail
   1.283 +@SYMDEF                 DEF145047
   1.284 +*/  
   1.285 +void Utf8OpenDatabaseOomTest()
   1.286 +    {
   1.287 +    OpenDatabaseOomTest();
   1.288 +    }
   1.289 +
   1.290 +void CreateSecureDatabaseOomTest(TSqlDbEncoding aEncoding)
   1.291 +    {
   1.292 +    (void)TheFs.Delete(KDbFile2);
   1.293 +    TInt failingAllocationNo = 0;
   1.294 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.295 +    
   1.296 +    TheServer = NULL; 
   1.297 +    TRAPD(err, TheServer = CreateSqlServerL());
   1.298 +    TEST2(err, KErrNone);
   1.299 +        
   1.300 +    err = KErrNoMemory;
   1.301 +    while(err == KErrNoMemory)
   1.302 +        {
   1.303 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.304 +        OomPreStep(failingAllocationNo);
   1.305 +        
   1.306 +        TSqlSrvFileData& fdata = TheServer->FileData();
   1.307 +        RMessage2 msg;
   1.308 +        TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
   1.309 +        if(err == KErrNone)
   1.310 +            {
   1.311 +            TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
   1.312 +            CSqlSecurityPolicy* policy = NULL;
   1.313 +            TRAP(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
   1.314 +            if(err == KErrNone)
   1.315 +                {
   1.316 +                CSqlSrvDatabase* db = NULL;
   1.317 +                TRAP(err, db = CSqlSrvDatabase::CreateSecureL(fdata, policy));
   1.318 +                delete db;
   1.319 +                }
   1.320 +            }
   1.321 +        OomPostStep();
   1.322 +        }
   1.323 +
   1.324 +    delete TheServer;
   1.325 +    TheServer = NULL;
   1.326 +    
   1.327 +    TEST2(err, KErrNone);   
   1.328 +    TheTest.Printf(_L("\r\n===CSqlSrvDatabase::CreateSecureL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.329 +    }
   1.330 +
   1.331 +/**
   1.332 +@SYMTestCaseID          PDS-SQL-UT-4169
   1.333 +@SYMTestCaseDesc        CSqlSrvDatabase::CreateSecureL() OOM test.
   1.334 +@SYMTestPriority        High
   1.335 +@SYMTestActions         The test runs CSqlSrvDatabase::CreateSecureL() in an OOM loop.
   1.336 +                        UTF16 encoded database is used.
   1.337 +@SYMTestExpectedResults Test must not fail
   1.338 +@SYMDEF                 DEF144577
   1.339 +*/  
   1.340 +void Utf16CreateSecureDatabaseOomTest()
   1.341 +    {
   1.342 +    CreateSecureDatabaseOomTest(ESqlDbUtf16);
   1.343 +    }
   1.344 +
   1.345 +/**
   1.346 +@SYMTestCaseID          PDS-SQL-UT-4184
   1.347 +@SYMTestCaseDesc        CSqlSrvDatabase::CreateSecureL() OOM test.
   1.348 +@SYMTestPriority        High
   1.349 +@SYMTestActions         The test runs CSqlSrvDatabase::CreateSecureL() in an OOM loop.
   1.350 +                        UTF8 encoded database is used.
   1.351 +@SYMTestExpectedResults Test must not fail
   1.352 +@SYMDEF                 DEF145047
   1.353 +*/  
   1.354 +void Utf8CreateSecureDatabaseOomTest()
   1.355 +    {
   1.356 +    CreateSecureDatabaseOomTest(ESqlDbUtf8);
   1.357 +    }
   1.358 +
   1.359 +void OpenSecureDatabaseOomTest()
   1.360 +    {
   1.361 +    //The database is created by the previous test: CreateSecureDatabaseOomTest().
   1.362 +    
   1.363 +    TInt failingAllocationNo = 0;
   1.364 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.365 +    
   1.366 +    TheServer = NULL; 
   1.367 +    TRAPD(err, TheServer = CreateSqlServerL());
   1.368 +    TEST2(err, KErrNone);
   1.369 +    
   1.370 +    err = KErrNoMemory;
   1.371 +    while(err == KErrNoMemory)
   1.372 +        {
   1.373 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.374 +        OomPreStep(failingAllocationNo);
   1.375 +        
   1.376 +        TSqlSrvFileData& fdata = TheServer->FileData();
   1.377 +        RMessage2 msg;
   1.378 +        TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2));
   1.379 +        if(err == KErrNone)
   1.380 +            {
   1.381 +            CSqlSrvDatabase* db = NULL;
   1.382 +            TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   1.383 +            delete db;
   1.384 +            }
   1.385 +        
   1.386 +        OomPostStep();
   1.387 +        }
   1.388 +    
   1.389 +    delete TheServer;
   1.390 +    TheServer = NULL;
   1.391 +    
   1.392 +    TEST2(err, KErrNone);   
   1.393 +    TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() [secure db] OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.394 +    }
   1.395 +
   1.396 +/**
   1.397 +@SYMTestCaseID          PDS-SQL-UT-4170
   1.398 +@SYMTestCaseDesc        CSqlSrvDatabase::OpenL() OOM test - secure database.
   1.399 +@SYMTestPriority        High
   1.400 +@SYMTestActions         The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
   1.401 +                        UTF16 encoded database is used.
   1.402 +@SYMTestExpectedResults Test must not fail
   1.403 +@SYMDEF                 DEF144577, PDEF44845
   1.404 +*/  
   1.405 +void Utf16OpenSecureDatabaseOomTest()
   1.406 +    {
   1.407 +    OpenSecureDatabaseOomTest();
   1.408 +    }
   1.409 +
   1.410 +/**
   1.411 +@SYMTestCaseID          PDS-SQL-UT-4185
   1.412 +@SYMTestCaseDesc        CSqlSrvDatabase::OpenL() OOM test - secure database.
   1.413 +@SYMTestPriority        High
   1.414 +@SYMTestActions         The test runs CSqlSrvDatabase::OpenL() in an OOM loop.
   1.415 +                        UTF8 encoded database is used.
   1.416 +@SYMTestExpectedResults Test must not fail
   1.417 +@SYMDEF                 DEF145047
   1.418 +*/  
   1.419 +void Utf8OpenSecureDatabaseOomTest()
   1.420 +    {
   1.421 +    OpenSecureDatabaseOomTest();
   1.422 +    }
   1.423 +
   1.424 +/////////////////////////////////////////////////////////////
   1.425 +
   1.426 +const TInt KDbConnCount = 7; 
   1.427 +#ifdef _DEBUG
   1.428 +const TInt KDbAttachedCount = 10;
   1.429 +#endif
   1.430 +TBuf<10> TheAttachedDbName;
   1.431 +
   1.432 +//Declares KDbConnCount "CSqlSrvDatabase*" variables.  
   1.433 +#define TEST_DECLARE_DB_VARS() \
   1.434 +    CSqlSrvDatabase* db[KDbConnCount]; \
   1.435 +    Mem::FillZ(db, sizeof(db));
   1.436 +
   1.437 +//Declares all KDbConnCount "CSqlSrvDatabase*" objects.  
   1.438 +#define TEST_DELETE_DB() \
   1.439 +    for(TInt i=0;i<KDbConnCount;++i) \
   1.440 +        { \
   1.441 +        delete db[i]; \
   1.442 +        }
   1.443 +
   1.444 +//Creates CSqlSrvDatabase object where the database file is dbFile (the second macro parameter).
   1.445 +//The CSqlSrvDatabase pointer db[N - 1] (N is the first macro parameter) will be set to point to 
   1.446 +//the created CSqlSrvDatabase object. 
   1.447 +//N is the number of the database to be opened, between 1 and KDbConnCount.
   1.448 +#define TEST_OPEN_DB(N, dbFile) \
   1.449 +    __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
   1.450 +    TRAP(err, fdata.SetL(msg, dbFile.Length(), 0, dbFile)); \
   1.451 +    if(err != KErrNone) \
   1.452 +        { \
   1.453 +        goto Cleanup; \
   1.454 +        } \
   1.455 +    db[N - 1] = NULL; \
   1.456 +    TRAP(err, db[N - 1] = CSqlSrvDatabase::OpenL(fdata)); \
   1.457 +    if(err != KErrNone) \
   1.458 +        { \
   1.459 +        goto Cleanup; \
   1.460 +        }
   1.461 +
   1.462 +//Attaches the "dbFile" database to the database number specified by the first macro parameter.
   1.463 +//The attached database name is "A<M>", where M is the third macro parameter.
   1.464 +//N is the number of the database connection, between 1 and KDbConnCount.
   1.465 +//M is the number of the database to be attached, between 1 and KDbAttachedCount.
   1.466 +#define TEST_ATTACH_DB(N, dbFile, M) \
   1.467 +    __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
   1.468 +    __ASSERT_DEBUG(M > 0 && M <= KDbAttachedCount, User::Invariant()); \
   1.469 +    TRAP(err, fdata.SetL(msg, dbFile.Length(), 0, dbFile)); \
   1.470 +    if(err != KErrNone) \
   1.471 +        { \
   1.472 +        goto Cleanup; \
   1.473 +        } \
   1.474 +    TheAttachedDbName.Copy(_L("A")); \
   1.475 +    TheAttachedDbName.AppendNum(M); \
   1.476 +    TRAP(err, db[N - 1]->AttachDbL(fdata, TheAttachedDbName)); \
   1.477 +    if(err != KErrNone) \
   1.478 +        { \
   1.479 +        goto Cleanup; \
   1.480 +        }
   1.481 +
   1.482 +//Detaches database "A<M>" (M is the second macro parameter) from the database identified
   1.483 +//by the number N - the first macro parameter.
   1.484 +//N is the number of the database connection, between 1 and KDbConnCount.
   1.485 +//M is the number of the database to be detached, between 1 and KDbAttachedCount.
   1.486 +#define TEST_DETACH_DB(N, M) \
   1.487 +    __ASSERT_DEBUG(N > 0 && N <= KDbConnCount, User::Invariant()); \
   1.488 +    __ASSERT_DEBUG(M > 0 && M <= KDbAttachedCount, User::Invariant()); \
   1.489 +    if(db[N - 1]) \
   1.490 +        { \
   1.491 +        TheAttachedDbName.Copy(_L("A")); \
   1.492 +        TheAttachedDbName.AppendNum(M); \
   1.493 +        TRAP_IGNORE(db[N - 1]->DetachDbL(TheAttachedDbName)); \
   1.494 +        }
   1.495 +
   1.496 +/////////////////////////////////////////////////////////////
   1.497 +
   1.498 +void CreateSecureTestDb(const TDesC& aDbFile, TSqlDbEncoding aEncoding)
   1.499 +    {
   1.500 +    (void)TheFs.Delete(aDbFile);
   1.501 +    
   1.502 +    TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
   1.503 +    CSqlSecurityPolicy* policy = NULL;
   1.504 +    TRAPD(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
   1.505 +    TEST2(err, KErrNone);
   1.506 +    
   1.507 +    TSqlSrvFileData& fdata = TheServer->FileData();
   1.508 +    RMessage2 msg;
   1.509 +    TRAP(err, fdata.SetL(msg, aDbFile.Length(), 0, aDbFile, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
   1.510 +    
   1.511 +    CSqlSrvDatabase* db = NULL;
   1.512 +    TRAP(err, db = CSqlSrvDatabase::CreateSecureL(fdata, policy));
   1.513 +    delete db;
   1.514 +    TEST2(err, KErrNone);
   1.515 +    }
   1.516 +    
   1.517 +void OpenAttachDatabaseOomTest(TSqlDbEncoding aEncoding)
   1.518 +    {
   1.519 +    //Part of the databases are created by the previous tests.
   1.520 +        
   1.521 +    TInt failingAllocationNo = 0;
   1.522 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.523 +    
   1.524 +    TheServer = NULL; 
   1.525 +    TRAPD(err, TheServer = CreateSqlServerL());
   1.526 +    TEST2(err, KErrNone);
   1.527 +
   1.528 +    CreateSecureTestDb(KDbFile3, aEncoding);
   1.529 +    CreateSecureTestDb(KDbFile4, aEncoding);
   1.530 +    
   1.531 +    //The following 2 declarations are used by the macros in the OOM loop
   1.532 +    RMessage2 msg;
   1.533 +    TSqlSrvFileData& fdata = TheServer->FileData();
   1.534 +    
   1.535 +    err = KErrNoMemory;
   1.536 +    while(err == KErrNoMemory)
   1.537 +        {
   1.538 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.539 +        OomPreStep(failingAllocationNo);
   1.540 +        //Declare KDbConnCount "CSqlSrvDatabase*" variables.
   1.541 +        TEST_DECLARE_DB_VARS();
   1.542 +        //Create CSqlSrvDatabase object, the database name is the second parameter of the macro. 
   1.543 +        //The related db[N - 1] variable will be set to point to the created object.
   1.544 +        TEST_OPEN_DB(1, KDbFile2());
   1.545 +        TEST_OPEN_DB(2, KDbFile2());
   1.546 +        TEST_OPEN_DB(3, KDbFile3());
   1.547 +        TEST_OPEN_DB(4, KDbFile3());
   1.548 +        TEST_OPEN_DB(5, KDbFile3());
   1.549 +        TEST_OPEN_DB(6, KDbFile());
   1.550 +        TEST_OPEN_DB(7, KDbFile());
   1.551 +        //Attach to the database with the number specified as first macro parameter, the database file, specified
   1.552 +        //as second macro parameter. The logical name of the attached database is "A<M>", where M is the third macro parameter.
   1.553 +        TEST_ATTACH_DB(1, KDbFile(), 1);
   1.554 +        TEST_ATTACH_DB(2, KDbFile(), 2);
   1.555 +        TEST_ATTACH_DB(2, KDbFile(), 3);
   1.556 +        TEST_ATTACH_DB(5, KDbFile4(), 4);
   1.557 +        TEST_ATTACH_DB(2, KDbFile4(), 5);
   1.558 +        TEST_ATTACH_DB(2, KDbFile4(), 6);
   1.559 +        TEST_ATTACH_DB(5, KDbFile4(), 7);
   1.560 +        TEST_ATTACH_DB(5, KDbFile4(), 8);
   1.561 +        TEST_ATTACH_DB(1, KDbFile4(), 9);
   1.562 +        TEST_ATTACH_DB(1, KDbFile(), 10);
   1.563 +Cleanup:
   1.564 +        __UHEAP_SETBURSTFAIL(RAllocator::ENone, 0, 0);
   1.565 +        //Detach from the database with the number specified as first macro parameter, the database         
   1.566 +        //with name "A<M>", where M is the second macro parameter.
   1.567 +        TEST_DETACH_DB(1, 9);
   1.568 +        TEST_DETACH_DB(1, 1);
   1.569 +        TEST_DETACH_DB(1, 10);
   1.570 +        TEST_DETACH_DB(2, 2);
   1.571 +        TEST_DETACH_DB(2, 3);
   1.572 +        TEST_DETACH_DB(2, 5);
   1.573 +        TEST_DETACH_DB(2, 6);
   1.574 +        TEST_DETACH_DB(5, 4);
   1.575 +        TEST_DETACH_DB(5, 7);
   1.576 +        TEST_DETACH_DB(5, 8);
   1.577 +        //Delete all created CSqlSrvDatabase objects.
   1.578 +        TEST_DELETE_DB();        
   1.579 +        
   1.580 +        OomPostStep();
   1.581 +        }
   1.582 +    
   1.583 +    delete TheServer;
   1.584 +    TheServer = NULL;
   1.585 +    
   1.586 +    (void)TheFs.Delete(KDbFile4);
   1.587 +    (void)TheFs.Delete(KDbFile3);
   1.588 +    
   1.589 +    TEST2(err, KErrNone);   
   1.590 +    TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.591 +    }
   1.592 +
   1.593 +/**
   1.594 +@SYMTestCaseID          PDS-SQL-UT-4171
   1.595 +@SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
   1.596 +@SYMTestPriority        High
   1.597 +@SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
   1.598 +                        The test is a complex one - 7 (KDbConnCount constant) databases opened 
   1.599 +                        (secure and non-secure), 10 (KDbAttachedCount constant) databases
   1.600 +                        attached (secure and non-secure).
   1.601 +                        UTF16 encoded database is used.
   1.602 +@SYMTestExpectedResults Test must not fail
   1.603 +@SYMDEF                 DEF144577, DEF144603
   1.604 +*/  
   1.605 +void Utf16OpenAttachDatabaseOomTest()
   1.606 +    {
   1.607 +    OpenAttachDatabaseOomTest(ESqlDbUtf16);
   1.608 +    }
   1.609 +
   1.610 +/**
   1.611 +@SYMTestCaseID          PDS-SQL-UT-4186
   1.612 +@SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
   1.613 +@SYMTestPriority        High
   1.614 +@SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
   1.615 +                        The test is a complex one - 7 (KDbConnCount constant) databases opened 
   1.616 +                        (secure and non-secure), 10 (KDbAttachedCount constant) databases
   1.617 +                        attached (secure and non-secure).
   1.618 +                        UTF8 encoded database is used.
   1.619 +@SYMTestExpectedResults Test must not fail
   1.620 +@SYMDEF                 DEF144603
   1.621 +*/  
   1.622 +void Utf8OpenAttachDatabaseOomTest()
   1.623 +    {
   1.624 +    OpenAttachDatabaseOomTest(ESqlDbUtf8);
   1.625 +    }
   1.626 +
   1.627 +void OpenAttachDatabaseOomTest2(TSqlDbEncoding aEncoding)
   1.628 +    {
   1.629 +    TheServer = NULL; 
   1.630 +    TRAPD(err, TheServer = CreateSqlServerL());
   1.631 +    TEST2(err, KErrNone);
   1.632 +    
   1.633 +    CreateSecureTestDb(KDbFile3, aEncoding);
   1.634 +    CreateSecureTestDb(KDbFile4, aEncoding);
   1.635 +    
   1.636 +    TInt failingAllocationNo = 0;
   1.637 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.638 +    
   1.639 +    RMessage2 msg;
   1.640 +    TSqlSrvFileData& fdata = TheServer->FileData();
   1.641 +    
   1.642 +    err = KErrNoMemory;
   1.643 +    while(err == KErrNoMemory)
   1.644 +        {
   1.645 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.646 +        OomPreStep(failingAllocationNo);
   1.647 +        
   1.648 +        TRAP(err, fdata.SetL(msg, KDbFile3().Length(), 0, KDbFile3));
   1.649 +        if(err == KErrNone)
   1.650 +            {
   1.651 +            CSqlSrvDatabase* db = NULL;
   1.652 +            TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   1.653 +            if(err == KErrNone)
   1.654 +                {
   1.655 +                TRAP(err, fdata.SetL(msg, KDbFile4().Length(), 0, KDbFile4));
   1.656 +                if(err == KErrNone)
   1.657 +                    {
   1.658 +                    TRAP(err, db->AttachDbL(fdata, _L("db2")));
   1.659 +                    if(err == KErrNone)
   1.660 +                        {
   1.661 +                        TRAP(err, db->DetachDbL(_L("db2")));
   1.662 +                        }
   1.663 +                    }
   1.664 +                delete db;
   1.665 +                }
   1.666 +            }
   1.667 +        OomPostStep();
   1.668 +        }
   1.669 +    
   1.670 +    (void)TheFs.Delete(KDbFile4);
   1.671 +    (void)TheFs.Delete(KDbFile3);
   1.672 +    
   1.673 +    delete TheServer;
   1.674 +    TheServer = NULL;
   1.675 +     
   1.676 +    TEST2(err, KErrNone);   
   1.677 +    TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test 2 succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.678 +    }
   1.679 +
   1.680 +/**
   1.681 +@SYMTestCaseID          PDS-SQL-UT-4172
   1.682 +@SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
   1.683 +@SYMTestPriority        High
   1.684 +@SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
   1.685 +                        Two secure databases are created and then, in an OOM loop, the test executes this sequence of
   1.686 +                        commands: open first database, attach the second database, detach the attached database,
   1.687 +                        close the first database. 
   1.688 +                        UTF16 encoded database is used.
   1.689 +@SYMTestExpectedResults Test must not fail
   1.690 +@SYMDEF                 DEF144577, PDEF44845
   1.691 +*/  
   1.692 +void Utf16OpenAttachDatabaseOomTest2()
   1.693 +    {
   1.694 +    OpenAttachDatabaseOomTest2(ESqlDbUtf16);
   1.695 +    }
   1.696 +
   1.697 +/**
   1.698 +@SYMTestCaseID          PDS-SQL-UT-4187
   1.699 +@SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM test.
   1.700 +@SYMTestPriority        High
   1.701 +@SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::AttachDbL() in an OOM test.
   1.702 +                        Two secure databases are created and then, in an OOM loop, the test executes this sequence of
   1.703 +                        commands: open first database, attach the second database, detach the attached database,
   1.704 +                        close the first database. 
   1.705 +                        UTF8 encoded database is used.
   1.706 +@SYMTestExpectedResults Test must not fail
   1.707 +@SYMDEF                 DEF145047
   1.708 +*/  
   1.709 +void Utf8OpenAttachDatabaseOomTest2()
   1.710 +    {
   1.711 +    OpenAttachDatabaseOomTest2(ESqlDbUtf8);
   1.712 +    }
   1.713 +
   1.714 +void OpenCreateDatabaseOomTest(TSqlDbEncoding aEncoding)
   1.715 +    {
   1.716 +    TheServer = NULL; 
   1.717 +    TRAPD(err, TheServer = CreateSqlServerL());
   1.718 +    TEST2(err, KErrNone);
   1.719 +    
   1.720 +    (void)TheFs.Delete(KDbFile2);
   1.721 +    CreateSecureTestDb(KDbFile2, aEncoding);
   1.722 +    
   1.723 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.724 +
   1.725 +    //Open the database
   1.726 +    TInt failingAllocationNo = 0;
   1.727 +    err = KErrNoMemory;
   1.728 +    while(err == KErrNoMemory)
   1.729 +        {
   1.730 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.731 +        OomPreStep(failingAllocationNo);
   1.732 +        
   1.733 +        RMessage2 msg;
   1.734 +        TSqlSrvFileData& fdata = TheServer->FileData();
   1.735 +        TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2));
   1.736 +        if(err == KErrNone)
   1.737 +            {
   1.738 +            CSqlSrvDatabase* db = NULL;
   1.739 +            TRAP(err, db = CSqlSrvDatabase::OpenL(fdata));
   1.740 +            if(err == KErrNone)
   1.741 +                {
   1.742 +                delete db;
   1.743 +                }
   1.744 +            else
   1.745 +                {
   1.746 +                TEST(!db);
   1.747 +                }
   1.748 +            }
   1.749 +        OomPostStep();
   1.750 +        }
   1.751 +    TEST2(err, KErrNone);   
   1.752 +    err = TheFs.Delete(KDbFile2);
   1.753 +    TEST2(err, KErrNone);   
   1.754 +    //Create the database
   1.755 +    TInt failingAllocationNo2 = 0;
   1.756 +    err = KErrNoMemory;
   1.757 +    while(err == KErrNoMemory)
   1.758 +        {
   1.759 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo2);
   1.760 +        OomPreStep(failingAllocationNo2);
   1.761 +        RMessage2 msg;
   1.762 +        TSqlSrvFileData& fdata = TheServer->FileData();
   1.763 +        TRAP(err, fdata.SetL(msg, KDbFile2().Length(), 0, KDbFile2, aEncoding == ESqlDbUtf8 ? &KConfig : NULL));
   1.764 +        if(err == KErrNone)
   1.765 +            {
   1.766 +            TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass);
   1.767 +            CSqlSecurityPolicy* policy = NULL;
   1.768 +            TRAP(err, policy = CSqlSecurityPolicy::NewL(defaultPolicy));
   1.769 +            if(err == KErrNone)
   1.770 +                {
   1.771 +                CSqlSrvDatabase* db = NULL;
   1.772 +                TRAP(err, db = CSqlSrvDatabase::CreateSecureL(fdata, policy));
   1.773 +                if(err == KErrNone)
   1.774 +                    {
   1.775 +                    delete db;
   1.776 +                    }
   1.777 +                else
   1.778 +                    {
   1.779 +                    TEST(!db);
   1.780 +                    }
   1.781 +                }
   1.782 +            }
   1.783 +        OomPostStep();
   1.784 +        }
   1.785 +    
   1.786 +    (void)TheFs.Delete(KDbFile2);
   1.787 +    
   1.788 +    delete TheServer;
   1.789 +    TheServer = NULL;
   1.790 +     
   1.791 +    TEST2(err, KErrNone);   
   1.792 +    TheTest.Printf(_L("\r\n===CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateSecureL() OOM test succeeded at heap failure rate of %d ===\r\n"), 
   1.793 +                   failingAllocationNo + failingAllocationNo2);
   1.794 +    }
   1.795 +
   1.796 +/**
   1.797 +@SYMTestCaseID          PDS-SQL-UT-4173
   1.798 +@SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateSecureL() OOM test.
   1.799 +@SYMTestPriority        High
   1.800 +@SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::CreateSecureL() in an OOM test.
   1.801 +                        The test creates a secure database then executes CSqlSrvDatabase::OpenL() in an OOM loop.
   1.802 +                        After that the database is deleted and the test executes CSqlSrvDatabase::CreateSecureL() in an OOM loop.
   1.803 +                        The purpose of the test is to check that the CSqlSrver maps are properly updated when
   1.804 +                        the database is closed.
   1.805 +                        UTF16 encoded database is used.
   1.806 +@SYMTestExpectedResults Test must not fail
   1.807 +@SYMDEF                 DEF144577, PDEF44845
   1.808 +*/  
   1.809 +void Utf16OpenCreateDatabaseOomTest()
   1.810 +    {
   1.811 +    OpenCreateDatabaseOomTest(ESqlDbUtf16);
   1.812 +    }
   1.813 +
   1.814 +/**
   1.815 +@SYMTestCaseID          PDS-SQL-UT-4188
   1.816 +@SYMTestCaseDesc        CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateSecureL() OOM test.
   1.817 +@SYMTestPriority        High
   1.818 +@SYMTestActions         The test runs CSqlSrvDatabase::OpenL() and CSqlSrvDatabase::CreateSecureL() in an OOM test.
   1.819 +                        The test creates a secure database then executes CSqlSrvDatabase::OpenL() in an OOM loop.
   1.820 +                        After that the database is deleted and the test executes CSqlSrvDatabase::CreateSecureL() in an OOM loop.
   1.821 +                        The purpose of the test is to check that the CSqlSrver maps are properly updated when
   1.822 +                        the database is closed.
   1.823 +                        UTF8 encoded database is used.
   1.824 +@SYMTestExpectedResults Test must not fail
   1.825 +@SYMDEF                 DEF145047
   1.826 +*/  
   1.827 +void Utf8OpenCreateDatabaseOomTest()
   1.828 +    {
   1.829 +    OpenCreateDatabaseOomTest(ESqlDbUtf8);
   1.830 +    }
   1.831 +
   1.832 +void DoTests()
   1.833 +	{
   1.834 +#ifndef _DEBUG
   1.835 +    TheTest.Start(_L("This test can be run only in debug mode!"));
   1.836 +#else	
   1.837 +    CActiveScheduler* scheduler = new CActiveScheduler;
   1.838 +    TEST(scheduler != NULL);
   1.839 +    CActiveScheduler::Install(scheduler);
   1.840 +	
   1.841 +    TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4167 CSqlSrvDatabase::CreateL() OOM unit test"));
   1.842 +    Utf16CreateDatabaseOomTest();
   1.843 +
   1.844 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4168 CSqlSrvDatabase::OpenL() OOM unit test - non-secure database"));
   1.845 +    Utf16OpenDatabaseOomTest();
   1.846 +
   1.847 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4169 CSqlSrvDatabase::CreateSecureL() OOM unit test"));
   1.848 +    Utf16CreateSecureDatabaseOomTest();
   1.849 +
   1.850 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4170 CSqlSrvDatabase::OpenL() OOM unit test - secure database"));
   1.851 +    Utf16OpenSecureDatabaseOomTest();
   1.852 +    
   1.853 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4171 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test"));
   1.854 +    Utf16OpenAttachDatabaseOomTest();
   1.855 +
   1.856 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4172 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test - 2"));
   1.857 +    Utf16OpenAttachDatabaseOomTest2();
   1.858 +
   1.859 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4173 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateL() OOM unit test"));
   1.860 +    Utf16OpenCreateDatabaseOomTest();
   1.861 +
   1.862 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4182 CSqlSrvDatabase::CreateL() OOM unit test, UTF8 database"));
   1.863 +    Utf8CreateDatabaseOomTest();
   1.864 +
   1.865 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4183 CSqlSrvDatabase::OpenL() OOM unit test - non-secure UTF8 database"));
   1.866 +    Utf8OpenDatabaseOomTest();
   1.867 +
   1.868 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4184 CSqlSrvDatabase::CreateSecureL() OOM unit test, UTF8 database"));
   1.869 +    Utf8CreateSecureDatabaseOomTest();
   1.870 +
   1.871 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4185 CSqlSrvDatabase::OpenL() OOM unit test - secure UTF8 database"));
   1.872 +    Utf8OpenSecureDatabaseOomTest();
   1.873 +
   1.874 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4186 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test, UTF8 database"));
   1.875 +    Utf8OpenAttachDatabaseOomTest();
   1.876 +
   1.877 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4187 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::AttachDbL() OOM unit test 2, UTF8 database"));
   1.878 +    Utf8OpenAttachDatabaseOomTest2();
   1.879 +
   1.880 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4188 CSqlSrvDatabase::OpenL() & CSqlSrvDatabase::CreateL() OOM unit test, UTF8 database"));
   1.881 +    Utf8OpenCreateDatabaseOomTest();
   1.882 +    
   1.883 +    delete scheduler;
   1.884 +#endif //_DEBUG    
   1.885 +	}
   1.886 +
   1.887 +TInt E32Main()
   1.888 +	{
   1.889 +	TheTest.Title();
   1.890 +	
   1.891 +	CTrapCleanup* tc = CTrapCleanup::New();
   1.892 +	TheTest(tc != NULL);
   1.893 +	
   1.894 +	__UHEAP_MARK;
   1.895 +	
   1.896 +	CreateTestEnv();
   1.897 +	DoTests();
   1.898 +	DestroyTestEnv();
   1.899 +
   1.900 +	__UHEAP_MARKEND;
   1.901 +	
   1.902 +	TheTest.End();
   1.903 +	TheTest.Close();
   1.904 +	
   1.905 +	delete tc;
   1.906 +
   1.907 +	User::Heap().Check();
   1.908 +	return KErrNone;
   1.909 +	}