os/persistentdata/persistentstorage/sql/TEST/testexecute/SQLite/src/cdtest.cpp
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/cdtest.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,788 @@
     1.4 +// Copyright (c) 2006-2010 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 +#include "cdtest.h"
    1.20 +#include "hashing.h"
    1.21 +#include "common.h"
    1.22 +#include<bautils.h>
    1.23 +
    1.24 +//Constants taken from SqlSrvConfig.h
    1.25 +#ifdef __WINSCW__
    1.26 +		const TInt KDefaultSoftHeapLimitKb = 1024;
    1.27 +#else
    1.28 +		const TInt KDefaultSoftHeapLimitKb = 8192;
    1.29 +#endif	
    1.30 +
    1.31 +// Includes any code required for 'Code-Driven' testing, generally tests
    1.32 +// that cannot be data-driven (or not completely).
    1.33 +
    1.34 +CSQLCDT::~CSQLCDT()
    1.35 +    {
    1.36 +    }
    1.37 +
    1.38 +CSQLCDT::CSQLCDT()
    1.39 +    {
    1.40 +    SetTestStepName(KSQLCDT);
    1.41 +    }
    1.42 +
    1.43 +
    1.44 +// Look at 'arg' and call whichever function is required.
    1.45 +void CSQLCDT::ResolveTestFunctionL(const TDesC &acfgblk, const TInt acnnum,
    1.46 +                                  const TPtrC &arg )
    1.47 +    {
    1.48 +    _LIT(KTestFunction, "cdtest::ResolveTestFunction");
    1.49 +    INFO_PRINTF3(_L("In %S, arg is %S"), &KTestFunction, &arg);
    1.50 +
    1.51 +    if(arg == _L("WriteBigTable"))
    1.52 +        WriteBigTableL(acfgblk, acnnum);
    1.53 +    else if(arg == _L("ReadBigTable"))
    1.54 +        ReadBigTableL(acfgblk);
    1.55 +
    1.56 +    // This assumes that a ParameterIndex and ColumnIndex call has been
    1.57 +    // set up previously - the apidxs/apicxs array access below will
    1.58 +    // certainly PANIC if you haven't done the require preparation..
    1.59 +    else if(arg == _L("CopyCellsUsingStreams"))
    1.60 +        CopyCellsUsingStreamsL(acfgblk);
    1.61 +    else if(arg == _L("WriteIntsToStream"))
    1.62 +        WriteIntsToStream(acfgblk, acnnum);
    1.63 +    else if(arg == _L("NearFillDisk"))
    1.64 +        NearFillDisk(acfgblk);
    1.65 +    else if(arg == _L("ScalarFullSelect"))
    1.66 +        ScalarFullSelectL(acfgblk, acnnum);
    1.67 +    else if(arg == _L("FilesDifferBySize"))
    1.68 +        FilesDifferBySize(acfgblk, acnnum);
    1.69 +    else if(arg == _L("SecurityPolicyCheck"))
    1.70 +        SecurityPolicyCheck(acfgblk, acnnum);
    1.71 +    else if(arg == _L("CollationTest"))
    1.72 +        CollationTest(acfgblk, acnnum);
    1.73 +    
    1.74 +    else User::Panic(_L("Unknown Function"), 42);
    1.75 +    }
    1.76 +
    1.77 +// ------------------------------------------------------------------------ 
    1.78 +//
    1.79 +// There's some hardwired nastiness in here - which we might be able to remove
    1.80 +// if we can restructure the code (with the parameter index array as a
    1.81 +// member variable in sqlfn), but until we can get reporting (INFO_PRINTF etc)
    1.82 +// working in new objects that isn't going to happen.
    1.83 +// There should have been a 
    1.84 +// 'Insert into t(what, ever, whatever) values (:FInt, :FReal, :FText)'
    1.85 +// ... before this is called. Those on the right are the nasty hardwiring,
    1.86 +// and should correspond to integer, real, and text fields.
    1.87 +void CSQLCDT::WriteBigTableL(const TDesC &acfgblk, TInt acnnum )
    1.88 +    {
    1.89 +    _LIT(KTestFunction, "WriteBigTable");
    1.90 +
    1.91 +    // Parameters for the loop.
    1.92 +    TInt low=1, high=10, step=1, experr = KErrNone;
    1.93 +    TReal mult; TPtrC text, experrS;
    1.94 +    FromConfig(KTestFunction, acfgblk, _L("LowCount"), low);
    1.95 +    FromConfig(KTestFunction, acfgblk, _L("HighCount"), high);
    1.96 +    FromConfig(KTestFunction, acfgblk, _L("CountStep"), step);
    1.97 +    FromConfig(KTestFunction, acfgblk, _L("Multiplier"), mult);
    1.98 +    FromConfig(KTestFunction, acfgblk, _L("Text"), text);
    1.99 +    if( FromConfig(KTestFunction, acfgblk, _L("EventuallyExpectedError"), experrS) )
   1.100 +        experr = ErrStringToEnum(experrS);
   1.101 +
   1.102 +    // First work out if out text is actually a filename..
   1.103 +    TInt textfromfile=0;
   1.104 +    textfromfile = BaflUtils::FileExists(irfs, text);
   1.105 +
   1.106 +    // Ahoy! Nasty hardwiring ahead!
   1.107 +    TInt pidxi = ParamIndex(_L(":FInt"), acfgblk, 0 );
   1.108 +    TInt pidxr = ParamIndex(_L(":FReal"), acfgblk, 0 );
   1.109 +    TInt pidxt = ParamIndex(_L(":FText"), acfgblk, 0 );
   1.110 +
   1.111 +    TInt i;
   1.112 +    for(i=low ; i<=high ; i+=step)
   1.113 +        {
   1.114 +        TInt err=KErrNone;
   1.115 +        // Can use a stream write for speed to write the text to the disk. Don't
   1.116 +        // make the file too big or a memory error (server side) will result.
   1.117 +        if(textfromfile)
   1.118 +            SWBindTextL(pidxt, text, acfgblk, acnnum);
   1.119 +        else
   1.120 +            {
   1.121 +            err = isqlst.BindText(pidxt, text);
   1.122 +            ReportOnError( KTestFunction, _L("BindText"), acfgblk, acnnum, err );
   1.123 +            }
   1.124 +
   1.125 +        TReal tr = i * mult;
   1.126 +        err = isqlst.BindInt(pidxi, i);
   1.127 +        ReportOnError( KTestFunction, _L("BindInt"), acfgblk, acnnum, err );
   1.128 +        err = isqlst.BindReal(pidxr, tr);
   1.129 +        ReportOnError( KTestFunction, _L("BindReal"), acfgblk, acnnum, err);
   1.130 +
   1.131 +        err = isqlst.Exec();
   1.132 +        if((err != KErrNone) && (err == experr))
   1.133 +            {
   1.134 +            INFO_PRINTF1(HTML_GREEN);
   1.135 +            INFO_PRINTF3(_L("Loop dropped out with expected error %S, i=%d"), &experrS, i );
   1.136 +            INFO_PRINTF1(HTML_COLOUR_OFF);
   1.137 +            break;
   1.138 +            }
   1.139 +        else if(err < 0)  // <0 a real error we weren't expecting.
   1.140 +            {
   1.141 +            ReportOnError( KTestFunction, _L("Exec"), acfgblk, acnnum, err );
   1.142 +            INFO_PRINTF3(_L("%S: counter i is %d"), &KTestFunction, i );
   1.143 +            break;
   1.144 +            }
   1.145 +
   1.146 +        err = isqlst.Reset();
   1.147 +        ReportOnError( KTestFunction, _L("Reset"), acfgblk, acnnum, err );
   1.148 +        acnnum++;
   1.149 +        }
   1.150 +    isqlst.Close();
   1.151 +
   1.152 +    return;
   1.153 +    }
   1.154 +void CSQLCDT::ReadBigTableL(const TDesC &acfgblk)
   1.155 +    {
   1.156 +    _LIT(KTestFunction, "ReadBigTable");
   1.157 +
   1.158 +    // Parameters for the loop.
   1.159 +    TInt low=1, high=10, step=1, err;
   1.160 +    TReal mult; TPtrC text;
   1.161 +    FromConfig(KTestFunction, acfgblk, _L("LowCount"), low);
   1.162 +    FromConfig(KTestFunction, acfgblk, _L("HighCount"), high);
   1.163 +    FromConfig(KTestFunction, acfgblk, _L("CountStep"), step);
   1.164 +    FromConfig(KTestFunction, acfgblk, _L("Multiplier"), mult);
   1.165 +    FromConfig(KTestFunction, acfgblk, _L("Text"), text);
   1.166 +
   1.167 +    // First work out if out text is actually a filename..
   1.168 +    TInt textfromfile=0;
   1.169 +    textfromfile = BaflUtils::FileExists(irfs, text);
   1.170 +
   1.171 +    // Ahoy! Nasty hardwiring ahead!
   1.172 +    TInt cidxi = ColumnIndex(_L("Someint"), acfgblk, 0 );
   1.173 +    TInt cidxr = ColumnIndex(_L("Somereal"), acfgblk, 0 );
   1.174 +    TInt cidxt = ColumnIndex(_L("Sometext"), acfgblk, 0 );
   1.175 +
   1.176 +    for(TInt i=low ; i<=high ; i+=step)
   1.177 +        {
   1.178 +        TReal tr = i * mult;
   1.179 +// INFO_PRINTF3(_L("CFGBLK: %S        COUNT: %d"), &acfgblk, i);
   1.180 +
   1.181 +        TInt cint = isqlst.ColumnInt(cidxi);
   1.182 +        TReal creal = isqlst.ColumnReal(cidxr);
   1.183 +        if((cint != i) || (creal != tr))
   1.184 +            {
   1.185 +            SetTestStepResult(EFail);
   1.186 +            INFO_PRINTF1(HTML_RED);
   1.187 +            ERR_PRINTF4(_L("%S: ColumnInt gave %d, wanted %d"),
   1.188 +                           &KTestFunction, cint, i );
   1.189 +            ERR_PRINTF4(_L("%S: ColumnReal gave %f, wanted %f"),
   1.190 +                           &KTestFunction, creal, tr );
   1.191 +            INFO_PRINTF1(HTML_COLOUR_OFF);
   1.192 +            break;
   1.193 +            }
   1.194 +        // Now check the text..
   1.195 +        if(textfromfile)
   1.196 +            SRColumnTextL(cidxt, text, acfgblk, -1 );
   1.197 +        else
   1.198 +            ColumnTextL(cidxt, text, acfgblk, -1 );
   1.199 +        if(isqlst.Next()==KSqlAtEnd)
   1.200 +            {
   1.201 +            // This expected error was for *writing* the table - we don't
   1.202 +            // get an error reading it back, just KSqlAtEnd. But lets assume
   1.203 +            // that an expected error on write implies a short table and
   1.204 +            // so no failure if we get KSqlAtEnd early.
   1.205 +            INFO_PRINTF1(HTML_GREEN);
   1.206 +            INFO_PRINTF3(_L("%S: Next gave KSqlAtEnd, i is %d"),
   1.207 +                                                   &KTestFunction, i );
   1.208 +            INFO_PRINTF1(HTML_COLOUR_OFF);
   1.209 +            break;
   1.210 +            }
   1.211 +        }
   1.212 +
   1.213 +    if( (err = isqlst.Next()) != KSqlErrMisuse )
   1.214 +        {
   1.215 +        SetTestStepResult(EFail);
   1.216 +        INFO_PRINTF1(HTML_RED);
   1.217 +        ERR_PRINTF3(_L("%S: Next gave %d, is there some table left? Expected KSqlErrMisuse"), &KTestFunction, err );
   1.218 +        INFO_PRINTF1(HTML_COLOUR_OFF);
   1.219 +        }
   1.220 +    return;
   1.221 +    }
   1.222 +
   1.223 +
   1.224 +// Copy a single cell in a table using streams. We'll use the BindBinary
   1.225 +// and ColumnBinary methods of RSqlParamWriteStream and RSqlColumnReadStream
   1.226 +// respectively. Don't try to copy integers or reals, as the API spec
   1.227 +// says very clearly in a table, converting most of these to Binary
   1.228 +// gives KNullDesc8.
   1.229 +void CSQLCDT::CopyCellsUsingStreamsL(const TDesC &acfgblk) 
   1.230 +    {
   1.231 +    _LIT(KTestFunction, "CopyCellUsingStreams");
   1.232 +
   1.233 +    // We only have one RSqlStatement around, and we must have two - a
   1.234 +    // source and destination, so lets get another one - we'll write to
   1.235 +    // this.
   1.236 +    RSqlStatement sqlst2;
   1.237 +    
   1.238 +    // The prepare statement used to add to the second table.
   1.239 +    TPtrC prep;
   1.240 +    FromConfig(KTestFunction, acfgblk, _L("PrepareStatement"), prep);
   1.241 +    // The parameter name (e.g :freddy) in the above.
   1.242 +    TPtrC paramname;
   1.243 +    FromConfig(KTestFunction, acfgblk, _L("ParamName"), paramname);
   1.244 +
   1.245 +    // Prepare and get pidx.
   1.246 +    TInt err = sqlst2.Prepare(isqldb, prep);
   1.247 +    TInt pidx = sqlst2.ParameterIndex(paramname);
   1.248 +
   1.249 +    // Whilst we're reading 
   1.250 +    while(isqlst.Next() == KSqlAtRow)
   1.251 +        {
   1.252 +        // First lets find a cell to copy. This assumes there is a single
   1.253 +        // column selected..
   1.254 +        // Set up where we're reading from. ColumnIndex will be zero.
   1.255 +        // Obviously a prepare must already have been done.
   1.256 +        RSqlColumnReadStream sqlr;
   1.257 +        err = sqlr.ColumnText(isqlst, 0);
   1.258 +    
   1.259 +        // Read a cell from the database as a stream. Pass that stream to
   1.260 +        // another stream, an RSqlParamWriteStream to copy the cell into
   1.261 +        // another db.
   1.262 +    
   1.263 +        // Get our writable stream..
   1.264 +        RSqlParamWriteStream sqlw;
   1.265 +    
   1.266 +        // Set up where we're writing to.
   1.267 +        err = sqlw.BindText(sqlst2, pidx);
   1.268 +    
   1.269 +        // Write.
   1.270 +        sqlw.WriteL(sqlr);
   1.271 +        sqlw.Close();
   1.272 +        err = sqlst2.Exec();
   1.273 +        err = sqlst2.Reset();
   1.274 +        }
   1.275 +    sqlst2.Close();
   1.276 +    return;
   1.277 +    }
   1.278 +
   1.279 +// Write to 32-bit signed integers to a stream (a cell in a table) until
   1.280 +// the write operation Leaves with a KErrNoMem. A 'prepare' statement
   1.281 +// must already have been run, and a parameterindex also. We assume
   1.282 +// that the parameterindex is zero.
   1.283 +// If the user wants to do an Exec and Reset, that's up to them. That
   1.284 +// would end up sticking a NULL into the current cell though.
   1.285 +void CSQLCDT::WriteIntsToStream(const TDesC &acfgblk, const TInt acnnum)
   1.286 +                                   
   1.287 +    {
   1.288 +    _LIT(KTestFunction, "WriteIntsToStream");
   1.289 +
   1.290 +    // Get our writable stream..
   1.291 +    RSqlParamWriteStream sqlw;
   1.292 +    // Find out how many integers to write..
   1.293 +    TInt count;
   1.294 +    FromConfig(KTestFunction, acfgblk, _L("Count"), count);
   1.295 +    if(count == -1) count = 2000000000;
   1.296 +
   1.297 +    // Assume only one 'ParameterIndex' has been run..
   1.298 +    sqlw.BindBinary(isqlst,0);
   1.299 +
   1.300 +    TInt i, leavecode;
   1.301 +    for(i=0 ; i<count ; i++)
   1.302 +        {
   1.303 +        // A fast way to send a lot of data down a stream..
   1.304 +        TRAP(leavecode, sqlw.WriteInt32L(i));
   1.305 +        if(leavecode != KErrNone) break;
   1.306 +        }
   1.307 +    // Close the stream immediately. If we've run out of memory (a common test)
   1.308 +    // this will free it up and allow (e.g) LogEngine to function so we get
   1.309 +    // proper error reports.
   1.310 +    sqlw.Close();
   1.311 +
   1.312 +    ReportOnError( KTestFunction, _L("Stream Write"), acfgblk, acnnum, leavecode );
   1.313 +    INFO_PRINTF3(_L("%S bound %d integers"), &KTestFunction, i );
   1.314 +
   1.315 +    return;
   1.316 +    }
   1.317 +
   1.318 +//This function is needed for drives with more free space than KMaxTUint32 (4GB -1) 
   1.319 +//This is because in a FAT32 file system, the maximum file size is (4GB-1)
   1.320 +//In the case where the free space is larger than this limit, this function will create additional 
   1.321 +//file(s)until the disk is under the (4GB-1) limit. After that CSQLCDT::NearFillDisk will fill the 
   1.322 +//disk up to the required amount.
   1.323 +void CSQLCDT::PrepareLargeDisk(const TDesC& /*acfgblk*/, const TDriveUnit atdu, TInt64 &atowrite)
   1.324 +    {
   1.325 +    _LIT(KTestFunction, "PrepareLargeDisk");
   1.326 +    _LIT(KFillDiskName,"\\FillDisk");
   1.327 +    _LIT(KFillDiskExt,".txt");
   1.328 +    TFileName fname;
   1.329 +    TInt count = 1;
   1.330 +    TInt err = 0;
   1.331 +    
   1.332 +    while(atowrite > KMaxTUint32)
   1.333 +        {
   1.334 +        RFile64 fillDiskFile;
   1.335 +        fname.Copy(atdu.Name());
   1.336 +        fname.Append(KFillDiskName);
   1.337 +        fname.AppendNum(count);
   1.338 +        fname.Append(KFillDiskExt);
   1.339 +        
   1.340 +        if( (err = fillDiskFile.Create(irfs, fname, EFileWrite)) != KErrNone )
   1.341 +            {
   1.342 +            SetTestStepResult(EFail);
   1.343 +            INFO_PRINTF1(HTML_RED);
   1.344 +            ERR_PRINTF4(_L("%S: Failed to open RFile64 for file %S, err %d"),
   1.345 +                               &KTestFunction, &fname, err );
   1.346 +            INFO_PRINTF1(HTML_COLOUR_OFF);
   1.347 +            return;
   1.348 +            }
   1.349 +        
   1.350 +        if( (err = fillDiskFile.SetSize(KMaxTUint32)) != KErrNone )
   1.351 +            {
   1.352 +            SetTestStepResult(EFail);
   1.353 +            INFO_PRINTF1(HTML_RED);
   1.354 +            ERR_PRINTF4(_L("%S: Failed on RFile64::SetSize for file %S, err %d"),
   1.355 +                               &KTestFunction, &fname, err );
   1.356 +            INFO_PRINTF1(HTML_COLOUR_OFF);
   1.357 +            fillDiskFile.Close();
   1.358 +            return;
   1.359 +            }
   1.360 +        
   1.361 +        fillDiskFile.Close();
   1.362 +        atowrite-=KMaxTUint32;
   1.363 +        count++;
   1.364 +        }
   1.365 +    }
   1.366 +
   1.367 +// Create a file specified by 'FillFile' in the config and write to
   1.368 +// it until 'DiskFree' bytes remain. Note that because files use whole
   1.369 +// sectors (512/1024/2048/4096 or whatever bytes), that attempting to leave
   1.370 +// (e.g) 1023 bytes could result in 512 bytes remaining on a file system
   1.371 +// with 512 byte sectors, or zero bytes remaining if the sectors are bigger.
   1.372 +void CSQLCDT::NearFillDisk(const TDesC &acfgblk)
   1.373 +    {
   1.374 +    _LIT(KTestFunction, "NearFillDisk");
   1.375 +
   1.376 +    // What file should we use? Requires a full path.
   1.377 +    TPtrC fillfile;
   1.378 +    (void)FromConfig(KTestFunction, acfgblk, _L("FillFile"), fillfile);
   1.379 +    irfs.Delete(fillfile);
   1.380 +
   1.381 +    // Get the drive number. This method ignores trailing text.
   1.382 +    // Probably wants upper case.
   1.383 +    TDriveUnit tdu(fillfile);
   1.384 +
   1.385 +    // Find out how much disk we want left.. 
   1.386 +    TInt free, err;
   1.387 +    (void)FromConfig(KTestFunction, acfgblk, _L("DiskFree"), free);
   1.388 +
   1.389 +    // Find out how much disk space currently remains..
   1.390 +    TVolumeInfo vol;
   1.391 +    if((err = irfs.Volume(vol, tdu )) != KErrNone)
   1.392 +        {
   1.393 +        SetTestStepResult(EFail);
   1.394 +        INFO_PRINTF1(HTML_RED);
   1.395 +        ERR_PRINTF4(_L("%S: Failed to get volume info for %S, err %d"),
   1.396 +                           &KTestFunction, &fillfile, err );
   1.397 +        INFO_PRINTF1(HTML_COLOUR_OFF);
   1.398 +        return;
   1.399 +        }
   1.400 +
   1.401 +    // So how many bytes do we need to write?
   1.402 +    TInt64 towrite = vol.iFree - free;
   1.403 +    INFO_PRINTF4(_L("%S: Disk writing %Ld, free %Ld"), &KTestFunction, 
   1.404 +                    towrite, vol.iFree );
   1.405 +    INFO_PRINTF3(_L("%S: free %Ld"), &KTestFunction, vol.iFree );
   1.406 +    INFO_PRINTF3(_L("%S: writing %Ld"), &KTestFunction, towrite );
   1.407 +
   1.408 +    if( towrite < 0 )
   1.409 +        {
   1.410 +        SetTestStepResult(EFail);
   1.411 +        INFO_PRINTF1(HTML_RED);
   1.412 +        ERR_PRINTF3(_L("%S: Disk wanted remaining less than current(%Ld)"),
   1.413 +                           &KTestFunction, vol.iFree );
   1.414 +        INFO_PRINTF1(HTML_COLOUR_OFF);
   1.415 +        return;
   1.416 +        }
   1.417 +    
   1.418 +    //In case the disk is large (i.e >4G -1 bytes) we need another function to 
   1.419 +    //create more files to fill it
   1.420 +    PrepareLargeDisk(acfgblk, tdu, towrite);
   1.421 +    
   1.422 +    // Get a file.
   1.423 +    RFile64 myfile;
   1.424 +    if( (err = myfile.Create(irfs, fillfile, EFileWrite)) != KErrNone )
   1.425 +        {
   1.426 +        SetTestStepResult(EFail);
   1.427 +        INFO_PRINTF1(HTML_RED);
   1.428 +        ERR_PRINTF4(_L("%S: Failed to open RFile64 for file %S, err %d"),
   1.429 +                           &KTestFunction, &fillfile, err );
   1.430 +        INFO_PRINTF1(HTML_COLOUR_OFF);
   1.431 +        return;
   1.432 +        }
   1.433 +    // Write it.
   1.434 +
   1.435 +    // We seem to hit trouble if we just try to write 'towrite' bytes, so
   1.436 +    // here we write 50% of them and check the remainder repeatedly until
   1.437 +    // the right amount remains. Actually it is unlikely to be exactly the
   1.438 +    // right amount - depending on sector sizes and other factors the
   1.439 +    // remaining space tends to be a kilobyte or two less than requested.
   1.440 +    // Obviously this is likely to be different between file system types,
   1.441 +    // between hardware and emulator and so on.
   1.442 +    
   1.443 +    
   1.444 +    TInt64 size = 0;
   1.445 +    while(towrite > 0)
   1.446 +        {
   1.447 +        if(towrite < 1024) break;
   1.448 +        TInt64 tow = towrite/2;
   1.449 +        if(towrite < 4096) tow = towrite;
   1.450 +		size += tow;
   1.451 +        if( (err = myfile.SetSize(size)) != KErrNone )
   1.452 +            {
   1.453 +            SetTestStepResult(EFail);
   1.454 +            INFO_PRINTF1(HTML_RED);
   1.455 +            ERR_PRINTF4(_L("%S: Failed on RFile64::SetSize for file %S, err %d"),
   1.456 +                               &KTestFunction, &fillfile, err );
   1.457 +            INFO_PRINTF1(HTML_COLOUR_OFF);
   1.458 +			break;
   1.459 +            }
   1.460 +        err = irfs.Volume(vol, tdu );
   1.461 +        if(err != KErrNone)
   1.462 +        	{
   1.463 +            SetTestStepResult(EFail);
   1.464 +            INFO_PRINTF1(HTML_RED);
   1.465 +            ERR_PRINTF3(_L("%S: 2-RFs::Volume() has failed, err=%d"),
   1.466 +                               &KTestFunction, err);
   1.467 +            INFO_PRINTF1(HTML_COLOUR_OFF);
   1.468 +            break;
   1.469 +        	}
   1.470 +        towrite = vol.iFree - free;
   1.471 +        }
   1.472 +
   1.473 +    err = irfs.Volume(vol, tdu );
   1.474 +    if(err != KErrNone)
   1.475 +    	{
   1.476 +        SetTestStepResult(EFail);
   1.477 +        INFO_PRINTF1(HTML_RED);
   1.478 +        ERR_PRINTF3(_L("%S: 3-RFs::Volume() has failed, err=%d"),
   1.479 +                           &KTestFunction, err);
   1.480 +        INFO_PRINTF1(HTML_COLOUR_OFF);
   1.481 +    	}
   1.482 +    INFO_PRINTF3(_L("%S: Disk remaining is %Ld"), &KTestFunction, vol.iFree );
   1.483 +	myfile.Close();
   1.484 +    return;
   1.485 +    }
   1.486 +
   1.487 +// This method exercises the TSqlScalarFullSelectQuery class, which is
   1.488 +// just a wrapper. Its methods expect a select statement whose result will
   1.489 +// be a single cell. Perhaps this should be in sqlfn.cpp.
   1.490 +void CSQLCDT::ScalarFullSelectL(const TDesC &acfgblk, const TInt acnnum)
   1.491 +                                   
   1.492 +    {
   1.493 +    _LIT(KTestFunction, "ScalarFullSelect");
   1.494 +
   1.495 +    // Look for an integer called 'Use_SetNN'.
   1.496 +    TInt useset;
   1.497 +    TBuf<KConfigItemMaxNameLength> conS(_L("Use_Set"));
   1.498 +    conS.AppendNum(acnnum);
   1.499 +    FromConfig(KTestFunction, acfgblk, conS, useset);
   1.500 +    // Look for a string called 'MethodNN'.
   1.501 +    TPtrC meth;
   1.502 +    TBuf<KConfigItemMaxNameLength> methS(_L("Method"));
   1.503 +    methS.AppendNum(acnnum);
   1.504 +    FromConfig(KTestFunction, acfgblk, methS, meth);
   1.505 +    // Look for a string called 'StatementNN'.
   1.506 +    TPtrC stmt;
   1.507 +    TBuf<KConfigItemMaxNameLength> stmtS(_L("Statement"));
   1.508 +    stmtS.AppendNum(acnnum);
   1.509 +    FromConfig(KTestFunction, acfgblk, stmtS, stmt);
   1.510 +    // Convert the SQL statement to an UTF-8 version.
   1.511 +    RBuf8 stmt8;
   1.512 +    stmt8.Create(stmt.Length());
   1.513 +    stmt8.Copy(stmt);
   1.514 +    CleanupClosePushL(stmt8);
   1.515 +
   1.516 +    // Look for a string called 'ResultNN'.
   1.517 +    TPtrC res;
   1.518 +    TBuf<KConfigItemMaxNameLength> resS(_L("Result"));
   1.519 +    resS.AppendNum(acnnum);
   1.520 +    FromConfig(KTestFunction, acfgblk, resS, res);
   1.521 +    // We may want to convert the expected result to a real or int or something
   1.522 +    TLex conv = res;
   1.523 +
   1.524 +    // Ok, now create a TSqlScalarFullSelectQuery object.
   1.525 +    TSqlScalarFullSelectQuery *asfs;
   1.526 +    TSqlScalarFullSelectQuery one(isqldb);
   1.527 +    TSqlScalarFullSelectQuery two;
   1.528 +    two.SetDatabase(isqldb);
   1.529 +    // Use one of the above objects.
   1.530 +    asfs = useset ? &two : &one;
   1.531 +
   1.532 +    // Get the action hash for this..
   1.533 +    CSQLSFSTEFAction *cs = new CSQLSFSTEFAction();
   1.534 +    TInt action = cs->GetNumFromString(meth);
   1.535 +    switch(action)
   1.536 +        {
   1.537 +        case CSQLSFSTEFAction::ESFS_SelectIntL:
   1.538 +            {
   1.539 +            TInt actual;
   1.540 +            if(i8bit)
   1.541 +                actual = asfs->SelectIntL(stmt8);
   1.542 +            else
   1.543 +                actual = asfs->SelectIntL(stmt);
   1.544 +				
   1.545 +            TInt expected;
   1.546 +			if (res.CompareF(_L("DEFAULT_SOFT_HEAP_LIMIT")) == 0)
   1.547 +				{
   1.548 +				expected = KDefaultSoftHeapLimitKb;
   1.549 +				}
   1.550 +			else
   1.551 +				{
   1.552 +				conv.Val(expected);
   1.553 +				}
   1.554 +				
   1.555 +            if( actual != expected )
   1.556 +                {
   1.557 +                SetTestStepResult(EFail);
   1.558 +                INFO_PRINTF1(HTML_RED);
   1.559 +                ERR_PRINTF4(_L("%S: SelectIntL gave %d, wanted %d"),
   1.560 +                       &KTestFunction, actual,  expected);
   1.561 +                INFO_PRINTF1(HTML_COLOUR_OFF);
   1.562 +                }
   1.563 +            else
   1.564 +                {
   1.565 +                INFO_PRINTF1(HTML_GREEN);
   1.566 +                INFO_PRINTF3(_L("%S: SelectIntL gave %d, as expected"),
   1.567 +                       &KTestFunction, actual);
   1.568 +                INFO_PRINTF1(HTML_COLOUR_OFF);
   1.569 +                }
   1.570 +            }
   1.571 +            break;
   1.572 +
   1.573 +        case CSQLSFSTEFAction::ESFS_SelectInt64L:
   1.574 +            {
   1.575 +            TInt64 actual;
   1.576 +            if(i8bit)
   1.577 +                actual = asfs->SelectInt64L(stmt8);
   1.578 +            else
   1.579 +                actual = asfs->SelectInt64L(stmt);
   1.580 +            TInt64 expected;
   1.581 +            conv.Val(expected);
   1.582 +            if( actual != expected )
   1.583 +                {
   1.584 +                SetTestStepResult(EFail);
   1.585 +                INFO_PRINTF1(HTML_RED);
   1.586 +                ERR_PRINTF4(_L("%S: SelectInt64L gave %d, wanted %d"),
   1.587 +                       &KTestFunction, actual,  expected);
   1.588 +                INFO_PRINTF1(HTML_COLOUR_OFF);
   1.589 +                }
   1.590 +            else
   1.591 +                {
   1.592 +                INFO_PRINTF1(HTML_GREEN);
   1.593 +                INFO_PRINTF3(_L("%S: SelectInt64L gave %d, as expected"),
   1.594 +                       &KTestFunction, actual);
   1.595 +                INFO_PRINTF1(HTML_COLOUR_OFF);
   1.596 +                }
   1.597 +            }
   1.598 +            break;
   1.599 +
   1.600 +        case CSQLSFSTEFAction::ESFS_SelectRealL:
   1.601 +            {
   1.602 +            TReal actual;
   1.603 +            if(i8bit)
   1.604 +                actual = asfs->SelectRealL(stmt8);
   1.605 +            else
   1.606 +                actual = asfs->SelectRealL(stmt);
   1.607 +            TReal expected;
   1.608 +            conv.Val(expected);
   1.609 +            if( actual != expected )
   1.610 +                {
   1.611 +                SetTestStepResult(EFail);
   1.612 +                INFO_PRINTF1(HTML_RED);
   1.613 +                ERR_PRINTF4(_L("%S: SelectRealL gave %f, wanted %f"),
   1.614 +                       &KTestFunction, actual,  expected);
   1.615 +                INFO_PRINTF1(HTML_COLOUR_OFF);
   1.616 +                }
   1.617 +            else
   1.618 +                {
   1.619 +                INFO_PRINTF1(HTML_GREEN);
   1.620 +                INFO_PRINTF3(_L("%S: SelectRealL gave %f, as expected"),
   1.621 +                       &KTestFunction, actual);
   1.622 +                INFO_PRINTF1(HTML_COLOUR_OFF);
   1.623 +                }
   1.624 +            }
   1.625 +            break;
   1.626 +
   1.627 +        case CSQLSFSTEFAction::ESFS_SelectTextL:
   1.628 +            {
   1.629 +            RBuf actual;
   1.630 +            actual.Create(32768);
   1.631 +            CleanupClosePushL(actual);
   1.632 +            TInt rc = KErrNone;
   1.633 +            if(i8bit)
   1.634 +                rc = asfs->SelectTextL(stmt8, actual);
   1.635 +            else
   1.636 +                rc = asfs->SelectTextL(stmt, actual);
   1.637 +            if( actual != res )
   1.638 +                {
   1.639 +                SetTestStepResult(EFail);
   1.640 +                INFO_PRINTF1(HTML_RED);
   1.641 +                ERR_PRINTF4(_L("%S: SelectTextL gave %S, wanted %S"),
   1.642 +                       &KTestFunction, &actual,  &res);
   1.643 +                INFO_PRINTF1(HTML_COLOUR_OFF);
   1.644 +                }
   1.645 +            else
   1.646 +                {
   1.647 +                INFO_PRINTF1(HTML_GREEN);
   1.648 +                INFO_PRINTF3(_L("%S: SelectTextL gave %S, as expected"),
   1.649 +                       &KTestFunction, &actual);
   1.650 +                INFO_PRINTF1(HTML_COLOUR_OFF);
   1.651 +                }
   1.652 +            ReportOnError( KTestFunction, _L("SelectTextL"), acfgblk, acnnum,
   1.653 +                                                                          rc );
   1.654 +            CleanupStack::PopAndDestroy(1, &actual);
   1.655 +        }
   1.656 +        break;
   1.657 +
   1.658 +        case CSQLSFSTEFAction::ESFS_SelectBinaryL:
   1.659 +            {
   1.660 +            RBuf8 actual;
   1.661 +            actual.Create(32768);
   1.662 +            CleanupClosePushL(actual);
   1.663 +            TInt rc = KErrNone;
   1.664 +            if(i8bit)
   1.665 +                rc = asfs->SelectBinaryL(stmt8, actual);
   1.666 +            else
   1.667 +                rc = asfs->SelectBinaryL(stmt, actual);
   1.668 +            ReportOnError( KTestFunction, _L("SelectBinaryL"), acfgblk, acnnum, rc );
   1.669 +            if(!rc)
   1.670 +                {
   1.671 +                TInt rc2 = CompareBinaryAgainstFileL(actual, res);
   1.672 +                if(rc2)
   1.673 +                    {
   1.674 +                    SetTestStepResult(EFail);
   1.675 +                    INFO_PRINTF1(HTML_RED);
   1.676 +                    ERR_PRINTF3(_L("%S: File compare gave error %d"),
   1.677 +                                     &KTestFunction, rc2 );
   1.678 +                    INFO_PRINTF1(HTML_COLOUR_OFF);
   1.679 +                    }
   1.680 +                else
   1.681 +                    {
   1.682 +                    INFO_PRINTF1(HTML_GREEN);
   1.683 +                    _LIT(KSelectBinaryStr, "SelectBinaryL");
   1.684 +                    ERR_PRINTF3(_L("%S: File compare successful, %S"), &KTestFunction, &KSelectBinaryStr);
   1.685 +                    INFO_PRINTF1(HTML_COLOUR_OFF);
   1.686 +                    }
   1.687 +
   1.688 +                }
   1.689 +            CleanupStack::PopAndDestroy(1, &actual);
   1.690 +            }
   1.691 +            break;
   1.692 +
   1.693 +        default: User::Panic(_L("Unknown Function"), 49);
   1.694 +
   1.695 +        }
   1.696 +    CleanupStack::PopAndDestroy(1, &stmt8);
   1.697 +    }
   1.698 +
   1.699 +// Verifies that two files differ by size.
   1.700 +void CSQLCDT::FilesDifferBySize(const TDesC &acfgblk, const TInt acnnum)
   1.701 +                                   
   1.702 +    {
   1.703 +    _LIT(KTestFunction, "FilesDifferBySize");
   1.704 +
   1.705 +    // Look for a string called 'FileANN'.
   1.706 +    TPtrC filea;
   1.707 +    TBuf<KConfigItemMaxNameLength> fileaS(_L("FileA"));
   1.708 +    fileaS.AppendNum(acnnum);
   1.709 +    FromConfig(KTestFunction, acfgblk, fileaS, filea);
   1.710 +    // Look for a string called 'FileBNN'.
   1.711 +    TPtrC fileb;
   1.712 +    TBuf<KConfigItemMaxNameLength> filebS(_L("FileB"));
   1.713 +    filebS.AppendNum(acnnum);
   1.714 +    FromConfig(KTestFunction, acfgblk, filebS, fileb);
   1.715 +
   1.716 +    TInt fza = FileSize(filea);
   1.717 +    TInt fzb = FileSize(fileb);
   1.718 +    if(fza == fzb)
   1.719 +        {
   1.720 +        SetTestStepResult(EFail);
   1.721 +        INFO_PRINTF1(HTML_RED);
   1.722 +        ERR_PRINTF4(_L("%S: File A %d, File B %d"), &KTestFunction, fza,  fzb);
   1.723 +        INFO_PRINTF1(HTML_COLOUR_OFF);
   1.724 +        }
   1.725 +    else
   1.726 +        {
   1.727 +        INFO_PRINTF1(HTML_GREEN);
   1.728 +        INFO_PRINTF6(_L("%S: Files %S and %S differ in size as expected, %d, %d"), &KTestFunction, &fileaS, &filebS, fza, fzb);
   1.729 +        INFO_PRINTF1(HTML_COLOUR_OFF);
   1.730 +        }
   1.731 +    }
   1.732 +
   1.733 +// Tests the method that retrive security policies.
   1.734 +void CSQLCDT::SecurityPolicyCheck(const TDesC &/*acfgblk*/, const TInt /*acnnum*/)
   1.735 +    {
   1.736 +//    _LIT(KTestFunction, "SecurityPolicyCheck");
   1.737 +    
   1.738 +    // The methods to be tested here have been tested in the developer test:
   1.739 +    // t_sqlsecurityXX.cpp. The work here has been deferred because it has been 
   1.740 +    // duplicated in the unit tests.
   1.741 +    }
   1.742 +
   1.743 +// Tests for Locale change
   1.744 +// This test has been deferred pending a defect fix, defect is:
   1.745 +// DEF091753 "Initialize locale" should be part of the system startup
   1.746 +void CSQLCDT::CollationTest(const TDesC &/*acfgblk*/, const TInt /*acnnum*/)
   1.747 +    {
   1.748 +    TExtendedLocale myExtendedLocale;
   1.749 +    myExtendedLocale.LoadSystemSettings();
   1.750 +
   1.751 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
   1.752 +    
   1.753 +    TBuf<100> DllLanguage; 
   1.754 +    DllLanguage.Copy(_L("elocl_lan.003"));
   1.755 +    
   1.756 +    TBuf<100> DllRegion; 
   1.757 +    DllRegion.Copy(_L("elocl_reg.056"));
   1.758 +    
   1.759 +    TBuf<100> DllCollation; 
   1.760 +    DllCollation.Copy(_L("elocl_col.003"));
   1.761 +    
   1.762 +    // Change the locale 
   1.763 +    TInt err = myExtendedLocale.LoadLocale(DllLanguage, DllRegion, DllCollation);
   1.764 +    
   1.765 +#else
   1.766 +    
   1.767 +    TBuf<100> DllName; 
   1.768 +    DllName.Copy(_L("elocl.sc"));
   1.769 +    
   1.770 +    // Change the locale to Scandinavian Locale 
   1.771 +    TInt err = myExtendedLocale.LoadLocale(DllName);    
   1.772 +    
   1.773 +#endif
   1.774 +    if( err != KErrNone )
   1.775 +        {
   1.776 +        _LIT(KTestFunction, "CollationTest");
   1.777 +        SetTestStepResult(EFail);
   1.778 +        INFO_PRINTF1(HTML_RED);
   1.779 +        ERR_PRINTF4(_L("%S: TExtendedLocale::LoadLocale gave %d, wanted %d"),
   1.780 +                          &KTestFunction, err,  KErrNone);
   1.781 +        INFO_PRINTF1(HTML_COLOUR_OFF);
   1.782 +        }
   1.783 +    
   1.784 +    // Save the changes to system settings
   1.785 +    myExtendedLocale.SaveSystemSettings();
   1.786 +
   1.787 +    // Wait
   1.788 +    User::After(1000000);
   1.789 +    }
   1.790 +
   1.791 +