1 /*=============================================================================
2 
3   Library: CTK
4 
5   Copyright (c) German Cancer Research Center,
6     Division of Medical and Biological Informatics
7 
8   Licensed under the Apache License, Version 2.0 (the "License");
9   you may not use this file except in compliance with the License.
10   You may obtain a copy of the License at
11 
12     http://www.apache.org/licenses/LICENSE-2.0
13 
14   Unless required by applicable law or agreed to in writing, software
15   distributed under the License is distributed on an "AS IS" BASIS,
16   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   See the License for the specific language governing permissions and
18   limitations under the License.
19 
20 =============================================================================*/
21 
22 
23 #ifndef CTKSERVICELISTENERTESTSUITE_P_H
24 #define CTKSERVICELISTENERTESTSUITE_P_H
25 
26 #include <QObject>
27 
28 #include <ctkTestSuiteInterface.h>
29 #include <ctkServiceEvent.h>
30 
31 class ctkPlugin;
32 class ctkPluginContext;
33 
34 class ctkServiceListenerTestSuite : public QObject,
35     public ctkTestSuiteInterface
36 {
37   Q_OBJECT
38   Q_INTERFACES(ctkTestSuiteInterface)
39 
40 public:
41     ctkServiceListenerTestSuite(ctkPluginContext* pc);
42 
43 private Q_SLOTS:
44 
45     void initTestCase();
46     void cleanupTestCase();
47 
48     // test functions
49 
50     // Checks that the correct service events
51     // are sent to a registered service listener.
52     // Case where the plugin does not unregister its
53     // service in the stop()-method.
54     void frameSL05a();
55 
56     // Checks that the correct service events
57     // are sent to a registered service listener.
58     // Case where the plugin unregisters its service
59     // in the stop()-method.
60     void frameSL10a();
61 
62 //    void frameSL15a();
63 //    void frameSL20a();
64     void frameSL25a();
65 
66 private:
67 
68     ctkPluginContext* pc;
69     QSharedPointer<ctkPlugin> p;
70 
71     QSharedPointer<ctkPlugin> pA;
72     QSharedPointer<ctkPlugin> pA2;
73     QSharedPointer<ctkPlugin> pSL1;
74     QSharedPointer<ctkPlugin> pSL3;
75     QSharedPointer<ctkPlugin> pSL4;
76 
77     bool runStartStopTest(
78       const QString& tcName, int cnt, QSharedPointer<ctkPlugin> targetPlugin,
79       const QList<ctkServiceEvent::Type>& events);
80 };
81 
82 class ctkServiceListener : public QObject
83 {
84   Q_OBJECT
85 
86 private:
87 
88   friend class ctkServiceListenerTestSuite;
89 
90   const bool checkUsingPlugins;
91   QList<ctkServiceEvent> events;
92 
93   bool teststatus;
94 
95   ctkPluginContext* pc;
96 
97 public:
98 
99   ctkServiceListener(ctkPluginContext* pc, bool checkUsingPlugins = true);
100 
101   void clearEvents();
102 
103   bool checkEvents(const QList<ctkServiceEvent::Type>& eventTypes);
104 
105 protected Q_SLOTS:
106 
107   void serviceChanged(const ctkServiceEvent& evt);
108 
109 private:
110 
111   void printUsingPlugins(const ctkServiceReference& sr, const QString& caption);
112 
113   // Print expected and actual service events.
114   void dumpEvents(const QList<ctkServiceEvent::Type>& eventTypes);
115 
116 }; // end of class ctkServiceListener
117 
118 
119 
120 #endif // CTKSERVICELISTENERTESTSUITE_P_H
121