|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #if (!defined __SQLFN_H__) |
|
17 #define __SQLFN_H__ |
|
18 #include <test/testexecutestepbase.h> |
|
19 #include "Te_SQL_SuiteStepBase.h" |
|
20 #include "hashing.h" |
|
21 |
|
22 #include<s32file.h> // For RFileReadStream etc. |
|
23 |
|
24 class CSQLFnStep : public CTe_SQL_SuiteStepBase |
|
25 { |
|
26 public: |
|
27 CSQLFnStep(); |
|
28 ~CSQLFnStep(); |
|
29 virtual TVerdict doTestStepL(); |
|
30 virtual TVerdict doTestPostambleL(); |
|
31 |
|
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). |
|
35 enum TSqlDbFns { |
|
36 Ectrl_endblock=0, Ectrl_newblock, Ectrl_function, |
|
37 Ectrl_waitA, Ectrl_signalA, Ectrl_waitB, Ectrl_signalB, |
|
38 Ectrl_sleep, Ectrl_eightbit, Ectrl_async, |
|
39 |
|
40 Efn_nop, Efn_create, Efn_createl, |
|
41 Efn_createsp, |
|
42 Efn_open, Efn_openl, |
|
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, |
|
48 |
|
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, |
|
58 |
|
59 Esp_create, Esp_createl, Esp_close, Esp_setdbpolicy, |
|
60 Esp_setpolicy, Esp_externalizel, Esp_internalizel, |
|
61 |
|
62 Estreamwrite_bindtext, Estreamwrite_bindbinary, |
|
63 Estreamread_columntext, Estreamread_columnbinary, |
|
64 Edefineconfig, |
|
65 |
|
66 // Marks the last item in the enumeration. |
|
67 Efn_undefined, |
|
68 }; |
|
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(); }; |
|
74 |
|
75 // Utility functions. These should move into a separate class, this |
|
76 // is untidy. |
|
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& ); |
|
96 |
|
97 // Top-level method. The third parameter is the config block to |
|
98 // use. |
|
99 void SQLDbStepL(const TPtrC &); |
|
100 |
|
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 &) |
|
104 = 0; |
|
105 |
|
106 /* |
|
107 * These methods are wrappers around the RSqlDatabase methods of |
|
108 * the same (or similar) name. Includes error checking etc. |
|
109 */ |
|
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); |
|
115 void Close(); |
|
116 TBool Delete(const TPtrC&, const TDesC&, TInt); |
|
117 |
|
118 /* |
|
119 * The next three methods are newer.. |
|
120 */ |
|
121 void Attach(const TPtrC&, const TDesC&, TInt); |
|
122 void Detach(const TPtrC&, const TDesC&, TInt); |
|
123 void Copy(const TPtrC&, const TDesC&, TInt); |
|
124 |
|
125 void LastErrorMessage(const TPtrC&); |
|
126 void Exec(const TPtrC&, const TDesC&, TInt); |
|
127 void SetIsolationLevel(const TPtrC&, const TDesC&, TInt); |
|
128 |
|
129 /* |
|
130 * These methods are wrappers around the RSqlStatement methods of |
|
131 * the same (or similar) name. Includes error checking etc. |
|
132 */ |
|
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); |
|
137 void Close(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); |
|
150 |
|
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(); |
|
169 |
|
170 /* |
|
171 * These are the methods associated with setting up a security |
|
172 * policy for a secure database |
|
173 */ |
|
174 TBool SPCreate(const TDesC&, const TInt); |
|
175 TBool SPCreate(const TPtrC&, const TDesC&, const TInt); |
|
176 void SPClose(); |
|
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); |
|
184 |
|
185 static const TInt KConfigItemMaxNameLength = 30; |
|
186 static const TInt KConfigItemMaxStringLength = 30; |
|
187 static const TInt KStatementFunMaxLength = 30; |
|
188 |
|
189 private: |
|
190 // Arbitrary. |
|
191 static const TInt KTEFSQLSizeError = 98989898; |
|
192 static const TInt KTEFSQLUnknownError = 98989897; |
|
193 |
|
194 protected: |
|
195 TBool i8bit; |
|
196 TBool iasync; |
|
197 TPtrC8* icfg; |
|
198 RSqlDatabase isqldb; |
|
199 RSqlStatement isqlst; |
|
200 RSqlSecurityPolicy isqlsp; |
|
201 |
|
202 // This is where we store the current column and parameter indices. |
|
203 RArray<TInt> icidxs, ipidxs; |
|
204 |
|
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; |
|
209 |
|
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. |
|
212 RFs irfs; |
|
213 |
|
214 // This semaphore is used to synchronize things when we have multiple |
|
215 // threads running (as supported by the CONCURRENT keyword in TEF |
|
216 // scripts). |
|
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 |
|
220 // without it. |
|
221 RSemaphore isemA, isemB; |
|
222 |
|
223 // This lets us associate errors (in string form) with their numeric |
|
224 // equivalent. |
|
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 |
|
233 // ini file |
|
234 CSQLCapability *icaphsh; |
|
235 // This associates the policy enum with policies read |
|
236 // from the ini file |
|
237 CSQLPolicy *ipolhsh; |
|
238 // This associates the database object enum with policies read |
|
239 // from the ini file |
|
240 CSQLObject *iobjhsh; |
|
241 }; |
|
242 |
|
243 |
|
244 // Data-driven. |
|
245 _LIT(KSQLDDT, "CSQLDDT"); |
|
246 |
|
247 // Code driven. |
|
248 _LIT(KSQLCDT, "CSQLCDT"); |
|
249 |
|
250 _LIT(SQLFN_KTEFSQLUnknownError, "KTEFSQLUnknownError" ); |
|
251 _LIT(SQLFN_KTEFSQLSizeError, "KTEFSQLSizeError" ); |
|
252 |
|
253 #endif // SQLFN_H__ |