ctkEAScenario1TestSuite_p.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKEASCENARIO1TESTSUITE_P_H
  16. #define CTKEASCENARIO1TESTSUITE_P_H
  17. #include <QObject>
  18. #include <QThread>
  19. #include <service/event/ctkEventHandler.h>
  20. #include <ctkTestSuiteInterface.h>
  21. #include <ctkServiceRegistration.h>
  22. #include <ctkRuntimeException.h>
  23. class ctkPluginContext;
  24. struct ctkEventAdmin;
  25. /**
  26. * This class consumes events
  27. */
  28. class ctkEAScenario1EventConsumer : public QObject, public ctkEventHandler
  29. {
  30. Q_OBJECT
  31. Q_INTERFACES(ctkEventHandler)
  32. private:
  33. ctkPluginContext* context;
  34. ctkServiceReference eventAdminRef;
  35. ctkEventAdmin* eventAdmin;
  36. qlonglong slotId;
  37. /** class variable for service registration */
  38. ctkServiceRegistration serviceRegistration;
  39. /** class variable indicating the topics */
  40. QStringList topicsToConsume;
  41. /** class variable keeping number of asynchronus messages */
  42. int numOfasynchMessages;
  43. /** class variable keeping number of synchronus messages */
  44. int numOfsynchMessages;
  45. /** class variable holding the old syncronus message nummber */
  46. int synchMessageExpectedNumber;
  47. /** class variable holding the old asyncronus message nummber */
  48. int asynchMessageExpectedNumber;
  49. const int messagesSent;
  50. bool error;
  51. ctkRuntimeException exc;
  52. bool useSignalSlot;
  53. public:
  54. /**
  55. * Constructor creates a consumer service
  56. */
  57. ctkEAScenario1EventConsumer(ctkPluginContext* pluginContext, const QStringList& topics,
  58. int messagesSent, bool useSignalSlot);
  59. /**
  60. * run the test
  61. */
  62. void runTest();
  63. void cleanup();
  64. void reset();
  65. public slots:
  66. /**
  67. * This method takes events from the event admin service.
  68. */
  69. void handleEvent(const ctkEvent& event);
  70. };
  71. /**
  72. * Class publish events
  73. */
  74. class ctkEAScenario1EventPublisher : public QObject
  75. {
  76. Q_OBJECT
  77. private:
  78. /** A reference to a service */
  79. ctkServiceReference serviceReference;
  80. /** The admin which delivers the events */
  81. ctkEventAdmin* eventAdmin;
  82. /** class variable holding bundle context */
  83. ctkPluginContext* context;
  84. /** variable holding messages to send */
  85. int messageTosend;
  86. QThread thread;
  87. bool useSignalSlot;
  88. public:
  89. ctkEAScenario1EventPublisher(ctkPluginContext* context, const QString& name,
  90. int id, int numOfMessage, bool useSignalSlot);
  91. void runTest();
  92. protected slots:
  93. void sendEvents();
  94. void postEvents();
  95. signals:
  96. void syncSignalEvent(const ctkEvent&);
  97. void asyncSignalEvent(const ctkEvent&);
  98. };
  99. /**
  100. * Test sute for testing the requirements specified in the test
  101. * specification for the EventAdmin service. It will ensure that the
  102. * events arrive in time and order it will even check that the
  103. * wildcards according to the topics works properly.
  104. *
  105. * @author Magnus Klack
  106. */
  107. class ctkEAScenario1TestSuite : public QObject, public ctkTestSuiteInterface
  108. {
  109. Q_OBJECT
  110. Q_INTERFACES(ctkTestSuiteInterface)
  111. private:
  112. /** plugin context variable */
  113. ctkPluginContext* pluginContext;
  114. /** the messages to be deliverd */
  115. const int MESSAGES_SENT;
  116. long eventPluginId;
  117. ctkServiceReference reference;
  118. ctkEAScenario1EventConsumer* eventConsumer;
  119. ctkEAScenario1EventPublisher* eventPublisher;
  120. bool useSignalSlot;
  121. public:
  122. /**
  123. * Constructor for the TestSuite class.
  124. *
  125. * @param context The handle to the framework
  126. * @param eventPluginId The id of the plugin implementing the EventAdmin spec
  127. */
  128. ctkEAScenario1TestSuite(ctkPluginContext* context, long eventPluginId, bool useSignalSlot);
  129. private slots:
  130. void initTestCase();
  131. void cleanupTestCase();
  132. void testRegisterConsumer();
  133. void testPublishEvents();
  134. };
  135. #endif // CTKEASCENARIO1TESTSUITE_P_H