Variables and constants of enum types can be handled with a dedicated set of API macros. The macros can report enum values using enumeration identifiers, rather than plain integral numbers. The following API macros can be used to handle enum values:
<scoped enum name> is full name of enumeration, including all namespace names. For example: INNER_NS::MyEnumeration, INNER_NS::MyClass::MyEnumeration,
<value string> is a string that describes the reported value,
<value> is an integral value or enumerator,
<expected> is an integral value or enumerator.
The API macros presented above require the “Enable enum data autogeneration” test configuration option to be enabled. Go to Test Configuration > Execution tab > General tab > Instrumentation mode > Edit > Instrumentation features > Advanced options to configure this option.
You can specify values inside the Test Case Editor’s Parameters table using identifiers of enumerators. Press CTRL+SPACE for a list of known enumerators.
By default, only enumerators defined in the project are shown when CTRL+SPACE is pressed. To show enumerators defined outside of the project, open the project properties, go to Parasoft > C++test > Other Settings and provide the advanced option(s):
xharness.dumpEnumsFromFile <PATH>, where <PATH> is a disk location of sources that define enumerations. Wildcard * can be used while specifying the path. Multiple entries of the
xharness.dumpEnumsFromFile <PATH> option are allowed.
The following example shows the Parameters step with enumeration identifiers:
You also can use enumeration identifiers in data sources. The following example shows an extract from a CSV file:
"Input","Output" MON,TUE TUE,WED WED,THU
A simple enumerator name or a full name that includes all name spaces can be used. For example, if the MON enumerator is defined in ::INNER_NS::MyClass::DaysEnumeration, you can type either MON or ::INNER_NS::MyClass::MON.
Use the following helper macro to to extract an enum value from a data source or the Parameters step:
CPPTEST_DS_GET_ENUM(<scoped enum name>, <column name>)
The following example shows a simple example of extracting the enum value from a data source: