Mock implementation of an option storage class for unit testing.
Provides facilities for checking that correct methods are called, and for controlling how they add values using the base class methods.
|
| MockOptionStorage (const MockOption &settings) |
| Initializes the storage from option settings. More...
|
|
void | addDummyValue () |
| Calls addValue("dummy") in the base class.
|
|
void | markAsSet () |
| Marks the option as set. More...
|
|
void | addValue (const std::string &value) |
| Adds a value to a temporary storage. More...
|
|
void | commitValues () |
| Commits values added with addValue(). More...
|
|
virtual gmx::OptionInfo & | optionInfo () |
| Returns an option info object corresponding to this option.
|
|
virtual std::string | typeString () const |
| Returns a short string describing the type of the option.
|
|
virtual std::string | formatSingleValue (const std::string &) const |
| Formats a single value as a string. More...
|
|
virtual int | valueCount () const |
| Returns the number of option values added so far. More...
|
|
virtual std::string | formatValue (int i) const |
| Returns the i'th value formatted as a string. More...
|
|
bool | isSet () const |
| Returns true if the option has been set.
|
|
bool | isBoolean () const |
| Returns true if the option is a boolean option. More...
|
|
bool | isHidden () const |
| Returns true if the option is a hidden option.
|
|
bool | isRequired () const |
| Returns true if the option is required.
|
|
bool | isVector () const |
| Returns true if the option is vector-valued.
|
|
const std::string & | name () const |
| Returns the name of the option.
|
|
const std::string & | description () const |
| Returns the description of the option set by the calling code.
|
|
bool | defaultValueIfSetExists () const |
| Returns true if defaultValueIfSet() value is specified.
|
|
int | minValueCount () const |
| Returns the minimum number of values required in one set.
|
|
int | maxValueCount () const |
| Returns the maximum allowed number of values in one set (-1 = no limit).
|
|
virtual std::string | formatExtraDescription () const |
| Formats additional description for the option. More...
|
|
std::string | formatDefaultValueIfSet () const |
| Returns the default value if set for the option as a string. More...
|
|
void | startSource () |
| Starts adding values from a new source for the option. More...
|
|
void | startSet () |
| Starts adding a new set of values for the option. More...
|
|
void | appendValue (const std::string &value) |
| Adds a new value for the option, converting it from a string. More...
|
|
void | finishSet () |
| Performs validation and/or actions once a set of values has been added. More...
|
|
void | finish () |
| Performs validation and/or actions once all values have been added. More...
|
|
void anonymous_namespace{abstractoptionstorage.cpp}::MockOptionStorage::addValue |
( |
const std::string & |
value | ) |
|
|
inline |
Adds a value to a temporary storage.
- Parameters
-
[in] | value | Value to add. A copy is made. |
- Exceptions
-
std::bad_alloc | if out of memory. |
InvalidInputError | if the maximum value count has been reached. |
Derived classes should call this function from the convertValue() implementation to add converted values to the storage. If the maximum value count has been reached, the value is discarded and an exception is thrown.
If adding values outside convertValue() (e.g., to set a custom default value), derived classes should call clearSet() before adding values (unless in the constructor) and commitValues() once all values are added.
void anonymous_namespace{abstractoptionstorage.cpp}::MockOptionStorage::commitValues |
( |
| ) |
|
|
inline |
Commits values added with addValue().
- Exceptions
-
std::bad_alloc | if out of memory. |
If this function succeeds, values added with addValue() since the previous clearSet() are added to the storage for the option. Only throws in out-of-memory conditions, and provides the strong exception safety guarantee as long as the copy constructor of T
does not throw.
See addValue() for cases where this method should be used in derived classes.
Calls refreshValues() and clearSet() if it is successful.