Переглянути джерело

Fix ctkFileDialogEventTranslatorPlayerTests

Replace absolute path with path relative to CTK_SOURCE_DIR
Julien Finet 10 роки тому
батько
коміт
6a1eec3a12

+ 13 - 22
Libs/Widgets/Testing/Cpp/ctkFileDialogEventTranslatorPlayerTest1.cpp

@@ -47,31 +47,21 @@ namespace
 {
 //-----------------------------------------------------------------------------
 void checkFinalWidgetState(void* data)
-  {
+{
   ctkFileDialog* widget = reinterpret_cast<ctkFileDialog*>(data);
-  QStringList listActual =  widget->selectedFiles();
-  QStringList listExpected;
-  listExpected << "/home/benjaminlong/Documents/ctk-QtTesting-renderView/ctkVTKRenderViewEventTranslatorPlayerTest1Screenshot.png";
-  listExpected << "/home/benjaminlong/Documents/ctk-QtTesting-renderView/ctkVTKRenderViewEventTranslatorPlayerTest1ScreenshotTest.png";
+  QStringList expectedSelectedFiles;
+  expectedSelectedFiles << CTK_SOURCE_DIR"/ctkLogo.png";
+  expectedSelectedFiles << CTK_SOURCE_DIR"/ctkLogo-small.png";
+
+  CTKCOMPARE(widget->selectedFiles(), expectedSelectedFiles);
+}
 
-  if( listActual.count() == listExpected.count())
-    {
-    for(int i = 0 ; i < listActual.count() ; i++)
-      {
-      CTKCOMPARE(listExpected[i], listActual[i]);
-      }
-    }
-  else
-    {
-    QApplication::exit(EXIT_FAILURE);
-    }
-  }
 //-----------------------------------------------------------------------------
 void checkFinalWidgetState2(void* data)
-  {
+{
   ctkFileDialog* widget = reinterpret_cast<ctkFileDialog*>(data);
   QStringList actual =  widget->selectedFiles();
-  QString expected = "/home/benjaminlong/GroupBox.png";
+  QString expected = CTK_SOURCE_DIR"/ctkLogo.png";
 
   if( actual.count() == 1)
     {
@@ -81,13 +71,13 @@ void checkFinalWidgetState2(void* data)
     {
     QApplication::exit(EXIT_FAILURE);
     }
-  }
+}
 //-----------------------------------------------------------------------------
 void checkFinalWidgetState3(void* data)
-  {
+{
   ctkFileDialog* widget = reinterpret_cast<ctkFileDialog*>(data);
   CTKCOMPARE(widget->isHidden(), true);
-  }
+}
 }
 
 //-----------------------------------------------------------------------------
@@ -100,6 +90,7 @@ int ctkFileDialogEventTranslatorPlayerTest1(int argc, char * argv [] )
   // ------------------------
   ctkEventTranslatorPlayerWidget etpWidget;
   pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
+  testUtility->addDataDirectory("CTK_SOURCE_DIR", QDir(CTK_SOURCE_DIR));
   etpWidget.setTestUtility(testUtility);
   etpWidget.addWidgetEventPlayer(new ctkFileDialogEventPlayer(etpWidget.testUtility()));
   etpWidget.addWidgetEventTranslator(new ctkFileDialogEventTranslator(etpWidget.testUtility()));

+ 1 - 1
Libs/Widgets/Testing/Cpp/ctkFileDialogEventTranslatorPlayerTest1.xml

@@ -12,6 +12,6 @@
         <event widget="fileDialog1/checkBox1" command="set_boolean" arguments="true"/>
         <event widget="fileDialog1/checkBox1" command="set_boolean" arguments="false"/>
         <event widget="fileDialog1/checkBox1" command="set_boolean" arguments="true"/>
-        <event widget="fileDialog1" command="newFile" arguments="/home/benjaminlong/Documents/ctk-QtTesting-renderView/ctkVTKRenderViewEventTranslatorPlayerTest1Screenshot.png#/home/benjaminlong/Documents/ctk-QtTesting-renderView/ctkVTKRenderViewEventTranslatorPlayerTest1ScreenshotTest.png"/>
+        <event widget="fileDialog1" command="newFile" arguments="${CTK_SOURCE_DIR}/ctkLogo.png#${CTK_SOURCE_DIR}/ctkLogo-small.png"/>
     </events>
 </QtTesting>

+ 1 - 1
Libs/Widgets/Testing/Cpp/ctkFileDialogEventTranslatorPlayerTest2.xml

@@ -14,6 +14,6 @@
         <event widget="fileDialog2/checkBox2" command="set_boolean" arguments="true"/>
         <event widget="fileDialog2/checkBox2" command="set_boolean" arguments="false"/>
         <event widget="fileDialog2/checkBox2" command="set_boolean" arguments="true"/>
-        <event widget="fileDialog2" command="newFile" arguments="/home/benjaminlong/GroupBox.png"/>
+        <event widget="fileDialog2" command="newFile" arguments="${CTK_SOURCE_DIR}/ctkLogo.png"/>
     </events>
 </QtTesting>

+ 27 - 21
Libs/Widgets/ctkFileDialogEventPlayer.cpp

@@ -28,6 +28,9 @@
 #include "ctkFileDialog.h"
 #include "ctkFileDialogEventPlayer.h"
 
+// QtTesting includes
+#include <pqTestUtility.h>
+
 // ----------------------------------------------------------------------------
 ctkFileDialogEventPlayer::ctkFileDialogEventPlayer(pqTestUtility* util, QObject *parent)
   : pqNativeFileDialogEventPlayer(util, parent)
@@ -36,39 +39,42 @@ ctkFileDialogEventPlayer::ctkFileDialogEventPlayer(pqTestUtility* util, QObject
 }
 
 // ----------------------------------------------------------------------------
-bool ctkFileDialogEventPlayer::playEvent(QObject *Object,
-                                                const QString &Command,
-                                                const QString &Arguments,
-                                                bool &Error)
+bool ctkFileDialogEventPlayer::playEvent(QObject *object,
+                                         const QString &command,
+                                         const QString &arguments,
+                                         bool &error)
 {
-  if (Command == "FileOpen" || Command == "DirOpen" ||
-      Command == "FileSave" || Command == "FilesOpen")
+  if (command == "FileOpen" || command == "DirOpen" ||
+      command == "FileSave" || command == "FilesOpen")
     {
-    return this->Superclass::playEvent(Object, Command, Arguments, Error);
+    return this->Superclass::playEvent(object, command, arguments, error);
     }
 
-  if (Command != "newFile" &&
-      Command != "rejected" &&
-      Command != "fileSave")
+  if (command != "newFile" &&
+      command != "rejected" &&
+      command != "fileSave")
     {
     return false;
     }
 
-  if(ctkFileDialog* const object =
-       qobject_cast<ctkFileDialog*>(Object))
+  if(ctkFileDialog* const fileDialog = qobject_cast<ctkFileDialog*>(object))
     {
-    if (Command == "newFile")
+    if (command == "newFile")
       {
       // set the directory
-      QStringList files = Arguments.split("#");
+      QStringList files;
+	  foreach(const QString& file, arguments.split("#"))
+	  {
+        files.append(mUtil->convertFromDataDirectory(file));
+	  }
       QFileInfo infoFile(files.at(0));
       if(!infoFile.exists())
         {
-        qWarning() << "The File doesn't exist, or wasn't finded.";
+        qWarning() << "File does not exist or can't be found.";
         return false;
         }
-      object->setDirectory(infoFile.absoluteDir().absolutePath());
-      if(object->directory() != infoFile.absoluteDir())
+	  fileDialog->setDirectory(infoFile.absoluteDir().absolutePath());
+	  if (fileDialog->directory() != infoFile.absoluteDir())
         {
         qWarning() << "The Directory wasn't selected.";
         }
@@ -108,15 +114,15 @@ bool ctkFileDialogEventPlayer::playEvent(QObject *Object,
         }
       return true;
       }
-    if (Command == "rejected")
+    if (command == "rejected")
       {
-      object->close();
+      fileDialog->close();
       return true;
       }
     }
 
-  qCritical() << "calling newFile/rejected on unhandled type " << Object;
-  Error = true;
+  qCritical() << "calling newFile/rejected on unhandled type " << object;
+  error = true;
   return true;
 }