ChoiceTest.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. 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. TEST_F(StatemachineTest, elseChoiceUsingNonDefaultTransition) {
  27. statechart->enter();
  28. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  29. statechart->getDefaultSCI()->set_c(true);
  30. statechart->raise_e();
  31. statechart->runCycle();
  32. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_C));
  33. }
  34. TEST_F(StatemachineTest, elseChoiceUsingDefaultTransition) {
  35. statechart->enter();
  36. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  37. statechart->getDefaultSCI()->set_c(false);
  38. statechart->raise_e();
  39. statechart->runCycle();
  40. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_B));
  41. }
  42. TEST_F(StatemachineTest, defaultChoiceUsingNonDefaultTransition) {
  43. statechart->enter();
  44. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  45. statechart->getDefaultSCI()->set_c(true);
  46. statechart->raise_g();
  47. statechart->runCycle();
  48. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_C));
  49. }
  50. TEST_F(StatemachineTest, defaultChoiceUsingDefaultTransition) {
  51. statechart->enter();
  52. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  53. statechart->getDefaultSCI()->set_c(false);
  54. statechart->raise_g();
  55. statechart->runCycle();
  56. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_B));
  57. }
  58. TEST_F(StatemachineTest, uncheckedChoiceUsingNonDefaultTransition) {
  59. statechart->enter();
  60. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  61. statechart->getDefaultSCI()->set_c(true);
  62. statechart->raise_f();
  63. statechart->runCycle();
  64. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_C));
  65. }
  66. TEST_F(StatemachineTest, uncheckedChoiceUsingDefaultTransition) {
  67. statechart->enter();
  68. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  69. statechart->getDefaultSCI()->set_c(false);
  70. statechart->raise_f();
  71. statechart->runCycle();
  72. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_B));
  73. }
  74. TEST_F(StatemachineTest, alwaysTrueTransitionInChoice) {
  75. statechart->enter();
  76. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_A));
  77. statechart->getDefaultSCI()->set_c(true);
  78. statechart->raise_h();
  79. statechart->runCycle();
  80. EXPECT_TRUE(statechart->isStateActive(Choice::main_region_C));
  81. }