Classes | Typedefs | Functions | Variables

PlanarFigureTestDriver.cpp File Reference

#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mitkLog.h"

Go to the source code of this file.

Classes

struct  functionMapEntry

Typedefs

typedef int(* MainFuncPointer )(int, char *[])

Functions

int mitkPlanarCrossTest (int, char *[])
int mitkPlanarPolygonTest (int, char *[])
int mitkPlanarFigureIOTest (int, char *[])
 Test for PlanarFigure reader and writer classes.
int mitkPlanarFigureObjectFactoryTest (int, char *[])
int mitkPlanarArrowTest (int, char *[])
char * lowercase (const char *string)
int main (int ac, char *av[])

Variables

functionMapEntry cmakeGeneratedFunctionMapEntries []

Typedef Documentation

typedef int(* MainFuncPointer)(int, char *[])

Definition at line 20 of file PlanarFigureTestDriver.cpp.


Function Documentation

char* lowercase ( const char *  string )

Definition at line 55 of file PlanarFigureTestDriver.cpp.

{
  char *new_string, *p;

#ifdef __cplusplus
  new_string = static_cast<char *>(malloc(sizeof(char) *
    static_cast<size_t>(strlen(string) + 1)));
#else
  new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
#endif

  if (!new_string)
    {
    return 0;
    }
  strcpy(new_string, string);
  p = new_string;
  while (*p != 0)
    {
#ifdef __cplusplus
    *p = static_cast<char>(tolower(*p));
#else
    *p = (char)(tolower(*p));
#endif

    ++p;
    }
  return new_string;
}
int main ( int  ac,
char *  av[] 
)

Definition at line 85 of file PlanarFigureTestDriver.cpp.

References functionMapEntry::func, lowercase(), functionMapEntry::name, mitk::LoggingBackend::Register(), and mitk::LoggingBackend::Unregister().

{
  int i, NumTests, testNum, partial_match;
  char *arg, *test_name;
  int count;
  int testToRun = -1;

  
    
  for(count =0; cmakeGeneratedFunctionMapEntries[count].name != 0; count++)
    {
    }
  NumTests = count;
  /* If no test name was given */
  /* process command line with user function.  */
  if (ac < 2)
    {
    /* Ask for a test.  */
    printf("Available tests:\n");
    for (i =0; i < NumTests; ++i)
      {
      printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
      }
    printf("To run a test, enter the test number: ");
    fflush(stdout);
    testNum = 0;
    if( scanf("%d", &testNum) != 1 )
      {
      printf("Couldn't parse that input as a number\n");
      return -1;
      }
    if (testNum >= NumTests)
      {
      printf("%3d is an invalid test number.\n", testNum);
      return -1;
      }
    testToRun = testNum;
    ac--;
    av++;
    }
  partial_match = 0;
  arg = 0;
  /* If partial match is requested.  */
  if(testToRun == -1 && ac > 1)
    {
    partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
    }
  if (partial_match && ac < 3)
    {
    printf("-R needs an additional parameter.\n");
    return -1;
    }
  if(testToRun == -1)
    {
    arg = lowercase(av[1 + partial_match]);
    }
  for (i =0; i < NumTests && testToRun == -1; ++i)
    {
    test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
    if (partial_match && strstr(test_name, arg) != NULL)
      {
      testToRun = i;
      ac -=2;
      av += 2;
      }
    else if (!partial_match && strcmp(test_name, arg) == 0)
      {
      testToRun = i;
      ac--;
      av++;
      }
    free(test_name);
    }
  if(arg)
    {
    free(arg);
    }
  if(testToRun != -1)
    {
    int result;
mitk::LoggingBackend::Register(); ;
    result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
mitk::LoggingBackend::Unregister();
    return result;
    }
  
  
  /* Nothing was run, display the test names.  */
  printf("Available tests:\n");
  for (i =0; i < NumTests; ++i)
    {
    printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
    }
  printf("Failed: %s is an invalid test name.\n", av[1]);
  
  return -1;
}
int mitkPlanarArrowTest ( int  ,
char *  [] 
)

mitkPlanarArrowTest tests the methods and behavior of mitk::PlanarArrow with sub-tests:

1. Instantiation and basic tests

Definition at line 71 of file mitkPlanarArrowTest.cpp.

References MITK_TEST_BEGIN, MITK_TEST_CONDITION_REQUIRED, MITK_TEST_END, mitk::PlanarArrow::New(), mitk::PlaneGeometry::New(), and mitkPlanarArrowTestClass::TestPlanarArrowPlacement().

{
  // always start with this!
  MITK_TEST_BEGIN("PlanarArrow")

  // create PlaneGeometry on which to place the PlanarArrow
  mitk::PlaneGeometry::Pointer planeGeometry = mitk::PlaneGeometry::New();
  planeGeometry->InitializeStandardPlane( 100.0, 100.0 );

  // **************************************************************************
  // 1. Instantiation and basic tests
  mitk::PlanarArrow::Pointer PlanarArrow = mitk::PlanarArrow::New();
  PlanarArrow->SetGeometry2D( planeGeometry );

  // first test: did this work?
  MITK_TEST_CONDITION_REQUIRED( PlanarArrow.IsNotNull(), "Testing instantiation" );

  // Test placement of PlanarArrow by control points
  mitkPlanarArrowTestClass::TestPlanarArrowPlacement( PlanarArrow );

  // always end with this!
  MITK_TEST_END();
} 
int mitkPlanarCrossTest ( int  ,
char *  [] 
)

mitkPlanarCrossTest tests the methods and behavior of mitk::PlanarCross with four sub-tests:

1. Double-line mode instantiation and basic tests 2. Single-line mode instantiation and basic tests 3. Tests of application of spatial constraints for double-line mode 4. Tests if editing of PlanarCross works as intended

Definition at line 352 of file mitkPlanarCrossTest.cpp.

References MITK_TEST_BEGIN, MITK_TEST_CONDITION_REQUIRED, MITK_TEST_END, mitk::PlanarCross::New(), mitk::PlaneGeometry::New(), mitkPlanarCrossTestClass::TestPlanarCrossEdit(), mitkPlanarCrossTestClass::TestPlanarCrossPlacement(), mitkPlanarCrossTestClass::TestPlanarCrossPlacementConstrained(), and mitkPlanarCrossTestClass::TestPlanarCrossPlacementSingleLine().

{
  // always start with this!
  MITK_TEST_BEGIN("PlanarCross")

  // create PlaneGeometry on which to place the PlanarCross
  mitk::PlaneGeometry::Pointer planeGeometry = mitk::PlaneGeometry::New();
  planeGeometry->InitializeStandardPlane( 100.0, 100.0 );

  // **************************************************************************
  // 1. Double-line mode instantiation and basic tests
  mitk::PlanarCross::Pointer planarCross = mitk::PlanarCross::New();
  planarCross->SetGeometry2D( planeGeometry );

  // first test: did this work?
  MITK_TEST_CONDITION_REQUIRED( planarCross.IsNotNull(), "Testing instantiation" );

  // test: default cross-mode (not single-line-mode)?
  MITK_TEST_CONDITION_REQUIRED( !planarCross->GetSingleLineMode(), "Testing default cross mode" );


  // Test placement of PlanarCross by control points
  mitkPlanarCrossTestClass::TestPlanarCrossPlacement( planarCross );


  // **************************************************************************
  // 2. Single-line mode instantiation and basic tests
  planarCross = mitk::PlanarCross::New();
  planarCross->SingleLineModeOn();
  planarCross->SetGeometry2D( planeGeometry );

  // test: single-line mode?
  MITK_TEST_CONDITION_REQUIRED( planarCross->GetSingleLineMode(), "Testing activation of single-line mode" );

  // Test placement of single-line PlanarCross by control points
  mitkPlanarCrossTestClass::TestPlanarCrossPlacementSingleLine( planarCross );


  // **************************************************************************
  // 3. Tests of application of spatial constraints for double-line mode
  planarCross = mitk::PlanarCross::New();
  planarCross->SetGeometry2D( planeGeometry );

  // Test placement with various out-of-bounds control points (automatic application of
  // constraints expected)
  mitkPlanarCrossTestClass::TestPlanarCrossPlacementConstrained( planarCross );


  // **************************************************************************
  // 4. Tests if editing of PlanarCross works as intended
  mitkPlanarCrossTestClass::TestPlanarCrossEdit( planarCross );



  // always end with this!
  MITK_TEST_END()
}
int mitkPlanarFigureIOTest ( int  ,
char *  [] 
)

Test for PlanarFigure reader and writer classes.

The test works as follows:

First, a number of PlanarFigure objects of different types are created and placed with various control points. These objects are the serialized to file, read again from file, and the retrieved objects are compared with their control points, properties, and geometry information to the original PlanarFigure objects.

Definition at line 333 of file mitkPlanarFigureIOTest.cpp.

References PlanarFigureIOTestClass::CreatePlanarFigures(), PlanarFigureIOTestClass::DeserializePlanarFigures(), MITK_TEST_BEGIN, MITK_TEST_END, PlanarFigureIOTestClass::SerializePlanarFigures(), and PlanarFigureIOTestClass::VerifyPlanarFigures().

{
  MITK_TEST_BEGIN("PlanarFigureIO")

  // Create a number of PlanarFigure objects
  PlanarFigureIOTestClass::PlanarFigureList originalPlanarFigures = 
    PlanarFigureIOTestClass::CreatePlanarFigures();


  // Write PlanarFigure objects into temp file
  
  // tmpname
  static unsigned long count = 0;
        unsigned long n = count++;
  std::ostringstream name;
  for (int i = 0; i < 6; ++i)
        {
                name << char('a' + (n % 26));
                n /= 26;
        }
  std::string myname;
  myname.append(name.str());

  std::string fileName = itksys::SystemTools::GetCurrentWorkingDirectory() + myname + ".pf";

  PlanarFigureIOTestClass::SerializePlanarFigures( originalPlanarFigures, fileName );


  // Read PlanarFigure objects from temp file
  PlanarFigureIOTestClass::PlanarFigureList retrievedPlanarFigures =
  PlanarFigureIOTestClass::DeserializePlanarFigures( fileName );


  // Test if original and retrieved PlanarFigure objects are the same
  PlanarFigureIOTestClass::VerifyPlanarFigures( originalPlanarFigures, retrievedPlanarFigures );


  MITK_TEST_END()
}
int mitkPlanarFigureObjectFactoryTest ( int  ,
char *  [] 
)

Documentation Test for factory registration

Definition at line 26 of file mitkPlanarFigureObjectFactoryTest.cpp.

References MITK_TEST_BEGIN, MITK_TEST_END, and RegisterPlanarFigureObjectFactory().

{
  // always start with this!
  MITK_TEST_BEGIN("PlanarFigureObjectFactoryTest");
  
  RegisterPlanarFigureObjectFactory();

  // always end with this!
  MITK_TEST_END();
}
int mitkPlanarPolygonTest ( int  ,
char *  [] 
)

mitkplanarPolygonTest tests the methods and behavior of mitk::PlanarPolygon with sub-tests:

1. Instantiation and basic tests, including feature evaluation

Definition at line 96 of file mitkPlanarPolygonTest.cpp.

References MITK_TEST_BEGIN, MITK_TEST_CONDITION_REQUIRED, MITK_TEST_END, mitk::PlanarPolygon::New(), mitk::PlaneGeometry::New(), and mitkPlanarPolygonTestClass::TestPlanarPolygonPlacement().

{
  // always start with this!
  MITK_TEST_BEGIN("planarPolygon")

  // create PlaneGeometry on which to place the planarPolygon
  mitk::PlaneGeometry::Pointer planeGeometry = mitk::PlaneGeometry::New();
  planeGeometry->InitializeStandardPlane( 100.0, 100.0 );

  // **************************************************************************
  // 1. Instantiation and basic tests, including feature evaluation
  mitk::PlanarPolygon::Pointer planarPolygon = mitk::PlanarPolygon::New();
  planarPolygon->SetGeometry2D( planeGeometry );

  // first test: did this work?
  MITK_TEST_CONDITION_REQUIRED( planarPolygon.IsNotNull(), "Testing instantiation" );

  // Test placement of planarPolygon by control points
  mitkPlanarPolygonTestClass::TestPlanarPolygonPlacement( planarPolygon );

  // always end with this!
  MITK_TEST_END();
} 

Variable Documentation

Initial value:
 {
    {
    "mitkPlanarCrossTest",
    mitkPlanarCrossTest
  },
  {
    "mitkPlanarPolygonTest",
    mitkPlanarPolygonTest
  },
  {
    "mitkPlanarFigureIOTest",
    mitkPlanarFigureIOTest
  },
  {
    "mitkPlanarFigureObjectFactoryTest",
    mitkPlanarFigureObjectFactoryTest
  },
  {
    "mitkPlanarArrowTest",
    mitkPlanarArrowTest
  },

  {0,0}
}

Definition at line 27 of file PlanarFigureTestDriver.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines