Skip to content

Commit

Permalink
mock,api: use comparison operators rather than mmk_memcmp
Browse files Browse the repository at this point in the history
mmk_memcmp might have been a good idea in theory.

That is, if you don't account for endianness.

We now use regular comparison operators.  This means that users can't use
comparison matchers with types that doesn't implement those operators,
but in practice this is exactly what mmk_that is for, so we choose
correctness over genericity.
  • Loading branch information
Snaipe committed Jul 13, 2017
1 parent cac5368 commit 47a735a
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions include/mimick/mock.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ void mmk_reset(mmk_fn fn);
if (m->kind == MMK_MATCHER_ANY) { \ if (m->kind == MMK_MATCHER_ANY) { \
/* Ugly but keeps the indentation level as it is */ \ /* Ugly but keeps the indentation level as it is */ \
} else if (m->kind & MMK_MATCHER_BIT_CMP) { \ } else if (m->kind & MMK_MATCHER_BIT_CMP) { \
int res = mmk_memcmp(&param ## N, \ if (param ## N == bind->params.param ## N \
&bind->params.param ## N, sizeof (Type)); \ && !(m->kind & MMK_MATCHER_BIT_EQ)) \
if (res == 0 && !(m->kind & MMK_MATCHER_BIT_EQ)) \
continue; \ continue; \
if (res < 0 && !(m->kind & MMK_MATCHER_BIT_LT)) \ if (param ## N < bind->params.param ## N \
&& !(m->kind & MMK_MATCHER_BIT_LT)) \
continue; \ continue; \
if (res > 0 && !(m->kind & MMK_MATCHER_BIT_GT)) \ if (param ## N > bind->params.param ## N \
&& !(m->kind & MMK_MATCHER_BIT_GT)) \
continue; \ continue; \
} else if (m->kind == MMK_MATCHER_THAT) { \ } else if (m->kind == MMK_MATCHER_THAT) { \
int (*predicate)(Type) = (int (*)(Type)) \ int (*predicate)(Type) = (int (*)(Type)) \
mmk_matcher_get_predicate(m); \ mmk_matcher_get_predicate(m); \
if (!predicate(param ## N)) \ if (!predicate(param ## N)) \
continue; \ continue; \
} \ } \
} else { \ } else if (param ## N != bind->params.param ## N) { \
if (mmk_memcmp(&param ## N, &bind->params.param ## N, sizeof (Type))) \ continue; \
continue; \
} }


# define MMK_TRYVERIFY_VA(Id, ...) \ # define MMK_TRYVERIFY_VA(Id, ...) \
Expand All @@ -144,22 +144,23 @@ void mmk_reset(mmk_fn fn);
if (m->kind == MMK_MATCHER_ANY) { \ if (m->kind == MMK_MATCHER_ANY) { \
/* Ugly but keeps the indentation level as it is */ \ /* Ugly but keeps the indentation level as it is */ \
} else if (m->kind & MMK_MATCHER_BIT_CMP) { \ } else if (m->kind & MMK_MATCHER_BIT_CMP) { \
int res = mmk_memcmp(&p->param ## N, &param ## N, sizeof (Type)); \ if (p->param ## N == param ## N \
if (res == 0 && !(m->kind & MMK_MATCHER_BIT_EQ)) \ && !(m->kind & MMK_MATCHER_BIT_EQ)) \
goto fail; \ goto fail; \
if (res < 0 && !(m->kind & MMK_MATCHER_BIT_LT)) \ if (p->param ## N < param ## N \
&& !(m->kind & MMK_MATCHER_BIT_LT)) \
goto fail; \ goto fail; \
if (res > 0 && !(m->kind & MMK_MATCHER_BIT_GT)) \ if (p->param ## N > param ## N \
&& !(m->kind & MMK_MATCHER_BIT_GT)) \
goto fail; \ goto fail; \
} else if (m->kind == MMK_MATCHER_THAT) { \ } else if (m->kind == MMK_MATCHER_THAT) { \
int (*predicate)(Type) = (int (*)(Type)) \ int (*predicate)(Type) = (int (*)(Type)) \
mmk_matcher_get_predicate(m); \ mmk_matcher_get_predicate(m); \
if (!predicate(p->param ## N)) \ if (!predicate(p->param ## N)) \
goto fail; \ goto fail; \
} \ } \
} else { \ } else if (p->param ## N != param ## N) { \
if (mmk_memcmp(&p->param ## N, &param ## N, sizeof (Type))) \ goto fail; \
goto fail; \
} }


# define MMK_SET_PARAMS_VA(Id, ...) \ # define MMK_SET_PARAMS_VA(Id, ...) \
Expand Down

0 comments on commit 47a735a

Please sign in to comment.