mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-09 08:18:02 +02:00
test: replace the double assert macros with proper checks
Instead of value * 256 which makes for bad debug messages, expand it to a full double test with a 1/256 epsilon. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
c3005ce48e
commit
f70b80569a
2 changed files with 44 additions and 6 deletions
|
|
@ -206,6 +206,24 @@ litest_fail_comparison_int(const char *file,
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((noreturn))
|
||||||
|
void
|
||||||
|
litest_fail_comparison_double(const char *file,
|
||||||
|
int line,
|
||||||
|
const char *func,
|
||||||
|
const char *operator,
|
||||||
|
double a,
|
||||||
|
double b,
|
||||||
|
const char *astr,
|
||||||
|
const char *bstr)
|
||||||
|
{
|
||||||
|
litest_log("FAILED COMPARISON: %s %s %s\n", astr, operator, bstr);
|
||||||
|
litest_log("Resolved to: %.3f %s %.3f\n", a, operator, b);
|
||||||
|
litest_log("in %s() (%s:%d)\n", func, file, line);
|
||||||
|
litest_backtrace();
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
__attribute__((noreturn))
|
__attribute__((noreturn))
|
||||||
void
|
void
|
||||||
litest_fail_comparison_ptr(const char *file,
|
litest_fail_comparison_ptr(const char *file,
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,15 @@ litest_fail_comparison_int(const char *file,
|
||||||
const char *astr,
|
const char *astr,
|
||||||
const char *bstr);
|
const char *bstr);
|
||||||
void
|
void
|
||||||
|
litest_fail_comparison_double(const char *file,
|
||||||
|
int line,
|
||||||
|
const char *func,
|
||||||
|
const char *operator,
|
||||||
|
double a,
|
||||||
|
double b,
|
||||||
|
const char *astr,
|
||||||
|
const char *bstr);
|
||||||
|
void
|
||||||
litest_fail_comparison_ptr(const char *file,
|
litest_fail_comparison_ptr(const char *file,
|
||||||
int line,
|
int line,
|
||||||
const char *func,
|
const char *func,
|
||||||
|
|
@ -164,6 +173,17 @@ litest_fail_comparison_ptr(const char *file,
|
||||||
#a_ " " #op_ " " #b_); \
|
#a_ " " #op_ " " #b_); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
#define litest_assert_comparison_double_(a_, op_, b_) \
|
||||||
|
do { \
|
||||||
|
const double EPSILON = 1.0/256; \
|
||||||
|
__typeof__(a_) _a = a_; \
|
||||||
|
__typeof__(b_) _b = b_; \
|
||||||
|
if (!((_a) op_ (_b)) && fabs((_a) - (_b)) > EPSILON) \
|
||||||
|
litest_fail_comparison_double(__FILE__, __LINE__, __func__,\
|
||||||
|
#op_, _a, _b, \
|
||||||
|
#a_, #b_); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#define litest_assert_ptr_eq(a_, b_) \
|
#define litest_assert_ptr_eq(a_, b_) \
|
||||||
litest_assert_comparison_ptr_(a_, ==, b_)
|
litest_assert_comparison_ptr_(a_, ==, b_)
|
||||||
|
|
||||||
|
|
@ -177,22 +197,22 @@ litest_fail_comparison_ptr(const char *file,
|
||||||
litest_assert_comparison_ptr_(a_, !=, NULL)
|
litest_assert_comparison_ptr_(a_, !=, NULL)
|
||||||
|
|
||||||
#define litest_assert_double_eq(a_, b_)\
|
#define litest_assert_double_eq(a_, b_)\
|
||||||
ck_assert_int_eq((int)((a_) * 256), (int)((b_) * 256))
|
litest_assert_comparison_double_((a_), ==, (b_))
|
||||||
|
|
||||||
#define litest_assert_double_ne(a_, b_)\
|
#define litest_assert_double_ne(a_, b_)\
|
||||||
ck_assert_int_ne((int)((a_) * 256), (int)((b_) * 256))
|
litest_assert_comparison_double_((a_), !=, (b_))
|
||||||
|
|
||||||
#define litest_assert_double_lt(a_, b_)\
|
#define litest_assert_double_lt(a_, b_)\
|
||||||
ck_assert_int_lt((int)((a_) * 256), (int)((b_) * 256))
|
litest_assert_comparison_double_((a_), <, (b_))
|
||||||
|
|
||||||
#define litest_assert_double_le(a_, b_)\
|
#define litest_assert_double_le(a_, b_)\
|
||||||
ck_assert_int_le((int)((a_) * 256), (int)((b_) * 256))
|
litest_assert_comparison_double_((a_), <=, (b_))
|
||||||
|
|
||||||
#define litest_assert_double_gt(a_, b_)\
|
#define litest_assert_double_gt(a_, b_)\
|
||||||
ck_assert_int_gt((int)((a_) * 256), (int)((b_) * 256))
|
litest_assert_comparison_double_((a_), >, (b_))
|
||||||
|
|
||||||
#define litest_assert_double_ge(a_, b_)\
|
#define litest_assert_double_ge(a_, b_)\
|
||||||
ck_assert_int_ge((int)((a_) * 256), (int)((b_) * 256))
|
litest_assert_comparison_double_((a_), >=, (b_))
|
||||||
|
|
||||||
enum litest_device_type {
|
enum litest_device_type {
|
||||||
LITEST_NO_DEVICE = -1,
|
LITEST_NO_DEVICE = -1,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue