With Isolator++ Professional, you can access any data member of your classes, regardless of their access modifier.
This includes private and protected members, as well as static variables. This feature allows you to write more robust tests since modifying the access modifier of a variable will not affect your test logic.
Set member value:
To set a member variable's value in a test, use the following syntax:
auto a = Isolator();
a.Variable.Set(A::Member(<instance>, <member>), <value>);
Example:
a.Variable.Set(A::Member(&person, m_id), 10);
Get member value:
To retrieve a member variable’s value, use the following syntax:
a.Variable.Get<type>(A::Member(<instance>, <member>));
Example:
int memberValue = a.Variable.Get<int>(A::Member(person, m_id));
Note: When retrieving an array value, no copy is made. Instead, a pointer to the array is returned. The best practice is to use a pointer:
int* arr = a.Variable.Get<int *>(A::Member(&person, m_array));
Static Data Members
To access static data members use A::Global.
Example setting std::map member:
std::map<int,mytype> myMap;
myMap[0] = mytype{0};
a.Variable.Set(A::Global(Person::m_static), myMap);
and
auto memberValue = a.Variable.Get<std::map<int,mytype>)(A::Global(Person::m_static));
Static Variables
Static Data Members
To access static variable, use A::Global.
Example:
a.Variable.Set(A::Global(staticVariable), 10);
and
int value = a.Variable.Get<int>(A::Global(staticVariable));
|