googletest - how to test static functions of C using google test -
i have c file contains static functions, how use google test test static function?
header file:
test.h int accessdata();
source file:
test.c static int value; static int getdata() { return value; } int accessdata() { if(value != 0) { return getdata(); } return 0; }
static function called global function, how test static function using google test?
one way achieve #include
c source file test source. then, static
function part of same translation unit test code, , can called it:
#include "test.c" /* here follow tests of getdata() */
the downside in test.c
gets compiled again, obvious impact on build times. if gets problem, might consider extracting static functions tested own source file (e.g. test_p.c
, _p
meaning private/internal). #include "test_p.c"
both test.c
, unit test.
Comments
Post a Comment