ChoiceTest.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "Choice.h"
  14. #include "sc_types.h"
  15. static Choice* statechart;
  16. class StatemachineTest : public ::testing::Test{
  17. protected:
  18. virtual void SetUp() {
  19. statechart = new Choice();
  20. statechart->init();
  21. }
  22. virtual void TearDown() {
  23. delete statechart;
  24. }
  25. };
  26. void initForEventE(bool valueForC){
  27. statechart->enter();
  28. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  29. statechart->getDefaultSCI()->set_c(valueForC);
  30. statechart->getDefaultSCI()->raise_e();
  31. statechart->runCycle();;
  32. }
  33. void initForEventF(bool valueForC){
  34. statechart->enter();
  35. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  36. statechart->getDefaultSCI()->set_c(valueForC);
  37. statechart->getDefaultSCI()->raise_f();
  38. statechart->runCycle();;
  39. }
  40. void initForEventG(bool valueForC){
  41. statechart->enter();
  42. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  43. statechart->getDefaultSCI()->set_c(valueForC);
  44. statechart->getDefaultSCI()->raise_g();
  45. statechart->runCycle();;
  46. }
  47. void initForEventH(bool valueForC){
  48. statechart->enter();
  49. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  50. statechart->getDefaultSCI()->set_c(valueForC);
  51. statechart->getDefaultSCI()->raise_h();
  52. statechart->runCycle();;
  53. }
  54. TEST_F(StatemachineTest, elseChoiceUsingNonDefaultTransition) {
  55. initForEventE(true);
  56. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_C));
  57. }
  58. TEST_F(StatemachineTest, elseChoiceUsingDefaultTransition) {
  59. initForEventE(false);
  60. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_B));
  61. }
  62. TEST_F(StatemachineTest, defaultChoiceUsingNonDefaultTransition) {
  63. initForEventG(true);
  64. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_C));
  65. }
  66. TEST_F(StatemachineTest, defaultChoiceUsingDefaultTransition) {
  67. initForEventG(false);
  68. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_B));
  69. }
  70. TEST_F(StatemachineTest, uncheckedChoiceUsingNonDefaultTransition) {
  71. initForEventF(true);
  72. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_C));
  73. }
  74. TEST_F(StatemachineTest, uncheckedChoiceUsingDefaultTransition) {
  75. initForEventF(false);
  76. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_B));
  77. }
  78. TEST_F(StatemachineTest, alwaysTrueTransitionInChoice) {
  79. initForEventH(true);
  80. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_C));
  81. }