os/persistentdata/persistentstorage/sql/TEST/testexecute/SQLite/src/sqlfn.cpp
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
// It would have been nice to create a new object every time we jump to
sl@0
    15
// a new config block but reporting (INFO_PRINTF and ERR_PRINTF) doesn't
sl@0
    16
// work from sub-objects. All in all the structure isn't what I'd like,
sl@0
    17
// perhaps I'm missing some TEF functionality which would get around this. 
sl@0
    18
// Various bits of repetition may be removed into utility class(es).
sl@0
    19
// Some utility methods probably should go into utility class(es).
sl@0
    20
// Unimplemented 8-bit methods, e.g Exec8.
sl@0
    21
// 
sl@0
    22
//
sl@0
    23
sl@0
    24
#include "sqlfn.h"
sl@0
    25
#include "Te_SQL_SuiteDefs.h"
sl@0
    26
#include "common.h"
sl@0
    27
sl@0
    28
// Contains code to perform functions on SQLite databases - what functions
sl@0
    29
// and in what order is determined by the content of the config (.ini) file.
sl@0
    30
sl@0
    31
CSQLFnStep::~CSQLFnStep()
sl@0
    32
/**
sl@0
    33
 * Destructor
sl@0
    34
 */
sl@0
    35
    {
sl@0
    36
    // Get rid of the RFs object.. Note this isn't set up in the constructor
sl@0
    37
    // but in doTestStepL.
sl@0
    38
    irfs.Close();
sl@0
    39
sl@0
    40
    // Get rid of the semaphore objects.
sl@0
    41
    isemA.Close();
sl@0
    42
    isemB.Close();
sl@0
    43
sl@0
    44
    // Get rid of the hashes. These are originally set up in doTestStepL.
sl@0
    45
    delete ierrhsh;
sl@0
    46
    delete icoltypehsh;
sl@0
    47
    delete iactionhsh;
sl@0
    48
    delete icaphsh;
sl@0
    49
    delete ipolhsh;
sl@0
    50
    delete iobjhsh;
sl@0
    51
sl@0
    52
    // Get rid of the config item.
sl@0
    53
    if(icfg)delete icfg;
sl@0
    54
    }
sl@0
    55
CSQLFnStep::CSQLFnStep()
sl@0
    56
    {
sl@0
    57
    // Create a global semaphore to be used by all instances of this framework
sl@0
    58
    // to be used for synchronising separate threads when 'CONCURRENT' is
sl@0
    59
    // used. If it already exists, then perhaps another thread already has it
sl@0
    60
    // which is fine - in that case just open it.
sl@0
    61
    TInt err = isemA.CreateGlobal(_L("SQLiteSemA"), 0);
sl@0
    62
    if(err == KErrAlreadyExists)
sl@0
    63
    	{
sl@0
    64
        err = isemA.OpenGlobal(_L("SQLiteSemA"));
sl@0
    65
    	}
sl@0
    66
    if(err != KErrNone)
sl@0
    67
    	{
sl@0
    68
		INFO_PRINTF2(_L("Error %d creating semaphore"), err);
sl@0
    69
		__ASSERT_ALWAYS(err == KErrNone, User::Invariant());
sl@0
    70
    	}
sl@0
    71
sl@0
    72
	//
sl@0
    73
	// Second semaphore require for DEF140385.
sl@0
    74
	//
sl@0
    75
    err = isemB.CreateGlobal(_L("SQLiteSemB"), 0);
sl@0
    76
    if(err == KErrAlreadyExists)
sl@0
    77
    	{
sl@0
    78
        err = isemB.OpenGlobal(_L("SQLiteSemB"));
sl@0
    79
    	}
sl@0
    80
    if(err != KErrNone)
sl@0
    81
    	{
sl@0
    82
		INFO_PRINTF2(_L("Error %d creating semaphoreB"), err);
sl@0
    83
		__ASSERT_ALWAYS(err == KErrNone, User::Invariant());
sl@0
    84
    	}
sl@0
    85
    }
sl@0
    86
TVerdict CSQLFnStep::doTestStepPostambleL()
sl@0
    87
    {
sl@0
    88
    // Try to make sure that the database and statement resources have been
sl@0
    89
    // properly closed (in case of problems).
sl@0
    90
    isqlst.Close();
sl@0
    91
    isqldb.Close();
sl@0
    92
    return TestStepResult();
sl@0
    93
    }
sl@0
    94
TVerdict CSQLFnStep::doTestStepL()
sl@0
    95
/**
sl@0
    96
 * @return - TVerdict code
sl@0
    97
 * Override of base class pure virtual. Our implementation only gets called
sl@0
    98
 * if the base class doTestStepPreambleL() did not leave. That being the case,
sl@0
    99
 * the current test result value will be EPass.
sl@0
   100
 */
sl@0
   101
    {
sl@0
   102
    // Create the RFs object so we can talk to the file-system when necessary.
sl@0
   103
    // Moved from the constructor to shut up leavescan.
sl@0
   104
    User::LeaveIfError(irfs.Connect());
sl@0
   105
    irfs.ShareProtected();
sl@0
   106
sl@0
   107
    // Make sure the database and statement objects get cleaned up..
sl@0
   108
    CleanupClosePushL(isqldb);
sl@0
   109
    CleanupClosePushL(isqlst);
sl@0
   110
sl@0
   111
    // Make sure that the icfg member is definitely unset when we start.
sl@0
   112
    icfg = NULL;
sl@0
   113
sl@0
   114
    // Get the hashes we use to associate words with numbers (e.g
sl@0
   115
    // KErrNone with 0). If these fail due to lack of memory they will
sl@0
   116
    // PANIC, which is fine. If we're that short of memory nothing is
sl@0
   117
    // going to work anyway.
sl@0
   118
    ierrhsh = new CSQLErrHash();
sl@0
   119
    icoltypehsh = new CSQLColTypeHash();
sl@0
   120
    iactionhsh = new CSQLTEFAction();
sl@0
   121
    icaphsh = new CSQLCapability();
sl@0
   122
    ipolhsh = new CSQLPolicy();
sl@0
   123
    iobjhsh = new CSQLObject();
sl@0
   124
     
sl@0
   125
    // Set the test result to PASS to start with and call the main block..
sl@0
   126
    SetTestStepResult(EPass);    
sl@0
   127
    SQLDbStepL(ConfigSection());
sl@0
   128
sl@0
   129
    // Clean up the database and statement objects.
sl@0
   130
    CleanupStack::PopAndDestroy(2, &isqldb);
sl@0
   131
sl@0
   132
    return TestStepResult();
sl@0
   133
    }
sl@0
   134
// This is our 'main' function. It works out what method (e.g RSqlStatement::
sl@0
   135
// Close) the user wants (based on the configuration file) and then calls
sl@0
   136
// the appropriate wrapper function which runs the wanted method and reports
sl@0
   137
// on any unexpected errors.
sl@0
   138
void CSQLFnStep::SQLDbStepL(const TPtrC& acfgblk)
sl@0
   139
    {
sl@0
   140
    _LIT(KTestFunction, "SQLDbStep");
sl@0
   141
sl@0
   142
    /*
sl@0
   143
     * Go through all of the actions defined in the configuration file
sl@0
   144
     * acting on each. The counter will keep incrementing until we
sl@0
   145
     * fail to find a config item called 'CreateNN', or 'OpenNN' etc.
sl@0
   146
     * The two arrays hold Parameter and Column indices for use in
sl@0
   147
     * any method that needs one. E.G..
sl@0
   148
     */
sl@0
   149
    TInt ended=0;
sl@0
   150
sl@0
   151
    iasync = i8bit = EFalse;
sl@0
   152
    for(TInt count=0 ; ; count++)
sl@0
   153
        {
sl@0
   154
        TPtrC argument;
sl@0
   155
        TInt whatfun=Efn_undefined;
sl@0
   156
        for(TInt i=0 ; i < Efn_undefined ; i++)
sl@0
   157
            {
sl@0
   158
            // Construct something like 'ColumnInt37'
sl@0
   159
            TBuf<KStatementFunMaxLength> stfn(*(iactionhsh->GetStringFromNum(i)));
sl@0
   160
            stfn.AppendNum(count);
sl@0
   161
sl@0
   162
            // Does it exist in the config file? If not try e.g 'ColumnReal37'
sl@0
   163
            if(!GetStringFromConfig(acfgblk, stfn, argument))
sl@0
   164
                continue;
sl@0
   165
sl@0
   166
            whatfun = i;
sl@0
   167
            if(whatfun == Ectrl_endblock)
sl@0
   168
                ended = 1;
sl@0
   169
            // The GetString was successful, so we drop out anyway.
sl@0
   170
            break;
sl@0
   171
            }
sl@0
   172
        // If we hit an EndBlock marker or couldn't find any keyword with
sl@0
   173
        // the current counter number then drop out.
sl@0
   174
        if((whatfun == Efn_undefined) || (whatfun == Ectrl_endblock))
sl@0
   175
            break;
sl@0
   176
sl@0
   177
        // If there's a comma in the argument, split it up. We do
sl@0
   178
        // this here (rather than, more logically, in the called methods)
sl@0
   179
        // because we'd end up repeating the 'CommaSeparated' call in
sl@0
   180
        // all of the wrapper methods. Also, we need the indices for
sl@0
   181
        // Column and Parameter index resolution.
sl@0
   182
        TInt arg1, arg2;
sl@0
   183
        TPtrC arg3;
sl@0
   184
        CommaSeparated(argument, arg1, arg2);
sl@0
   185
        CommaSeparated(argument, arg1, arg3);
sl@0
   186
sl@0
   187
        TInt err=0;
sl@0
   188
        switch(whatfun)
sl@0
   189
            {
sl@0
   190
                case Efn_nop: break;
sl@0
   191
            // First the RSqlDatabase methods...
sl@0
   192
                case Efn_create:
sl@0
   193
                        Create(argument, acfgblk, count);
sl@0
   194
                        break;
sl@0
   195
                case Efn_createl:
sl@0
   196
                        CreateL_(argument, acfgblk, count);
sl@0
   197
                        break;
sl@0
   198
                case Efn_createsp:
sl@0
   199
                        CreateSP(argument, acfgblk, count);
sl@0
   200
                        break;
sl@0
   201
                case Efn_open:
sl@0
   202
                        Open(argument, acfgblk, count);
sl@0
   203
                        break;
sl@0
   204
                case Efn_openl:
sl@0
   205
                        OpenL_(argument, acfgblk, count);
sl@0
   206
                        break;
sl@0
   207
                case Efn_attach:
sl@0
   208
                        Attach(argument, acfgblk, count);
sl@0
   209
                        break;
sl@0
   210
                case Efn_detach:
sl@0
   211
                        Detach(argument, acfgblk, count);
sl@0
   212
                        break;
sl@0
   213
                case Efn_copy:
sl@0
   214
                        Copy(argument, acfgblk, count);
sl@0
   215
                        break;
sl@0
   216
                case Efn_close:
sl@0
   217
                        Close();
sl@0
   218
                        break;
sl@0
   219
                case Efn_delete:
sl@0
   220
                        Delete(argument, acfgblk, count);
sl@0
   221
                        break;
sl@0
   222
                case Efn_lasterrormessage:
sl@0
   223
                        LastErrorMessage(argument);
sl@0
   224
                        break;
sl@0
   225
                case Efn_exec:
sl@0
   226
                        Exec(argument, acfgblk, count);
sl@0
   227
                        break;
sl@0
   228
                case Efn_setisolationlevel:
sl@0
   229
                        SetIsolationLevel(argument, acfgblk, count);
sl@0
   230
                        break;
sl@0
   231
                case Efn_reservedrivespace:
sl@0
   232
                        ReserveDriveSpace(arg1, acfgblk, count);
sl@0
   233
                        break;
sl@0
   234
                case Efn_freereservedspace:
sl@0
   235
                        FreeReservedSpace();
sl@0
   236
                        break;
sl@0
   237
                case Efn_getreserveaccess:
sl@0
   238
                        GetReserveAccess(acfgblk, count);
sl@0
   239
                        break;
sl@0
   240
                case Efn_releasereserveaccess:
sl@0
   241
                        ReleaseReserveAccess();
sl@0
   242
                        break;
sl@0
   243
sl@0
   244
            // Now the RSqlStatement methods...
sl@0
   245
                case Erstmt_prepare:
sl@0
   246
                        Prepare(argument, acfgblk, count);
sl@0
   247
                        break;
sl@0
   248
                case Erstmt_preparel:
sl@0
   249
                        PrepareL_(argument, acfgblk, count);
sl@0
   250
                        break;
sl@0
   251
                case Erstmt_close:
sl@0
   252
                        Close(1);
sl@0
   253
                        break;
sl@0
   254
                case Erstmt_atrow:
sl@0
   255
                        AtRow(argument);
sl@0
   256
                        break;
sl@0
   257
                case Erstmt_reset:
sl@0
   258
                        err = isqlst.Reset();
sl@0
   259
                        ReportOnError(KTestFunction, _L("Reset"), acfgblk,
sl@0
   260
                                                                 count, err);
sl@0
   261
                        break;
sl@0
   262
                case Erstmt_exec:
sl@0
   263
                        {
sl@0
   264
                            TBuf<KConfigItemMaxNameLength> apiname(_L("st_exec"));
sl@0
   265
                            if(!iasync)
sl@0
   266
                                err = isqlst.Exec();
sl@0
   267
                            else
sl@0
   268
                                {
sl@0
   269
                                TChar ch = 'A';
sl@0
   270
                                apiname.Append(ch);
sl@0
   271
                                TRequestStatus trs;
sl@0
   272
                                isqlst.Exec(trs);
sl@0
   273
                                User::WaitForRequest(trs);
sl@0
   274
                                err = trs.Int();
sl@0
   275
                                }
sl@0
   276
                            ReportOnError(KTestFunction, apiname,
sl@0
   277
                                                        acfgblk, count, err);
sl@0
   278
                        }
sl@0
   279
                        break;
sl@0
   280
                case Erstmt_next:
sl@0
   281
                        Next(argument, acfgblk, count);
sl@0
   282
                        break;
sl@0
   283
                case Erstmt_paramindex:
sl@0
   284
                            {
sl@0
   285
                            TInt pidx = ParamIndex(argument, acfgblk, count);
sl@0
   286
                            // The test designer will have to remember how many
sl@0
   287
                            // param indices have been stuck in this array..
sl@0
   288
                            if(pidx >= 0)ipidxs.Append(pidx);
sl@0
   289
                            }
sl@0
   290
                        break;
sl@0
   291
                case Erstmt_colindex:
sl@0
   292
                            {
sl@0
   293
                            TInt cidx = ColumnIndex(argument, acfgblk, count);
sl@0
   294
                            // The test designer will have to remember how many
sl@0
   295
                            // column indices have been stuck in this array..
sl@0
   296
                            if(cidx >= 0)icidxs.Append(cidx);
sl@0
   297
                            }
sl@0
   298
                        break;
sl@0
   299
                case Erstmt_coltype:
sl@0
   300
                        // ColumnType needs the ColumnIndex (the last arg)
sl@0
   301
                        // and also the expected result, which it will get from
sl@0
   302
                        // the config file. We have to deal with the ColumnIndex
sl@0
   303
                        // here because it lives in our scope, not that of the
sl@0
   304
                        // method we're calling..
sl@0
   305
                        // The test designer will have to remember how many
sl@0
   306
                        // column indices have been stuck in this array..
sl@0
   307
                        ColumnType(icidxs[arg1], arg3);
sl@0
   308
                        break;
sl@0
   309
                case Erstmt_colsize:
sl@0
   310
                        ColumnSize(icidxs[arg1], arg2);
sl@0
   311
                        break;
sl@0
   312
                case Erstmt_bindnull:
sl@0
   313
                        BindNull(ipidxs[arg1], acfgblk, count);
sl@0
   314
                        break;
sl@0
   315
                case Erstmt_bindint:
sl@0
   316
                        BindInt(ipidxs[arg1], arg2, acfgblk, count);
sl@0
   317
                        break;
sl@0
   318
                case Erstmt_bindint64:
sl@0
   319
                        BindInt64(ipidxs[arg1], arg3, acfgblk, count);
sl@0
   320
                        break;
sl@0
   321
                case Erstmt_bindreal:
sl@0
   322
                        {
sl@0
   323
                        TLex tl = arg3;
sl@0
   324
                        TReal tr;
sl@0
   325
                        tl.Val(tr);
sl@0
   326
                        BindReal(ipidxs[arg1], tr, acfgblk, count);
sl@0
   327
                        }
sl@0
   328
                        break;
sl@0
   329
                case Erstmt_bindtext:
sl@0
   330
                        BindText(ipidxs[arg1], arg3, acfgblk, count);
sl@0
   331
                        break;
sl@0
   332
                case Erstmt_bindbigtext:
sl@0
   333
                        // Not an RSqlStatement method, but calls BindText
sl@0
   334
                        // after reading from a file.
sl@0
   335
                        BindBigTextL(ipidxs[arg1], arg3, acfgblk, count);
sl@0
   336
                        break;
sl@0
   337
                case Erstmt_bindbinary:
sl@0
   338
                        BindBinaryL(ipidxs[arg1], arg3, acfgblk, count);
sl@0
   339
                        break;
sl@0
   340
                case Erstmt_isnull:
sl@0
   341
                        IsNull(icidxs[arg1], arg3);
sl@0
   342
                        break;
sl@0
   343
                case Erstmt_colint:
sl@0
   344
                        ColumnInt(icidxs[arg1], arg2);
sl@0
   345
                        break;
sl@0
   346
                case Erstmt_colint64:
sl@0
   347
                        ColumnInt64(icidxs[arg1], arg3);
sl@0
   348
                        break;
sl@0
   349
                case Erstmt_colreal:
sl@0
   350
                        {
sl@0
   351
                        TLex tl = arg3;
sl@0
   352
                        TReal tr2;
sl@0
   353
                        tl.Val(tr2);
sl@0
   354
                        ColumnReal(icidxs[arg1], tr2);
sl@0
   355
                        }
sl@0
   356
                        break;
sl@0
   357
                case Erstmt_coltextL:
sl@0
   358
                        ColumnTextL(icidxs[arg1], arg3, acfgblk, count);
sl@0
   359
                        break;
sl@0
   360
                case Erstmt_coltextP:
sl@0
   361
                        ColumnTextPL(icidxs[arg1], arg3, acfgblk, count);
sl@0
   362
                        break;
sl@0
   363
                case Erstmt_coltextD:
sl@0
   364
                        ColumnTextDL(icidxs[arg1], arg3, acfgblk, count);
sl@0
   365
                        break;
sl@0
   366
                case Erstmt_colbinL:
sl@0
   367
                        ColumnBinaryL(icidxs[arg1], arg3, acfgblk, count);
sl@0
   368
                        break;
sl@0
   369
                case Erstmt_colbinP:
sl@0
   370
                        ColumnBinaryPL(icidxs[arg1], arg3, acfgblk, count);
sl@0
   371
                        break;
sl@0
   372
                case Erstmt_colbinD:
sl@0
   373
                        ColumnBinaryDL(icidxs[arg1], arg3, acfgblk, count);
sl@0
   374
                        break;
sl@0
   375
sl@0
   376
                case Esp_create:
sl@0
   377
                        SPCreate(acfgblk, count);
sl@0
   378
                        break;
sl@0
   379
                case Esp_createl:
sl@0
   380
                        SPCreate(argument, acfgblk, count);
sl@0
   381
                        break;
sl@0
   382
                case Esp_close:
sl@0
   383
                        SPClose();
sl@0
   384
                        break;
sl@0
   385
                case Esp_setdbpolicy:
sl@0
   386
                        SPSetDBPolicy(argument, acfgblk, count);
sl@0
   387
                        break;
sl@0
   388
                case Esp_setpolicy:
sl@0
   389
                        SPSetPolicy(argument, acfgblk, count);
sl@0
   390
                        break;
sl@0
   391
                case Esp_externalizel:
sl@0
   392
                        SPExternalize(argument, acfgblk, count);
sl@0
   393
                        break;
sl@0
   394
                case Esp_internalizel:
sl@0
   395
                        SPInternalize(argument, acfgblk, count);
sl@0
   396
                        break;
sl@0
   397
sl@0
   398
                case Estreamwrite_bindtext:
sl@0
   399
                        SWBindTextL(ipidxs[arg1], arg3, acfgblk, count);
sl@0
   400
                        break;
sl@0
   401
                case Estreamwrite_bindbinary:
sl@0
   402
                        SWBindBinaryL(ipidxs[arg1], arg3, acfgblk, count);
sl@0
   403
                        break;
sl@0
   404
                case Estreamread_columntext:
sl@0
   405
                        SRColumnTextL(icidxs[arg1], arg3, acfgblk, count);
sl@0
   406
                        break;
sl@0
   407
                case Estreamread_columnbinary:
sl@0
   408
                        SRColumnBinaryL(icidxs[arg1], arg3, acfgblk, count);
sl@0
   409
                        break;
sl@0
   410
                case Edefineconfig:
sl@0
   411
                        {
sl@0
   412
                        if(icfg)
sl@0
   413
                            delete icfg;
sl@0
   414
                        TInt len = argument.Length();
sl@0
   415
                        if(len)
sl@0
   416
                            {
sl@0
   417
                            // At the time of writing, configuration strings
sl@0
   418
                            // are limited to 255 bytes.
sl@0
   419
                            TBuf8<256> arg;
sl@0
   420
                            arg.Copy(argument);
sl@0
   421
                            icfg = new TPtrC8(arg);
sl@0
   422
                            }
sl@0
   423
                        else
sl@0
   424
                            icfg = NULL;
sl@0
   425
                        }
sl@0
   426
                        break;
sl@0
   427
sl@0
   428
            // Actions that aren't direct method calls..
sl@0
   429
                case Ectrl_newblock:
sl@0
   430
                        // Continue executing from another configuration
sl@0
   431
                        // block. Obviously this restarts the step
sl@0
   432
                        // counter at zero. It's unfortunate that we can't
sl@0
   433
                        // create a new test object here, that would be
sl@0
   434
                        // so much neater. But logging doesn't work in
sl@0
   435
                        // sub-objects (it could be bodged around but it
sl@0
   436
                        // really would be a bodge). A shame, we could have
sl@0
   437
                        // lots of member vars holding all this junk we're
sl@0
   438
                        // passing around. Note that because we don't create
sl@0
   439
                        // a new object we are playing with the same
sl@0
   440
                        // RSqlDatabase and RSqlStatement objects.
sl@0
   441
                        SQLDbStepL(argument);
sl@0
   442
                        break;
sl@0
   443
                case Ectrl_function:
sl@0
   444
                        // Pure virtual. Lives elsewhere..
sl@0
   445
                        ResolveTestFunctionL(acfgblk, count, argument);
sl@0
   446
                        break;
sl@0
   447
sl@0
   448
                case Ectrl_waitA:
sl@0
   449
                        // Wait for the isem member semaphore to receive
sl@0
   450
                        // arg1 signals for this thread. Obviously this assumes
sl@0
   451
                        // there's another thread that's going to execute
sl@0
   452
                        // a 'Signal' at some point.
sl@0
   453
						for(TInt ii=0 ; ii<arg1 ; ++ii)
sl@0
   454
                            {
sl@0
   455
                            WaitA();
sl@0
   456
                            }
sl@0
   457
                        break;
sl@0
   458
                case Ectrl_waitB:
sl@0
   459
                        // Wait for the isemB member semaphore to receive
sl@0
   460
                        // arg1 signals for this thread. Obviously this assumes
sl@0
   461
                        // there's another thread that's going to execute
sl@0
   462
                        // a 'SignalB' at some point.
sl@0
   463
						for(TInt ii=0 ; ii<arg1 ; ++ii)
sl@0
   464
                            {
sl@0
   465
                            WaitB();
sl@0
   466
                            }
sl@0
   467
                        break;
sl@0
   468
                case Ectrl_signalA:
sl@0
   469
                        // E.G Signal37=6 to wake up six threads that are
sl@0
   470
                        // waiting on isem.
sl@0
   471
                        SignalA(arg1);
sl@0
   472
                        break;
sl@0
   473
                case Ectrl_signalB:
sl@0
   474
                        // E.G SignalB37=6 to wake up six threads that are
sl@0
   475
                        // waiting on isemB..
sl@0
   476
                        SignalB(arg1);
sl@0
   477
                        break;
sl@0
   478
                case Ectrl_sleep:
sl@0
   479
                        INFO_PRINTF2(_L("Sleeping for %d microseconds"), arg1);
sl@0
   480
                        User::After(arg1);
sl@0
   481
                        break;
sl@0
   482
                case Ectrl_eightbit:
sl@0
   483
                        if((argument == _L("On")) || (argument == _L("True")))
sl@0
   484
                            i8bit = ETrue;
sl@0
   485
                        else
sl@0
   486
                            i8bit = EFalse;
sl@0
   487
                        break;
sl@0
   488
                case Ectrl_async:
sl@0
   489
                        if((argument == _L("On")) || (argument == _L("True")))
sl@0
   490
                            iasync = ETrue;
sl@0
   491
                        else
sl@0
   492
                            iasync = EFalse;
sl@0
   493
                        break;
sl@0
   494
sl@0
   495
            // Big problems if this stuff executes.
sl@0
   496
                case Efn_undefined:
sl@0
   497
                        SetTestStepResult(EFail);
sl@0
   498
                        INFO_PRINTF1(HTML_RED);
sl@0
   499
                        ERR_PRINTF1(_L("This should never happen. A"));
sl@0
   500
                        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   501
                        break;
sl@0
   502
                default:
sl@0
   503
                        SetTestStepResult(EFail);
sl@0
   504
                        INFO_PRINTF1(HTML_RED);
sl@0
   505
                        ERR_PRINTF1(_L("This should never happen. B"));
sl@0
   506
                        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   507
                        break;
sl@0
   508
            }
sl@0
   509
        // Let's get rid of any colour. Can get tangled in multi-threaded
sl@0
   510
        // tests.
sl@0
   511
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   512
        }
sl@0
   513
    // If we get to this point and the 'ended' flag hasn't been set then
sl@0
   514
    // we haven't seen an 'EndBlockNN=' line in the config file. That
sl@0
   515
    // usually means the test has a missing <keyword><number> item
sl@0
   516
    // which is a test  failure.
sl@0
   517
    if(!ended)
sl@0
   518
        {
sl@0
   519
        SetTestStepResult(EFail);
sl@0
   520
        INFO_PRINTF1(HTML_RED);
sl@0
   521
        ERR_PRINTF2(_L("Put an 'EndBlock' marker at the end of all config blocks. This is intended to\nspot missing numbers (which cause the test to drop out) failing to generate a failure (%S)"), &acfgblk);
sl@0
   522
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   523
        }
sl@0
   524
    }
sl@0
   525
sl@0
   526
// ----------Methods to exercise RSqlDatabase methods ------------------------
sl@0
   527
sl@0
   528
TBool CSQLFnStep::Create(const TPtrC& adbnm,
sl@0
   529
                         const TDesC &acfgblk, TInt acnnum)
sl@0
   530
    {
sl@0
   531
    _LIT(KTestFunction, "Create");
sl@0
   532
    INFO_PRINTF3(_L("%S: Database name is %S "), &KTestFunction, &adbnm);
sl@0
   533
sl@0
   534
    // Try to create the database.
sl@0
   535
    TInt rc = isqldb.Create(adbnm, icfg);
sl@0
   536
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   537
    if(rc == KErrNone) return ETrue;
sl@0
   538
    return EFalse;
sl@0
   539
    }
sl@0
   540
TBool CSQLFnStep::CreateL_(const TPtrC& adbnm,
sl@0
   541
                           const TDesC &acfgblk, TInt acnnum)
sl@0
   542
    {
sl@0
   543
    _LIT(KTestFunction, "CreateL");
sl@0
   544
    INFO_PRINTF3(_L("%S: Database name is %S "), &KTestFunction, &adbnm);
sl@0
   545
sl@0
   546
    // Try to create the database. Trap any leave (we're actually duplicating
sl@0
   547
    // what is in the non-leaving Create method, but hey, this is black box
sl@0
   548
    // testing, we're not supposed to know that..)
sl@0
   549
    TInt rc=KErrNone;
sl@0
   550
    TRAP(rc, isqldb.CreateL(adbnm, icfg));
sl@0
   551
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   552
    if(rc == KErrNone) return ETrue;
sl@0
   553
    return EFalse;
sl@0
   554
    }
sl@0
   555
sl@0
   556
TBool CSQLFnStep::CreateSP(const TPtrC& adbnm, const TDesC &acfgblk, TInt acnnum)
sl@0
   557
    {
sl@0
   558
    _LIT(KTestFunction, "CreateSP");
sl@0
   559
    INFO_PRINTF3(_L("%S: Database name is %S "), &KTestFunction, &adbnm);
sl@0
   560
sl@0
   561
    TInt rc = isqldb.Create(adbnm, isqlsp, icfg);
sl@0
   562
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   563
    if(rc == KErrNone) return ETrue;
sl@0
   564
    return EFalse;
sl@0
   565
    }
sl@0
   566
    
sl@0
   567
TBool CSQLFnStep::Open(const TPtrC& adbnm,
sl@0
   568
                       const TDesC &acfgblk, TInt acnnum)
sl@0
   569
    {
sl@0
   570
    _LIT(KTestFunction, "Open");
sl@0
   571
    INFO_PRINTF3(_L("%S: Database name is %S "), &KTestFunction, &adbnm);
sl@0
   572
sl@0
   573
    // Try to open the database.
sl@0
   574
    TInt rc = isqldb.Open(adbnm, icfg);
sl@0
   575
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   576
    if(rc == KErrNone) return ETrue;
sl@0
   577
    return EFalse;
sl@0
   578
    }
sl@0
   579
TBool CSQLFnStep::OpenL_(const TPtrC& adbnm,
sl@0
   580
                         const TDesC &acfgblk, TInt acnnum)
sl@0
   581
    {
sl@0
   582
    _LIT(KTestFunction, "OpenL");
sl@0
   583
    INFO_PRINTF3(_L("%S: Database name is %S "), &KTestFunction, &adbnm);
sl@0
   584
sl@0
   585
    // Try to open the database.
sl@0
   586
    TInt rc = KErrNone;
sl@0
   587
    TRAP(rc, isqldb.OpenL(adbnm, icfg));
sl@0
   588
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   589
    if(rc == KErrNone) return ETrue;
sl@0
   590
    return EFalse;
sl@0
   591
    }
sl@0
   592
// Close the current database.
sl@0
   593
void CSQLFnStep::Close()
sl@0
   594
    {
sl@0
   595
//  _LIT(KTestFunction, "Close");
sl@0
   596
    isqldb.Close();
sl@0
   597
    return;
sl@0
   598
    }
sl@0
   599
void CSQLFnStep::Attach(const TPtrC &arg,
sl@0
   600
                        const TDesC &acfgblk, TInt acnnum)
sl@0
   601
    {
sl@0
   602
    _LIT(KTestFunction, "Attach");
sl@0
   603
    TPtrC sqldb, sqldbname;
sl@0
   604
    // Break arg into 'sqldb', the path/filename of the database to attach
sl@0
   605
    // and sqldbname, the name by which the database will be referred to
sl@0
   606
    // through this Attach.
sl@0
   607
    CommaSeparated(arg, sqldb, sqldbname);
sl@0
   608
    TInt rc = isqldb.Attach(sqldb, sqldbname);
sl@0
   609
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   610
    return;
sl@0
   611
    }
sl@0
   612
void CSQLFnStep::Detach(const TPtrC &arg,
sl@0
   613
                        const TDesC &acfgblk, TInt acnnum)
sl@0
   614
    {
sl@0
   615
    _LIT(KTestFunction, "Detach");
sl@0
   616
    TInt rc = isqldb.Detach(arg);
sl@0
   617
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   618
    return;
sl@0
   619
    }
sl@0
   620
void CSQLFnStep::Copy(const TPtrC &arg,
sl@0
   621
                      const TDesC &acfgblk, TInt acnnum)
sl@0
   622
    {
sl@0
   623
    _LIT(KTestFunction, "Copy");
sl@0
   624
    TPtrC sqldb1, sqldb2;
sl@0
   625
    CommaSeparated(arg, sqldb1, sqldb2);
sl@0
   626
    TInt rc = isqldb.Copy(sqldb1, sqldb2);
sl@0
   627
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   628
    return;
sl@0
   629
    }
sl@0
   630
TBool CSQLFnStep::Delete(const TPtrC& adbnm,
sl@0
   631
                         const TDesC &acfgblk, TInt acnnum)
sl@0
   632
    {
sl@0
   633
    _LIT(KTestFunction, "Delete");
sl@0
   634
    INFO_PRINTF3(_L("%S: Database name is %S "), &KTestFunction, &adbnm);
sl@0
   635
sl@0
   636
    // Try to delete the database.
sl@0
   637
    TInt rc = isqldb.Delete(adbnm);
sl@0
   638
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   639
    if(rc == KErrNone) return ETrue;
sl@0
   640
    return EFalse;
sl@0
   641
    }
sl@0
   642
void CSQLFnStep::LastErrorMessage(const TPtrC& arg)
sl@0
   643
                
sl@0
   644
    {
sl@0
   645
    _LIT(KTestFunction, "LastErrorMessage");
sl@0
   646
sl@0
   647
    TPtrC lem = isqldb.LastErrorMessage();
sl@0
   648
    if(arg.Length() == 0)
sl@0
   649
        {
sl@0
   650
        INFO_PRINTF3(_L("%S: '%S'"), &KTestFunction, &lem);
sl@0
   651
        return; // No particular error message was expected, so just return.
sl@0
   652
        }
sl@0
   653
    if(lem != arg)
sl@0
   654
        {
sl@0
   655
        SetTestStepResult(EFail);
sl@0
   656
        INFO_PRINTF1(HTML_RED);
sl@0
   657
        ERR_PRINTF4(_L("%S: Expected Message '%S', got '%S'"), &KTestFunction,
sl@0
   658
                                                                   &arg, &lem);
sl@0
   659
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   660
        }
sl@0
   661
    else
sl@0
   662
        {
sl@0
   663
        INFO_PRINTF1(HTML_GREEN);
sl@0
   664
        INFO_PRINTF3(_L("%S: Got expected Message '%S'"), &KTestFunction, &arg);
sl@0
   665
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   666
        }
sl@0
   667
    return;
sl@0
   668
    }
sl@0
   669
void CSQLFnStep::Exec(const TPtrC& arg,
sl@0
   670
                      const TDesC &acfgblk, TInt acnnum)
sl@0
   671
    {
sl@0
   672
    _LIT(KTestFunction, "Exec");
sl@0
   673
    TBuf<KConfigItemMaxNameLength> apiname(KTestFunction);
sl@0
   674
    TInt rc;
sl@0
   675
    if(i8bit == EFalse)
sl@0
   676
        {
sl@0
   677
        if(!iasync)
sl@0
   678
            rc = isqldb.Exec(arg);
sl@0
   679
        else
sl@0
   680
            {
sl@0
   681
            TChar ch = 'A';
sl@0
   682
            apiname.Append(ch);
sl@0
   683
            TRequestStatus trs;
sl@0
   684
            isqldb.Exec(arg, trs);
sl@0
   685
            User::WaitForRequest(trs);
sl@0
   686
            rc = trs.Int();
sl@0
   687
            }
sl@0
   688
        }
sl@0
   689
    else
sl@0
   690
        {
sl@0
   691
        apiname.AppendNum(8);
sl@0
   692
        RBuf8 b8;
sl@0
   693
        b8.Create(arg.Length());
sl@0
   694
        b8.Copy(arg);
sl@0
   695
        if(!iasync)
sl@0
   696
            rc = isqldb.Exec(b8);
sl@0
   697
        else
sl@0
   698
            {
sl@0
   699
            TChar ch = 'A';
sl@0
   700
            apiname.Append(ch);
sl@0
   701
            TRequestStatus trs;
sl@0
   702
            isqldb.Exec(b8, trs);
sl@0
   703
            User::WaitForRequest(trs);
sl@0
   704
            rc = trs.Int();
sl@0
   705
            }
sl@0
   706
        b8.Close();
sl@0
   707
        }
sl@0
   708
    ReportOnError(KTestFunction, apiname, acfgblk, acnnum, rc);
sl@0
   709
    return;
sl@0
   710
    }
sl@0
   711
void CSQLFnStep::SetIsolationLevel(const TPtrC& arg,
sl@0
   712
                                   const TDesC &acfgblk, TInt acnnum)
sl@0
   713
    {
sl@0
   714
    _LIT(KTestFunction, "SetIsolationLevel");
sl@0
   715
    // Get the expected error code..
sl@0
   716
    TPtrC experrS;
sl@0
   717
    TInt experr = ActionNoToErrEnum(acfgblk, acnnum, experrS);
sl@0
   718
sl@0
   719
    INFO_PRINTF2(_L("SetIsolationLevel: %S"), &arg);
sl@0
   720
    RSqlDatabase::TIsolationLevel sil;
sl@0
   721
    if(arg == _L("EReadUncommitted"))
sl@0
   722
        sil = RSqlDatabase::EReadUncommitted;
sl@0
   723
    else if(arg == _L("EReadCommitted"))
sl@0
   724
        sil = RSqlDatabase::EReadCommitted;
sl@0
   725
    else if(arg == _L("ERepeatableRead"))
sl@0
   726
        sil = RSqlDatabase::ERepeatableRead;
sl@0
   727
    else if(arg == _L("ESerializable"))
sl@0
   728
        sil = RSqlDatabase::ESerializable;
sl@0
   729
    else
sl@0
   730
        {
sl@0
   731
        SetTestStepResult(EFail);
sl@0
   732
        INFO_PRINTF1(HTML_RED);
sl@0
   733
        ERR_PRINTF3(_L("%S: Unrecognized TIsolationLevel '%S'"), 
sl@0
   734
                                                    &KTestFunction, &arg);
sl@0
   735
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   736
        return;
sl@0
   737
        }
sl@0
   738
sl@0
   739
    TInt rc = isqldb.SetIsolationLevel(sil);
sl@0
   740
    TPtrC err;
sl@0
   741
    ErrEnumToString(rc,err);
sl@0
   742
    if(rc != experr)
sl@0
   743
        {
sl@0
   744
        SetTestStepResult(EFail);
sl@0
   745
        INFO_PRINTF1(HTML_RED);
sl@0
   746
        ERR_PRINTF3(_L("Unexpected SetIsolationLevel error %d/%S"), rc, &err);
sl@0
   747
        TPtrC lem = isqldb.LastErrorMessage();
sl@0
   748
        ERR_PRINTF2(_L(" - Last Error Message: %S"), &lem);
sl@0
   749
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   750
        return;
sl@0
   751
        }
sl@0
   752
    else
sl@0
   753
        INFO_PRINTF2(_L("SetIsolation level, got error %S as expected"), &err);
sl@0
   754
    return;
sl@0
   755
    }
sl@0
   756
sl@0
   757
void CSQLFnStep::ReserveDriveSpace(TInt ares,
sl@0
   758
                                   const TDesC& acfgblk, const TInt acnnum)
sl@0
   759
    {
sl@0
   760
    _LIT(KTestFunction, "ReserveDriveSpace");
sl@0
   761
sl@0
   762
    // Try to reserve space..
sl@0
   763
    TInt rc = isqldb.ReserveDriveSpace(ares);
sl@0
   764
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   765
    return;
sl@0
   766
    }
sl@0
   767
void CSQLFnStep::FreeReservedSpace()
sl@0
   768
    {
sl@0
   769
//    _LIT(KTestFunction, "FreeReservedSpace");
sl@0
   770
    isqldb.FreeReservedSpace();
sl@0
   771
    return;
sl@0
   772
    }
sl@0
   773
void CSQLFnStep::GetReserveAccess(const TDesC& acfgblk,
sl@0
   774
                                  const TInt acnnum)
sl@0
   775
    {
sl@0
   776
    _LIT(KTestFunction, "GetReserveAccess");
sl@0
   777
sl@0
   778
    // Try to reserve space..
sl@0
   779
    TInt rc = isqldb.GetReserveAccess();
sl@0
   780
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   781
    return;
sl@0
   782
    }
sl@0
   783
void CSQLFnStep::ReleaseReserveAccess()
sl@0
   784
    {
sl@0
   785
//    _LIT(KTestFunction, "ReleaseReserveSpace");
sl@0
   786
    isqldb.ReleaseReserveAccess();
sl@0
   787
    return;
sl@0
   788
    }
sl@0
   789
sl@0
   790
// ----------Methods to exercise RSqlStatement methods ------------------------
sl@0
   791
//
sl@0
   792
// Execute a Close on the current RSqlStatement. This also clears out the
sl@0
   793
// arrays of RBufs and RBuf8s which are used for BindText and
sl@0
   794
// BindBinary (just a way of keeping the buffers in scope until the 
sl@0
   795
// Exec/Close happens) and loses all of the ParameterIndex and ColumnIndex's.
sl@0
   796
// The 'TInt' argument is just to differentiate between the RSqlDatabase
sl@0
   797
// Close wrapper, and this RSqlStatement Close wrapper.
sl@0
   798
void CSQLFnStep::Close(TInt)
sl@0
   799
    {
sl@0
   800
//    _LIT(KTestFunction, "St_Close");
sl@0
   801
sl@0
   802
    // Close the RSqlStatement.
sl@0
   803
    isqlst.Close();
sl@0
   804
sl@0
   805
    // Empty the arrays where we keep references to BindXXX buffers,
sl@0
   806
    // closing those buffers as we go.
sl@0
   807
    for(TInt count = iBindRBufarr.Count() - 1 ; count >= 0; count--)
sl@0
   808
        {
sl@0
   809
        iBindRBufarr[count].Close();
sl@0
   810
        iBindRBufarr.Remove(count);
sl@0
   811
        }
sl@0
   812
    for(TInt count = iBindRBuf8arr.Count() - 1 ; count >= 0 ; count--)
sl@0
   813
        {
sl@0
   814
        iBindRBuf8arr[count].Close();
sl@0
   815
        iBindRBuf8arr.Remove(count);
sl@0
   816
        }
sl@0
   817
    if((iBindRBuf8arr.Count() != 0) || (iBindRBufarr.Count() != 0))
sl@0
   818
        {
sl@0
   819
        User::Panic(_L("RBuf arrays not empty"), 512);
sl@0
   820
        }
sl@0
   821
sl@0
   822
    // Empty the ParameterIndex and ColumnIndex arrays.
sl@0
   823
    while(ipidxs.Count()) ipidxs.Remove(0);
sl@0
   824
    while(icidxs.Count()) icidxs.Remove(0);
sl@0
   825
sl@0
   826
    return;
sl@0
   827
    }
sl@0
   828
void CSQLFnStep::Next(TPtrC& arg,
sl@0
   829
                      const TDesC &acfgblk, TInt acnnum=-1)
sl@0
   830
    {
sl@0
   831
    _LIT(KTestFunction, "Next");
sl@0
   832
    TInt rc = isqlst.Next();
sl@0
   833
sl@0
   834
    // If arg is not zero length it will be KSqlAtEnd/KSqlAtRow, turn that
sl@0
   835
    // into the enumeration.
sl@0
   836
    if(arg.Length())
sl@0
   837
        {
sl@0
   838
        TInt expn = ErrStringToEnum(arg);
sl@0
   839
        TPtrC errS;
sl@0
   840
        ErrEnumToString(rc, errS); // Convert the actual rc to a string.
sl@0
   841
        if(expn != rc)
sl@0
   842
            {
sl@0
   843
            SetTestStepResult(EFail);
sl@0
   844
            INFO_PRINTF1(HTML_RED);
sl@0
   845
            ERR_PRINTF7(_L("%S/%S: Got %S/%d, expected %S/%d"), &KTestFunction,
sl@0
   846
                                    &acfgblk, &errS, rc, &arg, expn );
sl@0
   847
            INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   848
            }
sl@0
   849
        }
sl@0
   850
    ReportOnError(KTestFunction, _L("Next"), acfgblk, acnnum, rc);
sl@0
   851
    return;
sl@0
   852
    }
sl@0
   853
sl@0
   854
// Call the RSqlStatement method 'AtRow'. This returns a boolean. This
sl@0
   855
// method expects the config file to contain a line resembling
sl@0
   856
// 'AtRow57=false'. The return value is checked against the config
sl@0
   857
// value and error/info is reported.
sl@0
   858
void CSQLFnStep::AtRow(const TPtrC &arg)
sl@0
   859
sl@0
   860
    {
sl@0
   861
    _LIT(KTestFunction, "AtRow");
sl@0
   862
    TBuf<8> atrres(arg);
sl@0
   863
    atrres.LowerCase();
sl@0
   864
    TBool expected = EFalse;
sl@0
   865
    if(atrres == _L("false"))
sl@0
   866
        expected = EFalse;
sl@0
   867
    else if(atrres == _L("true"))
sl@0
   868
        expected = ETrue;
sl@0
   869
    else
sl@0
   870
        {
sl@0
   871
        SetTestStepResult(EFail);
sl@0
   872
        INFO_PRINTF1(HTML_RED);
sl@0
   873
        ERR_PRINTF3(_L("%S: expected config item to be true/false, got %S"),
sl@0
   874
                      &KTestFunction, &arg);
sl@0
   875
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   876
        }
sl@0
   877
    TBool atr = isqlst.AtRow();
sl@0
   878
    if(atr != expected)
sl@0
   879
        {
sl@0
   880
        SetTestStepResult(EFail);
sl@0
   881
        INFO_PRINTF1(HTML_RED);
sl@0
   882
        ERR_PRINTF4(_L("%S: expected AtRow to return %S, got %d"),
sl@0
   883
                           &KTestFunction, &atrres, atr);
sl@0
   884
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   885
        return;
sl@0
   886
        }
sl@0
   887
    else
sl@0
   888
        {
sl@0
   889
        INFO_PRINTF1(HTML_GREEN);
sl@0
   890
        INFO_PRINTF3(_L("%S: Got expected result, %S"), &KTestFunction, &atrres);
sl@0
   891
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
   892
        }
sl@0
   893
    return;
sl@0
   894
    }
sl@0
   895
// Call the RSqlStatement method 'Prepare'. This returns an int. This
sl@0
   896
// method expects the config file to contain a line resembling
sl@0
   897
// 'Prepare43=Create Table tbl3(f1 etc)'. The return value is checked
sl@0
   898
// against the expected error (in ReportOnError).
sl@0
   899
void CSQLFnStep::Prepare(const TPtrC &arg,
sl@0
   900
                         const TDesC &acfgblk, TInt acnnum=-1)
sl@0
   901
    {
sl@0
   902
    _LIT(KTestFunction, "Prepare");
sl@0
   903
    INFO_PRINTF3(_L("%S: Prepare command is %S"), &KTestFunction, &arg);
sl@0
   904
sl@0
   905
    TInt rc;
sl@0
   906
    if(i8bit == EFalse)
sl@0
   907
        rc = isqlst.Prepare(isqldb, arg);
sl@0
   908
    else
sl@0
   909
        {
sl@0
   910
        RBuf8 b8;
sl@0
   911
        b8.Create(arg.Length());
sl@0
   912
        b8.Copy(arg);
sl@0
   913
        rc = isqlst.Prepare(isqldb, b8);
sl@0
   914
        b8.Close();
sl@0
   915
        }
sl@0
   916
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   917
    }
sl@0
   918
void CSQLFnStep::PrepareL_(const TPtrC &arg,
sl@0
   919
                           const TDesC &acfgblk, TInt acnnum=-1)
sl@0
   920
    {
sl@0
   921
    _LIT(KTestFunction, "PrepareL");
sl@0
   922
    INFO_PRINTF3(_L("%S: PrepareL command is %S"), &KTestFunction, &arg);
sl@0
   923
sl@0
   924
    TInt rc=KErrNone;
sl@0
   925
    if(i8bit == EFalse)
sl@0
   926
        {
sl@0
   927
        TRAP(rc, isqlst.PrepareL(isqldb, arg));
sl@0
   928
        }
sl@0
   929
    else
sl@0
   930
        {
sl@0
   931
        RBuf8 b8;
sl@0
   932
        b8.Create(arg.Length());
sl@0
   933
        b8.Copy(arg);
sl@0
   934
        TRAP(rc, isqlst.PrepareL(isqldb, b8));
sl@0
   935
        b8.Close();
sl@0
   936
        }
sl@0
   937
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
   938
    }
sl@0
   939
// Call the RSqlStatement method 'ParamIndex'. This returns an int. This
sl@0
   940
// method expects the config file to contain a line resembling
sl@0
   941
// 'ParamIndex12=:Frog'. The return value is returned.
sl@0
   942
TInt CSQLFnStep::ParamIndex(const TDesC &arg,
sl@0
   943
                            const TDesC &acfgblk, TInt acnnum=-1)
sl@0
   944
    {
sl@0
   945
    _LIT(KTestFunction, "ParameterIndex");
sl@0
   946
sl@0
   947
    // If the test specifies ':?' was the parameter index, we'll assume that
sl@0
   948
    // ':?' was given in the SELECT (a nameless parameter), this always gives
sl@0
   949
    // '1' for the paramIndex.
sl@0
   950
    if(arg == _L(":?"))
sl@0
   951
        return 1;
sl@0
   952
sl@0
   953
    // If arg resembles '23,*explicit*', then return the leading integer.
sl@0
   954
    // This is so we can call BindEtc with bad values for PANIC testing
sl@0
   955
    // or otherwise generate a specific parameter index.
sl@0
   956
    TInt pidx=0;
sl@0
   957
    TPtrC rhs;
sl@0
   958
    CommaSeparated(arg, pidx, rhs);
sl@0
   959
    if(rhs == _L("*explicit*"))
sl@0
   960
        {
sl@0
   961
        INFO_PRINTF3(_L("%S: Returning explicit Parameter Index %d"),
sl@0
   962
                                                      &KTestFunction, pidx);
sl@0
   963
        return pidx;
sl@0
   964
        }
sl@0
   965
sl@0
   966
    // Ok, run ParameterIndex.
sl@0
   967
    pidx = isqlst.ParameterIndex(arg);
sl@0
   968
sl@0
   969
    // ParameterIndex returns a non-negative integer on success. If the
sl@0
   970
    // return is negative, we have a problem. We cannot know what the
sl@0
   971
    // return is if the operation has succeeded, so checking the error
sl@0
   972
    // code is limited to required errors, i.e < 0.
sl@0
   973
    // ReportOnError will set test result to failure if the error doesn't
sl@0
   974
    // match our expected error.
sl@0
   975
    if(pidx < 0)
sl@0
   976
        ReportOnError(KTestFunction, _L("ParameterIndex"),
sl@0
   977
                       acfgblk, acnnum, pidx);
sl@0
   978
    return pidx;
sl@0
   979
    }
sl@0
   980
// Call the RSqlStatement method 'ColumnIndex'. This returns an int. This
sl@0
   981
// method expects the config file to contain a line resembling
sl@0
   982
// 'ColumnIndex12=Fld3'. The return value is returned.
sl@0
   983
TInt CSQLFnStep::ColumnIndex(const TPtrC& arg,
sl@0
   984
                             const TDesC &acfgblk, TInt acnnum=-1)
sl@0
   985
    {
sl@0
   986
    _LIT(KTestFunction, "ColumnIndex");
sl@0
   987
sl@0
   988
    // If no column is specified then return zero - this may be necessary
sl@0
   989
    // if the test is for example counting lines in a table ...
sl@0
   990
    // >select count(*) from mytbl;
sl@0
   991
    // In this case obviously there is no namable column, but the Api just
sl@0
   992
    // requires that the index for ColumnInt will be zero.
sl@0
   993
    if(arg.Length() == 0) return 0;
sl@0
   994
sl@0
   995
    // If arg resembles '23,*explicit*', then return the leading integer.
sl@0
   996
    // This is so we can call ColumnEtc with bad values for PANIC testing
sl@0
   997
    // or otherwise generate a specific parameter index.
sl@0
   998
    TInt colIndex=0;
sl@0
   999
    TPtrC rhs;
sl@0
  1000
    CommaSeparated(arg, colIndex, rhs);
sl@0
  1001
    if(rhs == _L("*explicit*"))
sl@0
  1002
        {
sl@0
  1003
        INFO_PRINTF3(_L("%S: Returning explicit Column Index %d"),
sl@0
  1004
                                                      &KTestFunction, colIndex);
sl@0
  1005
        return colIndex;
sl@0
  1006
        }
sl@0
  1007
    colIndex = isqlst.ColumnIndex(arg);
sl@0
  1008
    // ColumnIndex returns a non-negative integer on success. If the
sl@0
  1009
    // return is negative, we have a problem. We cannot know what the
sl@0
  1010
    // return is if the operation has succeeded, so checking the error
sl@0
  1011
    // code is limited to required errors, i.e < 0.
sl@0
  1012
    // ReportOnError will set test result to failure if the error doesn't
sl@0
  1013
    // match our expected error.
sl@0
  1014
    if(colIndex < 0)
sl@0
  1015
        ReportOnError(KTestFunction, _L("ColumnIndex"),
sl@0
  1016
                       acfgblk, acnnum, colIndex);
sl@0
  1017
    return colIndex;
sl@0
  1018
    }
sl@0
  1019
// Call the RSqlStatement method 'ColumnType'.
sl@0
  1020
void CSQLFnStep::ColumnType(const TInt &acidx, const TPtrC &aexp)
sl@0
  1021
sl@0
  1022
    {
sl@0
  1023
    _LIT(KTestFunction, "ColumnType");
sl@0
  1024
    TSqlColumnType gottype = isqlst.ColumnType(acidx);
sl@0
  1025
    TPtrC got(SqlColumnTypeToString(gottype));
sl@0
  1026
sl@0
  1027
    if((aexp.Length() ==0) || (StringToSqlColumnType(aexp)==gottype))
sl@0
  1028
        {
sl@0
  1029
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1030
        INFO_PRINTF3(_L("%S: Got Column type %S"), &KTestFunction, &got); 
sl@0
  1031
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1032
        return;
sl@0
  1033
        }
sl@0
  1034
sl@0
  1035
    // If the expected type hasn't been specified then just display what
sl@0
  1036
    // we've got.
sl@0
  1037
    INFO_PRINTF1(HTML_RED);
sl@0
  1038
    ERR_PRINTF4(_L("%S: Got Column type %S, expected %S"),
sl@0
  1039
                          &KTestFunction, &got, &aexp);
sl@0
  1040
    SetTestStepResult(EFail);
sl@0
  1041
    INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1042
    return;
sl@0
  1043
    }
sl@0
  1044
// Call the RSqlStatement method 'ColumnSize'. Check it against the
sl@0
  1045
// expected size specified in the config file.
sl@0
  1046
void CSQLFnStep::ColumnSize(const TInt& acolidx, const TInt &axexp)
sl@0
  1047
    {
sl@0
  1048
    _LIT(KTestFunction, "ColumnSize");
sl@0
  1049
    TInt csize = isqlst.ColumnSize(acolidx);
sl@0
  1050
sl@0
  1051
    if((axexp != -1) && (axexp != csize))
sl@0
  1052
        {
sl@0
  1053
        INFO_PRINTF1(HTML_RED);
sl@0
  1054
        SetTestStepResult(EFail);
sl@0
  1055
        ERR_PRINTF4(_L("%S: Got Column size %d, expected %d"),
sl@0
  1056
                       &KTestFunction, csize, axexp);
sl@0
  1057
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1058
        return;
sl@0
  1059
        }
sl@0
  1060
    // If colsize is -1 display what we have.
sl@0
  1061
    INFO_PRINTF3(_L("%S: Got Column size %d"), &KTestFunction, csize); 
sl@0
  1062
sl@0
  1063
    return;
sl@0
  1064
    }
sl@0
  1065
// Onto the Bind methods...
sl@0
  1066
void CSQLFnStep::BindNull(const TInt& apidx,
sl@0
  1067
                          const TDesC &acfgblk, const TInt acnnum=-1)
sl@0
  1068
    {
sl@0
  1069
    _LIT(KTestFunction, "BindNull");
sl@0
  1070
     
sl@0
  1071
    TInt err = isqlst.BindNull(apidx);
sl@0
  1072
    ReportOnError(KTestFunction, _L("BindNull"), acfgblk, acnnum, err);
sl@0
  1073
sl@0
  1074
    return;
sl@0
  1075
    }
sl@0
  1076
void CSQLFnStep::BindInt(const TInt& apidx, const TInt& atob,
sl@0
  1077
                         const TDesC &acfgblk, const TInt acnnum=-1)
sl@0
  1078
    {
sl@0
  1079
    _LIT(KTestFunction, "BindInt");
sl@0
  1080
     
sl@0
  1081
    TInt err = isqlst.BindInt(apidx, atob);
sl@0
  1082
    ReportOnError(KTestFunction, _L("BindInt"), acfgblk, acnnum, err);
sl@0
  1083
sl@0
  1084
    return;
sl@0
  1085
    }
sl@0
  1086
void CSQLFnStep::BindInt64(const TInt& apidx, const TPtrC& atob,
sl@0
  1087
                           const TDesC &acfgblk, const TInt acnnum=-1)
sl@0
  1088
    {
sl@0
  1089
    _LIT(KTestFunction, "BindInt64");
sl@0
  1090
    TInt64 bind;
sl@0
  1091
    TLex tl = atob;
sl@0
  1092
    tl.Val(bind);
sl@0
  1093
    TInt err = isqlst.BindInt64(apidx, bind);
sl@0
  1094
    ReportOnError(KTestFunction, _L("BindInt64"), acfgblk, acnnum, err);
sl@0
  1095
sl@0
  1096
    return;
sl@0
  1097
    }
sl@0
  1098
void CSQLFnStep::BindReal(const TInt& apidx, const TReal& areal,
sl@0
  1099
                          const TDesC &acfgblk, const TInt acnnum=-1)
sl@0
  1100
    {
sl@0
  1101
    _LIT(KTestFunction, "BindReal");
sl@0
  1102
    TInt err = isqlst.BindReal(apidx, areal);
sl@0
  1103
    ReportOnError(KTestFunction, _L("BindReal"), acfgblk, acnnum, err);
sl@0
  1104
sl@0
  1105
    return;
sl@0
  1106
    }
sl@0
  1107
// BindText from the config line...
sl@0
  1108
// May be modified to return a ref which we can keep on the
sl@0
  1109
// stack in the main loop. Then, when we hit a 'Next' that can be cleared.
sl@0
  1110
// This is necessary because there are scoping problems with text and
sl@0
  1111
// binarys - the SQL code expects buffers to remain in scope until
sl@0
  1112
// the Exec/Next.
sl@0
  1113
void CSQLFnStep::BindText(const TInt& apidx, const TPtrC& atxt,
sl@0
  1114
                          const TDesC &acfgblk, const TInt acnnum=-1)
sl@0
  1115
    {
sl@0
  1116
    _LIT(KTestFunction, "BindText");
sl@0
  1117
    TInt err = isqlst.BindText(apidx, atxt);
sl@0
  1118
    ReportOnError(KTestFunction, _L("BindText"), acfgblk, acnnum, err);
sl@0
  1119
sl@0
  1120
    return;
sl@0
  1121
    }
sl@0
  1122
// An additional method to let us bind more than one line of text from
sl@0
  1123
// a config file...
sl@0
  1124
// If the Bind is successful the buffer which has been bound is appended
sl@0
  1125
// to the 'iBindRBufarr' array. This is necessary to keep it in scope until
sl@0
  1126
// the 'Next'/'Exec' actions.
sl@0
  1127
void CSQLFnStep::BindBigTextL(const TInt& apidx, const TPtrC& arg,
sl@0
  1128
                              const TDesC &acfgblk, const TInt acnnum=-1)
sl@0
  1129
    {
sl@0
  1130
    _LIT(KTestFunction, "BindBigText");
sl@0
  1131
    RBuf buf;
sl@0
  1132
sl@0
  1133
    TInt fsize = FileSize(arg);
sl@0
  1134
    if(fsize < 0) return;  // This will have reported an error if necessary.
sl@0
  1135
    
sl@0
  1136
#ifdef _UNICODE
sl@0
  1137
    fsize >>= 1;  // We're assuming here that one character is two bytes..
sl@0
  1138
#endif
sl@0
  1139
sl@0
  1140
    // Create a buffer big enough for the text in the file.
sl@0
  1141
    TInt err = buf.Create(fsize);
sl@0
  1142
    if(err != KErrNone)
sl@0
  1143
        {
sl@0
  1144
        SetTestStepResult(EFail);
sl@0
  1145
        INFO_PRINTF1(HTML_RED);
sl@0
  1146
        ERR_PRINTF3(_L("%S: Can't allocate file buffer %S"), &KTestFunction, &arg);
sl@0
  1147
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1148
        return;
sl@0
  1149
        }
sl@0
  1150
    // Don't push buf onto the cleanup stack. We'll keep a reference to it
sl@0
  1151
    // which get removed on RSqlStatement::Reset.
sl@0
  1152
sl@0
  1153
    // Use an RFileReadStream because we need to worry about characters,
sl@0
  1154
    // not just bytes.
sl@0
  1155
    RFileReadStream rflrs;
sl@0
  1156
    if(rflrs.Open(irfs, arg, EFileRead) != KErrNone)
sl@0
  1157
        {
sl@0
  1158
        SetTestStepResult(EFail);
sl@0
  1159
        INFO_PRINTF1(HTML_RED);
sl@0
  1160
        ERR_PRINTF3(_L("%S: Can't open file %S"), &KTestFunction, &arg);
sl@0
  1161
        buf.Close();
sl@0
  1162
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1163
        return;
sl@0
  1164
        }
sl@0
  1165
    CleanupClosePushL(rflrs);
sl@0
  1166
    rflrs.ReadL(buf);
sl@0
  1167
sl@0
  1168
    // Do the bind...
sl@0
  1169
    err = isqlst.BindText(apidx, buf);
sl@0
  1170
    ReportOnError(KTestFunction, _L("BindText"), acfgblk, acnnum, err);
sl@0
  1171
    // Drop out if it failed.
sl@0
  1172
    if(err != KErrNone)
sl@0
  1173
        {
sl@0
  1174
        CleanupStack::PopAndDestroy(1, &rflrs);
sl@0
  1175
        buf.Close();
sl@0
  1176
        return;
sl@0
  1177
        }
sl@0
  1178
    CleanupStack::PopAndDestroy(1, &rflrs);
sl@0
  1179
sl@0
  1180
    // Tack the buffer onto the internal array. This keeps it in 
sl@0
  1181
    // scope until a RSqlStatement::Close is performed when it will get
sl@0
  1182
    // destroyed.
sl@0
  1183
    iBindRBufarr.Append(buf);
sl@0
  1184
sl@0
  1185
    return;
sl@0
  1186
    }
sl@0
  1187
// If the Bind is successful the buffer which has been bound is appended
sl@0
  1188
// to the 'iBindRBuf8arr' array. This is necessary to keep it in scope until
sl@0
  1189
// the 'Next'/'Exec' actions.
sl@0
  1190
void CSQLFnStep::BindBinaryL(const TInt& apidx, const TDesC& arg,
sl@0
  1191
                              const TDesC &acfgblk, const TInt acnnum)
sl@0
  1192
    {
sl@0
  1193
    _LIT(KTestFunction, "BindBinary");
sl@0
  1194
    TInt fsize = FileSize(arg);
sl@0
  1195
    if(fsize < 0)
sl@0
  1196
        {
sl@0
  1197
        SetTestStepResult(EFail);
sl@0
  1198
        INFO_PRINTF1(HTML_RED);
sl@0
  1199
        ERR_PRINTF3(_L("%S: Can't find file %S"), &KTestFunction, &arg);
sl@0
  1200
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1201
        return;
sl@0
  1202
        }
sl@0
  1203
    // Create the buffer we're going to bind from. We'll keep a reference
sl@0
  1204
    // to this so it doesn't go out of scope (it mustn't
sl@0
  1205
    // until Exec/Reset) so don't put it on the cleanup stack.
sl@0
  1206
    RBuf8 ap;
sl@0
  1207
    TInt err = ap.Create(fsize);
sl@0
  1208
    ReportOnError(KTestFunction, _L("BufferCreate"), acfgblk, acnnum, err);
sl@0
  1209
    if(err != KErrNone) return;
sl@0
  1210
sl@0
  1211
    // Now open the file specified in the argument.
sl@0
  1212
    RFile file;
sl@0
  1213
    TFileName fn = arg;
sl@0
  1214
    err = file.Open(irfs, fn, 0);
sl@0
  1215
    ReportOnError(KTestFunction, _L("FileOpen"), acfgblk, acnnum, err);
sl@0
  1216
    if(err != KErrNone)
sl@0
  1217
        {
sl@0
  1218
        ap.Close();
sl@0
  1219
        return;
sl@0
  1220
        }
sl@0
  1221
    CleanupClosePushL(file);
sl@0
  1222
sl@0
  1223
    // Attempt to read from the file.
sl@0
  1224
    err = file.Read(ap, fsize);
sl@0
  1225
    ReportOnError(KTestFunction, _L("FileRead"), acfgblk, acnnum, err);
sl@0
  1226
    if(err != KErrNone)
sl@0
  1227
        {
sl@0
  1228
        CleanupStack::PopAndDestroy(1, &file);
sl@0
  1229
        ap.Close();
sl@0
  1230
        return;
sl@0
  1231
        }
sl@0
  1232
sl@0
  1233
    // Do the bind...
sl@0
  1234
    err = isqlst.BindBinary(apidx, ap);
sl@0
  1235
    ReportOnError(KTestFunction, _L("BindBinary"), acfgblk, acnnum, err);
sl@0
  1236
sl@0
  1237
    // Drop out if it failed.
sl@0
  1238
    if(err != KErrNone)
sl@0
  1239
        {
sl@0
  1240
        CleanupStack::PopAndDestroy(1, &file);
sl@0
  1241
        ap.Close();
sl@0
  1242
        return;
sl@0
  1243
        }
sl@0
  1244
sl@0
  1245
    CleanupStack::PopAndDestroy(1, &file);
sl@0
  1246
sl@0
  1247
    // Ok things seemed to have worked. Tack the buffer onto our internal
sl@0
  1248
    // RBuf8 array to keep it in scope. It will finally get trashed when
sl@0
  1249
    // we do the next RSqlStatement::Reset.
sl@0
  1250
    iBindRBuf8arr.Append(ap);
sl@0
  1251
sl@0
  1252
    return;
sl@0
  1253
    }
sl@0
  1254
void CSQLFnStep::IsNull(const TInt& apidx, const TPtrC& atxt)
sl@0
  1255
    {
sl@0
  1256
    _LIT(KTestFunction, "IsNull");
sl@0
  1257
    TBuf<8> isn(atxt);
sl@0
  1258
    isn.LowerCase();
sl@0
  1259
    TBool expected;
sl@0
  1260
    if(isn == _L("false"))
sl@0
  1261
        expected = EFalse;
sl@0
  1262
    else if(isn == _L("true"))
sl@0
  1263
        expected = ETrue;
sl@0
  1264
    else
sl@0
  1265
        {
sl@0
  1266
        SetTestStepResult(EFail);
sl@0
  1267
        INFO_PRINTF1(HTML_RED);
sl@0
  1268
        ERR_PRINTF3(_L("%S: expected argument item to be true/false, got %S"),
sl@0
  1269
                     &KTestFunction, &atxt);
sl@0
  1270
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1271
        return;
sl@0
  1272
        }
sl@0
  1273
    if(isqlst.IsNull(apidx) != expected)
sl@0
  1274
        {
sl@0
  1275
        SetTestStepResult(EFail);
sl@0
  1276
        INFO_PRINTF1(HTML_RED);
sl@0
  1277
        ERR_PRINTF3(_L("%S: expected IsNull to return %S"), &KTestFunction,
sl@0
  1278
                            &atxt);
sl@0
  1279
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1280
        return;
sl@0
  1281
        }
sl@0
  1282
    else
sl@0
  1283
        {
sl@0
  1284
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1285
        INFO_PRINTF3(_L("%S: Got expected result, %S"), &KTestFunction, &atxt);
sl@0
  1286
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1287
        }
sl@0
  1288
    return;
sl@0
  1289
    }
sl@0
  1290
void CSQLFnStep::ColumnInt(const TInt& acidx, const TInt& aint)
sl@0
  1291
    {
sl@0
  1292
    _LIT(KTestFunction, "ColumnInt");
sl@0
  1293
sl@0
  1294
    TInt got = isqlst.ColumnInt(acidx);
sl@0
  1295
    if(got != aint)
sl@0
  1296
        {
sl@0
  1297
        SetTestStepResult(EFail);
sl@0
  1298
        INFO_PRINTF1(HTML_RED);
sl@0
  1299
        ERR_PRINTF4(_L("%S: expected ColumnInt to return %d, got %d"),
sl@0
  1300
                           &KTestFunction, aint, got);
sl@0
  1301
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1302
        return;
sl@0
  1303
        }
sl@0
  1304
    else
sl@0
  1305
        {
sl@0
  1306
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1307
        INFO_PRINTF3(_L("%S: Got expected result, %d"), &KTestFunction,
sl@0
  1308
                           got);
sl@0
  1309
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1310
        }
sl@0
  1311
    return;
sl@0
  1312
    }
sl@0
  1313
void CSQLFnStep::ColumnInt64(const TInt& acidx, const TPtrC& aintS)
sl@0
  1314
    {
sl@0
  1315
    _LIT(KTestFunction, "ColumnInt64");
sl@0
  1316
sl@0
  1317
    TLex tl(aintS);
sl@0
  1318
    TInt64 aint;
sl@0
  1319
    tl.Val(aint);
sl@0
  1320
    TInt64 got = isqlst.ColumnInt64(acidx);
sl@0
  1321
    if(got != aint)
sl@0
  1322
        {
sl@0
  1323
        SetTestStepResult(EFail);
sl@0
  1324
        INFO_PRINTF1(HTML_RED);
sl@0
  1325
        ERR_PRINTF3(_L("%S: expected ColumnInt to return %S"),
sl@0
  1326
                                   &KTestFunction, &aint);
sl@0
  1327
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1328
        return;
sl@0
  1329
        }
sl@0
  1330
    else
sl@0
  1331
        {
sl@0
  1332
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1333
        INFO_PRINTF3(_L("%S: Got expected result, %ld"), &KTestFunction,
sl@0
  1334
                           got);
sl@0
  1335
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1336
        }
sl@0
  1337
    return;
sl@0
  1338
    }
sl@0
  1339
void CSQLFnStep::ColumnReal(const TInt& acidx, const TReal& areal)
sl@0
  1340
    {
sl@0
  1341
    _LIT(KTestFunction, "ColumnReal");
sl@0
  1342
sl@0
  1343
    TReal got = isqlst.ColumnReal(acidx);
sl@0
  1344
    if(got != areal)
sl@0
  1345
        {
sl@0
  1346
        SetTestStepResult(EFail);
sl@0
  1347
        INFO_PRINTF1(HTML_RED);
sl@0
  1348
        ERR_PRINTF4(_L("%S: expected ColumnReal to return %f, got %f"),
sl@0
  1349
                           &KTestFunction, areal, got);
sl@0
  1350
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1351
        return;
sl@0
  1352
        }
sl@0
  1353
    else
sl@0
  1354
        {
sl@0
  1355
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1356
        INFO_PRINTF3(_L("%S: Got expected result, %f"), &KTestFunction, got);
sl@0
  1357
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1358
        }
sl@0
  1359
    return;
sl@0
  1360
    }
sl@0
  1361
void CSQLFnStep::ColumnTextL(const TInt& acidx, const TPtrC& atxt,
sl@0
  1362
                             const TDesC &acfgblk, const TInt acnnum=-1)
sl@0
  1363
    {
sl@0
  1364
    _LIT(KTestFunction, "ColumnTextL");
sl@0
  1365
sl@0
  1366
    TPtrC got = isqlst.ColumnTextL(acidx);
sl@0
  1367
    TInt err;
sl@0
  1368
sl@0
  1369
    // First the simplest, does the text match the config text?
sl@0
  1370
    if(got == atxt)
sl@0
  1371
        {
sl@0
  1372
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1373
        INFO_PRINTF3(_L("%S: Got expected result, %S"), &KTestFunction,
sl@0
  1374
                           &got);
sl@0
  1375
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1376
        return;
sl@0
  1377
        }
sl@0
  1378
sl@0
  1379
    // Perhaps 'atxt' is a file, CompareTextAgainstFile will
sl@0
  1380
    // return KErrNotFound if it can't find the file.
sl@0
  1381
    if((err = CompareTextAgainstFileL(got, atxt)) == KErrNone)
sl@0
  1382
        {
sl@0
  1383
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1384
        INFO_PRINTF3(_L("%S: Text match with file %S"), &KTestFunction,
sl@0
  1385
                           &atxt);
sl@0
  1386
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1387
        return;
sl@0
  1388
        }
sl@0
  1389
sl@0
  1390
    ReportOnError(KTestFunction, _L("ColumnTextL"), acfgblk, acnnum, err);
sl@0
  1391
sl@0
  1392
    return;
sl@0
  1393
    }
sl@0
  1394
void CSQLFnStep::ColumnTextPL(const TInt& acidx, const TPtrC &arg,
sl@0
  1395
                              const TDesC& acfgblk, const TInt acnnum=-1)
sl@0
  1396
    {
sl@0
  1397
    _LIT(KTestFunction, "ColumnTextP");
sl@0
  1398
sl@0
  1399
    TPtrC got;
sl@0
  1400
    TInt err = isqlst.ColumnText(acidx, got);
sl@0
  1401
    ReportOnError(KTestFunction, _L("ColumnTextP"), acfgblk, acnnum, err);
sl@0
  1402
sl@0
  1403
    // First the simplest, does the text match the config text?
sl@0
  1404
    if(got == arg)
sl@0
  1405
        {
sl@0
  1406
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1407
        INFO_PRINTF3(_L("%S: Got expected result, %S"), &KTestFunction,
sl@0
  1408
                           &got);
sl@0
  1409
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1410
        return;
sl@0
  1411
        }
sl@0
  1412
sl@0
  1413
    // Perhaps 'arg' is a file, CompareTextAgainstFile will
sl@0
  1414
    // return KErrNotFound if it can't find the file.
sl@0
  1415
    if((err = CompareTextAgainstFileL(got, arg)) == KErrNone)
sl@0
  1416
        {
sl@0
  1417
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1418
        INFO_PRINTF3(_L("%S: Text match with file %S"), &KTestFunction,
sl@0
  1419
                           &arg);
sl@0
  1420
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1421
        return;
sl@0
  1422
        }
sl@0
  1423
sl@0
  1424
    ReportOnError(KTestFunction, _L("ColumnTextP"), acfgblk, acnnum, err);
sl@0
  1425
    }
sl@0
  1426
void CSQLFnStep::ColumnTextDL(const TInt& acidx, const TPtrC &arg,
sl@0
  1427
                              const TDesC& acfgblk, const TInt acnnum=-1)
sl@0
  1428
    {
sl@0
  1429
    _LIT(KTestFunction, "ColumnTextD");
sl@0
  1430
// Masses of duplication.. We should have a common method to get around
sl@0
  1431
// this, but perhaps when time permits..
sl@0
  1432
sl@0
  1433
    // How big is this item? This is measured in bytes, not characters.
sl@0
  1434
    TInt colsize = isqlst.ColumnSize(acidx);
sl@0
  1435
sl@0
  1436
    // Allocate a buffer.
sl@0
  1437
    RBuf buf;
sl@0
  1438
    TInt err = buf.Create(colsize);
sl@0
  1439
    INFO_PRINTF3(_L("%S: colsize %d"), &KTestFunction, colsize);
sl@0
  1440
    if(err != KErrNone)
sl@0
  1441
        {
sl@0
  1442
        SetTestStepResult(EFail);
sl@0
  1443
        INFO_PRINTF1(HTML_RED);
sl@0
  1444
        ERR_PRINTF3(_L("%S: Failed to allocate %d"), &KTestFunction,
sl@0
  1445
                           colsize);
sl@0
  1446
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1447
        }
sl@0
  1448
    CleanupClosePushL(buf);
sl@0
  1449
sl@0
  1450
    // Call ColumnText(TInt aColumnIndex, TDes& aDest);
sl@0
  1451
    err = isqlst.ColumnText(acidx, buf);
sl@0
  1452
    ReportOnError(KTestFunction, _L("ColumnTextD"), acfgblk, acnnum, err);
sl@0
  1453
    if(err != KErrNone)
sl@0
  1454
        {
sl@0
  1455
        CleanupStack::PopAndDestroy(1, &buf);
sl@0
  1456
        return;
sl@0
  1457
        }
sl@0
  1458
sl@0
  1459
    // First the simplest, does the text match the config text?
sl@0
  1460
    if(buf == arg)
sl@0
  1461
        {
sl@0
  1462
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1463
        INFO_PRINTF3(_L("%S: Got expected result, %S"), &KTestFunction,
sl@0
  1464
                           &buf);
sl@0
  1465
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1466
        CleanupStack::PopAndDestroy(1, &buf);
sl@0
  1467
        return;
sl@0
  1468
        }
sl@0
  1469
sl@0
  1470
    // Perhaps 'arg' is a file, CompareTextAgainstFile will
sl@0
  1471
    // return KErrNotFound if it can't find the file.
sl@0
  1472
    if((err = CompareTextAgainstFileL(buf, arg)) == KErrNone)
sl@0
  1473
        {
sl@0
  1474
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1475
        INFO_PRINTF3(_L("%S: Text match with file %S"), &KTestFunction,
sl@0
  1476
                           &arg);
sl@0
  1477
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1478
        CleanupStack::PopAndDestroy(1, &buf);
sl@0
  1479
        return;
sl@0
  1480
        }
sl@0
  1481
sl@0
  1482
    ReportOnError(KTestFunction, _L("ColumnTextD"), acfgblk, acnnum, err);
sl@0
  1483
    CleanupStack::PopAndDestroy(1, &buf);
sl@0
  1484
    return;
sl@0
  1485
    }
sl@0
  1486
void CSQLFnStep::ColumnBinaryL(const TInt& acidx, const TPtrC &arg,
sl@0
  1487
                               const TDesC& acfgblk, const TInt acnnum=-1)
sl@0
  1488
    {
sl@0
  1489
    _LIT(KTestFunction, "ColumnBinaryL");
sl@0
  1490
sl@0
  1491
    // Get the output from ColumnBinary.
sl@0
  1492
    TPtrC8 colb = isqlst.ColumnBinaryL(acidx);
sl@0
  1493
    INFO_PRINTF3(_L("%S: Got length %d"), &KTestFunction, colb.Length());
sl@0
  1494
    // If both are zero length, then we're expected nothing, which is a
sl@0
  1495
    // reasonable possibility.
sl@0
  1496
    if((colb.Length() == 0) && (arg.Length() == 0))
sl@0
  1497
        {
sl@0
  1498
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1499
        INFO_PRINTF2(_L("%S: Got expected empty buffer."), &KTestFunction);
sl@0
  1500
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1501
        return;
sl@0
  1502
        }
sl@0
  1503
sl@0
  1504
    // Compare ColumnBinary return against a file.
sl@0
  1505
    TInt err = CompareBinaryAgainstFileL(colb, arg);
sl@0
  1506
    ReportOnError(KTestFunction, _L("ColumnBinaryL"), acfgblk, acnnum, err);
sl@0
  1507
sl@0
  1508
    return;
sl@0
  1509
    }
sl@0
  1510
void CSQLFnStep::ColumnBinaryPL(const TInt& acidx, const TPtrC &arg,
sl@0
  1511
                                const TDesC& acfgblk, const TInt acnnum=-1)
sl@0
  1512
    {
sl@0
  1513
    _LIT(KTestFunction, "ColumnBinaryP");
sl@0
  1514
sl@0
  1515
    TInt csize = isqlst.ColumnSize(acidx);
sl@0
  1516
    INFO_PRINTF3(_L("%S: Colsize %d"), &KTestFunction, csize);
sl@0
  1517
#ifdef _UNICODE
sl@0
  1518
    if(isqlst.ColumnType(acidx) == ESqlText) csize <<= 1;
sl@0
  1519
#endif
sl@0
  1520
sl@0
  1521
    RBuf8 data;
sl@0
  1522
    TInt err;
sl@0
  1523
    if((err = data.Create(csize)) != KErrNone)
sl@0
  1524
        {
sl@0
  1525
        ReportOnError(KTestFunction, _L("Createbuf"), acfgblk, acnnum, err);
sl@0
  1526
        return;
sl@0
  1527
        }
sl@0
  1528
    CleanupClosePushL(data);
sl@0
  1529
    err = isqlst.ColumnBinary(acidx, data);
sl@0
  1530
    ReportOnError(KTestFunction, _L("ColumnBinaryP"), acfgblk, acnnum, err);
sl@0
  1531
    if((data.Length()==0) && (arg.Length()==0))
sl@0
  1532
        {
sl@0
  1533
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1534
        INFO_PRINTF2(_L("%S: Got expected empty buffer."), &KTestFunction);
sl@0
  1535
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1536
        CleanupStack::PopAndDestroy(1, &data);
sl@0
  1537
        return;
sl@0
  1538
        }
sl@0
  1539
    if(err != KErrNone)
sl@0
  1540
        {
sl@0
  1541
        CleanupStack::PopAndDestroy(1, &data);
sl@0
  1542
           return;
sl@0
  1543
        }
sl@0
  1544
sl@0
  1545
    // Compare ColumnBinary return against a file.
sl@0
  1546
    err = CompareBinaryAgainstFileL(data, arg);
sl@0
  1547
    ReportOnError(KTestFunction, _L("FileCompare"), acfgblk, acnnum, err);
sl@0
  1548
    CleanupStack::PopAndDestroy(1, &data);
sl@0
  1549
    return;
sl@0
  1550
    }
sl@0
  1551
void CSQLFnStep::ColumnBinaryDL(const TInt& acidx, const TPtrC &arg,
sl@0
  1552
                                const TDesC& acfgblk, const TInt acnnum=-1)
sl@0
  1553
    {
sl@0
  1554
    _LIT(KTestFunction, "ColumnBinaryD");
sl@0
  1555
sl@0
  1556
    // How big is this item?
sl@0
  1557
    TInt colsize = isqlst.ColumnSize(acidx);
sl@0
  1558
    INFO_PRINTF3(_L("%S: colsize %d"), &KTestFunction, colsize);
sl@0
  1559
#ifdef _UNICODE
sl@0
  1560
    if(isqlst.ColumnType(acidx) == ESqlText) colsize <<= 1;
sl@0
  1561
#endif
sl@0
  1562
sl@0
  1563
    // Allocate a buffer.
sl@0
  1564
    RBuf8 buf;
sl@0
  1565
    TInt err = buf.Create(colsize);
sl@0
  1566
    if(err != KErrNone)
sl@0
  1567
        {
sl@0
  1568
        SetTestStepResult(EFail);
sl@0
  1569
        INFO_PRINTF1(HTML_RED);
sl@0
  1570
        ERR_PRINTF3(_L("%S: Failed to allocate %d bytes"), &KTestFunction,
sl@0
  1571
                           colsize);
sl@0
  1572
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1573
        }
sl@0
  1574
    CleanupClosePushL(buf);
sl@0
  1575
sl@0
  1576
    // Call ColumnBinary(TInt aColumnIndex, TDes8& aDest);
sl@0
  1577
    err = isqlst.ColumnBinary(acidx, buf);
sl@0
  1578
    ReportOnError(KTestFunction, _L("ColumnBinaryD"), acfgblk, acnnum, err);
sl@0
  1579
    if(err != KErrNone)
sl@0
  1580
        {
sl@0
  1581
        CleanupStack::PopAndDestroy(1, &buf);
sl@0
  1582
        return;
sl@0
  1583
        }
sl@0
  1584
    if((buf.Length()==0) && (arg.Length()==0))
sl@0
  1585
        {
sl@0
  1586
        CleanupStack::PopAndDestroy(1, &buf);
sl@0
  1587
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1588
        INFO_PRINTF2(_L("%S: Got expected empty buffer."), &KTestFunction);
sl@0
  1589
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1590
        return;
sl@0
  1591
        }
sl@0
  1592
sl@0
  1593
    // Compare ColumnBinary return against a file.
sl@0
  1594
    err = CompareBinaryAgainstFileL(buf, arg);
sl@0
  1595
    ReportOnError(KTestFunction, _L("ColumnBinaryD"), acfgblk, acnnum, err);
sl@0
  1596
    CleanupStack::PopAndDestroy(1, &buf);
sl@0
  1597
sl@0
  1598
    return;
sl@0
  1599
    }
sl@0
  1600
sl@0
  1601
// The following four methods, SWBindText, SWBindBinary, SRColumnText and
sl@0
  1602
// SRColumnBinary are Stream-Write and Stream-Read methods.
sl@0
  1603
// In each case 'arg' specifies a file which is opened as a source (SW)
sl@0
  1604
// of data, or else as another stream (SR) to compare against.
sl@0
  1605
void CSQLFnStep::SWBindTextL(const TInt& apidx, const TPtrC &arg,
sl@0
  1606
                             const TDesC& acfgblk, const TInt acnnum=-1)
sl@0
  1607
    {
sl@0
  1608
    _LIT(KTestFunction, "SWBindText");
sl@0
  1609
    RSqlParamWriteStream sqlw;
sl@0
  1610
    // Get the WriteStream to stuff data down..
sl@0
  1611
    TInt err = sqlw.BindText(isqlst, apidx);
sl@0
  1612
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, err);
sl@0
  1613
    if(err != KErrNone) return;
sl@0
  1614
    WriteFileToStreamL(sqlw, arg);
sl@0
  1615
    sqlw.Close();
sl@0
  1616
    return;
sl@0
  1617
    }
sl@0
  1618
void CSQLFnStep::SWBindBinaryL(const TInt& apidx, const TPtrC &arg,
sl@0
  1619
                               const TDesC& acfgblk, const TInt acnnum=-1)
sl@0
  1620
    {
sl@0
  1621
    _LIT(KTestFunction, "SWBindBinary");
sl@0
  1622
    RSqlParamWriteStream sqlw;
sl@0
  1623
    // Get the WriteStream to stuff data down..
sl@0
  1624
    TInt err = sqlw.BindBinary(isqlst, apidx);
sl@0
  1625
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, err);
sl@0
  1626
    if(err != KErrNone) return;
sl@0
  1627
    WriteFileToStreamL(sqlw, arg);
sl@0
  1628
    sqlw.Close();
sl@0
  1629
    return;
sl@0
  1630
    }
sl@0
  1631
void CSQLFnStep::SRColumnTextL(const TInt& acidx, const TPtrC &arg,
sl@0
  1632
                              const TDesC& acfgblk, const TInt acnnum=-1)
sl@0
  1633
    {
sl@0
  1634
    _LIT(KTestFunction, "SRColumnText");
sl@0
  1635
sl@0
  1636
    // First find out how much data is in this cell..
sl@0
  1637
    TInt dsize = isqlst.ColumnSize(acidx);
sl@0
  1638
    INFO_PRINTF3(_L("%S: ColumnSize is %d"), &KTestFunction, dsize);
sl@0
  1639
sl@0
  1640
    RSqlColumnReadStream sqlr;
sl@0
  1641
    TInt err = sqlr.ColumnText(isqlst, acidx);
sl@0
  1642
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, err);
sl@0
  1643
    if(err != KErrNone) return;
sl@0
  1644
    // Ok, we have a Read Stream..
sl@0
  1645
    CleanupClosePushL(sqlr);
sl@0
  1646
sl@0
  1647
    // Compare it..
sl@0
  1648
    TInt rc = CompareTextStreamAgainstFileL(sqlr, dsize, arg);
sl@0
  1649
    if(rc)
sl@0
  1650
        {
sl@0
  1651
        SetTestStepResult(EFail);
sl@0
  1652
        INFO_PRINTF1(HTML_RED);
sl@0
  1653
        ERR_PRINTF3(_L("%S: Stream comparison failure, file %S"),
sl@0
  1654
                           &KTestFunction, &arg);
sl@0
  1655
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1656
        }
sl@0
  1657
    else
sl@0
  1658
        {
sl@0
  1659
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1660
        INFO_PRINTF3(_L("%S: Stream comparison success, file %S"),
sl@0
  1661
                           &KTestFunction, &arg);
sl@0
  1662
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1663
        }
sl@0
  1664
    CleanupStack::PopAndDestroy(1,&sqlr);
sl@0
  1665
    return;
sl@0
  1666
    }
sl@0
  1667
void CSQLFnStep::SRColumnBinaryL(const TInt& acidx, const TPtrC &arg,
sl@0
  1668
                                 const TDesC& acfgblk, const TInt acnnum=-1)
sl@0
  1669
    {
sl@0
  1670
    _LIT(KTestFunction, "SRColumnBinary");
sl@0
  1671
sl@0
  1672
    // First find out how much data is in this cell..
sl@0
  1673
    TInt dsize = isqlst.ColumnSize(acidx);
sl@0
  1674
    INFO_PRINTF3(_L("%S: Colsize is %d"), &KTestFunction, dsize);
sl@0
  1675
#ifdef _UNICODE
sl@0
  1676
    if(isqlst.ColumnType(acidx) == ESqlText) dsize <<= 1;
sl@0
  1677
#endif
sl@0
  1678
sl@0
  1679
    // Get our RReadStream and check for errors.
sl@0
  1680
    RSqlColumnReadStream sqlr;
sl@0
  1681
    TInt err = sqlr.ColumnBinary(isqlst, acidx);
sl@0
  1682
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, err);
sl@0
  1683
    if(err != KErrNone) return;
sl@0
  1684
    // Ok, we have a Read Stream..
sl@0
  1685
    CleanupClosePushL(sqlr);
sl@0
  1686
sl@0
  1687
    // Compare it..
sl@0
  1688
    TInt rc = CompareBinaryStreamAgainstFileL(sqlr, dsize, arg);
sl@0
  1689
    if(rc)
sl@0
  1690
        {
sl@0
  1691
        SetTestStepResult(EFail);
sl@0
  1692
        INFO_PRINTF1(HTML_RED);
sl@0
  1693
        ERR_PRINTF3(_L("%S: Stream comparison failure, file %S"),
sl@0
  1694
                           &KTestFunction, &arg);
sl@0
  1695
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1696
        }
sl@0
  1697
    else
sl@0
  1698
        {
sl@0
  1699
        INFO_PRINTF1(HTML_GREEN);
sl@0
  1700
        INFO_PRINTF3(_L("%S: Stream comparison success, file %S"),
sl@0
  1701
                           &KTestFunction, &arg);
sl@0
  1702
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1703
        }
sl@0
  1704
    CleanupStack::PopAndDestroy(1,&sqlr);
sl@0
  1705
    return;
sl@0
  1706
    }
sl@0
  1707
sl@0
  1708
TBool CSQLFnStep::SPCreate(const TDesC &acfgblk, const TInt acnnum)
sl@0
  1709
    {
sl@0
  1710
    _LIT(KTestFunction, "SPCreate");
sl@0
  1711
    
sl@0
  1712
    TSecurityPolicy defaultPolicy;
sl@0
  1713
    
sl@0
  1714
    // Try to create the SQLDB security policy.
sl@0
  1715
    TInt rc = isqlsp.Create(defaultPolicy);
sl@0
  1716
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
  1717
    if(rc == KErrNone) return ETrue;
sl@0
  1718
    return EFalse;
sl@0
  1719
    }
sl@0
  1720
sl@0
  1721
TBool CSQLFnStep::SPCreate(const TPtrC&, const TDesC &acfgblk, const TInt acnnum)
sl@0
  1722
    {
sl@0
  1723
    _LIT(KTestFunction, "SPCreate");
sl@0
  1724
    
sl@0
  1725
    TSecurityPolicy defaultPolicy;
sl@0
  1726
    
sl@0
  1727
    // Try to create the SQLDB security policy.
sl@0
  1728
    TInt rc = KErrNone;
sl@0
  1729
    TRAP(rc, isqlsp.CreateL(defaultPolicy));
sl@0
  1730
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
  1731
    if(rc == KErrNone) return ETrue;
sl@0
  1732
    return EFalse;
sl@0
  1733
    }
sl@0
  1734
sl@0
  1735
void CSQLFnStep::SPClose()
sl@0
  1736
    {
sl@0
  1737
    isqlsp.Close();
sl@0
  1738
    return;
sl@0
  1739
    }
sl@0
  1740
sl@0
  1741
TBool CSQLFnStep::SPSetDBPolicy(const TPtrC& apol, const TDesC &acfgblk, const TInt acnnum)
sl@0
  1742
    {
sl@0
  1743
    _LIT(KTestFunction, "SPSetDBPolicy");
sl@0
  1744
sl@0
  1745
    //extract the policy level and capability from the argument passed in
sl@0
  1746
    TPtrC level, cap;
sl@0
  1747
    CommaSeparated(apol, level, cap);
sl@0
  1748
sl@0
  1749
    //create the security policy object with the supplied capability
sl@0
  1750
    TSecurityPolicy sp((TCapability)(icaphsh->GetNumFromString(cap)));
sl@0
  1751
sl@0
  1752
    INFO_PRINTF2(_L("SetDBPolicy: %S"), &level);
sl@0
  1753
    INFO_PRINTF2(_L("Capabilities are: %S"), &cap);
sl@0
  1754
    
sl@0
  1755
    TInt rc = isqlsp.SetDbPolicy(((RSqlSecurityPolicy::TPolicyType)ipolhsh->GetNumFromString(level)), sp);
sl@0
  1756
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
  1757
    if(rc == KErrNone) return ETrue;
sl@0
  1758
    return EFalse;
sl@0
  1759
    }
sl@0
  1760
sl@0
  1761
TBool CSQLFnStep::SPSetPolicy(const TPtrC& apol, const TDesC &acfgblk, const TInt acnnum)
sl@0
  1762
    {
sl@0
  1763
    _LIT(KTestFunction, "SPSetPolicy");
sl@0
  1764
sl@0
  1765
    //extract the policy level and capability from the argument passed in
sl@0
  1766
    TPtrC arg, arg2, object, name, level, caps;
sl@0
  1767
    CommaSeparated(apol, object, arg);
sl@0
  1768
    CommaSeparated(arg, name, arg2);
sl@0
  1769
    CommaSeparated(arg2, level, caps);
sl@0
  1770
sl@0
  1771
    //create the security policy object with the supplied capability
sl@0
  1772
    TSecurityPolicy sp((TCapability)(icaphsh->GetNumFromString(caps)));
sl@0
  1773
sl@0
  1774
    INFO_PRINTF2(_L("SetPolicy: %S"), &level);
sl@0
  1775
    INFO_PRINTF2(_L("Capabilities are: %S"), &caps);
sl@0
  1776
    INFO_PRINTF2(_L("Object type is: %S"), &object);
sl@0
  1777
    INFO_PRINTF2(_L("Object name is: %S"), &name);
sl@0
  1778
    
sl@0
  1779
    TInt rc = isqlsp.SetPolicy(((RSqlSecurityPolicy::TObjectType)iobjhsh->GetNumFromString(object)), name, ((RSqlSecurityPolicy::TPolicyType)ipolhsh->GetNumFromString(level)), sp);
sl@0
  1780
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
  1781
    if(rc == KErrNone) return ETrue;
sl@0
  1782
    return EFalse;
sl@0
  1783
    }
sl@0
  1784
sl@0
  1785
void CSQLFnStep::SPExternalize(const TPtrC &arg, const TDesC &acfgblk, const TInt acnnum)
sl@0
  1786
    {
sl@0
  1787
    _LIT(KTestFunction, "SPExternalize");
sl@0
  1788
    
sl@0
  1789
    RFileWriteStream rfws;
sl@0
  1790
sl@0
  1791
    TInt err = rfws.Create(irfs, arg, EFileStream);
sl@0
  1792
    if(err != KErrNone)
sl@0
  1793
        {
sl@0
  1794
        SetTestStepResult(EFail);
sl@0
  1795
        INFO_PRINTF1(HTML_RED);
sl@0
  1796
        ERR_PRINTF4(_L("%S: Can't open file %S, err %d"), &KTestFunction, &arg,
sl@0
  1797
                         err );
sl@0
  1798
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1799
        return;
sl@0
  1800
        }
sl@0
  1801
    
sl@0
  1802
    TInt rc = KErrNone;
sl@0
  1803
    TRAP(rc, isqlsp.ExternalizeL(rfws));
sl@0
  1804
    TRAP(rc, rfws.CommitL());
sl@0
  1805
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
  1806
    rfws.Close();    
sl@0
  1807
    return;
sl@0
  1808
    }
sl@0
  1809
sl@0
  1810
void CSQLFnStep::SPInternalize(const TPtrC &arg, const TDesC &acfgblk, const TInt acnnum)
sl@0
  1811
    {
sl@0
  1812
    _LIT(KTestFunction, "SPInternalize");
sl@0
  1813
    
sl@0
  1814
    RFileReadStream rfrs;
sl@0
  1815
    
sl@0
  1816
    TInt err = rfrs.Open(irfs, arg, EFileStream);
sl@0
  1817
    if(err != KErrNone)
sl@0
  1818
        {
sl@0
  1819
        SetTestStepResult(EFail);
sl@0
  1820
        INFO_PRINTF1(HTML_RED);
sl@0
  1821
        ERR_PRINTF3(_L("%S: Failed to open stream from file %S"), &KTestFunction, &arg);
sl@0
  1822
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1823
        return;
sl@0
  1824
        }
sl@0
  1825
    
sl@0
  1826
    TInt rc = KErrNone;
sl@0
  1827
    TRAP(rc, isqlsp.InternalizeL(rfrs));
sl@0
  1828
        
sl@0
  1829
    ReportOnError(KTestFunction, KTestFunction, acfgblk, acnnum, rc);
sl@0
  1830
    rfrs.Close();     
sl@0
  1831
    return;
sl@0
  1832
    }
sl@0
  1833
sl@0
  1834
// - Utility functions... ---  we should remove these into a separate class -- 
sl@0
  1835
//
sl@0
  1836
// Stream functions - should we have a persistent stream? Here it goes
sl@0
  1837
// out of scope once the method completes, but what about a case where for
sl@0
  1838
// example we write to a cell, then write some more later to the same cell?
sl@0
  1839
//
sl@0
  1840
// Loads more duplication..
sl@0
  1841
TInt CSQLFnStep::CompareTextStreamAgainstFileL(RReadStream &as, TInt asiz,
sl@0
  1842
                                               const TPtrC &afile)
sl@0
  1843
    {
sl@0
  1844
    _LIT(KTestFunction, "CompareTextStreamAgainstFile");
sl@0
  1845
    // Get the file size. This is in bytes, so for Unicode will be
sl@0
  1846
    // out by a factor of two. Also, if created with notepad or similar
sl@0
  1847
    // will have a 'FEFF' two byte marker at the start (which SQLite
sl@0
  1848
    // strips when it sees it).
sl@0
  1849
    TInt fsize = FileSize(afile);
sl@0
  1850
    if(fsize < 0) return fsize;;
sl@0
  1851
    // We don't divide asiz by two: This will have originated in ColumnSize
sl@0
  1852
    // which returns the number of characters in a cell.
sl@0
  1853
    TInt textlen = asiz;
sl@0
  1854
#ifdef _UNICODE
sl@0
  1855
    fsize >>= 1;
sl@0
  1856
#endif
sl@0
  1857
sl@0
  1858
    // If fsize is 1 different (2 bytes) from textlen, then we'll expect
sl@0
  1859
    // a unicode marker. If not 1 or zero give up straight away.
sl@0
  1860
    TInt diff = fsize - textlen;
sl@0
  1861
    TInt ucmark = (diff == 1);
sl@0
  1862
    if((diff>1) || (diff<0))
sl@0
  1863
        {
sl@0
  1864
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1865
        ERR_PRINTF4(_L("%S Size mismatch. Expected %d, got %d"),
sl@0
  1866
                                                &KTestFunction, fsize, textlen);
sl@0
  1867
        SetTestStepResult(EFail);
sl@0
  1868
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1869
        return KTEFSQLSizeError;
sl@0
  1870
        }
sl@0
  1871
sl@0
  1872
    // Open the reference file specified in the argument.
sl@0
  1873
    // Use an RFileReadStream because we need to worry about characters,
sl@0
  1874
    // not just bytes.
sl@0
  1875
    RFileReadStream rflrs;
sl@0
  1876
    TInt err = rflrs.Open(irfs, afile, EFileRead);
sl@0
  1877
    if(err != KErrNone)
sl@0
  1878
        return err;
sl@0
  1879
    CleanupClosePushL(rflrs);
sl@0
  1880
sl@0
  1881
    // Dumps the FEFF marker bytes for unicode files.
sl@0
  1882
    // SQLite does the same for text.
sl@0
  1883
    if(ucmark)
sl@0
  1884
        {
sl@0
  1885
        TInt16 mark = rflrs.ReadInt16L();  // byte order?
sl@0
  1886
        if((mark != (TInt16)0xfeff) && (mark != (TInt16)0xfffe))
sl@0
  1887
            {
sl@0
  1888
            CleanupStack::PopAndDestroy(1, &rflrs);
sl@0
  1889
            return KTEFSQLSizeError;
sl@0
  1890
            }
sl@0
  1891
        }
sl@0
  1892
sl@0
  1893
    // For each 32768 chars in the text buffer...
sl@0
  1894
    const TInt slice = 32768;
sl@0
  1895
    RBuf fbuf, abuf;
sl@0
  1896
    err = fbuf.Create(slice);
sl@0
  1897
    if(err == KErrNone) err = abuf.Create(slice);
sl@0
  1898
    if(err != KErrNone)
sl@0
  1899
        {
sl@0
  1900
        CleanupStack::PopAndDestroy(1, &rflrs);
sl@0
  1901
        return KErrNoMemory;
sl@0
  1902
        }
sl@0
  1903
    CleanupClosePushL(fbuf);
sl@0
  1904
    CleanupClosePushL(abuf);
sl@0
  1905
sl@0
  1906
    TInt rc = KErrNone;
sl@0
  1907
    for(TInt pos=0; pos < textlen ; pos += slice)
sl@0
  1908
        {
sl@0
  1909
        TInt toread = textlen - pos;
sl@0
  1910
        if(toread > slice)
sl@0
  1911
            toread = slice;
sl@0
  1912
sl@0
  1913
        // Read 'toread' characters from the file and from the passed in
sl@0
  1914
        // data.
sl@0
  1915
        as.ReadL(abuf, toread);
sl@0
  1916
        TPtrC txtslice = abuf.Left(toread);
sl@0
  1917
        rflrs.ReadL(fbuf, toread);
sl@0
  1918
        TPtrC fileslice = fbuf.Left(toread);
sl@0
  1919
sl@0
  1920
        // Compare ..
sl@0
  1921
        if (fileslice != txtslice)
sl@0
  1922
            { 
sl@0
  1923
            rc = KTEFSQLSizeError;
sl@0
  1924
            break;
sl@0
  1925
            }
sl@0
  1926
        }
sl@0
  1927
    CleanupStack::PopAndDestroy(3, &rflrs);
sl@0
  1928
    return rc;
sl@0
  1929
    }
sl@0
  1930
sl@0
  1931
// Loads more duplication..
sl@0
  1932
TInt CSQLFnStep::CompareBinaryStreamAgainstFileL(RReadStream &as, TInt asiz,
sl@0
  1933
                                                const TPtrC &afile)
sl@0
  1934
    {
sl@0
  1935
    _LIT(KTestFunction, "CompareBinaryStreamAgainstFile");
sl@0
  1936
    // Get the file size. This is in bytes.
sl@0
  1937
    TInt fsize = FileSize(afile);
sl@0
  1938
    if(fsize < 0) return fsize;;
sl@0
  1939
sl@0
  1940
    // If sizes differ give up immediately.
sl@0
  1941
    if(fsize - asiz)
sl@0
  1942
        {
sl@0
  1943
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1944
        ERR_PRINTF4(_L("%S Size mismatch. Expected %d, got %d"),
sl@0
  1945
                                                &KTestFunction, fsize, asiz);
sl@0
  1946
        SetTestStepResult(EFail);
sl@0
  1947
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  1948
        return KTEFSQLSizeError;
sl@0
  1949
        }
sl@0
  1950
sl@0
  1951
    // Open the reference file specified in the argument.
sl@0
  1952
    // Use an RFileReadStream because we need to worry about characters,
sl@0
  1953
    // not just bytes.
sl@0
  1954
    RFileReadStream rflrs;
sl@0
  1955
    TInt err = rflrs.Open(irfs, afile, EFileRead);
sl@0
  1956
    if(err != KErrNone) return err;
sl@0
  1957
    CleanupClosePushL(rflrs);
sl@0
  1958
sl@0
  1959
    // For each 32768 chars in the text buffer...
sl@0
  1960
    const TInt slice = 32768;
sl@0
  1961
    RBuf8 fbuf, abuf;
sl@0
  1962
    err = fbuf.Create(slice);
sl@0
  1963
    if(err == KErrNone) err = abuf.Create(slice);
sl@0
  1964
    if(err != KErrNone)
sl@0
  1965
        {
sl@0
  1966
        CleanupStack::PopAndDestroy(1, &rflrs);
sl@0
  1967
        return err;
sl@0
  1968
        }
sl@0
  1969
    CleanupClosePushL(fbuf);
sl@0
  1970
    CleanupClosePushL(abuf);
sl@0
  1971
sl@0
  1972
    TInt rc = KErrNone;
sl@0
  1973
    for(TInt pos=0; pos < asiz ; pos += slice)
sl@0
  1974
        {
sl@0
  1975
        TInt toread = asiz - pos;
sl@0
  1976
        if(toread > slice)
sl@0
  1977
            toread = slice;
sl@0
  1978
sl@0
  1979
        // Read 'toread' characters from the file and from the passed in
sl@0
  1980
        // data. Do we really need to chop out only the read bits for
sl@0
  1981
        // comparison? Wouldn't comparing fbuf and abuf work?
sl@0
  1982
        rflrs.ReadL(fbuf, toread);
sl@0
  1983
        TPtr8 fslice = fbuf.LeftTPtr(toread);
sl@0
  1984
        as.ReadL(abuf, toread);
sl@0
  1985
        TPtr8 aslice = abuf.LeftTPtr(toread);
sl@0
  1986
sl@0
  1987
        // Compare .. (does this compare only what's been read?)
sl@0
  1988
        if (fslice != aslice)
sl@0
  1989
            { 
sl@0
  1990
            rc = KTEFSQLSizeError;
sl@0
  1991
            break;
sl@0
  1992
            }
sl@0
  1993
        }
sl@0
  1994
    CleanupStack::PopAndDestroy(3, &rflrs);
sl@0
  1995
    return rc;
sl@0
  1996
    }
sl@0
  1997
void CSQLFnStep::WriteFileToStreamL(RWriteStream &as1, const TPtrC &afile)
sl@0
  1998
    {
sl@0
  1999
    _LIT(KTestFunction, "WriteFileToStream");
sl@0
  2000
    // Open the reference file specified in the argument.
sl@0
  2001
    RFileReadStream rflrs;
sl@0
  2002
    TInt err = rflrs.Open(irfs, afile, EFileRead);
sl@0
  2003
    // Do we want to return anything?
sl@0
  2004
    if(err != KErrNone)
sl@0
  2005
        {
sl@0
  2006
        SetTestStepResult(EFail);
sl@0
  2007
        INFO_PRINTF1(HTML_RED);
sl@0
  2008
        ERR_PRINTF3(_L("%S: Failed to open stream from file %S"),
sl@0
  2009
                           &KTestFunction, &afile);
sl@0
  2010
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  2011
        return;
sl@0
  2012
        }
sl@0
  2013
    CleanupClosePushL(rflrs);
sl@0
  2014
    as1.WriteL(rflrs);
sl@0
  2015
    CleanupStack::PopAndDestroy(1, &rflrs);
sl@0
  2016
    return;
sl@0
  2017
    }
sl@0
  2018
sl@0
  2019
TInt CSQLFnStep::CompareBinaryAgainstFileL(const TDesC8 &abuf,
sl@0
  2020
                                          const TFileName& afile)
sl@0
  2021
    {
sl@0
  2022
    _LIT(KTestFunction, "CompareBinaryAgainstFile");
sl@0
  2023
    // Get the file size.
sl@0
  2024
    TInt fsize = FileSize(afile);
sl@0
  2025
    if(fsize < 0) return fsize;
sl@0
  2026
    // How much binary do we have?
sl@0
  2027
    TInt binlen = abuf.Length();
sl@0
  2028
sl@0
  2029
    INFO_PRINTF4(_L("%S: Filelen %d, Binlen %d"), &KTestFunction, fsize, binlen);
sl@0
  2030
sl@0
  2031
    // If sizes differ drop out immediately.
sl@0
  2032
    if(fsize - binlen)
sl@0
  2033
        return KTEFSQLSizeError;
sl@0
  2034
sl@0
  2035
    // Open the reference file specified in the argument.
sl@0
  2036
    // Use an RFileReadStream because we need to worry about characters,
sl@0
  2037
    // not just bytes.
sl@0
  2038
    RFileReadStream rflrs;
sl@0
  2039
    TInt err = rflrs.Open(irfs, afile, EFileRead);
sl@0
  2040
    if(err != KErrNone)
sl@0
  2041
        return err;
sl@0
  2042
    CleanupClosePushL(rflrs);
sl@0
  2043
sl@0
  2044
    // For each 32768 chars in the text buffer...
sl@0
  2045
    const TInt slice = 32768;
sl@0
  2046
    RBuf8 fbuf;
sl@0
  2047
    fbuf.Create(slice);
sl@0
  2048
    CleanupClosePushL(fbuf);
sl@0
  2049
sl@0
  2050
    TInt rc = KErrNone;
sl@0
  2051
    for(TInt pos=0; pos < binlen ; pos += slice)
sl@0
  2052
        {
sl@0
  2053
        TInt toread = binlen - pos;
sl@0
  2054
        if(toread > slice)
sl@0
  2055
            toread = slice;
sl@0
  2056
sl@0
  2057
        // Read 'toread' bytes from the file and from the passed in
sl@0
  2058
        // data.
sl@0
  2059
        rflrs.ReadL(fbuf, toread);
sl@0
  2060
        TPtrC8 fileslice = fbuf.Left(toread);
sl@0
  2061
        TPtrC8 binslice = abuf.Mid(pos, toread);
sl@0
  2062
sl@0
  2063
        // Compare ..
sl@0
  2064
        if (fileslice != binslice)
sl@0
  2065
            { 
sl@0
  2066
            rc = KTEFSQLSizeError;
sl@0
  2067
            break;
sl@0
  2068
            }
sl@0
  2069
        }
sl@0
  2070
sl@0
  2071
    INFO_PRINTF2(_L("%S: Comparison successful"), &KTestFunction);
sl@0
  2072
    CleanupStack::PopAndDestroy(2, &rflrs);
sl@0
  2073
    return rc;
sl@0
  2074
    }
sl@0
  2075
sl@0
  2076
// Tested and working..
sl@0
  2077
TInt CSQLFnStep::CompareTextAgainstFileL(const TDesC &atxt,
sl@0
  2078
                                        const TFileName& afile)
sl@0
  2079
    {
sl@0
  2080
    // Get the file size. This is in bytes, so for Unicode will be
sl@0
  2081
    // out by a factor of two. Also, if created with notepad or similar
sl@0
  2082
    // will have a 'FEFF' two byte marker at the start (which SQLite
sl@0
  2083
    // strips when it sees it).
sl@0
  2084
    TInt fsize = FileSize(afile);
sl@0
  2085
    if(fsize < 0) return fsize;
sl@0
  2086
#ifdef _UNICODE
sl@0
  2087
    fsize >>= 1;
sl@0
  2088
#endif
sl@0
  2089
    // How much text do we have?
sl@0
  2090
    TInt textlen = atxt.Length();
sl@0
  2091
sl@0
  2092
    // If fsize is 1 different (2 bytes) from textlen, then we'll expect
sl@0
  2093
    // a unicode marker. If not 1 or zero give up straight away.
sl@0
  2094
    TInt diff = fsize - textlen;
sl@0
  2095
    TInt ucmark = (diff == 1);
sl@0
  2096
    if((diff>1) || (diff<0))
sl@0
  2097
        {
sl@0
  2098
        ERR_PRINTF3(_L("FSIZE is %d, textlen is %d"), fsize, textlen);
sl@0
  2099
        return KTEFSQLSizeError;
sl@0
  2100
        }
sl@0
  2101
sl@0
  2102
    // Open the reference file specified in the argument.
sl@0
  2103
    // Use an RFileReadStream because we need to worry about characters,
sl@0
  2104
    // not just bytes.
sl@0
  2105
    RFileReadStream rflrs;
sl@0
  2106
    TInt err = rflrs.Open(irfs, afile, EFileRead);
sl@0
  2107
    if(err != KErrNone)
sl@0
  2108
        return err;
sl@0
  2109
    CleanupClosePushL(rflrs);
sl@0
  2110
sl@0
  2111
    // Dumps the FEFF marker bytes for unicode files.
sl@0
  2112
    // SQLite does the same for text.
sl@0
  2113
    if(ucmark)
sl@0
  2114
        {
sl@0
  2115
        TInt16 mark = rflrs.ReadInt16L();  // byte order?
sl@0
  2116
        if((mark != (TInt16)0xfeff) && (mark != (TInt16)0xfffe))
sl@0
  2117
            {
sl@0
  2118
            CleanupStack::PopAndDestroy(1, &rflrs);
sl@0
  2119
            return KTEFSQLSizeError;
sl@0
  2120
            }
sl@0
  2121
        }
sl@0
  2122
sl@0
  2123
    // For each 32768 chars in the text buffer...
sl@0
  2124
    const TInt slice = 32768;
sl@0
  2125
    RBuf fbuf;
sl@0
  2126
    fbuf.Create(slice);
sl@0
  2127
    CleanupClosePushL(fbuf);
sl@0
  2128
sl@0
  2129
    TInt rc = KErrNone;
sl@0
  2130
    for(TInt pos=0; pos < textlen ; pos += slice)
sl@0
  2131
        {
sl@0
  2132
        TInt toread = textlen - pos;
sl@0
  2133
        if(toread > slice)
sl@0
  2134
            toread = slice;
sl@0
  2135
sl@0
  2136
        // Read 'toread' characters from the file and from the passed in
sl@0
  2137
        // data.
sl@0
  2138
        rflrs.ReadL(fbuf, toread);
sl@0
  2139
        TPtrC txtslice = atxt.Mid(pos, toread);
sl@0
  2140
sl@0
  2141
        // Compare ..
sl@0
  2142
        if (fbuf != txtslice)
sl@0
  2143
            { 
sl@0
  2144
            rc = KTEFSQLSizeError;
sl@0
  2145
            break;
sl@0
  2146
            }
sl@0
  2147
        }
sl@0
  2148
    CleanupStack::PopAndDestroy(2, &rflrs);
sl@0
  2149
    return rc;
sl@0
  2150
    }
sl@0
  2151
sl@0
  2152
// Get the expected error code for the current action. Assume KErrNone if it
sl@0
  2153
// isn't in the config file. We might have (in the config file)
sl@0
  2154
// ExpectedError27=KSqlErrPermission
sl@0
  2155
int CSQLFnStep::ActionNoToErrEnum(const TDesC& acfgsec, const TInt aActionNum,
sl@0
  2156
                                  TPtrC& aes)
sl@0
  2157
    {
sl@0
  2158
    TBuf<KConfigItemMaxNameLength> cnfgerr(_L("ExpectedError"));
sl@0
  2159
    if(aActionNum != -1) cnfgerr.AppendNum(aActionNum);
sl@0
  2160
    if(!GetStringFromConfig(acfgsec, cnfgerr, aes))
sl@0
  2161
        aes.Set(_L("KErrNone"));
sl@0
  2162
    return(ErrStringToEnum(aes));
sl@0
  2163
}
sl@0
  2164
TInt CSQLFnStep::ErrStringToEnum(TPtrC &aerr)
sl@0
  2165
    {
sl@0
  2166
    return(ierrhsh->GetNumFromString(aerr));
sl@0
  2167
    }
sl@0
  2168
void CSQLFnStep::ErrEnumToString(const TInt &aerr, TPtrC &aptrstr)
sl@0
  2169
    {
sl@0
  2170
    aptrstr.Set(*(ierrhsh->GetStringFromNum(aerr)));
sl@0
  2171
    return;
sl@0
  2172
    }
sl@0
  2173
const TPtrC CSQLFnStep::SqlColumnTypeToString(TSqlColumnType &asqltype)
sl@0
  2174
    {
sl@0
  2175
    return *icoltypehsh->GetStringFromNum(asqltype);
sl@0
  2176
    }
sl@0
  2177
TSqlColumnType CSQLFnStep::StringToSqlColumnType(const TDesC &atype)
sl@0
  2178
    {
sl@0
  2179
    return (TSqlColumnType) icoltypehsh->GetNumFromString(atype);
sl@0
  2180
    }
sl@0
  2181
/*
sl@0
  2182
 * A helper function to report on an error. This won't say anything if the
sl@0
  2183
 * error received (aerr) is equal to the error expected as defined in the
sl@0
  2184
 * configuration file.
sl@0
  2185
 */
sl@0
  2186
void CSQLFnStep::ReportOnError(const TDesC &afnnam, const TDesC &apinam,
sl@0
  2187
                                const TDesC &acfgblk, const TInt acfgno,
sl@0
  2188
                                const TInt aerr)
sl@0
  2189
    {
sl@0
  2190
    // Get the expected error.
sl@0
  2191
    TPtrC experrS;
sl@0
  2192
    TInt experr = ActionNoToErrEnum(acfgblk, acfgno, experrS);
sl@0
  2193
sl@0
  2194
    // Some methods such as Exec and Next return a positive value on
sl@0
  2195
    // success. If we're not expecting an error and the actual error code
sl@0
  2196
    // is positive just return, everything is cool.
sl@0
  2197
    if((experr == KErrNone) && (aerr >= 0))
sl@0
  2198
        return;
sl@0
  2199
sl@0
  2200
    // Is the actual error the same as the expected error?
sl@0
  2201
    if(aerr != experr)
sl@0
  2202
        {
sl@0
  2203
        INFO_PRINTF1(HTML_RED);
sl@0
  2204
        SetTestStepResult(EFail);
sl@0
  2205
        TPtrC errS;
sl@0
  2206
        ErrEnumToString(aerr, errS); // Convert the actual error to a string.
sl@0
  2207
sl@0
  2208
        ERR_PRINTF7(_L("%S: %S gave error %d/%S, expected %d/%S"),
sl@0
  2209
                        &afnnam, &apinam, aerr, &errS, experr, &experrS);
sl@0
  2210
        // Run 'LastErrorMessage' if we unexpectedly have 'KSqlErrGeneral',
sl@0
  2211
        // often what it has to say is very helpful.
sl@0
  2212
        if(aerr == KSqlErrGeneral)
sl@0
  2213
            LastErrorMessage(_L(""));
sl@0
  2214
sl@0
  2215
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  2216
        }
sl@0
  2217
    else if(aerr != KErrNone)
sl@0
  2218
        {
sl@0
  2219
        INFO_PRINTF1(HTML_GREEN);
sl@0
  2220
        INFO_PRINTF5(_L("%S: %S got expected error %d/%S"), &afnnam, &apinam,
sl@0
  2221
                              aerr, &experrS);
sl@0
  2222
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  2223
        }
sl@0
  2224
    return;
sl@0
  2225
    }
sl@0
  2226
TBool CSQLFnStep::FromConfig(const TDesC &afnnam, const TDesC &acfgblk,
sl@0
  2227
                             const TDesC &acfgname, TPtrC &acfgval)
sl@0
  2228
    {
sl@0
  2229
    if(!GetStringFromConfig(acfgblk, acfgname, acfgval))
sl@0
  2230
        {
sl@0
  2231
        INFO_PRINTF1(HTML_RED);
sl@0
  2232
        ERR_PRINTF4(_L("%S: Failed to get %S:%S parameter."), &afnnam, &acfgblk,
sl@0
  2233
                                                              &acfgname);
sl@0
  2234
        SetTestStepResult(EFail);
sl@0
  2235
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  2236
        return EFalse;
sl@0
  2237
        }
sl@0
  2238
    return ETrue;
sl@0
  2239
    }
sl@0
  2240
TBool CSQLFnStep::FromConfig(const TDesC &afnnam, const TDesC &acfgblk,
sl@0
  2241
                             const TDesC &acfgname, TInt &acfgval)
sl@0
  2242
    {
sl@0
  2243
    if(!GetIntFromConfig(acfgblk, acfgname, acfgval))
sl@0
  2244
        {
sl@0
  2245
        INFO_PRINTF1(HTML_RED);
sl@0
  2246
        ERR_PRINTF4(_L("%S: Failed to get %S:%S parameter."), &afnnam, &acfgblk,
sl@0
  2247
                           &acfgname);
sl@0
  2248
        SetTestStepResult(EFail);
sl@0
  2249
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  2250
        return EFalse;
sl@0
  2251
        }
sl@0
  2252
    return ETrue;
sl@0
  2253
    }
sl@0
  2254
TBool CSQLFnStep::FromConfig(const TDesC &afnnam, const TDesC &acfgblk,
sl@0
  2255
                             const TDesC &acfgname, TReal &acfgval)
sl@0
  2256
    {
sl@0
  2257
    TPtrC gotS;
sl@0
  2258
    if(!GetStringFromConfig(acfgblk, acfgname, gotS))
sl@0
  2259
        {
sl@0
  2260
        INFO_PRINTF1(HTML_RED);
sl@0
  2261
        ERR_PRINTF4(_L("%S: Failed to get %S:%S parameter."), &afnnam, &acfgblk,
sl@0
  2262
                                                              &acfgname);
sl@0
  2263
        SetTestStepResult(EFail);
sl@0
  2264
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  2265
        return EFalse;
sl@0
  2266
        }
sl@0
  2267
    TLex tl = gotS;
sl@0
  2268
    if(tl.Val(acfgval) != KErrNone)
sl@0
  2269
        {
sl@0
  2270
        ERR_PRINTF5(_L("%S:%S Failed to convert %S:%S to real."),
sl@0
  2271
                           &afnnam, &acfgblk, &acfgname, &gotS);
sl@0
  2272
        return EFalse;
sl@0
  2273
        }
sl@0
  2274
sl@0
  2275
    return ETrue;
sl@0
  2276
    }
sl@0
  2277
// Looking for, e.g, "9876,1234" 
sl@0
  2278
void CSQLFnStep::CommaSeparated(const TPtrC& ainp, TInt &aint, TInt &aint2)
sl@0
  2279
    {
sl@0
  2280
//    _LIT(KTestFunction, "CommaSeparated");
sl@0
  2281
sl@0
  2282
    // Read in what kind of binds we'll be doing..
sl@0
  2283
    TInt origlen = ainp.Length();
sl@0
  2284
    TChar comma(',');
sl@0
  2285
    TInt comoffset = ainp.Locate(comma);
sl@0
  2286
    if(comoffset != KErrNotFound)
sl@0
  2287
        {
sl@0
  2288
        TPtrC left = ainp.Left(comoffset);
sl@0
  2289
        TLex tl(left);
sl@0
  2290
        tl.Val(aint);
sl@0
  2291
        TInt rightlen = origlen - comoffset - 1;
sl@0
  2292
        TPtrC right = ainp.Right(rightlen);
sl@0
  2293
        tl = right;
sl@0
  2294
        tl.Val(aint2);
sl@0
  2295
        }
sl@0
  2296
    else
sl@0
  2297
        {
sl@0
  2298
        TLex tl(ainp);
sl@0
  2299
        tl.Val(aint);
sl@0
  2300
        aint2=-1;
sl@0
  2301
        }
sl@0
  2302
    }
sl@0
  2303
// Looking for, e.g, "9876,some words"
sl@0
  2304
void CSQLFnStep::CommaSeparated(const TPtrC& ainp, TInt &aint, TPtrC &astr)
sl@0
  2305
    {
sl@0
  2306
//    _LIT(KTestFunction, "CommaSeparated");
sl@0
  2307
sl@0
  2308
    TInt origlen = ainp.Length();
sl@0
  2309
    TChar comma(',');
sl@0
  2310
    TInt comoffset = ainp.Locate(comma);
sl@0
  2311
    if(comoffset != KErrNotFound)
sl@0
  2312
        {
sl@0
  2313
        TPtrC left = ainp.Left(comoffset);
sl@0
  2314
        TLex tl(left);
sl@0
  2315
        tl.Val(aint);
sl@0
  2316
        TInt rightlen = origlen - comoffset - 1;
sl@0
  2317
        astr.Set(ainp.Right(rightlen));
sl@0
  2318
        }
sl@0
  2319
    else
sl@0
  2320
        {
sl@0
  2321
        TLex tl(ainp);
sl@0
  2322
        tl.Val(aint);
sl@0
  2323
        astr.Set(_L(""));
sl@0
  2324
        }
sl@0
  2325
    }
sl@0
  2326
void CSQLFnStep::CommaSeparated(const TPtrC& ainp, TPtrC &aleft, TPtrC &aright)
sl@0
  2327
    {
sl@0
  2328
//    _LIT(KTestFunction, "CommaSeparated");
sl@0
  2329
    aleft.Set(ainp);
sl@0
  2330
    aright.Set(_L(""));
sl@0
  2331
sl@0
  2332
    TInt origlen = ainp.Length();
sl@0
  2333
    TChar comma(',');
sl@0
  2334
    TInt comoffset = ainp.Locate(comma);
sl@0
  2335
    if(comoffset != KErrNotFound)
sl@0
  2336
        {
sl@0
  2337
        aleft.Set(ainp.Left(comoffset));
sl@0
  2338
        TInt rightlen = origlen - comoffset - 1;
sl@0
  2339
        aright.Set(ainp.Right(rightlen));
sl@0
  2340
        }
sl@0
  2341
    else
sl@0
  2342
        return;
sl@0
  2343
    }
sl@0
  2344
TInt CSQLFnStep::FileSize(const TPtrC &afile)
sl@0
  2345
    {
sl@0
  2346
    // First open the file specified in the argument.
sl@0
  2347
    // This lot gets duplicated a lot.
sl@0
  2348
    RFile file;
sl@0
  2349
    TFileName fn = afile;
sl@0
  2350
    TInt err;
sl@0
  2351
    if((err = file.Open(irfs, fn, 0)) != KErrNone)
sl@0
  2352
        {
sl@0
  2353
        INFO_PRINTF1(HTML_RED);
sl@0
  2354
        ERR_PRINTF3(_L("Cannot open %S to get filesize, err %d"), &afile, err);
sl@0
  2355
        SetTestStepResult(EFail);
sl@0
  2356
        INFO_PRINTF1(HTML_COLOUR_OFF);
sl@0
  2357
sl@0
  2358
        return err;
sl@0
  2359
        }
sl@0
  2360
    TInt fsize;
sl@0
  2361
    file.Size(fsize);
sl@0
  2362
    file.Close();
sl@0
  2363
    return fsize;
sl@0
  2364
    }
sl@0
  2365