change MemEquals pointers to "const void *ptr"

This commit is contained in:
2024-01-12 17:07:16 +01:00
parent 1da9d3e65e
commit 4497561ccf
2 changed files with 11 additions and 10 deletions

View File

@@ -224,20 +224,21 @@ void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
} }
void CuAssertMemEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, void CuAssertMemEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
const char* expected, const char* actual, const int len) const void *expected, const void *actual, const int len)
{ {
size_t diffc = 0; size_t diffc = 0;
const uchar *exp = expected, *act = actual;
/* below, len*2*2 is to display twice len hex strings, 128 is for extra chars. /* below, len*2*2 is to display twice len hex strings, 128 is for extra chars.
* This is rather conservative. * This is rather conservative.
*/ */
char buf[128 + len * 2 * 2]; char buf[128 + len * 2 * 2];
if (! (expected || actual)) /* both NULL */ if (! (exp || act)) /* both NULL */
return; return;
if (! (expected && actual)) { /* one is null */ if (! (exp && act)) { /* one is null */
sprintf(buf, "%s pointer is null", expected ? "actual": "expected"); sprintf(buf, "<%s> pointer is null", exp ? "actual": "expected");
} else { } else {
if (!(diffc = CuMemCmp(expected, actual, len))) if (!(diffc = CuMemCmp(exp, act, len)))
return; return;
} }
if (diffc--) { /* compare was done and wrong */ if (diffc--) { /* compare was done and wrong */
@@ -246,13 +247,13 @@ void CuAssertMemEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
/* we will build the "common" mem string /* we will build the "common" mem string
*/ */
for (i = 0; i < diffc; ++i) for (i = 0; i < diffc; ++i)
sprintf(common + i * 2, "%02X", *(expected + i)); sprintf(common + i * 2, "%02X", *(exp + i));
/* and final message /* and final message
*/ */
sprintf(buf, sprintf(buf,
"expected <0x%s[%02X]...> but was <0x%s[%02X]...> (differ at char %lu)\n", "expected <0x%s[%02X]...> but was <0x%s[%02X]...> (differ at char %lu)\n",
common, *(expected + i), common, *(exp + i),
common, *(actual + i), common, *(act + i),
diffc); diffc);
} }
CuFail_Line(tc, file, line, message, buf); CuFail_Line(tc, file, line, message, buf);

View File

@@ -73,9 +73,9 @@ void CuAssertStrEquals_LineMsg(CuTest* tc,
const char* expected, const char* actual); const char* expected, const char* actual);
void CuAssertMemEquals_LineMsg(CuTest* tc, void CuAssertMemEquals_LineMsg(CuTest* tc,
const char *file, int line, const char *message, const char *file, int line, const char *message,
const char *expected, const char *actual, const int len); const void *expected, const void *actual, const int len);
void CuAssertMem_LineMsg(CuTest* tc, const char* file, int line, const char* message, void CuAssertMem_LineMsg(CuTest* tc, const char* file, int line, const char* message,
const char* expected, const char* actual, const int len); const void *expected, const void *actual, const int len);
void CuAssertIntEquals_LineMsg(CuTest* tc, void CuAssertIntEquals_LineMsg(CuTest* tc,
const char* file, int line, const char* message, const char* file, int line, const char* message,
int expected, int actual); int expected, int actual);