ctkEAScenario4TestSuite_p.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 CTKEASCENARIO4TESTSUITE_P_H
  16. #define CTKEASCENARIO4TESTSUITE_P_H
  17. #include <QObject>
  18. #include <QThread>
  19. #include <QMutex>
  20. #include <service/event/ctkEventHandler.h>
  21. #include <ctkTestSuiteInterface.h>
  22. #include <ctkServiceRegistration.h>
  23. #include <ctkRuntimeException.h>
  24. struct ctkEventAdmin;
  25. class ctkEAScenario4EventConsumer : public QObject, public ctkEventHandler
  26. {
  27. Q_OBJECT
  28. Q_INTERFACES(ctkEventHandler)
  29. private:
  30. ctkPluginContext* context;
  31. /** class variable for service registration */
  32. ctkServiceRegistration serviceRegistration;
  33. /** class variable indicating the topics correct version */
  34. QStringList topicsToConsume;
  35. /** class variable indicating the topics */
  36. QString filterToConsume;
  37. /** class variable keeping number of asynchronous message */
  38. int asynchMessages;
  39. /** class variable keeping number of synchronous message */
  40. int synchMessages;
  41. /**
  42. * class variable indication the number of synchronous messages to be
  43. * received
  44. */
  45. int numSyncMessages;
  46. /**
  47. * class variable indication the number of asynchronous messages to be
  48. * received
  49. */
  50. int numAsyncMessages;
  51. bool error;
  52. ctkRuntimeException exc;
  53. QMutex mutex;
  54. public:
  55. /**
  56. * Constructor creates a consumer service
  57. *
  58. * @param bundleContext
  59. * @param topics
  60. * @param numSyncMsg
  61. * number of synchronous messages to be received
  62. * @param numAsyncMsg
  63. * number of asynchronous messages to be received
  64. * @param name
  65. * name of the Consumer
  66. * @param id
  67. */
  68. ctkEAScenario4EventConsumer(ctkPluginContext* pluginContext, const QStringList topics,
  69. int numSyncMsg, int numAsyncMsg, const QString& filter);
  70. void runTest();
  71. void cleanup();
  72. /**
  73. * This method takes events from the event admin service.
  74. */
  75. void handleEvent(const ctkEvent& event);
  76. };
  77. class ctkEAScenario4EventPublisher : public QObject
  78. {
  79. Q_OBJECT
  80. private:
  81. /** A reference to a service */
  82. ctkServiceReference serviceReference;
  83. /** The admin which delivers the events */
  84. ctkEventAdmin* eventAdmin;
  85. /** class variable holding plugin context */
  86. ctkPluginContext* context;
  87. /** variable holding messages to send */
  88. int messageTosend;
  89. /** variable holding the topic to use */
  90. QString topicToSend;
  91. /** variable holding the parameters to use */
  92. ctkDictionary propertiesToSend;
  93. QThread thread;
  94. protected slots:
  95. void sendEvents();
  96. void postEvents();
  97. public:
  98. ctkEAScenario4EventPublisher(ctkPluginContext* context, const QString& name,
  99. const QString& topic, const ctkDictionary& props,
  100. int id, int numOfMessage);
  101. void runTest();
  102. };
  103. /**
  104. * Test suite for testing the requirements specified in the test specification
  105. * for the EventAdmin service.
  106. *
  107. * Check the filter both faulty and correctly, also check if the events are
  108. * received in the order that they were sent both synchronously and
  109. * asynchronously.
  110. */
  111. class ctkEAScenario4TestSuite : public QObject, public ctkTestSuiteInterface
  112. {
  113. Q_OBJECT
  114. Q_INTERFACES(ctkTestSuiteInterface)
  115. private:
  116. /** plugin context variable */
  117. ctkPluginContext* pluginContext;
  118. long eventPluginId;
  119. QList<ctkEAScenario4EventConsumer*> eventConsumers;
  120. QList<ctkEAScenario4EventPublisher*> eventPublishers;
  121. public:
  122. /**
  123. * Constructor for the TestSuite class.
  124. *
  125. * @param context
  126. * the handle to the frame work
  127. */
  128. ctkEAScenario4TestSuite(ctkPluginContext* context, long eventPluginId);
  129. private slots:
  130. void initTestCase();
  131. void cleanupTestCase();
  132. void testRegisterConsumer();
  133. void testPublishEvents();
  134. };
  135. #endif // CTKEASCENARIO4TESTSUITE_P_H