GuardedEntryTest.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 "gtest/gtest.h"
  12. #include "GuardedEntry.h"
  13. static GuardedEntry statechart;
  14. class StatemachineTest : public ::testing::Test{
  15. protected:
  16. virtual void SetUp() {
  17. guardedEntry_init(&statechart);
  18. }
  19. };
  20. void initEntryInTransition(bool guardVar, bool doneVar){
  21. guardedEntry_enter(&statechart);
  22. EXPECT_TRUE(guardedEntry_isStateActive(&statechart, GuardedEntry_main_region_A));
  23. guardedEntryIface_raise_e(&statechart);
  24. guardedEntry_runCycle(&statechart);
  25. EXPECT_TRUE(guardedEntry_isStateActive(&statechart, GuardedEntry_main_region_B));
  26. guardedEntryIface_set_guard(&statechart,guardVar);
  27. guardedEntryIface_set_done(&statechart,doneVar);
  28. guardedEntryIface_raise_e(&statechart);
  29. guardedEntry_runCycle(&statechart);
  30. EXPECT_TRUE(guardedEntry_isStateActive(&statechart, GuardedEntry_main_region_A));
  31. }
  32. TEST_F(StatemachineTest, EntryNotTakenOnStatechartEnter) {
  33. EXPECT_TRUE(guardedEntryIface_get_guard(&statechart)== false);
  34. guardedEntry_enter(&statechart);
  35. EXPECT_TRUE(guardedEntry_isStateActive(&statechart, GuardedEntry_main_region_A));
  36. EXPECT_TRUE(guardedEntryIface_get_done(&statechart)== false);
  37. }
  38. TEST_F(StatemachineTest, EntryTakenOnStatechartEnter) {
  39. guardedEntryIface_set_guard(&statechart,true);
  40. guardedEntry_enter(&statechart);
  41. EXPECT_TRUE(guardedEntry_isStateActive(&statechart, GuardedEntry_main_region_A));
  42. EXPECT_TRUE(guardedEntryIface_get_done(&statechart)== true);
  43. }
  44. TEST_F(StatemachineTest, EntryTakenInTransition) {
  45. initEntryInTransition(true,false);
  46. EXPECT_TRUE(guardedEntryIface_get_done(&statechart));
  47. }
  48. TEST_F(StatemachineTest, EntryNotTakenInTransition) {
  49. initEntryInTransition(false,false);
  50. EXPECT_TRUE(!guardedEntryIface_get_done(&statechart));
  51. }