r20 | charles.nicholson | 2010-03-18 16:49:54 -0500 (Thu, 18 Mar 2010) | 1 line

add UNITTEST_WIN32 macro, turn dllmacros.h into helpermacros.h, wrap do/while(0) in __pragma to avoid VS 'conditional expression is constant' warning
This commit is contained in:
Patrick Johnmeyer 2013-01-09 23:44:37 -06:00
parent a0501f6b71
commit 534aca3236
19 changed files with 64 additions and 58 deletions

View file

@ -4,7 +4,6 @@
// Standard defines documented here: http://predef.sourceforge.net
#if defined(_MSC_VER)
#pragma warning(disable:4127) // conditional expression is constant
#pragma warning(disable:4702) // unreachable code
#pragma warning(disable:4722) // destructor never returns, potential memory leak
@ -16,6 +15,7 @@
#ifdef _USRDLL
#define UNITTEST_WIN32_DLL
#endif
#define UNITTEST_WIN32
#endif
#if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \
@ -30,8 +30,8 @@
// by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive.
// uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream).
#define UNITTEST_USE_CUSTOM_STREAMS
//#define UNITTEST_USE_CUSTOM_STREAMS
#define UNITTEST_USE_DEFERRED_REPORTER
#define UNITTEST_USE_EXCEPTIONS
//#define UNITTEST_USE_EXCEPTIONS
#endif

View file

@ -4,7 +4,7 @@
#include "../config.h"
#ifdef UNITTEST_USE_EXCEPTIONS
#include "DllMacros.h"
#include "HelperMacros.h"
#include <exception>
namespace UnitTest {

View file

@ -1,6 +1,7 @@
#ifndef UNITTEST_CHECKMACROS_H
#define UNITTEST_CHECKMACROS_H
#include "HelperMacros.h"
#include "ExceptionMacros.h"
#include "Checks.h"
#include "AssertException.h"
@ -34,9 +35,8 @@
#endif
#define CHECK(value) \
do \
{ \
UT_TRY \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
({ \
if (!UnitTest::Check(value)) \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
@ -46,11 +46,10 @@
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK(" #value ")"); \
}) \
} while (0)
UNITTEST_MULTILINE_MACRO_END
#define CHECK_EQUAL(expected, actual) \
do \
{ \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
({ \
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
@ -60,11 +59,10 @@
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
}) \
} while (0)
UNITTEST_MULTILINE_MACRO_END
#define CHECK_CLOSE(expected, actual, tolerance) \
do \
{ \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
({ \
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
@ -74,11 +72,10 @@
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
}) \
} while (0)
UNITTEST_MULTILINE_MACRO_END
#define CHECK_ARRAY_EQUAL(expected, actual, count) \
do \
{ \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
({ \
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
@ -88,11 +85,10 @@
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
}) \
} while (0)
UNITTEST_MULTILINE_MACRO_END
#define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
do \
{ \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
({ \
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
@ -102,11 +98,10 @@
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
}) \
} while (0)
UNITTEST_MULTILINE_MACRO_END
#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
do \
{ \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
({ \
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
@ -116,29 +111,27 @@
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
}) \
} while (0)
UNITTEST_MULTILINE_MACRO_END
// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_USE_EXCEPTIONS is defined (see Config.h)
#ifdef UNITTEST_USE_EXCEPTIONS
#define CHECK_THROW(expression, ExpectedExceptionType) \
do \
{ \
UNITTEST_MULTILINE_MACRO_BEGIN \
bool caught_ = false; \
try { expression; } \
catch (ExpectedExceptionType const&) { caught_ = true; } \
catch (...) {} \
if (!caught_) \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \
} while(0)
UNITTEST_MULTILINE_MACRO_END
#define CHECK_ASSERT(expression) \
do \
{ \
UNITTEST_MULTILINE_MACRO_BEGIN \
UnitTest::Detail::ExpectAssert(true); \
CHECK_THROW(expression, UnitTest::AssertException); \
UnitTest::Detail::ExpectAssert(false); \
} while(0)
UNITTEST_MULTILINE_MACRO_END
#endif
#endif

View file

@ -1,7 +1,7 @@
#ifndef UNITTEST_CURRENTTESTRESULTS_H
#define UNITTEST_CURRENTTESTRESULTS_H
#include "DllMacros.h"
#include "HelperMacros.h"
namespace UnitTest {

View file

@ -4,7 +4,7 @@
#include "../config.h"
#ifdef UNITTEST_USE_DEFERRED_REPORTER
#include "DllMacros.h"
#include "HelperMacros.h"
#include <string>
#include <vector>

View file

@ -1,8 +1,18 @@
#ifndef UNITTEST_DLLMACROS_H
#define UNITTEST_DLLMACROS_H
#ifndef UNITTEST_HELPERMACROS_H
#define UNITTEST_HELPERMACROS_H
#include "../config.h"
#define UNITTEST_MULTILINE_MACRO_BEGIN do {
#ifdef UNITTEST_WIN32
#define UNITTEST_MULTILINE_MACRO_END \
} __pragma(warning(push)) __pragma(warning(disable:4127)) while (0) __pragma(warning(pop))
#else
#define UNITTEST_MULTILINE_MACRO_END } while(0)
#endif
#ifdef UNITTEST_WIN32_DLL
#define UNITTEST_IMPORT __declspec(dllimport)
#define UNITTEST_EXPORT __declspec(dllexport)

View file

@ -2,7 +2,7 @@
#define UNITTEST_MEMORYOUTSTREAM_H
#include "../config.h"
#include "DllMacros.h"
#include "HelperMacros.h"
#ifndef UNITTEST_USE_CUSTOM_STREAMS

View file

@ -1,7 +1,7 @@
#ifndef UNITTEST_ASSERT_H
#define UNITTEST_ASSERT_H
#include "DllMacros.h"
#include "HelperMacros.h"
namespace UnitTest {

View file

@ -27,7 +27,7 @@ UNITTEST_LINKAGE bool AssertExpected();
#ifndef UNITTEST_USE_EXCEPTIONS
UNITTEST_LINKAGE jmp_buf* GetAssertJmpBuf();
#ifdef _MSC_VER
#ifdef UNITTEST_WIN32
#define UNITTEST_SET_ASSERT_JUMP_TARGET() \
__pragma(warning(push)) __pragma(warning(disable:4611)) \
setjmp(*UnitTest::Detail::GetAssertJmpBuf()) \

View file

@ -1,7 +1,7 @@
#ifndef UNITTEST_TESTDETAILS_H
#define UNITTEST_TESTDETAILS_H
#include "DllMacros.h"
#include "HelperMacros.h"
namespace UnitTest {

View file

@ -1,7 +1,7 @@
#ifndef UNITTEST_TESTLIST_H
#define UNITTEST_TESTLIST_H
#include "DllMacros.h"
#include "HelperMacros.h"
namespace UnitTest {

View file

@ -1,7 +1,7 @@
#ifndef UNITTEST_TESTREPORTER_H
#define UNITTEST_TESTREPORTER_H
#include "DllMacros.h"
#include "HelperMacros.h"
namespace UnitTest {

View file

@ -4,7 +4,7 @@
#include "TestDetails.h"
// cstdio doesn't pull in namespace std on VC6, so we do it here.
#if defined(_MSC_VER) && (_MSC_VER == 1200)
#if defined(UNITTEST_WIN32) && (_MSC_VER == 1200)
namespace std {}
#endif

View file

@ -1,7 +1,7 @@
#ifndef UNITTEST_TESTRESULTS_H
#define UNITTEST_TESTRESULTS_H
#include "DllMacros.h"
#include "HelperMacros.h"
namespace UnitTest {

View file

@ -2,7 +2,7 @@
#define UNITTEST_TIMECONSTRAINT_H
#include "TimeHelpers.h"
#include "DllMacros.h"
#include "HelperMacros.h"
namespace UnitTest {
@ -27,7 +27,10 @@ private:
#define UNITTEST_TIME_CONSTRAINT(ms) \
UnitTest::TimeConstraint unitTest__timeConstraint__(ms, UnitTest::TestDetails(m_details, __LINE__))
#define UNITTEST_TIME_CONSTRAINT_EXEMPT() do { m_timeConstraintExempt = true; } while (0)
#define UNITTEST_TIME_CONSTRAINT_EXEMPT() \
UNITTEST_MULTILINE_MACRO_BEGIN \
m_timeConstraintExempt = true; \
UNITTEST_MULTILINE_MACRO_END
}

View file

@ -9,7 +9,7 @@ Timer::Timer()
: m_threadHandle(::GetCurrentThread())
, m_startTime(0)
{
#if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR
#if defined(UNITTEST_WIN32) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR
typedef unsigned long DWORD_PTR;
#endif

View file

@ -2,7 +2,7 @@
#define UNITTEST_TIMEHELPERS_H
#include "../../config.h"
#include "../DllMacros.h"
#include "../HelperMacros.h"
#ifdef UNITTEST_MINGW
#ifndef __int64

View file

@ -93,7 +93,7 @@ TEST(CheckCloseFailsOnException)
RecordingReporter reporter;
UnitTest::TestResults testResults(&reporter);
ScopedCurrentTest scopedResults(testResults);
CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f);
CHECK_CLOSE((float)ThrowingFunction(), 1.0001f, 0.1f);
failure = (testResults.GetFailureCount() > 0);
}
@ -108,7 +108,7 @@ TEST(CheckCloseFailureBecauseOfExceptionContainsCorrectDetails)
UnitTest::TestResults testResults(&reporter);
UnitTest::TestDetails testDetails("closeTest", "closeSuite", "filename", -1);
ScopedCurrentTest scopedResults(testResults, &testDetails);
CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); line = __LINE__;
CHECK_CLOSE((float)ThrowingFunction(), 1.0001f, 0.1f); line = __LINE__;
}
CHECK_EQUAL("closeTest", reporter.lastFailedTest);
@ -123,7 +123,7 @@ TEST(CheckCloseFailureBecauseOfExceptionIncludesCheckContents)
{
UnitTest::TestResults testResults(&reporter);
ScopedCurrentTest scopedResults(testResults);
CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f);
CHECK_CLOSE((float)ThrowingFunction(), 1.0001f, 0.1f);
}
CHECK(strstr(reporter.lastFailedMessage, "(float)ThrowingFunction()"));
@ -149,7 +149,7 @@ TEST(CheckArrayCloseFailureBecauseOfExceptionContainsCorrectDetails)
ScopedCurrentTest scopedResults(testResults, &testDetails);
int const data[4] = { 0, 1, 2, 3 };
CHECK_ARRAY_CLOSE (data, ThrowingObject(), 4, 0.01f); line = __LINE__;
CHECK_ARRAY_CLOSE(data, ThrowingObject(), 4, 0.01f); line = __LINE__;
}
CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest);
@ -168,7 +168,7 @@ TEST(CheckArrayCloseFailsOnException)
const float data[4] = { 0, 1, 2, 3 };
ThrowingObject obj;
CHECK_ARRAY_CLOSE (data, obj, 3, 0.01f);
CHECK_ARRAY_CLOSE(data, obj, 3, 0.01f);
failure = (testResults.GetFailureCount() > 0);
}
@ -185,7 +185,7 @@ TEST(CheckArrayCloseFailureOnExceptionIncludesCheckContents)
const float data[4] = { 0, 1, 2, 3 };
ThrowingObject obj;
CHECK_ARRAY_CLOSE (data, obj, 3, 0.01f);
CHECK_ARRAY_CLOSE(data, obj, 3, 0.01f);
}
CHECK(strstr(reporter.lastFailedMessage, "data"));
@ -253,7 +253,7 @@ TEST(CheckArray2DCloseFailureBecauseOfExceptionContainsCorrectDetails)
ScopedCurrentTest scopedResults(testResults, &testDetails);
const float data[2][2] = { {0, 1}, {2, 3} };
CHECK_ARRAY2D_CLOSE (data, ThrowingObject2D(), 2, 2, 0.01f); line = __LINE__;
CHECK_ARRAY2D_CLOSE(data, ThrowingObject2D(), 2, 2, 0.01f); line = __LINE__;
}
CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest);
@ -272,7 +272,7 @@ TEST(CheckArray2DCloseFailsOnException)
const float data[2][2] = { {0, 1}, {2, 3} };
ThrowingObject2D obj;
CHECK_ARRAY2D_CLOSE (data, obj, 2, 2, 0.01f);
CHECK_ARRAY2D_CLOSE(data, obj, 2, 2, 0.01f);
failure = (testResults.GetFailureCount() > 0);
}
@ -289,7 +289,7 @@ TEST(CheckArray2DCloseFailureOnExceptionIncludesCheckContents)
const float data[2][2] = { {0, 1}, {2, 3} };
ThrowingObject2D obj;
CHECK_ARRAY2D_CLOSE (data, obj, 2, 2, 0.01f);
CHECK_ARRAY2D_CLOSE(data, obj, 2, 2, 0.01f);
}
CHECK(strstr(reporter.lastFailedMessage, "data"));

View file

@ -488,10 +488,6 @@
RelativePath=".\DeferredTestResult.h"
>
</File>
<File
RelativePath=".\DllMacros.h"
>
</File>
<File
RelativePath=".\ExceptionMacros.h"
>
@ -500,6 +496,10 @@
RelativePath=".\ExecuteTest.h"
>
</File>
<File
RelativePath=".\HelperMacros.h"
>
</File>
<File
RelativePath=".\MemoryOutStream.cpp"
>