TriggerGuardExpressionsTest.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Copyright (c) 2016 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 "TriggerGuardExpressions.h"
  14. TEST(StatemachineTest, trueGuard) {
  15. TriggerGuardExpressions* statechart = new TriggerGuardExpressions();
  16. statechart->init();
  17. statechart->enter();
  18. EXPECT_TRUE(statechart->isStateActive(TriggerGuardExpressions::main_region_A));
  19. statechart->raise_e1();
  20. statechart->getDefaultSCI()->set_b(true);
  21. statechart->runCycle();
  22. EXPECT_TRUE(statechart->isStateActive(TriggerGuardExpressions::main_region_B));
  23. statechart->runCycle();
  24. EXPECT_TRUE(statechart->isStateActive(TriggerGuardExpressions::main_region_A));
  25. statechart->raise_e2();
  26. statechart->runCycle();
  27. EXPECT_TRUE(statechart->isStateActive(TriggerGuardExpressions::main_region_B));
  28. statechart->runCycle();
  29. EXPECT_TRUE(statechart->isStateActive(TriggerGuardExpressions::main_region_A));
  30. statechart->raise_e1();
  31. statechart->raise_e2();
  32. statechart->runCycle();
  33. EXPECT_TRUE(statechart->isStateActive(TriggerGuardExpressions::main_region_B));
  34. delete statechart;
  35. }
  36. TEST(StatemachineTest, falseGuard) {
  37. TriggerGuardExpressions* statechart = new TriggerGuardExpressions();
  38. statechart->init();
  39. statechart->enter();
  40. EXPECT_TRUE(statechart->isStateActive(TriggerGuardExpressions::main_region_A));
  41. statechart->getDefaultSCI()->set_b(false);
  42. statechart->raise_e1();
  43. statechart->runCycle();
  44. EXPECT_TRUE(statechart->isStateActive(TriggerGuardExpressions::main_region_A));
  45. statechart->raise_e2();
  46. statechart->runCycle();
  47. EXPECT_TRUE(statechart->isStateActive(TriggerGuardExpressions::main_region_A));
  48. statechart->raise_e1();
  49. statechart->raise_e2();
  50. statechart->runCycle();
  51. EXPECT_TRUE(statechart->isStateActive(TriggerGuardExpressions::main_region_A));
  52. delete statechart;
  53. }