Prechádzať zdrojové kódy

ENH: Added test skeleton for consoleWidget and pythonShell

Jean-Christophe Fillion-Robin 15 rokov pred
rodič
commit
e5f4aa70d9

+ 1 - 1
Libs/Scripting/Python/Widgets/CMakeLists.txt

@@ -54,5 +54,5 @@ ctkMacroBuildLib(
 
 # Testing
 IF(BUILD_TESTING)
-  #ADD_SUBDIRECTORY(Testing)
+  ADD_SUBDIRECTORY(Testing)
 ENDIF(BUILD_TESTING)

+ 2 - 2
Libs/Scripting/Python/Widgets/Testing/Cpp/CMakeLists.txt

@@ -1,7 +1,7 @@
 SET(KIT ${PROJECT_NAME})
 
 CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cpp
-  
+  ctkPythonShellTest1.cpp
   #EXTRA_INCLUDE TestingMacros.h
   )
 
@@ -27,4 +27,4 @@ ENDMACRO( SIMPLE_TEST  )
 # Add Tests
 #
 
-#SIMPLE_TEST( ctkModelTesterTest1 )
+SIMPLE_TEST( ctkPythonShellTest1 )

+ 56 - 0
Libs/Scripting/Python/Widgets/Testing/Cpp/ctkPythonShellTest1.cpp

@@ -0,0 +1,56 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  Kitware Inc.
+
+  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.commontk.org/LICENSE
+
+  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.
+
+=========================================================================*/
+
+// Qt includes
+#include <QApplication>
+#include <QTimer>
+#include <QPushButton>
+
+// CTK includes
+#include "ctkPythonShell.h"
+#include "ctkAbstractPythonManager.h"
+
+// STD includes
+#include <stdlib.h>
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkPythonShellTest1(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  QPushButton button("Show PythonShell");
+
+  ctkPythonShell pythonShell(new ctkAbstractPythonManager);
+
+  QObject::connect(&button, SIGNAL(clicked()), &pythonShell, SLOT(show()));
+
+  button.show();
+
+  QTimer autoExit;
+  if (argc < 2 || QString(argv[1]) != "-I")
+    {
+    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
+    autoExit.start(100);
+    }
+
+  return app.exec();
+}
+

+ 2 - 0
Libs/Widgets/Testing/Cpp/CMakeLists.txt

@@ -10,6 +10,7 @@ CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cxx
   ctkCollapsibleGroupBoxTest1.cpp
   ctkColorPickerButtonTest1.cpp
   ctkComboBoxTest1.cpp
+  ctkConsoleWidgetTest1.cpp
   ctkCoordinatesWidgetTest1.cpp
   ctkDirectoryButtonTest1.cpp
   ctkDoubleRangeSliderTest1.cpp
@@ -54,6 +55,7 @@ SIMPLE_TEST( ctkCollapsibleButtonTest1 )
 SIMPLE_TEST( ctkCollapsibleGroupBoxTest1 )
 SIMPLE_TEST( ctkColorPickerButtonTest1 )
 SIMPLE_TEST( ctkComboBoxTest1 )
+SIMPLE_TEST( ctkConsoleWidgetTest1 )
 SIMPLE_TEST( ctkCoordinatesWidgetTest1 )
 SIMPLE_TEST( ctkDirectoryButtonTest1 )
 SIMPLE_TEST( ctkDoubleRangeSliderTest1 )

+ 50 - 0
Libs/Widgets/Testing/Cpp/ctkConsoleWidgetTest1.cpp

@@ -0,0 +1,50 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  Kitware Inc.
+
+  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.commontk.org/LICENSE
+
+  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.
+
+=========================================================================*/
+
+// Qt includes
+#include <QApplication>
+#include <QTimer>
+
+// CTK includes
+#include "ctkConsoleWidget.h"
+
+// STD includes
+#include <stdlib.h>
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkConsoleWidgetTest1(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  ctkConsoleWidget widget;
+
+  widget.show();
+
+  QTimer autoExit;
+  if (argc < 2 || QString(argv[1]) != "-I")
+    {
+    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
+    autoExit.start(100);
+    }
+
+  return app.exec();
+}
+

+ 1 - 1
Libs/Widgets/ctkConsoleWidget.h

@@ -73,7 +73,7 @@ class CTK_WIDGETS_EXPORT ctkConsoleWidget : public QWidget
   Q_OBJECT
   
 public:
-  ctkConsoleWidget(QWidget* Parent);
+  ctkConsoleWidget(QWidget* parent = 0);
   virtual ~ctkConsoleWidget();
 
   /// Returns the current formatting that will be used by printString