From 561335ed55c6aca916b637e4ceb2a4783435299a Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@orfeo-toolbox.org>
Date: Mon, 28 Mar 2011 18:43:50 +0200
Subject: [PATCH] TEST: Adding a test to build int, float and empty QtWidget
 parameters

---
 Code/Wrappers/QtWidget/CMakeLists.txt         |  2 +-
 Testing/CMakeLists.txt                        | 19 +++++
 .../otbWrapperQtWidgetParameterFactory.cxx    | 71 +++++++++++++++++++
 Testing/otbWrapperQtWidgetTests.cxx           | 28 ++++++++
 4 files changed, 119 insertions(+), 1 deletion(-)
 create mode 100644 Testing/otbWrapperQtWidgetParameterFactory.cxx
 create mode 100644 Testing/otbWrapperQtWidgetTests.cxx

diff --git a/Code/Wrappers/QtWidget/CMakeLists.txt b/Code/Wrappers/QtWidget/CMakeLists.txt
index 92c136ea85..26f2e871da 100644
--- a/Code/Wrappers/QtWidget/CMakeLists.txt
+++ b/Code/Wrappers/QtWidget/CMakeLists.txt
@@ -2,4 +2,4 @@
 FILE(GLOB srcs "*.cxx")
 
 ADD_LIBRARY(OTBWrapperQtWidget ${srcs})
-TARGET_LINK_LIBRARIES(OTBWrapperQtWidget OTBCommon OTBIO OTBWrapperCore)
+TARGET_LINK_LIBRARIES(OTBWrapperQtWidget OTBCommon OTBIO OTBWrapperCore ${QT_LIBRARIES})
diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt
index 8466a719a6..823a4a6de9 100644
--- a/Testing/CMakeLists.txt
+++ b/Testing/CMakeLists.txt
@@ -5,6 +5,7 @@ IF(WIN32)
 ENDIF(WIN32)
 
 SET(OTB_WRAPPER_TESTS ${CXX_TEST_PATH}/otbWrapperTests)
+SET(OTB_WRAPPER_QT_TESTS ${CXX_TEST_PATH}/otbWrapperQtWidgetTests)
 
 ADD_TEST(owTuParameterNew ${OTB_WRAPPER_TESTS}
 	otbWrapperParameterNew
@@ -43,6 +44,13 @@ ADD_TEST(owTuApplication ${OTB_WRAPPER_TESTS}
 	otbWrapperApplicationNew
   )
   
+IF(OTB_USE_QT)
+ADD_TEST(owTvQtWidgetParameterFactory ${OTB_WRAPPER_QT_TESTS}
+        otbWrapperQtWidgetParameterFactory
+)
+
+ENDIF(OTB_USE_QT)
+
 # ----------------Source files CXX -----------------------------------
 
 SET(Wrapper_SRCS
@@ -57,3 +65,14 @@ otbWrapperParameterListTest.cxx
 ADD_EXECUTABLE(otbWrapperTests ${Wrapper_SRCS})
 TARGET_LINK_LIBRARIES(otbWrapperTests OTBIO OTBCommon ITKIO ITKCommon OTBTesting OTBWrapperCore)
 
+IF(OTB_USE_QT)
+
+SET(WrapperQtWidget_SRCS
+otbWrapperQtWidgetTests.cxx
+otbWrapperQtWidgetParameterFactory.cxx
+)
+
+ADD_EXECUTABLE(otbWrapperQtWidgetTests ${WrapperQtWidget_SRCS})
+TARGET_LINK_LIBRARIES(otbWrapperQtWidgetTests OTBIO OTBCommon ITKIO ITKCommon OTBTesting OTBWrapperCore OTBWrapperQtWidget)
+
+ENDIF(OTB_USE_QT)
diff --git a/Testing/otbWrapperQtWidgetParameterFactory.cxx b/Testing/otbWrapperQtWidgetParameterFactory.cxx
new file mode 100644
index 0000000000..015d873b2d
--- /dev/null
+++ b/Testing/otbWrapperQtWidgetParameterFactory.cxx
@@ -0,0 +1,71 @@
+/*=========================================================================
+
+  Program:   ORFEO Toolbox
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+
+  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+  See OTBCopyright.txt for details.
+
+
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+#if defined(_MSC_VER)
+#pragma warning ( disable : 4786 )
+#endif
+
+#include "otbWrapperQtWidgetParameterFactory.h"
+#include "otbWrapperEmptyParameter.h"
+#include "otbWrapperNumericalParameter.h"
+
+int otbWrapperQtWidgetParameterFactory(int argc, char* argv[])
+{
+  QApplication app(argc, argv);
+
+  otb::Wrapper::QtWidgetParameterFactory::Pointer factory = otb::Wrapper::QtWidgetParameterFactory::New();
+
+  otb::Wrapper::IntParameter::Pointer   intParam = otb::Wrapper::IntParameter::New();
+  otb::Wrapper::FloatParameter::Pointer floatParam = otb::Wrapper::FloatParameter::New();
+  otb::Wrapper::EmptyParameter::Pointer emptyParam = otb::Wrapper::EmptyParameter::New();
+
+  intParam->SetName("Int parameter");
+  intParam->SetDescription("This is an int parameter");
+  intParam->SetKey("int");
+  intParam->SetDefaultValue(10);
+  intParam->SetValue(5);
+  intParam->SetMinimumValue(-10);
+  intParam->SetMaximumValue(10);
+
+  floatParam->SetName("Float parameter");
+  floatParam->SetDescription("This is an float parameter");
+  floatParam->SetKey("float");
+  floatParam->SetDefaultValue(0.567);
+  floatParam->SetValue(0.21);
+  floatParam->SetMinimumValue(-3.75);
+  floatParam->SetMaximumValue(4.97);
+
+  emptyParam->SetName("Empty parameter");
+  emptyParam->SetDescription("This is an empty parameter");
+  emptyParam->SetKey("empty");
+
+
+  QWidget * intWidget = factory->CreateQtWidget(intParam);
+  QWidget * floatWidget = factory->CreateQtWidget(floatParam);
+  QWidget * emptyWidget = factory->CreateQtWidget(emptyParam);
+
+  if(intWidget)
+    {
+    intWidget->show();
+    floatWidget->show();
+    emptyWidget->show();
+
+    return EXIT_SUCCESS;
+    }
+
+  return EXIT_FAILURE;
+}
diff --git a/Testing/otbWrapperQtWidgetTests.cxx b/Testing/otbWrapperQtWidgetTests.cxx
new file mode 100644
index 0000000000..8cdafefb8d
--- /dev/null
+++ b/Testing/otbWrapperQtWidgetTests.cxx
@@ -0,0 +1,28 @@
+/*=========================================================================
+
+  Program:   ORFEO Toolbox
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+
+  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+  See OTBCopyright.txt for details.
+
+
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+
+#if defined(_MSC_VER)
+#pragma warning ( disable : 4786 )
+#endif
+
+#include "otbTestMain.h"
+
+void RegisterTests()
+{
+  REGISTER_TEST(otbWrapperQtWidgetParameterFactory);
+}
-- 
GitLab