소스 검색

Added a test for plug-in updates.

Sascha Zelzer 13 년 전
부모
커밋
bc9845d96b

+ 1 - 0
Libs/PluginFramework/Testing/CMakeLists.txt

@@ -7,6 +7,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Cpp)
 
 set(fwtest_plugins
   pluginA_test
+  pluginA1_test
   pluginS_test
   pluginA2_test
   pluginD_test

+ 30 - 0
Libs/PluginFramework/Testing/FrameworkTestPlugins/pluginA1_test/CMakeLists.txt

@@ -0,0 +1,30 @@
+project(pluginA1_test)
+
+set(PLUGIN_export_directive "pluginA1_test_EXPORT")
+
+set(PLUGIN_SRCS
+  ctkTestPluginA.cpp
+  ctkTestPluginAActivator.cpp
+  ctkTestPluginAService.h
+)
+
+set(PLUGIN_MOC_SRCS
+  ctkTestPluginA_p.h
+  ctkTestPluginAActivator_p.h
+)
+
+set(PLUGIN_resources
+  
+)
+
+ctkFunctionGetTargetLibraries(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
+)

+ 32 - 0
Libs/PluginFramework/Testing/FrameworkTestPlugins/pluginA1_test/ctkTestPluginA.cpp

@@ -0,0 +1,32 @@
+/*=============================================================================
+
+  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 <QStringList>
+
+ctkTestPluginA::ctkTestPluginA(ctkPluginContext* pc)
+{
+  pc->registerService<ctkTestPluginAService>(this);
+}

+ 42 - 0
Libs/PluginFramework/Testing/FrameworkTestPlugins/pluginA1_test/ctkTestPluginAActivator.cpp

@@ -0,0 +1,42 @@
+/*=============================================================================
+
+  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 "ctkTestPluginA_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)
+}
+
+Q_EXPORT_PLUGIN2(pluginA_test, ctkTestPluginAActivator)

+ 47 - 0
Libs/PluginFramework/Testing/FrameworkTestPlugins/pluginA1_test/ctkTestPluginAActivator_p.h

@@ -0,0 +1,47 @@
+/*=============================================================================
+
+  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 <ctkTestPluginAService.h>
+
+class ctkTestPluginAActivator : public QObject,
+                                public ctkPluginActivator
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkPluginActivator)
+
+public:
+
+  void start(ctkPluginContext* context);
+  void stop(ctkPluginContext* context);
+
+private:
+
+  QScopedPointer<ctkTestPluginAService> s;
+
+};
+
+#endif // CTKTESTPLUGINAACTIVATOR_P_H

+ 35 - 0
Libs/PluginFramework/Testing/FrameworkTestPlugins/pluginA1_test/ctkTestPluginAService.h

@@ -0,0 +1,35 @@
+/*=============================================================================
+
+  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
+
+#include <qglobal.h>
+
+struct ctkTestPluginAService
+{
+  virtual ~ctkTestPluginAService() {}
+};
+
+Q_DECLARE_INTERFACE(ctkTestPluginAService, "org.commontk.pluginAtest.TestPluginAService")
+
+#endif // CTKTESTPLUGINASERVICE_H

+ 42 - 0
Libs/PluginFramework/Testing/FrameworkTestPlugins/pluginA1_test/ctkTestPluginA_p.h

@@ -0,0 +1,42 @@
+/*=============================================================================
+
+  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 ctkTestPluginA : public QObject,
+                       public ctkTestPluginAService
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkTestPluginAService)
+
+public:
+  ctkTestPluginA(ctkPluginContext* pc);
+};
+
+#endif // CTKTESTPLUGINA_P_H

+ 7 - 0
Libs/PluginFramework/Testing/FrameworkTestPlugins/pluginA1_test/manifest_headers.cmake

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

+ 9 - 0
Libs/PluginFramework/Testing/FrameworkTestPlugins/pluginA1_test/target_libraries.cmake

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

+ 94 - 0
Libs/PluginFramework/Testing/org.commontk.pluginfwtest/ctkPluginFrameworkTestSuite.cpp

@@ -27,6 +27,7 @@
 #include <ctkPluginException.h>
 #include <ctkServiceException.h>
 
+#include <QDir>
 #include <QTest>
 #include <QDebug>
 
@@ -455,6 +456,90 @@ void ctkPluginFrameworkTestSuite::frame045a()
 }
 
 //----------------------------------------------------------------------------
+// Reinstalls and the updates testbundle_A.
+// The version is checked to see if an update has been made.
+void ctkPluginFrameworkTestSuite::frame070a()
+{
+  QString pluginA = "pluginA_test";
+  QString pluginA1 = "libpluginA1_test";
+  //InputStream fis;
+  QString versionA;
+  QString versionA1;
+
+  pA.clear();
+
+  clearEvents();
+
+  try
+  {
+    pA = ctkPluginFrameworkTestUtil::installPlugin(pc, pluginA);
+  }
+  catch (const ctkPluginException& pexcA)
+  {
+    qDebug() << "framework test plugin" << pexcA << ":FRAME070A:FAIL";
+  }
+//  catch (const ctkSecurityException& secA)
+//  {
+//    qDebug() << "framework test plugin" << secA << ":FRAME070A:FAIL";
+//    teststatus = false;
+//  }
+
+  QHash<QString,QString> ai = pA->getHeaders();
+  versionA = ai["Plugin-Version"];
+  qDebug() << "Before version =" << versionA;
+
+  QDir testPluginDir(pc->getProperty("pluginfw.testDir").toString());
+  QString pluginA1Path;
+
+  QStringList libSuffixes;
+  libSuffixes << ".so" << ".dll" << ".dylib";
+  foreach(QString libSuffix, libSuffixes)
+  {
+    QFileInfo info(testPluginDir, pluginA1 + libSuffix);
+    if (info.exists())
+    {
+      pluginA1Path = info.absoluteFilePath();
+      break;
+    }
+  }
+
+  if (pluginA1Path.isEmpty())
+  {
+    qDebug() << "Plug-in" << pluginA1 << "not found in" << testPluginDir;
+    QFAIL("Test plug-in not found");
+  }
+
+  QUrl urk = QUrl::fromLocalFile(pluginA1Path);
+  qDebug() << "update from" << urk;
+
+  try
+  {
+    pA->update(urk);
+  }
+  catch (const ctkPluginException& pe)
+  {
+    QFAIL("framework test plug-in, update without new plug-in source :FRAME070A:FAIL");
+  }
+
+  QHash<QString,QString> a1i = pA->getHeaders();
+  versionA1 = a1i["Plugin-Version"];
+  qDebug() << "After version =" << versionA1;
+
+  QList<ctkPluginEvent> pEvts;
+  pEvts << ctkPluginEvent(ctkPluginEvent::INSTALLED, pA);
+  pEvts << ctkPluginEvent(ctkPluginEvent::RESOLVED, pA);
+  pEvts << ctkPluginEvent(ctkPluginEvent::UNRESOLVED, pA);
+  pEvts << ctkPluginEvent(ctkPluginEvent::UPDATED, pA);
+
+
+  QVERIFY2(checkListenerEvents(QList<ctkPluginFrameworkEvent>(),
+                               pEvts, QList<ctkServiceEvent>()),
+           "Unexpected events");
+
+  QVERIFY2(versionA1 != versionA, "framework test plug-in, update of plug-in failed, version info unchanged :FRAME070A:Fail");
+}
+
+//----------------------------------------------------------------------------
 void ctkPluginFrameworkTestSuite::frameworkListener(const ctkPluginFrameworkEvent& fwEvent)
 {
   frameworkEvents.push_back(fwEvent);
@@ -718,6 +803,15 @@ bool ctkPluginFrameworkTestSuite::checkSyncListenerEvents(
   return listenState;
 }
 
+void ctkPluginFrameworkTestSuite::clearEvents()
+{
+  QTest::qWait(300);
+  pluginEvents.clear();
+  syncPluginEvents.clear();
+  frameworkEvents.clear();
+  serviceEvents.clear();
+}
+
 //----------------------------------------------------------------------------
 ctkServiceEvent ctkServiceListenerPFW::getEvent() const
 {

+ 3 - 0
Libs/PluginFramework/Testing/org.commontk.pluginfwtest/ctkPluginFrameworkTestSuite_p.h

@@ -66,6 +66,7 @@ private Q_SLOTS:
   void frame040a();
   void frame042a();
   void frame045a();
+  void frame070a();
 
 private:
 
@@ -99,6 +100,8 @@ private:
   // reset the events
   bool checkSyncListenerEvents(const QList<ctkPluginEvent>& pEvts);
 
+  void clearEvents();
+
   static int nRunCount;
 
   QList<ctkPluginEvent> pluginEvents;