Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement unit test for a simple C function that returns binary data?

I want to implement some very simple C/C++ unit tests for a function that is supposed to compress or decompress some data.

Mainly the input is a binary block and the output is also a binary block. The binary blocks should be less than 50 bytes, probably having 5-6 pairs.

I am looking for a solution that would preferably not require third party libraries. If it would require this one should be very small/simple.

like image 800
sorin Avatar asked Nov 04 '22 05:11

sorin


1 Answers

"I am looking for a solution that would not require third party libraries."

Just write the unit-test function, it's easy: Create a function which will call the to-be-testet-function with different arguments and compare the result with the expected outputs. Add a function-pointer to that testing-function to a global function-pointer-array in which you store all testing-functions so that you can run all of them on demand.

like image 106
Bernd Elkemann Avatar answered Nov 09 '22 10:11

Bernd Elkemann