* Test the abstract state machine. */
| 212 | * Test the abstract state machine. |
| 213 | */ |
| 214 | static void testStateMachine() |
| 215 | { |
| 216 | TestState stateA; |
| 217 | TestState stateB; |
| 218 | StateMachine sm; |
| 219 | |
| 220 | /* State machine has no state yet. */ |
| 221 | TEST_ASSERT_NULL(sm.getState()); |
| 222 | |
| 223 | /* Add state A, but don't process it. */ |
| 224 | sm.setState(stateA); |
| 225 | TEST_ASSERT_NULL(sm.getState()); |
| 226 | TEST_ASSERT_EQUAL_UINT32(0u, stateA.getCallCntEntry()); |
| 227 | TEST_ASSERT_EQUAL_UINT32(0u, stateA.getCallCntExit()); |
| 228 | |
| 229 | /* Process it once. |
| 230 | * Expectation: |
| 231 | * The entry part is called once and the process part. |
| 232 | */ |
| 233 | sm.process(); |
| 234 | TEST_ASSERT_EQUAL_UINT32(1u, stateA.getCallCntEntry()); |
| 235 | TEST_ASSERT_EQUAL_UINT32(0u, stateA.getCallCntExit()); |
| 236 | TEST_ASSERT_EQUAL_PTR(static_cast<AbstractState*>(&stateA), sm.getState()); |
| 237 | |
| 238 | /* Process it a 2nd time. |
| 239 | * Expectation: |
| 240 | * Only the process part is called. |
| 241 | */ |
| 242 | sm.process(); |
| 243 | TEST_ASSERT_EQUAL_UINT32(1u, stateA.getCallCntEntry()); |
| 244 | TEST_ASSERT_EQUAL_UINT32(0u, stateA.getCallCntExit()); |
| 245 | |
| 246 | /* Transistion from A to B. */ |
| 247 | stateA.setState(stateB); |
| 248 | sm.process(); |
| 249 | sm.process(); |
| 250 | TEST_ASSERT_EQUAL_UINT32(1u, stateA.getCallCntEntry()); |
| 251 | TEST_ASSERT_EQUAL_UINT32(1u, stateA.getCallCntExit()); |
| 252 | TEST_ASSERT_EQUAL_UINT32(1u, stateB.getCallCntEntry()); |
| 253 | TEST_ASSERT_EQUAL_UINT32(0u, stateB.getCallCntExit()); |
| 254 | |
| 255 | /* Transistion from B to A. */ |
| 256 | stateB.setState(stateA); |
| 257 | sm.process(); |
| 258 | sm.process(); |
| 259 | TEST_ASSERT_EQUAL_UINT32(2u, stateA.getCallCntEntry()); |
| 260 | TEST_ASSERT_EQUAL_UINT32(1u, stateA.getCallCntExit()); |
| 261 | TEST_ASSERT_EQUAL_UINT32(1u, stateB.getCallCntEntry()); |
| 262 | TEST_ASSERT_EQUAL_UINT32(1u, stateB.getCallCntExit()); |
| 263 | } |
nothing calls this directly
no test coverage detected