os/mm/mmhais/dvbhunittest/hai/dvbh/src/dvbhhaitestutil.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-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
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @internalComponent
sl@0
    19
 @prototype
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "dvbhhaitestutil.h"
sl@0
    23
sl@0
    24
const TUid KDvbhPropertyCategory = 
sl@0
    25
	{
sl@0
    26
	0x101f45ef //TestFramework's UID3
sl@0
    27
	};
sl@0
    28
sl@0
    29
struct TDvbhProperty
sl@0
    30
	{
sl@0
    31
	TInt iKey;
sl@0
    32
	TInt iType;
sl@0
    33
	};
sl@0
    34
		
sl@0
    35
const TUint KNumDvbhProperties = 8;
sl@0
    36
const TDvbhProperty KDvbhProperties[] =
sl@0
    37
	{
sl@0
    38
	{EDvbhPropertyKeyState, RProperty::EInt},
sl@0
    39
	{EDvbhPropertyKeyPlatform, RProperty::EByteArray},
sl@0
    40
	{EDvbhPropertyKeyNetworkTime, RProperty::EByteArray},
sl@0
    41
	{EDvbhPropertyKeyPerformanceData, RProperty::EByteArray},
sl@0
    42
	{EDvbhPropertyKeyFrequency, RProperty::EInt},
sl@0
    43
	{EDvbhPropertyKeyNetworkId, RProperty::EInt},
sl@0
    44
	{EDvbhPropertyKeySignalQuality, RProperty::EInt}, 
sl@0
    45
	{EDvbhPropertyKeyCellId, RProperty::EInt}
sl@0
    46
	};
sl@0
    47
	
sl@0
    48
TInt CDvbhTestUtil::GetKey(TDvbhPropertyKey aKey)
sl@0
    49
	{
sl@0
    50
	return KDvbhProperties[aKey].iKey;
sl@0
    51
	}
sl@0
    52
	
sl@0
    53
TInt CDvbhTestUtil::GetType(TDvbhPropertyKey aKey)
sl@0
    54
	{
sl@0
    55
	return KDvbhProperties[aKey].iType;
sl@0
    56
	}
sl@0
    57
	
sl@0
    58
CDvbhTestUtil::CDvbhTestUtil(MDvbhHaiTestLoggerInterface& aTestStepLogger)
sl@0
    59
: iTestStepLogger(aTestStepLogger)
sl@0
    60
	{
sl@0
    61
	}
sl@0
    62
	
sl@0
    63
CDvbhTestUtil* CDvbhTestUtil::NewL(MDvbhHaiTestLoggerInterface& aTestStepLogger)
sl@0
    64
	{
sl@0
    65
	CDvbhTestUtil* self = new (ELeave) CDvbhTestUtil(aTestStepLogger);
sl@0
    66
	return self;
sl@0
    67
	}
sl@0
    68
	
sl@0
    69
TInt CDvbhTestUtil::DefineDvbhProperty(TInt aPropertyKey, TInt aType) const
sl@0
    70
	{
sl@0
    71
	TInt err = RProperty::Define(KDvbhPropertyCategory, aPropertyKey, aType);
sl@0
    72
	if (err != KErrAlreadyExists && err != KErrNone)
sl@0
    73
	    {
sl@0
    74
	    iTestStepLogger.InfoPrintf3(_L("Error %d defining property %d"), err, aPropertyKey);
sl@0
    75
	    return err;
sl@0
    76
	    }
sl@0
    77
	else
sl@0
    78
		{
sl@0
    79
		err = KErrNone;
sl@0
    80
		}
sl@0
    81
    return err;	
sl@0
    82
	}
sl@0
    83
sl@0
    84
TInt CDvbhTestUtil::DefineDvbhProperty(TInt aPropertyKey, TInt aType, const TDesC8& aInitialValue) const
sl@0
    85
	{
sl@0
    86
	TInt err = DefineDvbhProperty(aPropertyKey, aType);
sl@0
    87
	if (err != KErrNone)
sl@0
    88
		{
sl@0
    89
		return err;
sl@0
    90
		}
sl@0
    91
	return SetByteArrayProperty(aPropertyKey, aInitialValue);
sl@0
    92
	}
sl@0
    93
	
sl@0
    94
TInt CDvbhTestUtil::DeleteDvbhProperty(TInt aPropertyKey)
sl@0
    95
	{
sl@0
    96
	TInt err = RProperty::Delete(KDvbhPropertyCategory, aPropertyKey);
sl@0
    97
	if (err != KErrNone && err != KErrNotFound)
sl@0
    98
	    {
sl@0
    99
	    iTestStepLogger.InfoPrintf3(_L("Error %d deleting property %d"), err, aPropertyKey);
sl@0
   100
	    }
sl@0
   101
	else
sl@0
   102
		{
sl@0
   103
		err = KErrNone;
sl@0
   104
		}
sl@0
   105
	return err;
sl@0
   106
	}
sl@0
   107
sl@0
   108
TInt CDvbhTestUtil::SetByteArrayProperty(TInt aPropertyKey, const TDesC8& aValue) const
sl@0
   109
	{
sl@0
   110
	TInt result = RProperty::Set(KDvbhPropertyCategory, aPropertyKey, aValue);
sl@0
   111
	if (result != KErrNone)
sl@0
   112
		{
sl@0
   113
		iTestStepLogger.InfoPrintf3(_L("Error %d setting the byte array property with key %d."), result, aPropertyKey);
sl@0
   114
		}
sl@0
   115
	return result;
sl@0
   116
	}
sl@0
   117
	
sl@0
   118
TInt CDvbhTestUtil::SetIntegerProperty(TInt aPropertyKey, TInt aValue) const
sl@0
   119
	{
sl@0
   120
	TInt result = RProperty::Set(KDvbhPropertyCategory, aPropertyKey, aValue);
sl@0
   121
	if (result != KErrNone)
sl@0
   122
		{
sl@0
   123
		iTestStepLogger.InfoPrintf4(_L("Error %d setting the integer property with key %d to %d"), result, aPropertyKey, aValue);
sl@0
   124
		}
sl@0
   125
	return result;		
sl@0
   126
	}
sl@0
   127
sl@0
   128
TInt CDvbhTestUtil::DefineDvbhStateProperty(TInt aInitialState)
sl@0
   129
	{
sl@0
   130
	TInt result = DefineDvbhProperty(EDvbhPropertyKeyState, KDvbhProperties[EDvbhPropertyKeyState].iType);
sl@0
   131
	if (result == KErrNone && aInitialState != ENoInitialState)
sl@0
   132
		{
sl@0
   133
		result = SetStateProperty(aInitialState);	
sl@0
   134
		}
sl@0
   135
	return result;
sl@0
   136
	}
sl@0
   137
	
sl@0
   138
TInt CDvbhTestUtil::DefineDvbhIntegerProperty(TInt aPropertyKey, TInt aInitialValue) const
sl@0
   139
	{
sl@0
   140
	TInt result = DefineDvbhProperty(aPropertyKey, KDvbhProperties[aPropertyKey].iType);
sl@0
   141
	if (result == KErrNone)
sl@0
   142
		{
sl@0
   143
		result = SetIntegerProperty(aPropertyKey, aInitialValue);	
sl@0
   144
		}
sl@0
   145
	return result;	
sl@0
   146
	}
sl@0
   147
	
sl@0
   148
TInt CDvbhTestUtil::SetStateProperty(TInt aValue)
sl@0
   149
	{
sl@0
   150
	TInt result = SetIntegerProperty(EDvbhPropertyKeyState, aValue);
sl@0
   151
	if (result != KErrNone)
sl@0
   152
		{
sl@0
   153
		iTestStepLogger.InfoPrintf3(_L("Error %d setting state property to %d"), result, aValue);
sl@0
   154
		}
sl@0
   155
	return result;
sl@0
   156
	}
sl@0
   157
	
sl@0
   158
TInt CDvbhTestUtil::DefineAllDvbhProperties()
sl@0
   159
	{
sl@0
   160
	for (TUint i=0;i<KNumDvbhProperties;++i)
sl@0
   161
		{
sl@0
   162
		const TDvbhProperty property = KDvbhProperties[i];
sl@0
   163
		TInt defineResult = DefineDvbhProperty(property.iKey, property.iType);
sl@0
   164
		if (defineResult != KErrNone)
sl@0
   165
			{
sl@0
   166
		    iTestStepLogger.InfoPrintf3(_L("Error %d defining property number %d"), defineResult, i);
sl@0
   167
			DeleteAllDvbhProperties();
sl@0
   168
			return defineResult;
sl@0
   169
			}
sl@0
   170
		}
sl@0
   171
	return KErrNone;
sl@0
   172
	}
sl@0
   173
	
sl@0
   174
TInt CDvbhTestUtil::DeleteAllDvbhProperties()
sl@0
   175
	{
sl@0
   176
	TInt result = KErrNone;
sl@0
   177
	for (TUint i=0;i<KNumDvbhProperties;++i)
sl@0
   178
		{
sl@0
   179
		const TDvbhProperty property = KDvbhProperties[i];
sl@0
   180
		TInt deleteResult = DeleteDvbhProperty(property.iKey);
sl@0
   181
		if (deleteResult != KErrNone)
sl@0
   182
			{
sl@0
   183
		    result = deleteResult;
sl@0
   184
			}
sl@0
   185
		}
sl@0
   186
	return result;	
sl@0
   187
	}
sl@0
   188
	
sl@0
   189
TBool CDvbhTestUtil::CompareVersions(const TVersion& aVersion1, const TVersion& aVersion2)
sl@0
   190
	{
sl@0
   191
	return (aVersion1.iMinor == aVersion2.iMinor &&
sl@0
   192
			aVersion1.iMajor == aVersion2.iMajor &&
sl@0
   193
			aVersion1.iBuild == aVersion2.iBuild);
sl@0
   194
	}
sl@0
   195
sl@0
   196
TBool CDvbhTestUtil::ComparePlatforms(const TDvbhPlatform& aPlatform1, const TDvbhPlatform& aPlatform2)
sl@0
   197
	{
sl@0
   198
	return (aPlatform1.iId == aPlatform2.iId &&
sl@0
   199
			aPlatform1.iName.Compare(aPlatform2.iName) == 0); // Compare returns 0 if they are the same
sl@0
   200
	}
sl@0
   201
sl@0
   202
TBool CDvbhTestUtil::ComparePerformanceDatas(const TDvbhPerformanceData& aData1, const TDvbhPerformanceData& aData2)
sl@0
   203
	{
sl@0
   204
	return (aData1.iFilterCount == aData2.iFilterCount &&
sl@0
   205
			aData1.iMaxFilters == aData2.iMaxFilters &&
sl@0
   206
			aData1.iDataCount == aData2.iDataCount &&
sl@0
   207
			aData1.iWriteCount == aData2.iWriteCount &&
sl@0
   208
			aData1.iWriteCommandCount == aData2.iWriteCommandCount &&
sl@0
   209
			aData1.iReadCount == aData2.iReadCount &&
sl@0
   210
			aData1.iReadCommandCount == aData2.iReadCommandCount);
sl@0
   211
	}
sl@0
   212
		
sl@0
   213
TBool CDvbhTestUtil::CompareScanConfigurations(const TDvbhScanConfiguration& aConfig1, const TDvbhScanConfiguration& aConfig2)
sl@0
   214
	{
sl@0
   215
	return (aConfig1.iScanStartFrequency == aConfig2.iScanStartFrequency &&
sl@0
   216
			aConfig1.iScanEndFrequency == aConfig2.iScanEndFrequency &&
sl@0
   217
			aConfig1.iSignalBandwidth == aConfig2.iSignalBandwidth &&
sl@0
   218
			aConfig1.iScanOptions == aConfig2.iScanOptions );
sl@0
   219
	}
sl@0
   220
sl@0
   221
sl@0
   222