os/persistentdata/persistentstorage/sql/TEST/testexecute/SQLite/src/sqlfn.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#if (!defined __SQLFN_H__)
sl@0
    17
#define __SQLFN_H__
sl@0
    18
#include <test/testexecutestepbase.h>
sl@0
    19
#include "Te_SQL_SuiteStepBase.h"
sl@0
    20
#include "hashing.h"
sl@0
    21
sl@0
    22
#include<s32file.h>    // For RFileReadStream etc.
sl@0
    23
sl@0
    24
class CSQLFnStep : public CTe_SQL_SuiteStepBase
sl@0
    25
    {
sl@0
    26
public:
sl@0
    27
    CSQLFnStep();
sl@0
    28
    ~CSQLFnStep();
sl@0
    29
    virtual TVerdict doTestStepL();
sl@0
    30
    virtual TVerdict doTestStepPostambleL();
sl@0
    31
    
sl@0
    32
    // This big enumeration defines the values associated with particular
sl@0
    33
    // actions (as read from a config file and converted to the numeric
sl@0
    34
    // equivalent by the CSQLTEFAction class).
sl@0
    35
    enum TSqlDbFns { 
sl@0
    36
            Ectrl_endblock=0, Ectrl_newblock, Ectrl_function,
sl@0
    37
            Ectrl_waitA, Ectrl_signalA, Ectrl_waitB, Ectrl_signalB,
sl@0
    38
            Ectrl_sleep, Ectrl_eightbit, Ectrl_async,
sl@0
    39
sl@0
    40
            Efn_nop, Efn_create, Efn_createl,
sl@0
    41
            Efn_createsp,
sl@0
    42
            Efn_open, Efn_openl,
sl@0
    43
            Efn_attach, Efn_detach, Efn_copy,
sl@0
    44
            Efn_delete, Efn_close, Efn_exec,
sl@0
    45
            Efn_setisolationlevel, Efn_lasterrormessage,
sl@0
    46
            Efn_reservedrivespace, Efn_freereservedspace, 
sl@0
    47
            Efn_getreserveaccess, Efn_releasereserveaccess, 
sl@0
    48
sl@0
    49
            Erstmt_prepare, Erstmt_preparel, Erstmt_close,
sl@0
    50
            Erstmt_atrow, Erstmt_reset, Erstmt_exec, Erstmt_next,
sl@0
    51
            Erstmt_paramindex, Erstmt_colindex, Erstmt_coltype,
sl@0
    52
            Erstmt_colsize, Erstmt_bindnull, Erstmt_bindint,
sl@0
    53
            Erstmt_bindint64, Erstmt_bindreal, Erstmt_bindtext,
sl@0
    54
            Erstmt_bindbigtext, Erstmt_bindbinary, Erstmt_isnull,
sl@0
    55
            Erstmt_colint, Erstmt_colint64, Erstmt_colreal,
sl@0
    56
            Erstmt_coltextL, Erstmt_coltextP, Erstmt_coltextD,
sl@0
    57
            Erstmt_colbinL, Erstmt_colbinP, Erstmt_colbinD, 
sl@0
    58
sl@0
    59
            Esp_create, Esp_createl, Esp_close, Esp_setdbpolicy,
sl@0
    60
            Esp_setpolicy, Esp_externalizel, Esp_internalizel,
sl@0
    61
            
sl@0
    62
            Estreamwrite_bindtext, Estreamwrite_bindbinary,
sl@0
    63
            Estreamread_columntext, Estreamread_columnbinary,
sl@0
    64
            Edefineconfig,
sl@0
    65
sl@0
    66
            // Marks the last item in the enumeration.
sl@0
    67
            Efn_undefined,
sl@0
    68
                     };
sl@0
    69
    // Methods to handle our simple semaphore thread syncing..
sl@0
    70
    void SignalA(TInt ai) { isemA.Signal(ai); };
sl@0
    71
    void WaitA() { isemA.Wait(); };
sl@0
    72
    void SignalB(TInt ai) { isemB.Signal(ai); };
sl@0
    73
    void WaitB() { isemB.Wait(); };
sl@0
    74
sl@0
    75
    // Utility functions. These should move into a separate class, this
sl@0
    76
    // is untidy.
sl@0
    77
    TInt ActionNoToErrEnum(const TDesC&, const TInt, TPtrC &);
sl@0
    78
    TInt ErrStringToEnum(TPtrC &aerr);
sl@0
    79
    void ErrEnumToString(const TInt &, TPtrC &);
sl@0
    80
    const TPtrC SqlColumnTypeToString( TSqlColumnType & );
sl@0
    81
    TSqlColumnType StringToSqlColumnType( const TDesC & );
sl@0
    82
    void ReportOnError( const TDesC &, const TDesC &, const TDesC &,
sl@0
    83
                           const TInt, const TInt );
sl@0
    84
    TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TPtrC& );
sl@0
    85
    TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TInt& );
sl@0
    86
    TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TReal& );
sl@0
    87
    void CommaSeparated( const TPtrC &, TInt&, TInt& );
sl@0
    88
    void CommaSeparated( const TPtrC &, TInt&, TPtrC& );
sl@0
    89
    void CommaSeparated( const TPtrC &, TPtrC&, TPtrC& );
sl@0
    90
    TInt FileSize( const TPtrC & );
sl@0
    91
    TInt CompareBinaryAgainstFileL(const TDesC8&, const TFileName&);
sl@0
    92
    TInt CompareTextAgainstFileL(const TDesC&, const TFileName&);
sl@0
    93
    TInt CompareTextStreamAgainstFileL(RReadStream& , TInt, const TPtrC& );
sl@0
    94
    TInt CompareBinaryStreamAgainstFileL(RReadStream& , TInt, const TPtrC& );
sl@0
    95
    void WriteFileToStreamL(RWriteStream& , const TPtrC& );
sl@0
    96
sl@0
    97
    // Top-level method. The third parameter is the config block to
sl@0
    98
    // use.
sl@0
    99
    void SQLDbStepL(const TPtrC &);
sl@0
   100
sl@0
   101
    // Function=whatever. This function recognizes the third parameter and
sl@0
   102
    // calls a (code-driven) test.
sl@0
   103
    virtual void ResolveTestFunctionL( const TDesC&, const TInt, const TPtrC &)
sl@0
   104
                                                                          = 0;
sl@0
   105
    
sl@0
   106
    /*
sl@0
   107
     * These methods are wrappers around the RSqlDatabase methods of
sl@0
   108
     * the same (or similar) name. Includes error checking etc.
sl@0
   109
     */
sl@0
   110
    TBool Create(const TPtrC&,   const TDesC&, TInt);
sl@0
   111
    TBool CreateL_(const TPtrC&, const TDesC&, TInt);
sl@0
   112
    TBool CreateSP(const TPtrC&, const TDesC&, TInt);
sl@0
   113
    TBool Open(const TPtrC&,     const TDesC&, TInt);
sl@0
   114
    TBool OpenL_(const TPtrC&,   const TDesC&, TInt);
sl@0
   115
    void  Close();
sl@0
   116
    TBool Delete(const TPtrC&,   const TDesC&, TInt);
sl@0
   117
sl@0
   118
    /*
sl@0
   119
     * The next three methods are newer..
sl@0
   120
     */
sl@0
   121
    void Attach(const TPtrC&, const TDesC&, TInt);
sl@0
   122
    void Detach(const TPtrC&, const TDesC&, TInt);
sl@0
   123
    void Copy(const TPtrC&,   const TDesC&, TInt);
sl@0
   124
sl@0
   125
    void LastErrorMessage(const TPtrC&);
sl@0
   126
    void Exec(const TPtrC&,   const TDesC&, TInt);
sl@0
   127
    void SetIsolationLevel(const TPtrC&, const TDesC&, TInt);
sl@0
   128
sl@0
   129
    /*
sl@0
   130
     * These methods are wrappers around the RSqlStatement methods of
sl@0
   131
     * the same (or similar) name. Includes error checking etc.
sl@0
   132
     */
sl@0
   133
    void Prepare(const TPtrC &, const TDesC&, TInt);
sl@0
   134
    void PrepareL_(const TPtrC &, const TDesC&, TInt);
sl@0
   135
    void AtRow(const TPtrC&);
sl@0
   136
    void Reset(const TDesC&, TInt);
sl@0
   137
    void Close(TInt);
sl@0
   138
    void Next(TPtrC&, const TDesC&, TInt);
sl@0
   139
    TInt ParamIndex(const TDesC&, const TDesC&, TInt);
sl@0
   140
    TInt ColumnIndex(const TPtrC&, const TDesC&, TInt);
sl@0
   141
    void ColumnType(const TInt&, const TPtrC&);
sl@0
   142
    void ColumnSize(const TInt&, const TInt&);
sl@0
   143
    void BindNull(const TInt&, const TDesC&, const TInt);
sl@0
   144
    void BindInt(const TInt&, const TInt&, const TDesC&, const TInt);
sl@0
   145
    void BindInt64(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   146
    void BindReal(const TInt&, const TReal &, const TDesC&, const TInt);
sl@0
   147
    void BindText(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   148
    void BindBigTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   149
    void BindBinaryL(const TInt&, const TDesC&, const TDesC&, const TInt);
sl@0
   150
sl@0
   151
    void IsNull(const TInt&, const TPtrC&);
sl@0
   152
    void ColumnInt(const TInt&, const TInt&);
sl@0
   153
    void ColumnInt64(const TInt&, const TPtrC&);
sl@0
   154
    void ColumnReal(const TInt&, const TReal&);
sl@0
   155
    void ColumnTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   156
    void ColumnTextPL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   157
    void ColumnTextDL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   158
    void ColumnBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   159
    void ColumnBinaryPL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   160
    void ColumnBinaryDL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   161
    void SWBindTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   162
    void SWBindBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   163
    void SRColumnTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   164
    void SRColumnBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt);
sl@0
   165
    void ReserveDriveSpace(TInt, const TDesC&, const TInt);
sl@0
   166
    void FreeReservedSpace();
sl@0
   167
    void GetReserveAccess(const TDesC&, const TInt);
sl@0
   168
    void ReleaseReserveAccess();
sl@0
   169
sl@0
   170
    /*
sl@0
   171
     * These are the methods associated with setting up a security
sl@0
   172
     * policy for a secure database
sl@0
   173
     */
sl@0
   174
    TBool SPCreate(const TDesC&, const TInt);
sl@0
   175
    TBool SPCreate(const TPtrC&, const TDesC&, const TInt);
sl@0
   176
    void SPClose();
sl@0
   177
    TBool SPSetDBPolicy(const TPtrC&, const TDesC&, const TInt);
sl@0
   178
    TBool SPSetPolicy(const TPtrC&, const TDesC&, const TInt);
sl@0
   179
/*  void SPDefaultPolicy(const TDesC&, const TDesC&, const TInt);
sl@0
   180
    void SPDBPolicy(const TDesC&, const TDesC&, const TInt);
sl@0
   181
    void SPPolicy(const TDesC&, const TDesC&, const TInt);
sl@0
   182
*/  void SPExternalize(const TPtrC&, const TDesC&, const TInt);
sl@0
   183
    void SPInternalize(const TPtrC&, const TDesC&, const TInt);
sl@0
   184
sl@0
   185
    static const TInt KConfigItemMaxNameLength = 30;
sl@0
   186
    static const TInt KConfigItemMaxStringLength = 30;
sl@0
   187
    static const TInt KStatementFunMaxLength = 30;
sl@0
   188
sl@0
   189
private:
sl@0
   190
    // Arbitrary.
sl@0
   191
    static const TInt KTEFSQLSizeError = 98989898;
sl@0
   192
    static const TInt KTEFSQLUnknownError = 98989897;
sl@0
   193
sl@0
   194
protected:
sl@0
   195
    TBool i8bit;
sl@0
   196
    TBool iasync;
sl@0
   197
    TPtrC8* icfg;
sl@0
   198
    RSqlDatabase isqldb;
sl@0
   199
    RSqlStatement isqlst;
sl@0
   200
    RSqlSecurityPolicy isqlsp;
sl@0
   201
sl@0
   202
    // This is where we store the current column and parameter indices.
sl@0
   203
    RArray<TInt> icidxs, ipidxs;
sl@0
   204
sl@0
   205
    // Now the arrays of RBuf[8]s, these keep buffers in scope between
sl@0
   206
    // binding and exec'ing.
sl@0
   207
    RArray<RBuf> iBindRBufarr;
sl@0
   208
    RArray<RBuf8> iBindRBuf8arr;
sl@0
   209
sl@0
   210
    // Various methods do stuff with files, so we're often going to need
sl@0
   211
    // an RFs, lets create/destroy it in the constructor/destructor.
sl@0
   212
    RFs irfs;
sl@0
   213
    
sl@0
   214
    // This semaphore is used to synchronize things when we have multiple
sl@0
   215
    // threads running (as supported by the CONCURRENT keyword in TEF
sl@0
   216
    // scripts).
sl@0
   217
    // 'isemB' is a second semaphore required by DEF140385, there's small
sl@0
   218
    // possibility with a single semaphore one thread can run and finish
sl@0
   219
    // before the other thread(s) even start - the tests are not fully robust
sl@0
   220
    // without it.
sl@0
   221
    RSemaphore isemA, isemB;
sl@0
   222
sl@0
   223
    // This lets us associate errors (in string form) with their numeric
sl@0
   224
    // equivalent.
sl@0
   225
    CSQLErrHash *ierrhsh;
sl@0
   226
    // This lets us associate column type names (in string form) with their
sl@0
   227
    // numeric equivalent.
sl@0
   228
    CSQLColTypeHash *icoltypehsh;
sl@0
   229
    // This lets us associate actions read from a config file with the
sl@0
   230
    // TSQLDbFns enumeration above.
sl@0
   231
    CSQLTEFAction *iactionhsh;
sl@0
   232
    // This associates capability enums with capabilities read in from the
sl@0
   233
    // ini file
sl@0
   234
    CSQLCapability *icaphsh;
sl@0
   235
    // This associates the policy enum with policies read
sl@0
   236
    // from the ini file
sl@0
   237
    CSQLPolicy *ipolhsh;
sl@0
   238
    // This associates the database object enum with policies read
sl@0
   239
    // from the ini file
sl@0
   240
    CSQLObject *iobjhsh;
sl@0
   241
    };
sl@0
   242
sl@0
   243
sl@0
   244
// Data-driven.
sl@0
   245
_LIT(KSQLDDT, "CSQLDDT");
sl@0
   246
sl@0
   247
// Code driven.
sl@0
   248
_LIT(KSQLCDT, "CSQLCDT");
sl@0
   249
sl@0
   250
_LIT(SQLFN_KTEFSQLUnknownError, "KTEFSQLUnknownError" );
sl@0
   251
_LIT(SQLFN_KTEFSQLSizeError,    "KTEFSQLSizeError" );
sl@0
   252
sl@0
   253
#endif // SQLFN_H__