...
Code Block | ||
---|---|---|
| ||
#pragma once #include "attitudeStateManager.hpp" class attitudeManager { public: attitudeManager(); inline attitudeState* getCurrentState() const {return currentState;} void execute(); void setState(attitudeState& newState); private: attitudeState* currentState; }; |
...
Ok, so where do we start ? At the beginning. We know from our architecture that the state machine needs to be in the “fetchInstructionsMode” state. So the first unit test should just be creating an attitudeManager object and checking to see wether it’s in this state right after it’s created. That looks like this:
(Don’t be bothered of pointer de-referencing or the calling of the getInstance method, these are just the way we chose to implement things as part of our architecture. How you choose to do design module is up to you)
...
Code Block | ||
---|---|---|
| ||
TEST(AttitudeManagerFSM, InitialStateIsFetchInstructions) {
/***********************SETUP***********************/
attitudeManager attMng;
/********************DEPENDENCIES*******************/
/********************STEPTHROUGH********************/
/**********************ASSERTS**********************/
ASSERT_EQ(*(attMng.getCurrentState()), fetchInstructionsMode::getInstance());
}
|
(Don’t be bothered of pointer de-referencing or the calling of the getInstance method, these are just the way we chose to implement things as part of our architecture. How you choose to do design module is up to you)
So there’s a very simple test. If you ruin the unit tests (with ./Tools/build.bash -t), you’l notice things won’t compile. Makes sense, since we don’t actually have any code implemented. So let’s write the constructor of this class and the getCurrentState methods:
In attitudeManager.cpp:
Code Block | ||
---|---|---|
| ||
attitudeManager::attitudeManager()
{
}
|
This time, when you run the unit tests, you’l notice it fails. So now let’s write the code to allow it to pass:
Code Block | ||
---|---|---|
| ||
attitudeManager::attitudeManager()
{
currentState = &fetchInstructionsMode::getInstance();
}
|
An now, when we run the unit tests, we will see everything passes! This new test will run everytime you run all the other tests, and eventually when things get merged, Everytime someone pushes to our repo. What it’s done is give us insurance forever that whatever happens, attitudeManager objects always start in the “fetchInstructionsmode” state.