Menu

CppUnit and C code

Help
2006-10-17
2013-04-22
  • ovtchinnikov

    ovtchinnikov - 2006-10-17

    While quickly studying CppUnit for the needs of my project I did not notice any obstacles for using it with C code as well as Cpp code.

    Is it fully suitable for C code in your opinion, or shall I look at the CUnit and the like?

     
    • Code Guru

      Code Guru - 2006-10-17

      If you are using a C++ compiler for your "C code", you should be fine.  However, if you are using a true C compiler, you might have issues since CppUnit uses classes.  It's been a while since I used a real C compiler, so I'm not sure whether the linker will complain or not.

      I suggest that You make an simple function and tests for it to see what happens.

       
    • John Pye

      John Pye - 2007-05-12

      I expect that the C 'purists' out there would think that this was a quite a bad thing.

      I'd suggest that it's perhaps not so bad, but you should try to set things up so that your tested code is compiled by a pure C compiler, perhaps as a shared library, so that the only way a C++ compiler gets near your code is via #includes and via the linker. This will ensure you don't get any C++-isms creeping in to your C code.

      Another option would be to add simple SWIG bindigs to your code and using something like Python to test it. Given the amount of time you spend waiting for a compiler while writing test code, this can possibly be a good thing. I'm sure it depends on the type of code you're testing: the nature of your data structures and API and so on.

      Cheers
      JP

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.