Menu

Help: get Complex to link w/vc6 & cppunit

Lynn Allan
2002-04-17
2002-04-18
  • Lynn Allan

    Lynn Allan - 2002-04-17

    Help: get Complex to link w/vc6 & cppunit

    I'm trying to get a simple program 'knitted' together so it compiles/links with VC 6.0.  I have a class, Complex, this is generally from the cppunit cookbook with annoying/frustrating compiler errors cleared up. I'd like to take 'baby steps' to begin using cppunit rather than staring at the huge examples.dsw project.

    I'm getting unresolved link errors with the code below.  I tried matching the multithreaded libraries, but that doesn't help.

    I'll acknowledge the very real possibility that I'm incompetent, but I'm baffled why cppunit is so much harder to learn that it seems like it should be.  Where is a "hello, world" program?

    #include "stdafx.h"
    #include <cppunit/TestCase.h>
    #include <cppunit/extensions/HelperMacros.h>
    #include <cppunit/extensions/TestFactoryRegistry.h>
    #include <cppunit/ui/text/TestRunner.h>

    class Complex {
    public:
      Complex( double r, double i = 0 ) : real(r), imag(i)
      {
      }
      bool operator ==(const Complex& other);
      Complex operator +(const Complex& other);
      void Add(const Complex& other);

    private:
      double real;
      double imag;

    };

    bool Complex::operator ==( const Complex &other )
    {
      return (real == other.real )  &&  ( imag == other.imag );
    }

    Complex Complex::operator +( const Complex &other )
    {
      Complex result(real + other.real, imag + other.imag);
      return result;
    }

    void Complex::Add( const Complex &other )
    {
      real += other.real;
      imag += other.imag;
    }

    class ComplexNumberTest : public CppUnit::TestCase  {
    CPPUNIT_TEST_SUITE( ComplexNumberTest );
    CPPUNIT_TEST( testEquality );
    CPPUNIT_TEST( testAddition );
    CPPUNIT_TEST_SUITE_END();

    private:
      Complex *m_10_1, *m_1_1, *m_11_2;

    public:
      void setUp()
      {
        m_10_1 = new Complex( 10, 1 );
        m_1_1 =  new Complex( 1, 1 );
        m_11_2 = new Complex( 11, 2 ); 
      }

      void tearDown()
      {
        delete m_10_1;
        delete m_1_1;
        delete m_11_2;
      }

      void testEquality()
      {
        CPPUNIT_ASSERT( *m_10_1 == *m_10_1 );
        CPPUNIT_ASSERT( !(*m_10_1 == *m_11_2) );
      }

      void testAddition()
      {
        CPPUNIT_ASSERT( *m_10_1 + *m_1_1 == *m_11_2 );
      }
    };
    CPPUNIT_TEST_SUITE_REGISTRATION( ComplexNumberTest );

    int main( int argc, char **argv)
    {
      CppUnit::TextUi::TestRunner runner;
      CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
      runner.addTest( registry.makeTest() );
      bool wasSucessful = runner.run( "", false );
      return wasSucessful;
      return 0;
    }

     
    • Baptiste Lepilleur

      Are you linking the correct library (cppunitd.lib for debug, cppunit.lib for release).

      I added a simple example in example/simple.

      You can get it with the CVS tree browser (on the cvs tab of this page).

      Baptiste.

       
    • Lynn Allan

      Lynn Allan - 2002-04-18

      Baptiste,

      Thanks for the prompt reply ... however, I'm still baffled.

      - I had to get a fresher version of XmlOutter.h to get the 'simple' code to compile.  It didn't like:
      xml.setStyleSheet( "report.xsl" );

      - I had to get BriefTestProgressListener.h to get the code to compile.  This file is not included with the source distribution, as near as I can tell.

      - The code was in examples/simple (instead of example/simple)

      - There were enough pieces missing or obsolete, that I suspect I didn't get the correct .h files, or put them in the correct subdirectory.

      I'm referencing cppunit.lib for Release, cppunitd.lib for debug.  Plus the equivalent testrunner<d>.lib

      Still getting similar unresolved link errors.

      In any case, ExampleTestCase doesn't illustrate much of what I'm interested in.  I'd like to have a class, such as Complex, and see how to 'knit' the corresponding ComplexTestCase.  ExampleTestCase doesn't resemble an actual class template, which would be very useful.

      Still, I can see the value of having a 'do-nothing' class to get it to compile and link. 

      The 'cookbook' sample code seems out-of-date and buggy, but would be a helpful to get a compilable/linkable version of something like that.

      Again, thanks, and hope to get an update to this. I really liked using junit.

       

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.