|
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 #include "cdtest.h" |
|
17 #include "hashing.h" |
|
18 #include "common.h" |
|
19 #include<bautils.h> |
|
20 |
|
21 // Includes any code required for 'Code-Driven' testing, generally tests |
|
22 // that cannot be data-driven (or not completely). |
|
23 |
|
24 CSQLCDT::~CSQLCDT() |
|
25 { |
|
26 } |
|
27 |
|
28 CSQLCDT::CSQLCDT() |
|
29 { |
|
30 SetTestStepName(KSQLCDT); |
|
31 } |
|
32 |
|
33 |
|
34 // Look at 'arg' and call whichever function is required. |
|
35 void CSQLCDT::ResolveTestFunctionL(const TDesC &acfgblk, const TInt acnnum, |
|
36 const TPtrC &arg ) |
|
37 { |
|
38 _LIT(KTestFunction, "cdtest::ResolveTestFunction"); |
|
39 INFO_PRINTF3(_L("In %S, arg is %S"), &KTestFunction, &arg); |
|
40 |
|
41 if(arg == _L("WriteBigTable")) |
|
42 WriteBigTableL(acfgblk, acnnum); |
|
43 else if(arg == _L("ReadBigTable")) |
|
44 ReadBigTableL(acfgblk); |
|
45 |
|
46 // This assumes that a ParameterIndex and ColumnIndex call has been |
|
47 // set up previously - the apidxs/apicxs array access below will |
|
48 // certainly PANIC if you haven't done the require preparation.. |
|
49 else if(arg == _L("CopyCellsUsingStreams")) |
|
50 CopyCellsUsingStreamsL(acfgblk); |
|
51 else if(arg == _L("WriteIntsToStream")) |
|
52 WriteIntsToStream(acfgblk, acnnum); |
|
53 else if(arg == _L("NearFillDisk")) |
|
54 NearFillDisk(acfgblk); |
|
55 else if(arg == _L("ScalarFullSelect")) |
|
56 ScalarFullSelectL(acfgblk, acnnum); |
|
57 else if(arg == _L("FilesDifferBySize")) |
|
58 FilesDifferBySize(acfgblk, acnnum); |
|
59 else if(arg == _L("SecurityPolicyCheck")) |
|
60 SecurityPolicyCheck(acfgblk, acnnum); |
|
61 else if(arg == _L("CollationTest")) |
|
62 CollationTest(acfgblk, acnnum); |
|
63 |
|
64 else User::Panic(_L("Unknown Function"), 42); |
|
65 } |
|
66 |
|
67 // ------------------------------------------------------------------------ |
|
68 // |
|
69 // There's some hardwired nastiness in here - which we might be able to remove |
|
70 // if we can restructure the code (with the parameter index array as a |
|
71 // member variable in sqlfn), but until we can get reporting (INFO_PRINTF etc) |
|
72 // working in new objects that isn't going to happen. |
|
73 // There should have been a |
|
74 // 'Insert into t(what, ever, whatever) values (:FInt, :FReal, :FText)' |
|
75 // ... before this is called. Those on the right are the nasty hardwiring, |
|
76 // and should correspond to integer, real, and text fields. |
|
77 void CSQLCDT::WriteBigTableL(const TDesC &acfgblk, TInt acnnum ) |
|
78 { |
|
79 _LIT(KTestFunction, "WriteBigTable"); |
|
80 |
|
81 // Parameters for the loop. |
|
82 TInt low=1, high=10, step=1, experr = KErrNone; |
|
83 TReal mult; TPtrC text, experrS; |
|
84 FromConfig(KTestFunction, acfgblk, _L("LowCount"), low); |
|
85 FromConfig(KTestFunction, acfgblk, _L("HighCount"), high); |
|
86 FromConfig(KTestFunction, acfgblk, _L("CountStep"), step); |
|
87 FromConfig(KTestFunction, acfgblk, _L("Multiplier"), mult); |
|
88 FromConfig(KTestFunction, acfgblk, _L("Text"), text); |
|
89 if( FromConfig(KTestFunction, acfgblk, _L("EventuallyExpectedError"), experrS) ) |
|
90 experr = ErrStringToEnum(experrS); |
|
91 |
|
92 // First work out if out text is actually a filename.. |
|
93 TInt textfromfile=0; |
|
94 textfromfile = BaflUtils::FileExists(irfs, text); |
|
95 |
|
96 // Ahoy! Nasty hardwiring ahead! |
|
97 TInt pidxi = ParamIndex(_L(":FInt"), acfgblk, 0 ); |
|
98 TInt pidxr = ParamIndex(_L(":FReal"), acfgblk, 0 ); |
|
99 TInt pidxt = ParamIndex(_L(":FText"), acfgblk, 0 ); |
|
100 |
|
101 TInt i; |
|
102 for(i=low ; i<=high ; i+=step) |
|
103 { |
|
104 TInt err=KErrNone; |
|
105 // Can use a stream write for speed to write the text to the disk. Don't |
|
106 // make the file too big or a memory error (server side) will result. |
|
107 if(textfromfile) |
|
108 SWBindTextL(pidxt, text, acfgblk, acnnum); |
|
109 else |
|
110 { |
|
111 err = isqlst.BindText(pidxt, text); |
|
112 ReportOnError( KTestFunction, _L("BindText"), acfgblk, acnnum, err ); |
|
113 } |
|
114 |
|
115 TReal tr = i * mult; |
|
116 err = isqlst.BindInt(pidxi, i); |
|
117 ReportOnError( KTestFunction, _L("BindInt"), acfgblk, acnnum, err ); |
|
118 err = isqlst.BindReal(pidxr, tr); |
|
119 ReportOnError( KTestFunction, _L("BindReal"), acfgblk, acnnum, err); |
|
120 |
|
121 err = isqlst.Exec(); |
|
122 if((err != KErrNone) && (err == experr)) |
|
123 { |
|
124 INFO_PRINTF1(HTML_GREEN); |
|
125 INFO_PRINTF3(_L("Loop dropped out with expected error %S, i=%d"), &experrS, i ); |
|
126 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
127 break; |
|
128 } |
|
129 else if(err < 0) // <0 a real error we weren't expecting. |
|
130 { |
|
131 ReportOnError( KTestFunction, _L("Exec"), acfgblk, acnnum, err ); |
|
132 INFO_PRINTF3(_L("%S: counter i is %d"), &KTestFunction, i ); |
|
133 break; |
|
134 } |
|
135 |
|
136 err = isqlst.Reset(); |
|
137 ReportOnError( KTestFunction, _L("Reset"), acfgblk, acnnum, err ); |
|
138 acnnum++; |
|
139 } |
|
140 isqlst.Close(); |
|
141 |
|
142 return; |
|
143 } |
|
144 void CSQLCDT::ReadBigTableL(const TDesC &acfgblk) |
|
145 { |
|
146 _LIT(KTestFunction, "ReadBigTable"); |
|
147 |
|
148 // Parameters for the loop. |
|
149 TInt low=1, high=10, step=1, err; |
|
150 TReal mult; TPtrC text; |
|
151 FromConfig(KTestFunction, acfgblk, _L("LowCount"), low); |
|
152 FromConfig(KTestFunction, acfgblk, _L("HighCount"), high); |
|
153 FromConfig(KTestFunction, acfgblk, _L("CountStep"), step); |
|
154 FromConfig(KTestFunction, acfgblk, _L("Multiplier"), mult); |
|
155 FromConfig(KTestFunction, acfgblk, _L("Text"), text); |
|
156 |
|
157 // First work out if out text is actually a filename.. |
|
158 TInt textfromfile=0; |
|
159 textfromfile = BaflUtils::FileExists(irfs, text); |
|
160 |
|
161 // Ahoy! Nasty hardwiring ahead! |
|
162 TInt cidxi = ColumnIndex(_L("Someint"), acfgblk, 0 ); |
|
163 TInt cidxr = ColumnIndex(_L("Somereal"), acfgblk, 0 ); |
|
164 TInt cidxt = ColumnIndex(_L("Sometext"), acfgblk, 0 ); |
|
165 |
|
166 for(TInt i=low ; i<=high ; i+=step) |
|
167 { |
|
168 TReal tr = i * mult; |
|
169 // INFO_PRINTF3(_L("CFGBLK: %S COUNT: %d"), &acfgblk, i); |
|
170 |
|
171 TInt cint = isqlst.ColumnInt(cidxi); |
|
172 TReal creal = isqlst.ColumnReal(cidxr); |
|
173 if((cint != i) || (creal != tr)) |
|
174 { |
|
175 SetTestStepResult(EFail); |
|
176 INFO_PRINTF1(HTML_RED); |
|
177 ERR_PRINTF4(_L("%S: ColumnInt gave %d, wanted %d"), |
|
178 &KTestFunction, cint, i ); |
|
179 ERR_PRINTF4(_L("%S: ColumnReal gave %f, wanted %f"), |
|
180 &KTestFunction, creal, tr ); |
|
181 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
182 break; |
|
183 } |
|
184 // Now check the text.. |
|
185 if(textfromfile) |
|
186 SRColumnTextL(cidxt, text, acfgblk, -1 ); |
|
187 else |
|
188 ColumnTextL(cidxt, text, acfgblk, -1 ); |
|
189 if(isqlst.Next()==KSqlAtEnd) |
|
190 { |
|
191 // This expected error was for *writing* the table - we don't |
|
192 // get an error reading it back, just KSqlAtEnd. But lets assume |
|
193 // that an expected error on write implies a short table and |
|
194 // so no failure if we get KSqlAtEnd early. |
|
195 INFO_PRINTF1(HTML_GREEN); |
|
196 INFO_PRINTF3(_L("%S: Next gave KSqlAtEnd, i is %d"), |
|
197 &KTestFunction, i ); |
|
198 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
199 break; |
|
200 } |
|
201 } |
|
202 |
|
203 if( (err = isqlst.Next()) != KSqlErrMisuse ) |
|
204 { |
|
205 SetTestStepResult(EFail); |
|
206 INFO_PRINTF1(HTML_RED); |
|
207 ERR_PRINTF3(_L("%S: Next gave %d, is there some table left? Expected KSqlErrMisuse"), &KTestFunction, err ); |
|
208 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
209 } |
|
210 return; |
|
211 } |
|
212 |
|
213 |
|
214 // Copy a single cell in a table using streams. We'll use the BindBinary |
|
215 // and ColumnBinary methods of RSqlParamWriteStream and RSqlColumnReadStream |
|
216 // respectively. Don't try to copy integers or reals, as the API spec |
|
217 // says very clearly in a table, converting most of these to Binary |
|
218 // gives KNullDesc8. |
|
219 void CSQLCDT::CopyCellsUsingStreamsL(const TDesC &acfgblk) |
|
220 { |
|
221 _LIT(KTestFunction, "CopyCellUsingStreams"); |
|
222 |
|
223 // We only have one RSqlStatement around, and we must have two - a |
|
224 // source and destination, so lets get another one - we'll write to |
|
225 // this. |
|
226 RSqlStatement sqlst2; |
|
227 |
|
228 // The prepare statement used to add to the second table. |
|
229 TPtrC prep; |
|
230 FromConfig(KTestFunction, acfgblk, _L("PrepareStatement"), prep); |
|
231 // The parameter name (e.g :freddy) in the above. |
|
232 TPtrC paramname; |
|
233 FromConfig(KTestFunction, acfgblk, _L("ParamName"), paramname); |
|
234 |
|
235 // Prepare and get pidx. |
|
236 TInt err = sqlst2.Prepare(isqldb, prep); |
|
237 TInt pidx = sqlst2.ParameterIndex(paramname); |
|
238 |
|
239 // Whilst we're reading |
|
240 while(isqlst.Next() == KSqlAtRow) |
|
241 { |
|
242 // First lets find a cell to copy. This assumes there is a single |
|
243 // column selected.. |
|
244 // Set up where we're reading from. ColumnIndex will be zero. |
|
245 // Obviously a prepare must already have been done. |
|
246 RSqlColumnReadStream sqlr; |
|
247 err = sqlr.ColumnText(isqlst, 0); |
|
248 |
|
249 // Read a cell from the database as a stream. Pass that stream to |
|
250 // another stream, an RSqlParamWriteStream to copy the cell into |
|
251 // another db. |
|
252 |
|
253 // Get our writable stream.. |
|
254 RSqlParamWriteStream sqlw; |
|
255 |
|
256 // Set up where we're writing to. |
|
257 err = sqlw.BindText(sqlst2, pidx); |
|
258 |
|
259 // Write. |
|
260 sqlw.WriteL(sqlr); |
|
261 sqlw.Close(); |
|
262 err = sqlst2.Exec(); |
|
263 err = sqlst2.Reset(); |
|
264 } |
|
265 sqlst2.Close(); |
|
266 return; |
|
267 } |
|
268 |
|
269 // Write to 32-bit signed integers to a stream (a cell in a table) until |
|
270 // the write operation Leaves with a KErrNoMem. A 'prepare' statement |
|
271 // must already have been run, and a parameterindex also. We assume |
|
272 // that the parameterindex is zero. |
|
273 // If the user wants to do an Exec and Reset, that's up to them. That |
|
274 // would end up sticking a NULL into the current cell though. |
|
275 void CSQLCDT::WriteIntsToStream(const TDesC &acfgblk, const TInt acnnum) |
|
276 |
|
277 { |
|
278 _LIT(KTestFunction, "WriteIntsToStream"); |
|
279 |
|
280 // Get our writable stream.. |
|
281 RSqlParamWriteStream sqlw; |
|
282 // Find out how many integers to write.. |
|
283 TInt count; |
|
284 FromConfig(KTestFunction, acfgblk, _L("Count"), count); |
|
285 if(count == -1) count = 2000000000; |
|
286 |
|
287 // Assume only one 'ParameterIndex' has been run.. |
|
288 sqlw.BindBinary(isqlst,0); |
|
289 |
|
290 TInt i, leavecode; |
|
291 for(i=0 ; i<count ; i++) |
|
292 { |
|
293 // A fast way to send a lot of data down a stream.. |
|
294 TRAP(leavecode, sqlw.WriteInt32L(i)); |
|
295 if(leavecode != KErrNone) break; |
|
296 } |
|
297 // Close the stream immediately. If we've run out of memory (a common test) |
|
298 // this will free it up and allow (e.g) LogEngine to function so we get |
|
299 // proper error reports. |
|
300 sqlw.Close(); |
|
301 |
|
302 ReportOnError( KTestFunction, _L("Stream Write"), acfgblk, acnnum, leavecode ); |
|
303 INFO_PRINTF3(_L("%S bound %d integers"), &KTestFunction, i ); |
|
304 |
|
305 return; |
|
306 } |
|
307 |
|
308 // Create a file specified by 'FillFile' in the config and write to |
|
309 // it until 'DiskFree' bytes remain. Note that because files use whole |
|
310 // sectors (512/1024/2048/4096 or whatever bytes), that attempting to leave |
|
311 // (e.g) 1023 bytes could result in 512 bytes remaining on a file system |
|
312 // with 512 byte sectors, or zero bytes remaining if the sectors are bigger. |
|
313 void CSQLCDT::NearFillDisk(const TDesC &acfgblk) |
|
314 { |
|
315 _LIT(KTestFunction, "NearFillDisk"); |
|
316 |
|
317 // What file should we use? Requires a full path. |
|
318 TPtrC fillfile; |
|
319 (void)FromConfig(KTestFunction, acfgblk, _L("FillFile"), fillfile); |
|
320 irfs.Delete(fillfile); |
|
321 |
|
322 // Get the drive number. This method ignores trailing text. |
|
323 // Probably wants upper case. |
|
324 TDriveUnit tdu(fillfile); |
|
325 |
|
326 // Find out how much disk we want left.. |
|
327 TInt free, err; |
|
328 (void)FromConfig(KTestFunction, acfgblk, _L("DiskFree"), free); |
|
329 |
|
330 // Find out how much disk space currently remains.. |
|
331 TVolumeInfo vol; |
|
332 if((err = irfs.Volume(vol, tdu )) != KErrNone) |
|
333 { |
|
334 SetTestStepResult(EFail); |
|
335 INFO_PRINTF1(HTML_RED); |
|
336 ERR_PRINTF4(_L("%S: Failed to get volume info for %S, err %d"), |
|
337 &KTestFunction, &fillfile, err ); |
|
338 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
339 return; |
|
340 } |
|
341 |
|
342 // So how many bytes do we need to write? |
|
343 TInt towrite = vol.iFree - free; |
|
344 INFO_PRINTF4(_L("%S: Disk writing %d, free %d"), &KTestFunction, |
|
345 towrite, vol.iFree ); |
|
346 INFO_PRINTF3(_L("%S: free %d"), &KTestFunction, vol.iFree ); |
|
347 INFO_PRINTF3(_L("%S: writing %d"), &KTestFunction, towrite ); |
|
348 |
|
349 if( towrite < 0 ) |
|
350 { |
|
351 SetTestStepResult(EFail); |
|
352 INFO_PRINTF1(HTML_RED); |
|
353 ERR_PRINTF3(_L("%S: Disk wanted remaining less than current(%d)"), |
|
354 &KTestFunction, vol.iFree ); |
|
355 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
356 return; |
|
357 } |
|
358 |
|
359 // Get a file. |
|
360 RFile myfile; |
|
361 if( (err = myfile.Create(irfs, fillfile, EFileWrite)) != KErrNone ) |
|
362 { |
|
363 SetTestStepResult(EFail); |
|
364 INFO_PRINTF1(HTML_RED); |
|
365 ERR_PRINTF4(_L("%S: Failed to open RFile for file %S, err %d"), |
|
366 &KTestFunction, &fillfile, err ); |
|
367 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
368 return; |
|
369 } |
|
370 // Write it. |
|
371 |
|
372 // We seem to hit trouble if we just try to write 'towrite' bytes, so |
|
373 // here we write 50% of them and check the remainder repeatedly until |
|
374 // the right amount remains. Actually it is unlikely to be exactly the |
|
375 // right amount - depending on sector sizes and other factors the |
|
376 // remaining space tends to be a kilobyte or two less than requested. |
|
377 // Obviously this is likely to be different between file system types, |
|
378 // between hardware and emulator and so on. |
|
379 TInt size = 0; |
|
380 while(towrite > 0) |
|
381 { |
|
382 if(towrite < 1024) break; |
|
383 TInt tow = towrite/2; |
|
384 if(towrite < 4096) tow = towrite; |
|
385 size += tow; |
|
386 if( (err = myfile.SetSize(size)) != KErrNone ) |
|
387 { |
|
388 SetTestStepResult(EFail); |
|
389 INFO_PRINTF1(HTML_RED); |
|
390 ERR_PRINTF4(_L("%S: Failed on RFile::SetSize for file %S, err %d"), |
|
391 &KTestFunction, &fillfile, err ); |
|
392 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
393 break; |
|
394 } |
|
395 err = irfs.Volume(vol, tdu ); |
|
396 if(err != KErrNone) |
|
397 { |
|
398 SetTestStepResult(EFail); |
|
399 INFO_PRINTF1(HTML_RED); |
|
400 ERR_PRINTF3(_L("%S: 2-RFs::Volume() has failed, err=%d"), |
|
401 &KTestFunction, err); |
|
402 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
403 break; |
|
404 } |
|
405 towrite = vol.iFree - free; |
|
406 } |
|
407 |
|
408 err = irfs.Volume(vol, tdu ); |
|
409 if(err != KErrNone) |
|
410 { |
|
411 SetTestStepResult(EFail); |
|
412 INFO_PRINTF1(HTML_RED); |
|
413 ERR_PRINTF3(_L("%S: 3-RFs::Volume() has failed, err=%d"), |
|
414 &KTestFunction, err); |
|
415 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
416 } |
|
417 INFO_PRINTF3(_L("%S: Disk remaining is %d"), &KTestFunction, vol.iFree ); |
|
418 myfile.Close(); |
|
419 return; |
|
420 } |
|
421 |
|
422 // This method exercises the TSqlScalarFullSelectQuery class, which is |
|
423 // just a wrapper. Its methods expect a select statement whose result will |
|
424 // be a single cell. Perhaps this should be in sqlfn.cpp. |
|
425 void CSQLCDT::ScalarFullSelectL(const TDesC &acfgblk, const TInt acnnum) |
|
426 |
|
427 { |
|
428 _LIT(KTestFunction, "ScalarFullSelect"); |
|
429 |
|
430 // Look for an integer called 'Use_SetNN'. |
|
431 TInt useset; |
|
432 TBuf<KConfigItemMaxNameLength> conS(_L("Use_Set")); |
|
433 conS.AppendNum(acnnum); |
|
434 FromConfig(KTestFunction, acfgblk, conS, useset); |
|
435 // Look for a string called 'MethodNN'. |
|
436 TPtrC meth; |
|
437 TBuf<KConfigItemMaxNameLength> methS(_L("Method")); |
|
438 methS.AppendNum(acnnum); |
|
439 FromConfig(KTestFunction, acfgblk, methS, meth); |
|
440 // Look for a string called 'StatementNN'. |
|
441 TPtrC stmt; |
|
442 TBuf<KConfigItemMaxNameLength> stmtS(_L("Statement")); |
|
443 stmtS.AppendNum(acnnum); |
|
444 FromConfig(KTestFunction, acfgblk, stmtS, stmt); |
|
445 // Convert the SQL statement to an UTF-8 version. |
|
446 RBuf8 stmt8; |
|
447 stmt8.Create(stmt.Length()); |
|
448 stmt8.Copy(stmt); |
|
449 CleanupClosePushL(stmt8); |
|
450 |
|
451 // Look for a string called 'ResultNN'. |
|
452 TPtrC res; |
|
453 TBuf<KConfigItemMaxNameLength> resS(_L("Result")); |
|
454 resS.AppendNum(acnnum); |
|
455 FromConfig(KTestFunction, acfgblk, resS, res); |
|
456 // We may want to convert the expected result to a real or int or something |
|
457 TLex conv = res; |
|
458 |
|
459 // Ok, now create a TSqlScalarFullSelectQuery object. |
|
460 TSqlScalarFullSelectQuery *asfs; |
|
461 TSqlScalarFullSelectQuery one(isqldb); |
|
462 TSqlScalarFullSelectQuery two; |
|
463 two.SetDatabase(isqldb); |
|
464 // Use one of the above objects. |
|
465 asfs = useset ? &two : &one; |
|
466 |
|
467 // Get the action hash for this.. |
|
468 CSQLSFSTEFAction *cs = new CSQLSFSTEFAction(); |
|
469 TInt action = cs->GetNumFromString(meth); |
|
470 switch(action) |
|
471 { |
|
472 case CSQLSFSTEFAction::ESFS_SelectIntL: |
|
473 { |
|
474 TInt actual; |
|
475 if(i8bit) |
|
476 actual = asfs->SelectIntL(stmt8); |
|
477 else |
|
478 actual = asfs->SelectIntL(stmt); |
|
479 TInt expected; |
|
480 conv.Val(expected); |
|
481 if( actual != expected ) |
|
482 { |
|
483 SetTestStepResult(EFail); |
|
484 INFO_PRINTF1(HTML_RED); |
|
485 ERR_PRINTF4(_L("%S: SelectIntL gave %d, wanted %d"), |
|
486 &KTestFunction, actual, expected); |
|
487 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
488 } |
|
489 else |
|
490 { |
|
491 INFO_PRINTF1(HTML_GREEN); |
|
492 INFO_PRINTF3(_L("%S: SelectIntL gave %d, as expected"), |
|
493 &KTestFunction, actual); |
|
494 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
495 } |
|
496 } |
|
497 break; |
|
498 |
|
499 case CSQLSFSTEFAction::ESFS_SelectInt64L: |
|
500 { |
|
501 TInt64 actual; |
|
502 if(i8bit) |
|
503 actual = asfs->SelectInt64L(stmt8); |
|
504 else |
|
505 actual = asfs->SelectInt64L(stmt); |
|
506 TInt64 expected; |
|
507 conv.Val(expected); |
|
508 if( actual != expected ) |
|
509 { |
|
510 SetTestStepResult(EFail); |
|
511 INFO_PRINTF1(HTML_RED); |
|
512 ERR_PRINTF4(_L("%S: SelectInt64L gave %d, wanted %d"), |
|
513 &KTestFunction, actual, expected); |
|
514 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
515 } |
|
516 else |
|
517 { |
|
518 INFO_PRINTF1(HTML_GREEN); |
|
519 INFO_PRINTF3(_L("%S: SelectInt64L gave %d, as expected"), |
|
520 &KTestFunction, actual); |
|
521 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
522 } |
|
523 } |
|
524 break; |
|
525 |
|
526 case CSQLSFSTEFAction::ESFS_SelectRealL: |
|
527 { |
|
528 TReal actual; |
|
529 if(i8bit) |
|
530 actual = asfs->SelectRealL(stmt8); |
|
531 else |
|
532 actual = asfs->SelectRealL(stmt); |
|
533 TReal expected; |
|
534 conv.Val(expected); |
|
535 if( actual != expected ) |
|
536 { |
|
537 SetTestStepResult(EFail); |
|
538 INFO_PRINTF1(HTML_RED); |
|
539 ERR_PRINTF4(_L("%S: SelectRealL gave %f, wanted %f"), |
|
540 &KTestFunction, actual, expected); |
|
541 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
542 } |
|
543 else |
|
544 { |
|
545 INFO_PRINTF1(HTML_GREEN); |
|
546 INFO_PRINTF3(_L("%S: SelectRealL gave %f, as expected"), |
|
547 &KTestFunction, actual); |
|
548 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
549 } |
|
550 } |
|
551 break; |
|
552 |
|
553 case CSQLSFSTEFAction::ESFS_SelectTextL: |
|
554 { |
|
555 RBuf actual; |
|
556 actual.Create(32768); |
|
557 CleanupClosePushL(actual); |
|
558 TInt rc = KErrNone; |
|
559 if(i8bit) |
|
560 rc = asfs->SelectTextL(stmt8, actual); |
|
561 else |
|
562 rc = asfs->SelectTextL(stmt, actual); |
|
563 if( actual != res ) |
|
564 { |
|
565 SetTestStepResult(EFail); |
|
566 INFO_PRINTF1(HTML_RED); |
|
567 ERR_PRINTF4(_L("%S: SelectTextL gave %S, wanted %S"), |
|
568 &KTestFunction, &actual, &res); |
|
569 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
570 } |
|
571 else |
|
572 { |
|
573 INFO_PRINTF1(HTML_GREEN); |
|
574 INFO_PRINTF3(_L("%S: SelectTextL gave %S, as expected"), |
|
575 &KTestFunction, &actual); |
|
576 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
577 } |
|
578 ReportOnError( KTestFunction, _L("SelectTextL"), acfgblk, acnnum, |
|
579 rc ); |
|
580 CleanupStack::PopAndDestroy(1, &actual); |
|
581 } |
|
582 break; |
|
583 |
|
584 case CSQLSFSTEFAction::ESFS_SelectBinaryL: |
|
585 { |
|
586 RBuf8 actual; |
|
587 actual.Create(32768); |
|
588 CleanupClosePushL(actual); |
|
589 TInt rc = KErrNone; |
|
590 if(i8bit) |
|
591 rc = asfs->SelectBinaryL(stmt8, actual); |
|
592 else |
|
593 rc = asfs->SelectBinaryL(stmt, actual); |
|
594 ReportOnError( KTestFunction, _L("SelectBinaryL"), acfgblk, acnnum, rc ); |
|
595 if(!rc) |
|
596 { |
|
597 TInt rc2 = CompareBinaryAgainstFileL(actual, res); |
|
598 if(rc2) |
|
599 { |
|
600 SetTestStepResult(EFail); |
|
601 INFO_PRINTF1(HTML_RED); |
|
602 ERR_PRINTF3(_L("%S: File compare gave error %d"), |
|
603 &KTestFunction, rc2 ); |
|
604 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
605 } |
|
606 else |
|
607 { |
|
608 INFO_PRINTF1(HTML_GREEN); |
|
609 _LIT(KSelectBinaryStr, "SelectBinaryL"); |
|
610 ERR_PRINTF3(_L("%S: File compare successful, %S"), &KTestFunction, &KSelectBinaryStr); |
|
611 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
612 } |
|
613 |
|
614 } |
|
615 CleanupStack::PopAndDestroy(1, &actual); |
|
616 } |
|
617 break; |
|
618 |
|
619 default: User::Panic(_L("Unknown Function"), 49); |
|
620 |
|
621 } |
|
622 CleanupStack::PopAndDestroy(1, &stmt8); |
|
623 } |
|
624 |
|
625 // Verifies that two files differ by size. |
|
626 void CSQLCDT::FilesDifferBySize(const TDesC &acfgblk, const TInt acnnum) |
|
627 |
|
628 { |
|
629 _LIT(KTestFunction, "FilesDifferBySize"); |
|
630 |
|
631 // Look for a string called 'FileANN'. |
|
632 TPtrC filea; |
|
633 TBuf<KConfigItemMaxNameLength> fileaS(_L("FileA")); |
|
634 fileaS.AppendNum(acnnum); |
|
635 FromConfig(KTestFunction, acfgblk, fileaS, filea); |
|
636 // Look for a string called 'FileBNN'. |
|
637 TPtrC fileb; |
|
638 TBuf<KConfigItemMaxNameLength> filebS(_L("FileB")); |
|
639 filebS.AppendNum(acnnum); |
|
640 FromConfig(KTestFunction, acfgblk, filebS, fileb); |
|
641 |
|
642 TInt fza = FileSize(filea); |
|
643 TInt fzb = FileSize(fileb); |
|
644 if(fza == fzb) |
|
645 { |
|
646 SetTestStepResult(EFail); |
|
647 INFO_PRINTF1(HTML_RED); |
|
648 ERR_PRINTF4(_L("%S: File A %d, File B %d"), &KTestFunction, fza, fzb); |
|
649 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
650 } |
|
651 else |
|
652 { |
|
653 INFO_PRINTF1(HTML_GREEN); |
|
654 INFO_PRINTF6(_L("%S: Files %S and %S differ in size as expected, %d, %d"), &KTestFunction, &fileaS, &filebS, fza, fzb); |
|
655 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
656 } |
|
657 } |
|
658 |
|
659 // Tests the method that retrive security policies. |
|
660 void CSQLCDT::SecurityPolicyCheck(const TDesC &/*acfgblk*/, const TInt /*acnnum*/) |
|
661 { |
|
662 // _LIT(KTestFunction, "SecurityPolicyCheck"); |
|
663 |
|
664 // The methods to be tested here have been tested in the developer test: |
|
665 // t_sqlsecurityXX.cpp. The work here has been deferred because it has been |
|
666 // duplicated in the unit tests. |
|
667 } |
|
668 |
|
669 // Tests for Locale change |
|
670 // This test has been deferred pending a defect fix, defect is: |
|
671 // DEF091753 "Initialize locale" should be part of the system startup |
|
672 void CSQLCDT::CollationTest(const TDesC &/*acfgblk*/, const TInt /*acnnum*/) |
|
673 { |
|
674 TExtendedLocale myExtendedLocale; |
|
675 myExtendedLocale.LoadSystemSettings(); |
|
676 |
|
677 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL |
|
678 |
|
679 TBuf<100> DllLanguage; |
|
680 DllLanguage.Copy(_L("elocl_lan.003")); |
|
681 |
|
682 TBuf<100> DllRegion; |
|
683 DllRegion.Copy(_L("elocl_reg.056")); |
|
684 |
|
685 TBuf<100> DllCollation; |
|
686 DllCollation.Copy(_L("elocl_col.003")); |
|
687 |
|
688 // Change the locale |
|
689 TInt err = myExtendedLocale.LoadLocale(DllLanguage, DllRegion, DllCollation); |
|
690 |
|
691 #else |
|
692 |
|
693 TBuf<100> DllName; |
|
694 DllName.Copy(_L("elocl.sc")); |
|
695 |
|
696 // Change the locale to Scandinavian Locale |
|
697 TInt err = myExtendedLocale.LoadLocale(DllName); |
|
698 |
|
699 #endif |
|
700 if( err != KErrNone ) |
|
701 { |
|
702 _LIT(KTestFunction, "CollationTest"); |
|
703 SetTestStepResult(EFail); |
|
704 INFO_PRINTF1(HTML_RED); |
|
705 ERR_PRINTF4(_L("%S: TExtendedLocale::LoadLocale gave %d, wanted %d"), |
|
706 &KTestFunction, err, KErrNone); |
|
707 INFO_PRINTF1(HTML_COLOUR_OFF); |
|
708 } |
|
709 |
|
710 // Save the changes to system settings |
|
711 myExtendedLocale.SaveSystemSettings(); |
|
712 |
|
713 // Wait |
|
714 User::After(1000000); |
|
715 } |
|
716 |
|
717 |