os/persistentdata/persistentstorage/sql/TEST/testexecute/SQLite/src/hashing.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.
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "hashing.h"
    17 #include "sqlfn.h"
    18 #include "cdtest.h"
    19 #include <sqldb.h>
    20 
    21 //
    22 // This code is for setting up and accessing hashes. These are used within
    23 // the test harness to associate a word (for example "KErrNone") with an
    24 // integer value (0 in this case). The base class CSQLHashUtil contains the
    25 // accessor and destructor methods which do 99% of the work. All of the
    26 // other classes merely contain constructors to set up their hashes.
    27 //
    28 
    29 // Basic functionality first...
    30 TPtrC* CSQLHashUtil::GetStringFromNum(TInt aErrNum)
    31     {
    32     return ihash.Find(aErrNum);
    33     }
    34 
    35 TInt CSQLHashUtil::GetNumFromString(TPtrC aErrMsg)
    36     {
    37     THashMapIter<TInt, TPtrC> it(ihash);
    38     it.NextValue();
    39     while (it.CurrentValue())
    40         {
    41         if (*it.CurrentValue() == aErrMsg)
    42             return *it.CurrentKey();
    43         it.NextValue();
    44         }
    45     return (KErrNotFound);
    46     }
    47 
    48 CSQLHashUtil::~CSQLHashUtil()
    49     {
    50     while(ihash.Count())
    51         {
    52         THashMapIter<TInt, TPtrC> it(ihash);
    53         const TInt *curkey = it.NextKey();
    54         ihash.Remove(*curkey);
    55         }
    56     }
    57 
    58 // Now setup OS errors..
    59 CSQLOsErrHash::CSQLOsErrHash()
    60     {
    61     // error codes from e32err.h
    62     ihash.Insert(KErrNone, _L("KErrNone"));
    63     ihash.Insert(KErrNotFound, _L("KErrNotFound"));
    64     ihash.Insert(KErrGeneral, _L("KErrGeneral"));
    65     ihash.Insert(KErrCancel, _L("KErrCancel"));
    66     ihash.Insert(KErrNoMemory, _L("KErrNoMemory"));
    67     ihash.Insert(KErrNotSupported, _L("KErrNotSupported"));
    68     ihash.Insert(KErrArgument, _L("KErrArgument"));
    69     ihash.Insert(KErrTotalLossOfPrecision, _L("KErrTotalLossOfPrecision"));
    70     ihash.Insert(KErrBadHandle, _L("KErrBadHandle"));
    71     ihash.Insert(KErrOverflow, _L("KErrOverflow"));
    72     ihash.Insert(KErrUnderflow, _L("KErrUnderflow"));
    73     ihash.Insert(KErrAlreadyExists, _L("KErrAlreadyExists"));
    74     ihash.Insert(KErrPathNotFound, _L("KErrPathNotFound"));
    75     ihash.Insert(KErrDied, _L("KErrDied"));
    76     ihash.Insert(KErrInUse, _L("KErrInUse"));
    77     ihash.Insert(KErrServerTerminated, _L("KErrServerTerminated"));
    78     ihash.Insert(KErrServerBusy, _L("KErrServerBusy"));
    79     ihash.Insert(KErrCompletion, _L("KErrCompletion"));
    80     ihash.Insert(KErrNotReady, _L("KErrNotReady"));
    81     ihash.Insert(KErrUnknown, _L("KErrUnknown"));
    82     ihash.Insert(KErrCorrupt, _L("KErrCorrupt"));
    83     ihash.Insert(KErrAccessDenied, _L("KErrAccessDenied"));
    84     ihash.Insert(KErrLocked, _L("KErrLocked"));
    85     ihash.Insert(KErrWrite, _L("KErrWrite"));
    86     ihash.Insert(KErrDisMounted, _L("KErrDisMounted"));
    87     ihash.Insert(KErrEof, _L("KErrEof"));
    88     ihash.Insert(KErrDiskFull, _L("KErrDiskFull"));
    89     ihash.Insert(KErrBadDriver, _L("KErrBadDriver"));
    90     ihash.Insert(KErrBadName, _L("KErrBadName"));
    91     ihash.Insert(KErrCommsLineFail, _L("KErrCommsLineFail"));
    92     ihash.Insert(KErrCommsFrame, _L("KErrCommsFrame"));
    93     ihash.Insert(KErrCommsOverrun, _L("KErrCommsOverrun"));
    94     ihash.Insert(KErrCommsParity, _L("KErrCommsParity"));
    95     ihash.Insert(KErrTimedOut, _L("KErrTimedOut"));
    96     ihash.Insert(KErrCouldNotConnect, _L("KErrCouldNotConnect"));
    97     ihash.Insert(KErrCouldNotDisconnect, _L("KErrCouldNotDisconnect"));
    98     ihash.Insert(KErrDisconnected, _L("KErrDisconnected"));
    99     ihash.Insert(KErrBadLibraryEntryPoint, _L("KErrBadLibraryEntryPoint"));
   100     ihash.Insert(KErrBadDescriptor, _L("KErrBadDescriptor"));
   101     ihash.Insert(KErrAbort, _L("KErrAbort"));
   102     ihash.Insert(KErrTooBig, _L("KErrTooBig"));
   103     ihash.Insert(KErrDivideByZero, _L("KErrDivideByZero"));
   104     ihash.Insert(KErrBadPower, _L("KErrBadPower"));
   105     ihash.Insert(KErrDirFull, _L("KErrDirFull"));
   106     ihash.Insert(KErrHardwareNotAvailable, _L("KErrHardwareNotAvailable"));
   107     ihash.Insert(KErrSessionClosed, _L("KErrSessionClosed"));
   108     ihash.Insert(KErrPermissionDenied, _L("KErrPermissionDenied"));
   109     ihash.Insert(KErrExtensionNotSupported, _L("KErrExtensionNotSupported"));
   110     TInt err = ihash.Insert(KErrCommsBreak, _L("KErrCommsBreak"));
   111     if( err == KErrNone )
   112         return;
   113     User::Panic(_L("Unable to create OS error hash"), 1411);
   114     }
   115     
   116 // Now setup SQL errors..
   117 CSQLErrHash::CSQLErrHash()
   118     {
   119     // error codes from sqldb.h
   120     ihash.Insert(KSqlErrGeneral, _L("KSqlErrGeneral"));
   121     ihash.Insert(KSqlErrInternal, _L("KSqlErrInternal"));
   122     ihash.Insert(KSqlErrPermission, _L("KSqlErrPermission"));
   123     ihash.Insert(KSqlErrAbort, _L("KSqlErrAbort"));
   124     ihash.Insert(KSqlErrBusy, _L("KSqlErrBusy"));
   125     ihash.Insert(KSqlErrLocked, _L("KSqlErrLocked"));
   126     ihash.Insert(KSqlErrReadOnly, _L("KSqlErrReadOnly"));
   127     ihash.Insert(KSqlErrInterrupt, _L("KSqlErrInterrupt"));
   128     ihash.Insert(KSqlErrIO, _L("KSqlErrIO"));
   129     ihash.Insert(KSqlErrCorrupt, _L("KSqlErrCorrupt"));
   130     ihash.Insert(KSqlErrNotFound, _L("KSqlErrNotFound"));
   131     ihash.Insert(KSqlErrFull, _L("KSqlErrFull"));
   132     ihash.Insert(KSqlErrCantOpen, _L("KSqlErrCantOpen"));
   133     ihash.Insert(KSqlErrProtocol, _L("KSqlErrProtocol"));
   134     ihash.Insert(KSqlErrEmpty, _L("KSqlErrEmpty"));
   135     ihash.Insert(KSqlErrSchema, _L("KSqlErrSchema"));
   136     ihash.Insert(KSqlErrTooBig, _L("KSqlErrTooBig"));
   137     ihash.Insert(KSqlErrConstraint, _L("KSqlErrConstraint"));
   138     ihash.Insert(KSqlErrMismatch, _L("KSqlErrMismatch"));
   139     ihash.Insert(KSqlErrMisuse, _L("KSqlErrMisuse"));
   140     ihash.Insert(KSqlErrRange, _L("KSqlErrRange"));
   141     ihash.Insert(KSqlErrNotDb, _L("KSqlErrNotDb"));
   142     ihash.Insert(KSqlErrStmtExpired, _L("KSqlErrStmtExpired"));
   143     // The last two aren't strictly errors, but it is convenient to treat
   144     // them as such to process the output from RSqlStatement::Next().
   145     ihash.Insert(KSqlAtRow, _L("KSqlAtRow"));
   146     TInt err = ihash.Insert(KSqlAtEnd, _L("KSqlAtEnd"));
   147     if( err == KErrNone )
   148         return;
   149     User::Panic(_L("Unable to create SQL error hash"), 1412);
   150     }
   151 
   152 // Now do the SQL enumerations.. 
   153 CSQLColTypeHash::CSQLColTypeHash()
   154     {
   155     // Enumerations for sqldb.h
   156     ihash.Insert(ESqlNull, _L("ESqlNull"));
   157     ihash.Insert(ESqlInt, _L("ESqlInt"));
   158     ihash.Insert(ESqlInt64, _L("ESqlInt64"));
   159     ihash.Insert(ESqlReal, _L("ESqlReal"));
   160     ihash.Insert(ESqlText, _L("ESqlText"));
   161     ihash.Insert(ESqlBinary, _L("ESqlBinary"));
   162     TInt err = ihash.Insert(ESqlNull, _L("ESqlNull"));
   163     if( err == KErrNone )
   164         return;
   165 
   166     User::Panic(_L("Unable to create column type hash"), 1413);
   167     }
   168 
   169 // Now do the enumerations for all of the functions in sqlfn..
   170 CSQLTEFAction::CSQLTEFAction()
   171     {
   172     // Enumerations from sqlfn.h
   173     ihash.Insert(CSQLFnStep::Efn_undefined, _L("fn_undefined"));
   174     ihash.Insert(CSQLFnStep::Efn_nop, _L("NoOperation"));
   175     ihash.Insert(CSQLFnStep::Efn_create, _L("Create"));
   176     ihash.Insert(CSQLFnStep::Efn_createl, _L("CreateL"));
   177     ihash.Insert(CSQLFnStep::Efn_createsp, _L("CreateSP"));
   178     ihash.Insert(CSQLFnStep::Efn_open, _L("Open"));
   179     ihash.Insert(CSQLFnStep::Efn_openl, _L("OpenL"));
   180     ihash.Insert(CSQLFnStep::Efn_attach, _L("Attach"));
   181     ihash.Insert(CSQLFnStep::Efn_detach, _L("Detach"));
   182     ihash.Insert(CSQLFnStep::Efn_copy, _L("Copy"));
   183     ihash.Insert(CSQLFnStep::Efn_delete, _L("Delete"));
   184     ihash.Insert(CSQLFnStep::Efn_close, _L("Close"));
   185     ihash.Insert(CSQLFnStep::Efn_exec, _L("Exec"));
   186     ihash.Insert(CSQLFnStep::Efn_setisolationlevel, _L("SetIsolationLevel"));
   187     ihash.Insert(CSQLFnStep::Efn_lasterrormessage, _L("LastErrorMessage"));
   188     ihash.Insert(CSQLFnStep::Efn_reservedrivespace, _L("ReserveDriveSpace"));
   189     ihash.Insert(CSQLFnStep::Efn_freereservedspace, _L("FreeReservedSpace"));
   190     ihash.Insert(CSQLFnStep::Efn_getreserveaccess, _L("GetReserveAccess"));
   191     ihash.Insert(CSQLFnStep::Efn_releasereserveaccess, _L("ReleaseReserveAccess"));
   192     ihash.Insert(CSQLFnStep::Erstmt_prepare, _L("Prepare"));
   193     ihash.Insert(CSQLFnStep::Erstmt_preparel, _L("PrepareL"));
   194     ihash.Insert(CSQLFnStep::Erstmt_close, _L("St_Close"));
   195     ihash.Insert(CSQLFnStep::Erstmt_atrow, _L("AtRow"));
   196     ihash.Insert(CSQLFnStep::Erstmt_reset, _L("Reset"));
   197     ihash.Insert(CSQLFnStep::Erstmt_exec, _L("St_Exec"));
   198     ihash.Insert(CSQLFnStep::Erstmt_next, _L("Next"));
   199     ihash.Insert(CSQLFnStep::Erstmt_paramindex, _L("ParameterIndex"));
   200     ihash.Insert(CSQLFnStep::Erstmt_colindex, _L("ColumnIndex"));
   201     ihash.Insert(CSQLFnStep::Erstmt_coltype, _L("ColumnType"));
   202     ihash.Insert(CSQLFnStep::Erstmt_colsize, _L("ColumnSize"));
   203     ihash.Insert(CSQLFnStep::Erstmt_bindnull, _L("BindNull"));
   204     ihash.Insert(CSQLFnStep::Erstmt_bindint, _L("BindInt"));
   205     ihash.Insert(CSQLFnStep::Erstmt_bindint64, _L("BindInt64_"));
   206     ihash.Insert(CSQLFnStep::Erstmt_bindreal, _L("BindReal"));
   207     ihash.Insert(CSQLFnStep::Erstmt_bindtext, _L("BindText"));
   208     ihash.Insert(CSQLFnStep::Erstmt_bindbigtext, _L("BindTextFromFile"));
   209     ihash.Insert(CSQLFnStep::Erstmt_bindbinary, _L("BindBinary"));
   210     ihash.Insert(CSQLFnStep::Erstmt_isnull, _L("IsNull"));
   211     ihash.Insert(CSQLFnStep::Erstmt_colint, _L("ColumnInt"));
   212     ihash.Insert(CSQLFnStep::Erstmt_colint64, _L("ColumnInt64_"));
   213     ihash.Insert(CSQLFnStep::Erstmt_colreal, _L("ColumnReal"));
   214     ihash.Insert(CSQLFnStep::Erstmt_coltextL, _L("ColumnTextL"));
   215     ihash.Insert(CSQLFnStep::Erstmt_coltextP, _L("ColumnTextP"));
   216     ihash.Insert(CSQLFnStep::Erstmt_coltextD, _L("ColumnTextD"));
   217     ihash.Insert(CSQLFnStep::Erstmt_colbinL, _L("ColumnBinaryL"));
   218     ihash.Insert(CSQLFnStep::Erstmt_colbinP, _L("ColumnBinaryP"));
   219     ihash.Insert(CSQLFnStep::Erstmt_colbinD, _L("ColumnBinaryD"));
   220     ihash.Insert(CSQLFnStep::Esp_create, _L("SPCreate"));
   221     ihash.Insert(CSQLFnStep::Esp_createl, _L("SPCreateL"));
   222     ihash.Insert(CSQLFnStep::Esp_close, _L("SPClose"));
   223     ihash.Insert(CSQLFnStep::Esp_setdbpolicy, _L("SetDBPolicy"));
   224     ihash.Insert(CSQLFnStep::Esp_setpolicy, _L("SetPolicy"));
   225     ihash.Insert(CSQLFnStep::Esp_externalizel, _L("SPExternalizeL"));
   226     ihash.Insert(CSQLFnStep::Esp_internalizel, _L("SPInternalizeL"));
   227     ihash.Insert(CSQLFnStep::Estreamwrite_bindtext, _L("StreamWriteBindText"));
   228     ihash.Insert(CSQLFnStep::Estreamwrite_bindbinary, _L("StreamWriteBindBin"));
   229     ihash.Insert(CSQLFnStep::Estreamread_columntext, _L("StreamReadColText"));
   230     ihash.Insert(CSQLFnStep::Estreamread_columnbinary, _L("StreamReadColBin"));
   231     ihash.Insert(CSQLFnStep::Edefineconfig, _L("DefineConfig"));
   232     ihash.Insert(CSQLFnStep::Ectrl_newblock, _L("NewBlock"));
   233     ihash.Insert(CSQLFnStep::Ectrl_function, _L("Function"));
   234     ihash.Insert(CSQLFnStep::Ectrl_waitA, _L("WaitA"));
   235     ihash.Insert(CSQLFnStep::Ectrl_signalA, _L("SignalA"));
   236     ihash.Insert(CSQLFnStep::Ectrl_waitB, _L("WaitB"));
   237     ihash.Insert(CSQLFnStep::Ectrl_signalB, _L("SignalB"));
   238     ihash.Insert(CSQLFnStep::Ectrl_sleep, _L("Sleep"));
   239     ihash.Insert(CSQLFnStep::Ectrl_eightbit, _L("EightBit"));
   240     ihash.Insert(CSQLFnStep::Ectrl_async, _L("Async"));
   241     TInt err = ihash.Insert(CSQLFnStep::Ectrl_endblock, _L("EndBlock"));
   242     if( err == KErrNone )
   243         return;
   244 
   245     User::Panic(_L("Unable to create action hash"), 1414);
   246     }
   247 
   248 CSQLCapability::CSQLCapability()
   249 	{
   250     ihash.Insert(ECapabilityTCB, _L("ECapabilityTCB"));
   251     ihash.Insert(ECapabilityCommDD, _L("ECapabilityCommDD"));
   252     ihash.Insert(ECapabilityPowerMgmt, _L("ECapabilityPowerMgmt"));
   253     ihash.Insert(ECapabilityMultimediaDD, _L("ECapabilityMultimediaDD"));
   254     ihash.Insert(ECapabilityReadDeviceData, _L("ECapabilityReadDeviceData"));
   255     ihash.Insert(ECapabilityWriteDeviceData, _L("ECapabilityWriteDeviceData"));
   256     ihash.Insert(ECapabilityDRM, _L("ECapabilityDRM"));
   257 	ihash.Insert(ECapabilityTrustedUI, _L("ECapabilityTrustedUI"));
   258     ihash.Insert(ECapabilityProtServ, _L("ECapabilityProtServ"));
   259     ihash.Insert(ECapabilityDiskAdmin, _L("ECapabilityDiskAdmin"));
   260     ihash.Insert(ECapabilityNetworkControl, _L("ECapabilityNetworkControl"));
   261     ihash.Insert(ECapabilityAllFiles, _L("ECapabilityAllFiles"));
   262     ihash.Insert(ECapabilitySwEvent, _L("ECapabilitySwEvent"));
   263     ihash.Insert(ECapabilityNetworkServices, _L("ECapabilityNetworkServices"));
   264     ihash.Insert(ECapabilityLocalServices, _L("ECapabilityLocalServices"));
   265     ihash.Insert(ECapabilityReadUserData, _L("ECapabilityReadUserData"));
   266     ihash.Insert(ECapabilityWriteUserData, _L("ECapabilityWriteUserData"));
   267     ihash.Insert(ECapabilityLocation, _L("ECapabilityLocation"));
   268     ihash.Insert(ECapabilitySurroundingsDD, _L("ECapabilitySurroundingsDD"));
   269     ihash.Insert(ECapabilityUserEnvironment, _L("ECapabilityUserEnvironment"));
   270     ihash.Insert(ECapability_Limit, _L("ECapability_Limit"));
   271     ihash.Insert(ECapability_HardLimit, _L("ECapability_HardLimit"));
   272     ihash.Insert(ECapability_None, _L("ECapability_None"));
   273     TInt err = ihash.Insert(ECapability_Denied, _L("ECapability_Denied"));
   274     if( err == KErrNone )
   275         return;
   276 
   277     User::Panic(_L("Unable to create capability hash"), 1414);
   278     }
   279 
   280 CSQLPolicy::CSQLPolicy()
   281 	{
   282 	ihash.Insert(RSqlSecurityPolicy::ESchemaPolicy, _L("ESchemaPolicy"));
   283     ihash.Insert(RSqlSecurityPolicy::EReadPolicy, _L("EReadPolicy"));
   284     TInt err = ihash.Insert(RSqlSecurityPolicy::EWritePolicy, _L("EWritePolicy"));
   285     if( err == KErrNone )
   286         return;
   287 
   288     User::Panic(_L("Unable to create SQL policy hash"), 1414);
   289 	}
   290 
   291 CSQLObject::CSQLObject()
   292 	{
   293 	TInt err = ihash.Insert(RSqlSecurityPolicy::ETable, _L("ETable"));
   294     if( err == KErrNone )
   295         return;
   296 
   297     User::Panic(_L("Unable to create SQL policy hash"), 1414);
   298 	}
   299 
   300 CSQLSFSTEFAction::CSQLSFSTEFAction()
   301     {
   302     ihash.Insert(ESFS_SelectIntL, _L("SelectIntL"));
   303     ihash.Insert(ESFS_SelectInt64L, _L("SelectInt64L"));
   304     ihash.Insert(ESFS_SelectRealL, _L("SelectRealL"));
   305     ihash.Insert(ESFS_SelectTextL, _L("SelectTextL"));
   306 
   307     TInt err = ihash.Insert(ESFS_SelectBinaryL, _L("SelectBinaryL"));
   308     if( err == KErrNone )
   309         return;
   310 
   311     User::Panic(_L("Unable to create action hash"), 1414);
   312     }
   313