浏览代码

Add/edit ctkCore-unittest to fix a low coverage

Improve coverage for ctkHistogram, ctkTransferFunction,
ctkTransfertFunctionRepresentation.
Benjamin Long 14 年之前
父节点
当前提交
e80497a32a

+ 0 - 40
Libs/Core/Testing/Cpp/ctkHistogramTest1.cpp

@@ -54,16 +54,6 @@ public:
     return 0;
   }
 
-  virtual bool isDiscrete()const
-  {
-    return true;
-  }
-
-  virtual bool isEditable()const
-  {
-    return false;
-  }
-
   virtual void range(qreal& minRange, qreal& maxRange)const
   {
     Q_UNUSED(minRange);
@@ -82,40 +72,10 @@ public:
     return 0;
   }
 
-  ///
-  virtual int insertControlPoint(const ctkControlPoint& cp)
-  {
-    Q_UNUSED(cp);
-    return -1;
-  }
-
-  virtual int insertControlPoint(qreal pos)
-  {
-    Q_UNUSED(pos);
-    return -1;
-  }
-
   virtual void removeControlPoint( qreal pos )
   {
     Q_UNUSED(pos);
   }
-  ///
-  /// be careful with it, as changing the value might require
-  /// more changes to ctkControlPoint.
-  virtual void setControlPointPos(int index, qreal pos)
-  {
-    Q_UNUSED(pos);
-    Q_UNUSED(index);
-  }
-
-  ///
-  /// be careful with it, as changing the value might require
-  /// more changes to ctkControlPoint.
-  virtual void setControlPointValue(int index, const QVariant& value)
-  {
-    Q_UNUSED(index);
-    Q_UNUSED(value);
-  }
 
   virtual void build()
   {

+ 46 - 2
Libs/Core/Testing/Cpp/ctkTransferFunctionRepresentationTest1.cpp

@@ -89,6 +89,24 @@ int ctkTransferFunctionRepresentationTest1(int argc, char * argv [])
   return EXIT_FAILURE;
   }
 
+  ctkControlPoint cp;
+  if (representation.posX(&cp) != cp.x())
+    {
+    std::cerr << "Line " << __LINE__
+              << " - Problem with ctkTransfertFunctionRepresentation::posX"
+              << representation.posX(&cp);
+    return EXIT_FAILURE;
+    }
+
+  ctkPoint point;
+  if (representation.posX(point) != point.X)
+    {
+    std::cerr << "Line " << __LINE__
+              << " - Problem with ctkTransfertFunctionRepresentation::posX"
+              << representation.posX(point);
+    return EXIT_FAILURE;
+    }
+
   //---------Test PosY--------------------------
   QVariant variant = 2.;
   if (representation.posY(variant) != 2.)  
@@ -105,10 +123,24 @@ int ctkTransferFunctionRepresentationTest1(int argc, char * argv [])
     {
     std::cerr << "Line " << __LINE__
               << " - Problem with ctkTransfertFunctionRepresentation::posY"
-              << " - for the color: " << representation.posY(variant) 
-              << " - " << defaultColor.alphaF() << std::endl;
+              << " - for the color: " << representation.posY(variant);
     return EXIT_FAILURE;
     } 
+
+  if (representation.posY(&cp) != cp.value())
+    {
+    std::cerr << "Line " << __LINE__
+              << " - Problem with ctkTransfertFunctionRepresentation::posY"
+              << representation.posY(&cp);
+    return EXIT_FAILURE;
+    }
+  if (representation.posY(point) != point.Value)
+    {
+    std::cerr << "Line " << __LINE__
+              << " - Problem with ctkTransfertFunctionRepresentation::posY"
+              << representation.posX(point);
+    return EXIT_FAILURE;
+    }
  
   //--------Test Color--------------------------
   QColor expectedColor = QColor::fromRgbF(1., 1., 1.);
@@ -130,6 +162,18 @@ int ctkTransferFunctionRepresentationTest1(int argc, char * argv [])
               << std::endl;
     return EXIT_FAILURE;
     }
+  if (representation.color(&cp) != representation.color(cp.value()))
+    {
+    std::cerr << "Line " << __LINE__
+              << " - Problem with ctkTransfertFunctionRepresentation::color";
+    return EXIT_FAILURE;
+    }
+  if (representation.color(point) != representation.color(point.Value))
+    {
+    std::cerr << "Line " << __LINE__
+              << " - Problem with ctkTransfertFunctionRepresentation::color";
+    return EXIT_FAILURE;
+    }
 
   //---------Test MapXToScene------------------
   qreal xPos = 2.;

+ 8 - 0
Libs/Core/Testing/Cpp/ctkTransferFunctionTest1.cpp

@@ -149,6 +149,13 @@ int ctkTransferFunctionTest1(int argc, char * argv [])
               <<std::endl;
     return EXIT_FAILURE;
     }
+  if (dummy.value(0) != 0)
+    {
+    std::cerr << "Line : " << __LINE__
+              << " - Problem with ctkHistogram::value"
+              <<std::endl;
+    return EXIT_FAILURE;
+    }
   if (dummy.minValue() != 0)
     {
     std::cerr << "Line : " << __LINE__
@@ -184,6 +191,7 @@ int ctkTransferFunctionTest1(int argc, char * argv [])
   dummy.removeControlPoint(defaultPos);
   dummy.setControlPointPos(defaultIndex,defaultPos);
   dummy.setControlPointValue(defaultIndex,defaultValue);
+  dummy.representation();
 
   return EXIT_SUCCESS;
 }

+ 2 - 0
Libs/Visualization/VTK/Core/Testing/Cpp/CMakeLists.txt

@@ -12,6 +12,7 @@ SET(TEST_SOURCES
   ctkVTKHistogramTest3.cpp
   ctkVTKHistogramTest4.cpp
   ctkVTKObjectTest1.cpp
+  ctkVTKTransferFunctionRepresentationTest1.cpp
   )
 
 #
@@ -82,6 +83,7 @@ SIMPLE_TEST( ctkVTKHistogramTest2 )
 SIMPLE_TEST( ctkVTKHistogramTest3 )
 SIMPLE_TEST( ctkVTKHistogramTest4 )
 SIMPLE_TEST( ctkVTKObjectTest1 )
+SIMPLE_TEST( ctkVTKTransferFunctionRepresentationTest1 )
 
 #
 # Add Tests expecting CTKData to be set

+ 71 - 0
Libs/Visualization/VTK/Core/Testing/Cpp/ctkVTKTransferFunctionRepresentationTest1.cpp

@@ -0,0 +1,71 @@
+
+// Qt includes
+#include <QCoreApplication>
+#include <QDebug>
+
+// CTK includes
+#include "ctkTransferFunctionRepresentation.h"
+
+// CTKVTK includes
+#include "ctkVTKColorTransferFunction.h"
+#include "ctkVTKLookupTable.h"
+
+// VTK includes
+#include <vtkColorTransferFunction.h>
+#include <vtkLookupTable.h>
+#include <vtkSmartPointer.h>
+
+// STD includes
+#include <cstdlib>
+#include <iostream>
+
+int ctkVTKTransferFunctionRepresentationTest1( int argc, char * argv [])
+{
+  Q_UNUSED(argc);
+  Q_UNUSED(argv);
+
+//--------------------------------------------
+//Test 1 : with default TransfertFunction
+//----------------------------------------------------------------------
+
+  /// Function not discrete
+  ctkVTKColorTransferFunction defaultCTF;
+
+  vtkColorTransferFunction*  colorTransferFunction = vtkColorTransferFunction::New();
+  defaultCTF.setColorTransferFunction(colorTransferFunction);
+
+  ctkTransferFunctionRepresentation representation;
+  representation.setTransferFunction(&defaultCTF);
+
+  qreal defaultMinRange = 0.;
+  qreal defaultMaxRange = 1.;
+  defaultCTF.range(defaultMinRange, defaultMaxRange);
+
+  qreal firstPos = 10.;
+  qreal secondPos = 20.;
+  ctkControlPoint* defaultControlPoint;
+  int firstIndex = defaultCTF.insertControlPoint(firstPos);
+  int secondIndex = defaultCTF.insertControlPoint(secondPos);
+  std::cout << "Index :" << firstIndex << "  " << secondIndex << std::endl;
+  defaultControlPoint = defaultCTF.controlPoint(0);
+  defaultControlPoint = defaultCTF.controlPoint(firstIndex);
+  defaultControlPoint = defaultCTF.controlPoint(secondIndex);
+
+  representation.computeCurve();
+  representation.computeGradient();
+
+  colorTransferFunction->Delete();
+
+  /// Function discrete
+  ctkVTKLookupTable defaultLuT;
+  vtkLookupTable* lookupTable = vtkLookupTable::New();
+  defaultLuT.setLookupTable(lookupTable);
+
+  representation.setTransferFunction(&defaultLuT);
+
+  representation.computeCurve();
+  representation.computeGradient();
+
+  lookupTable->Delete();
+  return EXIT_SUCCESS;
+}