From a0cd2b9a3c68efb42855e2cf7666a525283773f8 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 19 Feb 2015 19:59:53 +0100 Subject: [PATCH] check: more comparison with `ck_assert_ptr_eq()` --- tests/Makefile.am | 11 ++++++----- tests/check-compat.h | 14 ++++++++++++++ tests/check_lldp.c | 6 +++--- tests/check_marshal.c | 11 +---------- tests/common.h | 1 + 5 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 tests/check-compat.h diff --git a/tests/Makefile.am b/tests/Makefile.am index 4d305186..1278f6c0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -9,26 +9,27 @@ AM_CFLAGS += @CHECK_CFLAGS@ LDADD = $(top_builddir)/src/daemon/liblldpd.la @CHECK_LIBS@ @LIBEVENT_LDFLAGS@ check_marshal_SOURCES = check_marshal.c \ - $(top_srcdir)/src/marshal.h + $(top_srcdir)/src/marshal.h \ + check-compat.h check_pattern_SOURCES = check_pattern.c \ $(top_srcdir)/src/daemon/lldpd.h check_lldp_SOURCES = check_lldp.c \ $(top_srcdir)/src/daemon/lldpd.h \ - common.h common.c + common.h common.c check-compat.h check_cdp_SOURCES = check_cdp.c \ $(top_srcdir)/src/daemon/lldpd.h \ - common.h common.c + common.h common.c check-compat.h check_sonmp_SOURCES = check_sonmp.c \ $(top_srcdir)/src/daemon/lldpd.h \ - common.h common.c + common.h common.c check-compat.h check_edp_SOURCES = check_edp.c \ $(top_srcdir)/src/daemon/lldpd.h \ - common.h common.c + common.h common.c check-compat.h check_fixedpoint_SOURCES = check_fixedpoint.c check_fixedpoint_LDADD = $(top_builddir)/src/lib/libfixedpoint.la $(LDADD) diff --git a/tests/check-compat.h b/tests/check-compat.h new file mode 100644 index 00000000..47abe6fd --- /dev/null +++ b/tests/check-compat.h @@ -0,0 +1,14 @@ +#ifndef _CHECK_COMPAT_H +#define _CHECK_COMPAT_H + +#if (CHECK_MAJOR_VERSION == 0 && (CHECK_MINOR_VERSION < 9 || (CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION < 10))) +# define ck_assert_ptr_eq(X,Y) do { \ + void* _ck_x = (X); \ + void* _ck_y = (Y); \ + ck_assert_msg(_ck_x == _ck_y, \ + "Assertion '"#X"=="#Y"' failed: "#X"==%p, "#Y"==%p", \ + _ck_x, _ck_y); \ + } while (0) +#endif + +#endif diff --git a/tests/check_lldp.c b/tests/check_lldp.c index 1b48372b..8b81a9fd 100644 --- a/tests/check_lldp.c +++ b/tests/check_lldp.c @@ -490,9 +490,9 @@ Link Layer Discovery Protocol ck_assert_int_eq(nport->p_id_len, ETHER_ADDR_LEN); fail_unless(memcmp(mac2, nport->p_id, ETHER_ADDR_LEN) == 0); ck_assert_int_eq(nchassis->c_ttl, 120); - ck_assert_int_eq(nchassis->c_name, NULL); - ck_assert_int_eq(nchassis->c_descr, NULL); - ck_assert_int_eq(nport->p_descr, NULL); + ck_assert_ptr_eq(nchassis->c_name, NULL); + ck_assert_ptr_eq(nchassis->c_descr, NULL); + ck_assert_ptr_eq(nport->p_descr, NULL); } END_TEST diff --git a/tests/check_marshal.c b/tests/check_marshal.c index 1254dd26..438d2d05 100644 --- a/tests/check_marshal.c +++ b/tests/check_marshal.c @@ -4,6 +4,7 @@ #include #define MARSHAL_EXPORT +#include "check-compat.h" #include "../src/marshal.h" #include "../src/log.h" @@ -11,16 +12,6 @@ CK_FORK=no valgrind -v --leak-check=yes ./tests/check_marshal */ -#if (CHECK_MAJOR_VERSION == 0 && (CHECK_MINOR_VERSION < 9 || (CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION < 10))) -# define ck_assert_ptr_eq(X,Y) do { \ - void* _ck_x = (X); \ - void* _ck_y = (Y); \ - ck_assert_msg(_ck_x == _ck_y, \ - "Assertion '"#X"=="#Y"' failed: "#X"==%p, "#Y"==%p", \ - _ck_x, _ck_y); \ - } while (0) -#endif - /* Use this callback to avoid some logs */ void donothing(int pri, const char *msg) {}; diff --git a/tests/common.h b/tests/common.h index 179aee6a..ed6320c4 100644 --- a/tests/common.h +++ b/tests/common.h @@ -1,6 +1,7 @@ #ifndef _COMMON_H #define _COMMON_H +#include "check-compat.h" #include "../src/daemon/lldpd.h" /* See: -- 2.39.5