GuardedEntryTest.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "GuardedEntry.h"
  14. #include "sc_types.h"
  15. GuardedEntry* statechart;
  16. class StatemachineTest : public ::testing::Test{
  17. protected:
  18. virtual void SetUp() {
  19. statechart = new GuardedEntry();
  20. statechart->init();
  21. }
  22. virtual void TearDown() {
  23. delete statechart;
  24. }
  25. };
  26. void initEntryInTransition(bool guardVar, bool doneVar){
  27. statechart->enter();
  28. EXPECT_TRUE(statechart->isStateActive(GuardedEntry::main_region_A));
  29. statechart->raise_e();
  30. statechart->runCycle();
  31. EXPECT_TRUE(statechart->isStateActive(GuardedEntry::main_region_B));
  32. statechart->getDefaultSCI()->set_guard(guardVar);
  33. statechart->getDefaultSCI()->set_done(doneVar);
  34. statechart->raise_e();
  35. statechart->runCycle();
  36. EXPECT_TRUE(statechart->isStateActive(GuardedEntry::main_region_A));
  37. }
  38. TEST_F(StatemachineTest, EntryNotTakenOnStatechartEnter) {
  39. EXPECT_TRUE(statechart->getDefaultSCI()->get_guard()== false);
  40. statechart->enter();
  41. EXPECT_TRUE(statechart->isStateActive(GuardedEntry::main_region_A));
  42. EXPECT_TRUE(statechart->getDefaultSCI()->get_done()== false);
  43. }
  44. TEST_F(StatemachineTest, EntryTakenOnStatechartEnter) {
  45. statechart->getDefaultSCI()->set_guard(true);
  46. statechart->enter();
  47. EXPECT_TRUE(statechart->isStateActive(GuardedEntry::main_region_A));
  48. EXPECT_TRUE(statechart->getDefaultSCI()->get_done()== true);
  49. }
  50. TEST_F(StatemachineTest, EntryTakenInTransition) {
  51. initEntryInTransition(true,false);
  52. EXPECT_TRUE(statechart->getDefaultSCI()->get_done());
  53. }
  54. TEST_F(StatemachineTest, EntryNotTakenInTransition) {
  55. initEntryInTransition(false,false);
  56. EXPECT_TRUE(!statechart->getDefaultSCI()->get_done());
  57. }