main.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * main.c
  3. *
  4. * Created on: 16.11.2011
  5. * Author: showcase
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <assert.h>
  10. #include <string.h>
  11. #include "Timer.h"
  12. #include "DummyTimer.h"
  13. #include "Test_TransitionStatemachine.h"
  14. /*@DTestSuite: Hierachy Statechart Test (Test_Transition.sct) */
  15. #define MAXEVENTSPERTYPE 4
  16. const char* stateName[6] = {"State1", "State2", "State3", "State4", "State5", "State6"};
  17. void setupStatemachine(Test_TransitionStatemachine* machine, Timer* dummyTimer, EventPool* eventPool)
  18. {
  19. /* set up dummy Timer */
  20. dummyTimer_init(dummyTimer);
  21. /* Set up Event Pool */
  22. test_Transition_eventPool_init_heap(eventPool, MAXEVENTSPERTYPE);
  23. /* initialize state machine */
  24. test_TransitionStatemachine_init(machine, dummyTimer, eventPool);
  25. /* call all necessary enter functions */
  26. test_TransitionStatemachine_enter(machine);
  27. }
  28. void teardownStatemachine(Test_TransitionStatemachine* machine, Timer* dummyTimer, EventPool* eventPool)
  29. {
  30. /* call all exit actions for this state machine */
  31. test_TransitionStatemachine_exit(machine);
  32. /* free all internal memory for this state machine */
  33. test_TransitionStatemachine_destruct(machine);
  34. /* free the timer */
  35. timer_exit(dummyTimer);
  36. /* free all events in the event pool */
  37. eventPool_exit(eventPool);
  38. }
  39. /*@Test: test_default_var1 test behavior of var1 in default interface */
  40. int test_initialization()
  41. {
  42. return 0;
  43. }
  44. /*@Test: test_state9_state10_transition test behavior of var1 in default and other interface */
  45. int test_state9_state10_transition()
  46. {
  47. Test_TransitionStatemachine machine;
  48. Timer dummyTimer;
  49. EventPool eventPool;
  50. /*@Desc: setup initial statemachine */
  51. setupStatemachine(&machine, &dummyTimer, &eventPool);
  52. /*@Desc: run the statechart for the first time (initially) */
  53. test_TransitionStatemachine_runCycle(&machine);
  54. /*@Desc: teardown statemachine */
  55. teardownStatemachine(&machine, &dummyTimer, &eventPool);
  56. return 0;
  57. }
  58. /*@Test: test_default_var1 test behavior of var1 in default and other interface */
  59. int test_state1_state2_back_transition()
  60. {
  61. Test_TransitionStatemachine machine;
  62. Timer dummyTimer;
  63. EventPool eventPool;
  64. /*@Desc: setup initial statemachine */
  65. setupStatemachine(&machine, &dummyTimer, &eventPool);
  66. /*@Desc: run an explicit cycle - without any waiting event (for initialization) */
  67. test_TransitionStatemachine_runCycle(&machine);
  68. /*@Desc: */
  69. /*@Desc: teardown statemachine */
  70. teardownStatemachine(&machine, &dummyTimer, &eventPool);
  71. return 0;
  72. }
  73. int main(int argc, char** argv)
  74. {
  75. if (argc != 2)
  76. return -1;
  77. switch (atoi(argv[1])) {
  78. case 1:
  79. return test_state9_state10_transition();
  80. case 2:
  81. return test_state1_state2_back_transition();
  82. }
  83. return -1;
  84. }