Questions tagged [cmockery]

Cmockery is a testing and mocking library for C.

Cmockery only requires linking with the C library; it does not require use of C++ or a C++ compiler or any advanced or recent features of the C language, thus making it portable and usable in many situations, e.g., testing embedded code.

10 questions
6
votes
4 answers

How do I compile and link C++ code with compiled C code?

I want to be able to use Cmockery to mock C functions called from C++ code I'm testing. As a step towards that, I've renamed the Cmockery example run_tests.c to run_tests.cpp, and am attempting to compile and link it with cmockery.c: g++ -m32…
Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
5
votes
1 answer

Cmocka - Error: No Entries for symbol

I'm just starting out with Cmocka, I've been stuck on this issue for a while now. I have a cmocka project that I'm trying to build. I'm seeing the error when I try to use 'make'. [ ERROR ] --- No entries for symbol __wrap_i2c_read. Also I'm…
User_MK
  • 63
  • 1
  • 6
4
votes
1 answer

CMockery Compilation unknown type name "jmp_buf"

I am trying to add unit testing framework cMockery to my C project. I have downloaded and installed the cMockery into global include path. But after #include in my source file, cmake throws the following issue. It seems the same thing…
thuyein
  • 1,684
  • 13
  • 29
4
votes
2 answers

Correct way to temporarily enable and disable function wrapping in cmocka?

I am using the cmocka library to test some embedded c code. According to the documentation I use the __wrap_ prefix to mock functions so I can isolate my unit tests. However once I do that all calls to the function forever go to the wrapped…
satur9nine
  • 13,927
  • 5
  • 80
  • 123
3
votes
2 answers

How do I tell gcc to relax its restrictions on typecasting when calling a C function from C++?

I'm trying to use Cmockery to mock C functions called from C++ code. Because the SUT is in C++, my tests need to be in C++. When I use the Cmockery expect_string() macro like this: expect_string(mock_function, url, "Foo"); I get: my_tests.cpp: In…
Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
3
votes
1 answer

Verify function pointer equality with Cmockery

I am writing Unit test and wondering how would I test function pointers with Cmockery. A.c void (*FunctionPtr)(void) = &funcA; void funcA() { // calls func B funcB(); } TestA.c void Test_A( void ** state ) { // test for FunA; working as…
samprat
  • 2,150
  • 8
  • 39
  • 73
0
votes
1 answer

CMockery Mock, Duplicate Symbol Error

I'm having the problem with CMockery mocks that there are coming duplicate symbol warnings. The implementation of the code is quite long, so it's in a Gist here. The Gist includes the test (.c), implementation (.c) and header file, the project is…
Lee Hambley
  • 6,270
  • 5
  • 49
  • 81
0
votes
1 answer

How do I work around the GCC "error: cast from ‘SourceLocation*’ to ‘int’ loses precision" error when compiling cmockery.c?

I need to add unit tests using Cmockery to an existing build environment that uses as hand-crafted Makefile. So I need to figure out how to build cmockery.c (without automake). When I run: g++ -DHAVE_CONFIG_H -DPIC -I ../cmockery-0.1.2 -I…
Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
0
votes
1 answer

how do i use cmockery in my projects

I was searching for a way to create mocking objects with c-code until I stumbled upon cmockery. For me it seems to be the best mocking software available since it doesn't have a lot of dependencies. I'm working in ubuntu and downloaded the tarball…
Mathias
  • 633
  • 5
  • 5
-3
votes
1 answer

Checking if function, tested with CMockery, calls another particular function

I am facing problem in writing mock code using CMockery for a function shown below. Can you please give me some hint? I want to test if startCalCompute is called and also to assign value to updateMode, so that it is not equal to SYSTEM_CAL_CONFIG.…
samprat
  • 2,150
  • 8
  • 39
  • 73