[Cppunit-devel] Re: Autoreg & the linker
Brought to you by:
blep
From: Arlo B. <arl...@ho...> - 2001-12-08 00:31:21
|
I was looking over the forums, in search of others seeing similar issues to what I'm seeing (didn't find any). I saw this thread and figured I'd respond, as I ran into it myself last month and solved it adequately. I use a two part solution. First, for dynamic libraries: I use a method very similar to a standard plugin. Define some function that your company will always use to to export unit tests. Bundle each set of unit tests with the link unit that contains the things they are testing. Use the auto-registration features to make them register themselves within that link unit. Now just have the standard export function look at the library's internal registry & get the tests, and return them. Then, you simply have your main executable walk the directory(s) in which you place these files (I build the whole series of projects with a common "unit testing" directory into which all output files are placed). Dynamically load each dll found, and attempt to dynamically find the export function. If you fail to find the export function, then this module doesn't have tests, so you can unload it. Otherwise, keep it around. Once you've walked the entire directory tree & loaded all the libraries with tests, you run the test runner and let the user select what he wants to test (this also has the advantage of automagically setting up the test tree such that one level contains the filenames for each linking unit, and selecting one runs all tests in that unit only). After tests are done, the libraries are dynamically unloaded. Static link libraries can't be handled in this fashion. However, I find it perfectly palatable for the module that uses a static link library to know that it is. Thus, I simply place all of my autoregistrations for a static link library into their own file (not inline in the CPP for that one test). Then, I add this cpp to the project for any project that uses the static link library. Now, those tests will be added to the auto-register tests for the main project. In my case, the using project is another DLL, which exports the tests using the above method. If anyone is interested, I can send source. It's about 5 files, so I'll not send them unless there's interest. Arlo |