Seeking code stub generator (from header files)

Viewed 10512

Imagine I have the header files to a subsystem, but no access to the source code.

Now I want to generate stubs to match all functions declared in the header files (for testing purposes).

I wrote some simple code to do this, but it's not perfect. Does anyone know of any freely available software which will do this?


[Update] Five years after asking, this question is still getting upvotes.

It was closed as of-topic, which it is nowadays (althoguh it was not when it was originally posted). Fortunately, we can now ask for software recommendations at https://softwarerecs.stackexchange.com/

5 Answers

Visual Assist X for Visual Studio has this functionality, although it isn't automated.

On the function

Tri ProjectTriOnPlane(Tri* a_Triangle);

And then, if the corresponding .c or .cpp is found, go to Refactor (VA X) -> Create Implementation, which will create an implementation like so:

Tri Camera::ProjectTriOnPlane( Tri* a_Triangle )
{

}

It also doesn't return something standard, that's a bit of a shame.

You can write a stub generator pretty easily using doxygen. It's not well known but it comes with a helper library that provides a very nice abstraction over the XML output (see this page).

If you look at the end of this header file, you'll see that you get nice IStructs, IClass objects, from which you can list ISections then IMembers. All very easy, and customizable to your liking.

As I doubt you'll get the exact stubs you want from a generic tool, you might be better off if you code your own using Doxygen, as all the heavy lifting of properly parsing C++ syntax is done for you.

And if your testing patterns are mainly dependent on the method parameters' type, you can probably generate full test stubs by analyzing the method's parameters and generating appropriate code.

Related