GuardedExitTest.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Copyright (c) 2017 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 "GuardedExit.h"
  14. #include "sc_types.h"
  15. static GuardedExit* statechart;
  16. class StatemachineTest : public ::testing::Test{
  17. protected:
  18. virtual void SetUp() {
  19. statechart = new GuardedExit();
  20. statechart->init();
  21. }
  22. virtual void TearDown() {
  23. delete statechart;
  24. }
  25. };
  26. void checkDone(bool shouldBeDone){
  27. statechart->getDefaultSCI()->raise_e();
  28. statechart->runCycle();;
  29. EXPECT_TRUE(statechart->isStateActive(GuardedExit::main_region_B));
  30. EXPECT_TRUE(shouldBeDone ? statechart->getDefaultSCI()->get_done() : !statechart->getDefaultSCI()->get_done());
  31. }
  32. TEST_F(StatemachineTest, ExitTaken) {
  33. statechart->enter();
  34. EXPECT_TRUE(statechart->isStateActive(GuardedExit::main_region_A));
  35. EXPECT_TRUE(!statechart->getDefaultSCI()->get_guard());
  36. checkDone(false);
  37. }
  38. TEST_F(StatemachineTest, ExitNotTaken) {
  39. statechart->enter();
  40. EXPECT_TRUE(statechart->isStateActive(GuardedExit::main_region_A));
  41. statechart->getDefaultSCI()->set_guard(true);
  42. checkDone(true);
  43. }