ChoiceTest.cc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * Copyright (c) 2014 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 "Choice.h"
  14. TEST(StatemachineTest, elseChoiceUsingNonDefaultTransition) {
  15. Choice* statechart = new Choice();
  16. statechart->init();
  17. statechart->enter();
  18. EXPECT_TRUE(statechart->isActive(Choice::A));
  19. statechart->getSCInterface()->set_c(true);
  20. statechart->raise_e();
  21. statechart->runCycle();
  22. EXPECT_TRUE(statechart->isActive(Choice::C));
  23. delete statechart;
  24. }
  25. TEST(StatemachineTest, elseChoiceUsingDefaultTransition) {
  26. Choice* statechart = new Choice();
  27. statechart->init();
  28. statechart->enter();
  29. EXPECT_TRUE(statechart->isActive(Choice::A));
  30. statechart->getSCInterface()->set_c(false);
  31. statechart->raise_e();
  32. statechart->runCycle();
  33. EXPECT_TRUE(statechart->isActive(Choice::B));
  34. delete statechart;
  35. }
  36. TEST(StatemachineTest, defaultChoiceUsingNonDefaultTransition) {
  37. Choice* statechart = new Choice();
  38. statechart->init();
  39. statechart->enter();
  40. EXPECT_TRUE(statechart->isActive(Choice::A));
  41. statechart->getSCInterface()->set_c(true);
  42. statechart->raise_g();
  43. statechart->runCycle();
  44. EXPECT_TRUE(statechart->isActive(Choice::C));
  45. delete statechart;
  46. }
  47. TEST(StatemachineTest, defaultChoiceUsingDefaultTransition) {
  48. Choice* statechart = new Choice();
  49. statechart->init();
  50. statechart->enter();
  51. EXPECT_TRUE(statechart->isActive(Choice::A));
  52. statechart->getSCInterface()->set_c(false);
  53. statechart->raise_g();
  54. statechart->runCycle();
  55. EXPECT_TRUE(statechart->isActive(Choice::B));
  56. delete statechart;
  57. }
  58. TEST(StatemachineTest, uncheckedChoiceUsingNonDefaultTransition) {
  59. Choice* statechart = new Choice();
  60. statechart->init();
  61. statechart->enter();
  62. EXPECT_TRUE(statechart->isActive(Choice::A));
  63. statechart->getSCInterface()->set_c(true);
  64. statechart->raise_f();
  65. statechart->runCycle();
  66. EXPECT_TRUE(statechart->isActive(Choice::C));
  67. delete statechart;
  68. }
  69. TEST(StatemachineTest, uncheckedChoiceUsingDefaultTransition) {
  70. Choice* statechart = new Choice();
  71. statechart->init();
  72. statechart->enter();
  73. EXPECT_TRUE(statechart->isActive(Choice::A));
  74. statechart->getSCInterface()->set_c(false);
  75. statechart->raise_f();
  76. statechart->runCycle();
  77. EXPECT_TRUE(statechart->isActive(Choice::B));
  78. delete statechart;
  79. }
  80. TEST(StatemachineTest, alwaysTrueTransitionInChoice) {
  81. Choice* statechart = new Choice();
  82. statechart->init();
  83. statechart->enter();
  84. EXPECT_TRUE(statechart->isActive(Choice::A));
  85. statechart->getSCInterface()->set_c(true);
  86. statechart->raise_h();
  87. statechart->runCycle();
  88. EXPECT_TRUE(statechart->isActive(Choice::C));
  89. delete statechart;
  90. }