GuardedEntryTest.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Copyright (c) 2013 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. TEST(StatemachineTest, EntryNotTakenOnStatechartEnter) {
  15. GuardedEntry* statechart = new GuardedEntry();
  16. statechart->init();
  17. EXPECT_TRUE(statechart->getSCInterface()->get_guard()== false);
  18. statechart->enter();
  19. EXPECT_TRUE(statechart->isActive(GuardedEntry::GuardedEntry_main_region_A));
  20. EXPECT_TRUE(statechart->getSCInterface()->get_done()== false);
  21. delete statechart;
  22. }
  23. TEST(StatemachineTest, EntryTakenOnStatechartEnter) {
  24. GuardedEntry* statechart = new GuardedEntry();
  25. statechart->init();
  26. statechart->getSCInterface()->set_guard(true);
  27. statechart->enter();
  28. EXPECT_TRUE(statechart->isActive(GuardedEntry::GuardedEntry_main_region_A));
  29. EXPECT_TRUE(statechart->getSCInterface()->get_done()== true);
  30. delete statechart;
  31. }
  32. TEST(StatemachineTest, EntryTakenInTransition) {
  33. GuardedEntry* statechart = new GuardedEntry();
  34. statechart->init();
  35. statechart->enter();
  36. EXPECT_TRUE(statechart->isActive(GuardedEntry::GuardedEntry_main_region_A));
  37. statechart->raise_e();
  38. statechart->runCycle();
  39. EXPECT_TRUE(statechart->isActive(GuardedEntry::GuardedEntry_main_region_B));
  40. statechart->getSCInterface()->set_guard(true);
  41. statechart->getSCInterface()->set_done(false);
  42. statechart->raise_e();
  43. statechart->runCycle();
  44. EXPECT_TRUE(statechart->isActive(GuardedEntry::GuardedEntry_main_region_A));
  45. EXPECT_TRUE(statechart->getSCInterface()->get_done());
  46. delete statechart;
  47. }
  48. TEST(StatemachineTest, EntryNotTakenInTransition) {
  49. GuardedEntry* statechart = new GuardedEntry();
  50. statechart->init();
  51. statechart->enter();
  52. EXPECT_TRUE(statechart->isActive(GuardedEntry::GuardedEntry_main_region_A));
  53. statechart->raise_e();
  54. statechart->runCycle();
  55. EXPECT_TRUE(statechart->isActive(GuardedEntry::GuardedEntry_main_region_B));
  56. statechart->getSCInterface()->set_guard(false);
  57. statechart->getSCInterface()->set_done(false);
  58. statechart->raise_e();
  59. statechart->runCycle();
  60. EXPECT_TRUE(statechart->isActive(GuardedEntry::GuardedEntry_main_region_A));
  61. EXPECT_TRUE(!statechart->getSCInterface()->get_done());
  62. delete statechart;
  63. }