os/persistentdata/persistentstorage/sql/TEST/t_sqloom6.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_sqloom6.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,733 @@
     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 <s32buf.h>
    1.21 +#include <bautils.h>
    1.22 +#include <sqldb.h>
    1.23 +#include <stdio.h>
    1.24 +#include <stdlib.h>
    1.25 +#include "SqlResourceTester.h"      //TSqlResourceTester
    1.26 +#include "sqlite3.h"
    1.27 +#include "SqliteSymbian.h"
    1.28 +
    1.29 +//In order to be able to compile the test, the following variables are defined (used inside the OS porting layer, 
    1.30 +//when _SQLPROFILER macro is defined)
    1.31 +#ifdef _SQLPROFILER
    1.32 +TInt TheSqlSrvProfilerFileRead = 0;
    1.33 +TInt TheSqlSrvProfilerFileWrite = 0;
    1.34 +TInt TheSqlSrvProfilerFileSync = 0;
    1.35 +TInt TheSqlSrvProfilerFileSetSize = 0;
    1.36 +#endif
    1.37 +
    1.38 +///////////////////////////////////////////////////////////////////////////////////////
    1.39 +
    1.40 +RTest TheTest(_L("t_sqloom6 test"));
    1.41 +
    1.42 +_LIT(KTestDir, "c:\\test\\");
    1.43 +_LIT(KDbFile, "c:\\test\\t_sqloom6.db");
    1.44 +
    1.45 +static RSqlDatabase TheDb;
    1.46 +static RSqlStatement TheStmt;
    1.47 +
    1.48 +static TInt TheProcessHandleCount = 0;
    1.49 +static TInt TheThreadHandleCount = 0;
    1.50 +static TInt TheAllocatedCellsCount = 0;
    1.51 +
    1.52 +///////////////////////////////////////////////////////////////////////////////////////
    1.53 +
    1.54 +void DestroyTestEnv()
    1.55 +	{
    1.56 +	TheStmt.Close();
    1.57 +	TheDb.Close();
    1.58 +    (void)RSqlDatabase::Delete(KDbFile);
    1.59 +    sqlite3SymbianLibFinalize();
    1.60 +    CloseSTDLIB();
    1.61 +	}
    1.62 +
    1.63 +///////////////////////////////////////////////////////////////////////////////////////
    1.64 +///////////////////////////////////////////////////////////////////////////////////////
    1.65 +//Test macros and functions
    1.66 +void Check(TInt aValue, TInt aLine)
    1.67 +	{
    1.68 +	if(!aValue)
    1.69 +		{
    1.70 +		DestroyTestEnv();
    1.71 +		RDebug::Print(_L("*** Expresssion evaluated to false\r\n"));
    1.72 +		TheTest(EFalse, aLine);
    1.73 +		}
    1.74 +	}
    1.75 +void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.76 +	{
    1.77 +	if(aValue != aExpected)
    1.78 +		{
    1.79 +		DestroyTestEnv();
    1.80 +		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.81 +		TheTest(EFalse, aLine);
    1.82 +		}
    1.83 +	}
    1.84 +#define TEST(arg) ::Check((arg), __LINE__)
    1.85 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    1.86 +
    1.87 +////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1.88 +
    1.89 +static void MarkHandles()
    1.90 +    {
    1.91 +    RThread().HandleCount(TheProcessHandleCount, TheThreadHandleCount);
    1.92 +    }
    1.93 +
    1.94 +static void MarkAllocatedCells()
    1.95 +    {
    1.96 +    TheAllocatedCellsCount = User::CountAllocCells();
    1.97 +    }
    1.98 +
    1.99 +static void CheckAllocatedCells()
   1.100 +    {
   1.101 +    TInt allocatedCellsCount = User::CountAllocCells();
   1.102 +    TEST2(allocatedCellsCount, TheAllocatedCellsCount);
   1.103 +    }
   1.104 +
   1.105 +static void CheckHandles()
   1.106 +    {
   1.107 +    TInt endProcessHandleCount;
   1.108 +    TInt endThreadHandleCount;
   1.109 +    
   1.110 +    RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   1.111 +
   1.112 +    TEST2(TheProcessHandleCount, endProcessHandleCount);
   1.113 +    TEST2(TheThreadHandleCount, endThreadHandleCount);
   1.114 +    }
   1.115 +
   1.116 +static void OomPreStep(TInt aFailingAllocationNo)
   1.117 +    {
   1.118 +    MarkHandles();
   1.119 +    MarkAllocatedCells();
   1.120 +    __UHEAP_MARK;
   1.121 +    TSqlResourceTester::Mark();
   1.122 +    TSqlResourceTester::SetHeapFailure(RHeap::EBurstFailNext, aFailingAllocationNo);
   1.123 +    }
   1.124 +
   1.125 +static void OomPostStep()
   1.126 +    {
   1.127 +    __UHEAP_RESET;
   1.128 +    TSqlResourceTester::SetHeapFailure(RHeap::ENone, 0);
   1.129 +    TSqlResourceTester::Check();
   1.130 +    CheckAllocatedCells();
   1.131 +    CheckHandles();
   1.132 +    }
   1.133 +
   1.134 +////////////////////////////////////////////////////////////////////////////////////////////////////////////
   1.135 +////////////////////////////////////////////////////////////////////////////////////////////////////////////
   1.136 +
   1.137 +void CreateTestEnv()
   1.138 +    {
   1.139 +    RFs fs;
   1.140 +    TInt err = fs.Connect();
   1.141 +    TEST2(err, KErrNone);
   1.142 +
   1.143 +    err = fs.MkDir(KTestDir);
   1.144 +    TEST(err == KErrNone || err == KErrAlreadyExists);
   1.145 +
   1.146 +    err = fs.CreatePrivatePath(EDriveC);
   1.147 +    TEST(err == KErrNone || err == KErrAlreadyExists);
   1.148 +    
   1.149 +    fs.Close();
   1.150 +
   1.151 +    sqlite3SymbianLibInit();
   1.152 +    }
   1.153 +
   1.154 +//Creates a UTF8 encoded database with:
   1.155 +// - One table with three colums: A(ColumnName1234567890, Col2, Col3);
   1.156 +// - One record in the table with values: ('A1234567890', 'A12345', '');
   1.157 +void CreateTestDb(const TDesC& aDbName)
   1.158 +    {
   1.159 +    TBuf8<100> dbName8;
   1.160 +    dbName8.Copy(aDbName);
   1.161 +    sqlite3* db = 0;
   1.162 +    int rc = sqlite3_open((const char*)dbName8.PtrZ(), &db);
   1.163 +    TEST2(rc, SQLITE_OK);
   1.164 +    rc = sqlite3_exec(db, "CREATE TABLE A(ColumnName1234567890 TEXT, Col2 LONG TEXT, Col3 SMALL TEXT)", 0, 0, 0);
   1.165 +    TEST2(rc, SQLITE_OK);
   1.166 +    rc = sqlite3_exec(db, "INSERT INTO A VALUES('A1234567890', 'A12345', '')", 0, 0, 0);
   1.167 +    TEST2(rc, SQLITE_OK);
   1.168 +    sqlite3_close(db);
   1.169 +    }
   1.170 +
   1.171 +/**
   1.172 +@SYMTestCaseID          PDS-SQL-CT-4176
   1.173 +@SYMTestCaseDesc        RSqlStatement::ColumnName() OOM test.
   1.174 +@SYMTestPriority        High
   1.175 +@SYMTestActions         The test runs RSqlStatement::ColumnName() in an OOM simulation loop.
   1.176 +                        The difference betwee this test case and the similar test case in t_sqloom2 is that here:
   1.177 +                         - burst OOM simulation is used;
   1.178 +                         - UTF8 encoded database is used;
   1.179 +                         - only SQL server side OOM simulation is performed;
   1.180 +                         The purpose of the test is to verify that the ColumnName() call behaves correctly 
   1.181 +                         when the related sqlite3_column_name16() call performed by the SQL server fails 
   1.182 +                         with "no memory".
   1.183 +@SYMTestExpectedResults Test must not fail
   1.184 +@SYMDEF                 DEF145033
   1.185 +*/  
   1.186 +void ColumnNameOomTest()
   1.187 +    {
   1.188 +    //This is not really a full OOM test, because the SQL server counts only the number of active statement and 
   1.189 +    //stream objects, the allocated memory cells are not counted.
   1.190 +    //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is
   1.191 +    //because the SQL server can make some per-connection memory allocations (cache pages, etc.)
   1.192 +    //and they will not be deallocated when the statement object is closed. 
   1.193 +    //But the result of the RSqlStatement::ColumnName() operation is checked. If there is a failed memory
   1.194 +    //allocation on the server side, the returned column name can be NULL and that will be tested.
   1.195 +    
   1.196 +    (void)RSqlDatabase::Delete(KDbFile);
   1.197 +    
   1.198 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.199 +
   1.200 +    CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record.
   1.201 +    
   1.202 +    TInt err = TheDb.Open(KDbFile);
   1.203 +    TEST2(err, KErrNone);
   1.204 +    
   1.205 +    TInt failingAllocationNo = 0;
   1.206 +    err = KErrNoMemory;
   1.207 +    while(err == KErrNoMemory)
   1.208 +        {
   1.209 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.210 +        OomPreStep(failingAllocationNo);
   1.211 +        
   1.212 +        err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A"));
   1.213 +        if(err != KErrNone)
   1.214 +            {
   1.215 +            goto LabelOomPostStep;
   1.216 +            }
   1.217 +        
   1.218 +        TPtrC name;
   1.219 +        err = TheStmt.ColumnName(0, name);
   1.220 +        if(err != KErrNone)
   1.221 +            {
   1.222 +            goto LabelStmtClose;
   1.223 +            }
   1.224 +        TEST(name == _L("ColumnName1234567890"));
   1.225 +        
   1.226 +        err = TheStmt.ColumnName(1, name);
   1.227 +        if(err != KErrNone)
   1.228 +            {
   1.229 +            goto LabelStmtClose;
   1.230 +            }
   1.231 +        TEST(name == _L("Col2"));
   1.232 +        
   1.233 +        err = TheStmt.ColumnName(2, name);
   1.234 +        if(err != KErrNone)
   1.235 +            {
   1.236 +            goto LabelStmtClose;
   1.237 +            }
   1.238 +        TEST(name == _L("Col3"));
   1.239 +        
   1.240 +LabelStmtClose:        
   1.241 +        TheStmt.Close();
   1.242 +        
   1.243 +LabelOomPostStep:        
   1.244 +        OomPostStep();
   1.245 +        }
   1.246 +
   1.247 +    TheDb.Close();
   1.248 +    (void)RSqlDatabase::Delete(KDbFile);
   1.249 +    
   1.250 +    TEST2(err, KErrNone);   
   1.251 +    TheTest.Printf(_L("\r\n===RSqlStatement::ColumnName() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.252 +    }
   1.253 +
   1.254 +/**
   1.255 +@SYMTestCaseID          PDS-SQL-CT-4177
   1.256 +@SYMTestCaseDesc        RSqlStatement::ParameterName() OOM test.
   1.257 +@SYMTestPriority        High
   1.258 +@SYMTestActions         The test runs RSqlStatement::ParameterName() in an OOM simulation loop.
   1.259 +                        The difference betwee this test case and the similar test case in t_sqloom2 is that here:
   1.260 +                         - burst OOM simulation is used;
   1.261 +                         - UTF8 encoded database is used;
   1.262 +                         - only SQL server side OOM simulation is performed;
   1.263 +                         The purpose of the test is to verify that the ParameterName() call behaves correctly 
   1.264 +                         if the related sqlite3_bind_parameter_name() call performed by the SQL server fails 
   1.265 +                         with "no memory".
   1.266 +@SYMTestExpectedResults Test must not fail
   1.267 +@SYMDEF                 DEF145033
   1.268 +*/  
   1.269 +void ParameterNameOomTest()
   1.270 +    {
   1.271 +    //This is not really a full OOM test, because the SQL server counts only the number of active statement and 
   1.272 +    //stream objects, the allocated memory cells are not counted.
   1.273 +    //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is
   1.274 +    //because the SQL server can make some per-connection memory allocations (cache pages, etc.)
   1.275 +    //and they will not be deallocated when the statement object is closed. 
   1.276 +    //But the result of the RSqlStatement::ParameterName() operation is checked. If there is a failed memory
   1.277 +    //allocation on the server side, the returned column name can be NULL and that will be tested.
   1.278 +    
   1.279 +    (void)RSqlDatabase::Delete(KDbFile);
   1.280 +    
   1.281 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.282 +
   1.283 +    CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record.
   1.284 +    
   1.285 +    TInt err = TheDb.Open(KDbFile);
   1.286 +    TEST2(err, KErrNone);
   1.287 +    
   1.288 +    TInt failingAllocationNo = 0;
   1.289 +    err = KErrNoMemory;
   1.290 +    while(err == KErrNoMemory)
   1.291 +        {
   1.292 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.293 +        OomPreStep(failingAllocationNo);
   1.294 +        
   1.295 +        err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A WHERE Col2 != :Prm1234567890 AND Col3 != :Prm2 AND ColumnName1234567890 != ?"));
   1.296 +        if(err != KErrNone)
   1.297 +            {
   1.298 +            goto LabelOomPostStep;
   1.299 +            }
   1.300 +        
   1.301 +        TPtrC name;
   1.302 +        err = TheStmt.ParameterName(0, name);
   1.303 +        if(err != KErrNone)
   1.304 +            {
   1.305 +            goto LabelStmtClose;
   1.306 +            }
   1.307 +        TEST(name == _L(":Prm1234567890"));
   1.308 +        
   1.309 +        err = TheStmt.ParameterName(1, name);
   1.310 +        if(err != KErrNone)
   1.311 +            {
   1.312 +            goto LabelStmtClose;
   1.313 +            }
   1.314 +        TEST(name == _L(":Prm2"));
   1.315 +        
   1.316 +        err = TheStmt.ParameterName(2, name);
   1.317 +        if(err != KErrNone)
   1.318 +            {
   1.319 +            goto LabelStmtClose;
   1.320 +            }
   1.321 +        TEST(name == _L("?2"));
   1.322 +        
   1.323 +LabelStmtClose:        
   1.324 +        TheStmt.Close();
   1.325 +        
   1.326 +LabelOomPostStep:        
   1.327 +        OomPostStep();
   1.328 +        }
   1.329 +
   1.330 +    TheDb.Close();
   1.331 +    (void)RSqlDatabase::Delete(KDbFile);
   1.332 +    
   1.333 +    TEST2(err, KErrNone);   
   1.334 +    TheTest.Printf(_L("\r\n===RSqlStatement::ColumnName() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.335 +    }
   1.336 +
   1.337 +/**
   1.338 +@SYMTestCaseID          PDS-SQL-CT-4178
   1.339 +@SYMTestCaseDesc        RSqlStatement::ColumnText() OOM test.
   1.340 +@SYMTestPriority        High
   1.341 +@SYMTestActions         The test runs RSqlStatement::ColumnText() in an OOM simulation loop.
   1.342 +                        The difference betwee this test case and the similar test case in t_sqloom2 is that here:
   1.343 +                         - burst OOM simulation is used;
   1.344 +                         - UTF8 encoded database is used;
   1.345 +                         - only SQL server side OOM simulation is performed;
   1.346 +                         The purpose of the test is to verify that the ColumnText() call behaves correctly 
   1.347 +                         when the related sqlite3_column_text16() call performed by the SQL server fails 
   1.348 +                         with "no memory" (or the sqlite3_column_bytes16() call).
   1.349 +@SYMTestExpectedResults Test must not fail
   1.350 +@SYMDEF                 DEF145033
   1.351 +*/  
   1.352 +void ColumnTextOomTest()
   1.353 +    {
   1.354 +    //This is not really a full OOM test, because the SQL server counts only the number of active statement and 
   1.355 +    //stream objects, the allocated memory cells are not counted.
   1.356 +    //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is
   1.357 +    //because the SQL server can make some per-connection memory allocations (cache pages, etc.)
   1.358 +    //and they will not be deallocated when the statement object is closed. 
   1.359 +    //But the result of the RSqlStatement::ColumnText() operation is checked. If there is a failed memory
   1.360 +    //allocation on the server side, the returned column name can be NULL and that will be tested.
   1.361 +    
   1.362 +    (void)RSqlDatabase::Delete(KDbFile);
   1.363 +    
   1.364 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.365 +
   1.366 +    CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record.
   1.367 +    
   1.368 +    TInt err = TheDb.Open(KDbFile);
   1.369 +    TEST2(err, KErrNone);
   1.370 +    
   1.371 +    TInt failingAllocationNo = 0;
   1.372 +    err = KErrNoMemory;
   1.373 +    while(err == KErrNoMemory)
   1.374 +        {
   1.375 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.376 +        OomPreStep(failingAllocationNo);
   1.377 +        
   1.378 +        err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A"));
   1.379 +        if(err != KErrNone)
   1.380 +            {
   1.381 +            goto LabelOomPostStep;
   1.382 +            }
   1.383 +        err = TheStmt.Next();
   1.384 +        if(err != KSqlAtRow)
   1.385 +            {
   1.386 +            goto LabelStmtClose;
   1.387 +            }
   1.388 +        
   1.389 +        TPtrC data;
   1.390 +        err = TheStmt.ColumnText(0, data);
   1.391 +        if(err != KErrNone)
   1.392 +            {
   1.393 +            goto LabelStmtClose;
   1.394 +            }
   1.395 +        TEST(data == _L("A1234567890"));
   1.396 +        
   1.397 +        err = TheStmt.ColumnText(1, data);
   1.398 +        if(err != KErrNone)
   1.399 +            {
   1.400 +            goto LabelStmtClose;
   1.401 +            }
   1.402 +        TEST(data == _L("A12345"));
   1.403 +
   1.404 +        err = TheStmt.ColumnText(2, data);
   1.405 +        if(err != KErrNone)
   1.406 +            {
   1.407 +            goto LabelStmtClose;
   1.408 +            }
   1.409 +        TEST(data == _L(""));
   1.410 +
   1.411 +LabelStmtClose:        
   1.412 +        TheStmt.Close();
   1.413 +                    
   1.414 +LabelOomPostStep:        
   1.415 +        OomPostStep();
   1.416 +        }
   1.417 +
   1.418 +    TheDb.Close();
   1.419 +    (void)RSqlDatabase::Delete(KDbFile);
   1.420 +    
   1.421 +    TEST2(err, KErrNone);   
   1.422 +    TheTest.Printf(_L("\r\n===RSqlStatement::ColumnText() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.423 +    }
   1.424 +
   1.425 +/**
   1.426 +@SYMTestCaseID          PDS-SQL-CT-4179
   1.427 +@SYMTestCaseDesc        RSqlColumnReadStream OOM test.
   1.428 +@SYMTestPriority        High
   1.429 +@SYMTestActions         The test runs RSqlColumnReadStream in an OOM simulation loop.
   1.430 +                        The difference betwee this test case and the similar test case in t_sqloom2 is that here:
   1.431 +                         - burst OOM simulation is used;
   1.432 +                         - UTF8 encoded database is used;
   1.433 +                         - only SQL server side OOM simulation is performed;
   1.434 +                         The purpose of the test is to verify that the RSqlColumnReadStream APIs behave correctly 
   1.435 +                         when the related sqlite3_column_text16() call performed by the SQL server fails 
   1.436 +                         with "no memory" (or the sqlite3_column_bytes16() call).
   1.437 +@SYMTestExpectedResults Test must not fail
   1.438 +@SYMDEF                 DEF145033
   1.439 +*/  
   1.440 +void TextColumnReadStreamOomTest()
   1.441 +    {
   1.442 +    //This is not really a full OOM test, because the SQL server counts only the number of active statement and 
   1.443 +    //stream objects, the allocated memory cells are not counted.
   1.444 +    //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is
   1.445 +    //because the SQL server can make some per-connection memory allocations (cache pages, etc.)
   1.446 +    //and they will not be deallocated when the statement object is closed. 
   1.447 +    //But the result of the RSqlColumnReadStream::ReadL() operation is checked. If there is a failed memory
   1.448 +    //allocation on the server side, the returned column name can be NULL and that will be tested.
   1.449 +    
   1.450 +    (void)RSqlDatabase::Delete(KDbFile);
   1.451 +    
   1.452 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.453 +
   1.454 +    CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record.
   1.455 +    
   1.456 +    TInt err = TheDb.Open(KDbFile);
   1.457 +    TEST2(err, KErrNone);
   1.458 +    
   1.459 +    TInt failingAllocationNo = 0;
   1.460 +    err = KErrNoMemory;
   1.461 +    while(err == KErrNoMemory)
   1.462 +        {
   1.463 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.464 +        OomPreStep(failingAllocationNo);
   1.465 +        
   1.466 +        err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A"));
   1.467 +        if(err != KErrNone)
   1.468 +            {
   1.469 +            goto LabelOomPostStep;
   1.470 +            }
   1.471 +        err = TheStmt.Next();
   1.472 +        if(err != KSqlAtRow)
   1.473 +            {
   1.474 +            goto LabelCloseStmt;
   1.475 +            }
   1.476 +        
   1.477 +        RSqlColumnReadStream strm;
   1.478 +        err = strm.ColumnText(TheStmt, 0);
   1.479 +        if(err != KErrNone)
   1.480 +            {
   1.481 +            goto LabelCloseStmt;
   1.482 +            }
   1.483 +        TBuf<50> data;
   1.484 +        TRAP(err, strm.ReadL(data, 11));
   1.485 +        strm.Close();
   1.486 +        if(err != KErrNone)
   1.487 +            {
   1.488 +            goto LabelCloseStmt;
   1.489 +            }
   1.490 +        TEST(data == _L("A1234567890"));
   1.491 +
   1.492 +        err = strm.ColumnText(TheStmt, 1);
   1.493 +        if(err != KErrNone)
   1.494 +            {
   1.495 +            goto LabelCloseStmt;
   1.496 +            }
   1.497 +        TRAP(err, strm.ReadL(data, 6));
   1.498 +        strm.Close();
   1.499 +        if(err != KErrNone)
   1.500 +            {
   1.501 +            goto LabelCloseStmt;
   1.502 +            }
   1.503 +        TEST(data == _L("A12345"));
   1.504 +
   1.505 +        err = strm.ColumnText(TheStmt, 2);
   1.506 +        if(err != KErrNone)
   1.507 +            {
   1.508 +            goto LabelCloseStmt;
   1.509 +            }
   1.510 +        TInt len = -1;
   1.511 +        TRAP(err, len = strm.Source()->SizeL());//The column value is with 0 length
   1.512 +        strm.Close();
   1.513 +        if(err != KErrNone)
   1.514 +            {
   1.515 +            goto LabelCloseStmt;
   1.516 +            }
   1.517 +        TEST2(len, 0);
   1.518 +
   1.519 +LabelCloseStmt:            
   1.520 +        TheStmt.Close();
   1.521 +        
   1.522 +LabelOomPostStep:        
   1.523 +        OomPostStep();
   1.524 +        }
   1.525 +
   1.526 +    TheDb.Close();
   1.527 +    (void)RSqlDatabase::Delete(KDbFile);
   1.528 +    
   1.529 +    TEST2(err, KErrNone);   
   1.530 +    TheTest.Printf(_L("\r\n===RSqlColumnReadStream OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.531 +    }
   1.532 +
   1.533 +/**
   1.534 +@SYMTestCaseID          PDS-SQL-CT-4180
   1.535 +@SYMTestCaseDesc        TSqlScalarFullSelectQuery::SelectTextL() OOM test.
   1.536 +@SYMTestPriority        High
   1.537 +@SYMTestActions         The test runs TSqlScalarFullSelectQuery::SelectTextL() in an OOM simulation loop.
   1.538 +                        The difference betwee this test case and the similar test case in t_sqloom2 is that here:
   1.539 +                         - burst OOM simulation is used;
   1.540 +                         - UTF8 encoded database is used;
   1.541 +                         - only SQL server side OOM simulation is performed;
   1.542 +                         The purpose of the test is to verify that the SelectTextL() call behaves correctly 
   1.543 +                         when the related sqlite3_column_text16() call performed by the SQL server fails 
   1.544 +                         with "no memory" (or the sqlite3_column_bytes16() call).
   1.545 +@SYMTestExpectedResults Test must not fail
   1.546 +@SYMDEF                 DEF145033
   1.547 +*/  
   1.548 +void ScalarColumnTextOomTest()
   1.549 +    {
   1.550 +    //This is not really a full OOM test, because the SQL server counts only the number of active statement and 
   1.551 +    //stream objects, the allocated memory cells are not counted.
   1.552 +    //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is
   1.553 +    //because the SQL server can make some per-connection memory allocations (cache pages, etc.)
   1.554 +    //and they will not be deallocated when the statement object is closed. 
   1.555 +    //But the result of the TSqlScalarFullSelectQuery::SelectTextL() operation is checked. If there is a failed memory
   1.556 +    //allocation on the server side, the returned column name can be NULL and that will be tested.
   1.557 +    
   1.558 +    (void)RSqlDatabase::Delete(KDbFile);
   1.559 +    
   1.560 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.561 +
   1.562 +    CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record.
   1.563 +    
   1.564 +    TInt err = TheDb.Open(KDbFile);
   1.565 +    TEST2(err, KErrNone);
   1.566 +    
   1.567 +    TInt failingAllocationNo = 0;
   1.568 +    err = KErrNoMemory;
   1.569 +    while(err == KErrNoMemory)
   1.570 +        {
   1.571 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.572 +        OomPreStep(failingAllocationNo);
   1.573 +        
   1.574 +        TSqlScalarFullSelectQuery query(TheDb);
   1.575 +        TBuf<50> data;
   1.576 +        TRAP(err, query.SelectTextL(_L("SELECT ColumnName1234567890 FROM A"), data));
   1.577 +        if(err != KErrNone)
   1.578 +            {
   1.579 +            goto LabelOomPostStep; 
   1.580 +            }
   1.581 +        TEST(data == _L("A1234567890"));
   1.582 +
   1.583 +        TRAP(err, query.SelectTextL(_L("SELECT Col2 FROM A"), data));
   1.584 +        if(err != KErrNone)
   1.585 +            {
   1.586 +            goto LabelOomPostStep; 
   1.587 +            }
   1.588 +        TEST(data == _L("A12345"));
   1.589 +        
   1.590 +        TRAP(err, query.SelectTextL(_L("SELECT Col3 FROM A"), data));
   1.591 +        if(err != KErrNone)
   1.592 +            {
   1.593 +            goto LabelOomPostStep; 
   1.594 +            }
   1.595 +        TEST(data == _L(""));
   1.596 +        
   1.597 +LabelOomPostStep:        
   1.598 +        OomPostStep();
   1.599 +        }
   1.600 +
   1.601 +    TheDb.Close();
   1.602 +    (void)RSqlDatabase::Delete(KDbFile);
   1.603 +    
   1.604 +    TEST2(err, KErrNone);   
   1.605 +    TheTest.Printf(_L("\r\n===TSqlScalarFullSelectQuery::SelectTextL() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.606 +    }
   1.607 +
   1.608 +/**
   1.609 +@SYMTestCaseID          PDS-SQL-CT-4181
   1.610 +@SYMTestCaseDesc        RSqlStatement::DeclaredColumnType() OOM test.
   1.611 +@SYMTestPriority        High
   1.612 +@SYMTestActions         The test runs RSqlStatement::DeclaredColumnType() in an OOM simulation loop.
   1.613 +                        The difference betwee this test case and the similar test case in t_sqloom2 is that here:
   1.614 +                         - burst OOM simulation is used;
   1.615 +                         - UTF8 encoded database is used;
   1.616 +                         - only SQL server side OOM simulation is performed;
   1.617 +                         The purpose of the test is to verify that the DeclaredColumnType() call behaves correctly 
   1.618 +                         when the related sqlite3_column_name16() call performed by the SQL server fails 
   1.619 +                         with "no memory".
   1.620 +@SYMTestExpectedResults Test must not fail
   1.621 +@SYMDEF                 DEF145033
   1.622 +*/  
   1.623 +void DeclaredColumnTypeOomTest()
   1.624 +    {
   1.625 +    //This is not really a full OOM test, because the SQL server counts only the number of active statement and 
   1.626 +    //stream objects, the allocated memory cells are not counted.
   1.627 +    //The reason that the allocated memory cells are not counted, and in case of an OOM failure - checked, is
   1.628 +    //because the SQL server can make some per-connection memory allocations (cache pages, etc.)
   1.629 +    //and they will not be deallocated when the statement object is closed. 
   1.630 +    //But the result of the RSqlStatement::DeclaredColumnType() operation is checked. If there is a failed memory
   1.631 +    //allocation on the server side, the returned column name can be NULL and that will be tested.
   1.632 +    
   1.633 +    (void)RSqlDatabase::Delete(KDbFile);
   1.634 +    
   1.635 +    TheTest.Printf(_L("Iteration:\r\n"));
   1.636 +
   1.637 +    CreateTestDb(KDbFile);//Creates UTF8 encoded database with one table with one record.
   1.638 +    
   1.639 +    TInt err = TheDb.Open(KDbFile);
   1.640 +    TEST2(err, KErrNone);
   1.641 +    
   1.642 +    TInt failingAllocationNo = 0;
   1.643 +    err = KErrNoMemory;
   1.644 +    while(err == KErrNoMemory)
   1.645 +        {
   1.646 +        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
   1.647 +        OomPreStep(failingAllocationNo);
   1.648 +        
   1.649 +        err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A"));
   1.650 +        if(err != KErrNone)
   1.651 +            {
   1.652 +            goto LabelOomPostStep;
   1.653 +            }
   1.654 +        
   1.655 +        TSqlColumnType colType = ESqlNull;
   1.656 +        err = TheStmt.DeclaredColumnType(0, colType);
   1.657 +        if(err != KErrNone)
   1.658 +            {
   1.659 +            goto LabelStmtClose;
   1.660 +            }
   1.661 +        TEST2(colType, ESqlText);
   1.662 +        
   1.663 +        colType = ESqlNull;
   1.664 +        err = TheStmt.DeclaredColumnType(1, colType);
   1.665 +        if(err != KErrNone)
   1.666 +            {
   1.667 +            goto LabelStmtClose;
   1.668 +            }
   1.669 +        TEST2(colType, ESqlText);
   1.670 +        
   1.671 +        colType = ESqlNull;
   1.672 +        err = TheStmt.DeclaredColumnType(2, colType);
   1.673 +        if(err != KErrNone)
   1.674 +            {
   1.675 +            goto LabelStmtClose;
   1.676 +            }
   1.677 +        TEST2(colType, ESqlText);
   1.678 +        
   1.679 +LabelStmtClose:        
   1.680 +        TheStmt.Close();
   1.681 +        
   1.682 +LabelOomPostStep:        
   1.683 +        OomPostStep();
   1.684 +        }
   1.685 +
   1.686 +    TheDb.Close();
   1.687 +    (void)RSqlDatabase::Delete(KDbFile);
   1.688 +    
   1.689 +    TEST2(err, KErrNone);   
   1.690 +    TheTest.Printf(_L("\r\n===RSqlStatement::DeclaredColumnType() OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
   1.691 +    }
   1.692 +
   1.693 +void DoTests()
   1.694 +	{
   1.695 +    TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-CT-4176 RSqlStatement::ColumnName() OOM test"));
   1.696 +    ColumnNameOomTest();
   1.697 +
   1.698 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4177 RSqlStatement::ParameterName() OOM test"));
   1.699 +    ParameterNameOomTest();
   1.700 +    
   1.701 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4178 RSqlStatement::ColumnText() OOM test"));
   1.702 +    ColumnTextOomTest();
   1.703 +    
   1.704 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4179 RSqlColumnReadStream OOM test"));
   1.705 +    TextColumnReadStreamOomTest();
   1.706 +    
   1.707 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4180 TSqlScalarFullSelectQuery::SelectTextL() OOM test"));
   1.708 +    ScalarColumnTextOomTest();
   1.709 +
   1.710 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4181 RSqlStatement::DeclaredColumnType() OOM test"));
   1.711 +    DeclaredColumnTypeOomTest();
   1.712 +	}
   1.713 +
   1.714 +TInt E32Main()
   1.715 +	{
   1.716 +	TheTest.Title();
   1.717 +	
   1.718 +	CTrapCleanup* tc = CTrapCleanup::New();
   1.719 +	TheTest(tc != NULL);
   1.720 +	
   1.721 +	__UHEAP_MARK;
   1.722 +	
   1.723 +	CreateTestEnv();
   1.724 +	DoTests();
   1.725 +	DestroyTestEnv();
   1.726 +
   1.727 +	__UHEAP_MARKEND;
   1.728 +	
   1.729 +	TheTest.End();
   1.730 +	TheTest.Close();
   1.731 +	
   1.732 +	delete tc;
   1.733 +
   1.734 +	User::Heap().Check();
   1.735 +	return KErrNone;
   1.736 +	}