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