From 305371c21f7d865296a8e93791ad8a4f286b0b1a Mon Sep 17 00:00:00 2001 From: hugo303 Date: Fri, 8 Feb 2013 14:43:06 +0000 Subject: [PATCH] * Add equivalent uint variants for __ck_assert_int. Patch from bug #3600433 git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@695 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- configure.ac | 1 + doc/check.texi | 10 +++++ src/check.h.in | 14 +++++- tests/check_check_master.c | 7 +++ tests/check_check_sub.c | 87 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 152c808..a86aa1e 100644 --- a/configure.ac +++ b/configure.ac @@ -168,6 +168,7 @@ AC_C_CONST AC_TYPE_PID_T AC_TYPE_SIZE_T AC_TYPE_INTMAX_T +AC_TYPE_UINTMAX_T AC_TYPE_UINT32_T AC_HEADER_TIME AC_STRUCT_TM diff --git a/doc/check.texi b/doc/check.texi index 4c1a688..7fef034 100644 --- a/doc/check.texi +++ b/doc/check.texi @@ -868,6 +868,16 @@ by the last two letters of the function name. The abbreviations @code{eq}, @code{==}, @code{!=}, @code{<}, @code{<=}, @code{>}, and @code{>=} respectively. +@item ck_assert_uint_eq +@itemx ck_assert_uint_ne +@itemx ck_assert_uint_lt +@itemx ck_assert_uint_le +@itemx ck_assert_uint_gt +@itemx ck_assert_uint_ge + +Similar to @code{ck_assert_int_*}, but compares two unsigned integer values +(@code{uintmax_t}) instead. + @item ck_assert_str_eq @itemx ck_assert_str_ne @itemx ck_assert_str_lt diff --git a/src/check.h.in b/src/check.h.in index 7e9c520..015a906 100644 --- a/src/check.h.in +++ b/src/check.h.in @@ -282,7 +282,7 @@ void CK_EXPORT _ck_assert_msg (int result, const char *file, #define ck_abort() ck_abort_msg(NULL) #define ck_abort_msg(...) _ck_assert_msg(0, __FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL) -/* Integer comparsion macros with improved output compared to ck_assert(). */ +/* Signed and unsigned integer comparsion macros with improved output compared to ck_assert(). */ /* OP may be any comparion operator. */ #define _ck_assert_int(X, OP, Y) do { \ intmax_t _ck_x = (X); \ @@ -296,6 +296,18 @@ void CK_EXPORT _ck_assert_msg (int result, const char *file, #define ck_assert_int_gt(X, Y) _ck_assert_int(X, >, Y) #define ck_assert_int_ge(X, Y) _ck_assert_int(X, >=, Y) +#define _ck_assert_uint(X, OP, Y) do { \ + uintmax_t _ck_x = (X); \ + uintmax_t _ck_y = (Y); \ + ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%ju, "#Y"==%ju", _ck_x, _ck_y); \ +} while (0) +#define ck_assert_uint_eq(X, Y) _ck_assert_uint(X, ==, Y) +#define ck_assert_uint_ne(X, Y) _ck_assert_uint(X, !=, Y) +#define ck_assert_uint_lt(X, Y) _ck_assert_uint(X, <, Y) +#define ck_assert_uint_le(X, Y) _ck_assert_uint(X, <=, Y) +#define ck_assert_uint_gt(X, Y) _ck_assert_uint(X, >, Y) +#define ck_assert_uint_ge(X, Y) _ck_assert_uint(X, >=, Y) + /* String comparsion macros with improved output compared to ck_assert() */ /* OP might be any operator that can be used in '0 OP strcmp(X,Y)' comparison */ /* The x and y parameter swap in strcmp() is needed to handle >, >=, <, <= operators */ diff --git a/tests/check_check_master.c b/tests/check_check_master.c index 8e09fe5..6c8d16e 100644 --- a/tests/check_check_master.c +++ b/tests/check_check_master.c @@ -52,6 +52,13 @@ static master_test_t master_tests[] = { { "Simple Tests", CK_FAILURE, "Assertion 'y>y' failed: y==3, y==3" }, { "Simple Tests", CK_FAILURE, "Assertion 'x>=y' failed: x==2, y==3" }, { "Simple Tests", CK_PASS, "Passed" }, + { "Simple Tests", CK_FAILURE, "Assertion 'x==y' failed: x==3, y==4" }, + { "Simple Tests", CK_FAILURE, "Assertion 'x!=y' failed: x==3, y==3" }, + { "Simple Tests", CK_FAILURE, "Assertion 'xy' failed: y==3, y==3" }, + { "Simple Tests", CK_FAILURE, "Assertion 'x>=y' failed: x==2, y==3" }, + { "Simple Tests", CK_PASS, "Passed" }, { "Simple Tests", CK_FAILURE, "Assertion '\"test1\"==s' failed: \"test1\"==\"test1\", s==\"test2\"" }, { "Simple Tests", CK_FAILURE, "Assertion 't!=s' failed: t==\"test2\", s==\"test2\"" }, { "Simple Tests", CK_FAILURE, "Assertion 's