diff options
author | Kevin Rocard <kevinx.rocard@intel.com> | 2012-08-21 18:52:17 +0200 |
---|---|---|
committer | David Wagner <david.wagner@intel.com> | 2014-02-12 17:03:13 +0100 |
commit | 997e709c17c6b19459db698f10c0fe60d393bdaa (patch) | |
tree | b4422b6b955a0cd22fedcba98c4525e44c3b9981 /test | |
parent | 326a31df0dd401283de6170ed09bcf605f61ef7d (diff) | |
download | external_parameter-framework-997e709c17c6b19459db698f10c0fe60d393bdaa.zip external_parameter-framework-997e709c17c6b19459db698f10c0fe60d393bdaa.tar.gz external_parameter-framework-997e709c17c6b19459db698f10c0fe60d393bdaa.tar.bz2 |
PFW: setCriterionState now support lexical state
BZ: 54174
If the test-platform setCriterionState command is unable to convert the supply state to integer,
it tries to consider it as a lexical state.
Before
setCriterionState SelectedOutputDevice 0x3
After
setCriterionState SelectedOutputDevice IHF Headset
Change-Id: Ib981eb955afd2acfa6e3d60d11828fcc4fc8860a
Signed-off-by: Kevin Rocard <kevinx.rocard@intel.com>
Reviewed-on: http://android.intel.com:8080/63478
Reviewed-by: Baron, Georges-henriX <georges-henrix.baron@intel.com>
Reviewed-by: Boisnard, FredericX <fredericx.boisnard@intel.com>
Reviewed-by: Benavoli, Patrick <patrick.benavoli@intel.com>
Reviewed-by: Denneulin, Guillaume <guillaume.denneulin@intel.com>
Reviewed-by: De Chivre, Renaud <renaud.de.chivre@intel.com>
Tested-by: Barthes, FabienX <fabienx.barthes@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/test-platform/TestPlatform.cpp | 82 | ||||
-rw-r--r-- | test/test-platform/TestPlatform.h | 1 |
2 files changed, 82 insertions, 1 deletions
diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index fea7506..fff0a8d 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -30,6 +30,7 @@ #include "TestPlatform.h" #include "ParameterMgrPlatformConnector.h" #include "RemoteProcessorServer.h" +#include <errno.h> class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnector::ILogger { @@ -118,7 +119,29 @@ CTestPlatform::CCommandHandler::CommandStatus CTestPlatform::startParameterMgrCo CTestPlatform::CCommandHandler::CommandStatus CTestPlatform::setCriterionStateCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - return setCriterionState(remoteCommand.getArgument(0), strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), strResult) ? CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; + + bool bSuccess; + + const char * pcState = remoteCommand.getArgument(1).c_str(); + + char *pcStrEnd; + + // Reset errno to check if it is updated during the conversion (strtol/strtoul) + errno = 0; + + uint32_t state = strtoul(pcState , &pcStrEnd, 0); + + if (!errno && (*pcStrEnd == '\0')) { + // Sucessfull conversion, set criterion state by numerical state + bSuccess = setCriterionState(remoteCommand.getArgument(0), state , strResult ) ; + + } else { + // Conversion failed, set criterion state by lexical state + bSuccess = setCriterionStateByLexicalSpace(remoteCommand , strResult ); + } + + return bSuccess ? CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; + } CTestPlatform::CCommandHandler::CommandStatus CTestPlatform::applyConfigurationsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) @@ -270,3 +293,60 @@ bool CTestPlatform::setCriterionState(const string& strName, uint32_t uiState, s return true; } +bool CTestPlatform::setCriterionStateByLexicalSpace(const IRemoteCommand& remoteCommand, string& strResult) +{ + + // Get criterion name + std::string strCriterionName = remoteCommand.getArgument(0); + + ISelectionCriterionInterface* pCriterion = _pParameterMgrPlatformConnector->getSelectionCriterion(strCriterionName); + + if (!pCriterion) { + + strResult = "Unable to retrieve selection criterion: " + strCriterionName; + + return false; + } + + // Get criterion type + const ISelectionCriterionTypeInterface* pCriterionType = pCriterion->getCriterionType(); + + // Get substate number, the first argument (index 0) is the criterion name + uint32_t uiNbSubStates = remoteCommand.getArgumentCount() - 1; + + // Check that exclusive criterion has only one substate + if (!pCriterionType->isTypeInclusive() && uiNbSubStates != 1) { + + strResult = "Exclusive criterion " + strCriterionName + " can only have one state"; + + return false; + } + + /// Translate lexical state to numerical state + uint32_t uiNumericalState = 0; + uint32_t uiLexicalSubStateIndex; + + // Parse lexical substates + for (uiLexicalSubStateIndex = 1; uiLexicalSubStateIndex <= uiNbSubStates; uiLexicalSubStateIndex++) { + + int iNumericalSubState; + + const std::string& strLexicalSubState = remoteCommand.getArgument(uiLexicalSubStateIndex); + + // Translate lexical to numerical substate + if (!pCriterionType->getNumericalValue(strLexicalSubState, iNumericalSubState)) { + + strResult = "Unable to find lexical state \"" + strLexicalSubState + "\" in criteria " + strCriterionName; + + return false; + } + + // Aggregate numerical substates + uiNumericalState |= iNumericalSubState; + } + + // Set criterion new state + pCriterion->setCriterionState(uiNumericalState); + + return true; +} diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index 9f3dca3..566fdc8 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -64,6 +64,7 @@ private: bool createExclusiveSelectionCriterion(const string& strName, uint32_t uiNbValues, string& strResult); bool createInclusiveSelectionCriterion(const string& strName, uint32_t uiNbValues, string& strResult); bool setCriterionState(const string& strName, uint32_t uiState, string& strResult); + bool setCriterionStateByLexicalSpace(const IRemoteCommand& remoteCommand, string& strResult); // Connector CParameterMgrPlatformConnector* _pParameterMgrPlatformConnector; |