diff --git a/include/CppUTest/UtestMacros.h b/include/CppUTest/UtestMacros.h index 743bf069e..a90c0e9bf 100644 --- a/include/CppUTest/UtestMacros.h +++ b/include/CppUTest/UtestMacros.h @@ -129,11 +129,20 @@ #define CHECK_EQUAL_TEXT(expected, actual, text)\ CHECK_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__) +namespace CppUTestPrivate +{ + template + 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); \ } \ diff --git a/tests/CppUTest/TestUTestMacro.cpp b/tests/CppUTest/TestUTestMacro.cpp index ecc07a619..b6ce1f8a2 100644 --- a/tests/CppUTest/TestUTestMacro.cpp +++ b/tests/CppUTest/TestUTestMacro.cpp @@ -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);