mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-29 04:35:29 +03:00
Merge c8522b0d99 into 9218ffc456
This commit is contained in:
commit
e667bb2c95
12 changed files with 1351 additions and 50 deletions
|
|
@ -34,6 +34,12 @@
|
|||
#error UnitTest++ redefines CHECK_ARRAY2D_CLOSE
|
||||
#endif
|
||||
|
||||
#ifdef IS_NOT_REQUIRED_CHECK
|
||||
#error UnitTest++ redefines IS_NOT_REQUIRED_CHECK
|
||||
#endif
|
||||
|
||||
#define IS_NOT_REQUIRED_CHECK false
|
||||
|
||||
#define CHECK(value) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
|
|
@ -59,7 +65,7 @@
|
|||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), IS_NOT_REQUIRED_CHECK); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
|
|
@ -79,7 +85,7 @@
|
|||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), IS_NOT_REQUIRED_CHECK); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
|
|
@ -99,7 +105,7 @@
|
|||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), IS_NOT_REQUIRED_CHECK); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
|
|
@ -119,7 +125,7 @@
|
|||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), IS_NOT_REQUIRED_CHECK); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
|
|
@ -139,7 +145,7 @@
|
|||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), IS_NOT_REQUIRED_CHECK); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace UnitTest {
|
|||
namespace {
|
||||
|
||||
void CheckStringsEqual(TestResults& results, char const* expected, char const* actual,
|
||||
TestDetails const& details)
|
||||
TestDetails const& details, bool const required)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
|
|
@ -16,6 +16,11 @@ void CheckStringsEqual(TestResults& results, char const* expected, char const* a
|
|||
stream << "Expected " << (expected ? expected : "<NULLPTR>") << " but was " << (actual ? actual : "<NULLPTR>");
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
|
||||
if(required)
|
||||
{
|
||||
UT_THROW(RequiredCheckFailedException());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -23,27 +28,27 @@ void CheckStringsEqual(TestResults& results, char const* expected, char const* a
|
|||
|
||||
|
||||
void CheckEqual(TestResults& results, char const* expected, char const* actual,
|
||||
TestDetails const& details)
|
||||
TestDetails const& details, bool const required)
|
||||
{
|
||||
CheckStringsEqual(results, expected, actual, details);
|
||||
CheckStringsEqual(results, expected, actual, details, required);
|
||||
}
|
||||
|
||||
void CheckEqual(TestResults& results, char* expected, char* actual,
|
||||
TestDetails const& details)
|
||||
TestDetails const& details, bool const required)
|
||||
{
|
||||
CheckStringsEqual(results, expected, actual, details);
|
||||
CheckStringsEqual(results, expected, actual, details, required);
|
||||
}
|
||||
|
||||
void CheckEqual(TestResults& results, char* expected, char const* actual,
|
||||
TestDetails const& details)
|
||||
TestDetails const& details, bool const required)
|
||||
{
|
||||
CheckStringsEqual(results, expected, actual, details);
|
||||
CheckStringsEqual(results, expected, actual, details, required);
|
||||
}
|
||||
|
||||
void CheckEqual(TestResults& results, char const* expected, char* actual,
|
||||
TestDetails const& details)
|
||||
TestDetails const& details, bool const required)
|
||||
{
|
||||
CheckStringsEqual(results, expected, actual, details);
|
||||
CheckStringsEqual(results, expected, actual, details, required);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@
|
|||
#define UNITTEST_CHECKS_H
|
||||
|
||||
#include "Config.h"
|
||||
#include "ExceptionMacros.h"
|
||||
#include "TestResults.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include "RequiredCheckFailedException.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
|
|
@ -16,7 +18,7 @@ bool Check(Value const value)
|
|||
|
||||
|
||||
template< typename Expected, typename Actual >
|
||||
void CheckEqual(TestResults& results, Expected const& expected, Actual const& actual, TestDetails const& details)
|
||||
void CheckEqual(TestResults& results, Expected const& expected, Actual const& actual, TestDetails const& details, bool const required)
|
||||
{
|
||||
if (!(expected == actual))
|
||||
{
|
||||
|
|
@ -24,16 +26,21 @@ void CheckEqual(TestResults& results, Expected const& expected, Actual const& ac
|
|||
stream << "Expected " << expected << " but was " << actual;
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
|
||||
if(required)
|
||||
{
|
||||
UT_THROW(RequiredCheckFailedException());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char const* actual, TestDetails const& details);
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char const* actual, TestDetails const& details, bool const required);
|
||||
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char* actual, TestDetails const& details);
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char* actual, TestDetails const& details, bool const required);
|
||||
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char const* actual, TestDetails const& details);
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char const* actual, TestDetails const& details, bool const required);
|
||||
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char* actual, TestDetails const& details);
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char* actual, TestDetails const& details, bool const required);
|
||||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
bool AreClose(Expected const& expected, Actual const& actual, Tolerance const& tolerance)
|
||||
|
|
@ -43,7 +50,7 @@ bool AreClose(Expected const& expected, Actual const& actual, Tolerance const& t
|
|||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
void CheckClose(TestResults& results, Expected const& expected, Actual const& actual, Tolerance const& tolerance,
|
||||
TestDetails const& details)
|
||||
TestDetails const& details, bool const required)
|
||||
{
|
||||
if (!AreClose(expected, actual, tolerance))
|
||||
{
|
||||
|
|
@ -51,13 +58,18 @@ void CheckClose(TestResults& results, Expected const& expected, Actual const& ac
|
|||
stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
|
||||
if(required)
|
||||
{
|
||||
UT_THROW(RequiredCheckFailedException());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template< typename Expected, typename Actual >
|
||||
void CheckArrayEqual(TestResults& results, Expected const& expected, Actual const& actual,
|
||||
int const count, TestDetails const& details)
|
||||
int const count, TestDetails const& details, bool const required)
|
||||
{
|
||||
bool equal = true;
|
||||
for (int i = 0; i < count; ++i)
|
||||
|
|
@ -80,6 +92,11 @@ void CheckArrayEqual(TestResults& results, Expected const& expected, Actual cons
|
|||
stream << "]";
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
|
||||
if(required)
|
||||
{
|
||||
UT_THROW(RequiredCheckFailedException());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +111,8 @@ bool ArrayAreClose(Expected const& expected, Actual const& actual, int const cou
|
|||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
void CheckArrayClose(TestResults& results, Expected const& expected, Actual const& actual,
|
||||
int const count, Tolerance const& tolerance, TestDetails const& details)
|
||||
int const count, Tolerance const& tolerance, TestDetails const& details,
|
||||
bool const required)
|
||||
{
|
||||
bool equal = ArrayAreClose(expected, actual, count, tolerance);
|
||||
|
||||
|
|
@ -112,12 +130,18 @@ void CheckArrayClose(TestResults& results, Expected const& expected, Actual cons
|
|||
stream << "]";
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
|
||||
if(required)
|
||||
{
|
||||
UT_THROW(RequiredCheckFailedException());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
void CheckArray2DClose(TestResults& results, Expected const& expected, Actual const& actual,
|
||||
int const rows, int const columns, Tolerance const& tolerance, TestDetails const& details)
|
||||
int const rows, int const columns, Tolerance const& tolerance, TestDetails const& details,
|
||||
bool const required)
|
||||
{
|
||||
bool equal = true;
|
||||
for (int i = 0; i < rows; ++i)
|
||||
|
|
@ -150,6 +174,11 @@ void CheckArray2DClose(TestResults& results, Expected const& expected, Actual co
|
|||
stream << "]";
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
|
||||
if(required)
|
||||
{
|
||||
UT_THROW(RequiredCheckFailedException());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "TestResults.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include "AssertException.h"
|
||||
#include "RequiredCheckFailedException.h"
|
||||
#include "CurrentTest.h"
|
||||
|
||||
#ifdef UNITTEST_NO_EXCEPTIONS
|
||||
|
|
@ -39,6 +40,7 @@ void ExecuteTest(T& testObject, TestDetails const& details, bool isMockTest)
|
|||
})
|
||||
#endif
|
||||
UT_CATCH(AssertException, e, { (void)e; })
|
||||
UT_CATCH(RequiredCheckFailedException, e, { (void)e; })
|
||||
UT_CATCH(std::exception, e,
|
||||
{
|
||||
MemoryOutStream stream;
|
||||
|
|
|
|||
229
UnitTest++/RequireMacros.h
Normal file
229
UnitTest++/RequireMacros.h
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
#ifndef UNITTEST_REQUIREMACROS_H
|
||||
#define UNITTEST_REQUIREMACROS_H
|
||||
|
||||
#include "HelperMacros.h"
|
||||
#include "ExceptionMacros.h"
|
||||
#include "Checks.h"
|
||||
#include "CurrentTest.h"
|
||||
#include "AssertException.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include "TestDetails.h"
|
||||
#include "CurrentTest.h"
|
||||
#include "ReportAssertImpl.h"
|
||||
#include "RequiredCheckFailedException.h"
|
||||
|
||||
#ifdef REQUIRE_CHECK
|
||||
#error UnitTest++ redefines REQUIRE_CHECK
|
||||
#endif
|
||||
|
||||
#ifdef REQUIRE_EQUAL
|
||||
#error UnitTest++ redefines REQUIRE_EQUAL
|
||||
#endif
|
||||
|
||||
#ifdef REQUIRE_CLOSE
|
||||
#error UnitTest++ redefines REQUIRE_CLOSE
|
||||
#endif
|
||||
|
||||
#ifdef REQUIRE_ARRAY_EQUAL
|
||||
#error UnitTest++ redefines REQUIRE_ARRAY_EQUAL
|
||||
#endif
|
||||
|
||||
#ifdef REQUIRE_ARRAY_CLOSE
|
||||
#error UnitTest++ redefines REQUIRE_ARRAY_CLOSE
|
||||
#endif
|
||||
|
||||
#ifdef REQUIRE_ARRAY2D_CLOSE
|
||||
#error UnitTest++ redefines REQUIRE_ARRAY2D_CLOSE
|
||||
#endif
|
||||
|
||||
#ifdef IS_REQUIRED_CHECK
|
||||
#error UnitTest++ redefines IS_REQUIRED_CHECK
|
||||
#endif
|
||||
|
||||
#define IS_REQUIRED_CHECK true
|
||||
|
||||
#define REQUIRE_CHECK(value) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
if (!UnitTest::Check(value)) \
|
||||
{ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
} \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckFailedException, e, \
|
||||
{ \
|
||||
UT_THROW(e); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
message << "Unhandled exception (" << e.what() << ") in REQUIRE_CHECK(" #value ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
message.GetText()); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UT_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in REQUIRE_CHECK(" #value ")"); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define REQUIRE_EQUAL(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), IS_REQUIRED_CHECK); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckFailedException, e, \
|
||||
{ \
|
||||
UT_THROW(e); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
message << "Unhandled exception (" << e.what() << ") in REQUIRE_EQUAL(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
message.GetText()); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UT_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in REQUIRE_EQUAL(" #expected ", " #actual ")"); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define REQUIRE_CLOSE(expected, actual, tolerance) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), IS_REQUIRED_CHECK); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckFailedException, e, \
|
||||
{ \
|
||||
UT_THROW(e); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
message << "Unhandled exception (" << e.what() << ") in REQUIRE_CLOSE(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
message.GetText()); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UT_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in REQUIRE_CLOSE(" #expected ", " #actual ")"); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define REQUIRE_ARRAY_EQUAL(expected, actual, count) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), IS_REQUIRED_CHECK); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckFailedException, e, \
|
||||
{ \
|
||||
UT_THROW(e); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
message << "Unhandled exception (" << e.what() << ") in REQUIRE_ARRAY_EQUAL(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
message.GetText()); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UT_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in REQUIRE_ARRAY_EQUAL(" #expected ", " #actual ")"); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define REQUIRE_ARRAY_CLOSE(expected, actual, count, tolerance) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), IS_REQUIRED_CHECK); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckFailedException, e, \
|
||||
{ \
|
||||
UT_THROW(e); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
message << "Unhandled exception (" << e.what() << ") in REQUIRE_ARRAY_CLOSE(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
message.GetText()); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UT_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in REQUIRE_ARRAY_CLOSE(" #expected ", " #actual ")"); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define REQUIRE_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), IS_REQUIRED_CHECK); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckFailedException, e, \
|
||||
{ \
|
||||
UT_THROW(e); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
message << "Unhandled exception (" << e.what() << ") in REQUIRE_ARRAY2D_CLOSE(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
message.GetText()); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UT_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in REQUIRE_ARRAY2D_CLOSE(" #expected ", " #actual ")"); \
|
||||
UT_THROW(UnitTest::RequiredCheckFailedException()); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
|
||||
// REQUIRE_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h)
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
#define REQUIRE_THROW(expression, ExpectedExceptionType) \
|
||||
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"); \
|
||||
UT_THROW(RequiredCheckFailed); \
|
||||
} \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
|
||||
#define REQUIRE_ASSERT(expression) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UnitTest::Detail::ExpectAssert(true); \
|
||||
REQUIRE_THROW(expression, UnitTest::AssertException); \
|
||||
UnitTest::Detail::ExpectAssert(false); \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
#endif
|
||||
#endif
|
||||
17
UnitTest++/RequiredCheckFailedException.cpp
Normal file
17
UnitTest++/RequiredCheckFailedException.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include "RequiredCheckFailedException.h"
|
||||
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
RequiredCheckFailedException::RequiredCheckFailedException()
|
||||
{
|
||||
}
|
||||
|
||||
RequiredCheckFailedException::~RequiredCheckFailedException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
23
UnitTest++/RequiredCheckFailedException.h
Normal file
23
UnitTest++/RequiredCheckFailedException.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef UNITTEST_REQUIREDCHECKFAILEDEXCEPTION_H
|
||||
#define UNITTEST_REQUIREDCHECKFAILEDEXCEPTION_H
|
||||
|
||||
#include "Config.h"
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
|
||||
#include "HelperMacros.h"
|
||||
#include <exception>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class UNITTEST_LINKAGE RequiredCheckFailedException : public std::exception
|
||||
{
|
||||
public:
|
||||
RequiredCheckFailedException();
|
||||
virtual ~RequiredCheckFailedException() throw();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -89,6 +89,10 @@
|
|||
{ \
|
||||
(void)e; \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckFailedException, e, \
|
||||
{ \
|
||||
(void)e; \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream stream; \
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "Config.h"
|
||||
#include "TestMacros.h"
|
||||
#include "CheckMacros.h"
|
||||
#include "RequireMacros.h"
|
||||
#include "TestRunner.h"
|
||||
#include "TimeConstraint.h"
|
||||
#include "ReportAssert.h"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using namespace UnitTest;
|
|||
|
||||
namespace {
|
||||
|
||||
static bool const isNotRequired = false;
|
||||
|
||||
TEST(CheckEqualWithUnsignedLong)
|
||||
{
|
||||
|
|
@ -21,7 +22,7 @@ TEST(CheckEqualsWithStringsFailsOnDifferentStrings)
|
|||
char txt1[] = "Hello";
|
||||
char txt2[] = "Hallo";
|
||||
TestResults results;
|
||||
CheckEqual(results, txt1, txt2, TestDetails("", "", "", 0));
|
||||
CheckEqual(results, txt1, txt2, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(1, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ TEST(CheckEqualsWithStringsWorksOnContentsNonConstNonConst)
|
|||
char const* const p1 = txt1;
|
||||
char const* const p2 = txt2;
|
||||
TestResults results;
|
||||
CheckEqual(results, p1, p2, TestDetails("", "", "", 0));
|
||||
CheckEqual(results, p1, p2, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ TEST(CheckEqualsWithStringsWorksOnContentsConstConst)
|
|||
char* const p1 = txt1;
|
||||
char* const p2 = txt2;
|
||||
TestResults results;
|
||||
CheckEqual(results, p1, p2, TestDetails("", "", "", 0));
|
||||
CheckEqual(results, p1, p2, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +52,7 @@ TEST(CheckEqualsWithStringsWorksOnContentsNonConstConst)
|
|||
char* const p1 = txt1;
|
||||
char const* const p2 = txt2;
|
||||
TestResults results;
|
||||
CheckEqual(results, p1, p2, TestDetails("", "", "", 0));
|
||||
CheckEqual(results, p1, p2, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ TEST(CheckEqualsWithStringsWorksOnContentsConstNonConst)
|
|||
char const* const p1 = txt1;
|
||||
char* const p2 = txt2;
|
||||
TestResults results;
|
||||
CheckEqual(results, p1, p2, TestDetails("", "", "", 0));
|
||||
CheckEqual(results, p1, p2, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +69,7 @@ TEST(CheckEqualsWithStringsWorksOnContentsWithALiteral)
|
|||
{
|
||||
char const* const p1 = txt1;
|
||||
TestResults results;
|
||||
CheckEqual(results, "Hello", p1, TestDetails("", "", "", 0));
|
||||
CheckEqual(results, "Hello", p1, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +78,7 @@ TEST(CheckEqualsWithStringsWorksOnNullExpected)
|
|||
char const* const expected = "hi";
|
||||
char const* const actual = NULL;
|
||||
TestResults results;
|
||||
CheckEqual(results, expected, actual, TestDetails("", "", "", 0));
|
||||
CheckEqual(results, expected, actual, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL (1, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +87,7 @@ TEST(CheckEqualsWithStringsWorksOnNullActual)
|
|||
char const* const expected = NULL;
|
||||
char const* const actual = "hi";
|
||||
TestResults results;
|
||||
CheckEqual(results, expected, actual, TestDetails("", "", "", 0));
|
||||
CheckEqual(results, expected, actual, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL (1, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +96,7 @@ TEST(CheckEqualsWithStringsWorksOnNullExpectedAndActual)
|
|||
char const* const expected = NULL;
|
||||
char const* const actual = NULL;
|
||||
TestResults results;
|
||||
CheckEqual(results, expected, actual, TestDetails("", "", "", 0));
|
||||
CheckEqual(results, expected, actual, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL (0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +105,7 @@ TEST(CheckEqualFailureIncludesCheckExpectedAndActual)
|
|||
RecordingReporter reporter;
|
||||
TestResults results(&reporter);
|
||||
const int something = 2;
|
||||
CheckEqual(results, 1, something, TestDetails("", "", "", 0));
|
||||
CheckEqual(results, 1, something, TestDetails("", "", "", 0), isNotRequired);
|
||||
|
||||
using namespace std;
|
||||
CHECK(strstr(reporter.lastFailedMessage, "xpected 1"));
|
||||
|
|
@ -117,7 +118,7 @@ TEST(CheckEqualFailureIncludesDetails)
|
|||
TestResults results(&reporter);
|
||||
TestDetails const details("mytest", "mysuite", "file.h", 101);
|
||||
|
||||
CheckEqual(results, 1, 2, details);
|
||||
CheckEqual(results, 1, 2, details, isNotRequired);
|
||||
|
||||
CHECK_EQUAL("mytest", reporter.lastFailedTest);
|
||||
CHECK_EQUAL("mysuite", reporter.lastFailedSuite);
|
||||
|
|
@ -128,21 +129,21 @@ TEST(CheckEqualFailureIncludesDetails)
|
|||
TEST(CheckCloseTrue)
|
||||
{
|
||||
TestResults results;
|
||||
CheckClose(results, 3.001f, 3.0f, 0.1f, TestDetails("", "", "", 0));
|
||||
CheckClose(results, 3.001f, 3.0f, 0.1f, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
TEST(CheckCloseFalse)
|
||||
{
|
||||
TestResults results;
|
||||
CheckClose(results, 3.12f, 3.0f, 0.1f, TestDetails("", "", "", 0));
|
||||
CheckClose(results, 3.12f, 3.0f, 0.1f, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(1, results.GetFailureCount());
|
||||
}
|
||||
|
||||
TEST(CheckCloseWithZeroEpsilonWorksForSameNumber)
|
||||
{
|
||||
TestResults results;
|
||||
CheckClose(results, 0.1f, 0.1f, 0, TestDetails("", "", "", 0));
|
||||
CheckClose(results, 0.1f, 0.1f, 0, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +154,7 @@ TEST(CheckCloseWithNaNFails)
|
|||
UNIITEST_NS_QUAL_STD(memcpy)(&nan, &bitpattern, sizeof(bitpattern));
|
||||
|
||||
TestResults results;
|
||||
CheckClose(results, 3.0f, nan, 0.1f, TestDetails("", "", "", 0));
|
||||
CheckClose(results, 3.0f, nan, 0.1f, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(1, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +165,7 @@ TEST(CheckCloseWithNaNAgainstItselfFails)
|
|||
UNIITEST_NS_QUAL_STD(memcpy)(&nan, &bitpattern, sizeof(bitpattern));
|
||||
|
||||
TestResults results;
|
||||
CheckClose(results, nan, nan, 0.1f, TestDetails("", "", "", 0));
|
||||
CheckClose(results, nan, nan, 0.1f, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(1, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +175,7 @@ TEST(CheckCloseFailureIncludesCheckExpectedAndActual)
|
|||
TestResults results(&reporter);
|
||||
const float expected = 0.9f;
|
||||
const float actual = 1.1f;
|
||||
CheckClose(results, expected, actual, 0.01f, TestDetails("", "", "", 0));
|
||||
CheckClose(results, expected, actual, 0.01f, TestDetails("", "", "", 0), isNotRequired);
|
||||
|
||||
using namespace std;
|
||||
CHECK(strstr(reporter.lastFailedMessage, "xpected 0.9"));
|
||||
|
|
@ -185,7 +186,7 @@ TEST(CheckCloseFailureIncludesTolerance)
|
|||
{
|
||||
RecordingReporter reporter;
|
||||
TestResults results(&reporter);
|
||||
CheckClose(results, 2, 3, 0.01f, TestDetails("", "", "", 0));
|
||||
CheckClose(results, 2, 3, 0.01f, TestDetails("", "", "", 0), isNotRequired);
|
||||
|
||||
using namespace std;
|
||||
CHECK(strstr(reporter.lastFailedMessage, "0.01"));
|
||||
|
|
@ -197,7 +198,7 @@ TEST(CheckCloseFailureIncludesDetails)
|
|||
TestResults results(&reporter);
|
||||
TestDetails const details("mytest", "mysuite", "header.h", 10);
|
||||
|
||||
CheckClose(results, 2, 3, 0.01f, details);
|
||||
CheckClose(results, 2, 3, 0.01f, details, isNotRequired);
|
||||
|
||||
CHECK_EQUAL("mytest", reporter.lastFailedTest);
|
||||
CHECK_EQUAL("mysuite", reporter.lastFailedSuite);
|
||||
|
|
@ -211,7 +212,7 @@ TEST(CheckArrayEqualTrue)
|
|||
TestResults results;
|
||||
|
||||
int const array[3] = { 1, 2, 3 };
|
||||
CheckArrayEqual(results, array, array, 3, TestDetails("", "", "", 0));
|
||||
CheckArrayEqual(results, array, array, 3, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -221,7 +222,7 @@ TEST(CheckArrayEqualFalse)
|
|||
|
||||
int const array1[3] = { 1, 2, 3 };
|
||||
int const array2[3] = { 1, 2, 2 };
|
||||
CheckArrayEqual(results, array1, array2, 3, TestDetails("", "", "", 0));
|
||||
CheckArrayEqual(results, array1, array2, 3, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(1, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +232,7 @@ TEST(CheckArrayCloseTrue)
|
|||
|
||||
float const array1[3] = { 1.0f, 1.5f, 2.0f };
|
||||
float const array2[3] = { 1.01f, 1.51f, 2.01f };
|
||||
CheckArrayClose(results, array1, array2, 3, 0.02f, TestDetails("", "", "", 0));
|
||||
CheckArrayClose(results, array1, array2, 3, 0.02f, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -241,7 +242,7 @@ TEST(CheckArrayCloseFalse)
|
|||
|
||||
float const array1[3] = { 1.0f, 1.5f, 2.0f };
|
||||
float const array2[3] = { 1.01f, 1.51f, 2.01f };
|
||||
CheckArrayClose(results, array1, array2, 3, 0.001f, TestDetails("", "", "", 0));
|
||||
CheckArrayClose(results, array1, array2, 3, 0.001f, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(1, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -253,7 +254,7 @@ TEST(CheckArrayCloseFailureIncludesDetails)
|
|||
|
||||
float const array1[3] = { 1.0f, 1.5f, 2.0f };
|
||||
float const array2[3] = { 1.01f, 1.51f, 2.01f };
|
||||
CheckArrayClose(results, array1, array2, 3, 0.001f, details);
|
||||
CheckArrayClose(results, array1, array2, 3, 0.001f, details, isNotRequired);
|
||||
|
||||
CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest);
|
||||
CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite);
|
||||
|
|
@ -272,7 +273,7 @@ TEST(CheckArray2DCloseTrue)
|
|||
float const array2[3][3] = { { 1.01f, 1.51f, 2.01f },
|
||||
{ 2.01f, 2.51f, 3.01f },
|
||||
{ 3.01f, 3.51f, 4.01f } };
|
||||
CheckArray2DClose(results, array1, array2, 3, 3, 0.02f, TestDetails("", "", "", 0));
|
||||
CheckArray2DClose(results, array1, array2, 3, 3, 0.02f, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(0, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +287,7 @@ TEST(CheckArray2DCloseFalse)
|
|||
float const array2[3][3] = { { 1.01f, 1.51f, 2.01f },
|
||||
{ 2.01f, 2.51f, 3.01f },
|
||||
{ 3.01f, 3.51f, 4.01f } };
|
||||
CheckArray2DClose(results, array1, array2, 3, 3, 0.001f, TestDetails("", "", "", 0));
|
||||
CheckArray2DClose(results, array1, array2, 3, 3, 0.001f, TestDetails("", "", "", 0), isNotRequired);
|
||||
CHECK_EQUAL(1, results.GetFailureCount());
|
||||
}
|
||||
|
||||
|
|
@ -307,7 +308,7 @@ TEST(CheckArray2DCloseFailureIncludesDetails)
|
|||
float const array2[3][3] = { { 1.01f, 1.51f, 2.01f },
|
||||
{ 2.01f, 2.51f, 3.01f },
|
||||
{ 3.01f, 3.51f, 4.01f } };
|
||||
CheckArray2DClose(results, array1, array2, 3, 3, 0.001f, details);
|
||||
CheckArray2DClose(results, array1, array2, 3, 3, 0.001f, details, isNotRequired);
|
||||
|
||||
CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest);
|
||||
CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite);
|
||||
|
|
|
|||
967
tests/TestRequireMacros.cpp
Normal file
967
tests/TestRequireMacros.cpp
Normal file
|
|
@ -0,0 +1,967 @@
|
|||
#include "UnitTest++/UnitTestPP.h"
|
||||
#include "UnitTest++/CurrentTest.h"
|
||||
#include "RecordingReporter.h"
|
||||
#include "ScopedCurrentTest.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(RequireCheckSucceedsOnTrue)
|
||||
{
|
||||
bool failure = true;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_CHECK(true);
|
||||
}
|
||||
catch(const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(!failure);
|
||||
CHECK(!exception);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckFailsOnFalse)
|
||||
{
|
||||
bool failure = false;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_CHECK(false);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
bool ThrowsOnCall()
|
||||
{
|
||||
throw std::exception();
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST(RequireCheckStopsTestOnException)
|
||||
{
|
||||
bool failure = false;
|
||||
bool continued = false;
|
||||
bool exception = false;
|
||||
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_CHECK(ThrowsOnCall());
|
||||
continued = true;
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(!continued);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
TEST(FailureReportsCorrectTestName)
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_CHECK(false);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_EQUAL(m_details.testName, reporter.lastFailedTest);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckFailureIncludesCheckContents)
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
const bool yaddayadda = false;
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_CHECK(yaddayadda);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(strstr(reporter.lastFailedMessage, "yaddayadda"));
|
||||
}
|
||||
|
||||
TEST(RequiredCheckEqualSucceedsOnEqual)
|
||||
{
|
||||
bool failure = true;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_EQUAL(1,1);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(!failure);
|
||||
CHECK(!exception);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckEqualFailsOnNotEqual)
|
||||
{
|
||||
bool failure = false;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_EQUAL(1, 2);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
TEST(RequireEqualStopsTestOnException)
|
||||
{
|
||||
bool failure = false;
|
||||
bool continued = false;
|
||||
bool exception = false;
|
||||
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_EQUAL(false, ThrowsOnCall());
|
||||
continued = true;
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(!continued);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckEqualFailureContainsCorrectDetails)
|
||||
{
|
||||
int line = 0;
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1);
|
||||
ScopedCurrentTest scopedResults(testResults, &testDetails);
|
||||
|
||||
try
|
||||
{
|
||||
line = __LINE__; REQUIRE_EQUAL(1, 123);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_EQUAL("testName", reporter.lastFailedTest);
|
||||
CHECK_EQUAL("suiteName", reporter.lastFailedSuite);
|
||||
CHECK_EQUAL("filename", reporter.lastFailedFile);
|
||||
CHECK_EQUAL(line, reporter.lastFailedLine);
|
||||
}
|
||||
|
||||
int g_sideEffect = 0;
|
||||
int FunctionWithSideEffects()
|
||||
{
|
||||
++g_sideEffect;
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenPassing)
|
||||
{
|
||||
g_sideEffect = 0;
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_EQUAL(1, FunctionWithSideEffects());
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenFailing)
|
||||
{
|
||||
g_sideEffect = 0;
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_EQUAL(2, FunctionWithSideEffects());
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
|
||||
TEST(RequiredCheckCloseSucceedsOnEqual)
|
||||
{
|
||||
bool failure = true;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_CLOSE(1.0f, 1.001f, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(!failure);
|
||||
CHECK(!exception);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckCloseFailsOnNotEqual)
|
||||
{
|
||||
bool failure = false;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_CLOSE (1.0f, 1.1f, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
float ThrowsOnCallReturnsFloat()
|
||||
{
|
||||
throw std::exception();
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
TEST(RequireCloseStopsTestOnException)
|
||||
{
|
||||
bool failure = false;
|
||||
bool continued = false;
|
||||
bool exception = false;
|
||||
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_CLOSE(1.0f, ThrowsOnCallReturnsFloat(), 0.1f);
|
||||
continued = true;
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(!continued);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckCloseFailureContainsCorrectDetails)
|
||||
{
|
||||
int line = 0;
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
UnitTest::TestDetails testDetails("test", "suite", "filename", -1);
|
||||
ScopedCurrentTest scopedResults(testResults, &testDetails);
|
||||
|
||||
try
|
||||
{
|
||||
line = __LINE__; REQUIRE_CLOSE(1.0f, 1.1f, 0.01f);
|
||||
CHECK(false);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_EQUAL("test", reporter.lastFailedTest);
|
||||
CHECK_EQUAL("suite", reporter.lastFailedSuite);
|
||||
CHECK_EQUAL("filename", reporter.lastFailedFile);
|
||||
CHECK_EQUAL(line, reporter.lastFailedLine);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenPassing)
|
||||
{
|
||||
g_sideEffect = 0;
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_CLOSE (1, FunctionWithSideEffects(), 0.1f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenFailing)
|
||||
{
|
||||
g_sideEffect = 0;
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_CLOSE(2, FunctionWithSideEffects(), 0.1f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayCloseSucceedsOnEqual)
|
||||
{
|
||||
bool failure = true;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
const float data[4] = { 0, 1, 2, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY_CLOSE (data, data, 4, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(!failure);
|
||||
CHECK(!exception);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayCloseFailsOnNotEqual)
|
||||
{
|
||||
bool failure = false;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
int const data1[4] = { 0, 1, 2, 3 };
|
||||
int const data2[4] = { 0, 1, 3, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY_CLOSE (data1, data2, 4, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
// more convenient to use std::array<> here... not every compiler has it.
|
||||
template<typename Type, std::size_t Count>
|
||||
struct array_wrapper
|
||||
{
|
||||
Type operator[](std::size_t index) const
|
||||
{
|
||||
return values_[index];
|
||||
}
|
||||
|
||||
Type values_[Count];
|
||||
};
|
||||
|
||||
array_wrapper<int, 4> ThrowsOnCallReturnsArray()
|
||||
{
|
||||
throw std::exception();
|
||||
return array_wrapper<int, 4>();
|
||||
}
|
||||
|
||||
TEST(RequireCheckArrayStopsTestOnException)
|
||||
{
|
||||
bool failure = false;
|
||||
bool continued = false;
|
||||
bool exception = false;
|
||||
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
int const data1[4] = { 0, 1, 2, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY_CLOSE (data1, ThrowsOnCallReturnsArray(), 4, 0.01f);
|
||||
continued = true;
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(!continued);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayCloseFailureIncludesCheckExpectedAndActual)
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
int const data1[4] = { 0, 1, 2, 3 };
|
||||
int const data2[4] = { 0, 1, 3, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY_CLOSE(data1, data2, 4, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]"));
|
||||
CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]"));
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayCloseFailureContainsCorrectDetails)
|
||||
{
|
||||
int line = 0;
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
UnitTest::TestDetails testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1);
|
||||
ScopedCurrentTest scopedResults(testResults, &testDetails);
|
||||
|
||||
int const data1[4] = { 0, 1, 2, 3 };
|
||||
int const data2[4] = { 0, 1, 3, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
line = __LINE__; REQUIRE_ARRAY_CLOSE (data1, data2, 4, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest);
|
||||
CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite);
|
||||
CHECK_EQUAL("filename", reporter.lastFailedFile);
|
||||
CHECK_EQUAL(line, reporter.lastFailedLine);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayCloseFailureIncludesTolerance)
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
float const data1[4] = { 0, 1, 2, 3 };
|
||||
float const data2[4] = { 0, 1, 3, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY_CLOSE (data1, data2, 4, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(strstr(reporter.lastFailedMessage, "0.01"));
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayEqualSuceedsOnEqual)
|
||||
{
|
||||
bool failure = true;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
const float data[4] = { 0, 1, 2, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY_EQUAL (data, data, 4);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(!failure);
|
||||
CHECK(!exception);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayEqualFailsOnNotEqual)
|
||||
{
|
||||
bool failure = false;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
int const data1[4] = { 0, 1, 2, 3 };
|
||||
int const data2[4] = { 0, 1, 3, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY_EQUAL (data1, data2, 4);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayEqualFailureIncludesCheckExpectedAndActual)
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
int const data1[4] = { 0, 1, 2, 3 };
|
||||
int const data2[4] = { 0, 1, 3, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY_EQUAL (data1, data2, 4);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]"));
|
||||
CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]"));
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayEqualFailureContainsCorrectInfo)
|
||||
{
|
||||
int line = 0;
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
int const data1[4] = { 0, 1, 2, 3 };
|
||||
int const data2[4] = { 0, 1, 3, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
line = __LINE__; REQUIRE_ARRAY_EQUAL (data1, data2, 4);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_EQUAL("RequiredCheckArrayEqualFailureContainsCorrectInfo", reporter.lastFailedTest);
|
||||
CHECK_EQUAL(__FILE__, reporter.lastFailedFile);
|
||||
CHECK_EQUAL(line, reporter.lastFailedLine);
|
||||
}
|
||||
|
||||
float const* FunctionWithSideEffects2()
|
||||
{
|
||||
++g_sideEffect;
|
||||
static float const data[] = {1,2,3,4};
|
||||
return data;
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing)
|
||||
{
|
||||
g_sideEffect = 0;
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
const float data[] = { 0, 1, 2, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenFailing)
|
||||
{
|
||||
g_sideEffect = 0;
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
const float data[] = { 0, 1, 3, 3 };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArray2DCloseSucceedsOnEqual)
|
||||
{
|
||||
bool failure = true;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
const float data[2][2] = { {0, 1}, {2, 3} };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY2D_CLOSE(data, data, 2, 2, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(!failure);
|
||||
CHECK(!exception);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArray2DCloseFailsOnNotEqual)
|
||||
{
|
||||
bool failure = false;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
int const data1[2][2] = { {0, 1}, {2, 3} };
|
||||
int const data2[2][2] = { {0, 1}, {3, 3} };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
array_wrapper<array_wrapper<int, 2>, 2> ThrowsOnCallMultidimensionalArray()
|
||||
{
|
||||
throw std::exception();
|
||||
return array_wrapper<array_wrapper<int, 2>, 2>();
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArray2DCloseStopsOnException)
|
||||
{
|
||||
bool failure = false;
|
||||
bool continued = false;
|
||||
bool exception = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
const float data[2][2] = { {0, 1}, {2, 3} };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY2D_CLOSE(data, ThrowsOnCallMultidimensionalArray(), 2, 2, 0.01f);
|
||||
continued = true;
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
CHECK(!continued);
|
||||
CHECK(exception);
|
||||
}
|
||||
|
||||
|
||||
TEST(RequiredCheckArray2DCloseFailureIncludesCheckExpectedAndActual)
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
int const data1[2][2] = { {0, 1}, {2, 3} };
|
||||
int const data2[2][2] = { {0, 1}, {3, 3} };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(strstr(reporter.lastFailedMessage, "xpected [ [ 0 1 ] [ 2 3 ] ]"));
|
||||
CHECK(strstr(reporter.lastFailedMessage, "was [ [ 0 1 ] [ 3 3 ] ]"));
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArray2DCloseFailureContainsCorrectDetails)
|
||||
{
|
||||
int line = 0;
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
UnitTest::TestDetails testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1);
|
||||
ScopedCurrentTest scopedResults(testResults, &testDetails);
|
||||
|
||||
int const data1[2][2] = { {0, 1}, {2, 3} };
|
||||
int const data2[2][2] = { {0, 1}, {3, 3} };
|
||||
|
||||
try
|
||||
{
|
||||
line = __LINE__; REQUIRE_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest);
|
||||
CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite);
|
||||
CHECK_EQUAL("filename", reporter.lastFailedFile);
|
||||
CHECK_EQUAL(line, reporter.lastFailedLine);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArray2DCloseFailureIncludesTolerance)
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
float const data1[2][2] = { {0, 1}, {2, 3} };
|
||||
float const data2[2][2] = { {0, 1}, {3, 3} };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(strstr(reporter.lastFailedMessage, "0.01"));
|
||||
}
|
||||
|
||||
float const* const* FunctionWithSideEffects3()
|
||||
{
|
||||
++g_sideEffect;
|
||||
static float const data1[] = {0,1};
|
||||
static float const data2[] = {2,3};
|
||||
static const float* const data[] = {data1, data2};
|
||||
return data;
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenPassing)
|
||||
{
|
||||
g_sideEffect = 0;
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
const float data[2][2] = { {0, 1}, {2, 3} };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenFailing)
|
||||
{
|
||||
g_sideEffect = 0;
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
const float data[2][2] = { {0, 1}, {3, 3} };
|
||||
|
||||
try
|
||||
{
|
||||
REQUIRE_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f);
|
||||
}
|
||||
catch (const UnitTest::RequiredCheckFailedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -7,6 +7,10 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
6093F5AA19C0F26600A43101 /* RequiredCheckFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 6093F5A919C0F26600A43101 /* RequiredCheckFailedException.h */; };
|
||||
6093F5AC19C0F27300A43101 /* RequireMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 6093F5AB19C0F27300A43101 /* RequireMacros.h */; };
|
||||
6093F5AE19C0F37C00A43101 /* RequiredCheckFailedException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6093F5AD19C0F37C00A43101 /* RequiredCheckFailedException.cpp */; };
|
||||
6093F5B019C0F8FE00A43101 /* TestRequireMacros.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6093F5AF19C0F8FE00A43101 /* TestRequireMacros.cpp */; };
|
||||
83D5FCED171F910E005B0069 /* AssertException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83D5FCB5171F910E005B0069 /* AssertException.cpp */; };
|
||||
83D5FCEE171F910E005B0069 /* AssertException.h in Headers */ = {isa = PBXBuildFile; fileRef = 83D5FCB6171F910E005B0069 /* AssertException.h */; };
|
||||
83D5FCEF171F910E005B0069 /* CheckMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 83D5FCB7171F910E005B0069 /* CheckMacros.h */; };
|
||||
|
|
@ -91,6 +95,10 @@
|
|||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
6093F5A919C0F26600A43101 /* RequiredCheckFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RequiredCheckFailedException.h; sourceTree = "<group>"; };
|
||||
6093F5AB19C0F27300A43101 /* RequireMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RequireMacros.h; sourceTree = "<group>"; };
|
||||
6093F5AD19C0F37C00A43101 /* RequiredCheckFailedException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RequiredCheckFailedException.cpp; sourceTree = "<group>"; };
|
||||
6093F5AF19C0F8FE00A43101 /* TestRequireMacros.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestRequireMacros.cpp; sourceTree = "<group>"; };
|
||||
8347D76F171F8D1C00FE3FC1 /* libUnitTest++.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libUnitTest++.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
83D5FCB5171F910E005B0069 /* AssertException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AssertException.cpp; sourceTree = "<group>"; };
|
||||
83D5FCB6171F910E005B0069 /* AssertException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AssertException.h; sourceTree = "<group>"; };
|
||||
|
|
@ -205,6 +213,9 @@
|
|||
83D5FCB4171F910E005B0069 /* UnitTest++ */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6093F5AD19C0F37C00A43101 /* RequiredCheckFailedException.cpp */,
|
||||
6093F5AB19C0F27300A43101 /* RequireMacros.h */,
|
||||
6093F5A919C0F26600A43101 /* RequiredCheckFailedException.h */,
|
||||
83D5FCB5171F910E005B0069 /* AssertException.cpp */,
|
||||
83D5FCB6171F910E005B0069 /* AssertException.h */,
|
||||
83D5FCB7171F910E005B0069 /* CheckMacros.h */,
|
||||
|
|
@ -270,6 +281,7 @@
|
|||
83D5FD2D171F9218005B0069 /* tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6093F5AF19C0F8FE00A43101 /* TestRequireMacros.cpp */,
|
||||
83D5FD2E171F9218005B0069 /* Main.cpp */,
|
||||
83D5FD2F171F9218005B0069 /* RecordingReporter.h */,
|
||||
83D5FD30171F9218005B0069 /* ScopedCurrentTest.h */,
|
||||
|
|
@ -310,6 +322,7 @@
|
|||
83D5FCF4171F910E005B0069 /* Config.h in Headers */,
|
||||
83D5FCF6171F910E005B0069 /* CurrentTest.h in Headers */,
|
||||
83D5FCF8171F910E005B0069 /* DeferredTestReporter.h in Headers */,
|
||||
6093F5AC19C0F27300A43101 /* RequireMacros.h in Headers */,
|
||||
83D5FCFA171F910E005B0069 /* DeferredTestResult.h in Headers */,
|
||||
83D5FCFB171F910E005B0069 /* ExceptionMacros.h in Headers */,
|
||||
83D5FCFC171F910E005B0069 /* ExecuteTest.h in Headers */,
|
||||
|
|
@ -328,6 +341,7 @@
|
|||
83D5FD13171F910E005B0069 /* TestResults.h in Headers */,
|
||||
83D5FD15171F910E005B0069 /* TestRunner.h in Headers */,
|
||||
83D5FD16171F910E005B0069 /* TestSuite.h in Headers */,
|
||||
6093F5AA19C0F26600A43101 /* RequiredCheckFailedException.h in Headers */,
|
||||
83D5FD18171F910E005B0069 /* TimeConstraint.h in Headers */,
|
||||
83D5FD19171F910E005B0069 /* TimeHelpers.h in Headers */,
|
||||
83D5FD1A171F910E005B0069 /* UnitTest++.h in Headers */,
|
||||
|
|
@ -413,6 +427,7 @@
|
|||
83D5FCF9171F910E005B0069 /* DeferredTestResult.cpp in Sources */,
|
||||
83D5FCFE171F910E005B0069 /* MemoryOutStream.cpp in Sources */,
|
||||
83D5FD00171F910E005B0069 /* SignalTranslator.cpp in Sources */,
|
||||
6093F5AE19C0F37C00A43101 /* RequiredCheckFailedException.cpp in Sources */,
|
||||
83D5FD02171F910E005B0069 /* TimeHelpers.cpp in Sources */,
|
||||
83D5FD04171F910E005B0069 /* ReportAssert.cpp in Sources */,
|
||||
83D5FD07171F910E005B0069 /* Test.cpp in Sources */,
|
||||
|
|
@ -447,6 +462,7 @@
|
|||
83D5FD52171F9218005B0069 /* TestTestRunner.cpp in Sources */,
|
||||
83D5FD53171F9218005B0069 /* TestTestSuite.cpp in Sources */,
|
||||
83D5FD54171F9218005B0069 /* TestTimeConstraint.cpp in Sources */,
|
||||
6093F5B019C0F8FE00A43101 /* TestRequireMacros.cpp in Sources */,
|
||||
83D5FD55171F9218005B0069 /* TestTimeConstraintMacro.cpp in Sources */,
|
||||
83D5FD56171F9218005B0069 /* TestUnitTestPP.cpp in Sources */,
|
||||
83D5FD57171F9218005B0069 /* TestXmlTestReporter.cpp in Sources */,
|
||||
|
|
@ -573,6 +589,7 @@
|
|||
83D5FD2C171F91B7005B0069 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue