os/persistentdata/persistentstorage/sql/TEST/testexecute/SQLite/src/sqlfn.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sql/TEST/testexecute/SQLite/src/sqlfn.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,253 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#if (!defined __SQLFN_H__)
    1.20 +#define __SQLFN_H__
    1.21 +#include <test/testexecutestepbase.h>
    1.22 +#include "Te_SQL_SuiteStepBase.h"
    1.23 +#include "hashing.h"
    1.24 +
    1.25 +#include<s32file.h>    // For RFileReadStream etc.
    1.26 +
    1.27 +class CSQLFnStep : public CTe_SQL_SuiteStepBase
    1.28 +    {
    1.29 +public:
    1.30 +    CSQLFnStep();
    1.31 +    ~CSQLFnStep();
    1.32 +    virtual TVerdict doTestStepL();
    1.33 +    virtual TVerdict doTestStepPostambleL();
    1.34 +    
    1.35 +    // This big enumeration defines the values associated with particular
    1.36 +    // actions (as read from a config file and converted to the numeric
    1.37 +    // equivalent by the CSQLTEFAction class).
    1.38 +    enum TSqlDbFns { 
    1.39 +            Ectrl_endblock=0, Ectrl_newblock, Ectrl_function,
    1.40 +            Ectrl_waitA, Ectrl_signalA, Ectrl_waitB, Ectrl_signalB,
    1.41 +            Ectrl_sleep, Ectrl_eightbit, Ectrl_async,
    1.42 +
    1.43 +            Efn_nop, Efn_create, Efn_createl,
    1.44 +            Efn_createsp,
    1.45 +            Efn_open, Efn_openl,
    1.46 +            Efn_attach, Efn_detach, Efn_copy,
    1.47 +            Efn_delete, Efn_close, Efn_exec,
    1.48 +            Efn_setisolationlevel, Efn_lasterrormessage,
    1.49 +            Efn_reservedrivespace, Efn_freereservedspace, 
    1.50 +            Efn_getreserveaccess, Efn_releasereserveaccess, 
    1.51 +
    1.52 +            Erstmt_prepare, Erstmt_preparel, Erstmt_close,
    1.53 +            Erstmt_atrow, Erstmt_reset, Erstmt_exec, Erstmt_next,
    1.54 +            Erstmt_paramindex, Erstmt_colindex, Erstmt_coltype,
    1.55 +            Erstmt_colsize, Erstmt_bindnull, Erstmt_bindint,
    1.56 +            Erstmt_bindint64, Erstmt_bindreal, Erstmt_bindtext,
    1.57 +            Erstmt_bindbigtext, Erstmt_bindbinary, Erstmt_isnull,
    1.58 +            Erstmt_colint, Erstmt_colint64, Erstmt_colreal,
    1.59 +            Erstmt_coltextL, Erstmt_coltextP, Erstmt_coltextD,
    1.60 +            Erstmt_colbinL, Erstmt_colbinP, Erstmt_colbinD, 
    1.61 +
    1.62 +            Esp_create, Esp_createl, Esp_close, Esp_setdbpolicy,
    1.63 +            Esp_setpolicy, Esp_externalizel, Esp_internalizel,
    1.64 +            
    1.65 +            Estreamwrite_bindtext, Estreamwrite_bindbinary,
    1.66 +            Estreamread_columntext, Estreamread_columnbinary,
    1.67 +            Edefineconfig,
    1.68 +
    1.69 +            // Marks the last item in the enumeration.
    1.70 +            Efn_undefined,
    1.71 +                     };
    1.72 +    // Methods to handle our simple semaphore thread syncing..
    1.73 +    void SignalA(TInt ai) { isemA.Signal(ai); };
    1.74 +    void WaitA() { isemA.Wait(); };
    1.75 +    void SignalB(TInt ai) { isemB.Signal(ai); };
    1.76 +    void WaitB() { isemB.Wait(); };
    1.77 +
    1.78 +    // Utility functions. These should move into a separate class, this
    1.79 +    // is untidy.
    1.80 +    TInt ActionNoToErrEnum(const TDesC&, const TInt, TPtrC &);
    1.81 +    TInt ErrStringToEnum(TPtrC &aerr);
    1.82 +    void ErrEnumToString(const TInt &, TPtrC &);
    1.83 +    const TPtrC SqlColumnTypeToString( TSqlColumnType & );
    1.84 +    TSqlColumnType StringToSqlColumnType( const TDesC & );
    1.85 +    void ReportOnError( const TDesC &, const TDesC &, const TDesC &,
    1.86 +                           const TInt, const TInt );
    1.87 +    TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TPtrC& );
    1.88 +    TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TInt& );
    1.89 +    TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TReal& );
    1.90 +    void CommaSeparated( const TPtrC &, TInt&, TInt& );
    1.91 +    void CommaSeparated( const TPtrC &, TInt&, TPtrC& );
    1.92 +    void CommaSeparated( const TPtrC &, TPtrC&, TPtrC& );
    1.93 +    TInt FileSize( const TPtrC & );
    1.94 +    TInt CompareBinaryAgainstFileL(const TDesC8&, const TFileName&);
    1.95 +    TInt CompareTextAgainstFileL(const TDesC&, const TFileName&);
    1.96 +    TInt CompareTextStreamAgainstFileL(RReadStream& , TInt, const TPtrC& );
    1.97 +    TInt CompareBinaryStreamAgainstFileL(RReadStream& , TInt, const TPtrC& );
    1.98 +    void WriteFileToStreamL(RWriteStream& , const TPtrC& );
    1.99 +
   1.100 +    // Top-level method. The third parameter is the config block to
   1.101 +    // use.
   1.102 +    void SQLDbStepL(const TPtrC &);
   1.103 +
   1.104 +    // Function=whatever. This function recognizes the third parameter and
   1.105 +    // calls a (code-driven) test.
   1.106 +    virtual void ResolveTestFunctionL( const TDesC&, const TInt, const TPtrC &)
   1.107 +                                                                          = 0;
   1.108 +    
   1.109 +    /*
   1.110 +     * These methods are wrappers around the RSqlDatabase methods of
   1.111 +     * the same (or similar) name. Includes error checking etc.
   1.112 +     */
   1.113 +    TBool Create(const TPtrC&,   const TDesC&, TInt);
   1.114 +    TBool CreateL_(const TPtrC&, const TDesC&, TInt);
   1.115 +    TBool CreateSP(const TPtrC&, const TDesC&, TInt);
   1.116 +    TBool Open(const TPtrC&,     const TDesC&, TInt);
   1.117 +    TBool OpenL_(const TPtrC&,   const TDesC&, TInt);
   1.118 +    void  Close();
   1.119 +    TBool Delete(const TPtrC&,   const TDesC&, TInt);
   1.120 +
   1.121 +    /*
   1.122 +     * The next three methods are newer..
   1.123 +     */
   1.124 +    void Attach(const TPtrC&, const TDesC&, TInt);
   1.125 +    void Detach(const TPtrC&, const TDesC&, TInt);
   1.126 +    void Copy(const TPtrC&,   const TDesC&, TInt);
   1.127 +
   1.128 +    void LastErrorMessage(const TPtrC&);
   1.129 +    void Exec(const TPtrC&,   const TDesC&, TInt);
   1.130 +    void SetIsolationLevel(const TPtrC&, const TDesC&, TInt);
   1.131 +
   1.132 +    /*
   1.133 +     * These methods are wrappers around the RSqlStatement methods of
   1.134 +     * the same (or similar) name. Includes error checking etc.
   1.135 +     */
   1.136 +    void Prepare(const TPtrC &, const TDesC&, TInt);
   1.137 +    void PrepareL_(const TPtrC &, const TDesC&, TInt);
   1.138 +    void AtRow(const TPtrC&);
   1.139 +    void Reset(const TDesC&, TInt);
   1.140 +    void Close(TInt);
   1.141 +    void Next(TPtrC&, const TDesC&, TInt);
   1.142 +    TInt ParamIndex(const TDesC&, const TDesC&, TInt);
   1.143 +    TInt ColumnIndex(const TPtrC&, const TDesC&, TInt);
   1.144 +    void ColumnType(const TInt&, const TPtrC&);
   1.145 +    void ColumnSize(const TInt&, const TInt&);
   1.146 +    void BindNull(const TInt&, const TDesC&, const TInt);
   1.147 +    void BindInt(const TInt&, const TInt&, const TDesC&, const TInt);
   1.148 +    void BindInt64(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.149 +    void BindReal(const TInt&, const TReal &, const TDesC&, const TInt);
   1.150 +    void BindText(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.151 +    void BindBigTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.152 +    void BindBinaryL(const TInt&, const TDesC&, const TDesC&, const TInt);
   1.153 +
   1.154 +    void IsNull(const TInt&, const TPtrC&);
   1.155 +    void ColumnInt(const TInt&, const TInt&);
   1.156 +    void ColumnInt64(const TInt&, const TPtrC&);
   1.157 +    void ColumnReal(const TInt&, const TReal&);
   1.158 +    void ColumnTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.159 +    void ColumnTextPL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.160 +    void ColumnTextDL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.161 +    void ColumnBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.162 +    void ColumnBinaryPL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.163 +    void ColumnBinaryDL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.164 +    void SWBindTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.165 +    void SWBindBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.166 +    void SRColumnTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.167 +    void SRColumnBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt);
   1.168 +    void ReserveDriveSpace(TInt, const TDesC&, const TInt);
   1.169 +    void FreeReservedSpace();
   1.170 +    void GetReserveAccess(const TDesC&, const TInt);
   1.171 +    void ReleaseReserveAccess();
   1.172 +
   1.173 +    /*
   1.174 +     * These are the methods associated with setting up a security
   1.175 +     * policy for a secure database
   1.176 +     */
   1.177 +    TBool SPCreate(const TDesC&, const TInt);
   1.178 +    TBool SPCreate(const TPtrC&, const TDesC&, const TInt);
   1.179 +    void SPClose();
   1.180 +    TBool SPSetDBPolicy(const TPtrC&, const TDesC&, const TInt);
   1.181 +    TBool SPSetPolicy(const TPtrC&, const TDesC&, const TInt);
   1.182 +/*  void SPDefaultPolicy(const TDesC&, const TDesC&, const TInt);
   1.183 +    void SPDBPolicy(const TDesC&, const TDesC&, const TInt);
   1.184 +    void SPPolicy(const TDesC&, const TDesC&, const TInt);
   1.185 +*/  void SPExternalize(const TPtrC&, const TDesC&, const TInt);
   1.186 +    void SPInternalize(const TPtrC&, const TDesC&, const TInt);
   1.187 +
   1.188 +    static const TInt KConfigItemMaxNameLength = 30;
   1.189 +    static const TInt KConfigItemMaxStringLength = 30;
   1.190 +    static const TInt KStatementFunMaxLength = 30;
   1.191 +
   1.192 +private:
   1.193 +    // Arbitrary.
   1.194 +    static const TInt KTEFSQLSizeError = 98989898;
   1.195 +    static const TInt KTEFSQLUnknownError = 98989897;
   1.196 +
   1.197 +protected:
   1.198 +    TBool i8bit;
   1.199 +    TBool iasync;
   1.200 +    TPtrC8* icfg;
   1.201 +    RSqlDatabase isqldb;
   1.202 +    RSqlStatement isqlst;
   1.203 +    RSqlSecurityPolicy isqlsp;
   1.204 +
   1.205 +    // This is where we store the current column and parameter indices.
   1.206 +    RArray<TInt> icidxs, ipidxs;
   1.207 +
   1.208 +    // Now the arrays of RBuf[8]s, these keep buffers in scope between
   1.209 +    // binding and exec'ing.
   1.210 +    RArray<RBuf> iBindRBufarr;
   1.211 +    RArray<RBuf8> iBindRBuf8arr;
   1.212 +
   1.213 +    // Various methods do stuff with files, so we're often going to need
   1.214 +    // an RFs, lets create/destroy it in the constructor/destructor.
   1.215 +    RFs irfs;
   1.216 +    
   1.217 +    // This semaphore is used to synchronize things when we have multiple
   1.218 +    // threads running (as supported by the CONCURRENT keyword in TEF
   1.219 +    // scripts).
   1.220 +    // 'isemB' is a second semaphore required by DEF140385, there's small
   1.221 +    // possibility with a single semaphore one thread can run and finish
   1.222 +    // before the other thread(s) even start - the tests are not fully robust
   1.223 +    // without it.
   1.224 +    RSemaphore isemA, isemB;
   1.225 +
   1.226 +    // This lets us associate errors (in string form) with their numeric
   1.227 +    // equivalent.
   1.228 +    CSQLErrHash *ierrhsh;
   1.229 +    // This lets us associate column type names (in string form) with their
   1.230 +    // numeric equivalent.
   1.231 +    CSQLColTypeHash *icoltypehsh;
   1.232 +    // This lets us associate actions read from a config file with the
   1.233 +    // TSQLDbFns enumeration above.
   1.234 +    CSQLTEFAction *iactionhsh;
   1.235 +    // This associates capability enums with capabilities read in from the
   1.236 +    // ini file
   1.237 +    CSQLCapability *icaphsh;
   1.238 +    // This associates the policy enum with policies read
   1.239 +    // from the ini file
   1.240 +    CSQLPolicy *ipolhsh;
   1.241 +    // This associates the database object enum with policies read
   1.242 +    // from the ini file
   1.243 +    CSQLObject *iobjhsh;
   1.244 +    };
   1.245 +
   1.246 +
   1.247 +// Data-driven.
   1.248 +_LIT(KSQLDDT, "CSQLDDT");
   1.249 +
   1.250 +// Code driven.
   1.251 +_LIT(KSQLCDT, "CSQLCDT");
   1.252 +
   1.253 +_LIT(SQLFN_KTEFSQLUnknownError, "KTEFSQLUnknownError" );
   1.254 +_LIT(SQLFN_KTEFSQLSizeError,    "KTEFSQLSizeError" );
   1.255 +
   1.256 +#endif // SQLFN_H__