sl@0: // Copyright (c) 2006-2009 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: #if (!defined __SQLFN_H__) sl@0: #define __SQLFN_H__ sl@0: #include sl@0: #include "Te_SQL_SuiteStepBase.h" sl@0: #include "hashing.h" sl@0: sl@0: #include // For RFileReadStream etc. sl@0: sl@0: class CSQLFnStep : public CTe_SQL_SuiteStepBase sl@0: { sl@0: public: sl@0: CSQLFnStep(); sl@0: ~CSQLFnStep(); sl@0: virtual TVerdict doTestStepL(); sl@0: virtual TVerdict doTestStepPostambleL(); sl@0: sl@0: // This big enumeration defines the values associated with particular sl@0: // actions (as read from a config file and converted to the numeric sl@0: // equivalent by the CSQLTEFAction class). sl@0: enum TSqlDbFns { sl@0: Ectrl_endblock=0, Ectrl_newblock, Ectrl_function, sl@0: Ectrl_waitA, Ectrl_signalA, Ectrl_waitB, Ectrl_signalB, sl@0: Ectrl_sleep, Ectrl_eightbit, Ectrl_async, sl@0: sl@0: Efn_nop, Efn_create, Efn_createl, sl@0: Efn_createsp, sl@0: Efn_open, Efn_openl, sl@0: Efn_attach, Efn_detach, Efn_copy, sl@0: Efn_delete, Efn_close, Efn_exec, sl@0: Efn_setisolationlevel, Efn_lasterrormessage, sl@0: Efn_reservedrivespace, Efn_freereservedspace, sl@0: Efn_getreserveaccess, Efn_releasereserveaccess, sl@0: sl@0: Erstmt_prepare, Erstmt_preparel, Erstmt_close, sl@0: Erstmt_atrow, Erstmt_reset, Erstmt_exec, Erstmt_next, sl@0: Erstmt_paramindex, Erstmt_colindex, Erstmt_coltype, sl@0: Erstmt_colsize, Erstmt_bindnull, Erstmt_bindint, sl@0: Erstmt_bindint64, Erstmt_bindreal, Erstmt_bindtext, sl@0: Erstmt_bindbigtext, Erstmt_bindbinary, Erstmt_isnull, sl@0: Erstmt_colint, Erstmt_colint64, Erstmt_colreal, sl@0: Erstmt_coltextL, Erstmt_coltextP, Erstmt_coltextD, sl@0: Erstmt_colbinL, Erstmt_colbinP, Erstmt_colbinD, sl@0: sl@0: Esp_create, Esp_createl, Esp_close, Esp_setdbpolicy, sl@0: Esp_setpolicy, Esp_externalizel, Esp_internalizel, sl@0: sl@0: Estreamwrite_bindtext, Estreamwrite_bindbinary, sl@0: Estreamread_columntext, Estreamread_columnbinary, sl@0: Edefineconfig, sl@0: sl@0: // Marks the last item in the enumeration. sl@0: Efn_undefined, sl@0: }; sl@0: // Methods to handle our simple semaphore thread syncing.. sl@0: void SignalA(TInt ai) { isemA.Signal(ai); }; sl@0: void WaitA() { isemA.Wait(); }; sl@0: void SignalB(TInt ai) { isemB.Signal(ai); }; sl@0: void WaitB() { isemB.Wait(); }; sl@0: sl@0: // Utility functions. These should move into a separate class, this sl@0: // is untidy. sl@0: TInt ActionNoToErrEnum(const TDesC&, const TInt, TPtrC &); sl@0: TInt ErrStringToEnum(TPtrC &aerr); sl@0: void ErrEnumToString(const TInt &, TPtrC &); sl@0: const TPtrC SqlColumnTypeToString( TSqlColumnType & ); sl@0: TSqlColumnType StringToSqlColumnType( const TDesC & ); sl@0: void ReportOnError( const TDesC &, const TDesC &, const TDesC &, sl@0: const TInt, const TInt ); sl@0: TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TPtrC& ); sl@0: TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TInt& ); sl@0: TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TReal& ); sl@0: void CommaSeparated( const TPtrC &, TInt&, TInt& ); sl@0: void CommaSeparated( const TPtrC &, TInt&, TPtrC& ); sl@0: void CommaSeparated( const TPtrC &, TPtrC&, TPtrC& ); sl@0: TInt FileSize( const TPtrC & ); sl@0: TInt CompareBinaryAgainstFileL(const TDesC8&, const TFileName&); sl@0: TInt CompareTextAgainstFileL(const TDesC&, const TFileName&); sl@0: TInt CompareTextStreamAgainstFileL(RReadStream& , TInt, const TPtrC& ); sl@0: TInt CompareBinaryStreamAgainstFileL(RReadStream& , TInt, const TPtrC& ); sl@0: void WriteFileToStreamL(RWriteStream& , const TPtrC& ); sl@0: sl@0: // Top-level method. The third parameter is the config block to sl@0: // use. sl@0: void SQLDbStepL(const TPtrC &); sl@0: sl@0: // Function=whatever. This function recognizes the third parameter and sl@0: // calls a (code-driven) test. sl@0: virtual void ResolveTestFunctionL( const TDesC&, const TInt, const TPtrC &) sl@0: = 0; sl@0: sl@0: /* sl@0: * These methods are wrappers around the RSqlDatabase methods of sl@0: * the same (or similar) name. Includes error checking etc. sl@0: */ sl@0: TBool Create(const TPtrC&, const TDesC&, TInt); sl@0: TBool CreateL_(const TPtrC&, const TDesC&, TInt); sl@0: TBool CreateSP(const TPtrC&, const TDesC&, TInt); sl@0: TBool Open(const TPtrC&, const TDesC&, TInt); sl@0: TBool OpenL_(const TPtrC&, const TDesC&, TInt); sl@0: void Close(); sl@0: TBool Delete(const TPtrC&, const TDesC&, TInt); sl@0: sl@0: /* sl@0: * The next three methods are newer.. sl@0: */ sl@0: void Attach(const TPtrC&, const TDesC&, TInt); sl@0: void Detach(const TPtrC&, const TDesC&, TInt); sl@0: void Copy(const TPtrC&, const TDesC&, TInt); sl@0: sl@0: void LastErrorMessage(const TPtrC&); sl@0: void Exec(const TPtrC&, const TDesC&, TInt); sl@0: void SetIsolationLevel(const TPtrC&, const TDesC&, TInt); sl@0: sl@0: /* sl@0: * These methods are wrappers around the RSqlStatement methods of sl@0: * the same (or similar) name. Includes error checking etc. sl@0: */ sl@0: void Prepare(const TPtrC &, const TDesC&, TInt); sl@0: void PrepareL_(const TPtrC &, const TDesC&, TInt); sl@0: void AtRow(const TPtrC&); sl@0: void Reset(const TDesC&, TInt); sl@0: void Close(TInt); sl@0: void Next(TPtrC&, const TDesC&, TInt); sl@0: TInt ParamIndex(const TDesC&, const TDesC&, TInt); sl@0: TInt ColumnIndex(const TPtrC&, const TDesC&, TInt); sl@0: void ColumnType(const TInt&, const TPtrC&); sl@0: void ColumnSize(const TInt&, const TInt&); sl@0: void BindNull(const TInt&, const TDesC&, const TInt); sl@0: void BindInt(const TInt&, const TInt&, const TDesC&, const TInt); sl@0: void BindInt64(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void BindReal(const TInt&, const TReal &, const TDesC&, const TInt); sl@0: void BindText(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void BindBigTextL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void BindBinaryL(const TInt&, const TDesC&, const TDesC&, const TInt); sl@0: sl@0: void IsNull(const TInt&, const TPtrC&); sl@0: void ColumnInt(const TInt&, const TInt&); sl@0: void ColumnInt64(const TInt&, const TPtrC&); sl@0: void ColumnReal(const TInt&, const TReal&); sl@0: void ColumnTextL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void ColumnTextPL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void ColumnTextDL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void ColumnBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void ColumnBinaryPL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void ColumnBinaryDL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void SWBindTextL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void SWBindBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void SRColumnTextL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void SRColumnBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt); sl@0: void ReserveDriveSpace(TInt, const TDesC&, const TInt); sl@0: void FreeReservedSpace(); sl@0: void GetReserveAccess(const TDesC&, const TInt); sl@0: void ReleaseReserveAccess(); sl@0: sl@0: /* sl@0: * These are the methods associated with setting up a security sl@0: * policy for a secure database sl@0: */ sl@0: TBool SPCreate(const TDesC&, const TInt); sl@0: TBool SPCreate(const TPtrC&, const TDesC&, const TInt); sl@0: void SPClose(); sl@0: TBool SPSetDBPolicy(const TPtrC&, const TDesC&, const TInt); sl@0: TBool SPSetPolicy(const TPtrC&, const TDesC&, const TInt); sl@0: /* void SPDefaultPolicy(const TDesC&, const TDesC&, const TInt); sl@0: void SPDBPolicy(const TDesC&, const TDesC&, const TInt); sl@0: void SPPolicy(const TDesC&, const TDesC&, const TInt); sl@0: */ void SPExternalize(const TPtrC&, const TDesC&, const TInt); sl@0: void SPInternalize(const TPtrC&, const TDesC&, const TInt); sl@0: sl@0: static const TInt KConfigItemMaxNameLength = 30; sl@0: static const TInt KConfigItemMaxStringLength = 30; sl@0: static const TInt KStatementFunMaxLength = 30; sl@0: sl@0: private: sl@0: // Arbitrary. sl@0: static const TInt KTEFSQLSizeError = 98989898; sl@0: static const TInt KTEFSQLUnknownError = 98989897; sl@0: sl@0: protected: sl@0: TBool i8bit; sl@0: TBool iasync; sl@0: TPtrC8* icfg; sl@0: RSqlDatabase isqldb; sl@0: RSqlStatement isqlst; sl@0: RSqlSecurityPolicy isqlsp; sl@0: sl@0: // This is where we store the current column and parameter indices. sl@0: RArray icidxs, ipidxs; sl@0: sl@0: // Now the arrays of RBuf[8]s, these keep buffers in scope between sl@0: // binding and exec'ing. sl@0: RArray iBindRBufarr; sl@0: RArray iBindRBuf8arr; sl@0: sl@0: // Various methods do stuff with files, so we're often going to need sl@0: // an RFs, lets create/destroy it in the constructor/destructor. sl@0: RFs irfs; sl@0: sl@0: // This semaphore is used to synchronize things when we have multiple sl@0: // threads running (as supported by the CONCURRENT keyword in TEF sl@0: // scripts). sl@0: // 'isemB' is a second semaphore required by DEF140385, there's small sl@0: // possibility with a single semaphore one thread can run and finish sl@0: // before the other thread(s) even start - the tests are not fully robust sl@0: // without it. sl@0: RSemaphore isemA, isemB; sl@0: sl@0: // This lets us associate errors (in string form) with their numeric sl@0: // equivalent. sl@0: CSQLErrHash *ierrhsh; sl@0: // This lets us associate column type names (in string form) with their sl@0: // numeric equivalent. sl@0: CSQLColTypeHash *icoltypehsh; sl@0: // This lets us associate actions read from a config file with the sl@0: // TSQLDbFns enumeration above. sl@0: CSQLTEFAction *iactionhsh; sl@0: // This associates capability enums with capabilities read in from the sl@0: // ini file sl@0: CSQLCapability *icaphsh; sl@0: // This associates the policy enum with policies read sl@0: // from the ini file sl@0: CSQLPolicy *ipolhsh; sl@0: // This associates the database object enum with policies read sl@0: // from the ini file sl@0: CSQLObject *iobjhsh; sl@0: }; sl@0: sl@0: sl@0: // Data-driven. sl@0: _LIT(KSQLDDT, "CSQLDDT"); sl@0: sl@0: // Code driven. sl@0: _LIT(KSQLCDT, "CSQLCDT"); sl@0: sl@0: _LIT(SQLFN_KTEFSQLUnknownError, "KTEFSQLUnknownError" ); sl@0: _LIT(SQLFN_KTEFSQLSizeError, "KTEFSQLSizeError" ); sl@0: sl@0: #endif // SQLFN_H__