Permalink
Browse files

mock,api: use comparison operators rather than mmk_memcmp

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 47a735ab76221593de6f9f4ab9c39d9f6a8fc384
Showing with 16 additions and 15 deletions.
  1. +16 −15 include/mimick/mock.h
@@ -109,23 +109,23 @@ void mmk_reset(mmk_fn fn);
if (m->kind == MMK_MATCHER_ANY) { \
/* Ugly but keeps the indentation level as it is */ \
} else if (m->kind & MMK_MATCHER_BIT_CMP) { \
int res = mmk_memcmp(&param ## N, \
&bind->params.param ## N, sizeof (Type)); \
if (res == 0 && !(m->kind & MMK_MATCHER_BIT_EQ)) \
if (param ## N == bind->params.param ## N \
&& !(m->kind & MMK_MATCHER_BIT_EQ)) \
continue; \
if (res < 0 && !(m->kind & MMK_MATCHER_BIT_LT)) \
if (param ## N < bind->params.param ## N \
&& !(m->kind & MMK_MATCHER_BIT_LT)) \
continue; \
if (res > 0 && !(m->kind & MMK_MATCHER_BIT_GT)) \
if (param ## N > bind->params.param ## N \
&& !(m->kind & MMK_MATCHER_BIT_GT)) \
continue; \
} else if (m->kind == MMK_MATCHER_THAT) { \
int (*predicate)(Type) = (int (*)(Type)) \
mmk_matcher_get_predicate(m); \
if (!predicate(param ## N)) \
continue; \
} \
} else { \
if (mmk_memcmp(&param ## N, &bind->params.param ## N, sizeof (Type))) \
continue; \
} else if (param ## N != bind->params.param ## N) { \
continue; \
}

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

# define MMK_SET_PARAMS_VA(Id, ...) \

0 comments on commit 47a735a

Please sign in to comment.