Implement CuAssertPtrNotEquals

This commit is contained in:
Petr Penzin 2023-01-03 23:03:20 -08:00
parent dd1efa973d
commit 05b68f5a66
2 changed files with 14 additions and 0 deletions

View File

@ -236,6 +236,15 @@ void CuAssertPtrEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
CuFail_Line(tc, file, line, message, buf);
}
void CuAssertPtrNotEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
void* reject, void* actual)
{
char buf[STRING_MAX];
if (reject != actual) return;
sprintf(buf, "expected pointer different from <0x%p>", actual);
CuFail_Line(tc, file, line, message, buf);
}
/*-------------------------------------------------------------------------*
* CuSuite

View File

@ -71,6 +71,9 @@ void CuAssertDblEquals_LineMsg(CuTest* tc,
void CuAssertPtrEquals_LineMsg(CuTest* tc,
const char* file, int line, const char* message,
void* expected, void* actual);
void CuAssertPtrNotEquals_LineMsg(CuTest* tc,
const char* file, int line, const char* message,
void* reject, void* actual);
/* public assert functions */
@ -86,6 +89,8 @@ void CuAssertPtrEquals_LineMsg(CuTest* tc,
#define CuAssertDblEquals_Msg(tc,ms,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac),(dl))
#define CuAssertPtrEquals(tc,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
#define CuAssertPtrEquals_Msg(tc,ms,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
#define CuAssertPtrNotEquals(tc,rj,ac) CuAssertPtrNotEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(rj),(ac))
#define CuAssertPtrNotEquals_Msg(tc,ms,rj,ac) CuAssertPtrNotEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(rj),(ac))
#define CuAssertPtrNotNull(tc,p) CuAssert_Line((tc),__FILE__,__LINE__,"null pointer unexpected",((p) != NULL))
#define CuAssertPtrNotNullMsg(tc,msg,p) CuAssert_Line((tc),__FILE__,__LINE__,(msg),((p) != NULL))