3
votes

I was thinking of if there is any framework/library which provides a mechanism to test the functions which are not exported by the shared library.

I want to test working of functions listed in "t" section of shared library. For testing functions in "T" section i'hv used cppunit.

Test scenario: There is a class exported using "__attribute__ ((visibility("default")))" which declares a variable of another class which is having "__attribute__ ((visibility("hidden")))" which is defined in the same library. I want to test the class with "__attribute__ ((visibility("hidden")))" attributes.

Programming language of library is c++

compiler gcc 4.1.2

platform RedHat/Solaris

2

2 Answers

2
votes

If you want to test those functions using the same binary file which you are shipping, I know just one practical solution: build some kind of maintenance hatch into your libary.

That means, add some publicly exported functions into the lib which call the internal functions you want to test. Use names for that functions making clear these are only for testing purposes, they should be not used by the "normal user" of the lib. Keep the documentation of that methods internal to make it really hard for outsiders to use them. Add a clear warning to the official docs that, for example, all methods starting with the prefix "TEST_" are not to be used by the normal user and are subject to change with every release.

And if someone is so ignorant to use that methods either, just don't care - you cannot prevent such people from shooting themselves into the foot.

5
votes

As unit-tests are supposed to have intimate knowledge of the code they test, unit-tests can also employ tricks that are not available to the normal users of a piece of code.

Possible tricks to employ here are:

  • Ensure the unit-tests and the code-under-test are linked as a single executable, without building the code-under-test in a library first.
  • Use a pre-processor macro to disable the visibility attributes when building for the unit-tests.