Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Macros
vtkMRMLCoreTestingMacros.h File Reference
#include <vtkMath.h>
#include "vtkMRMLCoreTestingUtilities.h"
#include "vtkMRMLNode.h"
#include <vtkAddonTestingMacros.h>
Include dependency graph for vtkMRMLCoreTestingMacros.h:

Go to the source code of this file.

Macros

#define CHECK_NODE_ID_AND_NAME(node, expectedID, expectedName)
 Verifies if the node's ID and name are the same as expected. More...
 
#define CHECK_NODE_IN_SCENE_BY_ID(scene, nodeID, expected)
 Verifies if the node's pointer defined by nodeID in scene is the same as expected. More...
 
#define EXERCISE_ALL_BASIC_MRML_METHODS(node)   CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseAllBasicMRMLMethods(node));
 Tests all applicable common MRML node methods. More...
 
#define EXERCISE_BASIC_DISPLAY_MRML_METHODS(className, node)   CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicDisplayMRMLMethods(node));
 
#define EXERCISE_BASIC_DISPLAYABLE_MRML_METHODS(className, node)   CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicDisplayableMRMLMethods(node));
 
#define EXERCISE_BASIC_MRML_METHODS(className, node)   CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicMRMLMethods(node));
 
#define EXERCISE_BASIC_OBJECT_METHODS(node)
 
#define EXERCISE_BASIC_STORABLE_MRML_METHODS(className, node)   CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicStorableMRMLMethods(node));
 
#define EXERCISE_BASIC_STORAGE_MRML_METHODS(className, node)   CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicStorageMRMLMethods(node));
 
#define EXERCISE_BASIC_TRANSFORM_MRML_METHODS(className, node)   CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicTransformMRMLMethods(node));
 
#define EXERCISE_BASIC_TRANSFORMABLE_MRML_METHODS(className, node)   CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicTransformableMRMLMethods(node));
 
#define TEST_GET_OBJECT(object, variable)
 test an object variable via Get More...
 
#define TEST_ITK_SET_GET(variable, command)
 test itk set/get More...
 
#define TEST_ITK_SET_GET_VALUE(variable, command)
 test itk set/get More...
 
#define TEST_SET_GET_BOOLEAN(object, variable)
 test object by calling Set on the variable with false, true, 0, 1, On, Off More...
 
#define TEST_SET_GET_DOUBLE(object, variable, value)
 
#define TEST_SET_GET_DOUBLE_RANDOM(object, variable, max)
 
#define TEST_SET_GET_DOUBLE_RANGE(object, variable, min, max)
 
#define TEST_SET_GET_INT(object, variable, value)
 
#define TEST_SET_GET_INT_RANDOM(object, variable, max)
 
#define TEST_SET_GET_INT_RANGE(object, variable, min, max)
 
#define TEST_SET_GET_STRING(object, variable)
 test a string variable on the object by calling Set/Get More...
 
#define TEST_SET_GET_UNSIGNED_INT_RANGE(object, variable, min, max)
 
#define TEST_SET_GET_VALUE(object, variable, value)
 
#define TEST_SET_GET_VECTOR3_DOUBLE(object, variable, x, y, z)
 
#define TEST_SET_GET_VECTOR3_DOUBLE_RANDOM(object, variable, max)
 
#define TEST_SET_GET_VECTOR3_DOUBLE_RANGE(object, variable, min, max)
 
#define TRY_EXPECT_ITK_EXCEPTION(command)
 try the itk command passed in, succeeding if catch an exception More...
 
#define TRY_EXPECT_NO_ITK_EXCEPTION(command)
 try the command passed in, succeeding if no exception More...
 

Macro Definition Documentation

◆ CHECK_NODE_ID_AND_NAME

#define CHECK_NODE_ID_AND_NAME (   node,
  expectedID,
  expectedName 
)
Value:
{ \
if (!vtkMRMLCoreTestingUtilities::CheckNodeIdAndName(__LINE__, (node), (expectedID), (expectedName))) \
{ \
return EXIT_FAILURE; \
} \
}
VTK_MRML_EXPORT bool CheckNodeIdAndName(int line, vtkMRMLNode *node, const char *expectedID, const char *expectedName)

Verifies if the node's ID and name are the same as expected.

Definition at line 35 of file vtkMRMLCoreTestingMacros.h.

◆ CHECK_NODE_IN_SCENE_BY_ID

#define CHECK_NODE_IN_SCENE_BY_ID (   scene,
  nodeID,
  expected 
)
Value:
{ \
if (!vtkMRMLCoreTestingUtilities::CheckNodeInSceneByID(__LINE__, (scene), (nodeID), (expected))) \
{ \
return EXIT_FAILURE; \
} \
}
VTK_MRML_EXPORT bool CheckNodeInSceneByID(int line, vtkMRMLScene *scene, const char *nodeID, vtkMRMLNode *expected)

Verifies if the node's pointer defined by nodeID in scene is the same as expected.

Convenience macros for unit tests.

The macro returns from the current method with EXIT_FAILURE if the check fails. Expressions can be passed as arguments, they are guaranteed to be executed only once.

Definition at line 26 of file vtkMRMLCoreTestingMacros.h.

◆ EXERCISE_ALL_BASIC_MRML_METHODS

#define EXERCISE_ALL_BASIC_MRML_METHODS (   node)    CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseAllBasicMRMLMethods(node));

Tests all applicable common MRML node methods.

Definition at line 374 of file vtkMRMLCoreTestingMacros.h.

◆ EXERCISE_BASIC_DISPLAY_MRML_METHODS

#define EXERCISE_BASIC_DISPLAY_MRML_METHODS (   className,
  node 
)    CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicDisplayMRMLMethods(node));

Definition at line 394 of file vtkMRMLCoreTestingMacros.h.

◆ EXERCISE_BASIC_DISPLAYABLE_MRML_METHODS

#define EXERCISE_BASIC_DISPLAYABLE_MRML_METHODS (   className,
  node 
)    CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicDisplayableMRMLMethods(node));

Definition at line 391 of file vtkMRMLCoreTestingMacros.h.

◆ EXERCISE_BASIC_MRML_METHODS

#define EXERCISE_BASIC_MRML_METHODS (   className,
  node 
)    CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicMRMLMethods(node));

Definition at line 382 of file vtkMRMLCoreTestingMacros.h.

◆ EXERCISE_BASIC_OBJECT_METHODS

#define EXERCISE_BASIC_OBJECT_METHODS (   node)
Value:
{ \
if (result != EXIT_SUCCESS) \
{ \
return result; \
} \
}
VTK_MRML_EXPORT int ExerciseBasicObjectMethods(vtkObject *object)
Test basic VTK object methods (print, superclass, etc.)

Definition at line 364 of file vtkMRMLCoreTestingMacros.h.

◆ EXERCISE_BASIC_STORABLE_MRML_METHODS

#define EXERCISE_BASIC_STORABLE_MRML_METHODS (   className,
  node 
)    CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicStorableMRMLMethods(node));

Definition at line 385 of file vtkMRMLCoreTestingMacros.h.

◆ EXERCISE_BASIC_STORAGE_MRML_METHODS

#define EXERCISE_BASIC_STORAGE_MRML_METHODS (   className,
  node 
)    CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicStorageMRMLMethods(node));

Definition at line 397 of file vtkMRMLCoreTestingMacros.h.

◆ EXERCISE_BASIC_TRANSFORM_MRML_METHODS

#define EXERCISE_BASIC_TRANSFORM_MRML_METHODS (   className,
  node 
)    CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicTransformMRMLMethods(node));

Definition at line 400 of file vtkMRMLCoreTestingMacros.h.

◆ EXERCISE_BASIC_TRANSFORMABLE_MRML_METHODS

#define EXERCISE_BASIC_TRANSFORMABLE_MRML_METHODS (   className,
  node 
)    CHECK_EXIT_SUCCESS(vtkMRMLCoreTestingUtilities::ExerciseBasicTransformableMRMLMethods(node));

Definition at line 388 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_GET_OBJECT

#define TEST_GET_OBJECT (   object,
  variable 
)
Value:
if ( !object->Get##variable() ) \
{ \
std::cerr << "Error in Get"#variable << ", non null value is expected " << std::endl; \
return EXIT_FAILURE; \
} \
object->Get##variable()->Print(std::cout);

test an object variable via Get

Definition at line 252 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_ITK_SET_GET

#define TEST_ITK_SET_GET (   variable,
  command 
)
Value:
if( variable.GetPointer() != command ) \
{ \
std::cerr << "Error in " << #command << std::endl; \
std::cerr << "Expected " << variable.GetPointer() << std::endl; \
std::cerr << "but got " << command << std::endl; \
return EXIT_FAILURE; \
}

test itk set/get

Definition at line 75 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_ITK_SET_GET_VALUE

#define TEST_ITK_SET_GET_VALUE (   variable,
  command 
)
Value:
if( variable != command ) \
{ \
std::cerr << "Error in " << #command << std::endl; \
std::cerr << "Expected " << variable << std::endl; \
std::cerr << "but got " << command << std::endl; \
return EXIT_FAILURE; \
}

test itk set/get

Definition at line 86 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_BOOLEAN

#define TEST_SET_GET_BOOLEAN (   object,
  variable 
)
Value:
object->Set##variable( false ); \
object->Set##variable( true ); \
if( object->Get##variable() == 0 ) \
{ \
std::cerr << "Error in Set/Get"#variable << ", Get"#variable << " returned zero while it is expected to return non-zero" << std::endl; \
return EXIT_FAILURE; \
} \
object->Set##variable( false ); \
if( object->Get##variable() != 0 ) \
{ \
std::cerr << "Error in Set/Get"#variable << ", Get"#variable << " returned " << object->Get##variable() << " instead of 0" << std::endl; \
return EXIT_FAILURE; \
} \
object->variable##On(); \
if( object->Get##variable() == 0 ) \
{ \
std::cerr << "Error in On/Get"#variable << ", Get"#variable << " returned zero while it is expected to return non-zero" << std::endl; \
return EXIT_FAILURE; \
} \
object->variable##Off(); \
if( object->Get##variable() != 0 ) \
{ \
std::cerr << "Error in Off/Get"#variable << ", Get"#variable << " returned " << object->Get##variable() << " while 0 is expected" << std::endl; \
return EXIT_FAILURE; \
}

test object by calling Set on the variable with false, true, 0, 1, On, Off

Definition at line 97 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_DOUBLE

#define TEST_SET_GET_DOUBLE (   object,
  variable,
  value 
)
Value:
{ \
object->Set##variable( value ); \
if( object->Get##variable() != value ) \
{ \
std::cerr << "Error in Set/Get"#variable << " using value " << value << std::endl; \
return EXIT_FAILURE; \
} \
}

test a double variable on the object by setting it to input value using Set, and testing it via the Get

Definition at line 202 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_DOUBLE_RANDOM

#define TEST_SET_GET_DOUBLE_RANDOM (   object,
  variable,
  max 
)
Value:
{ \
double val = vtkMath::Random() * max; \
object->Set##variable( val ); \
if( object->Get##variable() != val ) \
{ \
std::cerr << "Error in Set/Get"#variable << ", using random value " << val << std::endl; \
return EXIT_FAILURE; \
} \
}

test an integer variable on the object by setting it to a random value up to max using Set, and testing it via the Get

Definition at line 239 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_DOUBLE_RANGE

#define TEST_SET_GET_DOUBLE_RANGE (   object,
  variable,
  min,
  max 
)
Value:
{ \
double epsilon = 1.0; \
double val = min - epsilon; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = min; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = min + epsilon; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = (min + max) / 2.0; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = max - epsilon; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = max; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = max + epsilon; \
TEST_SET_GET_DOUBLE( object, variable, val); \
}

Test a double variable on object over the range, calls test set get in with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max, max + epsilon, where first and last test should report errors epsilon set to 1.0

Definition at line 217 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_INT

#define TEST_SET_GET_INT (   object,
  variable,
  value 
)
Value:
{ \
object->Set##variable( value ); \
if( object->Get##variable() != value ) \
{ \
std::cerr << "Error in Set/Get"#variable << " using value " << value << std::endl; \
return EXIT_FAILURE; \
} \
}

test an integer variable on the object by setting it to input value using Set, and testing it via the Get

Definition at line 127 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_INT_RANDOM

#define TEST_SET_GET_INT_RANDOM (   object,
  variable,
  max 
)
Value:
{ \
int val = (int)(vtkMath::Random() * max); \
object->Set##variable( val ); \
if( object->Get##variable() != val ) \
{ \
std::cerr << "Error in Set/Get"#variable << " using random value " << val << std::endl; \
return EXIT_FAILURE; \
} \
}

test an integer variable on the object by setting it to a random value up to max using Set, and testing it via the Get

Definition at line 164 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_INT_RANGE

#define TEST_SET_GET_INT_RANGE (   object,
  variable,
  min,
  max 
)
Value:
{ \
int epsilon = 1; \
int val = min - epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = min; \
TEST_SET_GET_INT( object, variable, val); \
val = min + epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = (min + max) / 2; \
TEST_SET_GET_INT( object, variable, val); \
val = max - epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = max; \
TEST_SET_GET_INT( object, variable, val); \
val = max + epsilon; \
TEST_SET_GET_INT( object, variable, val); \
}

Test an integer variable on object over the range, calls test set get in with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max, max + epsilon, where first and last test should report errors epsilon defined as 1

Definition at line 142 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_STRING

#define TEST_SET_GET_STRING (   object,
  variable 
)

test a string variable on the object by calling Set/Get

Definition at line 326 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_UNSIGNED_INT_RANGE

#define TEST_SET_GET_UNSIGNED_INT_RANGE (   object,
  variable,
  min,
  max 
)
Value:
{ \
unsigned int epsilon = 1; \
unsigned int val = min - epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = min; \
TEST_SET_GET_INT( object, variable, val); \
val = min + epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = (min + max) / 2; \
TEST_SET_GET_INT( object, variable, val); \
val = max - epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = max; \
TEST_SET_GET_INT( object, variable, val); \
val = max + epsilon; \
TEST_SET_GET_INT( object, variable, val); \
}

Test an unsigned integer variable on object over the range, calls test set get in with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max, max + epsilon, where first and last test should report errors epsilon defined as 1

Definition at line 180 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_VALUE

#define TEST_SET_GET_VALUE (   object,
  variable,
  value 
)
Value:
object->Set##variable(value); \
if (object->Get##variable() != value) \
{ \
std::cerr << "Error getting " << #variable << std::endl; \
std::cerr << "Expected " << value << std::endl; \
std::cerr << "but got " << object->Get##variable()<< std::endl; \
return EXIT_FAILURE; \
}

test an object variable on the object by setting it to input value using Set, and testing it via the Get

Definition at line 263 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_VECTOR3_DOUBLE

#define TEST_SET_GET_VECTOR3_DOUBLE (   object,
  variable,
  x,
  y,
 
)
Value:
{ \
object->Set##variable( x, y, z ); \
double *val = object->Get##variable(); \
if( val == nullptr || val[0] != x || val[1] != y || val[2] != z ) \
{ \
std::cerr << "Error in Set/Get"#variable << std::endl; \
return EXIT_FAILURE; \
} \
}

test a vector variable on the object by setting it to a the values x, y, z passed in using Set, and testing it via the Get

Definition at line 276 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_VECTOR3_DOUBLE_RANDOM

#define TEST_SET_GET_VECTOR3_DOUBLE_RANDOM (   object,
  variable,
  max 
)
Value:
{ \
double x = vtkMath::Random() * max; \
double y = vtkMath::Random() * max; \
double z = vtkMath::Random() * max; \
object->Set##variable( x, y, z ); \
double val[3] = {0.0, 0.0, 0.0}; \
object->Get##variable(val); \
if( val[0] != x || val[1] != y || val[2] != z ) \
{ \
std::cerr << "Error in Set/Get"#variable << " with " << x << ", " << y << ", " << z << std::endl; \
return EXIT_FAILURE; \
} \
}

test a vector variable on the object by setting all it's elements to the same random value up to max using Set, and testing it via the Get

Definition at line 309 of file vtkMRMLCoreTestingMacros.h.

◆ TEST_SET_GET_VECTOR3_DOUBLE_RANGE

#define TEST_SET_GET_VECTOR3_DOUBLE_RANGE (   object,
  variable,
  min,
  max 
)
Value:
{ \
double epsilon = 1.0; \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min - epsilon, min - epsilon, min - epsilon); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min, min, min); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min + epsilon, min + epsilon, min + epsilon); \
double half = (min+max/2.0); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, half, half, half); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max - epsilon, max - epsilon, max - epsilon); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max, max, max); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max + epsilon, max + epsilon, max + epsilon); \
}

Test a double vector variable on object over the range, calls test set get in with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max, max + epsilon, where first and last test should report errors. For now all three elements are set to the same thing each time. epsilon set to 1.0

Definition at line 293 of file vtkMRMLCoreTestingMacros.h.

◆ TRY_EXPECT_ITK_EXCEPTION

#define TRY_EXPECT_ITK_EXCEPTION (   command)
Value:
try \
{ \
std::cout << "Trying " << #command << std::endl; \
command; \
std::cerr << "Failed to catch expected exception" << std::endl; \
return EXIT_FAILURE; \
} \
catch( itk::ExceptionObject & excp ) \
{ \
std::cout << "Caught expected exception" << std::endl; \
std::cout << excp << std::endl; \
}

try the itk command passed in, succeeding if catch an exception

Definition at line 45 of file vtkMRMLCoreTestingMacros.h.

◆ TRY_EXPECT_NO_ITK_EXCEPTION

#define TRY_EXPECT_NO_ITK_EXCEPTION (   command)
Value:
try \
{ \
std::cout << "Trying " << #command << std::endl; \
command; \
} \
catch( itk::ExceptionObject & excp ) \
{ \
std::cerr << excp << std::endl; \
return EXIT_FAILURE; \
}

try the command passed in, succeeding if no exception

Definition at line 61 of file vtkMRMLCoreTestingMacros.h.