Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions include/CppUTest/UtestMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,20 @@
#define CHECK_EQUAL_TEXT(expected, actual, text)\
CHECK_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)

namespace CppUTestPrivate
{
template <typename T>
bool checkEqualSelfNotEqual(T a, T b)
{
return a != b;
}
}

#define CHECK_EQUAL_LOCATION(expected, actual, text, file, line)\
do { if ((expected) != (actual)) { \
if ((actual) != (actual)) \
if (::CppUTestPrivate::checkEqualSelfNotEqual((actual), (actual))) \
UtestShell::getCurrent()->print("WARNING:\n\tThe \"Actual Parameter\" parameter is evaluated multiple times resulting in different values.\n\tThus the value in the error message is probably incorrect.", file, line); \
if ((expected) != (expected)) \
if (::CppUTestPrivate::checkEqualSelfNotEqual((expected), (expected))) \
UtestShell::getCurrent()->print("WARNING:\n\tThe \"Expected Parameter\" parameter is evaluated multiple times resulting in different values.\n\tThus the value in the error message is probably incorrect.", file, line); \
UtestShell::getCurrent()->assertEquals(true, StringFrom(expected).asCharString(), StringFrom(actual).asCharString(), text, file, line); \
} \
Expand Down
7 changes: 7 additions & 0 deletions tests/CppUTest/TestUTestMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,13 @@ TEST(UnitTestMacros, failing_CHECK_EQUAL_withParamatersThatDontChangeWillNotGive
fixture.assertPrintContainsNot("WARNING");
}

TEST(UnitTestMacros, CHECK_EQUAL_compilesWithArrayOperand)
{
const char buf[] = "hello";
const char* actual = buf;
CHECK_EQUAL(buf, actual);
}

TEST(UnitTestMacros, CHECK_EQUALBehavesAsProperMacro)
{
if (false) CHECK_EQUAL(1, 2);
Expand Down