Browse Source

Added many more service listener tests.

Sascha Zelzer 14 years ago
parent
commit
67d076b06c
28 changed files with 1127 additions and 3 deletions
  1. 1 1
      Libs/PluginFramework/Testing/FrameworkTest/ctkPluginFrameworkTestSuite.cpp
  2. 249 0
      Libs/PluginFramework/Testing/FrameworkTest/ctkServiceListenerTestSuite.cpp
  3. 16 2
      Libs/PluginFramework/Testing/FrameworkTest/ctkServiceListenerTestSuite_p.h
  4. 4 0
      Libs/PluginFramework/Testing/TestPlugins/CMakeLists.txt
  5. 30 0
      Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/CMakeLists.txt
  6. 43 0
      Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/ctkTestPluginA.cpp
  7. 40 0
      Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/ctkTestPluginAActivator.cpp
  8. 48 0
      Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/ctkTestPluginAActivator_p.h
  9. 31 0
      Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/ctkTestPluginAService.h
  10. 48 0
      Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/ctkTestPluginA_p.h
  11. 7 0
      Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/manifest_headers.cmake
  12. 9 0
      Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/target_libraries.cmake
  13. 34 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/CMakeLists.txt
  14. 92 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/ctkActivatorSL1.cpp
  15. 67 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/ctkActivatorSL1_p.h
  16. 38 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/ctkFooService.h
  17. 7 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/manifest_headers.cmake
  18. 9 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/target_libraries.cmake
  19. 34 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL3_test/CMakeLists.txt
  20. 91 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL3_test/ctkActivatorSL3.cpp
  21. 67 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL3_test/ctkActivatorSL3_p.h
  22. 8 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL3_test/manifest_headers.cmake
  23. 9 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL3_test/target_libraries.cmake
  24. 34 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL4_test/CMakeLists.txt
  25. 50 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL4_test/ctkActivator.cpp
  26. 44 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL4_test/ctkActivator_p.h
  27. 8 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL4_test/manifest_headers.cmake
  28. 9 0
      Libs/PluginFramework/Testing/TestPlugins/pluginSL4_test/target_libraries.cmake

+ 1 - 1
Libs/PluginFramework/Testing/FrameworkTest/ctkPluginFrameworkTestSuite.cpp

@@ -170,7 +170,7 @@ void ctkPluginFrameworkTestSuite::frame020a()
     pc->getServiceReference("ctkTestPluginAService");
     QFAIL("framework test plugin, service from test plugin A unexpectedly found");
   }
-  catch (ctkServiceException& e)
+  catch (ctkServiceException& /*e*/)
   {
 
   }

+ 249 - 0
Libs/PluginFramework/Testing/FrameworkTest/ctkServiceListenerTestSuite.cpp

@@ -27,6 +27,7 @@
 #include <ctkPluginException.h>
 #include <ctkPluginConstants.h>
 #include <ctkServiceEvent.h>
+#include <ctkServiceException.h>
 
 #include <ctkPluginFrameworkTestUtil.h>
 
@@ -41,11 +42,23 @@ void ctkServiceListenerTestSuite::initTestCase()
 {
   pA = ctkPluginFrameworkTestUtil::installPlugin(pc, "pluginA_test");
   QVERIFY(pA);
+  pA2 = ctkPluginFrameworkTestUtil::installPlugin(pc, "pluginA2_test");
+  QVERIFY(pA2);
+  pSL1 = ctkPluginFrameworkTestUtil::installPlugin(pc, "pluginSL1_test");
+  QVERIFY(pSL1);
+  pSL3 = ctkPluginFrameworkTestUtil::installPlugin(pc, "pluginSL3_test");
+  QVERIFY(pSL3);
+  pSL4 = ctkPluginFrameworkTestUtil::installPlugin(pc, "pluginSL4_test");
+  QVERIFY(pSL4);
 }
 
 void ctkServiceListenerTestSuite::cleanupTestCase()
 {
   pA->uninstall();
+  pA2->uninstall();
+  pSL1->uninstall();
+  pSL3->uninstall();
+  pSL4->uninstall();
 }
 
 void ctkServiceListenerTestSuite::frameSL05a()
@@ -61,6 +74,242 @@ void ctkServiceListenerTestSuite::frameSL05a()
   QVERIFY(teststatus);
 }
 
+void ctkServiceListenerTestSuite::frameSL10a()
+{
+  int cnt = 1;
+
+  QList<ctkServiceEvent::Type> events;
+  events << ctkServiceEvent::REGISTERED;
+  events << ctkServiceEvent::UNREGISTERING;
+  QVERIFY(runStartStopTest("FRAMEsl10A", cnt, pA2,events));
+}
+
+void ctkServiceListenerTestSuite::frameSL25a()
+{
+  ctkServiceListener sListen(pc, false);
+  try
+  {
+    pc->connectServiceListener(&sListen, "serviceChanged");
+  }
+  catch (const std::logic_error& ise)
+  {
+    qDebug() << "service listener registration failed " << ise.what();
+    QFAIL("service listener registration failed");
+  }
+
+  QList<ctkServiceEvent::Type> expectedServiceEventTypes;
+
+  // Startup
+  expectedServiceEventTypes << ctkServiceEvent::REGISTERED; // ctkActivator at start of pSL1
+  expectedServiceEventTypes << ctkServiceEvent::REGISTERED; // ctkFooService at start of pSL4
+  expectedServiceEventTypes << ctkServiceEvent::REGISTERED; // ctkActivator at start of pSL3
+
+  // Stop pSL4
+  expectedServiceEventTypes << ctkServiceEvent::UNREGISTERING; // ctkFooService at first stop of pSL4
+
+  // Shutdown
+  expectedServiceEventTypes << ctkServiceEvent::UNREGISTERING; // ctkActivator at stop of pSL1
+  expectedServiceEventTypes << ctkServiceEvent::UNREGISTERING; // Activator at stop of pSL3
+
+
+  // Start pSL1 to ensure that the Service interface is available.
+  try
+  {
+    qDebug() << "Starting pSL1: " << pSL1;
+    pSL1->start();
+  }
+  catch (const ctkPluginException& pex)
+  {
+    qDebug() << "Failed to start plugin, got exception:" << pex;
+    QFAIL("Failed to start bundle, got exception: ctkPluginException");
+  }
+  catch (const std::exception& e)
+  {
+    qDebug() << "Failed to start plugin, got exception" << e.what();
+    QFAIL("Failed to start plugin, got exception: std::exception");
+  }
+
+  // Start pSL4 that will require the serivce interface and publish
+  // ctkFooService
+  try
+  {
+    qDebug() << "Starting pSL4:" << pSL4;
+    pSL4->start();
+  }
+  catch (const ctkPluginException& pex)
+  {
+    qDebug() << "Failed to start plugin, got exception:" << pex;
+    QFAIL("Failed to start bundle, got exception: ctkPluginException");
+  }
+  catch (const std::exception& e)
+  {
+    qDebug() << "Failed to start plugin, got exception" << e.what();
+    QFAIL("Failed to start plubin, got exception.");
+  }
+
+  // Start buSL3 that will require the serivce interface and get the service
+  try
+  {
+    qDebug() << "Starting pSL3:" << pSL3;
+    pSL3->start();
+  }
+  catch (const ctkPluginException& pex)
+  {
+    qDebug() << "Failed to start plugin, got exception:" << pex;
+    QFAIL("Failed to start plugin, got exception: ctkPluginException");
+  }
+  catch (const std::exception& e)
+  {
+    qDebug() << "Failed to start plugin, got exception" << e.what();
+    QFAIL("Failed to start plugin, got exception.");
+  }
+
+  // sleep to stabelize state.
+  QTest::qWait(300);
+
+  // Check that pSL3 has been notified about the ctkFooService.
+  qDebug() << "Check that ctkFooService is added to service tracker in pSL3";
+  try
+  {
+    ctkServiceReference pSL3SR
+        = pc->getServiceReference("ctkActivatorSL3");
+    QObject* pSL3Activator = pc->getService(pSL3SR);
+    QVERIFY2(pSL3Activator, "No activator service.");
+
+    QVariant serviceAddedField3 = pSL3Activator->property("serviceAdded");
+    QVERIFY2(serviceAddedField3.isValid() && serviceAddedField3.toBool(),
+             "pluginSL3 not notified about presence of ctkFooService");
+    qDebug() << "pSL3Activator::serviceAdded is true";
+    pc->ungetService(pSL3SR);
+  }
+  catch (const ctkServiceException& se)
+  {
+    qDebug() << "Failed to get service reference:" << se;
+    QFAIL("No activator service reference.");
+  }
+
+  // Check that pSL1 has been notified about the ctkFooService.
+  qDebug() << "Check that ctkFooService is added to service tracker in pSL1";
+  try
+  {
+    ctkServiceReference pSL1SR
+        = pc->getServiceReference("ctkActivatorSL1");
+    QObject* pSL1Activator = pc->getService(pSL1SR);
+    QVERIFY2(pSL1Activator, "No activator service.");
+
+    QVariant serviceAddedField = pSL1Activator->property("serviceAdded");
+    QVERIFY2(serviceAddedField.isValid() && serviceAddedField.toBool(),
+             "bundleSL1 not notified about presence of ctkFooService");
+    qDebug() << "pSL1Activator::serviceAdded is true";
+    pc->ungetService(pSL1SR);
+  }
+  catch (const ctkServiceException& se)
+  {
+    qDebug() << "Failed to get service reference:" << se;
+    QFAIL("No activator service reference.");
+  }
+
+  // Stop the service provider: pSL4
+  try
+  {
+    qDebug() << "Stop pSL4:" << pSL4;
+    pSL4->stop();
+  }
+  catch (const ctkPluginException& pex)
+  {
+    qDebug() << "Failed to stop plugin, got exception:" << pex;
+    QFAIL("Failed to stop bundle, got exception: ctkPluginException");
+  }
+  catch (const std::exception& e)
+  {
+    qDebug() << "Failed to stop plugin, got exception:" << e.what();
+    QFAIL("Failed to stop plugin, got exception.");
+  }
+
+  // sleep to stabelize state.
+  QTest::qWait(300);
+
+
+  // Check that pSL3 has been notified about the removal of ctkFooService.
+  qDebug() << "Check that ctkFooService is removed from service tracker in pSL3";
+  try
+  {
+    ctkServiceReference pSL3SR
+        = pc->getServiceReference("ctkActivatorSL3");
+    QObject* pSL3Activator = pc->getService(pSL3SR);
+    QVERIFY2(pSL3Activator, "No activator service.");
+    QVariant serviceRemovedField3 = pSL3Activator->property("serviceRemoved");
+    QVERIFY2(serviceRemovedField3.isValid() && serviceRemovedField3.toBool(),
+             "pluginSL3 not notified about removal of ctkFooService");
+    qDebug() << "pSL3Activator::serviceRemoved is true";
+    pc->ungetService(pSL3SR);
+  }
+  catch (const ctkServiceException& se)
+  {
+    qDebug() << "Failed to get service reference:" << se;
+    QFAIL("No activator service reference.");
+  }
+
+  // Stop pSL1
+  try
+  {
+    qDebug() << "Stop pSL1:" << pSL1;
+    pSL1->stop();
+  }
+  catch (const ctkPluginException& pex)
+  {
+    qDebug() << "Failed to stop plugin, got exception:" << pex;
+    QFAIL("Failed to stop bundle, got exception: ctkPluginException");
+  }
+  catch (const std::exception& e)
+  {
+    qDebug() << "Failed to stop plugin, got exception" << e.what();
+    QFAIL("Failed to stop plugin, got exception.");
+  }
+
+  // Stop pSL3
+  try
+  {
+    qDebug() << "Stop pSL3:" << pSL3;
+    pSL3->stop();
+  }
+  catch (const ctkPluginException& pex)
+  {
+    qDebug() << "Failed to stop plugin, got exception:" << pex;
+    QFAIL("Failed to stop plugin, got exception: ctkPluginException");
+  }
+  catch (const std::exception& e)
+  {
+    qDebug() << "Failed to stop plugin, got exception" << e.what();
+    QFAIL("Failed to stop plugin, got exception.");
+  }
+
+
+  // sleep to stabelize state.
+  QTest::qWait(300);
+
+  // Check service events seen by this class
+  qDebug() << "Checking ServiceEvents(ServiceListener):";
+  if (!sListen.checkEvents(expectedServiceEventTypes))
+  {
+    qDebug() << "Service listener event notification error";
+    QFAIL("Service listener event notification error");
+  }
+
+
+  QVERIFY2(sListen.teststatus, "Service listener checks");
+  try 
+  {
+    //pc->disconnectServiceListener(&sListen, "serviceChanged");
+    sListen.clearEvents();
+  } 
+  catch (const std::logic_error& ise)
+  {
+    qDebug() << ise.what();
+    QFAIL("service listener removal failed ");
+  }
+}
+
 bool ctkServiceListenerTestSuite::runStartStopTest(
   const QString& tcName, int cnt, QSharedPointer<ctkPlugin> targetPlugin,
   const QList<ctkServiceEvent::Type>& events)

+ 16 - 2
Libs/PluginFramework/Testing/FrameworkTest/ctkServiceListenerTestSuite_p.h

@@ -45,11 +45,22 @@ private slots:
     void cleanupTestCase();
 
     // test functions
+
+    // Checks that the correct service events
+    // are sent to a registered service listener.
+    // Case where the plugin does not unregister its
+    // service in the stop()-method.
     void frameSL05a();
-//    void frameSL10a();
+
+    // Checks that the correct service events
+    // are sent to a registered service listener.
+    // Case where the plugin unregisters its service
+    // in the stop()-method.
+    void frameSL10a();
+
 //    void frameSL15a();
 //    void frameSL20a();
-//    void frameSL25a();
+    void frameSL25a();
 
 private:
 
@@ -58,6 +69,9 @@ private:
 
     QSharedPointer<ctkPlugin> pA;
     QSharedPointer<ctkPlugin> pA2;
+    QSharedPointer<ctkPlugin> pSL1;
+    QSharedPointer<ctkPlugin> pSL3;
+    QSharedPointer<ctkPlugin> pSL4;
 
     bool runStartStopTest(
       const QString& tcName, int cnt, QSharedPointer<ctkPlugin> targetPlugin,

+ 4 - 0
Libs/PluginFramework/Testing/TestPlugins/CMakeLists.txt

@@ -1,5 +1,9 @@
 set(test_plugins
   pluginA_test
+  pluginA2_test
+  pluginSL1_test
+  pluginSL3_test
+  pluginSL4_test
 )
 
 foreach(test_plugin ${test_plugins})

+ 30 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/CMakeLists.txt

@@ -0,0 +1,30 @@
+PROJECT(pluginA2_test)
+
+SET(PLUGIN_export_directive "pluginA2_test_EXPORT")
+
+SET(PLUGIN_SRCS
+  ctkTestPluginA.cpp
+  ctkTestPluginAActivator.cpp
+  ctkTestPluginAService.h
+)
+
+SET(PLUGIN_MOC_SRCS
+  ctkTestPluginA_p.h
+  ctkTestPluginAActivator_p.h
+)
+
+SET(PLUGIN_resources
+  
+)
+
+ctkMacroGetTargetLibraries(PLUGIN_target_libraries)
+
+ctkMacroBuildPlugin(
+  NAME ${PROJECT_NAME}
+  EXPORT_DIRECTIVE ${PLUGIN_export_directive}
+  SRCS ${PLUGIN_SRCS}
+  MOC_SRCS ${PLUGIN_MOC_SRCS}
+  RESOURCES ${PLUGIN_resources}
+  TARGET_LIBRARIES ${PLUGIN_target_libraries}
+  TEST_PLUGIN
+)

+ 43 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/ctkTestPluginA.cpp

@@ -0,0 +1,43 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#include "ctkTestPluginA_p.h"
+
+#include <ctkPluginContext.h>
+#include <ctkServiceRegistration.h>
+
+#include <QStringList>
+
+ctkTestPluginA::ctkTestPluginA(ctkPluginContext* pc)
+{
+  sr = pc->registerService(QStringList("ctkTestPluginAService"), this);
+}
+
+void ctkTestPluginA::unregister()
+{
+  if (sr)
+  {
+    sr->unregister();
+  }
+  delete sr;
+  sr = 0;
+}

+ 40 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/ctkTestPluginAActivator.cpp

@@ -0,0 +1,40 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 2010 German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#include "ctkTestPluginAActivator_p.h"
+
+#include <ctkPluginContext.h>
+
+#include <QtPlugin>
+
+void ctkTestPluginAActivator::start(ctkPluginContext* context)
+{
+  s.reset(new ctkTestPluginA(context));
+}
+
+void ctkTestPluginAActivator::stop(ctkPluginContext* context)
+{
+  Q_UNUSED(context)
+  s->unregister();
+}
+
+Q_EXPORT_PLUGIN2(pluginA_test, ctkTestPluginAActivator)

+ 48 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/ctkTestPluginAActivator_p.h

@@ -0,0 +1,48 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+#ifndef CTKTESTPLUGINAACTIVATOR_P_H
+#define CTKTESTPLUGINAACTIVATOR_P_H
+
+#include <QScopedPointer>
+
+#include <ctkPluginActivator.h>
+
+#include "ctkTestPluginA_p.h"
+
+class ctkTestPluginAActivator : public QObject,
+                                public ctkPluginActivator
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkPluginActivator)
+
+public:
+
+  void start(ctkPluginContext* context);
+  void stop(ctkPluginContext* context);
+
+private:
+
+  QScopedPointer<ctkTestPluginA> s;
+
+};
+
+#endif // CTKTESTPLUGINAACTIVATOR_P_H

+ 31 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/ctkTestPluginAService.h

@@ -0,0 +1,31 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKTESTPLUGINASERVICE_H
+#define CTKTESTPLUGINASERVICE_H
+
+struct ctkTestPluginAService
+{
+  virtual ~ctkTestPluginAService() {}
+};
+
+#endif // CTKTESTPLUGINASERVICE_H

+ 48 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/ctkTestPluginA_p.h

@@ -0,0 +1,48 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKTESTPLUGINA_P_H
+#define CTKTESTPLUGINA_P_H
+
+#include <QObject>
+
+#include "ctkTestPluginAService.h"
+
+class ctkPluginContext;
+class ctkServiceRegistration;
+
+class ctkTestPluginA : public QObject,
+                       public ctkTestPluginAService
+{
+  Q_OBJECT
+
+public:
+    ctkTestPluginA(ctkPluginContext* pc);
+
+    void unregister();
+
+private:
+
+    ctkServiceRegistration* sr;
+};
+
+#endif // CTKTESTPLUGINA_P_H

+ 7 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/manifest_headers.cmake

@@ -0,0 +1,7 @@
+set(Plugin-ActivationPolicy "eager")
+set(Plugin-Name "pluginA_test")
+set(Plugin-Version "1.0.0")
+set(Plugin-Description "Test plugin for framework, pluginA_test")
+set(Plugin-Vendor "CommonTK")
+set(Plugin-ContactAddress "http://www.commontk.org")
+set(Plugin-Category "test")

+ 9 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginA2_test/target_libraries.cmake

@@ -0,0 +1,9 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+# 
+# This file should list the libraries required to build the current CTK plugin.
+# 
+
+SET(target_libraries
+  CTKPluginFramework
+  )

+ 34 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/CMakeLists.txt

@@ -0,0 +1,34 @@
+PROJECT(pluginSL1_test)
+
+SET(PLUGIN_export_directive "pluginSL1_test_EXPORT")
+
+SET(PLUGIN_SRCS
+  ctkActivatorSL1.cpp
+)
+
+# Files which should be processed by Qts moc
+SET(PLUGIN_MOC_SRCS
+  ctkActivatorSL1_p.h
+)
+
+# Qt Designer files which should be processed by Qts uic
+SET(PLUGIN_UI_FORMS
+)
+
+# QRC Files which should be compiled into the plugin
+SET(PLUGIN_resources
+)
+
+#Compute the plugin dependencies
+ctkMacroGetTargetLibraries(PLUGIN_target_libraries)
+
+ctkMacroBuildPlugin(
+  NAME ${PROJECT_NAME}
+  EXPORT_DIRECTIVE ${PLUGIN_export_directive}
+  SRCS ${PLUGIN_SRCS}
+  MOC_SRCS ${PLUGIN_MOC_SRCS}
+  UI_FORMS ${PLUGIN_UI_FORMS}
+  RESOURCES ${PLUGIN_resources}
+  TARGET_LIBRARIES ${PLUGIN_target_libraries}
+  TEST_PLUGIN
+)

+ 92 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/ctkActivatorSL1.cpp

@@ -0,0 +1,92 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#include "ctkActivatorSL1_p.h"
+#include "ctkFooService.h"
+
+#include <QtPlugin>
+#include <QStringList>
+
+ctkActivatorSL1::ctkActivatorSL1()
+  : _serviceAdded(false), _serviceRemoved(false),
+    context(0)
+{
+}
+
+ctkActivatorSL1::~ctkActivatorSL1()
+{
+  
+}
+
+void ctkActivatorSL1::start(ctkPluginContext* context)
+{
+  this->context = context;
+
+  context->registerService(QStringList(this->metaObject()->className()), this);
+
+  tracker.reset(new ctkServiceTracker(context, "ctkFooService", this));
+  tracker->open();
+}
+
+void ctkActivatorSL1::stop(ctkPluginContext* context)
+{
+  Q_UNUSED(context)
+  tracker->close();
+}
+
+bool ctkActivatorSL1::serviceAdded() const
+{
+  return _serviceAdded;
+}
+
+bool ctkActivatorSL1::serviceRemoved() const
+{
+  return _serviceRemoved;
+}
+
+QObject* ctkActivatorSL1::addingService(const ctkServiceReference& reference)
+{
+  _serviceAdded = true;
+  qDebug() << "Adding reference =" << reference;
+
+  QObject* serviceObject = context->getService(reference);
+  ctkFooService* fooService = qobject_cast<ctkFooService*>(serviceObject);
+  fooService->foo();
+  return serviceObject;
+}
+
+void ctkActivatorSL1::modifiedService(const ctkServiceReference& reference, QObject* service)
+{
+  Q_UNUSED(reference)
+  Q_UNUSED(service)
+}
+
+void ctkActivatorSL1::removedService(const ctkServiceReference& reference, QObject* service)
+{
+  Q_UNUSED(service)
+  _serviceRemoved = true;
+  qDebug() << "Removing reference =" << reference;
+}
+
+Q_EXPORT_PLUGIN2(pluginSL1_test, ctkActivatorSL1)
+
+

+ 67 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/ctkActivatorSL1_p.h

@@ -0,0 +1,67 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKACTIVATORSL1_P_H
+#define CTKACTIVATORSL1_P_H
+
+#include <ctkPluginActivator.h>
+#include <ctkServiceTrackerCustomizer.h>
+#include <ctkServiceTracker.h>
+
+#include <QScopedPointer>
+
+class ctkActivatorSL1 :
+    public QObject, public ctkPluginActivator,
+    public ctkServiceTrackerCustomizer
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkPluginActivator)
+  Q_PROPERTY(bool serviceAdded READ serviceAdded)
+  Q_PROPERTY(bool serviceRemoved READ serviceRemoved)
+
+public:
+
+  ctkActivatorSL1();
+  ~ctkActivatorSL1();
+
+  void start(ctkPluginContext* context);
+  void stop(ctkPluginContext* context);
+
+  bool serviceAdded() const;
+  bool serviceRemoved() const;
+
+  QObject* addingService(const ctkServiceReference& reference);
+  void modifiedService(const ctkServiceReference& reference, QObject* service);
+  void removedService(const ctkServiceReference& reference, QObject* service);
+
+private:
+
+  bool _serviceAdded;
+  bool _serviceRemoved;
+
+
+  QScopedPointer<ctkServiceTracker> tracker;
+  ctkPluginContext* context;
+
+}; // ctkActivatorSL1
+
+#endif // CTKACTIVATORSL1_P_H

+ 38 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/ctkFooService.h

@@ -0,0 +1,38 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKFOOSERVICE_H
+#define CTKFOOSERVICE_H
+
+class ctkFooService
+{
+ 
+public:
+  
+  virtual ~ctkFooService() {}
+  virtual void foo() = 0;
+
+};
+
+Q_DECLARE_INTERFACE(ctkFooService, "org.commontk.test.FooService")
+
+#endif // CTKFOOSERVICE_H

+ 7 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/manifest_headers.cmake

@@ -0,0 +1,7 @@
+set(Plugin-ActivationPolicy "eager")
+set(Plugin-Name "pluginSL1")
+set(Plugin-Version "1.0.0")
+set(Plugin-Description "Test plugin for framework, pluginSL1_test")
+set(Plugin-Vendor "CommonTK")
+set(Plugin-ContactAddress "http://www.commontk.org")
+set(Plugin-Category "test")

+ 9 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL1_test/target_libraries.cmake

@@ -0,0 +1,9 @@
+# See CMake/ctkMacroGetTargetLibraries.cmake
+#
+# This file should list the libraries required to build the current CTK plugin.
+# For specifying required plugins, see the manifest_headers.cmake file.
+#
+
+SET(target_libraries
+  CTKPluginFramework
+)

+ 34 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL3_test/CMakeLists.txt

@@ -0,0 +1,34 @@
+PROJECT(pluginSL3_test)
+
+SET(PLUGIN_export_directive "pluginSL3_test_EXPORT")
+
+SET(PLUGIN_SRCS
+  ctkActivatorSL3.cpp
+)
+
+# Files which should be processed by Qts moc
+SET(PLUGIN_MOC_SRCS
+  ctkActivatorSL3_p.h
+)
+
+# Qt Designer files which should be processed by Qts uic
+SET(PLUGIN_UI_FORMS
+)
+
+# QRC Files which should be compiled into the plugin
+SET(PLUGIN_resources
+)
+
+# Compute the plugin dependencies
+ctkMacroGetTargetLibraries(PLUGIN_target_libraries)
+
+ctkMacroBuildPlugin(
+  NAME ${PROJECT_NAME}
+  EXPORT_DIRECTIVE ${PLUGIN_export_directive}
+  SRCS ${PLUGIN_SRCS}
+  MOC_SRCS ${PLUGIN_MOC_SRCS}
+  UI_FORMS ${PLUGIN_UI_FORMS}
+  RESOURCES ${PLUGIN_resources}
+  TARGET_LIBRARIES ${PLUGIN_target_libraries}
+  TEST_PLUGIN
+)

+ 91 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL3_test/ctkActivatorSL3.cpp

@@ -0,0 +1,91 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#include "ctkActivatorSL3_p.h"
+
+#include <ctkFooService.h>
+
+#include <QtPlugin>
+#include <QStringList>
+
+ctkActivatorSL3::ctkActivatorSL3()
+  : _serviceAdded(false), _serviceRemoved(false), context(0)
+{
+}
+
+ctkActivatorSL3::~ctkActivatorSL3()
+{
+  
+}
+
+void ctkActivatorSL3::start(ctkPluginContext* context)
+{
+  this->context = context;
+
+  context->registerService(QStringList(this->metaObject()->className()), this);
+  tracker.reset(new ctkServiceTracker(context, "ctkFooService", this));
+  tracker->open();
+}
+
+void ctkActivatorSL3::stop(ctkPluginContext* context)
+{
+  Q_UNUSED(context)
+  tracker->close();
+}
+
+bool ctkActivatorSL3::serviceAdded() const
+{
+  return _serviceAdded;
+}
+
+bool ctkActivatorSL3::serviceRemoved() const
+{
+  return _serviceRemoved;
+}
+
+QObject* ctkActivatorSL3::addingService(const ctkServiceReference& reference)
+{
+  _serviceAdded = true;
+  qDebug() << "SL3: Adding reference =" << reference;
+
+  QObject* serviceObject = context->getService(reference);
+  ctkFooService* fooService = qobject_cast<ctkFooService*>(serviceObject);
+  fooService->foo();
+  return serviceObject;
+}
+
+void ctkActivatorSL3::modifiedService(const ctkServiceReference& reference, QObject* service)
+{
+  Q_UNUSED(reference)
+  Q_UNUSED(service)
+}
+
+void ctkActivatorSL3::removedService(const ctkServiceReference& reference, QObject* service)
+{
+  Q_UNUSED(service)
+  _serviceRemoved = true;
+  qDebug() << "SL3: Removing reference =" << reference;
+}
+
+Q_EXPORT_PLUGIN2(pluginSL3_test, ctkActivatorSL3)
+
+

+ 67 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL3_test/ctkActivatorSL3_p.h

@@ -0,0 +1,67 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKACTIVATORSL3_P_H
+#define CTKACTIVATORSL3_P_H
+
+#include <ctkPluginActivator.h>
+#include <ctkServiceTrackerCustomizer.h>
+#include <ctkServiceTracker.h>
+
+#include <QScopedPointer>
+
+class ctkActivatorSL3 :
+    public QObject, public ctkPluginActivator,
+    public ctkServiceTrackerCustomizer
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkPluginActivator)
+  Q_PROPERTY(bool serviceAdded READ serviceAdded)
+  Q_PROPERTY(bool serviceRemoved READ serviceRemoved)
+
+public:
+
+  ctkActivatorSL3();
+  ~ctkActivatorSL3();
+
+  void start(ctkPluginContext* context);
+  void stop(ctkPluginContext* context);
+
+  bool serviceAdded() const;
+  bool serviceRemoved() const;
+
+  QObject* addingService(const ctkServiceReference& reference);
+  void modifiedService(const ctkServiceReference& reference, QObject* service);
+  void removedService(const ctkServiceReference& reference, QObject* service);
+
+private:
+
+  bool _serviceAdded;
+  bool _serviceRemoved;
+
+  QScopedPointer<ctkServiceTracker> tracker;
+  ctkPluginContext* context;
+
+
+}; // ctkActivatorSL3
+
+#endif // CTKACTIVATORSL3_P_H

+ 8 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL3_test/manifest_headers.cmake

@@ -0,0 +1,8 @@
+set(Plugin-ActivationPolicy "eager")
+set(Plugin-Name "pluginSL3")
+set(Plugin-Version "1.0.0")
+set(Plugin-Description "Test plugin for framework, pluginSL3_test")
+set(Plugin-Vendor "CommonTK")
+set(Plugin-ContactAddress "http://www.commontk.org")
+set(Plugin-Category "test")
+set(Require-Plugin pluginSL1.test)

+ 9 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL3_test/target_libraries.cmake

@@ -0,0 +1,9 @@
+# See CMake/ctkMacroGetTargetLibraries.cmake
+#
+# This file should list the libraries required to build the current CTK plugin.
+# For specifying required plugins, see the manifest_headers.cmake file.
+#
+
+SET(target_libraries
+  CTKPluginFramework
+)

+ 34 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL4_test/CMakeLists.txt

@@ -0,0 +1,34 @@
+PROJECT(pluginSL4_test)
+
+SET(PLUGIN_export_directive "pluginSL4_test_EXPORT")
+
+SET(PLUGIN_SRCS
+  ctkActivator.cpp
+)
+
+# Files which should be processed by Qts moc
+SET(PLUGIN_MOC_SRCS
+  ctkActivator_p.h
+)
+
+# Qt Designer files which should be processed by Qts uic
+SET(PLUGIN_UI_FORMS
+)
+
+# QRC Files which should be compiled into the plugin
+SET(PLUGIN_resources
+)
+
+#Compute the plugin dependencies
+ctkMacroGetTargetLibraries(PLUGIN_target_libraries)
+
+ctkMacroBuildPlugin(
+  NAME ${PROJECT_NAME}
+  EXPORT_DIRECTIVE ${PLUGIN_export_directive}
+  SRCS ${PLUGIN_SRCS}
+  MOC_SRCS ${PLUGIN_MOC_SRCS}
+  UI_FORMS ${PLUGIN_UI_FORMS}
+  RESOURCES ${PLUGIN_resources}
+  TARGET_LIBRARIES ${PLUGIN_target_libraries}
+  TEST_PLUGIN
+)

+ 50 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL4_test/ctkActivator.cpp

@@ -0,0 +1,50 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#include "ctkActivator_p.h"
+
+#include <QtPlugin>
+#include <QDebug>
+#include <QStringList>
+
+void ctkActivator::foo()
+{
+  qDebug() << "pluginSL4: Doing foo";
+}
+
+void ctkActivator::start(ctkPluginContext* context)
+{
+  ctkServiceRegistration* registration =
+      context->registerService(QStringList("ctkFooService"), this);
+  qDebug() << "pluginSL4: Registered" << registration;
+}
+
+void ctkActivator::stop(ctkPluginContext* context)
+{
+  Q_UNUSED(context)
+  //unregister will be done automagically
+}
+
+
+Q_EXPORT_PLUGIN2(pluginSL4_test, ctkActivator)
+
+

+ 44 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL4_test/ctkActivator_p.h

@@ -0,0 +1,44 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKACTIVATOR_P_H
+#define CTKACTIVATOR_P_H
+
+#include <ctkPluginActivator.h>
+#include <ctkFooService.h>
+
+class ctkActivator :
+  public QObject, public ctkPluginActivator, public ctkFooService
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkPluginActivator ctkFooService)
+
+public:
+
+  void foo();
+
+  void start(ctkPluginContext* context);
+  void stop(ctkPluginContext* context);
+
+}; // ctkActivator
+
+#endif // CTKACTIVATOR_P_H

+ 8 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL4_test/manifest_headers.cmake

@@ -0,0 +1,8 @@
+set(Plugin-ActivationPolicy "eager")
+set(Plugin-Name "pluginSL4")
+set(Plugin-Version "1.0.0")
+set(Plugin-Description "Test plugin for framework, pluginSL4_test")
+set(Plugin-Vendor "CommonTK")
+set(Plugin-ContactAddress "http://www.commontk.org")
+set(Plugin-Category "test")
+set(Require-Plugin pluginSL1.test)

+ 9 - 0
Libs/PluginFramework/Testing/TestPlugins/pluginSL4_test/target_libraries.cmake

@@ -0,0 +1,9 @@
+# See CMake/ctkMacroGetTargetLibraries.cmake
+#
+# This file should list the libraries required to build the current CTK plugin.
+# For specifying required plugins, see the manifest_headers.cmake file.
+#
+
+SET(target_libraries
+  CTKPluginFramework
+)