ctkEAScenario3TestSuite_p.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 CTKEASCENARIO3TESTSUITE_P_H
  16. #define CTKEASCENARIO3TESTSUITE_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 <ctkException.h>
  24. struct ctkEventAdmin;
  25. class ctkEAScenario3EventConsumer : 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 keeping number of asynchronous message */
  36. int asynchMessages;
  37. /** class variable keeping number of synchronous message */
  38. int synchMessages;
  39. /**
  40. * class variable indication the number of synchronous messages to be
  41. * received
  42. */
  43. int numSyncMessages;
  44. /**
  45. * class variable indication the number of asynchronous messages to be
  46. * received
  47. */
  48. int numAsyncMessages;
  49. bool error;
  50. ctkRuntimeException exc;
  51. QMutex mutex;
  52. public:
  53. /**
  54. * Constructor creates a consumer service
  55. *
  56. * @param bundleContext
  57. * @param topics
  58. * @param numSyncMsg
  59. * number of synchronous messages to be received
  60. * @param numAsyncMsg
  61. * number of asynchronous messages to be received
  62. * @param name
  63. * name of the Consumer
  64. * @param id
  65. */
  66. ctkEAScenario3EventConsumer(ctkPluginContext* pluginContext, const QStringList topics,
  67. int numSyncMsg, int numAsyncMsg);
  68. void runTest();
  69. void cleanup();
  70. /**
  71. * This method takes events from the event admin service.
  72. */
  73. void handleEvent(const ctkEvent& event);
  74. };
  75. class ctkEAScenario3EventPublisher : public QObject
  76. {
  77. Q_OBJECT
  78. private:
  79. /** A reference to a service */
  80. ctkServiceReference serviceReference;
  81. /** The admin which delivers the events */
  82. ctkEventAdmin* eventAdmin;
  83. /** class variable holding plugin context */
  84. ctkPluginContext* context;
  85. /** variable holding messages to send */
  86. int messageTosend;
  87. /** variable holding the topic to use */
  88. QString topicToSend;
  89. QThread thread;
  90. protected Q_SLOTS:
  91. void sendEvents();
  92. void postEvents();
  93. public:
  94. ctkEAScenario3EventPublisher(ctkPluginContext* context, const QString& name,
  95. int id, int numOfMessage, const QString& topic);
  96. void runTest();
  97. };
  98. /**
  99. * Test suite for testing the requirements specified in the test specification
  100. * for the EventAdmin service.
  101. *
  102. * Several minor test of the Topics, this is done both synchronously and
  103. * asynchronously.
  104. */
  105. class ctkEAScenario3TestSuite : public QObject, public ctkTestSuiteInterface
  106. {
  107. Q_OBJECT
  108. Q_INTERFACES(ctkTestSuiteInterface)
  109. private:
  110. /** plugin context variable */
  111. ctkPluginContext* pluginContext;
  112. long eventPluginId;
  113. QList<ctkEAScenario3EventConsumer*> eventConsumers;
  114. QList<ctkEAScenario3EventPublisher*> eventPublishers;
  115. public:
  116. /**
  117. * Constructor for the TestSuite class.
  118. *
  119. * @param context
  120. * the handle to the frame work
  121. */
  122. ctkEAScenario3TestSuite(ctkPluginContext* context, long eventPluginId);
  123. private Q_SLOTS:
  124. void initTestCase();
  125. void cleanupTestCase();
  126. void testRegisterConsumer();
  127. void testPublishEvents();
  128. };
  129. #endif // CTKEASCENARIO3TESTSUITE_P_H