18

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/

Community
  • 1
  • 1
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • 1
    Are you trying to link to a 3rd party dll? Because if so you can easily generate a .lib for linking and then you can use a tool to get classes/functions assuming the dll was compiled with C++ name mangling. – user230821 Jan 07 '10 at 13:32
  • 3
    And the dolphins don't have any issues with this? (sorry, couldn't pass over the *porpoises*). – Tarydon Jan 07 '10 at 13:32
  • 1
    +1 I make otter little "mistakes" too ;-) – Mawg says reinstate Monica Feb 17 '11 at 02:19
  • An apt quote: `The Mock Turtle said: 'no wise fish would go anywhere without a porpoise'` (from *Alice's Adventures in Wonderland*, of course). – dbn Dec 20 '12 at 04:14

5 Answers5

7

I think stubgen may be what you're after.

Dushara
  • 616
  • 1
  • 5
  • 25
4

Here is a solution with perl and vim http://www.vim.org/scripts/script.php?script_id=213 it uses ctags, and if one can easily remove the vim need if desired by using the included perl script.

Batz
  • 41
  • 1
3

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.

knight666
  • 1,599
  • 3
  • 22
  • 38
3

Maybe Lzz does what you want.

swegi
  • 4,046
  • 1
  • 26
  • 45
  • maybe it does. It generates header (and source), but I want to feed it headers. If it does not choke on headers as input, I can ignore its generated headers and just use the generated source. I will give it a try & get back to you. – Mawg says reinstate Monica Jan 09 '10 at 08:30
1

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.

albert
  • 8,285
  • 3
  • 19
  • 32
Florian
  • 1,725
  • 3
  • 14
  • 13
  • Hi @albert. "Analysing" [is not a misspelling](https://dictionary.cambridge.org/dictionary/english/analysing). Thanks! – Lightness Races in Orbit Dec 24 '18 at 15:48
  • @LightnessRacesinOrbit depends on English or US-English (and as far as I know the language, mostly, used on stackoverflow us US-English) – albert Dec 24 '18 at 15:50
  • @albert [We don't "correct" English to American English](https://meta.stackoverflow.com/a/252504/560648) as both are valid. Thanks! – Lightness Races in Orbit Dec 24 '18 at 16:18
  • @LightnessRacesinOrbit thanks for the link. (My spelling corrector showed it when I was correcting the fact that the place of the doxygen documentation.) – albert Dec 24 '18 at 16:23