First public contribution.
1 // Copyright (c) 2006-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #if (!defined __SQLFN_H__)
18 #include <test/testexecutestepbase.h>
19 #include "Te_SQL_SuiteStepBase.h"
22 #include<s32file.h> // For RFileReadStream etc.
24 class CSQLFnStep : public CTe_SQL_SuiteStepBase
29 virtual TVerdict doTestStepL();
30 virtual TVerdict doTestStepPostambleL();
32 // This big enumeration defines the values associated with particular
33 // actions (as read from a config file and converted to the numeric
34 // equivalent by the CSQLTEFAction class).
36 Ectrl_endblock=0, Ectrl_newblock, Ectrl_function,
37 Ectrl_waitA, Ectrl_signalA, Ectrl_waitB, Ectrl_signalB,
38 Ectrl_sleep, Ectrl_eightbit, Ectrl_async,
40 Efn_nop, Efn_create, Efn_createl,
43 Efn_attach, Efn_detach, Efn_copy,
44 Efn_delete, Efn_close, Efn_exec,
45 Efn_setisolationlevel, Efn_lasterrormessage,
46 Efn_reservedrivespace, Efn_freereservedspace,
47 Efn_getreserveaccess, Efn_releasereserveaccess,
49 Erstmt_prepare, Erstmt_preparel, Erstmt_close,
50 Erstmt_atrow, Erstmt_reset, Erstmt_exec, Erstmt_next,
51 Erstmt_paramindex, Erstmt_colindex, Erstmt_coltype,
52 Erstmt_colsize, Erstmt_bindnull, Erstmt_bindint,
53 Erstmt_bindint64, Erstmt_bindreal, Erstmt_bindtext,
54 Erstmt_bindbigtext, Erstmt_bindbinary, Erstmt_isnull,
55 Erstmt_colint, Erstmt_colint64, Erstmt_colreal,
56 Erstmt_coltextL, Erstmt_coltextP, Erstmt_coltextD,
57 Erstmt_colbinL, Erstmt_colbinP, Erstmt_colbinD,
59 Esp_create, Esp_createl, Esp_close, Esp_setdbpolicy,
60 Esp_setpolicy, Esp_externalizel, Esp_internalizel,
62 Estreamwrite_bindtext, Estreamwrite_bindbinary,
63 Estreamread_columntext, Estreamread_columnbinary,
66 // Marks the last item in the enumeration.
69 // Methods to handle our simple semaphore thread syncing..
70 void SignalA(TInt ai) { isemA.Signal(ai); };
71 void WaitA() { isemA.Wait(); };
72 void SignalB(TInt ai) { isemB.Signal(ai); };
73 void WaitB() { isemB.Wait(); };
75 // Utility functions. These should move into a separate class, this
77 TInt ActionNoToErrEnum(const TDesC&, const TInt, TPtrC &);
78 TInt ErrStringToEnum(TPtrC &aerr);
79 void ErrEnumToString(const TInt &, TPtrC &);
80 const TPtrC SqlColumnTypeToString( TSqlColumnType & );
81 TSqlColumnType StringToSqlColumnType( const TDesC & );
82 void ReportOnError( const TDesC &, const TDesC &, const TDesC &,
83 const TInt, const TInt );
84 TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TPtrC& );
85 TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TInt& );
86 TBool FromConfig( const TDesC &, const TDesC &, const TDesC &, TReal& );
87 void CommaSeparated( const TPtrC &, TInt&, TInt& );
88 void CommaSeparated( const TPtrC &, TInt&, TPtrC& );
89 void CommaSeparated( const TPtrC &, TPtrC&, TPtrC& );
90 TInt FileSize( const TPtrC & );
91 TInt CompareBinaryAgainstFileL(const TDesC8&, const TFileName&);
92 TInt CompareTextAgainstFileL(const TDesC&, const TFileName&);
93 TInt CompareTextStreamAgainstFileL(RReadStream& , TInt, const TPtrC& );
94 TInt CompareBinaryStreamAgainstFileL(RReadStream& , TInt, const TPtrC& );
95 void WriteFileToStreamL(RWriteStream& , const TPtrC& );
97 // Top-level method. The third parameter is the config block to
99 void SQLDbStepL(const TPtrC &);
101 // Function=whatever. This function recognizes the third parameter and
102 // calls a (code-driven) test.
103 virtual void ResolveTestFunctionL( const TDesC&, const TInt, const TPtrC &)
107 * These methods are wrappers around the RSqlDatabase methods of
108 * the same (or similar) name. Includes error checking etc.
110 TBool Create(const TPtrC&, const TDesC&, TInt);
111 TBool CreateL_(const TPtrC&, const TDesC&, TInt);
112 TBool CreateSP(const TPtrC&, const TDesC&, TInt);
113 TBool Open(const TPtrC&, const TDesC&, TInt);
114 TBool OpenL_(const TPtrC&, const TDesC&, TInt);
116 TBool Delete(const TPtrC&, const TDesC&, TInt);
119 * The next three methods are newer..
121 void Attach(const TPtrC&, const TDesC&, TInt);
122 void Detach(const TPtrC&, const TDesC&, TInt);
123 void Copy(const TPtrC&, const TDesC&, TInt);
125 void LastErrorMessage(const TPtrC&);
126 void Exec(const TPtrC&, const TDesC&, TInt);
127 void SetIsolationLevel(const TPtrC&, const TDesC&, TInt);
130 * These methods are wrappers around the RSqlStatement methods of
131 * the same (or similar) name. Includes error checking etc.
133 void Prepare(const TPtrC &, const TDesC&, TInt);
134 void PrepareL_(const TPtrC &, const TDesC&, TInt);
135 void AtRow(const TPtrC&);
136 void Reset(const TDesC&, TInt);
138 void Next(TPtrC&, const TDesC&, TInt);
139 TInt ParamIndex(const TDesC&, const TDesC&, TInt);
140 TInt ColumnIndex(const TPtrC&, const TDesC&, TInt);
141 void ColumnType(const TInt&, const TPtrC&);
142 void ColumnSize(const TInt&, const TInt&);
143 void BindNull(const TInt&, const TDesC&, const TInt);
144 void BindInt(const TInt&, const TInt&, const TDesC&, const TInt);
145 void BindInt64(const TInt&, const TPtrC&, const TDesC&, const TInt);
146 void BindReal(const TInt&, const TReal &, const TDesC&, const TInt);
147 void BindText(const TInt&, const TPtrC&, const TDesC&, const TInt);
148 void BindBigTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
149 void BindBinaryL(const TInt&, const TDesC&, const TDesC&, const TInt);
151 void IsNull(const TInt&, const TPtrC&);
152 void ColumnInt(const TInt&, const TInt&);
153 void ColumnInt64(const TInt&, const TPtrC&);
154 void ColumnReal(const TInt&, const TReal&);
155 void ColumnTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
156 void ColumnTextPL(const TInt&, const TPtrC&, const TDesC&, const TInt);
157 void ColumnTextDL(const TInt&, const TPtrC&, const TDesC&, const TInt);
158 void ColumnBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt);
159 void ColumnBinaryPL(const TInt&, const TPtrC&, const TDesC&, const TInt);
160 void ColumnBinaryDL(const TInt&, const TPtrC&, const TDesC&, const TInt);
161 void SWBindTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
162 void SWBindBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt);
163 void SRColumnTextL(const TInt&, const TPtrC&, const TDesC&, const TInt);
164 void SRColumnBinaryL(const TInt&, const TPtrC&, const TDesC&, const TInt);
165 void ReserveDriveSpace(TInt, const TDesC&, const TInt);
166 void FreeReservedSpace();
167 void GetReserveAccess(const TDesC&, const TInt);
168 void ReleaseReserveAccess();
171 * These are the methods associated with setting up a security
172 * policy for a secure database
174 TBool SPCreate(const TDesC&, const TInt);
175 TBool SPCreate(const TPtrC&, const TDesC&, const TInt);
177 TBool SPSetDBPolicy(const TPtrC&, const TDesC&, const TInt);
178 TBool SPSetPolicy(const TPtrC&, const TDesC&, const TInt);
179 /* void SPDefaultPolicy(const TDesC&, const TDesC&, const TInt);
180 void SPDBPolicy(const TDesC&, const TDesC&, const TInt);
181 void SPPolicy(const TDesC&, const TDesC&, const TInt);
182 */ void SPExternalize(const TPtrC&, const TDesC&, const TInt);
183 void SPInternalize(const TPtrC&, const TDesC&, const TInt);
185 static const TInt KConfigItemMaxNameLength = 30;
186 static const TInt KConfigItemMaxStringLength = 30;
187 static const TInt KStatementFunMaxLength = 30;
191 static const TInt KTEFSQLSizeError = 98989898;
192 static const TInt KTEFSQLUnknownError = 98989897;
199 RSqlStatement isqlst;
200 RSqlSecurityPolicy isqlsp;
202 // This is where we store the current column and parameter indices.
203 RArray<TInt> icidxs, ipidxs;
205 // Now the arrays of RBuf[8]s, these keep buffers in scope between
206 // binding and exec'ing.
207 RArray<RBuf> iBindRBufarr;
208 RArray<RBuf8> iBindRBuf8arr;
210 // Various methods do stuff with files, so we're often going to need
211 // an RFs, lets create/destroy it in the constructor/destructor.
214 // This semaphore is used to synchronize things when we have multiple
215 // threads running (as supported by the CONCURRENT keyword in TEF
217 // 'isemB' is a second semaphore required by DEF140385, there's small
218 // possibility with a single semaphore one thread can run and finish
219 // before the other thread(s) even start - the tests are not fully robust
221 RSemaphore isemA, isemB;
223 // This lets us associate errors (in string form) with their numeric
225 CSQLErrHash *ierrhsh;
226 // This lets us associate column type names (in string form) with their
227 // numeric equivalent.
228 CSQLColTypeHash *icoltypehsh;
229 // This lets us associate actions read from a config file with the
230 // TSQLDbFns enumeration above.
231 CSQLTEFAction *iactionhsh;
232 // This associates capability enums with capabilities read in from the
234 CSQLCapability *icaphsh;
235 // This associates the policy enum with policies read
238 // This associates the database object enum with policies read
245 _LIT(KSQLDDT, "CSQLDDT");
248 _LIT(KSQLCDT, "CSQLCDT");
250 _LIT(SQLFN_KTEFSQLUnknownError, "KTEFSQLUnknownError" );
251 _LIT(SQLFN_KTEFSQLSizeError, "KTEFSQLSizeError" );