module stub generator for testing?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco

    #1

    module stub generator for testing?

    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.mod erated - moderation address: clcm@plethora.n et -- 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

    #2
    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.mod erated - moderation address: clcm@plethora.n et -- 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.

    Comment

    • Chuck F.

      #3
      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.
      This is my sixth column for Wired.com: It’s a David and Goliath story of the tech blogs defeating a mega-corporation. On Oct. 31, Mark Russinovich broke the story in his blog: Sony BMG Music Entertainment distributed a copy-protection scheme with music CDs that secretly installed a rootkit on computers. This software tool is run without your knowledge or consent—if it’s loaded on your computer with a CD, a hacker can gain and maintain access to your system and you wouldn’t know it. The Sony code modifies Windows so you can’t tell it’s there, a process called “cloaking” in the hacker world. It acts as spyware, surreptitiously sending information about you to Sony. And it can’t be removed; trying to get rid of it ...

      --
      comp.lang.c.mod erated - moderation address: clcm@plethora.n et -- 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.

      Comment

      • Malcolm

        #4
        Re: module stub generator for testing?

        "Marco" <prenom_nomus@y ahoo.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.mod erated - moderation address: clcm@plethora.n et -- 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.

        Comment

        • Michael Tiomkin

          #5
          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 TemporaryUglyCl ass {
          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: TemporaryUglyCl ass::" string to :Function: " string and
          removes all other "TemporaryUglyC lass::" 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.mod erated - moderation address: clcm@plethora.n et -- 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.

          Comment

          • Nick C

            #6
            Re: module stub generator for testing?

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

            "Marco" <prenom_nomus@y ahoo.com> wrote in message
            news:clcm-20051213-0023@plethora.n et...[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.mod erated - moderation address: clcm@plethora.n et -- 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.mod erated - moderation address: clcm@plethora.n et -- 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.

            Comment

            • Rahul Chandok

              #7
              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.mod erated - moderation address: clcm@plethora.n et -- 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.

              Comment

              • Francis Glassborow

                #8
                Re: module stub generator for testing?

                In message <clcm-20060109-0027@plethora.n et>, Rahul Chandok
                <chandok.r@gmai l.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.mod erated - moderation address: clcm@plethora.n et -- 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.

                Comment

                Working...