OperationsTestCustom.cc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. char myChar;
  25. TEST(StatemachineTest, OperationCallback) {
  26. internalOperation1Called = false;
  27. internalOperation2Called = false;
  28. internalOp2Param = 0;
  29. interfaceOperation1Called = false;
  30. interfaceOperation2Called = false;
  31. interfaceOp2Param = 0;
  32. unnamedInterfaceOperation1Called = false;
  33. unnamedInterfaceOperation2Called = false;
  34. unnamedInterfaceOp2Param = 0;
  35. Operations* statechart = new Operations();
  36. statechart->setDefaultSCI_OCB(new DefaultCallBack());
  37. statechart->setInternalSCI_OCB(new InternalCallBack());
  38. statechart->setSCI_Interface1_OCB(new Interface1CallBack());
  39. statechart->init();
  40. statechart->enter();
  41. statechart->runCycle();
  42. EXPECT_TRUE(internalOperation1Called);
  43. EXPECT_TRUE(internalOperation2Called);
  44. EXPECT_TRUE(internalOp2Param == 4);
  45. statechart->raise_ev();
  46. statechart->runCycle();
  47. EXPECT_TRUE(interfaceOperation1Called);
  48. EXPECT_TRUE(interfaceOperation2Called);
  49. EXPECT_TRUE(interfaceOp2Param == 4);
  50. statechart->raise_ev();
  51. statechart->runCycle();
  52. EXPECT_TRUE(unnamedInterfaceOperation1Called);
  53. EXPECT_TRUE(unnamedInterfaceOperation2Called);
  54. EXPECT_TRUE(unnamedInterfaceOp2Param == 4);
  55. delete statechart;
  56. }
  57. void InternalCallBack::internalOperation1() {
  58. internalOperation1Called = true;
  59. }
  60. sc_boolean InternalCallBack::InternalOperation2(sc_integer param1) {
  61. internalOperation2Called = true;
  62. internalOp2Param = param1;
  63. return true;
  64. }
  65. sc_real InternalCallBack::internalOperation3() {
  66. return 0.0d;
  67. }
  68. sc_real InternalCallBack::internalOperation3a(sc_real param1) {
  69. return 0.0d;
  70. }
  71. sc_integer InternalCallBack::internalOperation4() {
  72. return 0;
  73. }
  74. sc_integer InternalCallBack::internalOperation4a(sc_integer param1) {
  75. return 0;
  76. }
  77. sc_string InternalCallBack::internalOperation5() {
  78. return &myChar;
  79. }
  80. sc_string InternalCallBack::internalOperation5a(sc_string param1) {
  81. return &myChar;
  82. }
  83. void Interface1CallBack::interfaceOperation1() {
  84. interfaceOperation1Called = true;
  85. }
  86. sc_boolean Interface1CallBack::InterfaceOperation2(sc_integer param1) {
  87. interfaceOperation2Called = true;
  88. interfaceOp2Param = param1;
  89. return true;
  90. }
  91. sc_real Interface1CallBack::interfaceOperation3() {
  92. return 0.0d;
  93. }
  94. sc_real Interface1CallBack::interfaceOperation3a(sc_real param1) {
  95. return 0.0d;
  96. }
  97. sc_integer Interface1CallBack::interfaceOperation4() {
  98. return 0;
  99. }
  100. sc_integer Interface1CallBack::interfaceOperation4a(sc_integer param1) {
  101. return 0;
  102. }
  103. sc_string Interface1CallBack::interfaceOperation5() {
  104. return &myChar;
  105. }
  106. sc_string Interface1CallBack::interfaceOperation5a(sc_string param1) {
  107. return &myChar;
  108. }
  109. void DefaultCallBack::unnamedInterfaceOperation1() {
  110. unnamedInterfaceOperation1Called = true;
  111. }
  112. sc_boolean DefaultCallBack::UnnamedInterfaceOperation2(sc_integer param1) {
  113. unnamedInterfaceOperation2Called = true;
  114. unnamedInterfaceOp2Param = param1;
  115. return true;
  116. }
  117. sc_real DefaultCallBack::unnamedOperation3() {
  118. return 0.0d;
  119. }
  120. sc_real DefaultCallBack::unnamedOperation3a(sc_real param1) {
  121. return 0.0d;
  122. }
  123. sc_integer DefaultCallBack::unnamedOperation4() {
  124. return 0;
  125. }
  126. sc_integer DefaultCallBack::unnamedOperation4a(sc_integer param1) {
  127. return 0;
  128. }
  129. sc_string DefaultCallBack::unnamedOperation5() {
  130. return &myChar;
  131. }
  132. sc_string DefaultCallBack::unnamedOperation5a(sc_string param1) {
  133. return &myChar;
  134. }
  135. sc_boolean DefaultCallBack::alwaysTrue() {
  136. return true;
  137. }