mirror of
https://gitlab.freedesktop.org/wayland/weston
synced 2024-09-06 18:05:39 +00:00
shared: add weston_assert_bit_is_set()
Will be used in the next patch. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
parent
d9a7b3795a
commit
bdea44919b
|
@ -30,6 +30,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
struct weston_compositor;
|
||||
|
||||
|
@ -110,3 +111,15 @@ do { \
|
|||
|
||||
#define weston_assert_str_eq(compositor, a, b) \
|
||||
weston_assert_fn_(compositor, strcmp, a, b, const char *, "%s", ==)
|
||||
|
||||
#define weston_assert_bit_is_set(compositor, value, bit) \
|
||||
({ \
|
||||
struct weston_compositor *ec = compositor; \
|
||||
uint64_t v = (value); \
|
||||
uint8_t b = (bit); \
|
||||
bool cond = (v >> b) & 1; \
|
||||
if (!cond) \
|
||||
custom_assert_fail_(ec, "%s:%u: Assertion failed! Bit %s (%u) of %s (0x%" PRIx64 ") is not set.\n", \
|
||||
__FILE__, __LINE__, #bit, b, #value, v); \
|
||||
cond; \
|
||||
})
|
||||
|
|
|
@ -126,4 +126,10 @@ TEST(asserts)
|
|||
abort_if_not(ret);
|
||||
ret = weston_assert_my_type_lt(compositor, &a, &b);
|
||||
abort_if_not(ret == false);
|
||||
|
||||
uint32_t bitfield = 0xffff;
|
||||
ret = weston_assert_bit_is_set(compositor, bitfield, 2);
|
||||
abort_if_not(ret);
|
||||
ret = weston_assert_bit_is_set(compositor, bitfield, 57);
|
||||
abort_if_not(ret == false);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue