Questions tagged [cmocka]

Cmocka is a C unit testing framework

Cmocka is a C unit testing framework

66 questions
3
votes
1 answer

How to use cmocka library to mock a function from 3rd party library which cannot be modified?

I am trying to write a test case in c using cmocka library.My testcase is testing a function which then internally calls a function from a 3rd party library (cannot modify the library).This function return NULL value when application is not up and…
user2156513
  • 113
  • 7
3
votes
1 answer

How to handle problems with RPATH on Mac OS X while installing cmocka?

I am trying to install and run cmocka library for unit testing on Mac OSX Yosemite 10.10.3, but I've got some problems with the RPATH settings. Update: Thanks to @baf, I was able to include cmocka.h in my CMakeLists.txt manually like…
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
2
votes
0 answers

Integrating a library in eclipse stops the debug exe from running as expected

I am trying to set up a C project with cmocka unit test framework in eclipse. Following software is used: Windows 10 gcc 9.2.0 cmocka 1.1.0 Eclipse cdt 4.22.0 I create a new default Hello World ANSI C Project in eclipse called "cmocka_test". It…
2
votes
0 answers

Cmocka: how to mock a function called as a function pointer

INT32 shellInit(shell_t *shell) { INT32 ret = ZKOS_SUCCESS; /* initialize shell device */ if (shell->dev->ops->init) { if ((ret = shell->dev->ops->init(shell->dev)) != ZKOS_SUCCESS) { ZKOS_LOG("fail to…
Wanghz
  • 305
  • 2
  • 12
2
votes
1 answer

How to handle static elements with cmocka?

I am using cmocka to do some unit testing on my C-Project and I am wondering how to handle static emelents. Static elements are for me: Functions declared as static Variables inside functions which are declared as static So let the function fut be…
eDeviser
  • 1,605
  • 2
  • 17
  • 44
2
votes
2 answers

How can Cmocka test that my (void) callback function was called with the correct parameters?

I am using Cmocka for unit test and that cannot be changed. I am testing part of my software which invokes callback functions, if a value changes, indicating which data item changed and what the new value is. The callback functions have this…
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
2
votes
1 answer

CMOCKA / Linker : 'wrap'ping lots of functions

I recently came across the 'cmocka' mocking library for C. I was able to mock a single function and test the caller function successfully. Now i need it to use it for a project that i am working on, where it is required to mock a large number of…
melwin_jose
  • 315
  • 3
  • 20
2
votes
5 answers

Cmocka tests do not show any output

I have downloaded the cmocka example files and followed all the instructions. All test files were succesfully generated and I can run them, but no output appears in the console. I have tried to alter the CMOCKA_MESSAGE_OUTPUT environmental variable,…
jalooc
  • 1,169
  • 13
  • 23
1
vote
1 answer

Cmocka - should we all be creating one executable per test for isolating static variables?

Failure Given the following cmocka test with a static variable in a dependency: main.c #include #include #include #include #include "dependency.h" void test1(void** state) { increment(); …
karobar
  • 1,250
  • 8
  • 30
  • 61
1
vote
1 answer

Mocking functions with cmocka

I'm trying to mock some functions using cmocka: void test_led_driver_NeedToImplement(void **state) { state_t current = CLEAR; will_return(led_status_toggel,SET); TEST_ASSERT_EQUAL(SET, led_status_toggel(current)); } But, I…
Nesmo07
  • 15
  • 3
1
vote
1 answer

__wrap_strcpy() has remaining non-returned values

I'm new, I have a problem with unit-test using cmocka. I have the following function : #include #include #include "function.h" void copy_ip_addr(char *ip_addr_ascii) { char ip_ascii[50]; strcpy(ip_ascii,…
1
vote
0 answers

Cmocka: printing context on test failure

I am using CMocka to write some unit tests. Some of my tests loop though a list of cases which are stored in a struct to avoid repetition: typedef struct { char* test_arg; int expected; } TestCase; const static TestCase cases[] = { {"1",…
Inductiveload
  • 6,094
  • 4
  • 29
  • 55
1
vote
0 answers

How can I use CMake and CPack with a dependency that overwrites my variables?

I'm trying to use CPack to package my project, but I've run into an issue with one of my dependencies. First, I am trying to use modern CMake style by relying on targets and dependencies modeled between targets using target_link_libraries. My…
Dan Nestor
  • 2,441
  • 1
  • 24
  • 45
1
vote
2 answers

How does target_link_libraries(--wrap) work?

I want to create mock functions for C code testing and get to know that in target_link_libraries() have option to wrap the function which work similar to mock, But not understand how it will work? target_link_libraries(IntegrationTests…
AshishP
  • 39
  • 6
1
vote
1 answer

CMake and CMocka standard assertions for compiling tests

I have a small static library project that I'm rewriting from building with Makefiles to modern CMake, which I am trying to learn. My project uses assertions quite heavily for checking preconditions, so I have written a very simple custom assertion…
Andrew
  • 21
  • 5