Connecting Tech Pros Worldwide Forums | Help | Site Map

module stub generator for testing?

Marco
Guest
 
Posts: n/a
#1: Dec 13 '05
I am looking for an open-source or free tool that parses a C header
file (.h) for a module and creates a .c file with the functions stubbed
out ( ideally with dummy returns for non-void). This will be used for
testing purposes.

I have googled with little success. ( for a C++ class example google
"stubgen").

Any leads would be appreciated.

thanks

Marco
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.

usenet@zevv.nl
Guest
 
Posts: n/a
#2: Jan 10 '06

re: module stub generator for testing?


> I am looking for an open-source or free tool that parses a C header[color=blue]
> file (.h) for a module and creates a .c file with the functions stubbed
> out ( ideally with dummy returns for non-void). This will be used for
> testing purposes.
>
> I have googled with little success. ( for a C++ class example google
> "stubgen").
>
> Any leads would be appreciated.[/color]

Not aware of anything that does precisely this, but it'd be trivial to
write in either C or Perl. Even in less then 2 days.


--
:wq
^X^Cy^K^X^C^C^C^C
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Chuck F.
Guest
 
Posts: n/a
#3: Jan 10 '06

re: module stub generator for testing?


Marco wrote:[color=blue]
>
> I am looking for an open-source or free tool that parses a C
> header file (.h) for a module and creates a .c file with the
> functions stubbed out ( ideally with dummy returns for
> non-void). This will be used for testing purposes.
>
> I have googled with little success. ( for a C++ class example
> google "stubgen").[/color]

C++ is off-topic here. The tool required is your editor. Simply
eliminate the macros, typedefs, etc. and append a variant of:

{
return 0;
}

to each function header. Rename the resultant file from .h to .c.
Add a line "#include <original.h>" at the head.

--
Read about the Sony stealthware that is a security leak, phones
home, and is generally illegal in most parts of the world. Also
the apparent connivance of the various security software firms.
http://www.schneier.com/blog/archive...drm_rootk.html
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Malcolm
Guest
 
Posts: n/a
#4: Jan 10 '06

re: module stub generator for testing?


"Marco" <prenom_nomus@yahoo.com> wrote[color=blue]
>I am looking for an open-source or free tool that parses a C header
> file (.h) for a module and creates a .c file with the functions stubbed
> out ( ideally with dummy returns for non-void). This will be used for
> testing purposes.
>
> I have googled with little success. ( for a C++ class example google
> "stubgen").
>
> Any leads would be appreciated.
>[/color]
Unfortunately it is not possible to write a general-case "stub generator".
C functions are allowed to modify values passed to them by pointers, and the
structures pointed to can be arbitrarily complex.
Also, it is permitted to call functions by indirection.
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Michael Tiomkin
Guest
 
Posts: n/a
#5: Jan 10 '06

re: module stub generator for testing?


Marco wrote:[color=blue]
> I am looking for an open-source or free tool that parses a C header
> file (.h) for a module and creates a .c file with the functions stubbed
> out ( ideally with dummy returns for non-void). This will be used for
> testing purposes.
>
> I have googled with little success. ( for a C++ class example google
> "stubgen").[/color]

I think you can cannibalize this stubgen using a couple of scripts:

1. The first script adds a line
class TemporaryUglyClass {
before the .h file, and the line
};
after the .h file. Don't change the file, just send all the stuff to
to the standard output. It's just 3 lines of awk or shell script.
2. The 2nd script reads the result of 'stubgen', changes any
"Method: TemporaryUglyClass::" string to :Function: " string and
removes all other "TemporaryUglyClass::" strings. It's also 3 lines of
awk.
3. The 3rd script runs the first script on your .h file, runs 'stubgen'
on the result of the 1st script, and runs the 2nd script on the result
of 'stubgen'. This can be one line of a shell script.
1st_scr Input_file_name | stubgen | 2nd_scr > stubs_file_name.c

Michael
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Nick C
Guest
 
Posts: n/a
#6: Jan 10 '06

re: module stub generator for testing?


I would recomment getting a perl book. This is possible in a few lines...

"Marco" <prenom_nomus@yahoo.com> wrote in message
news:clcm-20051213-0023@plethora.net...[color=blue]
>I am looking for an open-source or free tool that parses a C header
> file (.h) for a module and creates a .c file with the functions stubbed
> out ( ideally with dummy returns for non-void). This will be used for
> testing purposes.
>
> I have googled with little success. ( for a C++ class example google
> "stubgen").
>
> Any leads would be appreciated.
>
> thanks
>
> Marco
> --
> comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
> have an appropriate newsgroups line in your header for your mail to be
> seen,
> or the newsgroup name in square brackets in the subject line. Sorry.[/color]
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Rahul Chandok
Guest
 
Posts: n/a
#7: Jan 10 '06

re: module stub generator for testing?


Hi,

You can try the following logic :

1) Open your header file in Read mode.
2) Create the c stub file. (Open in write mode)
3) Read the header file line by line and search for character "(" or
")" in the line.
4) If you don't find this character then ignore the line, otherwise
write the whole line to the C file, Don't write the last character ";"
to the c file.
5) Then search for the void in the beggining of the line, if it is not
there then
write the following in the c file
"{
return 0;
}"

else
just write the following in the .c file
"{
return;
}"

HTH
Rahul
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Francis Glassborow
Guest
 
Posts: n/a
#8: Jan 25 '06

re: module stub generator for testing?


In message <clcm-20060109-0027@plethora.net>, Rahul Chandok
<chandok.r@gmail.com> writes[color=blue]
>5) Then search for the void in the beggining of the line, if it is not
>there then
>write the following in the c file
>"{
>return 0;[color=green]
>>"[/color][/color]

struct X {
int i;
int j;
} myfunc();

I think fails under your method.

--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Closed Thread


Similar C / C++ bytes