ChoiceTest.cc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "gtest/gtest.h"
  12. #include "Choice.h"
  13. static Choice statechart;
  14. class StatemachineTest : public ::testing::Test{
  15. protected:
  16. virtual void SetUp() {
  17. choice_init(&statechart);
  18. }
  19. };
  20. void initForEventE(bool valueForC){
  21. choice_enter(&statechart);
  22. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_A));
  23. choiceIface_set_c(&statechart,valueForC);
  24. choiceIface_raise_e(&statechart);
  25. choice_runCycle(&statechart);
  26. }
  27. void initForEventF(bool valueForC){
  28. choice_enter(&statechart);
  29. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_A));
  30. choiceIface_set_c(&statechart,valueForC);
  31. choiceIface_raise_f(&statechart);
  32. choice_runCycle(&statechart);
  33. }
  34. void initForEventG(bool valueForC){
  35. choice_enter(&statechart);
  36. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_A));
  37. choiceIface_set_c(&statechart,valueForC);
  38. choiceIface_raise_g(&statechart);
  39. choice_runCycle(&statechart);
  40. }
  41. void initForEventH(bool valueForC){
  42. choice_enter(&statechart);
  43. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_A));
  44. choiceIface_set_c(&statechart,valueForC);
  45. choiceIface_raise_h(&statechart);
  46. choice_runCycle(&statechart);
  47. }
  48. TEST_F(StatemachineTest, elseChoiceUsingNonDefaultTransition) {
  49. initForEventE(true);
  50. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_C));
  51. }
  52. TEST_F(StatemachineTest, elseChoiceUsingDefaultTransition) {
  53. initForEventE(false);
  54. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_B));
  55. }
  56. TEST_F(StatemachineTest, defaultChoiceUsingNonDefaultTransition) {
  57. initForEventG(true);
  58. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_C));
  59. }
  60. TEST_F(StatemachineTest, defaultChoiceUsingDefaultTransition) {
  61. initForEventG(false);
  62. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_B));
  63. }
  64. TEST_F(StatemachineTest, uncheckedChoiceUsingNonDefaultTransition) {
  65. initForEventF(true);
  66. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_C));
  67. }
  68. TEST_F(StatemachineTest, uncheckedChoiceUsingDefaultTransition) {
  69. initForEventF(false);
  70. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_B));
  71. }
  72. TEST_F(StatemachineTest, alwaysTrueTransitionInChoice) {
  73. initForEventH(true);
  74. EXPECT_TRUE(choice_isStateActive(&statechart, Choice_main_region_C));
  75. }