From: Joseph Sutton Date: Wed, 18 Oct 2023 23:34:53 +0000 (+1300) Subject: lib/torture: Add torture_assert_size_*() macros X-Git-Tag: talloc-2.4.2~1156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46f0c2696582ab6561808dcfadcfc5cf9bc67a3a;p=thirdparty%2Fsamba.git lib/torture: Add torture_assert_size_*() macros BUG: https://bugzilla.samba.org/show_bug.cgi?id=15498 Signed-off-by: Joseph Sutton Reviewed-by: Andreas Schneider --- diff --git a/lib/torture/torture.h b/lib/torture/torture.h index 94d8543770c..ad343cb030b 100644 --- a/lib/torture/torture.h +++ b/lib/torture/torture.h @@ -653,6 +653,54 @@ static inline void torture_dump_data_str_cb(const char *buf, void *private_data) } \ } while(0) +#define torture_assert_size_equal(torture_ctx,got,expected,cmt)\ + do { size_t __got = (got), __expected = (expected); \ + if (__got != __expected) { \ + torture_result(torture_ctx, TORTURE_FAIL, \ + __location__": "#got" was %zu (0x%zX), expected %zu (0x%zX): %s", \ + __got, __got, \ + __expected, __expected, \ + cmt); \ + return false; \ + } \ + } while(0) + +#define torture_assert_size_equal_goto(torture_ctx,got,expected,ret,label,cmt)\ + do { size_t __got = (got), __expected = (expected); \ + if (__got != __expected) { \ + torture_result(torture_ctx, TORTURE_FAIL, \ + __location__": "#got" was %zu (0x%zX), expected %zu (0x%zX): %s", \ + __got, __got, \ + __expected, __expected, \ + cmt); \ + ret = false; \ + goto label; \ + } \ + } while(0) + +#define torture_assert_size_not_equal(torture_ctx,got,not_expected,cmt)\ + do { size_t __got = (got), __not_expected = (not_expected); \ + if (__got == __not_expected) { \ + torture_result(torture_ctx, TORTURE_FAIL, \ + __location__": "#got" was %zu (0x%zX), expected a different number: %s", \ + __got, __got, \ + cmt); \ + return false; \ + } \ + } while(0) + +#define torture_assert_size_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\ + do { size_t __got = (got), __not_expected = (not_expected); \ + if (__got == __not_expected) { \ + torture_result(torture_ctx, TORTURE_FAIL, \ + __location__": "#got" was %zu (0x%zX), expected a different number: %s", \ + __got, __got, \ + cmt); \ + ret = false; \ + goto label; \ + } \ + } while(0) + #define torture_assert_errno_equal(torture_ctx,expected,cmt)\ do { int __expected = (expected); \ if (errno != __expected) { \