2015-09-07 19:05:55 +00:00
|
|
|
#ifndef UNICORN_TEST_H
|
|
|
|
#define UNICORN_TEST_H
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
|
|
|
#include <unicorn/unicorn.h>
|
|
|
|
|
2015-09-14 01:32:31 +00:00
|
|
|
#define UC_ASSERT_ERR_ANY 0xDEADBEEF
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that err matches expect
|
|
|
|
*/
|
|
|
|
#define uc_assert_err(expect, err) \
|
|
|
|
do { \
|
|
|
|
uc_err __err = err; \
|
|
|
|
if ((__err != expect) \
|
|
|
|
|| (expect == UC_ASSERT_ERR_ANY && __err == UC_ERR_OK)) { \
|
|
|
|
fail_msg("%s", uc_strerror(__err)); \
|
|
|
|
} \
|
2015-09-07 20:07:48 +00:00
|
|
|
} while (0)
|
|
|
|
|
2015-09-14 01:32:31 +00:00
|
|
|
/**
|
|
|
|
* Assert that err is UC_ERR_OK
|
|
|
|
*/
|
|
|
|
#define uc_assert_success(err) uc_assert_err(UC_ERR_OK, err)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that err is anything but UC_ERR_OK
|
|
|
|
*
|
|
|
|
* Note: Better to use uc_assert_err(<specific error>, err),
|
|
|
|
* as this serves to document which errors a function will return
|
|
|
|
* in various scenarios.
|
|
|
|
*/
|
|
|
|
#define uc_assert_fail(err) uc_assert_err(UC_ASSERT_ERR_ANY, err)
|
2015-09-07 20:07:48 +00:00
|
|
|
|
2015-09-07 19:05:55 +00:00
|
|
|
|
|
|
|
#endif /* UNICORN_TEST_H */
|