unit testing - Replacing a C function from a common .o file for the scope of a single test executable -



unit testing - Replacing a C function from a common .o file for the scope of a single test executable -

so, i've got library phone call init_foo(), , function bar() calls it. these live in library.o along other useful stuff both need.

i want write code, bar_init_failure.t.c, test happens when init_foo() fails, without setting failure. in perl, mass of our codebase, i'd launch test::resub , replace library phone call stub returns failure code. accomplish similar in c, vaguely under impression redefine init_foo in source bar_init_failure.t.c , still link against library.o rest of code, gcc , ld complain duplicate symbols (instead of picking first one) think must wrong (and i'm pretty rusty on sort of stuff, i'm not over-confident in strategy).

is there way appease linker here, or there strategy should using? (i'd prefer not have hack library.c code if can help it.)

if can recompile library.c shared library, can redefine init_foo() within unit tests. ld won't complain duplicate symbols, neither @ compile time, nor @ execution`, , invoke function in executable whatever dynamic library contain - @ to the lowest degree on unix-like systems - never tried on windows.

this may prevent testing bar() won't able phone call real init_foo() in other tests ; unless utilize dlsym() invoke own init_foo(), instance when global variable set.

c unit-testing linker

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -