I'm writing a roboter controller class Controller in which I'm using a struct Axis for each of the 4 controllable motors.
For each test I want to reset everything, so I created a pointer in the class which is changed to a new Controller before each test method. The initialisation works fine in TEST_METHOD_INITIALIZE, but once any TEST_METHOD is called the program seems reset the Axis pointers.
Thanks for your help!
Edit: After further analysis I have the theory, that the initialised Axis objects Axis init_mx are deleted after the method is finished.
Edit2: I think this a slightly more complex problem like this: Pointer to local variable in C++ Nevertheless, I didn't find a way to reset the Axis variables at for every method without actually resetting each variable in it.
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
...
namespace UnitTest
{
TEST_CLASS(UnitTestController)
{
public:
Controller* controller;
struct Axis *mx, *my, *mz, *mg;
TEST_METHOD_INITIALIZE(methodName)
{
Axis init_mx(50), init_my(50), init_mz(50), init_mg(5);
mx = &init_mx;
my = &init_my;
mz = &init_mz;
mg = &init_mg;
Controller init_controller(mx, my, mz, mg);
controller = &init_controller;
}
...
TEST_METHOD(id_3_next_mode)
{
mx->position = 5;
controller->getAxisPositionMx();
//Axis in pointers got reset and therefore have no pointers to the
//provided structs from TEST_METHOD_INITIALIZE
}
}
};
}
private:
struct Axis *mx, *my, *mz, *mg;
Controller.cpp (excerpt)
Controller::Controller(Axis *mx_in, Axis *my_in, Axis *mz_in, Axis *mg_in)
{
mx = mx_in;
my = my_in;
mz = mz_in;
mg = mg_in;
}