sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "hashing.h" sl@0: #include "sqlfn.h" sl@0: #include "cdtest.h" sl@0: #include sl@0: sl@0: // sl@0: // This code is for setting up and accessing hashes. These are used within sl@0: // the test harness to associate a word (for example "KErrNone") with an sl@0: // integer value (0 in this case). The base class CSQLHashUtil contains the sl@0: // accessor and destructor methods which do 99% of the work. All of the sl@0: // other classes merely contain constructors to set up their hashes. sl@0: // sl@0: sl@0: // Basic functionality first... sl@0: TPtrC* CSQLHashUtil::GetStringFromNum(TInt aErrNum) sl@0: { sl@0: return ihash.Find(aErrNum); sl@0: } sl@0: sl@0: TInt CSQLHashUtil::GetNumFromString(TPtrC aErrMsg) sl@0: { sl@0: THashMapIter it(ihash); sl@0: it.NextValue(); sl@0: while (it.CurrentValue()) sl@0: { sl@0: if (*it.CurrentValue() == aErrMsg) sl@0: return *it.CurrentKey(); sl@0: it.NextValue(); sl@0: } sl@0: return (KErrNotFound); sl@0: } sl@0: sl@0: CSQLHashUtil::~CSQLHashUtil() sl@0: { sl@0: while(ihash.Count()) sl@0: { sl@0: THashMapIter it(ihash); sl@0: const TInt *curkey = it.NextKey(); sl@0: ihash.Remove(*curkey); sl@0: } sl@0: } sl@0: sl@0: // Now setup OS errors.. sl@0: CSQLOsErrHash::CSQLOsErrHash() sl@0: { sl@0: // error codes from e32err.h sl@0: ihash.Insert(KErrNone, _L("KErrNone")); sl@0: ihash.Insert(KErrNotFound, _L("KErrNotFound")); sl@0: ihash.Insert(KErrGeneral, _L("KErrGeneral")); sl@0: ihash.Insert(KErrCancel, _L("KErrCancel")); sl@0: ihash.Insert(KErrNoMemory, _L("KErrNoMemory")); sl@0: ihash.Insert(KErrNotSupported, _L("KErrNotSupported")); sl@0: ihash.Insert(KErrArgument, _L("KErrArgument")); sl@0: ihash.Insert(KErrTotalLossOfPrecision, _L("KErrTotalLossOfPrecision")); sl@0: ihash.Insert(KErrBadHandle, _L("KErrBadHandle")); sl@0: ihash.Insert(KErrOverflow, _L("KErrOverflow")); sl@0: ihash.Insert(KErrUnderflow, _L("KErrUnderflow")); sl@0: ihash.Insert(KErrAlreadyExists, _L("KErrAlreadyExists")); sl@0: ihash.Insert(KErrPathNotFound, _L("KErrPathNotFound")); sl@0: ihash.Insert(KErrDied, _L("KErrDied")); sl@0: ihash.Insert(KErrInUse, _L("KErrInUse")); sl@0: ihash.Insert(KErrServerTerminated, _L("KErrServerTerminated")); sl@0: ihash.Insert(KErrServerBusy, _L("KErrServerBusy")); sl@0: ihash.Insert(KErrCompletion, _L("KErrCompletion")); sl@0: ihash.Insert(KErrNotReady, _L("KErrNotReady")); sl@0: ihash.Insert(KErrUnknown, _L("KErrUnknown")); sl@0: ihash.Insert(KErrCorrupt, _L("KErrCorrupt")); sl@0: ihash.Insert(KErrAccessDenied, _L("KErrAccessDenied")); sl@0: ihash.Insert(KErrLocked, _L("KErrLocked")); sl@0: ihash.Insert(KErrWrite, _L("KErrWrite")); sl@0: ihash.Insert(KErrDisMounted, _L("KErrDisMounted")); sl@0: ihash.Insert(KErrEof, _L("KErrEof")); sl@0: ihash.Insert(KErrDiskFull, _L("KErrDiskFull")); sl@0: ihash.Insert(KErrBadDriver, _L("KErrBadDriver")); sl@0: ihash.Insert(KErrBadName, _L("KErrBadName")); sl@0: ihash.Insert(KErrCommsLineFail, _L("KErrCommsLineFail")); sl@0: ihash.Insert(KErrCommsFrame, _L("KErrCommsFrame")); sl@0: ihash.Insert(KErrCommsOverrun, _L("KErrCommsOverrun")); sl@0: ihash.Insert(KErrCommsParity, _L("KErrCommsParity")); sl@0: ihash.Insert(KErrTimedOut, _L("KErrTimedOut")); sl@0: ihash.Insert(KErrCouldNotConnect, _L("KErrCouldNotConnect")); sl@0: ihash.Insert(KErrCouldNotDisconnect, _L("KErrCouldNotDisconnect")); sl@0: ihash.Insert(KErrDisconnected, _L("KErrDisconnected")); sl@0: ihash.Insert(KErrBadLibraryEntryPoint, _L("KErrBadLibraryEntryPoint")); sl@0: ihash.Insert(KErrBadDescriptor, _L("KErrBadDescriptor")); sl@0: ihash.Insert(KErrAbort, _L("KErrAbort")); sl@0: ihash.Insert(KErrTooBig, _L("KErrTooBig")); sl@0: ihash.Insert(KErrDivideByZero, _L("KErrDivideByZero")); sl@0: ihash.Insert(KErrBadPower, _L("KErrBadPower")); sl@0: ihash.Insert(KErrDirFull, _L("KErrDirFull")); sl@0: ihash.Insert(KErrHardwareNotAvailable, _L("KErrHardwareNotAvailable")); sl@0: ihash.Insert(KErrSessionClosed, _L("KErrSessionClosed")); sl@0: ihash.Insert(KErrPermissionDenied, _L("KErrPermissionDenied")); sl@0: ihash.Insert(KErrExtensionNotSupported, _L("KErrExtensionNotSupported")); sl@0: TInt err = ihash.Insert(KErrCommsBreak, _L("KErrCommsBreak")); sl@0: if( err == KErrNone ) sl@0: return; sl@0: User::Panic(_L("Unable to create OS error hash"), 1411); sl@0: } sl@0: sl@0: // Now setup SQL errors.. sl@0: CSQLErrHash::CSQLErrHash() sl@0: { sl@0: // error codes from sqldb.h sl@0: ihash.Insert(KSqlErrGeneral, _L("KSqlErrGeneral")); sl@0: ihash.Insert(KSqlErrInternal, _L("KSqlErrInternal")); sl@0: ihash.Insert(KSqlErrPermission, _L("KSqlErrPermission")); sl@0: ihash.Insert(KSqlErrAbort, _L("KSqlErrAbort")); sl@0: ihash.Insert(KSqlErrBusy, _L("KSqlErrBusy")); sl@0: ihash.Insert(KSqlErrLocked, _L("KSqlErrLocked")); sl@0: ihash.Insert(KSqlErrReadOnly, _L("KSqlErrReadOnly")); sl@0: ihash.Insert(KSqlErrInterrupt, _L("KSqlErrInterrupt")); sl@0: ihash.Insert(KSqlErrIO, _L("KSqlErrIO")); sl@0: ihash.Insert(KSqlErrCorrupt, _L("KSqlErrCorrupt")); sl@0: ihash.Insert(KSqlErrNotFound, _L("KSqlErrNotFound")); sl@0: ihash.Insert(KSqlErrFull, _L("KSqlErrFull")); sl@0: ihash.Insert(KSqlErrCantOpen, _L("KSqlErrCantOpen")); sl@0: ihash.Insert(KSqlErrProtocol, _L("KSqlErrProtocol")); sl@0: ihash.Insert(KSqlErrEmpty, _L("KSqlErrEmpty")); sl@0: ihash.Insert(KSqlErrSchema, _L("KSqlErrSchema")); sl@0: ihash.Insert(KSqlErrTooBig, _L("KSqlErrTooBig")); sl@0: ihash.Insert(KSqlErrConstraint, _L("KSqlErrConstraint")); sl@0: ihash.Insert(KSqlErrMismatch, _L("KSqlErrMismatch")); sl@0: ihash.Insert(KSqlErrMisuse, _L("KSqlErrMisuse")); sl@0: ihash.Insert(KSqlErrRange, _L("KSqlErrRange")); sl@0: ihash.Insert(KSqlErrNotDb, _L("KSqlErrNotDb")); sl@0: ihash.Insert(KSqlErrStmtExpired, _L("KSqlErrStmtExpired")); sl@0: // The last two aren't strictly errors, but it is convenient to treat sl@0: // them as such to process the output from RSqlStatement::Next(). sl@0: ihash.Insert(KSqlAtRow, _L("KSqlAtRow")); sl@0: TInt err = ihash.Insert(KSqlAtEnd, _L("KSqlAtEnd")); sl@0: if( err == KErrNone ) sl@0: return; sl@0: User::Panic(_L("Unable to create SQL error hash"), 1412); sl@0: } sl@0: sl@0: // Now do the SQL enumerations.. sl@0: CSQLColTypeHash::CSQLColTypeHash() sl@0: { sl@0: // Enumerations for sqldb.h sl@0: ihash.Insert(ESqlNull, _L("ESqlNull")); sl@0: ihash.Insert(ESqlInt, _L("ESqlInt")); sl@0: ihash.Insert(ESqlInt64, _L("ESqlInt64")); sl@0: ihash.Insert(ESqlReal, _L("ESqlReal")); sl@0: ihash.Insert(ESqlText, _L("ESqlText")); sl@0: ihash.Insert(ESqlBinary, _L("ESqlBinary")); sl@0: TInt err = ihash.Insert(ESqlNull, _L("ESqlNull")); sl@0: if( err == KErrNone ) sl@0: return; sl@0: sl@0: User::Panic(_L("Unable to create column type hash"), 1413); sl@0: } sl@0: sl@0: // Now do the enumerations for all of the functions in sqlfn.. sl@0: CSQLTEFAction::CSQLTEFAction() sl@0: { sl@0: // Enumerations from sqlfn.h sl@0: ihash.Insert(CSQLFnStep::Efn_undefined, _L("fn_undefined")); sl@0: ihash.Insert(CSQLFnStep::Efn_nop, _L("NoOperation")); sl@0: ihash.Insert(CSQLFnStep::Efn_create, _L("Create")); sl@0: ihash.Insert(CSQLFnStep::Efn_createl, _L("CreateL")); sl@0: ihash.Insert(CSQLFnStep::Efn_createsp, _L("CreateSP")); sl@0: ihash.Insert(CSQLFnStep::Efn_open, _L("Open")); sl@0: ihash.Insert(CSQLFnStep::Efn_openl, _L("OpenL")); sl@0: ihash.Insert(CSQLFnStep::Efn_attach, _L("Attach")); sl@0: ihash.Insert(CSQLFnStep::Efn_detach, _L("Detach")); sl@0: ihash.Insert(CSQLFnStep::Efn_copy, _L("Copy")); sl@0: ihash.Insert(CSQLFnStep::Efn_delete, _L("Delete")); sl@0: ihash.Insert(CSQLFnStep::Efn_close, _L("Close")); sl@0: ihash.Insert(CSQLFnStep::Efn_exec, _L("Exec")); sl@0: ihash.Insert(CSQLFnStep::Efn_setisolationlevel, _L("SetIsolationLevel")); sl@0: ihash.Insert(CSQLFnStep::Efn_lasterrormessage, _L("LastErrorMessage")); sl@0: ihash.Insert(CSQLFnStep::Efn_reservedrivespace, _L("ReserveDriveSpace")); sl@0: ihash.Insert(CSQLFnStep::Efn_freereservedspace, _L("FreeReservedSpace")); sl@0: ihash.Insert(CSQLFnStep::Efn_getreserveaccess, _L("GetReserveAccess")); sl@0: ihash.Insert(CSQLFnStep::Efn_releasereserveaccess, _L("ReleaseReserveAccess")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_prepare, _L("Prepare")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_preparel, _L("PrepareL")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_close, _L("St_Close")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_atrow, _L("AtRow")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_reset, _L("Reset")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_exec, _L("St_Exec")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_next, _L("Next")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_paramindex, _L("ParameterIndex")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_colindex, _L("ColumnIndex")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_coltype, _L("ColumnType")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_colsize, _L("ColumnSize")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_bindnull, _L("BindNull")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_bindint, _L("BindInt")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_bindint64, _L("BindInt64_")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_bindreal, _L("BindReal")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_bindtext, _L("BindText")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_bindbigtext, _L("BindTextFromFile")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_bindbinary, _L("BindBinary")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_isnull, _L("IsNull")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_colint, _L("ColumnInt")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_colint64, _L("ColumnInt64_")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_colreal, _L("ColumnReal")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_coltextL, _L("ColumnTextL")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_coltextP, _L("ColumnTextP")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_coltextD, _L("ColumnTextD")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_colbinL, _L("ColumnBinaryL")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_colbinP, _L("ColumnBinaryP")); sl@0: ihash.Insert(CSQLFnStep::Erstmt_colbinD, _L("ColumnBinaryD")); sl@0: ihash.Insert(CSQLFnStep::Esp_create, _L("SPCreate")); sl@0: ihash.Insert(CSQLFnStep::Esp_createl, _L("SPCreateL")); sl@0: ihash.Insert(CSQLFnStep::Esp_close, _L("SPClose")); sl@0: ihash.Insert(CSQLFnStep::Esp_setdbpolicy, _L("SetDBPolicy")); sl@0: ihash.Insert(CSQLFnStep::Esp_setpolicy, _L("SetPolicy")); sl@0: ihash.Insert(CSQLFnStep::Esp_externalizel, _L("SPExternalizeL")); sl@0: ihash.Insert(CSQLFnStep::Esp_internalizel, _L("SPInternalizeL")); sl@0: ihash.Insert(CSQLFnStep::Estreamwrite_bindtext, _L("StreamWriteBindText")); sl@0: ihash.Insert(CSQLFnStep::Estreamwrite_bindbinary, _L("StreamWriteBindBin")); sl@0: ihash.Insert(CSQLFnStep::Estreamread_columntext, _L("StreamReadColText")); sl@0: ihash.Insert(CSQLFnStep::Estreamread_columnbinary, _L("StreamReadColBin")); sl@0: ihash.Insert(CSQLFnStep::Edefineconfig, _L("DefineConfig")); sl@0: ihash.Insert(CSQLFnStep::Ectrl_newblock, _L("NewBlock")); sl@0: ihash.Insert(CSQLFnStep::Ectrl_function, _L("Function")); sl@0: ihash.Insert(CSQLFnStep::Ectrl_waitA, _L("WaitA")); sl@0: ihash.Insert(CSQLFnStep::Ectrl_signalA, _L("SignalA")); sl@0: ihash.Insert(CSQLFnStep::Ectrl_waitB, _L("WaitB")); sl@0: ihash.Insert(CSQLFnStep::Ectrl_signalB, _L("SignalB")); sl@0: ihash.Insert(CSQLFnStep::Ectrl_sleep, _L("Sleep")); sl@0: ihash.Insert(CSQLFnStep::Ectrl_eightbit, _L("EightBit")); sl@0: ihash.Insert(CSQLFnStep::Ectrl_async, _L("Async")); sl@0: TInt err = ihash.Insert(CSQLFnStep::Ectrl_endblock, _L("EndBlock")); sl@0: if( err == KErrNone ) sl@0: return; sl@0: sl@0: User::Panic(_L("Unable to create action hash"), 1414); sl@0: } sl@0: sl@0: CSQLCapability::CSQLCapability() sl@0: { sl@0: ihash.Insert(ECapabilityTCB, _L("ECapabilityTCB")); sl@0: ihash.Insert(ECapabilityCommDD, _L("ECapabilityCommDD")); sl@0: ihash.Insert(ECapabilityPowerMgmt, _L("ECapabilityPowerMgmt")); sl@0: ihash.Insert(ECapabilityMultimediaDD, _L("ECapabilityMultimediaDD")); sl@0: ihash.Insert(ECapabilityReadDeviceData, _L("ECapabilityReadDeviceData")); sl@0: ihash.Insert(ECapabilityWriteDeviceData, _L("ECapabilityWriteDeviceData")); sl@0: ihash.Insert(ECapabilityDRM, _L("ECapabilityDRM")); sl@0: ihash.Insert(ECapabilityTrustedUI, _L("ECapabilityTrustedUI")); sl@0: ihash.Insert(ECapabilityProtServ, _L("ECapabilityProtServ")); sl@0: ihash.Insert(ECapabilityDiskAdmin, _L("ECapabilityDiskAdmin")); sl@0: ihash.Insert(ECapabilityNetworkControl, _L("ECapabilityNetworkControl")); sl@0: ihash.Insert(ECapabilityAllFiles, _L("ECapabilityAllFiles")); sl@0: ihash.Insert(ECapabilitySwEvent, _L("ECapabilitySwEvent")); sl@0: ihash.Insert(ECapabilityNetworkServices, _L("ECapabilityNetworkServices")); sl@0: ihash.Insert(ECapabilityLocalServices, _L("ECapabilityLocalServices")); sl@0: ihash.Insert(ECapabilityReadUserData, _L("ECapabilityReadUserData")); sl@0: ihash.Insert(ECapabilityWriteUserData, _L("ECapabilityWriteUserData")); sl@0: ihash.Insert(ECapabilityLocation, _L("ECapabilityLocation")); sl@0: ihash.Insert(ECapabilitySurroundingsDD, _L("ECapabilitySurroundingsDD")); sl@0: ihash.Insert(ECapabilityUserEnvironment, _L("ECapabilityUserEnvironment")); sl@0: ihash.Insert(ECapability_Limit, _L("ECapability_Limit")); sl@0: ihash.Insert(ECapability_HardLimit, _L("ECapability_HardLimit")); sl@0: ihash.Insert(ECapability_None, _L("ECapability_None")); sl@0: TInt err = ihash.Insert(ECapability_Denied, _L("ECapability_Denied")); sl@0: if( err == KErrNone ) sl@0: return; sl@0: sl@0: User::Panic(_L("Unable to create capability hash"), 1414); sl@0: } sl@0: sl@0: CSQLPolicy::CSQLPolicy() sl@0: { sl@0: ihash.Insert(RSqlSecurityPolicy::ESchemaPolicy, _L("ESchemaPolicy")); sl@0: ihash.Insert(RSqlSecurityPolicy::EReadPolicy, _L("EReadPolicy")); sl@0: TInt err = ihash.Insert(RSqlSecurityPolicy::EWritePolicy, _L("EWritePolicy")); sl@0: if( err == KErrNone ) sl@0: return; sl@0: sl@0: User::Panic(_L("Unable to create SQL policy hash"), 1414); sl@0: } sl@0: sl@0: CSQLObject::CSQLObject() sl@0: { sl@0: TInt err = ihash.Insert(RSqlSecurityPolicy::ETable, _L("ETable")); sl@0: if( err == KErrNone ) sl@0: return; sl@0: sl@0: User::Panic(_L("Unable to create SQL policy hash"), 1414); sl@0: } sl@0: sl@0: CSQLSFSTEFAction::CSQLSFSTEFAction() sl@0: { sl@0: ihash.Insert(ESFS_SelectIntL, _L("SelectIntL")); sl@0: ihash.Insert(ESFS_SelectInt64L, _L("SelectInt64L")); sl@0: ihash.Insert(ESFS_SelectRealL, _L("SelectRealL")); sl@0: ihash.Insert(ESFS_SelectTextL, _L("SelectTextL")); sl@0: sl@0: TInt err = ihash.Insert(ESFS_SelectBinaryL, _L("SelectBinaryL")); sl@0: if( err == KErrNone ) sl@0: return; sl@0: sl@0: User::Panic(_L("Unable to create action hash"), 1414); sl@0: } sl@0: