Menu

Trying to use CppUnit with VC++ .Net

Help
DaveW
2006-08-09
2013-04-22
  • DaveW

    DaveW - 2006-08-09

    I'm trying to use CppUnit to set up some unit tests on a project at work, and I'm running into some questions about the best way to set up these little test projects.  I'm relatively new to C++ and Microsoft VC++ .Net, though I've used VC++ 6.0 extensively for a number of C-based projects in the past.  I've worked through the Money sample project, and looked at some of the others.

    Right now, I'm trying to set up some tests for a linear equation class that's part of our MathProg static library.  I've set up TestLinearEquation as a separate (console app) project under the MathProg directory.  I've taken two approaches to organizing the project: 1) Make TestLinearEquation a project with a dependancy on MathProg, so it links with the production MathProg.lib after the latter is built, or 2) include ../linearequation.h and ../linearequation.cpp directly in TestLinearEquation, with the intent of building it stand alone.

    Of these two approaches, #1 works with some simple constructor tests, but gives me a lot of linkage errors about duplicate objects as soon as I try to output a LinearEquation to std::cout from within my test program (presumbably the first time I am accessing stuff in the .cpp file instead of just stuff defined in the .h file).  E.g.,
    msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in MathProg.lib(linearequation.obj)

    Approach #2 currently gives me an unresolved external symbol on a protected static variable of the LinearEquation class (which is just a base class that doesn't inherit from any other class).  This is just with the constructor tests that work under approach #1:

    linearequation.obj : error LNK2001: unresolved external symbol "protected: static double LinearEquation::iZeroEntryTolerance" (?iZeroEntryTolerance@LinearEquation@@1NA)

    Any comments about the best way to organize these unit test projects in general?  Also, any specific suggestions about resolving the above problems  would be much appreciated.

     
    • DaveW

      DaveW - 2006-08-15

      Followup: I figured out the problem with Approach #2.  The protected static variables of a whole bunch of classes were being initialized together in a different file (I didn't write this code, I'm just trying to work with it).  Moving the initialization into linearequation.cpp fixed the problem.  So for now, I'm moving ahead with approach #2.

       

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.