test/unit: simplify uc_assert_fail() macro

This removes the UC_ASSERT_ERR_ANY constant, which was causing a
compilation error on OSX:

error: comparison of constant 3735928559 with expression of type
'uc_err' (aka 'enum uc_err') is always true
[-Werror,-Wtautological-constant-out-of-range-compare]

I could have probably changed 0xDEADBEEF to a constant < 0x80000000
but this seems cleaner anyway.
This commit is contained in:
Jonathon Reinhart 2015-09-21 07:56:02 -04:00
parent 07122809b5
commit 02daa8df46

View File

@ -7,16 +7,13 @@
#include <cmocka.h> #include <cmocka.h>
#include <unicorn/unicorn.h> #include <unicorn/unicorn.h>
#define UC_ASSERT_ERR_ANY 0xDEADBEEF
/** /**
* Assert that err matches expect * Assert that err matches expect
*/ */
#define uc_assert_err(expect, err) \ #define uc_assert_err(expect, err) \
do { \ do { \
uc_err __err = err; \ uc_err __err = err; \
if ((__err != expect) \ if (__err != expect) { \
|| (expect == UC_ASSERT_ERR_ANY && __err == UC_ERR_OK)) { \
fail_msg("%s", uc_strerror(__err)); \ fail_msg("%s", uc_strerror(__err)); \
} \ } \
} while (0) } while (0)
@ -33,7 +30,13 @@ do { \
* as this serves to document which errors a function will return * as this serves to document which errors a function will return
* in various scenarios. * in various scenarios.
*/ */
#define uc_assert_fail(err) uc_assert_err(UC_ASSERT_ERR_ANY, err) #define uc_assert_fail(err) \
do { \
uc_err __err = err; \
if (__err == UC_ERR_OK) { \
fail_msg("%s", uc_strerror(__err)); \
} \
} while (0)
#endif /* UNICORN_TEST_H */ #endif /* UNICORN_TEST_H */