浏览代码

Start the main test plugin in the same thread as the test functions.

The main test plugin org.commontk.pluginfwtest is now started in the same
thread as the test functions are executed. Therefore, the test suites
(QObject classes) are created in the same thread and their "initTestCase"
method is not called in parallel to the actual test methods anymore.

QTestLib only invokes "initTestCase" with Qt::AutoConnection, all other
methods are invoked with Qt::DirectConnection, who knows why...
Sascha Zelzer 14 年之前
父节点
当前提交
241dc003f7
共有 1 个文件被更改,包括 11 次插入9 次删除
  1. 11 9
      Libs/PluginFramework/Testing/Cpp/ctkPluginFrameworkTestMain.cpp

+ 11 - 9
Libs/PluginFramework/Testing/Cpp/ctkPluginFrameworkTestMain.cpp

@@ -34,14 +34,18 @@ class TestRunner : public QThread
 {
 public:
 
-  TestRunner(ctkPluginContext* context, int argc, char** argv)
-    : context(context), argc(argc), argv(argv)
+  TestRunner(ctkPluginContext* context, long testPluginId, int argc, char** argv)
+    : context(context), testPluginId(testPluginId), argc(argc), argv(argv)
   {
 
   }
 
   void run()
   {
+    // start the main test plugin which registers the test suites (QObject classes)
+    QSharedPointer<ctkPlugin> fwTest = context->getPlugin(testPluginId);
+    fwTest->start();
+
     QList<ctkServiceReference> refs = context->getServiceReferences("ctkTestSuiteInterface");
 
     int result = 0;
@@ -56,6 +60,7 @@ public:
 private:
 
   ctkPluginContext* context;
+  long testPluginId;
   int argc;
   char** argv;
 };
@@ -86,7 +91,7 @@ int main(int argc, char** argv)
 
   ctkPluginContext* context = framework->getPluginContext();
 
-  QSharedPointer<ctkPlugin> fwTest;
+  long fwTestPluginId = -1;
   QStringList libFilter;
   libFilter << "*.dll" << "*.so" << "*.dylib";
   QDirIterator dirIter(pluginDir, libFilter, QDir::Files);
@@ -97,7 +102,7 @@ int main(int argc, char** argv)
     {
       try
       {
-        fwTest = context->installPlugin(QUrl::fromLocalFile(dirIter.filePath()).toString());
+        fwTestPluginId = context->installPlugin(QUrl::fromLocalFile(dirIter.filePath()).toString())->getPluginId();
         break;
       }
       catch (const ctkPluginException& e)
@@ -107,14 +112,11 @@ int main(int argc, char** argv)
     }
   }
 
-  if (!fwTest)
+  if (fwTestPluginId < 0)
   {
     qCritical() << "Could not find the plugin framework test plugin: org.commontk.pluginfwtest";
   }
 
-  // start the main test plugin which registers the test suites (QObject classes)
-  fwTest->start();
-
 //  QList<ctkServiceReference> refs = context->getServiceReferences("ctkTestSuiteInterface");
 
 //  int result = 0;
@@ -125,7 +127,7 @@ int main(int argc, char** argv)
 
 //  return result;
 
-  TestRunner runner(context, argc,argv);
+  TestRunner runner(context, fwTestPluginId, argc, argv);
   runner.start();
 
   return app.exec();