GuardedExitTest.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Generated by YAKINDU Statechart Tools code generator. */
  2. #include "gtest/gtest.h"
  3. #include "GuardedExit.h"
  4. #include "sc_timer_service.h"
  5. //! The timers are managed by a timer service. */
  6. static sc_unit_timer_service_t timer_service;
  7. static GuardedExit statechart;
  8. class GuardedExitTest : public ::testing::Test{
  9. protected:
  10. virtual void SetUp() {
  11. guardedExit_init(&statechart);
  12. sc_timer_service_init(
  13. &timer_service,
  14. 0,
  15. (sc_run_cycle_fp) &guardedExit_runCycle,
  16. false,
  17. 200,
  18. &statechart
  19. );
  20. }
  21. };
  22. void checkDone(bool shouldBeDone){
  23. guardedExitIface_raise_e(&statechart);
  24. sc_timer_service_proceed_cycles(&timer_service, 1);
  25. EXPECT_TRUE(guardedExit_isStateActive(&statechart, GuardedExit_main_region_B));
  26. EXPECT_TRUE(shouldBeDone ? guardedExitIface_get_done(&statechart) : !guardedExitIface_get_done(&statechart));
  27. }
  28. TEST_F(GuardedExitTest, ExitTaken) {
  29. guardedExit_enter(&statechart);
  30. EXPECT_TRUE(guardedExit_isStateActive(&statechart, GuardedExit_main_region_A));
  31. EXPECT_TRUE(!guardedExitIface_get_guard(&statechart));
  32. checkDone(false);
  33. }
  34. TEST_F(GuardedExitTest, ExitNotTaken) {
  35. guardedExit_enter(&statechart);
  36. EXPECT_TRUE(guardedExit_isStateActive(&statechart, GuardedExit_main_region_A));
  37. guardedExitIface_set_guard(&statechart,true);
  38. checkDone(true);
  39. }