chenjiancan / cmockery

Automatically exported from code.google.com/p/cmockery
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
Issue 1 has been merged into this issue.

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

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

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