I'm trying to use Cmockery to mock C functions called from C ++ code. Since SUT is in C ++, my tests should be in C ++.
When I use the Cmockery macro expect_string () as follows:
expect_string(mock_function, url, "Foo");
I get:
my_tests.cpp: In function βvoid test_some_stuff(void**)β:
my_tests.cpp:72: error: invalid conversion from βvoid*β to βconst char*β
my_tests.cpp:72: error: initializing argument 5 of βvoid _expect_string(const char*, const char*, const char*, int, const char*, int)β
I see in cmockery.h for which the expect_string function is defined:
#define expect_string(function, parameter, string) \
expect_string_count(function, parameter, string, 1)
#define expect_string_count(function, parameter, string, count) \
_expect_string(#function, #parameter, __FILE__, __LINE__, (void*)string, \
count)
And here is the prototype for _expect_string (from cmockery.h):
void _expect_string(
const char* const function, const char* const parameter,
const char* const file, const int line, const char* string,
const int count);
I believe the problem is that I am compiling C code as C ++, so the C ++ compiler objects (void*)stringto the expect_string_count macro passed as a parameter const char* stringto the _expect_string () function.
extern "C" cmockery.h my_tests.cpp, :
extern "C" {
#include <cmockery.h>
}
..., . (. " ++ C-?" )
- g++, ++ C cmockery.c?
, my_tests.cpp:
g++ -m32 -I ../cmockery-0.1.2 -c my_tests.cpp -o $(obj_dir)/my_tests.o