First: What is an opaque pointer in C?
Now when it comes to testing such a type, I know of 3 ways:
-
Include the source file (the one containing the definition of the type and the functions that work with it) directory into the test source file. (This is the easiest, but often discouraged without presenting any rationale).
-
Make public accessors that are conditionally available (i.e. only if if
LIB_TEST
is defined before including its header). -
Make a separate “lib-test.h” header file that contains the public accessors.
The last two avoid making the accessors part of the public API (we’re speaking of the case where the clients have no business knowing anything about the opaque type’s internals, and shouldn’t be provided with any accessors).
What is the usual approach (or the good approach) in C? Does one way have more upsides/downsides than the other?
1