sl@0: // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "t_sqloom.h" sl@0: sl@0: RTest TheTest(_L("t_sqloom2 test")); sl@0: sl@0: const TInt KSqlBufMaxLen = 16 * 1024; sl@0: const TInt KBlobStrLen = KSqlBufMaxLen / 2 - 100; sl@0: const TInt KBlobLen = KBlobStrLen; sl@0: sl@0: TBuf8 TheSqlBuf; sl@0: TBuf8 TheSqlBuf2; sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////// RSqlStatement OOM tests /////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: _LIT8(KSqlDbString, "BEGIN;\ sl@0: CREATE TABLE BBB(Fld1 INTEGER, Fld2 BIGINT, Fld3 DOUBLE, Fld4 TEXT, Fld5 LONGBLOB);\ sl@0: INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(4562, 123456789012345, 78612.0091, 'text data');\ sl@0: COMMIT;"); sl@0: _LIT8(KSqlDbString2,"INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(1, 34, 10.9897, 'data2');"); sl@0: sl@0: const TInt KLongColumnSize = 3013; sl@0: const TInt KLongParameterSize = 4501; sl@0: sl@0: #define MAX(a, b) ((a) > (b) ? (a) : (b)) sl@0: sl@0: static TUint16 TheTextColumnData[MAX(KLongColumnSize, KLongParameterSize)]; sl@0: static TUint8 TheBinaryColumnData[MAX(KLongColumnSize, KLongParameterSize) * sizeof(TUint16)]; sl@0: sl@0: //"RSqlStatement::Prepare()" OOM test (8-bit SELECT SQL statement) sl@0: void PrepareStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT8(KSqlString, "SELECT * FROM BBB WHERE Fld1=? AND Fld4<>?"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::PrepareL()" OOM test (8-bit SELECT SQL statement) sl@0: void PrepareStmt8_2L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT8(KSqlString, "SELECT * FROM BBB WHERE Fld1=? AND Fld4<>?"); sl@0: aStmt.PrepareL(aDb, KSqlString); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare()" OOM test (8-bit SELECT SQL statement), syntax error sl@0: void PrepareBadStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT8(KSqlString, "SELECT123 * FROM BBB WHERE Fld1=? AND Fld4<>?"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare()" OOM test (8-bit SELECT SQL statement, move next) sl@0: void PrepareMoveStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT8(KSqlString, "SELECT * FROM BBB WHERE Fld1=? AND Fld4<>?"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString); sl@0: User::LeaveIfError(err); sl@0: err = aStmt.BindInt(0, 1); sl@0: User::LeaveIfError(err); sl@0: err = aStmt.BindText(1, _L("data244weewfn43wr83224iu23ewkjfbrektug4i433b3k45b")); sl@0: User::LeaveIfError(err); sl@0: err = aStmt.Next(); sl@0: if(err == KSqlAtRow) sl@0: { sl@0: err = KErrNone; sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare()" OOM test (8-bit INSERT SQL statement) sl@0: void PrepareInsertStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT8(KSqlString, "INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(2, 22, 22.2222, '2-2-2-2');"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare(), RSqlStatement::Exec(), RSqlStatement::Next()" OOM test (8-bit INSERT SQL statement, long column) sl@0: void ExecInsertNextStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT8(KSqlString1, "INSERT INTO BBB(fld1, fld2, fld3, fld4, fld5) VALUES(10, 100, 100.001, :Prm1, :Prm2);"); sl@0: _LIT8(KSqlString2, "SELECT * FROM BBB WHERE fld1 = 10"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString1); sl@0: if(err == KErrNone) sl@0: { sl@0: for(TInt i=0;i= 0) sl@0: { sl@0: aStmt.Close(); sl@0: err = aStmt.Prepare(aDb, KSqlString2); sl@0: if(err == KErrNone) sl@0: { sl@0: err = aStmt.Next(); sl@0: } sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare()" OOM test (8-bit INSERT SQL statement with parameters) sl@0: void PrepareInsertPrmStmt8L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT8(KSqlString, "INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(:Prm0, :Prm1, :Prm2, :Prm3);"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare()" OOM test (16-bit SELECT SQL statement) sl@0: void PrepareStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT(KSqlString, "SELECT * FROM BBB"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::PrepareL()" OOM test (16-bit SELECT SQL statement) sl@0: void PrepareStmt16_2L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT(KSqlString, "SELECT * FROM BBB"); sl@0: aStmt.PrepareL(aDb, KSqlString); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare()" OOM test (16-bit SELECT SQL statement), syntax error sl@0: void PrepareBadStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT(KSqlString, "23478SELECT * FROM BBB"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare()" OOM test (16-bit SELECT SQL statement, move next) sl@0: void PrepareMoveStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT(KSqlString, "SELECT * FROM BBB"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString); sl@0: if(err == KErrNone) sl@0: { sl@0: err = aStmt.Next(); sl@0: if(err == KSqlAtRow) sl@0: { sl@0: err = KErrNone; sl@0: } sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare()" OOM test (16-bit INSERT SQL statement) sl@0: void PrepareInsertStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT(KSqlString, "INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(2, 22, 22.2222, '2-2-2-2');"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare(), RSqlStatement::Exec(), RSqlStatement::Next()" OOM test (16-bit INSERT SQL statement, long column) sl@0: void ExecInsertNextStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT(KSqlString1, "INSERT INTO BBB(fld1, fld2, fld3, fld4, fld5) VALUES(10, 100, 100.001, :Prm1, :Prm2);"); sl@0: _LIT(KSqlString2, "SELECT * FROM BBB WHERE fld1 = 10"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString1); sl@0: if(err == KErrNone) sl@0: { sl@0: for(TInt i=0;i= 0) sl@0: { sl@0: aStmt.Close(); sl@0: err = aStmt.Prepare(aDb, KSqlString2); sl@0: if(err == KErrNone) sl@0: { sl@0: err = aStmt.Next(); sl@0: } sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Prepare()" OOM test (16-bit INSERT SQL statement with parameters) sl@0: void PrepareInsertPrmStmt16L(RSqlDatabase& aDb, RSqlStatement& aStmt) sl@0: { sl@0: _LIT(KSqlString, "INSERT INTO BBB(fld1, fld2, fld3, fld4) VALUES(:Prm0, :Prm1, :Prm2, :Prm3);"); sl@0: TInt err = aStmt.Prepare(aDb, KSqlString); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1617 sl@0: @SYMTestCaseDesc RSqlStatement::Prepare() OOM test sl@0: Precondition: the database exists, opened, some record(s) inserted. sl@0: The test calls the given as an argument function while simulating OOM failures sl@0: and checks that there are no memory and resource leaks. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlStatement::Prepare() OOM test sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void DoStmtPrepareOomTestL(TStmtFuncPtrL aStmtFuncPtrL, const TDesC& aDbFileName, TDbType aDbType, TInt aExpectedError = KErrNone) sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1617 RSqlStatement::Prepare() - OOM test")); sl@0: RSqlSecurityPolicy securityPolicy; sl@0: CreateTestSecurityPolicy(securityPolicy); sl@0: for(TInt i=0;i<(TInt)(sizeof(TheOomTestType)/sizeof(TheOomTestType[0]));++i) sl@0: { sl@0: RSqlDatabase::Delete(aDbFileName); sl@0: RSqlDatabase db; sl@0: TInt err = aDbType == ESecureDb ? db.Create(aDbFileName, securityPolicy) : db.Create(aDbFileName); sl@0: TEST2(err, KErrNone); sl@0: err = db.Exec(KSqlDbString); sl@0: TEST(err >= 0); sl@0: //The next operation is executed to force the SQL server side session to make one memory allocation sl@0: //for the statement handle in its RDbObjContainer contrainer data member. Otherwise the OOM test will fail, sl@0: //because the server side session will do one additional allocation, which stays alive untill the sl@0: //session gets closed. sl@0: RSqlStatement dummyStmt; sl@0: err = dummyStmt.Prepare(db, _L("SELECT * FROM BBB")); sl@0: TEST2(err, KErrNone); sl@0: dummyStmt.Close(); sl@0: sl@0: err = KErrNoMemory; sl@0: const TInt KMaxAllocation = TheOomTestType[i] == EServerSideTest ? KStmtOomTestAllocLimitServer : KStmtOomTestAllocLimitClient; sl@0: TInt allocationNo = 0; sl@0: TInt failingAllocationNo = 0;//the real exit point of the OOM test. allocationNo is set KMaxAllocation times. sl@0: while(allocationNo < KMaxAllocation) sl@0: { sl@0: MarkHandles(); sl@0: MarkAllocatedCells(); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: SetHeapFailure(TheOomTestType[i], ++allocationNo); sl@0: sl@0: RSqlStatement stmt; sl@0: TRAP(err, (*aStmtFuncPtrL)(db, stmt)); sl@0: stmt.Close(); sl@0: if(err != KErrNoMemory) sl@0: { sl@0: TEST2(err, aExpectedError); sl@0: } sl@0: else sl@0: { sl@0: failingAllocationNo = allocationNo; sl@0: } sl@0: sl@0: ResetHeapFailure(TheOomTestType[i]); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: CheckAllocatedCells(); sl@0: CheckHandles(); sl@0: } sl@0: sl@0: db.Close(); sl@0: TEST2(err, aExpectedError); sl@0: PrintEndOfOomTest(TheOomTestType[i], failingAllocationNo); sl@0: } sl@0: //Delete the database file sl@0: RSqlDatabase::Delete(aDbFileName); sl@0: securityPolicy.Close(); sl@0: } sl@0: sl@0: //"RSqlStatement::Reset()" OOM test sl@0: void ResetStmtL(RSqlStatement& aStmt) sl@0: { sl@0: TInt err = aStmt.Next(); sl@0: if(err == KErrNone) sl@0: { sl@0: err = aStmt.Reset(); sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Exec()" OOM test sl@0: void ExecStmtL(RSqlStatement& aStmt) sl@0: { sl@0: TInt err = aStmt.Exec(); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::Next()" OOM test sl@0: void NextStmtL(RSqlStatement& aStmt) sl@0: { sl@0: TInt err = aStmt.Next(); sl@0: if(err == KErrNone) sl@0: { sl@0: err = aStmt.Next(); sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::ParameterIndex()" OOM test sl@0: void StmtParameterIndexL(RSqlStatement& aStmt) sl@0: { sl@0: TInt err = aStmt.ParameterIndex(_L(":Prm2")); sl@0: if(err == 1) //":Prm2" index is 1 sl@0: { sl@0: err = KErrNone; sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::ParameterName()" OOM test sl@0: void StmtParameterNameL(RSqlStatement& aStmt) sl@0: { sl@0: // _LIT(KExcpected, ":Prm2"); sl@0: TPtrC paramName; sl@0: TInt err = aStmt.ParameterName(1, paramName); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::ParamName()" OOM test sl@0: void StmtParamNameL(RSqlStatement& aStmt) sl@0: { sl@0: TPtrC paramName; sl@0: TInt err = aStmt.ParamName(1, paramName); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::ColumnIndex()" OOM test sl@0: void StmtColumnIndexL(RSqlStatement& aStmt) sl@0: { sl@0: TInt err = aStmt.ColumnIndex(_L("fLd3")); sl@0: if(err == 2) //"fLd3" index is 2 sl@0: { sl@0: err = KErrNone; sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::ColumnName()" OOM test sl@0: void StmtColumnNameL(RSqlStatement& aStmt) sl@0: { sl@0: //_LIT(KExpected, "fLd3"); sl@0: TPtrC colName; sl@0: TInt err = aStmt.ColumnName(2, colName); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: sl@0: //"RSqlStatement::ColumnType()" OOM test sl@0: void StmtColumnTypeL(RSqlStatement& aStmt) sl@0: { sl@0: TSqlColumnType coltype = aStmt.ColumnType(2); sl@0: TEST(coltype == ESqlReal); sl@0: } sl@0: sl@0: //"RSqlStatement::ColumnSize()" OOM test sl@0: void StmtColumnSizeL(RSqlStatement& aStmt) sl@0: { sl@0: TInt colsize = aStmt.ColumnSize(2); sl@0: TEST(colsize == sizeof(TReal)); sl@0: } sl@0: sl@0: //"RSqlStatement::BindNull()" OOM test sl@0: void StmtBindNullL(RSqlStatement& aStmt) sl@0: { sl@0: TInt err = aStmt.BindNull(1); sl@0: //The bindings will be transferred on the server side right before Next() or Exec() call sl@0: if(err == KErrNone) sl@0: { sl@0: err = aStmt.Exec(); sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::BindInt()" OOM test sl@0: void StmtBindIntL(RSqlStatement& aStmt) sl@0: { sl@0: TInt val = 184; sl@0: TInt err = aStmt.BindInt(0, val); sl@0: //The bindings will be transferred on the server side right before Next() or Exec() call sl@0: if(err == KErrNone) sl@0: { sl@0: err = aStmt.Exec(); sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::BindInt64()" OOM test sl@0: void StmtBindInt64L(RSqlStatement& aStmt) sl@0: { sl@0: TInt64 val = MAKE_TINT64(0x00FF00FF, 0x12345678); sl@0: TInt err = aStmt.BindInt64(1, val); sl@0: //The bindings will be transferred on the server side right before Next() or Exec() call sl@0: if(err == KErrNone) sl@0: { sl@0: err = aStmt.Exec(); sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::BindReal()" OOM test sl@0: void StmtBindRealL(RSqlStatement& aStmt) sl@0: { sl@0: TReal val = 25.2423; sl@0: TInt err = aStmt.BindReal(2, val); sl@0: //The bindings will be transferred on the server side right before Next() or Exec() call sl@0: if(err == KErrNone) sl@0: { sl@0: err = aStmt.Exec(); sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: //"RSqlStatement::BindText()" OOM test sl@0: void StmtBindTextL(RSqlStatement& aStmt) sl@0: { sl@0: for(TInt i=0;i> 8) & 0xFF)); sl@0: } sl@0: } sl@0: sl@0: //"RSqlStatement::ColumnBinary()" OOM test sl@0: void StmtColumnBinary2L(RSqlStatement& aStmt) sl@0: { sl@0: TPtrC8 val; sl@0: TInt err = aStmt.ColumnBinary(4, val); sl@0: User::LeaveIfError(err); sl@0: TEST(val.Length() == KLongColumnSize * sizeof(TUint16)); sl@0: for(TInt i=0,j=0;i> 8) & 0xFF)); sl@0: } sl@0: } sl@0: sl@0: //"RSqlStatement::ColumnBinary()" OOM test sl@0: void StmtColumnBinary3L(RSqlStatement& aStmt) sl@0: { sl@0: TPtr8 val(TheBinaryColumnData, KLongColumnSize * sizeof(TUint16)); sl@0: TInt err = aStmt.ColumnBinary(4, val); sl@0: User::LeaveIfError(err); sl@0: TEST(val.Length() == KLongColumnSize * sizeof(TUint16)); sl@0: for(TInt i=0,j=0;i> 8) & 0xFF)); sl@0: } sl@0: } sl@0: sl@0: //"RSqlStatement::ColumnCount()" OOM test sl@0: void StmtColumnCount(RSqlStatement& aStmt) sl@0: { sl@0: TInt cnt = aStmt.ColumnCount(); sl@0: TEST2(cnt, 5); sl@0: } sl@0: sl@0: //"RSqlStatement::DeclaredColumnType()" OOM test sl@0: void StmtDeclaredColumnTypeL(RSqlStatement& aStmt) sl@0: { sl@0: TInt cnt = aStmt.ColumnCount(); sl@0: TEST2(cnt, 5); sl@0: const TSqlColumnType KColTypes[] = {ESqlInt, ESqlInt, ESqlReal, ESqlText, ESqlBinary}; sl@0: for(TInt i=0;i> 8) & 0xFF)); sl@0: } sl@0: } sl@0: sl@0: //"RSqlColumnReadStream::ColumnText()" OOM test sl@0: void StmtColumnTextStreamL(RSqlStatement& aStmt) sl@0: { sl@0: RSqlColumnReadStream strm; sl@0: CleanupClosePushL(strm); sl@0: TInt err = strm.ColumnText(aStmt, 3); sl@0: User::LeaveIfError(err); sl@0: strm.ReadL(TheTextColumnData, KLongColumnSize); sl@0: CleanupStack::PopAndDestroy(&strm); sl@0: for(TInt i=0;i= 0); sl@0: err = db.Exec(KSqlDbString2); sl@0: TEST(err >= 0); sl@0: sl@0: err = KErrNoMemory; sl@0: const TInt KMaxAllocation = TheOomTestType[i] == EServerSideTest ? KStmtOomTestAllocLimitServer : KStmtOomTestAllocLimitClient; sl@0: TInt allocationNo = 0; sl@0: TInt failingAllocationNo = 0;//the real exit point of the OOM test. allocationNo is set KMaxAllocation times. sl@0: while(allocationNo < KMaxAllocation) sl@0: { sl@0: MarkHandles(); sl@0: MarkAllocatedCells(); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: RSqlStatement stmt; sl@0: TRAP(err, (*aStmtPrepareFuncPtrL)(db, stmt)); sl@0: TEST2(err, KErrNone); sl@0: sl@0: SetHeapFailure(TheOomTestType[i], ++allocationNo); sl@0: sl@0: TRAP(err, (*aStmtTestFuncPtrL)(stmt)); sl@0: sl@0: //ResetHeapFailure() has to be called before stmt.Close() because, sl@0: //otherwise it will panic the server (the server resource count, marked by sl@0: //SetHeapFailure() call, is 1 (there is one prepared statement)) sl@0: ResetHeapFailure(TheOomTestType[i]); sl@0: sl@0: stmt.Close(); sl@0: sl@0: if(err != KErrNoMemory) sl@0: { sl@0: TEST2(err, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: failingAllocationNo = allocationNo; sl@0: } sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: CheckAllocatedCells(); sl@0: CheckHandles(); sl@0: } sl@0: sl@0: db.Close(); sl@0: TEST2(err, KErrNone); sl@0: PrintEndOfOomTest(TheOomTestType[i], failingAllocationNo); sl@0: } sl@0: //Delete the database file sl@0: RSqlDatabase::Delete(aDbFileName); sl@0: securityPolicy.Close(); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: ////////////////// RSqlBlobReadStream, RSqlBlobWriteStream - OOM tests ///////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: //RSqlBlobReadStream, RSqlBlobWriteStream - OOM test preparation. sl@0: void ExecInsertBlobL(RSqlDatabase& aDb) sl@0: { sl@0: _LIT8(KSqlString1, "CREATE TABLE BBB(Fld1 INTEGER, Fld2 BIGINT, Fld3 DOUBLE, Fld4 TEXT, Fld5 LONGBLOB)"); sl@0: TInt err = aDb.Exec(KSqlString1); sl@0: User::LeaveIfError(err); sl@0: _LIT8(KSqlString2, "INSERT INTO BBB(fld1, fld2, fld3, fld4, fld5) VALUES(10, 100, 100.001, 'AAA', x'"); sl@0: TheSqlBuf.Copy(KSqlString2); sl@0: for(TInt i=0;i 0) sl@0: { sl@0: strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1, aAttachDbName); sl@0: } sl@0: else sl@0: { sl@0: strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1); sl@0: } sl@0: const TInt KReadOpCnt = 8; sl@0: for(TInt j=0;j 0) sl@0: { sl@0: strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1, aAttachDbName); sl@0: } sl@0: else sl@0: { sl@0: strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1); sl@0: } sl@0: TInt size = strm.SizeL(); sl@0: TEST2(size, KBlobLen); sl@0: CleanupStack::PopAndDestroy(&strm); sl@0: } sl@0: sl@0: //"RSqlBlobWriteStream::OpenL()/RSqlBlobWriteStream::WriteL()" OOM test sl@0: void BlobWriteStreamOpenL(RSqlDatabase& aDb, const TDesC& aAttachDbName) sl@0: { sl@0: RSqlBlobWriteStream strm; sl@0: CleanupClosePushL(strm); sl@0: if(aAttachDbName.Length() > 0) sl@0: { sl@0: strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1, aAttachDbName); sl@0: } sl@0: else sl@0: { sl@0: strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1); sl@0: } sl@0: const TInt KWriteOpCnt = 8; sl@0: TheSqlBuf.SetLength(KBlobLen / KWriteOpCnt); sl@0: TheSqlBuf.Fill(TChar('Z')); sl@0: for(TInt j=0;j 0) sl@0: { sl@0: strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1, aAttachDbName); sl@0: } sl@0: else sl@0: { sl@0: strm.OpenL(aDb, _L("BBB"), _L("fld5"), 1); sl@0: } sl@0: TInt size = strm.SizeL(); sl@0: TEST2(size, KBlobLen); sl@0: CleanupStack::PopAndDestroy(&strm); sl@0: } sl@0: sl@0: //"TSqlBlob::GetLC()" OOM test sl@0: void BlobWholeGet1L(RSqlDatabase& aDb, const TDesC& aAttachDbName) sl@0: { sl@0: HBufC8* buf = NULL; sl@0: if(aAttachDbName.Length() > 0) sl@0: { sl@0: buf = TSqlBlob::GetLC(aDb, _L("BBB"), _L("fld5"), 1, aAttachDbName); sl@0: } sl@0: else sl@0: { sl@0: buf = TSqlBlob::GetLC(aDb, _L("BBB"), _L("fld5"), 1); sl@0: } sl@0: TEST(buf->Length() == KBlobStrLen); sl@0: CleanupStack::PopAndDestroy(buf); sl@0: } sl@0: sl@0: //"TSqlBlob::Get()" OOM test sl@0: void BlobWholeGet2L(RSqlDatabase& aDb, const TDesC& aAttachDbName) sl@0: { sl@0: if(aAttachDbName.Length() > 0) sl@0: { sl@0: TSqlBlob::Get(aDb, _L("BBB"), _L("fld5"), TheSqlBuf2, 1, aAttachDbName); sl@0: } sl@0: else sl@0: { sl@0: TSqlBlob::Get(aDb, _L("BBB"), _L("fld5"), TheSqlBuf2, 1); sl@0: } sl@0: } sl@0: sl@0: //"TSqlBlob::SetL()" OOM test sl@0: void BlobWholeSetL(RSqlDatabase& aDb, const TDesC& aAttachDbName) sl@0: { sl@0: if(aAttachDbName.Length() > 0) sl@0: { sl@0: TSqlBlob::SetL(aDb, _L("BBB"), _L("fld5"), TheSqlBuf, 1, aAttachDbName); sl@0: } sl@0: else sl@0: { sl@0: TSqlBlob::Get(aDb, _L("BBB"), _L("fld5"), TheSqlBuf, 1); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4091 sl@0: @SYMTestCaseDesc RSqlBlobReadStream, RSqlBlobWriteStream methods OOM tests sl@0: Precondition: the database exists, opened, some record(s) inserted. sl@0: The test calls the given as an argument function while simulating OOM failures sl@0: and checks that there are no memory and resource leaks. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlBlobReadStream, RSqlBlobWriteStream methods OOM tests sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ10410 sl@0: REQ10411 sl@0: REQ10418 sl@0: */ sl@0: void DoBlobOomTestL(TBlobPrepareFuncPtrL aBlobPrepareFuncPtrL, TBlobTestFuncPtrL aBlobTestFuncPtrL, sl@0: const TDesC& aDbFileName, TDbType aDbType, TBool aAttachDb = EFalse) sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4091 RSqlBlobReadStream, RSqlBlobWriteStream - OOM test")); sl@0: RSqlSecurityPolicy securityPolicy; sl@0: CreateTestSecurityPolicy(securityPolicy); sl@0: for(TInt i=0;i<(TInt)(sizeof(TheOomTestType)/sizeof(TheOomTestType[0]));++i) sl@0: { sl@0: RSqlDatabase::Delete(aDbFileName); sl@0: RSqlDatabase db; sl@0: TInt err = aDbType == ESecureDb ? db.Create(aDbFileName, securityPolicy) : db.Create(aDbFileName); sl@0: TEST2(err, KErrNone); sl@0: TRAP(err, (*aBlobPrepareFuncPtrL)(db)); sl@0: TEST2(err, KErrNone); sl@0: _LIT(KAttachDbName, "AttachDb"); sl@0: if(aAttachDb) sl@0: { sl@0: err = db.Attach(aDbFileName, KAttachDbName); sl@0: TEST2(err, KErrNone); sl@0: } sl@0: sl@0: err = KErrNoMemory; sl@0: const TInt KMaxAllocation = TheOomTestType[i] == EServerSideTest ? KBlobOomTestAllocLimitServer : KBlobOomTestAllocLimitClient; sl@0: TInt allocationNo = 0; sl@0: TInt failingAllocationNo = 0;//the real exit point of the OOM test. allocationNo is set KMaxAllocation times. sl@0: while(allocationNo < KMaxAllocation) sl@0: { sl@0: MarkHandles(); sl@0: MarkAllocatedCells(); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: SetHeapFailure(TheOomTestType[i], ++allocationNo); sl@0: if(aAttachDb) sl@0: { sl@0: TRAP(err, (*aBlobTestFuncPtrL)(db, KAttachDbName)); sl@0: } sl@0: else sl@0: { sl@0: TRAP(err, (*aBlobTestFuncPtrL)(db, KNullDesC)); sl@0: } sl@0: sl@0: ResetHeapFailure(TheOomTestType[i]); sl@0: sl@0: if(err != KErrNoMemory) sl@0: { sl@0: if(err != KErrNone) sl@0: { sl@0: TPtrC errmsg = db.LastErrorMessage(); sl@0: if(errmsg.Length() > 0) sl@0: { sl@0: TheTest.Printf(_L("\r\n@@@ error %d, error message: %S\r\n"), err, &errmsg); sl@0: } sl@0: } sl@0: TEST2(err, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: failingAllocationNo = allocationNo; sl@0: } sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: CheckAllocatedCells(); sl@0: CheckHandles(); sl@0: } sl@0: TEST2(err, KErrNone); sl@0: sl@0: if(aAttachDb) sl@0: { sl@0: (void)db.Detach(KAttachDbName); sl@0: } sl@0: sl@0: db.Close(); sl@0: err = RSqlDatabase::Delete(aDbFileName); sl@0: TEST2(err, KErrNone); sl@0: PrintEndOfOomTest(TheOomTestType[i], failingAllocationNo); sl@0: } sl@0: securityPolicy.Close(); sl@0: } sl@0: sl@0: void ScalarFullSelectInt_8L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: TInt val = query.SelectIntL(_L8("SELECT F1 FROM A WHERE F3 < 0")); sl@0: TEST2(val, 2); sl@0: } sl@0: sl@0: void ScalarFullSelectInt64_8L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: TInt64 val = query.SelectInt64L(_L8("SELECT F2 FROM A WHERE F1 = 1")); sl@0: TEST2(val, 10000000000LL); sl@0: } sl@0: sl@0: void ScalarFullSelectReal_8L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: TReal val = query.SelectRealL(_L8("SELECT F3 FROM A WHERE F1 = 1")); sl@0: TEST(val > 2.0 && val < 3.0); sl@0: } sl@0: sl@0: void ScalarFullSelectText_8L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: TBuf<20> buf; sl@0: TInt err = query.SelectTextL(_L8("SELECT F4 FROM A WHERE F1 = 1"), buf); sl@0: TEST2(err, KErrNone); sl@0: _LIT(KText, "NAME1234567890"); sl@0: TEST(buf == KText); sl@0: } sl@0: sl@0: void ScalarFullSelectBinary_8L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: TBuf8<20> buf; sl@0: TInt err = query.SelectBinaryL(_L8("SELECT F5 FROM A WHERE F1 = 1"), buf); sl@0: TEST2(err, KErrNone); sl@0: TEST(buf.Length() == 0); sl@0: } sl@0: sl@0: void ScalarFullSelectInt_16L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: TInt val = query.SelectIntL(_L16("SELECT F1 FROM A WHERE F3 < 0")); sl@0: TEST2(val, 2); sl@0: } sl@0: sl@0: void ScalarFullSelectInt64_16L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: TInt64 val = query.SelectInt64L(_L16("SELECT F2 FROM A WHERE F1 = 1")); sl@0: TEST2(val, 10000000000LL); sl@0: } sl@0: sl@0: void ScalarFullSelectReal_16L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: TReal val = query.SelectRealL(_L16("SELECT F3 FROM A WHERE F1 = 1")); sl@0: TEST(val > 2.0 && val < 3.0); sl@0: } sl@0: sl@0: void ScalarFullSelectText_16L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: TBuf<20> buf; sl@0: TInt err = query.SelectTextL(_L16("SELECT F4 FROM A WHERE F1 = 1"), buf); sl@0: TEST2(err, KErrNone); sl@0: _LIT(KText, "NAME1234567890"); sl@0: TEST(buf == KText); sl@0: } sl@0: sl@0: void ScalarFullSelectBinary_16L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: TBuf8<20> buf; sl@0: TInt err = query.SelectBinaryL(_L16("SELECT F5 FROM A WHERE F1 = 1"), buf); sl@0: TEST2(err, KErrNone); sl@0: TEST(buf.Length() == 0); sl@0: } sl@0: sl@0: void ScalarFullSelectText2_8L(RSqlDatabase& aDb) sl@0: { sl@0: TSqlScalarFullSelectQuery query(aDb); sl@0: HBufC* buf = HBufC::NewLC(8); sl@0: TPtr name = buf->Des(); sl@0: TInt rc = query.SelectTextL(_L8("SELECT F4 FROM A WHERE F1 = 1"), name); sl@0: TEST(rc >= 0); //the function may return only non-negative values sl@0: if(rc > 0) sl@0: { sl@0: buf = buf->ReAllocL(rc); sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PushL(buf); sl@0: name.Set(buf->Des()); sl@0: rc = query.SelectTextL(_L8("SELECT F4 FROM A WHERE F1 = 1"), name); sl@0: TEST(rc == 0); sl@0: _LIT(KText, "NAME1234567890"); sl@0: TEST(name == KText); sl@0: } sl@0: CleanupStack::PopAndDestroy(buf); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1811 sl@0: @SYMTestCaseDesc TSqlScalarFullSelectQuery functions OOM test sl@0: Precondition: the database exists. sl@0: The test simulates OOM failures while calling TSqlScalarFullSelectQuery functions sl@0: and checks that there are no memory and resource leaks. sl@0: @SYMTestPriority High sl@0: @SYMTestActions TSqlScalarFullSelectQuery methods OOM tests sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void DoFullSelectOomTest(TScalarFullSelectFuncPtrL aTestFunctionPtrL) sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1811 TSqlScalarFullSelectQuery - OOM test")); sl@0: //Create test database sl@0: RSqlDatabase db; sl@0: TInt err = db.Create(KTestDb); sl@0: TEST2(err, KErrNone); sl@0: err = db.Exec(_L("CREATE TABLE A(F1 INTEGER, F2 INTEGER, F3 FLOAT, F4 TEXT, F5 BLOB)")); sl@0: TEST(err >= 0); sl@0: err = db.Exec(_L("INSERT INTO A(F1, F2, F3, F4, F5) VALUES(1, 10000000000, 2.54, 'NAME1234567890', NULL)")); sl@0: TEST2(err, 1); sl@0: err = db.Exec(_L("INSERT INTO A(F1, F2, F3, F4) VALUES(2, 200, -1.11, 'ADDRESS')")); sl@0: TEST2(err, 1); sl@0: db.Close(); sl@0: //OOM test loop sl@0: for(TInt i=0;i<(TInt)(sizeof(TheOomTestType)/sizeof(TheOomTestType[0]));++i) sl@0: { sl@0: err = KErrNoMemory; sl@0: const TInt KMaxAllocation = TheOomTestType[i] == EServerSideTest ? KStmtOomTestAllocLimitServer : KStmtOomTestAllocLimitClient; sl@0: TInt allocationNo = 0; sl@0: TInt failingAllocationNo = 0;//the real exit point of the OOM test. allocationNo is set KMaxAllocation times. sl@0: while(allocationNo < KMaxAllocation) sl@0: { sl@0: MarkHandles(); sl@0: MarkAllocatedCells(); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: if(TheOomTestType[i] == EServerSideTest) sl@0: {//We will delay the heap failure simulation, until the database is opened sl@0: SetDbHeapFailure(TheOomTestType[i], ++allocationNo, ETrue); sl@0: } sl@0: sl@0: err = db.Open(KTestDb); sl@0: TEST2(err, KErrNone); sl@0: sl@0: if(TheOomTestType[i] == EClientSideTest) sl@0: { sl@0: SetDbHeapFailure(TheOomTestType[i], ++allocationNo); sl@0: } sl@0: sl@0: TRAP(err, (*aTestFunctionPtrL)(db)); sl@0: db.Close(); sl@0: if(err != KErrNoMemory) sl@0: { sl@0: TEST2(err, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: failingAllocationNo = allocationNo; sl@0: } sl@0: sl@0: ResetDbHeapFailure(TheOomTestType[i]); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: CheckAllocatedCells(); sl@0: CheckHandles(); sl@0: } sl@0: TEST2(err, KErrNone); sl@0: PrintEndOfOomTest(TheOomTestType[i], failingAllocationNo); sl@0: } sl@0: //Delete the database file sl@0: RSqlDatabase::Delete(KTestDb); sl@0: } sl@0: sl@0: //RSqlStatement OOM tests sl@0: void StmtOomTestsL() sl@0: { sl@0: const TInt KTestCnt = 2; sl@0: const TPtrC dbFileName[KTestCnt] = {KTestDb(), KSecureTestDb()}; sl@0: TDbType dbType[KTestCnt] = {ENonSecureDb, ESecureDb}; sl@0: sl@0: for(TInt i=0;i