Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 5056557

Browse files
clerodawagner
authored andcommitted
libcriterion: Fix default state display for InclusiveCriterion
InclusiveCriterion has a default state called "none", this state was displayed through default Criterion behavior which is: if no valid state is available, let's display "<none>". This patch test explicitly the default value when formatting the state of an InclusiveCriterion. It also introduces the test getLiteralValue return when formatting a standard Criterion rather than testing the generated string emptiness. A difference can now be made between an inclusive criterion default value and an exclusive criterion with an unknown state. Signed-off-by: Jules Clero <julesx.clero@intel.com>
1 parent 8807207 commit 5056557

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

parameter/criterion/include/criterion/Criterion.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,6 @@ class Criterion : public IXmlSource, public CriterionInterface
137137
const ValuePairs& derivedValuePairs,
138138
const MatchMethods& derivedMatchMethods);
139139

140-
/** Set a "default formatted state" when no criterion state is set
141-
*
142-
* @param formattedState, the formatted state string to check
143-
* @result the reference of the string passed in parameter filled with the default value
144-
* if it was empty
145-
*
146-
* This method returns a reference on his referenced parameter in order to have the easy
147-
* notation.
148-
* return checkFormattedStateEmptyness(myFormattedStateToReturn);
149-
*/
150-
std::string& checkFormattedStateEmptyness(std::string& formattedState) const;
151-
152140
/** Contains pair association between literal and numerical value */
153141
ValuePairs mValuePairs;
154142

parameter/criterion/src/Criterion.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,10 @@ bool Criterion::getLiteralValue(int numericalValue, std::string& literalValue) c
221221
std::string Criterion::getFormattedState() const
222222
{
223223
std::string formattedState;
224-
getLiteralValue(mState, formattedState);
225-
226-
return Criterion::checkFormattedStateEmptyness(formattedState);
224+
if (!getLiteralValue(mState, formattedState)) {
225+
formattedState = "<none>";
226+
}
227+
return formattedState;
227228
}
228229

229230
std::string Criterion::listPossibleValues() const
@@ -246,14 +247,6 @@ std::string Criterion::listPossibleValues() const
246247
return possibleValues;
247248
}
248249

249-
std::string& Criterion::checkFormattedStateEmptyness(std::string& formattedState) const
250-
{
251-
if (formattedState.empty()) {
252-
formattedState = "<none>";
253-
}
254-
return formattedState;
255-
}
256-
257250
bool Criterion::match(const std::string& method, int32_t state) const
258251
{
259252
return mMatchMethods.at(method)(state);

parameter/criterion/src/InclusiveCriterion.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "Tokenizer.h"
3232

3333
#include <sstream>
34+
#include <cassert>
3435

3536
namespace core
3637
{
@@ -92,6 +93,12 @@ bool InclusiveCriterion::getNumericalValue(const std::string& literalValue,
9293
std::string InclusiveCriterion::getFormattedState() const
9394
{
9495
std::string formattedState;
96+
if (mState == 0) {
97+
// Default inclusive criterion state is always present
98+
getLiteralValue(0, formattedState);
99+
return formattedState;
100+
}
101+
95102
uint32_t bit;
96103
bool first = true;
97104

@@ -117,8 +124,7 @@ std::string InclusiveCriterion::getFormattedState() const
117124

118125
formattedState += atomicState;
119126
}
120-
121-
return Criterion::checkFormattedStateEmptyness(formattedState);
127+
return formattedState;
122128
}
123129

124130
} /** criterion namespace */

0 commit comments

Comments
 (0)