Questions tagged [cunit]

Anything related to CUnit, a unit testing framework for C programs.

Anything related to CUnit, a unit testing framework for C programs.

80 questions
10
votes
1 answer

How to test code that writes to stdout?

How to write a test in CUnit for a function that prints to stdout, to verify its output? Example function to test: void print() { printf("Hello world"); } Its unit test should somehow verify that "Hello world" was printed to the console: void…
qianchenglong
  • 474
  • 5
  • 13
5
votes
2 answers

netbeans cunit tests cases never end

Trying to test my C project on NetBeans, the tests never end while the output is: Test: testFileOne ...passed Test: testFileTwo ...passed Run Summary: Type Total Ran Passed Failed Inactive suites 1 1 n/a …
Desmond
  • 567
  • 1
  • 7
  • 17
5
votes
2 answers

CUnit - 'Mocking' libc functions

I'm using CUnit for my project unit testing. I need to test whether I call libc functions with the right parameters & whether I treat their return values the right way. for example: if I call the bind(...) function - I would like to check which af…
Jo D.
  • 53
  • 1
  • 3
5
votes
0 answers

A good tutorial for CUnit?

I am looking for an online tutorial for CUnit. After much "Googling", the only ones I have come across are the CUnit documentation on sourceforge and this one. None of which can really be described as a tutorial with a "walk though" working…
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
5
votes
2 answers

Is there a framework for running unit tests on Apache C modules?

I am about to make some changes to an existing Apache C module to fix some possible security flaws and general bad practices. However the functionality of the code must remain unchanged (except in cases where its fixing a bug). Standard regression…
Vagnerr
  • 2,977
  • 3
  • 33
  • 46
5
votes
1 answer

Unit test of flex bison scanner parse, how to drive the test case

I have a question about how to "drive" a flex bison based parser scanner in a unit test. The final solution will be a command parser available or telnet to a target board. I have a fully working flex bison implementation using stdin. Right now my…
rmcarlsson
  • 91
  • 6
4
votes
3 answers

How to create a JNIEnv mock in C/C++

I am writing some JNI code in C that I wish to test using cunit. In order to call the JNI functions, I need to create a valid JNIEnv struct. Does anyone know if there is a mocking framework for such a purpose, or who can give me some pointers on how…
David Arno
  • 42,717
  • 16
  • 86
  • 131
4
votes
0 answers

How to use gcov with gcc without the optimization?

I have a test code like this: int diff21(int n) { if (n <= 21) { return 21 - n; } else { return (n - 21) * 2; } } and I added the compile flags: -fprofile-arcs -ftest-coverage to provide coverage data. I…
shengy
  • 9,461
  • 4
  • 37
  • 61
4
votes
4 answers

CUnit failures in hudson show success

i put unit tests in C running over hudson, but when i have a test that failures it shows a success in the build, but must to appear fail! I'm using gcc to compile and run the executable in hudson like that: gcc -lcunit test_ctesting.c -o…
guisantogui
  • 4,017
  • 9
  • 49
  • 93
3
votes
3 answers

Unit testing for exit() in C

I'm using the CUnit framework for the way it displays the testing results. (I'm a programming & S.O. newbie so step by step answers really appreciated). Is there any way I can use the same CUnit framework for when I'm testing for functions that I…
3
votes
2 answers

Does anyone know of an easy way to programatically mount a file as a "disk" (FAT32) in Windows 7?

I have some automated test (using CUnit) which require a "disk-image"-file (raw copy of a disk) to be "mounted" in windows and explored. I have previously used a tool/library called "FileDisk-17" , but this doesn't seem to work on my Windows 7…
S.C. Madsen
  • 5,100
  • 5
  • 32
  • 50
3
votes
2 answers

Configuring xUnit for CUnit in Hudson CI

I want to use Hudson CI for my c-project, which also uses CUnit. However I've also come to understand that there is currently no plugin that supports CUnit. So I read on the internets that this might be possible using the xUnit plugin by translating…
mahju
  • 1,156
  • 1
  • 14
  • 21
3
votes
2 answers

CUnit assert that two arrays are equal

I'm trying to figure out, what is the best way of asserting equality of arrays in CUnit. The documentation I'm aware of does not contain anything related to arrays at all. Possibilities I considered so far: Loop through the array elements and check…
Attilio
  • 1,624
  • 1
  • 17
  • 27
3
votes
1 answer

How to test within a precision using Cgreen?

I need to test doubles in a unit test written using Cgreen. My comparison and generated values are very close, but assert_double_equal says 1.95 != 1.94887879 How can I tell Cgreen to test within a certain precision? This is close enough for…
DeepDeadpool
  • 1,441
  • 12
  • 36
3
votes
1 answer

Tests with CUNIT - walkthrough analysis / code coverage

I want to test some code with CUnit. Does anyone know if it is possible to do a walktrough Analysis? I want to have something, that says, you`ve tested 80% of your function. It must be ensured, that 100% coverage are reached with the test.
user1038155
1
2 3 4 5 6