version 1.2, 2015/04/20 18:10:35
|
version 1.3, 2015/04/20 18:20:37
|
|
|
#ifndef _ut_ut_h | #ifndef _ut_ut_h |
#define _ut_ut_h | #define _ut_ut_h |
| |
|
#if !defined(TEST_BUILD) |
|
# define TEST_BUILD |
|
#endif |
|
|
#include <common.h> | #include <common.h> |
#include <string> | #include <string> |
#include <cassert> | #include <cassert> |
#include <cstdio> | #include <cstdio> |
#include <sstream> | #include <sstream> |
| |
|
#include <nits/base/nits.h> |
|
|
|
|
// A constant 'false' value that can be used in a condition with getting the | // A constant 'false' value that can be used in a condition with getting the |
// 'conditional expression is constant' warning from from Windows. |
// 'conditional expression is constant' warning from Windows. |
inline bool __UT_False() { return false; } | inline bool __UT_False() { return false; } |
#define UT_FALSE __UT_False() | #define UT_FALSE __UT_False() |
| |
|
#define TEST_ASSERT(x) NitsAssert(x, PAL_T("")) |
|
|
//============================================================================== | //============================================================================== |
// | // |
// Test framework macros: |
// NITS version of these macros: |
// | // |
//============================================================================== | //============================================================================== |
| |
#define UT_ASSERT(cond) \ | #define UT_ASSERT(cond) \ |
do \ | do \ |
{ \ | { \ |
if(!(cond)) \ |
NitsAssertExA((cond) != 0, "", NitsHere(), NitsAutomatic); \ |
throw(ut::UnittestException(__FILE__, __LINE__, __FUNCTION__, \ |
|
#cond)); \ |
|
} \ | } \ |
while (__UT_False()) | while (__UT_False()) |
| |
#define UT_ASSERT_EQUAL(v1, v2) \ | #define UT_ASSERT_EQUAL(v1, v2) \ |
do \ | do \ |
{ \ | { \ |
if((v1) != (v2)) \ |
NitsAssertExA((v1) == (v2), "", NitsHere(), NitsAutomatic); \ |
{ \ |
|
std::stringstream ss; \ |
|
ss << #v1; \ |
|
ss << " == "; \ |
|
ss << #v2; \ |
|
ss << "; {"; \ |
|
ss << v1; \ |
|
ss << " == "; \ |
|
ss << v2; \ |
|
ss << "}"; \ |
|
\ |
|
throw(ut::UnittestException(__FILE__, __LINE__, __FUNCTION__, \ |
|
ss.str().c_str())); \ |
|
}\ |
|
} \ | } \ |
while (__UT_False()) | while (__UT_False()) |
| |
|
|
#define UT_ASSERT_NOT_EQUAL(v1, v2) \ | #define UT_ASSERT_NOT_EQUAL(v1, v2) \ |
do \ | do \ |
{ \ | { \ |
if((v1) == (v2)) \ |
NitsAssertExA((v1) != (v2), "", NitsHere(), NitsAutomatic); \ |
{ \ |
|
std::stringstream ss; \ |
|
ss << #v1; \ |
|
ss << " != "; \ |
|
ss << #v2; \ |
|
ss << "; {"; \ |
|
ss << v1; \ |
|
ss << " != "; \ |
|
ss << v2; \ |
|
ss << "}"; \ |
|
\ |
|
throw(ut::UnittestException(__FILE__, __LINE__, __FUNCTION__, \ |
|
ss.str().c_str())); \ |
|
}\ |
|
} \ | } \ |
while (__UT_False()) | while (__UT_False()) |
| |
void __UT_TEST( |
|
const char* testName, |
|
void (*setUp)(), |
|
void (*cleanUp)(), |
|
void (*test)()); |
|
|
|
#define UT_TEST(test) __UT_TEST(#test, setUp, cleanup, test) |
|
|
|
#define UT_ASSERT_FAILED_MSG(message) \ | #define UT_ASSERT_FAILED_MSG(message) \ |
throw(ut::UnittestException(__FILE__, __LINE__, __FUNCTION__, (message))) |
do {\ |
|
NitsAssertExA(0, message, NitsHere(), NitsAutomatic); \ |
#define UT_ENTRY_POINT(FUNC) static ut::TestRegister __entry(FUNC) |
} \ |
|
while (__UT_False()) |
| |
#define UT_WARNING(text) ut::testWarning(text) |
# define UT_WARNING(text) \ |
|
do { \ |
|
NitsTraceExA(text, NitsHere(), NitsAutomatic); \ |
|
} \ |
|
while (__UT_False()) |
| |
//============================================================================== | //============================================================================== |
// | // |
|
|
} | } |
}; | }; |
| |
|
INLINE int Assert( |
|
int cond, |
|
const char* condStr, |
|
const char* file, |
|
int line, |
|
const char* function) |
|
{ |
|
if (!cond) |
|
throw(ut::UnittestException(file, line, function, condStr)); |
|
return cond; |
|
} |
|
|
typedef void (*MODULE_TEST_CALLBACK) (); | typedef void (*MODULE_TEST_CALLBACK) (); |
| |
// interanl callbacks - used by macros | // interanl callbacks - used by macros |
|
|
| |
void testWarning(const char* text); | void testWarning(const char* text); |
| |
/////////////////////////////// |
|
// registration helper |
|
struct TestRegister |
|
{ |
|
TestRegister(MODULE_TEST_CALLBACK pfn) { registerCallback(pfn); } |
|
}; |
|
|
|
bool testGetAttr(const std::string& name, std::string& value); | bool testGetAttr(const std::string& name, std::string& value); |
}; | }; |
| |