]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/torture: Add torture_assert_size_*() macros
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Wed, 18 Oct 2023 23:34:53 +0000 (12:34 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 24 Oct 2023 14:48:36 +0000 (14:48 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15498

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/torture/torture.h

index 94d8543770cd6f818f27264408951392c6cc28ca..ad343cb030b8aa6cee07f05ccba332bef41f9168 100644 (file)
@@ -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) { \