Skip to content
Permalink
Browse files

STYLE: Add vtkAddonTestingUtilities and vtkAddonTestingMacros

This is done anticipating the addition of "vtkAddonMathUtilities" and
associated test to vtkAddon.

From: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>

git-svn-id: http://svn.slicer.org/Slicer4/trunk@25095 3bd1e089-480b-0410-8dfb-8563597acbee
  • Loading branch information...
jcfr committed May 20, 2016
1 parent fe45f62 commit 4101ff50577ead42a1bef23f417448b65453b1e7
@@ -30,96 +30,18 @@
using namespace vtkMRMLCoreTestingUtilities;

//----------------------------------------------------------------------------
bool TestCheckInt();
bool TestCheckNotNull();
bool TestCheckNull();
bool TestCheckPointer();
bool TestCheckString();
bool TestCheckNodeInSceneByID();
bool TestCheckNodeIdAndName();

//----------------------------------------------------------------------------
int vtkMRMLCoreTestingUtilitiesTest(int , char * [] )
{
bool res = true;
res = res && TestCheckInt();
res = res && TestCheckNotNull();
res = res && TestCheckNull();
res = res && TestCheckPointer();
res = res && TestCheckString();
res = res && TestCheckNodeInSceneByID();
res = res && TestCheckNodeIdAndName();
return res ? EXIT_SUCCESS : EXIT_FAILURE;
}

//----------------------------------------------------------------------------
bool TestCheckInt()
{
if (!CheckInt(__LINE__, "TestCheckInt", 1, 1)
|| CheckInt(__LINE__, "TestCheckInt Expected Failure", 1, -1))
{
std::cerr << "Line " << __LINE__ << " - TestCheckInt failed" << std::endl;
return false;
}
return true;
}

//----------------------------------------------------------------------------
bool TestCheckNotNull()
{
int foo = 1;
if (!CheckNotNull(__LINE__, "TestCheckNotNull", &foo)
|| CheckNotNull(__LINE__, "TestCheckNotNull Expected Failure", 0))
{
std::cerr << "Line " << __LINE__ << " - TestCheckNotNull failed" << std::endl;
return false;
}
return true;
}

//----------------------------------------------------------------------------
bool TestCheckNull()
{
int foo = 1;
if (!CheckNull(__LINE__, "TestCheckNull", 0)
|| CheckNull(__LINE__, "TestCheckNull Expected Failure", &foo))
{
std::cerr << "Line " << __LINE__ << " - TestCheckNull failed" << std::endl;
return false;
}
return true;
}

//----------------------------------------------------------------------------
bool TestCheckPointer()
{
int foo = 1;
int bar = 1;
if (!CheckPointer(__LINE__, "TestCheckPointer", &foo, &foo)
|| CheckPointer(__LINE__, "TestCheckPointer Expected Failure", &foo, &bar))
{
std::cerr << "Line " << __LINE__ << " - TestCheckPointer failed" << std::endl;
return false;
}
return true;
}

//----------------------------------------------------------------------------
bool TestCheckString()
{
const char* foo = "foo";
const char* bar = "bar";
if (!CheckString(__LINE__, "TestCheckString", 0, 0)
||!CheckString(__LINE__, "TestCheckString", foo, foo)
|| CheckString(__LINE__, "TestCheckString Expected Failure", foo, bar)
|| CheckString(__LINE__, "TestCheckString Expected Failure", foo, 0))
{
std::cerr << "Line " << __LINE__ << " - TestCheckString failed" << std::endl;
return false;
}
return true;
}

namespace
{

@@ -27,6 +27,7 @@
// STD includes
#include <sstream>

using namespace vtkAddonTestingUtilities;
using namespace vtkMRMLCoreTestingUtilities;

//---------------------------------------------------------------------------
@@ -2906,6 +2907,7 @@ void DisplaySceneNodeReferences(
//----------------------------------------------------------------------------
bool TestImportSceneReferenceValidDuringImport()
{
(void)(DisplaySceneNodeReferences); // Avoid unused-function warning

//
// Create scene and register node
@@ -21,168 +21,6 @@
/// 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.
///
/// Example:
///
/// \code{.cpp}
/// int testedFunction(int a, int b) { return a+b; }
///
/// int MyTest1(int , char * [])
/// {
///
/// int current = 40 + 2;
/// int expected = 42;
/// CHECK_INT(current, expected);
///
/// CHECK_INT(testedFunction(40,2), 42);
/// CHECK_INT(testedFunction(35,5), 40);
///
/// return EXIT_SUCCESS;
/// }
///
/// \endcode

/// Verifies that pointer is NULL
#define CHECK_NULL(pointer) \
{ \
const void* pointerValue = (pointer); \
if (!vtkMRMLCoreTestingUtilities::CheckNull(__LINE__,#pointer " is not NULL", pointerValue)) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies that pointer is not NULL
#define CHECK_NOT_NULL(pointer) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckNotNull(__LINE__,#pointer " is NULL", (pointer))) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies that pointer is NULL,
/// if check fails then it calls methodToCallOnFailure before returning with failure
#define CHECK_NOT_NULL_ADD_REPORT(pointer, methodToCallOnFailure) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckNotNull(__LINE__,#pointer " is NULL", (pointer))) \
{ \
methodToCallOnFailure; \
return EXIT_FAILURE; \
} \
}

#define CHECK_EXIT_SUCCESS(actual) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckInt(__LINE__,#actual " != EXIT_SUCCESS", (actual), EXIT_SUCCESS)) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies if actual int value is the same as expected
#define CHECK_INT(actual, expected) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckInt(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies if actual int value is the same as expected,
/// if check fails then it calls methodToCallOnFailure before returning with failure
#define CHECK_INT_ADD_REPORT(actual, expected, methodToCallOnFailure) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckInt(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
methodToCallOnFailure; \
return EXIT_FAILURE; \
} \
}

/// Verifies if actual pointer value is the same as expected
#define CHECK_POINTER(actual, expected) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckPointer(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies if actual pointer value is the same as expected
#define CHECK_POINTER_DIFFERENT(actual, expected) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckPointer(__LINE__,#actual " == " #expected, (actual), (expected), false)) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies if actual bool value is the same as expected
#define CHECK_BOOL(actual, expected) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckInt(__LINE__,#actual " != " #expected, (actual)?1:0, (expected)?1:0)) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies if actual const char* value is the same as expected.
/// It can handle NULL pointer inputs.
#define CHECK_STRING(actual, expected) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies if actual std::string value is the same as expected.
/// It is safe to use for comparing std::string values.
/// It cannot handle NULL pointer inputs.
#define CHECK_STD_STRING(actual, expected) \
{ \
std::string a = (actual); \
std::string e = (expected); \
if (!vtkMRMLCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, a.c_str(), e.c_str())) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies if actual const char* value is the same as expected,
/// if check fails then it calls methodToCallOnFailure before returning with failure
/// It can handle NULL pointer inputs.
#define CHECK_STRING_ADD_REPORT(actual, expected, methodToCallOnFailure) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
methodToCallOnFailure; \
return EXIT_FAILURE; \
} \
}

/// Verifies if actual const char* value is not the same as expected.
/// It can handle NULL pointer inputs.
#define CHECK_STRING_DIFFERENT(actual, expected) \
{ \
if (!vtkMRMLCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, (actual), (expected), false)) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies if actual std::string value is not the same as expected.
/// It is safe to use for comparing std::string values.
/// It cannot handle NULL pointer inputs.
#define CHECK_STD_STRING_DIFFERENT(actual, expected) \
{ \
std::string a = (actual); \
std::string e = (expected); \
if (!vtkMRMLCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, a.c_str(), e.c_str(), false)) \
{ \
return EXIT_FAILURE; \
} \
}

/// Verifies if the node's pointer defined by nodeID in scene is the same as expected
#define CHECK_NODE_IN_SCENE_BY_ID(scene, nodeID, expected) \
@@ -568,7 +406,6 @@
#include "vtkMRMLNode.h"

// Commonly used headers in tests
#include "vtkNew.h"
#include "vtkTestingOutputWindow.h"
#include <vtkAddonTestingMacros.h>

#endif

0 comments on commit 4101ff5

Please sign in to comment.
You can’t perform that action at this time.