GuardedEntryTest.cc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. GuardedEntry handle;
  14. class StatemachineTest : public ::testing::Test{
  15. protected:
  16. virtual void SetUp() {
  17. guardedEntry_init(&handle);
  18. }
  19. };
  20. TEST_F(StatemachineTest, EntryNotTakenOnStatechartEnter) {
  21. EXPECT_TRUE(guardedEntryIface_get_guard(&handle)== false);
  22. guardedEntry_enter(&handle);
  23. EXPECT_TRUE(guardedEntry_isStateActive(&handle, GuardedEntry_main_region_A));
  24. EXPECT_TRUE(guardedEntryIface_get_done(&handle)== false);
  25. }
  26. TEST_F(StatemachineTest, EntryTakenOnStatechartEnter) {
  27. guardedEntryIface_set_guard(&handle,true);
  28. guardedEntry_enter(&handle);
  29. EXPECT_TRUE(guardedEntry_isStateActive(&handle, GuardedEntry_main_region_A));
  30. EXPECT_TRUE(guardedEntryIface_get_done(&handle)== true);
  31. }
  32. TEST_F(StatemachineTest, EntryTakenInTransition) {
  33. guardedEntry_enter(&handle);
  34. EXPECT_TRUE(guardedEntry_isStateActive(&handle, GuardedEntry_main_region_A));
  35. guardedEntryIface_raise_e(&handle);
  36. guardedEntry_runCycle(&handle);
  37. EXPECT_TRUE(guardedEntry_isStateActive(&handle, GuardedEntry_main_region_B));
  38. guardedEntryIface_set_guard(&handle,true);
  39. guardedEntryIface_set_done(&handle,false);
  40. guardedEntryIface_raise_e(&handle);
  41. guardedEntry_runCycle(&handle);
  42. EXPECT_TRUE(guardedEntry_isStateActive(&handle, GuardedEntry_main_region_A));
  43. EXPECT_TRUE(guardedEntryIface_get_done(&handle));
  44. }
  45. TEST_F(StatemachineTest, EntryNotTakenInTransition) {
  46. guardedEntry_enter(&handle);
  47. EXPECT_TRUE(guardedEntry_isStateActive(&handle, GuardedEntry_main_region_A));
  48. guardedEntryIface_raise_e(&handle);
  49. guardedEntry_runCycle(&handle);
  50. EXPECT_TRUE(guardedEntry_isStateActive(&handle, GuardedEntry_main_region_B));
  51. guardedEntryIface_set_guard(&handle,false);
  52. guardedEntryIface_set_done(&handle,false);
  53. guardedEntryIface_raise_e(&handle);
  54. guardedEntry_runCycle(&handle);
  55. EXPECT_TRUE(guardedEntry_isStateActive(&handle, GuardedEntry_main_region_A));
  56. EXPECT_TRUE(!guardedEntryIface_get_done(&handle));
  57. }