OperationsCustom.cc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 "OperationsRequired.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. Operations handle;
  26. TEST(StatemachineTest, OperationCallback) {
  27. internalOperation1Called = false;
  28. internalOperation2Called = false;
  29. internalOp2Param = 0;
  30. interfaceOperation1Called = false;
  31. interfaceOperation2Called = false;
  32. interfaceOp2Param = 0;
  33. unnamedInterfaceOperation1Called = false;
  34. unnamedInterfaceOperation2Called = false;
  35. unnamedInterfaceOp2Param = 0;
  36. operations_init(&handle);
  37. operations_enter(&handle);
  38. operations_runCycle(&handle);
  39. EXPECT_TRUE(operations_isStateActive(&handle, Operations_main_region_B));
  40. EXPECT_TRUE(internalOperation1Called);
  41. EXPECT_TRUE(internalOperation2Called);
  42. EXPECT_TRUE(internalOp2Param == 4);
  43. operationsIface_raise_ev(&handle);
  44. operations_runCycle(&handle);
  45. EXPECT_TRUE(operations_isStateActive(&handle, Operations_main_region_C));
  46. EXPECT_TRUE(interfaceOperation1Called);
  47. EXPECT_TRUE(interfaceOperation2Called);
  48. EXPECT_TRUE(interfaceOp2Param == 4);
  49. operationsIface_raise_ev(&handle);
  50. operations_runCycle(&handle);
  51. EXPECT_TRUE(operations_isStateActive(&handle, Operations_main_region_D));
  52. EXPECT_TRUE(unnamedInterfaceOperation1Called);
  53. EXPECT_TRUE(unnamedInterfaceOperation2Called);
  54. EXPECT_TRUE(unnamedInterfaceOp2Param == 4);
  55. }
  56. void operationsInternal_internalOperation1(const Operations* handle){
  57. internalOperation1Called = true;
  58. }
  59. sc_boolean operationsInternal_internalOperation2(const Operations* handle, const sc_integer param1){
  60. internalOperation2Called = true;
  61. internalOp2Param = param1;
  62. return true;
  63. }
  64. sc_real operationsInternal_internalOperation3(const Operations* handle){
  65. return 0.0d;
  66. }
  67. sc_real operationsInternal_internalOperation3a(const Operations* handle, const sc_real param1){
  68. return 0.0d;
  69. }
  70. sc_integer operationsInternal_internalOperation4(const Operations* handle){
  71. return 0;
  72. }
  73. sc_integer operationsInternal_internalOperation4a(const Operations* handle, const sc_integer param1){
  74. return 0;
  75. }
  76. sc_string operationsInternal_internalOperation5(const Operations* handle){
  77. return &myChar;
  78. }
  79. sc_string operationsInternal_internalOperation5a(const Operations* handle, const sc_string param1){
  80. return &myChar;
  81. }
  82. void operationsIfaceInterface1_interfaceOperation1(const Operations* handle){
  83. interfaceOperation1Called = true;
  84. }
  85. sc_boolean operationsIfaceInterface1_interfaceOperation2(const Operations* handle, const sc_integer param1){
  86. interfaceOperation2Called = true;
  87. interfaceOp2Param = param1;
  88. return true;
  89. }
  90. sc_real operationsIfaceInterface1_interfaceOperation3(const Operations* handle){
  91. return 0.0d;
  92. }
  93. sc_real operationsIfaceInterface1_interfaceOperation3a(const Operations* handle, const sc_real param1){
  94. return 0.0d;
  95. }
  96. sc_integer operationsIfaceInterface1_interfaceOperation4(const Operations* handle){
  97. return 0;
  98. }
  99. sc_integer operationsIfaceInterface1_interfaceOperation4a(const Operations* handle, const sc_integer param1){
  100. return 0;
  101. }
  102. sc_string operationsIfaceInterface1_interfaceOperation5(const Operations* handle){
  103. return &myChar;
  104. }
  105. sc_string operationsIfaceInterface1_interfaceOperation5a(const Operations* handle, const sc_string param1){
  106. return &myChar;
  107. }
  108. void operationsIface_unnamedInterfaceOperation1(const Operations* handle){
  109. unnamedInterfaceOperation1Called = true;
  110. }
  111. sc_boolean operationsIface_unnamedInterfaceOperation2(const Operations* handle, const sc_integer param1){
  112. unnamedInterfaceOperation2Called = true;
  113. unnamedInterfaceOp2Param = param1;
  114. return true;
  115. }
  116. sc_real operationsIface_unnamedOperation3(const Operations* handle){
  117. return 0.0d;
  118. }
  119. sc_real operationsIface_unnamedOperation3a(const Operations* handle, const sc_real param1){
  120. return 0.0d;
  121. }
  122. sc_integer operationsIface_unnamedOperation4(const Operations* handle){
  123. return 0;
  124. }
  125. sc_integer operationsIface_unnamedOperation4a(const Operations* handle, const sc_integer param1){
  126. return 0;
  127. }
  128. sc_string operationsIface_unnamedOperation5(const Operations* handle){
  129. return &myChar;
  130. }
  131. sc_string operationsIface_unnamedOperation5a(const Operations* handle, const sc_string param1){
  132. return &myChar;
  133. }
  134. sc_boolean operationsIface_alwaysTrue(const Operations* handle){
  135. return true;
  136. }