ctkEAScenario2TestSuite_p.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 CTKEASCENARIO2TESTSUITE_P_H
  16. #define CTKEASCENARIO2TESTSUITE_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 ctkEAScenario2EventConsumer : 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 */
  34. QStringList topicsToConsume;
  35. /** class variable keeping number of asynchronus message */
  36. int asynchMessages;
  37. /** class variable keeping number of synchronus message */
  38. int synchMessages;
  39. /** class variable indication the number of synchronous messages to be received */
  40. int numSyncMessages;
  41. /** class variable indication the number of asynchronous messages to be received */
  42. int numAsyncMessages;
  43. bool error;
  44. ctkRuntimeException exc;
  45. QMutex mutex;
  46. public:
  47. /**
  48. * Constructor creates a consumer service
  49. */
  50. ctkEAScenario2EventConsumer(ctkPluginContext* pluginContext, const QStringList& topics,
  51. int numSyncMsg, int numAsyncMsg);
  52. void runTest();
  53. void cleanup();
  54. /**
  55. * This method takes events from the event admin service.
  56. */
  57. void handleEvent(const ctkEvent& event);
  58. };
  59. class ctkEAScenario2EventPublisher : public QObject
  60. {
  61. Q_OBJECT
  62. private:
  63. /** A reference to a service */
  64. ctkServiceReference serviceReference;
  65. /** The admin which delivers the events */
  66. ctkEventAdmin* eventAdmin;
  67. /** class variable holding plugin context */
  68. ctkPluginContext* context;
  69. /** variable holding messages to send */
  70. int messageTosend;
  71. /** variable holding the topic to send */
  72. QStringList topicsToSend;
  73. QThread thread;
  74. public:
  75. ctkEAScenario2EventPublisher(ctkPluginContext* context,
  76. const QString& name, const QStringList topics,
  77. int id, int numOfMessage);
  78. void runTest();
  79. protected Q_SLOTS:
  80. void sendEvents();
  81. void postEvents();
  82. };
  83. /**
  84. * Test suite for testing the requirements specified in the test specification
  85. * for the EventAdmin service.
  86. *
  87. * Check the Topic sorting of events, both synchronous and asynchronous.
  88. *
  89. */
  90. class ctkEAScenario2TestSuite : public QObject, public ctkTestSuiteInterface
  91. {
  92. Q_OBJECT
  93. Q_INTERFACES(ctkTestSuiteInterface)
  94. private:
  95. /** plugin context variable */
  96. ctkPluginContext* pluginContext;
  97. long eventPluginId;
  98. QList<ctkEAScenario2EventConsumer*> eventConsumers;
  99. ctkEAScenario2EventPublisher* eventPublisher;
  100. public:
  101. /**
  102. * Constructor for the TestSuite class.
  103. *
  104. * @param context the handle to the frame work
  105. * @param eventPluginId The id of the plugin implementing the EventAdmin spec
  106. */
  107. ctkEAScenario2TestSuite(ctkPluginContext* context, long eventPluginId);
  108. private Q_SLOTS:
  109. void initTestCase();
  110. void cleanupTestCase();
  111. void testRegisterConsumer();
  112. void testPublishEvents();
  113. };
  114. #endif // CTKEASCENARIO2TESTSUITE_P_H