OperationsTestCustom.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * Copyright (c) 2014 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 "Operations.h"
  14. #include "Operations_OCB.h"
  15. bool internalOperation1Called;
  16. bool internalOperation2Called;
  17. sc_integer internalOp2Param;
  18. bool interfaceOperation1Called;
  19. bool interfaceOperation2Called;
  20. sc_integer interfaceOp2Param;
  21. bool unnamedInterfaceOperation1Called;
  22. bool unnamedInterfaceOperation2Called;
  23. sc_integer unnamedInterfaceOp2Param;
  24. TEST(StatemachineTest, OperationCallback) {
  25. internalOperation1Called = false;
  26. internalOperation2Called = false;
  27. internalOp2Param = 0;
  28. interfaceOperation1Called = false;
  29. interfaceOperation2Called = false;
  30. interfaceOp2Param = 0;
  31. unnamedInterfaceOperation1Called = false;
  32. unnamedInterfaceOperation2Called = false;
  33. unnamedInterfaceOp2Param = 0;
  34. Operations* statechart = new Operations();
  35. statechart->setDefaultSCI_OCB(new DefaultCallBack());
  36. statechart->setInternalSCI_OCB(new InternalCallBack());
  37. statechart->setSCI_Interface1_OCB(new Interface1CallBack());
  38. statechart->init();
  39. statechart->enter();
  40. statechart->runCycle();
  41. EXPECT_TRUE(internalOperation1Called);
  42. EXPECT_TRUE(internalOperation2Called);
  43. EXPECT_TRUE(internalOp2Param == 4);
  44. statechart->raise_ev();
  45. statechart->runCycle();
  46. EXPECT_TRUE(interfaceOperation1Called);
  47. EXPECT_TRUE(interfaceOperation2Called);
  48. EXPECT_TRUE(interfaceOp2Param == 4);
  49. statechart->raise_ev();
  50. statechart->runCycle();
  51. EXPECT_TRUE(unnamedInterfaceOperation1Called);
  52. EXPECT_TRUE(unnamedInterfaceOperation2Called);
  53. EXPECT_TRUE(unnamedInterfaceOp2Param == 4);
  54. delete statechart;
  55. }
  56. void InternalCallBack::internalOperation1() {
  57. internalOperation1Called = true;
  58. }
  59. sc_boolean InternalCallBack::InternalOperation2(sc_integer param1) {
  60. internalOperation2Called = true;
  61. internalOp2Param = param1;
  62. return true;
  63. }
  64. void Interface1CallBack::interfaceOperation1() {
  65. interfaceOperation1Called = true;
  66. }
  67. sc_boolean Interface1CallBack::InterfaceOperation2(sc_integer param1) {
  68. interfaceOperation2Called = true;
  69. interfaceOp2Param = param1;
  70. return true;
  71. }
  72. void DefaultCallBack::unnamedInterfaceOperation1() {
  73. unnamedInterfaceOperation1Called = true;
  74. }
  75. sc_boolean DefaultCallBack::UnnamedInterfaceOperation2(sc_integer param1) {
  76. unnamedInterfaceOperation2Called = true;
  77. unnamedInterfaceOp2Param = param1;
  78. return true;
  79. }
  80. sc_boolean DefaultCallBack::alwaysTrue() {
  81. return true;
  82. }