CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
Macros
ctkCoreTestingMacros.h File Reference
#include "ctkCoreTestingUtilities.h"
Include dependency graph for ctkCoreTestingMacros.h:

Go to the source code of this file.

Macros

#define CHECK_BOOL(actual, expected)
 Verifies if actual bool value is the same as expected. More...
 
#define CHECK_EXIT_SUCCESS(actual)
 
#define CHECK_INT(actual, expected)
 Verifies if actual int value is the same as expected. More...
 
#define CHECK_NOT_NULL(pointer)
 Verifies that pointer is not NULL. More...
 
#define CHECK_NULL(pointer)
 Verifies that pointer is NULL. More...
 
#define CHECK_POINTER(actual, expected)
 Verifies if actual pointer value is the same as expected. More...
 
#define CHECK_POINTER_DIFFERENT(actual, expected)
 Verifies if actual pointer value is the same as expected. More...
 
#define CHECK_QSTRING(actual, expected)
 
#define CHECK_QSTRING_DIFFERENT(actual, expected)
 
#define CHECK_QSTRINGLIST(actual, expected)
 Verifies if actual QStringList is the same as expected. More...
 
#define CHECK_QVARIANT(actual, expected)
 Verifies if actual QVariant is the same as expected. More...
 
#define CHECK_STD_STRING(actual, expected)
 
#define CHECK_STD_STRING_DIFFERENT(actual, expected)
 
#define CHECK_STRING(actual, expected)
 
#define CHECK_STRING_DIFFERENT(actual, expected)
 

Macro Definition Documentation

◆ CHECK_BOOL

#define CHECK_BOOL (   actual,
  expected 
)
Value:
{ \
if (!ctkCoreTestingUtilities::CheckInt(__LINE__,#actual " != " #expected, (actual)?1:0, (expected)?1:0)) \
{ \
return EXIT_FAILURE; \
} \
}
CTK_CORE_EXPORT bool CheckInt(int line, const QString &description, int current, int expected)

Verifies if actual bool value is the same as expected.

Definition at line 106 of file ctkCoreTestingMacros.h.

◆ CHECK_EXIT_SUCCESS

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

Definition at line 70 of file ctkCoreTestingMacros.h.

◆ CHECK_INT

#define CHECK_INT (   actual,
  expected 
)
Value:
{ \
if (!ctkCoreTestingUtilities::CheckInt(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
return EXIT_FAILURE; \
} \
}

Verifies if actual int value is the same as expected.

Definition at line 79 of file ctkCoreTestingMacros.h.

◆ CHECK_NOT_NULL

#define CHECK_NOT_NULL (   pointer)
Value:
{ \
if (!ctkCoreTestingUtilities::CheckNotNull(__LINE__,#pointer " is NULL", (pointer))) \
{ \
return EXIT_FAILURE; \
} \
}
CTK_CORE_EXPORT bool CheckNotNull(int line, const QString &description, const void *pointer)

Verifies that pointer is not NULL.

Definition at line 62 of file ctkCoreTestingMacros.h.

◆ CHECK_NULL

#define CHECK_NULL (   pointer)
Value:
{ \
const void* pointerValue = (pointer); \
if (!ctkCoreTestingUtilities::CheckNull(__LINE__,#pointer " is not NULL", pointerValue)) \
{ \
return EXIT_FAILURE; \
} \
}
CTK_CORE_EXPORT bool CheckNull(int line, const QString &description, const void *pointer)

Verifies that pointer is NULL.

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.

Example:

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;
}
#define CHECK_INT(actual, expected)
Verifies if actual int value is the same as expected.

Definition at line 52 of file ctkCoreTestingMacros.h.

◆ CHECK_POINTER

#define CHECK_POINTER (   actual,
  expected 
)
Value:
{ \
if (!ctkCoreTestingUtilities::CheckPointer(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
return EXIT_FAILURE; \
} \
}
CTK_CORE_EXPORT bool CheckPointer(int line, const QString &description, void *current, void *expected, bool errorIfDifferent=true)

Verifies if actual pointer value is the same as expected.

Definition at line 88 of file ctkCoreTestingMacros.h.

◆ CHECK_POINTER_DIFFERENT

#define CHECK_POINTER_DIFFERENT (   actual,
  expected 
)
Value:
{ \
if (!ctkCoreTestingUtilities::CheckPointer(__LINE__,#actual " == " #expected, (actual), (expected), false)) \
{ \
return EXIT_FAILURE; \
} \
}

Verifies if actual pointer value is the same as expected.

Definition at line 97 of file ctkCoreTestingMacros.h.

◆ CHECK_QSTRING

#define CHECK_QSTRING (   actual,
  expected 
)
Value:
{ \
QString a = (actual); \
QString e = (expected); \
if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, qPrintable(a), qPrintable(e))) \
{ \
return EXIT_FAILURE; \
} \
}
CTK_CORE_EXPORT bool CheckString(int line, const QString &description, const char *current, const char *expected, bool errorIfDifferent=true)

Verifies if actual QString value is the same as expected. It is safe to use for comparing QString values. It cannot handle NULL pointer inputs.

Definition at line 140 of file ctkCoreTestingMacros.h.

◆ CHECK_QSTRING_DIFFERENT

#define CHECK_QSTRING_DIFFERENT (   actual,
  expected 
)
Value:
{ \
QString a = (actual); \
QString e = (expected); \
if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, qPrintable(a), qPrintable(e), false)) \
{ \
return EXIT_FAILURE; \
} \
}

Verifies if actual QString value is not the same as expected. It is safe to use for comparing QString values. It cannot handle NULL pointer inputs.

Definition at line 176 of file ctkCoreTestingMacros.h.

◆ CHECK_QSTRINGLIST

#define CHECK_QSTRINGLIST (   actual,
  expected 
)
Value:
{ \
QStringList a = (actual); \
QStringList e = (expected); \
if (!ctkCoreTestingUtilities::CheckStringList(__LINE__,#actual " != " #expected, a, e)) \
{ \
return EXIT_FAILURE; \
} \
}
CTK_CORE_EXPORT bool CheckStringList(int line, const QString &description, const QStringList &current, const QStringList &expected)

Verifies if actual QStringList is the same as expected.

Definition at line 187 of file ctkCoreTestingMacros.h.

◆ CHECK_QVARIANT

#define CHECK_QVARIANT (   actual,
  expected 
)
Value:
{ \
QVariant a = (actual); \
QVariant e = (expected); \
if (!ctkCoreTestingUtilities::CheckVariant(__LINE__,#actual " != " #expected, a, e)) \
{ \
return EXIT_FAILURE; \
} \
}
CTK_CORE_EXPORT bool CheckVariant(int line, const QString &description, const QVariant &current, const QVariant &expected)

Verifies if actual QVariant is the same as expected.

Definition at line 198 of file ctkCoreTestingMacros.h.

◆ CHECK_STD_STRING

#define CHECK_STD_STRING (   actual,
  expected 
)
Value:
{ \
std::string a = (actual); \
std::string e = (expected); \
if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, a.c_str(), e.c_str())) \
{ \
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.

Definition at line 127 of file ctkCoreTestingMacros.h.

◆ CHECK_STD_STRING_DIFFERENT

#define CHECK_STD_STRING_DIFFERENT (   actual,
  expected 
)
Value:
{ \
std::string a = (actual); \
std::string e = (expected); \
if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, a.c_str(), e.c_str(), 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.

Definition at line 163 of file ctkCoreTestingMacros.h.

◆ CHECK_STRING

#define CHECK_STRING (   actual,
  expected 
)
Value:
{ \
if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
return EXIT_FAILURE; \
} \
}

Verifies if actual const char* value is the same as expected. It can handle NULL pointer inputs.

Definition at line 116 of file ctkCoreTestingMacros.h.

◆ CHECK_STRING_DIFFERENT

#define CHECK_STRING_DIFFERENT (   actual,
  expected 
)
Value:
{ \
if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, (actual), (expected), false)) \
{ \
return EXIT_FAILURE; \
} \
}

Verifies if actual const char* value is not the same as expected. It can handle NULL pointer inputs.

Definition at line 152 of file ctkCoreTestingMacros.h.