TimedTransitionsTestCustom.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Copyright (c) 2015 committers of YAKINDU and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * committers of YAKINDU - initial API and implementation
  10. */
  11. #include <string>
  12. #include "gtest/gtest.h"
  13. #include "TimedTransitions.h"
  14. #include "Timer.h"
  15. TEST(StatemachineTest, Timer01) {
  16. TimedTransitions* statechart = new TimedTransitions();
  17. Timer* timer = new Timer();
  18. statechart->setTimer(timer);
  19. statechart->init();
  20. statechart->enter();
  21. EXPECT_TRUE(statechart->isStateActive(TimedTransitions::main_region_Start));
  22. EXPECT_EQ(2000, timer->getTime());
  23. EXPECT_FALSE(timer->isPeriodic());
  24. statechart->runCycle();
  25. EXPECT_TRUE(statechart->isStateActive(TimedTransitions::main_region_End));
  26. EXPECT_EQ(timer->getStatemachineSet(), timer->getStatemachineUnset());
  27. EXPECT_EQ(timer->getEventSet(),timer->getEventUnset());
  28. delete timer;
  29. delete statechart;
  30. }
  31. Timer::Timer() {
  32. }
  33. Timer::~Timer() {
  34. }
  35. void Timer::setTimer(TimedStatemachineInterface* statemachine, sc_eventid event, sc_integer time, sc_boolean isPeriodic) {
  36. statemachineSet = statemachine;
  37. eventSet = event;
  38. this->time = time;
  39. periodic = isPeriodic;
  40. statemachine->raiseTimeEvent(event);
  41. }
  42. void Timer::unsetTimer(TimedStatemachineInterface* statemachine, sc_eventid event) {
  43. statemachineUnset = statemachine;
  44. eventUnset = event;
  45. }
  46. void Timer::cancel() {
  47. }
  48. TimedStatemachineInterface* Timer::getStatemachineSet() {
  49. return statemachineSet;
  50. }
  51. TimedStatemachineInterface* Timer::getStatemachineUnset() {
  52. return statemachineUnset;
  53. }
  54. sc_eventid Timer::getEventSet() {
  55. return eventSet;
  56. }
  57. sc_eventid Timer::getEventUnset() {
  58. return eventUnset;
  59. }
  60. sc_integer Timer::getTime() {
  61. return time;
  62. }
  63. sc_boolean Timer::isPeriodic() {
  64. return periodic;
  65. }