persistentstorage/sql/TEST/t_sqloom2.cpp
changeset 0 08ec8eefde2f
child 13 211563e4b919
child 17 55f2396f6d25
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "t_sqloom.h"
       
    17 
       
    18 RTest TheTest(_L("t_sqloom2 test"));
       
    19 
       
    20 const TInt KSqlBufMaxLen = 16 * 1024;
       
    21 const TInt KBlobStrLen = KSqlBufMaxLen / 2 - 100;
       
    22 const TInt KBlobLen = KBlobStrLen;
       
    23 
       
    24 TBuf8<KSqlBufMaxLen> TheSqlBuf;
       
    25 TBuf8<KBlobStrLen> TheSqlBuf2;
       
    26 
       
    27 ///////////////////////////////////////////////////////////////////////////////////////
       
    28 ///////////////         RSqlStatement OOM tests         ///////////////////////////////
       
    29 ///////////////////////////////////////////////////////////////////////////////////////
       
    30 
       
    31 _LIT8(KSqlDbString, "BEGIN;\
       
    32 					 CREATE TABLE BBB(Fld1 INTEGER, Fld2 BIGINT, Fld3 DOUBLE, Fld4 TEXT, Fld5 LONGBLOB);\
       
    33                      INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(4562, 123456789012345, 78612.0091, 'text data');\
       
    34                      COMMIT;");
       
    35 _LIT8(KSqlDbString2,"INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(1, 34, 10.9897, 'data2');");
       
    36 
       
    37 const TInt KLongColumnSize = 3013;
       
    38 const TInt KLongParameterSize = 4501;
       
    39 
       
    40 #define MAX(a, b) ((a) > (b) ? (a) : (b))
       
    41 
       
    42 static TUint16 TheTextColumnData[MAX(KLongColumnSize, KLongParameterSize)];
       
    43 static TUint8 TheBinaryColumnData[MAX(KLongColumnSize, KLongParameterSize) * sizeof(TUint16)];
       
    44 
       
    45 //"RSqlStatement::Prepare()" OOM test (8-bit SELECT SQL statement)
       
    46 void PrepareStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
    47 	{
       
    48 	_LIT8(KSqlString, "SELECT * FROM BBB");
       
    49 	TInt err = aStmt.Prepare(aDb, KSqlString);
       
    50 	User::LeaveIfError(err);
       
    51 	}
       
    52 
       
    53 //"RSqlStatement::PrepareL()" OOM test (8-bit SELECT SQL statement)
       
    54 void PrepareStmt8_2L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
    55 	{
       
    56 	_LIT8(KSqlString, "SELECT * FROM BBB");
       
    57 	aStmt.PrepareL(aDb, KSqlString);
       
    58 	}
       
    59 
       
    60 //"RSqlStatement::Prepare()" OOM test (8-bit SELECT SQL statement), syntax error
       
    61 void PrepareBadStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
    62 	{
       
    63 	_LIT8(KSqlString, "SELECT123 * FROM BBB");
       
    64 	TInt err = aStmt.Prepare(aDb, KSqlString);
       
    65 	User::LeaveIfError(err);
       
    66 	}
       
    67 
       
    68 //"RSqlStatement::Prepare()" OOM test (8-bit SELECT SQL statement, move next)
       
    69 void PrepareMoveStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
    70 	{
       
    71 	_LIT8(KSqlString, "SELECT * FROM BBB");
       
    72 	TInt err = aStmt.Prepare(aDb, KSqlString);
       
    73 	if(err == KErrNone)
       
    74 		{
       
    75 		err = aStmt.Next();
       
    76 		if(err == KSqlAtRow)
       
    77 			{
       
    78 			err = KErrNone;
       
    79 			}
       
    80 		}
       
    81 	User::LeaveIfError(err);
       
    82 	}
       
    83 
       
    84 //"RSqlStatement::Prepare()" OOM test (8-bit INSERT SQL statement)
       
    85 void PrepareInsertStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
    86 	{
       
    87 	_LIT8(KSqlString, "INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(2, 22, 22.2222, '2-2-2-2');");
       
    88 	TInt err = aStmt.Prepare(aDb, KSqlString);
       
    89 	User::LeaveIfError(err);
       
    90 	}
       
    91 
       
    92 //"RSqlStatement::Prepare(), RSqlStatement::Exec(), RSqlStatement::Next()" OOM test (8-bit INSERT SQL statement, long column)
       
    93 void ExecInsertNextStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
    94 	{
       
    95 	_LIT8(KSqlString1, "INSERT INTO BBB(fld1, fld2, fld3, fld4, fld5) VALUES(10, 100, 100.001, :Prm1, :Prm2);");
       
    96 	_LIT8(KSqlString2, "SELECT * FROM BBB WHERE fld1 = 10");
       
    97 	TInt err = aStmt.Prepare(aDb, KSqlString1);
       
    98 	if(err == KErrNone)
       
    99 		{
       
   100 		for(TInt i=0;i<KLongColumnSize;++i)
       
   101 			{
       
   102 			TheTextColumnData[i] = (TUint16)i;
       
   103 			}
       
   104 		const TPtrC textVal(TheTextColumnData, KLongColumnSize);
       
   105 		const TPtrC8 binVal((TUint8*)TheTextColumnData, KLongColumnSize * sizeof(TUint16));
       
   106 		TInt err = aStmt.BindText(0, textVal);
       
   107 		if(err == KErrNone)
       
   108 			{
       
   109 			err = aStmt.BindBinary(1, binVal);
       
   110 			}
       
   111 		if(err == KErrNone)
       
   112 			{
       
   113 			err = aStmt.Exec();
       
   114 			}
       
   115 		}
       
   116 	if(err >= 0)
       
   117 		{
       
   118 		aStmt.Close();
       
   119 		err = aStmt.Prepare(aDb, KSqlString2);
       
   120 		if(err == KErrNone)
       
   121 			{
       
   122 			err = aStmt.Next();
       
   123 			}
       
   124 		}
       
   125 	User::LeaveIfError(err);
       
   126 	}
       
   127 
       
   128 //"RSqlStatement::Prepare()" OOM test (8-bit INSERT SQL statement with parameters)
       
   129 void PrepareInsertPrmStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
   130 	{
       
   131 	_LIT8(KSqlString, "INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(:Prm0, :Prm1, :Prm2, :Prm3);");
       
   132 	TInt err = aStmt.Prepare(aDb, KSqlString);
       
   133 	User::LeaveIfError(err);
       
   134 	}
       
   135 
       
   136 //"RSqlStatement::Prepare()" OOM test (16-bit SELECT SQL statement)
       
   137 void PrepareStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
   138 	{
       
   139 	_LIT(KSqlString, "SELECT * FROM BBB");
       
   140 	TInt err = aStmt.Prepare(aDb, KSqlString);
       
   141 	User::LeaveIfError(err);
       
   142 	}
       
   143 
       
   144 //"RSqlStatement::PrepareL()" OOM test (16-bit SELECT SQL statement)
       
   145 void PrepareStmt16_2L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
   146 	{
       
   147 	_LIT(KSqlString, "SELECT * FROM BBB");
       
   148 	aStmt.PrepareL(aDb, KSqlString);
       
   149 	}
       
   150 
       
   151 //"RSqlStatement::Prepare()" OOM test (16-bit SELECT SQL statement), syntax error
       
   152 void PrepareBadStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
   153 	{
       
   154 	_LIT(KSqlString, "23478SELECT * FROM BBB");
       
   155 	TInt err = aStmt.Prepare(aDb, KSqlString);
       
   156 	User::LeaveIfError(err);
       
   157 	}
       
   158 
       
   159 //"RSqlStatement::Prepare()" OOM test (16-bit SELECT SQL statement, move next)
       
   160 void PrepareMoveStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
   161 	{
       
   162 	_LIT(KSqlString, "SELECT * FROM BBB");
       
   163 	TInt err = aStmt.Prepare(aDb, KSqlString);
       
   164 	if(err == KErrNone)
       
   165 		{
       
   166 		err = aStmt.Next();
       
   167 		if(err == KSqlAtRow)
       
   168 			{
       
   169 			err = KErrNone;
       
   170 			}
       
   171 		}
       
   172 	User::LeaveIfError(err);
       
   173 	}
       
   174 
       
   175 //"RSqlStatement::Prepare()" OOM test (16-bit INSERT SQL statement)
       
   176 void PrepareInsertStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
   177 	{
       
   178 	_LIT(KSqlString, "INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(2, 22, 22.2222, '2-2-2-2');");
       
   179 	TInt err = aStmt.Prepare(aDb, KSqlString);
       
   180 	User::LeaveIfError(err);
       
   181 	}
       
   182 
       
   183 //"RSqlStatement::Prepare(), RSqlStatement::Exec(), RSqlStatement::Next()" OOM test (16-bit INSERT SQL statement, long column)
       
   184 void ExecInsertNextStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
   185 	{
       
   186 	_LIT(KSqlString1, "INSERT INTO BBB(fld1, fld2, fld3, fld4, fld5) VALUES(10, 100, 100.001, :Prm1, :Prm2);");
       
   187 	_LIT(KSqlString2, "SELECT * FROM BBB WHERE fld1 = 10");
       
   188 	TInt err = aStmt.Prepare(aDb, KSqlString1);
       
   189 	if(err == KErrNone)
       
   190 		{
       
   191 		for(TInt i=0;i<KLongColumnSize;++i)
       
   192 			{
       
   193 			TheTextColumnData[i] = (TUint16)i;
       
   194 			}
       
   195 		const TPtrC textVal(TheTextColumnData, KLongColumnSize);
       
   196 		const TPtrC8 binVal((TUint8*)TheTextColumnData, KLongColumnSize * sizeof(TUint16));
       
   197 		TInt err = aStmt.BindText(0, textVal);
       
   198 		if(err == KErrNone)
       
   199 			{
       
   200 			err = aStmt.BindBinary(1, binVal);
       
   201 			}
       
   202 		if(err == KErrNone)
       
   203 			{
       
   204 			err = aStmt.Exec();
       
   205 			}
       
   206 		}
       
   207 	if(err >= 0)
       
   208 		{
       
   209 		aStmt.Close();
       
   210 		err = aStmt.Prepare(aDb, KSqlString2);
       
   211 		if(err == KErrNone)
       
   212 			{
       
   213 			err = aStmt.Next();
       
   214 			}
       
   215 		}
       
   216 	User::LeaveIfError(err);
       
   217 	}
       
   218 
       
   219 //"RSqlStatement::Prepare()" OOM test (16-bit INSERT SQL statement with parameters)
       
   220 void PrepareInsertPrmStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt)
       
   221 	{
       
   222 	_LIT(KSqlString, "INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(:Prm0, :Prm1, :Prm2, :Prm3);");
       
   223 	TInt err = aStmt.Prepare(aDb, KSqlString);
       
   224 	User::LeaveIfError(err);
       
   225 	}
       
   226 
       
   227 /**
       
   228 @SYMTestCaseID			SYSLIB-SQL-CT-1617
       
   229 @SYMTestCaseDesc		RSqlStatement::Prepare() OOM test
       
   230 						Precondition: the database exists, opened, some record(s) inserted.
       
   231 						The test calls the given as an argument function while simulating OOM failures
       
   232 						and checks that there are no memory and resource leaks.
       
   233 @SYMTestPriority		High
       
   234 @SYMTestActions			RSqlStatement::Prepare() OOM test
       
   235 @SYMTestExpectedResults Test must not fail
       
   236 @SYMREQ					REQ5792
       
   237                         REQ5793
       
   238 */
       
   239 void DoStmtPrepareOomTestL(TStmtFuncPtrL aStmtFuncPtrL, const TDesC& aDbFileName, TDbType aDbType, TInt aExpectedError = KErrNone)
       
   240 	{
       
   241 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1617 RSqlStatement::Prepare() - OOM test"));
       
   242 	RSqlSecurityPolicy securityPolicy;
       
   243 	CreateTestSecurityPolicy(securityPolicy);
       
   244 	for(TInt i=0;i<(TInt)(sizeof(TheOomTestType)/sizeof(TheOomTestType[0]));++i)
       
   245 		{
       
   246 		RSqlDatabase::Delete(aDbFileName);
       
   247 		RSqlDatabase db;
       
   248 		TInt err = aDbType == ESecureDb ? db.Create(aDbFileName, securityPolicy) : db.Create(aDbFileName);
       
   249 		TEST2(err, KErrNone);
       
   250 		err = db.Exec(KSqlDbString);
       
   251 		TEST(err >= 0);
       
   252 		//The next operation is executed to force the SQL server side session to make one memory allocation
       
   253 		//for the statement handle in its RDbObjContainer contrainer data member. Otherwise the OOM test will fail,
       
   254 		//because the server side session will do one additional allocation, which stays alive untill the
       
   255 		//session gets closed.
       
   256 		RSqlStatement dummyStmt;
       
   257 		err = dummyStmt.Prepare(db, _L("SELECT * FROM BBB"));
       
   258 		TEST2(err, KErrNone);
       
   259 		dummyStmt.Close();
       
   260 
       
   261 		err = KErrNoMemory;
       
   262 		const TInt KMaxAllocation = TheOomTestType[i] == EServerSideTest ? KStmtOomTestAllocLimitServer : KStmtOomTestAllocLimitClient;
       
   263 		TInt allocationNo = 0;
       
   264 		TInt failingAllocationNo = 0;
       
   265 		while(allocationNo < KMaxAllocation)
       
   266 			{
       
   267 			MarkHandles();
       
   268 			MarkAllocatedCells();
       
   269 
       
   270 			__UHEAP_MARK;
       
   271 
       
   272 			SetHeapFailure(TheOomTestType[i], ++allocationNo);
       
   273 
       
   274 	    	RSqlStatement stmt;
       
   275 			TRAP(err, (*aStmtFuncPtrL)(db, stmt));
       
   276 			stmt.Close();
       
   277 			if(err != KErrNoMemory)
       
   278 				{
       
   279 				TEST2(err, aExpectedError);
       
   280 				}
       
   281 			else
       
   282 				{
       
   283 				failingAllocationNo = allocationNo;	
       
   284 				}
       
   285 
       
   286 			ResetHeapFailure(TheOomTestType[i]);
       
   287 
       
   288 			__UHEAP_MARKEND;
       
   289 
       
   290 			CheckAllocatedCells();
       
   291 			CheckHandles();
       
   292 			}
       
   293 
       
   294 		db.Close();
       
   295 		TEST2(err, aExpectedError);
       
   296 		PrintEndOfOomTest(TheOomTestType[i], failingAllocationNo);
       
   297 		}
       
   298 	//Delete the database file
       
   299 	RSqlDatabase::Delete(aDbFileName);
       
   300 	securityPolicy.Close();
       
   301 	}
       
   302 
       
   303 //"RSqlStatement::Reset()" OOM test
       
   304 void ResetStmtL(RSqlStatement& aStmt)
       
   305 	{
       
   306 	TInt err = aStmt.Next();
       
   307 	if(err == KErrNone)
       
   308 		{
       
   309 		err = aStmt.Reset();
       
   310 		}
       
   311 	User::LeaveIfError(err);
       
   312 	}
       
   313 
       
   314 //"RSqlStatement::Exec()" OOM test
       
   315 void ExecStmtL(RSqlStatement& aStmt)
       
   316 	{
       
   317 	TInt err = aStmt.Exec();
       
   318 	User::LeaveIfError(err);
       
   319 	}
       
   320 
       
   321 //"RSqlStatement::Next()" OOM test
       
   322 void NextStmtL(RSqlStatement& aStmt)
       
   323 	{
       
   324 	TInt err = aStmt.Next();
       
   325 	if(err == KErrNone)
       
   326 		{
       
   327 		err = aStmt.Next();
       
   328 		}
       
   329 	User::LeaveIfError(err);
       
   330 	}
       
   331 
       
   332 //"RSqlStatement::ParameterIndex()" OOM test
       
   333 void StmtParameterIndexL(RSqlStatement& aStmt)
       
   334 	{
       
   335 	TInt err = aStmt.ParameterIndex(_L(":Prm2"));
       
   336 	if(err == 1) //":Prm2" index is 1
       
   337 		{
       
   338 		err = KErrNone;
       
   339 		}
       
   340 	User::LeaveIfError(err);
       
   341 	}
       
   342 
       
   343 //"RSqlStatement::ParameterName()" OOM test
       
   344 void StmtParameterNameL(RSqlStatement& aStmt)
       
   345 	{
       
   346 	// _LIT(KExcpected, ":Prm2");
       
   347 	TPtrC paramName;
       
   348 	TInt err = aStmt.ParameterName(1, paramName);
       
   349 	User::LeaveIfError(err);
       
   350 	}
       
   351 
       
   352 //"RSqlStatement::ParamName()" OOM test
       
   353 void StmtParamNameL(RSqlStatement& aStmt)
       
   354 	{
       
   355 	TPtrC paramName;
       
   356 	TInt err = aStmt.ParamName(1, paramName);
       
   357 	User::LeaveIfError(err);
       
   358 	}
       
   359 
       
   360 //"RSqlStatement::ColumnIndex()" OOM test
       
   361 void StmtColumnIndexL(RSqlStatement& aStmt)
       
   362 	{
       
   363 	TInt err = aStmt.ColumnIndex(_L("fLd3"));
       
   364 	if(err == 2) //"fLd3" index is 2
       
   365 		{
       
   366 		err = KErrNone;
       
   367 		}
       
   368 	User::LeaveIfError(err);
       
   369 	}
       
   370 
       
   371 //"RSqlStatement::ColumnName()" OOM test
       
   372 void StmtColumnNameL(RSqlStatement& aStmt)
       
   373 	{
       
   374 	//_LIT(KExpected, "fLd3");
       
   375 	TPtrC colName;
       
   376 	TInt err = aStmt.ColumnName(2, colName);
       
   377 	User::LeaveIfError(err);
       
   378 	}
       
   379 
       
   380 
       
   381 //"RSqlStatement::ColumnType()" OOM test
       
   382 void StmtColumnTypeL(RSqlStatement& aStmt)
       
   383 	{
       
   384 	TSqlColumnType coltype = aStmt.ColumnType(2);
       
   385 	TEST(coltype == ESqlReal);
       
   386 	}
       
   387 
       
   388 //"RSqlStatement::ColumnSize()" OOM test
       
   389 void StmtColumnSizeL(RSqlStatement& aStmt)
       
   390 	{
       
   391 	TInt colsize = aStmt.ColumnSize(2);
       
   392 	TEST(colsize == sizeof(TReal));
       
   393 	}
       
   394 
       
   395 //"RSqlStatement::BindNull()" OOM test
       
   396 void StmtBindNullL(RSqlStatement& aStmt)
       
   397 	{
       
   398 	TInt err = aStmt.BindNull(1);
       
   399 	//The bindings will be transferred on the server side right before Next() or Exec() call
       
   400 	if(err == KErrNone)
       
   401 		{
       
   402 		err = aStmt.Exec();
       
   403 		}
       
   404 	User::LeaveIfError(err);
       
   405 	}
       
   406 
       
   407 //"RSqlStatement::BindInt()" OOM test
       
   408 void StmtBindIntL(RSqlStatement& aStmt)
       
   409 	{
       
   410 	TInt val = 184;
       
   411 	TInt err = aStmt.BindInt(0, val);
       
   412 	//The bindings will be transferred on the server side right before Next() or Exec() call
       
   413 	if(err == KErrNone)
       
   414 		{
       
   415 		err = aStmt.Exec();
       
   416 		}
       
   417 	User::LeaveIfError(err);
       
   418 	}
       
   419 
       
   420 //"RSqlStatement::BindInt64()" OOM test
       
   421 void StmtBindInt64L(RSqlStatement& aStmt)
       
   422 	{
       
   423 	TInt64 val = MAKE_TINT64(0x00FF00FF, 0x12345678);
       
   424 	TInt err = aStmt.BindInt64(1, val);
       
   425 	//The bindings will be transferred on the server side right before Next() or Exec() call
       
   426 	if(err == KErrNone)
       
   427 		{
       
   428 		err = aStmt.Exec();
       
   429 		}
       
   430 	User::LeaveIfError(err);
       
   431 	}
       
   432 
       
   433 //"RSqlStatement::BindReal()" OOM test
       
   434 void StmtBindRealL(RSqlStatement& aStmt)
       
   435 	{
       
   436 	TReal val = 25.2423;
       
   437 	TInt err = aStmt.BindReal(2, val);
       
   438 	//The bindings will be transferred on the server side right before Next() or Exec() call
       
   439 	if(err == KErrNone)
       
   440 		{
       
   441 		err = aStmt.Exec();
       
   442 		}
       
   443 	User::LeaveIfError(err);
       
   444 	}
       
   445 
       
   446 //"RSqlStatement::BindText()" OOM test
       
   447 void StmtBindTextL(RSqlStatement& aStmt)
       
   448 	{
       
   449 	for(TInt i=0;i<KLongParameterSize;++i)
       
   450 		{
       
   451 		TheTextColumnData[i] = (TUint16)i;
       
   452 		}
       
   453 	const TPtrC val(TheTextColumnData, KLongParameterSize);
       
   454 	TInt err = aStmt.BindText(3, val);
       
   455 	//The bindings will be transferred on the server side right before a Next() or Exec() call
       
   456 	if(err == KErrNone)
       
   457 		{
       
   458 		err = aStmt.Exec();
       
   459 		}
       
   460 	User::LeaveIfError(err);
       
   461 	}
       
   462 
       
   463 //"RSqlStatement::BindBinary()" OOM test
       
   464 void StmtBindBinaryL(RSqlStatement& aStmt)
       
   465 	{
       
   466 	for(TInt i=0;i<KLongParameterSize;++i)
       
   467 		{
       
   468 		TheBinaryColumnData[i] = (TUint8)i;
       
   469 		}
       
   470 	const TPtrC8 val(TheBinaryColumnData, KLongParameterSize);
       
   471 	TInt err = aStmt.BindBinary(3, val);
       
   472 	//The bindings will be transferred on the server side right before a Next() or Exec() call
       
   473 	if(err == KErrNone)
       
   474 		{
       
   475 		err = aStmt.Exec();
       
   476 		}
       
   477 	User::LeaveIfError(err);
       
   478 	}
       
   479 
       
   480 //"RSqlStatement::BindZeroBlob()" OOM test
       
   481 void StmtBindZeroBlobL(RSqlStatement& aStmt)
       
   482 	{
       
   483 	TInt err = aStmt.BindZeroBlob(3, KLongParameterSize);
       
   484 	//The bindings will be transferred on the server side right before a Next() or Exec() call
       
   485 	if(err == KErrNone)
       
   486 		{
       
   487 		err = aStmt.Exec();
       
   488 		}
       
   489 	User::LeaveIfError(err);
       
   490 	}
       
   491 
       
   492 //"RSqlStatement::IsNull()" OOM test
       
   493 void StmtIsNullColumnL(RSqlStatement& aStmt)
       
   494 	{
       
   495 	TBool rc = aStmt.IsNull(0);
       
   496 	TEST(!rc);
       
   497 	}
       
   498 
       
   499 //"RSqlStatement::ColumnInt()" OOM test
       
   500 void StmtColumnIntL(RSqlStatement& aStmt)
       
   501 	{
       
   502 	TInt val = aStmt.ColumnInt(0);
       
   503 	TEST(val == 10);
       
   504 	}
       
   505 
       
   506 //"RSqlStatement::ColumnInt64()" OOM test
       
   507 void StmtColumnInt64L(RSqlStatement& aStmt)
       
   508 	{
       
   509 	TInt64 val = aStmt.ColumnInt64(1);
       
   510 	TEST(val == 100);
       
   511 	}
       
   512 
       
   513 //"RSqlStatement::ColumnReal()" OOM test
       
   514 void StmtColumnRealL(RSqlStatement& aStmt)
       
   515 	{
       
   516 	TReal val = aStmt.ColumnReal(2);
       
   517 	TEST(Abs(val - 100.001) < 0.000001);
       
   518 	}
       
   519 
       
   520 //"RSqlStatement::ColumnTextL()" OOM test
       
   521 void StmtColumnText1L(RSqlStatement& aStmt)
       
   522 	{
       
   523 	TPtrC val = aStmt.ColumnTextL(3);
       
   524 	TEST(val.Length() == KLongColumnSize);
       
   525 	for(TInt i=0;i<KLongColumnSize;++i)
       
   526 		{
       
   527 		TEST(val[i] == (TUint16)i);
       
   528 		}
       
   529 	}
       
   530 
       
   531 //"RSqlStatement::ColumnText()" OOM test
       
   532 void StmtColumnText2L(RSqlStatement& aStmt)
       
   533 	{
       
   534 	TPtrC val;
       
   535 	TInt err = aStmt.ColumnText(3, val);
       
   536 	User::LeaveIfError(err);
       
   537 	TEST(val.Length() == KLongColumnSize);
       
   538 	for(TInt i=0;i<KLongColumnSize;++i)
       
   539 		{
       
   540 		TEST(val[i] == (TUint16)i);
       
   541 		}
       
   542 	}
       
   543 
       
   544 //"RSqlStatement::ColumnText()" OOM test
       
   545 void StmtColumnText3L(RSqlStatement& aStmt)
       
   546 	{
       
   547 	TPtr val(TheTextColumnData, KLongColumnSize);
       
   548 	TInt err = aStmt.ColumnText(3, val);
       
   549 	User::LeaveIfError(err);
       
   550 	TEST(val.Length() == KLongColumnSize);
       
   551 	for(TInt i=0;i<KLongColumnSize;++i)
       
   552 		{
       
   553 		TEST(val[i] == (TUint16)i);
       
   554 		}
       
   555 	}
       
   556 
       
   557 //"RSqlStatement::ColumnBinaryL()" OOM test
       
   558 void StmtColumnBinary1L(RSqlStatement& aStmt)
       
   559 	{
       
   560 	TPtrC8 val = aStmt.ColumnBinaryL(4);
       
   561 	TEST(val.Length() == KLongColumnSize * sizeof(TUint16));
       
   562 	for(TInt i=0,j=0;i<KLongColumnSize;++i,j+=2)
       
   563 		{
       
   564 		TUint8 valLow = val[j];
       
   565 		TUint8 valHigh = val[j + 1];
       
   566 		TEST(valLow == (TUint8)(i & 0xFF));
       
   567 		TEST(valHigh == (TUint8)(((TUint)i >> 8) & 0xFF));
       
   568 		}
       
   569 	}
       
   570 
       
   571 //"RSqlStatement::ColumnBinary()" OOM test
       
   572 void StmtColumnBinary2L(RSqlStatement& aStmt)
       
   573 	{
       
   574 	TPtrC8 val;
       
   575 	TInt err = aStmt.ColumnBinary(4, val);
       
   576 	User::LeaveIfError(err);
       
   577 	TEST(val.Length() == KLongColumnSize * sizeof(TUint16));
       
   578 	for(TInt i=0,j=0;i<KLongColumnSize;++i,j+=2)
       
   579 		{
       
   580 		TUint8 valLow = val[j];
       
   581 		TUint8 valHigh = val[j + 1];
       
   582 		TEST(valLow == (TUint8)(i & 0xFF));
       
   583 		TEST(valHigh == (TUint8)(((TUint)i >> 8) & 0xFF));
       
   584 		}
       
   585 	}
       
   586 
       
   587 //"RSqlStatement::ColumnBinary()" OOM test
       
   588 void StmtColumnBinary3L(RSqlStatement& aStmt)
       
   589 	{
       
   590 	TPtr8 val(TheBinaryColumnData, KLongColumnSize * sizeof(TUint16));
       
   591 	TInt err = aStmt.ColumnBinary(4, val);
       
   592 	User::LeaveIfError(err);
       
   593 	TEST(val.Length() == KLongColumnSize * sizeof(TUint16));
       
   594 	for(TInt i=0,j=0;i<KLongColumnSize;++i,j+=2)
       
   595 		{
       
   596 		TUint8 valLow = val[j];
       
   597 		TUint8 valHigh = val[j + 1];
       
   598 		TEST(valLow == (TUint8)(i & 0xFF));
       
   599 		TEST(valHigh == (TUint8)(((TUint)i >> 8) & 0xFF));
       
   600 		}
       
   601 	}
       
   602 
       
   603 //"RSqlStatement::ColumnCount()" OOM test
       
   604 void StmtColumnCount(RSqlStatement& aStmt)
       
   605 	{
       
   606 	TInt cnt = aStmt.ColumnCount();
       
   607 	TEST2(cnt, 5);
       
   608 	}
       
   609 
       
   610 //"RSqlStatement::DeclaredColumnType()" OOM test
       
   611 void StmtDeclaredColumnTypeL(RSqlStatement& aStmt)
       
   612 	{
       
   613 	TInt cnt = aStmt.ColumnCount();
       
   614 	TEST2(cnt, 5);
       
   615 	const TSqlColumnType KColTypes[] = {ESqlInt, ESqlInt, ESqlReal, ESqlText, ESqlBinary};
       
   616 	for(TInt i=0;i<cnt;++i)
       
   617 		{
       
   618 		TSqlColumnType colType;
       
   619 		TInt err = aStmt.DeclaredColumnType(i, colType);
       
   620 		User::LeaveIfError(err);
       
   621 		TEST2(colType, KColTypes[i]);
       
   622 		}
       
   623 	}
       
   624 
       
   625 //"RSqlColumnReadStream::ColumnBinary()" OOM test
       
   626 void StmtColumnBinaryStreamL(RSqlStatement& aStmt)
       
   627 	{
       
   628 	RSqlColumnReadStream strm;
       
   629 	CleanupClosePushL(strm);
       
   630 	TInt err = strm.ColumnBinary(aStmt, 4);
       
   631 	User::LeaveIfError(err);
       
   632 	strm.ReadL(TheBinaryColumnData, KLongColumnSize * sizeof(TUint16));
       
   633 	CleanupStack::PopAndDestroy(&strm);
       
   634 	for(TInt i=0,j=0;i<KLongColumnSize;++i,j+=2)
       
   635 		{
       
   636 		TUint8 valLow = TheBinaryColumnData[j];
       
   637 		TUint8 valHigh = TheBinaryColumnData[j + 1];
       
   638 		TEST(valLow == (TUint8)(i & 0xFF));
       
   639 		TEST(valHigh == (TUint8)(((TUint)i >> 8) & 0xFF));
       
   640 		}
       
   641 	}
       
   642 
       
   643 //"RSqlColumnReadStream::ColumnText()" OOM test
       
   644 void StmtColumnTextStreamL(RSqlStatement& aStmt)
       
   645 	{
       
   646 	RSqlColumnReadStream strm;
       
   647 	CleanupClosePushL(strm);
       
   648 	TInt err = strm.ColumnText(aStmt, 3);
       
   649 	User::LeaveIfError(err);
       
   650 	strm.ReadL(TheTextColumnData, KLongColumnSize);
       
   651 	CleanupStack::PopAndDestroy(&strm);
       
   652 	for(TInt i=0;i<KLongColumnSize;++i)
       
   653 		{
       
   654 		TEST(TheTextColumnData[i] == (TUint16)i);
       
   655 		}
       
   656 	}
       
   657 
       
   658 //"RSqlParamWriteStream::BindBinary()" OOM test
       
   659 void StmtParamBinaryStreamL(RSqlStatement& aStmt)
       
   660 	{
       
   661 	for(TInt i=0;i<KLongParameterSize;++i)
       
   662 		{
       
   663 		TheTextColumnData[i] = (TUint16)i;
       
   664 		}
       
   665 
       
   666 	RSqlParamWriteStream strm;
       
   667 	CleanupClosePushL(strm);
       
   668 	TInt err = strm.BindBinary(aStmt, 3);
       
   669 	User::LeaveIfError(err);
       
   670 	strm.WriteL((TUint8*)TheTextColumnData, KLongColumnSize * sizeof(TUint16));
       
   671 	CleanupStack::PopAndDestroy(&strm);
       
   672 	}
       
   673 
       
   674 //"RSqlParamWriteStream::BindText()" OOM test
       
   675 void StmtParamTextStreamL(RSqlStatement& aStmt)
       
   676 	{
       
   677 	for(TInt i=0;i<KLongParameterSize;++i)
       
   678 		{
       
   679 		TheTextColumnData[i] = (TUint16)i;
       
   680 		}
       
   681 
       
   682 	RSqlParamWriteStream strm;
       
   683 	CleanupClosePushL(strm);
       
   684 	TInt err = strm.BindText(aStmt, 3);
       
   685 	User::LeaveIfError(err);
       
   686 	strm.WriteL(TheTextColumnData, KLongColumnSize);
       
   687 	CleanupStack::PopAndDestroy(&strm);
       
   688 	}
       
   689 
       
   690 /**
       
   691 @SYMTestCaseID			SYSLIB-SQL-CT-1618
       
   692 @SYMTestCaseDesc		RSqlStatement methods OOM tests
       
   693 						Precondition: the database exists, opened, some record(s) inserted.
       
   694 						The test calls the given as an argument function while simulating OOM failures
       
   695 						and checks that there are no memory and resource leaks.
       
   696 @SYMTestPriority		High
       
   697 @SYMTestActions			RSqlStatement methods OOM tests
       
   698 @SYMTestExpectedResults Test must not fail
       
   699 @SYMREQ					REQ5792
       
   700                         REQ5793
       
   701 */
       
   702 void DoStmtOomTestL(TStmtFuncPtrL aStmtPrepareFuncPtrL, TStmtFuncPtr2L aStmtTestFuncPtrL, const TDesC& aDbFileName, TDbType aDbType)
       
   703 	{
       
   704 	//This is not really an OOM test, because:
       
   705 	//(A) The test forces the server to simulate heap failure on determied allocation step
       
   706 	//(B) SQL server counts only the number of active statement and stream objects, the allocated memory cells
       
   707 	//    are not counted.
       
   708 	//    The reason that the allocated memory cells are not counted and in case of OOM failure - checked is
       
   709 	//    because the SQL server may make some per-connection persistent memory allocations (cache pages, etc.)
       
   710 	//    which will not be deallocated when the statement object is closed.
       
   711 
       
   712 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1618 RSqlStatement - OOM test"));
       
   713 	RSqlSecurityPolicy securityPolicy;
       
   714 	CreateTestSecurityPolicy(securityPolicy);
       
   715 	for(TInt i=0;i<(TInt)(sizeof(TheOomTestType)/sizeof(TheOomTestType[0]));++i)
       
   716 		{
       
   717 		RSqlDatabase::Delete(aDbFileName);
       
   718 		RSqlDatabase db;
       
   719 		TInt err = aDbType == ESecureDb ? db.Create(aDbFileName, securityPolicy) : db.Create(aDbFileName);
       
   720 		TEST2(err, KErrNone);
       
   721 		err = db.Exec(KSqlDbString);
       
   722 		TEST(err >= 0);
       
   723 		err = db.Exec(KSqlDbString2);
       
   724 		TEST(err >= 0);
       
   725 
       
   726 		err = KErrNoMemory;
       
   727 		const TInt KMaxAllocation = TheOomTestType[i] == EServerSideTest ? KStmtOomTestAllocLimitServer : KStmtOomTestAllocLimitClient;
       
   728 		TInt allocationNo = 0;
       
   729 		TInt failingAllocationNo = 0;
       
   730 		while(allocationNo < KMaxAllocation)
       
   731 			{
       
   732 			MarkHandles();
       
   733 			MarkAllocatedCells();
       
   734 
       
   735 			__UHEAP_MARK;
       
   736 
       
   737 	    	RSqlStatement stmt;
       
   738 			TRAP(err, (*aStmtPrepareFuncPtrL)(db, stmt));
       
   739 			TEST2(err, KErrNone);
       
   740 
       
   741 			SetHeapFailure(TheOomTestType[i], ++allocationNo);
       
   742 
       
   743 			TRAP(err, (*aStmtTestFuncPtrL)(stmt));
       
   744 
       
   745 			//ResetHeapFailure() has to be called before stmt.Close() because,
       
   746 			//otherwise it will panic the server (the server resource count, marked by
       
   747 			//SetHeapFailure() call, is 1 (there is one prepared statement))
       
   748 			ResetHeapFailure(TheOomTestType[i]);
       
   749 
       
   750 			stmt.Close();
       
   751 
       
   752 			if(err != KErrNoMemory)
       
   753 				{
       
   754 				TEST2(err, KErrNone);
       
   755 				}
       
   756 			else
       
   757 				{
       
   758 				failingAllocationNo = allocationNo;	
       
   759 				}
       
   760 
       
   761 			__UHEAP_MARKEND;
       
   762 
       
   763 			CheckAllocatedCells();
       
   764 			CheckHandles();
       
   765 			}
       
   766 
       
   767 		db.Close();
       
   768 		TEST2(err, KErrNone);
       
   769 		PrintEndOfOomTest(TheOomTestType[i], failingAllocationNo);
       
   770 		}
       
   771 	//Delete the database file
       
   772 	RSqlDatabase::Delete(aDbFileName);
       
   773 	securityPolicy.Close();
       
   774 	}
       
   775 
       
   776 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   777 //////////////////               RSqlBlobReadStream, RSqlBlobWriteStream - OOM tests          /////////////////////
       
   778 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   779 
       
   780 //RSqlBlobReadStream, RSqlBlobWriteStream - OOM test preparation.
       
   781 void ExecInsertBlobL(RSqlDatabase& aDb)
       
   782 	{
       
   783 	_LIT8(KSqlString1, "CREATE TABLE BBB(Fld1 INTEGER, Fld2 BIGINT, Fld3 DOUBLE, Fld4 TEXT, Fld5 LONGBLOB)");
       
   784 	TInt err = aDb.Exec(KSqlString1);
       
   785 	User::LeaveIfError(err);
       
   786 	_LIT8(KSqlString2, "INSERT INTO BBB(fld1, fld2, fld3, fld4, fld5) VALUES(10, 100, 100.001, 'AAA', x'");
       
   787 	TheSqlBuf.Copy(KSqlString2);
       
   788 	for(TInt i=0;i<KBlobStrLen;++i)	
       
   789 		{
       
   790 		TheSqlBuf.Append(_L8("A5"));
       
   791 		}
       
   792 	TheSqlBuf.Append(_L8("')"));
       
   793 	err = aDb.Exec(TheSqlBuf);
       
   794 	User::LeaveIfError(err);
       
   795 	}
       
   796 
       
   797 //"RSqlBlobReadStream::OpenL()/RSqlBlobReadStream::ReadL()" OOM test
       
   798 void BlobReadStreamOpenL(RSqlDatabase& aDb, const TDesC& aAttachDbName = KNullDesC)
       
   799 	{
       
   800 	RSqlBlobReadStream strm;
       
   801 	CleanupClosePushL(strm);
       
   802 	if(aAttachDbName.Length() > 0)
       
   803 		{
       
   804 		strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1, aAttachDbName);
       
   805 		}
       
   806 	else
       
   807 		{
       
   808 		strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1);
       
   809 		}
       
   810 	const TInt KReadOpCnt = 8;
       
   811 	for(TInt j=0;j<KReadOpCnt;++j)
       
   812 		{
       
   813 		strm.ReadL(TheSqlBuf, KBlobLen / KReadOpCnt);
       
   814 		TEST2(TheSqlBuf.Length(), (KBlobLen / KReadOpCnt));
       
   815 		for(TInt i=0;i<(KBlobLen / KReadOpCnt);++i)
       
   816 			{
       
   817 			TUint8 val = TheSqlBuf[i];
       
   818 			TEST2(val, 0xA5);
       
   819 			}
       
   820 		}
       
   821 	CleanupStack::PopAndDestroy(&strm);
       
   822 	}
       
   823 
       
   824 //"RSqlBlobReadStream::OpenL()/RSqlBlobReadStream::SizeL()" OOM test
       
   825 void BlobReadStreamSizeL(RSqlDatabase& aDb, const TDesC& aAttachDbName = KNullDesC)
       
   826 	{
       
   827 	RSqlBlobReadStream strm;
       
   828 	CleanupClosePushL(strm);
       
   829 	if(aAttachDbName.Length() > 0)
       
   830 		{
       
   831 		strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1, aAttachDbName);
       
   832 		}
       
   833 	else
       
   834 		{
       
   835 		strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1);
       
   836 		}
       
   837 	TInt size = strm.SizeL();	
       
   838 	TEST2(size, KBlobLen);
       
   839 	CleanupStack::PopAndDestroy(&strm);
       
   840 	}
       
   841 
       
   842 //"RSqlBlobWriteStream::OpenL()/RSqlBlobWriteStream::WriteL()" OOM test
       
   843 void BlobWriteStreamOpenL(RSqlDatabase& aDb, const TDesC& aAttachDbName = KNullDesC)
       
   844 	{
       
   845 	RSqlBlobWriteStream strm;
       
   846 	CleanupClosePushL(strm);
       
   847 	if(aAttachDbName.Length() > 0)
       
   848 		{
       
   849 		strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1, aAttachDbName);
       
   850 		}
       
   851 	else
       
   852 		{
       
   853 		strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1);
       
   854 		}
       
   855 	const TInt KWriteOpCnt = 8;
       
   856 	TheSqlBuf.SetLength(KBlobLen / KWriteOpCnt);
       
   857 	TheSqlBuf.Fill(TChar('Z'));
       
   858 	for(TInt j=0;j<KWriteOpCnt;++j)
       
   859 		{
       
   860 		strm.WriteL(TheSqlBuf, KBlobLen / KWriteOpCnt);
       
   861 		}
       
   862 	strm.CommitL();		
       
   863 	CleanupStack::PopAndDestroy(&strm);
       
   864 	}
       
   865 
       
   866 //"RSqlBlobWriteStream::OpenL()/RSqlBlobWriteStream::SizeL()" OOM test
       
   867 void BlobWriteStreamSizeL(RSqlDatabase& aDb, const TDesC& aAttachDbName = KNullDesC)
       
   868 	{
       
   869 	RSqlBlobWriteStream strm;
       
   870 	CleanupClosePushL(strm);
       
   871 	if(aAttachDbName.Length() > 0)
       
   872 		{
       
   873 		strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1, aAttachDbName);
       
   874 		}
       
   875 	else
       
   876 		{
       
   877 		strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1);
       
   878 		}
       
   879 	TInt size = strm.SizeL();	
       
   880 	TEST2(size, KBlobLen);
       
   881 	CleanupStack::PopAndDestroy(&strm);
       
   882 	}
       
   883 	
       
   884 //"TSqlBlob::GetLC()" OOM test
       
   885 void BlobWholeGet1L(RSqlDatabase& aDb, const TDesC& aAttachDbName = KNullDesC)
       
   886 	{
       
   887 	HBufC8* buf = NULL;
       
   888 	if(aAttachDbName.Length() > 0)
       
   889 		{
       
   890 		buf = TSqlBlob::GetLC(aDb, _L("BBB"), _L("fld5"), 1, aAttachDbName);
       
   891 		}
       
   892 	else
       
   893 		{
       
   894 		buf = TSqlBlob::GetLC(aDb, _L("BBB"), _L("fld5"), 1);
       
   895 		}
       
   896 	TEST(buf->Length() == KBlobStrLen);
       
   897 	CleanupStack::PopAndDestroy(buf);
       
   898 	}
       
   899 	
       
   900 //"TSqlBlob::Get()" OOM test
       
   901 void BlobWholeGet2L(RSqlDatabase& aDb, const TDesC& aAttachDbName = KNullDesC)
       
   902 	{
       
   903 	if(aAttachDbName.Length() > 0)
       
   904 		{
       
   905 		TSqlBlob::Get(aDb, _L("BBB"), _L("fld5"), TheSqlBuf2, 1, aAttachDbName);
       
   906 		}
       
   907 	else
       
   908 		{
       
   909 		TSqlBlob::Get(aDb, _L("BBB"), _L("fld5"), TheSqlBuf2, 1);
       
   910 		}
       
   911 	}
       
   912 
       
   913 //"TSqlBlob::SetL()" OOM test
       
   914 void BlobWholeSetL(RSqlDatabase& aDb, const TDesC& aAttachDbName = KNullDesC)
       
   915 	{
       
   916 	if(aAttachDbName.Length() > 0)
       
   917 		{
       
   918 		TSqlBlob::SetL(aDb, _L("BBB"), _L("fld5"), TheSqlBuf, 1, aAttachDbName);
       
   919 		}
       
   920 	else
       
   921 		{
       
   922 		TSqlBlob::Get(aDb, _L("BBB"), _L("fld5"), TheSqlBuf, 1);
       
   923 		}
       
   924 	}
       
   925 
       
   926 /**
       
   927 @SYMTestCaseID			SYSLIB-SQL-UT-4091
       
   928 @SYMTestCaseDesc		RSqlBlobReadStream, RSqlBlobWriteStream methods OOM tests
       
   929 						Precondition: the database exists, opened, some record(s) inserted.
       
   930 						The test calls the given as an argument function while simulating OOM failures
       
   931 						and checks that there are no memory and resource leaks.
       
   932 @SYMTestPriority		High
       
   933 @SYMTestActions			RSqlBlobReadStream, RSqlBlobWriteStream methods OOM tests
       
   934 @SYMTestExpectedResults Test must not fail
       
   935 @SYMREQ					REQ5792
       
   936                         REQ10410
       
   937                         REQ10411
       
   938                         REQ10418
       
   939 */
       
   940 void DoBlobOomTestL(TBlobPrepareFuncPtrL aBlobPrepareFuncPtrL, TBlobTestFuncPtrL aBlobTestFuncPtrL, 
       
   941 					const TDesC& aDbFileName, TDbType aDbType, TBool aAttachDb = EFalse)
       
   942 	{
       
   943 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4091 RSqlBlobReadStream, RSqlBlobWriteStream - OOM test"));
       
   944 	RSqlSecurityPolicy securityPolicy;
       
   945 	CreateTestSecurityPolicy(securityPolicy);
       
   946 	for(TInt i=0;i<(TInt)(sizeof(TheOomTestType)/sizeof(TheOomTestType[0]));++i)
       
   947 		{
       
   948 		RSqlDatabase::Delete(aDbFileName);
       
   949 		RSqlDatabase db;
       
   950 		TInt err = aDbType == ESecureDb ? db.Create(aDbFileName, securityPolicy) : db.Create(aDbFileName);
       
   951 		TEST2(err, KErrNone);
       
   952 		TRAP(err, (*aBlobPrepareFuncPtrL)(db));
       
   953 		TEST2(err, KErrNone);
       
   954 		_LIT(KAttachDbName, "AttachDb");
       
   955 		if(aAttachDb)
       
   956 			{
       
   957 			err = db.Attach(aDbFileName, KAttachDbName);
       
   958 			TEST2(err, KErrNone);
       
   959 			}
       
   960 
       
   961 		err = KErrNoMemory;
       
   962 		const TInt KMaxAllocation = TheOomTestType[i] == EServerSideTest ? KBlobOomTestAllocLimitServer : KBlobOomTestAllocLimitClient;
       
   963 		TInt allocationNo = 0;
       
   964 		TInt failingAllocationNo = 0;
       
   965 		while(allocationNo < KMaxAllocation)
       
   966 			{
       
   967 			MarkHandles();
       
   968 			MarkAllocatedCells();
       
   969 
       
   970 			__UHEAP_MARK;
       
   971 
       
   972 			SetHeapFailure(TheOomTestType[i], ++allocationNo);
       
   973 			if(aAttachDb)
       
   974 				{
       
   975 				TRAP(err, (*aBlobTestFuncPtrL)(db, KAttachDbName));
       
   976 				}
       
   977 			else
       
   978 				{
       
   979 				TRAP(err, (*aBlobTestFuncPtrL)(db));
       
   980 				}
       
   981 
       
   982 			ResetHeapFailure(TheOomTestType[i]);
       
   983 
       
   984 			if(err != KErrNoMemory)
       
   985 				{
       
   986 				if(err != KErrNone)
       
   987 					{
       
   988 					TPtrC errmsg = db.LastErrorMessage();
       
   989 					if(errmsg.Length() > 0)
       
   990 						{
       
   991 						TheTest.Printf(_L("\r\n@@@ error %d, error message: %S\r\n"), err, &errmsg);	
       
   992 						}
       
   993 					}
       
   994 				TEST2(err, KErrNone);
       
   995 				}
       
   996 			else
       
   997 				{
       
   998 				failingAllocationNo = allocationNo;
       
   999 				}				
       
  1000 
       
  1001 			__UHEAP_MARKEND;
       
  1002 
       
  1003 			CheckAllocatedCells();
       
  1004 			CheckHandles();
       
  1005 			}
       
  1006 		TEST2(err, KErrNone);
       
  1007 
       
  1008 		if(aAttachDb)
       
  1009 			{
       
  1010 			(void)db.Detach(KAttachDbName);
       
  1011 			}
       
  1012 
       
  1013 		db.Close();
       
  1014 		err = RSqlDatabase::Delete(aDbFileName);
       
  1015 		TEST2(err, KErrNone);
       
  1016 		PrintEndOfOomTest(TheOomTestType[i], failingAllocationNo);
       
  1017 		}
       
  1018 	securityPolicy.Close();
       
  1019 	}
       
  1020 
       
  1021 void ScalarFullSelectInt_8L(RSqlDatabase& aDb)
       
  1022 	{
       
  1023 	TSqlScalarFullSelectQuery query(aDb);
       
  1024 	TInt val = query.SelectIntL(_L8("SELECT F1 FROM A WHERE F3 < 0"));
       
  1025 	TEST2(val, 2);
       
  1026 	}
       
  1027 
       
  1028 void ScalarFullSelectInt64_8L(RSqlDatabase& aDb)
       
  1029 	{
       
  1030 	TSqlScalarFullSelectQuery query(aDb);
       
  1031 	TInt64 val = query.SelectInt64L(_L8("SELECT F2 FROM A WHERE F1 = 1"));
       
  1032 	TEST2(val, 10000000000LL);
       
  1033 	}
       
  1034 
       
  1035 void ScalarFullSelectReal_8L(RSqlDatabase& aDb)
       
  1036 	{
       
  1037 	TSqlScalarFullSelectQuery query(aDb);
       
  1038 	TReal val = query.SelectRealL(_L8("SELECT F3 FROM A WHERE F1 = 1"));
       
  1039 	TEST(val > 2.0 && val < 3.0);
       
  1040 	}
       
  1041 
       
  1042 void ScalarFullSelectText_8L(RSqlDatabase& aDb)
       
  1043 	{
       
  1044 	TSqlScalarFullSelectQuery query(aDb);
       
  1045 	TBuf<20> buf;
       
  1046 	TInt err = query.SelectTextL(_L8("SELECT F4 FROM A WHERE F1 = 1"), buf);
       
  1047 	TEST2(err, KErrNone);
       
  1048 	_LIT(KText, "NAME1234567890");
       
  1049 	TEST(buf == KText);
       
  1050 	}
       
  1051 
       
  1052 void ScalarFullSelectBinary_8L(RSqlDatabase& aDb)
       
  1053 	{
       
  1054 	TSqlScalarFullSelectQuery query(aDb);
       
  1055 	TBuf8<20> buf;
       
  1056 	TInt err = query.SelectBinaryL(_L8("SELECT F5 FROM A WHERE F1 = 1"), buf);
       
  1057 	TEST2(err, KErrNone);
       
  1058 	TEST(buf.Length() == 0);
       
  1059 	}
       
  1060 
       
  1061 void ScalarFullSelectInt_16L(RSqlDatabase& aDb)
       
  1062 	{
       
  1063 	TSqlScalarFullSelectQuery query(aDb);
       
  1064 	TInt val = query.SelectIntL(_L16("SELECT F1 FROM A WHERE F3 < 0"));
       
  1065 	TEST2(val, 2);
       
  1066 	}
       
  1067 
       
  1068 void ScalarFullSelectInt64_16L(RSqlDatabase& aDb)
       
  1069 	{
       
  1070 	TSqlScalarFullSelectQuery query(aDb);
       
  1071 	TInt64 val = query.SelectInt64L(_L16("SELECT F2 FROM A WHERE F1 = 1"));
       
  1072 	TEST2(val, 10000000000LL);
       
  1073 	}
       
  1074 
       
  1075 void ScalarFullSelectReal_16L(RSqlDatabase& aDb)
       
  1076 	{
       
  1077 	TSqlScalarFullSelectQuery query(aDb);
       
  1078 	TReal val = query.SelectRealL(_L16("SELECT F3 FROM A WHERE F1 = 1"));
       
  1079 	TEST(val > 2.0 && val < 3.0);
       
  1080 	}
       
  1081 
       
  1082 void ScalarFullSelectText_16L(RSqlDatabase& aDb)
       
  1083 	{
       
  1084 	TSqlScalarFullSelectQuery query(aDb);
       
  1085 	TBuf<20> buf;
       
  1086 	TInt err = query.SelectTextL(_L16("SELECT F4 FROM A WHERE F1 = 1"), buf);
       
  1087 	TEST2(err, KErrNone);
       
  1088 	_LIT(KText, "NAME1234567890");
       
  1089 	TEST(buf == KText);
       
  1090 	}
       
  1091 
       
  1092 void ScalarFullSelectBinary_16L(RSqlDatabase& aDb)
       
  1093 	{
       
  1094 	TSqlScalarFullSelectQuery query(aDb);
       
  1095 	TBuf8<20> buf;
       
  1096 	TInt err = query.SelectBinaryL(_L16("SELECT F5 FROM A WHERE F1 = 1"), buf);
       
  1097 	TEST2(err, KErrNone);
       
  1098 	TEST(buf.Length() == 0);
       
  1099 	}
       
  1100 
       
  1101 void ScalarFullSelectText2_8L(RSqlDatabase& aDb)
       
  1102 	{
       
  1103 	TSqlScalarFullSelectQuery query(aDb);
       
  1104 	HBufC* buf = HBufC::NewLC(8);
       
  1105 	TPtr name = buf->Des();
       
  1106 	TInt rc = query.SelectTextL(_L8("SELECT F4 FROM A WHERE F1 = 1"), name);
       
  1107 	TEST(rc >= 0); //the function may return only non-negative values
       
  1108 	if(rc > 0)
       
  1109 		{
       
  1110 		buf = buf->ReAllocL(rc);
       
  1111 		CleanupStack::Pop();
       
  1112 		CleanupStack::PushL(buf);
       
  1113 		name.Set(buf->Des());
       
  1114 		rc = query.SelectTextL(_L8("SELECT F4 FROM A WHERE F1 = 1"), name);
       
  1115 		TEST(rc == 0);
       
  1116 		_LIT(KText, "NAME1234567890");
       
  1117 		TEST(name == KText);
       
  1118 		}
       
  1119 	CleanupStack::PopAndDestroy(buf);
       
  1120 	}
       
  1121 
       
  1122 /**
       
  1123 @SYMTestCaseID			SYSLIB-SQL-CT-1811
       
  1124 @SYMTestCaseDesc		TSqlScalarFullSelectQuery functions OOM test
       
  1125 						Precondition: the database exists.
       
  1126 						The test simulates OOM failures while calling TSqlScalarFullSelectQuery functions
       
  1127 						and checks that there are no memory and resource leaks.
       
  1128 @SYMTestPriority		High
       
  1129 @SYMTestActions			TSqlScalarFullSelectQuery methods OOM tests
       
  1130 @SYMTestExpectedResults Test must not fail
       
  1131 @SYMREQ					REQ5792
       
  1132                         REQ5793
       
  1133 */
       
  1134 void DoFullSelectOomTest(TScalarFullSelectFuncPtrL aTestFunctionPtrL)
       
  1135 	{
       
  1136 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1811 TSqlScalarFullSelectQuery - OOM test"));
       
  1137 	//Create test database
       
  1138 	RSqlDatabase db;
       
  1139 	TInt err = db.Create(KTestDb);
       
  1140 	TEST2(err, KErrNone);
       
  1141 	err = db.Exec(_L("CREATE TABLE A(F1 INTEGER, F2 INTEGER, F3 FLOAT, F4 TEXT, F5 BLOB)"));
       
  1142 	TEST(err >= 0);
       
  1143 	err = db.Exec(_L("INSERT INTO A(F1, F2, F3, F4, F5) VALUES(1, 10000000000, 2.54, 'NAME1234567890', NULL)"));
       
  1144 	TEST2(err, 1);
       
  1145 	err = db.Exec(_L("INSERT INTO A(F1, F2, F3, F4) VALUES(2, 200, -1.11, 'ADDRESS')"));
       
  1146 	TEST2(err, 1);
       
  1147 	db.Close();
       
  1148 	//OOM test loop
       
  1149 	for(TInt i=0;i<(TInt)(sizeof(TheOomTestType)/sizeof(TheOomTestType[0]));++i)
       
  1150 		{
       
  1151 		err = KErrNoMemory;
       
  1152 		const TInt KMaxAllocation = TheOomTestType[i] == EServerSideTest ? KStmtOomTestAllocLimitServer : KStmtOomTestAllocLimitClient;
       
  1153 		TInt allocationNo = 0;
       
  1154 		TInt failingAllocationNo = 0;
       
  1155 		while(allocationNo < KMaxAllocation)
       
  1156 			{
       
  1157 			MarkHandles();
       
  1158 			MarkAllocatedCells();
       
  1159 
       
  1160 			__UHEAP_MARK;
       
  1161 
       
  1162 			if(TheOomTestType[i] == EServerSideTest)
       
  1163 				{//We will delay the heap failure simulation, until the database is opened
       
  1164 				SetDbHeapFailure(TheOomTestType[i], ++allocationNo, ETrue);
       
  1165 				}
       
  1166 
       
  1167 			err = db.Open(KTestDb);
       
  1168 			TEST2(err, KErrNone);
       
  1169 
       
  1170 			if(TheOomTestType[i] == EClientSideTest)
       
  1171 				{
       
  1172 				SetDbHeapFailure(TheOomTestType[i], ++allocationNo);
       
  1173 				}
       
  1174 
       
  1175 			TRAP(err, (*aTestFunctionPtrL)(db));
       
  1176 			db.Close();
       
  1177 			if(err != KErrNoMemory)
       
  1178 				{
       
  1179 				TEST2(err, KErrNone);
       
  1180 				}
       
  1181 			else
       
  1182 				{
       
  1183 				failingAllocationNo = allocationNo;	
       
  1184 				}
       
  1185 
       
  1186 			ResetDbHeapFailure(TheOomTestType[i]);
       
  1187 
       
  1188 			__UHEAP_MARKEND;
       
  1189 
       
  1190 			CheckAllocatedCells();
       
  1191 			CheckHandles();
       
  1192 			}
       
  1193 		TEST2(err, KErrNone);
       
  1194 		PrintEndOfOomTest(TheOomTestType[i], failingAllocationNo);
       
  1195 		}
       
  1196 	//Delete the database file
       
  1197 	RSqlDatabase::Delete(KTestDb);
       
  1198 	}
       
  1199 
       
  1200 //RSqlStatement OOM tests
       
  1201 void StmtOomTestsL()
       
  1202 	{
       
  1203 	const TInt KTestCnt = 2;
       
  1204 	const TPtrC dbFileName[KTestCnt] = {KTestDb(), 	KSecureTestDb()};
       
  1205 	TDbType dbType[KTestCnt] = {ENonSecureDb, ESecureDb};
       
  1206 
       
  1207 	for(TInt i=0;i<KTestCnt;++i)
       
  1208 		{
       
  1209 		TheTest.Printf(_L("===RSqlStatement::Prepare(), 8-bit SQL\r\n"));
       
  1210 		DoStmtPrepareOomTestL(&PrepareStmt8L, dbFileName[i], dbType[i]);
       
  1211 
       
  1212 		TheTest.Printf(_L("===RSqlStatement::PrepareL(), 8-bit SQL\r\n"));
       
  1213 		DoStmtPrepareOomTestL(&PrepareStmt8_2L, dbFileName[i], dbType[i]);
       
  1214 
       
  1215 		TheTest.Printf(_L("===RSqlStatement::Prepare(), 16-bit SQL\r\n"));
       
  1216 		DoStmtPrepareOomTestL(&PrepareStmt16L, dbFileName[i], dbType[i]);
       
  1217 
       
  1218 		TheTest.Printf(_L("===RSqlStatement::PrepareL(), 16-bit SQL\r\n"));
       
  1219 		DoStmtPrepareOomTestL(&PrepareStmt16_2L, dbFileName[i], dbType[i]);
       
  1220 
       
  1221 		TheTest.Printf(_L("===RSqlStatement::Reset(), 8-bit SQL\r\n"));
       
  1222 		DoStmtOomTestL(&PrepareStmt8L, &ResetStmtL, dbFileName[i], dbType[i]);
       
  1223 
       
  1224 		TheTest.Printf(_L("===RSqlStatement::Reset(), 16-bit SQL\r\n"));
       
  1225 		DoStmtOomTestL(&PrepareStmt16L, &ResetStmtL, dbFileName[i], dbType[i]);
       
  1226 
       
  1227 		TheTest.Printf(_L("===RSqlStatement::Exec(), 8-bit SQL\r\n"));
       
  1228 		DoStmtOomTestL(&PrepareInsertStmt8L, &ExecStmtL, dbFileName[i], dbType[i]);
       
  1229 
       
  1230 		TheTest.Printf(_L("===RSqlStatement::Exec(), 16-bit SQL\r\n"));
       
  1231 		DoStmtOomTestL(&PrepareInsertStmt16L, &ExecStmtL, dbFileName[i], dbType[i]);
       
  1232 
       
  1233 		TheTest.Printf(_L("===RSqlStatement::Next(), 8-bit SQL\r\n"));
       
  1234 		DoStmtOomTestL(&PrepareStmt8L, &NextStmtL, dbFileName[i], dbType[i]);
       
  1235 
       
  1236 		TheTest.Printf(_L("===RSqlStatement::Next(), 16-bit SQL\r\n"));
       
  1237 		DoStmtOomTestL(&PrepareStmt16L, &NextStmtL, dbFileName[i], dbType[i]);
       
  1238 
       
  1239 		TheTest.Printf(_L("===RSqlStatement::ParameterIndex(), 8-bit SQL\r\n"));
       
  1240 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtParameterIndexL, dbFileName[i], dbType[i]);
       
  1241 
       
  1242 		TheTest.Printf(_L("===RSqlStatement::ParameterIndex(), 16-bit SQL\r\n"));
       
  1243 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtParameterIndexL, dbFileName[i], dbType[i]);
       
  1244 
       
  1245 		TheTest.Printf(_L("===RSqlStatement::ParameterName(), 8-bit SQL\r\n"));
       
  1246 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtParameterNameL, dbFileName[i], dbType[i]);
       
  1247 
       
  1248 		TheTest.Printf(_L("===RSqlStatement::ParameterName(), 16-bit SQL\r\n"));
       
  1249 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtParameterNameL, dbFileName[i], dbType[i]);
       
  1250 
       
  1251 		TheTest.Printf(_L("===RSqlStatement::ParamName(), 8-bit SQL\r\n"));
       
  1252 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtParamNameL, dbFileName[i], dbType[i]);
       
  1253 
       
  1254 		TheTest.Printf(_L("===RSqlStatement::ParamName(), 16-bit SQL\r\n"));
       
  1255 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtParamNameL, dbFileName[i], dbType[i]);
       
  1256 
       
  1257 		TheTest.Printf(_L("===RSqlStatement::ColumnIndex(), 8-bit SQL\r\n"));
       
  1258 		DoStmtOomTestL(&PrepareStmt8L, &StmtColumnIndexL, dbFileName[i], dbType[i]);
       
  1259 
       
  1260 		TheTest.Printf(_L("===RSqlStatement::ColumnIndex(), 16-bit SQL\r\n"));
       
  1261 		DoStmtOomTestL(&PrepareStmt16L, &StmtColumnIndexL, dbFileName[i], dbType[i]);
       
  1262 
       
  1263 		TheTest.Printf(_L("===RSqlStatement::ColumnType(), 8-bit SQL\r\n"));
       
  1264 		DoStmtOomTestL(&PrepareMoveStmt8L, &StmtColumnTypeL, dbFileName[i], dbType[i]);
       
  1265 
       
  1266 		TheTest.Printf(_L("===RSqlStatement::ColumnType(), 16-bit SQL\r\n"));
       
  1267 		DoStmtOomTestL(&PrepareMoveStmt16L, &StmtColumnTypeL, dbFileName[i], dbType[i]);
       
  1268 
       
  1269 		TheTest.Printf(_L("===RSqlStatement::ColumnSize(), 8-bit SQL\r\n"));
       
  1270 		DoStmtOomTestL(&PrepareMoveStmt8L, &StmtColumnSizeL, dbFileName[i], dbType[i]);
       
  1271 
       
  1272 		TheTest.Printf(_L("===RSqlStatement::ColumnSize(), 16-bit SQL\r\n"));
       
  1273 		DoStmtOomTestL(&PrepareMoveStmt16L, &StmtColumnSizeL, dbFileName[i], dbType[i]);
       
  1274 
       
  1275 		TheTest.Printf(_L("===RSqlStatement::ColumnName(), 8-bit SQL\r\n"));
       
  1276 		DoStmtOomTestL(&PrepareMoveStmt8L, &StmtColumnNameL, dbFileName[i], dbType[i]);
       
  1277 
       
  1278 		TheTest.Printf(_L("===RSqlStatement::ColumnName(), 16-bit SQL\r\n"));
       
  1279 		DoStmtOomTestL(&PrepareMoveStmt16L, &StmtColumnNameL, dbFileName[i], dbType[i]);
       
  1280 
       
  1281 		TheTest.Printf(_L("===RSqlStatement::BindNull(), 8-bit SQL\r\n"));
       
  1282 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtBindNullL, dbFileName[i], dbType[i]);
       
  1283 
       
  1284 		TheTest.Printf(_L("===RSqlStatement::BindNull(), 16-bit SQL\r\n"));
       
  1285 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtBindNullL, dbFileName[i], dbType[i]);
       
  1286 
       
  1287 		TheTest.Printf(_L("===RSqlStatement::BindInt(), 8-bit SQL\r\n"));
       
  1288 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtBindIntL, dbFileName[i], dbType[i]);
       
  1289 
       
  1290 		TheTest.Printf(_L("===RSqlStatement::BindInt(), 16-bit SQL\r\n"));
       
  1291 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtBindIntL, dbFileName[i], dbType[i]);
       
  1292 
       
  1293 		TheTest.Printf(_L("===RSqlStatement::BindInt64(), 8-bit SQL\r\n"));
       
  1294 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtBindInt64L, dbFileName[i], dbType[i]);
       
  1295 
       
  1296 		TheTest.Printf(_L("===RSqlStatement::BindInt64(), 16-bit SQL\r\n"));
       
  1297 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtBindInt64L, dbFileName[i], dbType[i]);
       
  1298 
       
  1299 		TheTest.Printf(_L("===RSqlStatement::BindReal(), 8-bit SQL\r\n"));
       
  1300 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtBindRealL, dbFileName[i], dbType[i]);
       
  1301 
       
  1302 		TheTest.Printf(_L("===RSqlStatement::BindReal(), 16-bit SQL\r\n"));
       
  1303 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtBindRealL, dbFileName[i], dbType[i]);
       
  1304 
       
  1305 		TheTest.Printf(_L("===RSqlStatement::BindText(), 8-bit SQL\r\n"));
       
  1306 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtBindTextL, dbFileName[i], dbType[i]);
       
  1307 
       
  1308 		TheTest.Printf(_L("===RSqlStatement::BindText(), 16-bit SQL\r\n"));
       
  1309 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtBindTextL, dbFileName[i], dbType[i]);
       
  1310 
       
  1311 		TheTest.Printf(_L("===RSqlStatement::BindBinary(), 8-bit SQL\r\n"));
       
  1312 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtBindBinaryL, dbFileName[i], dbType[i]);
       
  1313 
       
  1314 		TheTest.Printf(_L("===RSqlStatement::BindBinary(), 16-bit SQL\r\n"));
       
  1315 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtBindBinaryL, dbFileName[i], dbType[i]);
       
  1316 
       
  1317 		TheTest.Printf(_L("===RSqlStatement::BindZeroBlob(), 8-bit SQL\r\n"));
       
  1318 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtBindZeroBlobL, dbFileName[i], dbType[i]);
       
  1319 
       
  1320 		TheTest.Printf(_L("===RSqlStatement::BindZeroBlob(), 16-bit SQL\r\n"));
       
  1321 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtBindZeroBlobL, dbFileName[i], dbType[i]);
       
  1322 
       
  1323 		TheTest.Printf(_L("===RSqlStatement::IsNull(), 8-bit SQL\r\n"));
       
  1324 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtIsNullColumnL, dbFileName[i], dbType[i]);
       
  1325 
       
  1326 		TheTest.Printf(_L("===RSqlStatement::IsNull(), 16-bit SQL\r\n"));
       
  1327 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtIsNullColumnL, dbFileName[i], dbType[i]);
       
  1328 
       
  1329 		TheTest.Printf(_L("===RSqlStatement::ColumnInt(), 8-bit SQL\r\n"));
       
  1330 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnIntL, dbFileName[i], dbType[i]);
       
  1331 
       
  1332 		TheTest.Printf(_L("===RSqlStatement::ColumnInt(), 16-bit SQL\r\n"));
       
  1333 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnIntL, dbFileName[i], dbType[i]);
       
  1334 
       
  1335 		TheTest.Printf(_L("===RSqlStatement::ColumnInt64(), 8-bit SQL\r\n"));
       
  1336 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnInt64L, dbFileName[i], dbType[i]);
       
  1337 
       
  1338 		TheTest.Printf(_L("===RSqlStatement::ColumnInt64(), 16-bit SQL\r\n"));
       
  1339 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnInt64L, dbFileName[i], dbType[i]);
       
  1340 
       
  1341 		TheTest.Printf(_L("===RSqlStatement::ColumnReal(), 8-bit SQL\r\n"));
       
  1342 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnRealL, dbFileName[i], dbType[i]);
       
  1343 
       
  1344 		TheTest.Printf(_L("===RSqlStatement::ColumnReal(), 16-bit SQL\r\n"));
       
  1345 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnRealL, dbFileName[i], dbType[i]);
       
  1346 
       
  1347 		TheTest.Printf(_L("===RSqlStatement::ColumnTextL(), 8-bit SQL\r\n"));
       
  1348 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnText1L, dbFileName[i], dbType[i]);
       
  1349 
       
  1350 		TheTest.Printf(_L("===RSqlStatement::ColumnTextL(), 16-bit SQL\r\n"));
       
  1351 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnText1L, dbFileName[i], dbType[i]);
       
  1352 
       
  1353 		TheTest.Printf(_L("===RSqlStatement::ColumnText()-1, 8-bit SQL\r\n"));
       
  1354 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnText2L, dbFileName[i], dbType[i]);
       
  1355 
       
  1356 		TheTest.Printf(_L("===RSqlStatement::ColumnText()-1, 16-bit SQL\r\n"));
       
  1357 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnText2L, dbFileName[i], dbType[i]);
       
  1358 
       
  1359 		TheTest.Printf(_L("===RSqlStatement::ColumnText()-2, 8-bit SQL\r\n"));
       
  1360 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnText3L, dbFileName[i], dbType[i]);
       
  1361 
       
  1362 		TheTest.Printf(_L("===RSqlStatement::ColumnText()-2, 16-bit SQL\r\n"));
       
  1363 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnText3L, dbFileName[i], dbType[i]);
       
  1364 
       
  1365 		TheTest.Printf(_L("===RSqlStatement::ColumnBinaryL(), 8-bit SQL\r\n"));
       
  1366 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnBinary1L, dbFileName[i], dbType[i]);
       
  1367 
       
  1368 		TheTest.Printf(_L("===RSqlStatement::ColumnBinaryL(), 16-bit SQL\r\n"));
       
  1369 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnBinary1L, dbFileName[i], dbType[i]);
       
  1370 
       
  1371 		TheTest.Printf(_L("===RSqlStatement::ColumnBinary()-1, 8-bit SQL\r\n"));
       
  1372 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnBinary2L, dbFileName[i], dbType[i]);
       
  1373 
       
  1374 		TheTest.Printf(_L("===RSqlStatement::ColumnBinary()-1, 16-bit SQL\r\n"));
       
  1375 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnBinary2L, dbFileName[i], dbType[i]);
       
  1376 
       
  1377 		TheTest.Printf(_L("===RSqlStatement::ColumnBinary()-2, 8-bit SQL\r\n"));
       
  1378 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnBinary3L, dbFileName[i], dbType[i]);
       
  1379 
       
  1380 		TheTest.Printf(_L("===RSqlStatement::ColumnBinary()-2, 16-bit SQL\r\n"));
       
  1381 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnBinary3L, dbFileName[i], dbType[i]);
       
  1382 
       
  1383 		TheTest.Printf(_L("===RSqlStatement::ColumnCount(), 8-bit SQL\r\n"));
       
  1384 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnCount, dbFileName[i], dbType[i]);
       
  1385 
       
  1386 		TheTest.Printf(_L("===RSqlStatement::ColumnCount(), 16-bit SQL\r\n"));
       
  1387 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnCount, dbFileName[i], dbType[i]);
       
  1388 
       
  1389 		TheTest.Printf(_L("===RSqlStatement::DeclaredColumnType(), 8-bit SQL\r\n"));
       
  1390 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtDeclaredColumnTypeL, dbFileName[i], dbType[i]);
       
  1391 
       
  1392 		TheTest.Printf(_L("===RSqlStatement::DeclaredColumnType(), 16-bit SQL\r\n"));
       
  1393 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtDeclaredColumnTypeL, dbFileName[i], dbType[i]);
       
  1394 		}
       
  1395 	}
       
  1396 
       
  1397 //RSqlStatement - negative OOM tests
       
  1398 void StmtOomNegativeTestsL()
       
  1399 	{
       
  1400 	const TInt KTestCnt = 2;
       
  1401 	const TPtrC dbFileName[KTestCnt] = {KTestDb(), 	KSecureTestDb()};
       
  1402 	TDbType dbType[KTestCnt] = {ENonSecureDb, ESecureDb};
       
  1403 
       
  1404 	for(TInt i=0;i<KTestCnt;++i)
       
  1405 		{
       
  1406 		TheTest.Printf(_L("===RSqlStatement::Prepare(), 8-bit SQL\r\n"));
       
  1407 		DoStmtPrepareOomTestL(&PrepareBadStmt8L, dbFileName[i], dbType[i], KSqlErrGeneral);
       
  1408 
       
  1409 		TheTest.Printf(_L("===RSqlStatement::Prepare(), 16-bit SQL\r\n"));
       
  1410 		DoStmtPrepareOomTestL(&PrepareBadStmt16L, dbFileName[i], dbType[i], KSqlErrGeneral);
       
  1411 		}
       
  1412 	}
       
  1413 
       
  1414 //RSqlColumnReadStream OOM tests
       
  1415 void ColumnReadStreamOomTestsL()
       
  1416 	{
       
  1417 	const TInt KTestCnt = 2;
       
  1418 	const TPtrC dbFileName[KTestCnt] = {KTestDb(), 	KSecureTestDb()};
       
  1419 	TDbType dbType[KTestCnt] = {ENonSecureDb, ESecureDb};
       
  1420 
       
  1421 	for(TInt i=0;i<KTestCnt;++i)
       
  1422 		{
       
  1423 		TheTest.Printf(_L("===RSqlColumnReadStream::ColumnBinary(), 8-bit SQL\r\n"));
       
  1424 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnBinaryStreamL, dbFileName[i], dbType[i]);
       
  1425 
       
  1426 		TheTest.Printf(_L("===RSqlColumnReadStream::ColumnBinary(), 16-bit SQL\r\n"));
       
  1427 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnBinaryStreamL, dbFileName[i], dbType[i]);
       
  1428 
       
  1429 		TheTest.Printf(_L("===RSqlColumnReadStream::ColumnText(), 8-bit SQL\r\n"));
       
  1430 		DoStmtOomTestL(&ExecInsertNextStmt8L, &StmtColumnTextStreamL, dbFileName[i], dbType[i]);
       
  1431 
       
  1432 		TheTest.Printf(_L("===RSqlColumnReadStream::ColumnText(), 16-bit SQL\r\n"));
       
  1433 		DoStmtOomTestL(&ExecInsertNextStmt16L, &StmtColumnTextStreamL, dbFileName[i], dbType[i]);
       
  1434 		}
       
  1435 	}
       
  1436 
       
  1437 //RSqlParamWriteStream OOM tests
       
  1438 void ParamWriteStreamOomTestsL()
       
  1439 	{
       
  1440 	const TInt KTestCnt = 2;
       
  1441 	const TPtrC dbFileName[KTestCnt] = {KTestDb(), 	KSecureTestDb()};
       
  1442 	TDbType dbType[KTestCnt] = {ENonSecureDb, ESecureDb};
       
  1443 
       
  1444 	for(TInt i=0;i<KTestCnt;++i)
       
  1445 		{
       
  1446 		TheTest.Printf(_L("===RSqlParamWriteStream::BindBinary(), 8-bit SQL\r\n"));
       
  1447 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtParamBinaryStreamL, dbFileName[i], dbType[i]);
       
  1448 
       
  1449 		TheTest.Printf(_L("===RSqlParamWriteStream::BindBinary(), 16-bit SQL\r\n"));
       
  1450 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtParamBinaryStreamL, dbFileName[i], dbType[i]);
       
  1451 
       
  1452 		TheTest.Printf(_L("===RSqlParamWriteStream::BindText(), 8-bit SQL\r\n"));
       
  1453 		DoStmtOomTestL(&PrepareInsertPrmStmt8L, &StmtParamTextStreamL, dbFileName[i], dbType[i]);
       
  1454 
       
  1455 		TheTest.Printf(_L("===RSqlParamWriteStream::BindText(), 16-bit SQL\r\n"));
       
  1456 		DoStmtOomTestL(&PrepareInsertPrmStmt16L, &StmtParamTextStreamL, dbFileName[i], dbType[i]);
       
  1457 		}
       
  1458 	}
       
  1459 
       
  1460 //TSqlScalarFullSelectQuery OOM tests
       
  1461 void ScalarFullSelectQueryOomTestsL()
       
  1462 	{
       
  1463 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectIntL(), 8-bit SQL\r\n"));
       
  1464 	DoFullSelectOomTest(&ScalarFullSelectInt_8L);
       
  1465 
       
  1466 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectInt64L(), 8-bit SQL\r\n"));
       
  1467 	DoFullSelectOomTest(&ScalarFullSelectInt64_8L);
       
  1468 
       
  1469 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectRealL(), 8-bit SQL\r\n"));
       
  1470 	DoFullSelectOomTest(&ScalarFullSelectReal_8L);
       
  1471 
       
  1472 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectTextL(), 8-bit SQL\r\n"));
       
  1473 	DoFullSelectOomTest(&ScalarFullSelectText_8L);
       
  1474 
       
  1475 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectBinaryL(), 8-bit SQL\r\n"));
       
  1476 	DoFullSelectOomTest(&ScalarFullSelectBinary_8L);
       
  1477 
       
  1478 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectIntL(), 16-bit SQL\r\n"));
       
  1479 	DoFullSelectOomTest(&ScalarFullSelectInt_16L);
       
  1480 
       
  1481 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectInt64L(), 16-bit SQL\r\n"));
       
  1482 	DoFullSelectOomTest(&ScalarFullSelectInt64_16L);
       
  1483 
       
  1484 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectRealL(), 16-bit SQL\r\n"));
       
  1485 	DoFullSelectOomTest(&ScalarFullSelectReal_16L);
       
  1486 
       
  1487 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectTextL(), 16-bit SQL\r\n"));
       
  1488 	DoFullSelectOomTest(&ScalarFullSelectText_16L);
       
  1489 
       
  1490 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectBinaryL(), 16-bit SQL\r\n"));
       
  1491 	DoFullSelectOomTest(&ScalarFullSelectBinary_16L);
       
  1492 
       
  1493 	TheTest.Printf(_L("===TSqlScalarFullSelectQuery::SelectTextL(), 8-bit SQL, small buffer\r\n"));
       
  1494 	DoFullSelectOomTest(&ScalarFullSelectText2_8L);
       
  1495 	}
       
  1496 
       
  1497 void BlobReadStreamOomTestsL()
       
  1498 	{
       
  1499 	const TInt KTestCnt = 2;
       
  1500 	const TPtrC dbFileName[KTestCnt] = {KTestDb(), 	KSecureTestDb()};
       
  1501 	TDbType dbType[KTestCnt] = {ENonSecureDb, ESecureDb};
       
  1502 
       
  1503 	for(TInt i=0;i<KTestCnt;++i)
       
  1504 		{
       
  1505 		TheTest.Printf(_L("===RSqlBlobReadStream::OpenL()/RSqlBlobReadStream::ReadL()\r\n"));
       
  1506 		DoBlobOomTestL(&ExecInsertBlobL, &BlobReadStreamOpenL, dbFileName[i], dbType[i]);
       
  1507 
       
  1508 		TheTest.Printf(_L("===RSqlBlobReadStream::OpenL()/RSqlBlobReadStream::ReadL() + attached database\r\n"));
       
  1509 		DoBlobOomTestL(&ExecInsertBlobL, &BlobReadStreamOpenL, dbFileName[i], dbType[i], ETrue);
       
  1510 
       
  1511 		TheTest.Printf(_L("===RSqlBlobReadStream::OpenL()/RSqlBlobReadStream::SizeL()\r\n"));
       
  1512 		DoBlobOomTestL(&ExecInsertBlobL, &BlobReadStreamSizeL, dbFileName[i], dbType[i]);
       
  1513 
       
  1514 		TheTest.Printf(_L("===RSqlBlobReadStream::OpenL()/RSqlBlobReadStream::SizeL() + attached database\r\n"));
       
  1515 		DoBlobOomTestL(&ExecInsertBlobL, &BlobReadStreamSizeL, dbFileName[i], dbType[i], ETrue);
       
  1516 		}
       
  1517 	}
       
  1518 
       
  1519 void BlobWriteStreamOomTestsL()
       
  1520 	{
       
  1521 	const TInt KTestCnt = 2;
       
  1522 	const TPtrC dbFileName[KTestCnt] = {KTestDb(), 	KSecureTestDb()};
       
  1523 	TDbType dbType[KTestCnt] = {ENonSecureDb, ESecureDb};
       
  1524 
       
  1525 	for(TInt i=0;i<KTestCnt;++i)
       
  1526 		{
       
  1527 		TheTest.Printf(_L("===RSqlBlobWriteStream::OpenL()/RSqlBlobWriteStream::WriteL()\r\n"));
       
  1528 		DoBlobOomTestL(&ExecInsertBlobL, &BlobWriteStreamOpenL, dbFileName[i], dbType[i]);
       
  1529 
       
  1530 		TheTest.Printf(_L("===RSqlBlobWriteStream::OpenL()/RSqlBlobWriteStream::WriteL() + attached database\r\n"));
       
  1531 		DoBlobOomTestL(&ExecInsertBlobL, &BlobWriteStreamOpenL, dbFileName[i], dbType[i], ETrue);
       
  1532 
       
  1533 		TheTest.Printf(_L("===RSqlBlobWriteStream::OpenL()/RSqlBlobWriteStream::SizeL()\r\n"));
       
  1534 		DoBlobOomTestL(&ExecInsertBlobL, &BlobWriteStreamSizeL, dbFileName[i], dbType[i]);
       
  1535 
       
  1536 		TheTest.Printf(_L("===RSqlBlobWriteStream::OpenL()/RSqlBlobWriteStream::SizeL() + attached database\r\n"));
       
  1537 		DoBlobOomTestL(&ExecInsertBlobL, &BlobWriteStreamSizeL, dbFileName[i], dbType[i], ETrue);
       
  1538 		}
       
  1539 	}
       
  1540 	
       
  1541 void BlobWholeOomTestsL()
       
  1542 	{
       
  1543 	const TInt KTestCnt = 2;
       
  1544 	const TPtrC dbFileName[KTestCnt] = {KTestDb(), 	KSecureTestDb()};
       
  1545 	TDbType dbType[KTestCnt] = {ENonSecureDb, ESecureDb};
       
  1546 
       
  1547 	for(TInt i=0;i<KTestCnt;++i)
       
  1548 		{
       
  1549 		TheTest.Printf(_L("===TSqlBlob::GetLC()\r\n"));
       
  1550 		DoBlobOomTestL(&ExecInsertBlobL, &BlobWholeGet1L, dbFileName[i], dbType[i]);
       
  1551 
       
  1552 		TheTest.Printf(_L("===TSqlBlob::Get()\r\n"));
       
  1553 		DoBlobOomTestL(&ExecInsertBlobL, &BlobWholeGet2L, dbFileName[i], dbType[i]);
       
  1554 
       
  1555 		TheTest.Printf(_L("===TSqlBlob::SetL()\r\n"));
       
  1556 		DoBlobOomTestL(&ExecInsertBlobL, &BlobWholeSetL, dbFileName[i], dbType[i]);
       
  1557 		}
       
  1558 	}
       
  1559 
       
  1560 void DoTestsL()
       
  1561 	{
       
  1562 	TheTest.Start(_L("SQL OOM tests - 2"));
       
  1563 	
       
  1564 	StmtOomTestsL();
       
  1565 
       
  1566 	StmtOomNegativeTestsL();
       
  1567 
       
  1568 	ColumnReadStreamOomTestsL();
       
  1569 
       
  1570 	ParamWriteStreamOomTestsL();
       
  1571 
       
  1572 	ScalarFullSelectQueryOomTestsL();
       
  1573 
       
  1574 	BlobReadStreamOomTestsL();
       
  1575 
       
  1576 	BlobWriteStreamOomTestsL();
       
  1577 	
       
  1578 	BlobWholeOomTestsL();
       
  1579 	}
       
  1580 
       
  1581 TInt E32Main()
       
  1582 	{
       
  1583 	TheTest.Title();
       
  1584 
       
  1585 	CTrapCleanup* tc = CTrapCleanup::New();
       
  1586 
       
  1587 	__UHEAP_MARK;
       
  1588 
       
  1589 	CreateTestDir();
       
  1590 	DeleteTestFiles();
       
  1591 
       
  1592 	TRAPD(err, DoTestsL());
       
  1593 	DeleteTestFiles();
       
  1594 	TEST2(err, KErrNone);
       
  1595 
       
  1596 	__UHEAP_MARKEND;
       
  1597 
       
  1598 	TheTest.End();
       
  1599 	TheTest.Close();
       
  1600 
       
  1601 	delete tc;
       
  1602 
       
  1603 	User::Heap().Check();
       
  1604 	return KErrNone;
       
  1605 	}