]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/torture: add assert_int_{less,greater} macros
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 5 Apr 2024 01:22:11 +0000 (14:22 +1300)
committerJule Anger <janger@samba.org>
Mon, 10 Jun 2024 13:25:16 +0000 (13:25 +0000)
In some situations, like comparison functions for qsort, we don't care
about the actual value, just whethger it was greater or less than
zero.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15625

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit 6159b098cf35a8043682bfd4c4ea17ef0da6e8ee)

lib/torture/torture.h

index 6818084ea9612f4ed1edaaf3c6c7b10e56fc15c7..3509911c8ca4c11948ad78adc2bfc0f5e3801fed 100644 (file)
@@ -525,6 +525,26 @@ static inline void torture_dump_data_str_cb(const char *buf, void *private_data)
        } \
        } while(0)
 
+#define torture_assert_int_less(torture_ctx,got,limit,cmt)\
+       do { int __got = (got), __limit = (limit); \
+       if (__got >= __limit) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was %d (0x%X), expected < %d (0x%X): %s", \
+                       __got, __got, __limit, __limit, cmt); \
+               return false; \
+       } \
+       } while(0)
+
+#define torture_assert_int_greater(torture_ctx,got,limit,cmt)\
+       do { int __got = (got), __limit = (limit); \
+       if (__got <= __limit) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was %d (0x%X), expected > %d (0x%X): %s", \
+                       __got, __got, __limit, __limit, cmt); \
+               return false; \
+       } \
+       } while(0)
+
 #define torture_assert_int_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
        do { int __got = (got), __expected = (expected); \
        if (__got != __expected) { \