google / cmockery

A lightweight library to simplify and generalize the process of writing unit tests for C applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doing a mockup of a function which have a long long (>32 bits) parameter

GoogleCodeExporter opened this issue · comments

Hi !

If you have a function with "long long" parameters/return value, like this
one :
int myFunction(long long id, char *name);

If I try to do a mockup with this function :

int myFunction(long long id, char *name) {
  check_expected(id);
  check_expected(name);
  return *(int *)mock();
}

First, the computer will warn me "warning: cast to pointer from integer of
different size". The line "check_expected(id);" seems to trig the problem.

In fact the macro cast its parameter to a "void *", but a "void *" is a 32
bits wide and the "id" parameter is 64 bits wide.

I can ignore the warning and continue with it, but the checked value will
be truncated, the test will be a success, if I do someting like :

...
expect_value(myFunction, id, 0x34FFFFFFFF);
...
myFunction(0x89FFFFFFFF, "hello");
...

What is your opinion on it ?


Would it be easy to cast the "value" parameter to the biggest type
available on the current host (long long ?) ?
Or will it break something ?


Thanks for your help and for this amazing tool : mockup in c is a really
cool feature !

Original issue reported on code.google.com by meurant....@gmail.com on 7 Oct 2008 at 9:02

Issue 1 has been merged into this issue.

Original comment by stewarta...@gmail.com on 10 Apr 2009 at 9:43

Original comment by stewarta...@gmail.com on 10 Apr 2009 at 9:43

The fix for this will be integrated into cmockery release 0.1.3.

Original comment by stewarta...@gmail.com on 7 Jul 2009 at 7:43

Original comment by stewarta...@gmail.com on 7 Jul 2009 at 7:51

  • Changed state: Started