ShallowHistoryTest.cc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "ShallowHistory.h"
  14. #include "sc_types.h"
  15. static ShallowHistory* statechart;
  16. class StatemachineTest : public ::testing::Test{
  17. protected:
  18. virtual void SetUp() {
  19. statechart = new ShallowHistory();
  20. statechart->init();
  21. }
  22. virtual void TearDown() {
  23. delete statechart;
  24. }
  25. };
  26. TEST_F(StatemachineTest, shallowHistoryTest) {
  27. statechart->enter();
  28. statechart->getDefaultSCI()->raise_event1();
  29. statechart->runCycle();;
  30. statechart->getDefaultSCI()->raise_event3();
  31. statechart->runCycle();;
  32. statechart->getDefaultSCI()->raise_event5();
  33. statechart->runCycle();;
  34. statechart->getDefaultSCI()->raise_event7();
  35. statechart->runCycle();;
  36. EXPECT_TRUE(!statechart->isStateActive(ShallowHistory::mainRegion_State1));
  37. EXPECT_TRUE(statechart->isStateActive(ShallowHistory::mainRegion_State2__region0_State4__region0_State7__region0_State9));
  38. statechart->getDefaultSCI()->raise_event6();
  39. statechart->runCycle();;
  40. EXPECT_TRUE(!statechart->isStateActive(ShallowHistory::mainRegion_State2__region0_State4__region0_State7__region0_State9));
  41. EXPECT_TRUE(statechart->isStateActive(ShallowHistory::mainRegion_State2__region0_State4__region0_State6));
  42. statechart->getDefaultSCI()->raise_event5();
  43. statechart->runCycle();;
  44. EXPECT_TRUE(!statechart->isStateActive(ShallowHistory::mainRegion_State2__region0_State4__region0_State7__region0_State8));
  45. EXPECT_TRUE(statechart->isStateActive(ShallowHistory::mainRegion_State2__region0_State4__region0_State7__region0_State9));
  46. statechart->getDefaultSCI()->raise_event2();
  47. statechart->runCycle();;
  48. EXPECT_TRUE(!statechart->isStateActive(ShallowHistory::mainRegion_State2__region0_State4__region0_State7__region0_State9));
  49. EXPECT_TRUE(statechart->isStateActive(ShallowHistory::mainRegion_State1));
  50. statechart->getDefaultSCI()->raise_event1();
  51. statechart->runCycle();;
  52. EXPECT_TRUE(statechart->isStateActive(ShallowHistory::mainRegion_State2__region0_State4__region0_State6));
  53. EXPECT_TRUE(!statechart->isStateActive(ShallowHistory::mainRegion_State1));
  54. statechart->getDefaultSCI()->raise_event5();
  55. statechart->runCycle();;
  56. EXPECT_TRUE(!statechart->isStateActive(ShallowHistory::mainRegion_State2__region0_State4__region0_State6));
  57. EXPECT_TRUE(statechart->isStateActive(ShallowHistory::mainRegion_State2__region0_State4__region0_State7__region0_State9));
  58. }