[Cppunit-devel] Is this a bug?
Brought to you by:
blep
From: Sungmin C. <sm...@so...> - 2002-12-04 02:45:52
|
Hi, thank you for the effots for making such a good program as CppUnit! I tried to use the bug reporting system, but I'm not sure that it is a bug or not so I email you directly. I tried to use 1.8.0. 1. I tested with the STL complex Strangely enough, it seems that the test works only if I insert a magic code in the main function. int main( int argc, char **argv) { // Strangely, there should a code like this //////////////////////////////////////////////////////////////////////// //////////////////// Complex x; //////////////////////////////////////////////////////////////////////// //////////////////// 2. When I replace the Complex class by the following code, it works. class Complex { friend bool operator ==(const Complex& a, const Complex& b); friend Complex operator +(const Complex& a, const Complex& b); double real, imaginary; public: Complex( double r, double i = 0 ) : real(r) , imaginary(i) {} }; bool operator ==( const Complex &a, const Complex &b ) { return (a.real == b.real) && (a.imaginary == b.imaginary); } Complex operator +( const Complex &a, const Complex &b ) { return Complex(a.real + b.real, a.imaginary + b.imaginary); } 3. Is it a bug or is there anything I made a mistake? Followings are the full source code and I compiled g++ main.cpp -o main -lcppunit Thank you in advance and looking forward to your answer. With best regards. Sungmin Cho. softDSP Co., Ltd. //////////////////////////////////////////////////////////////////////// ////// // source code (mainly from CookBook and CppWiki) //////////////////////////////////////////////////////////////////////// ////// #include <memory> #include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/ui/text/TestRunner.h> #include <cppunit/CompilerOutputter.h> #include <cppunit/TestCase.h> #include <cppunit/extensions/HelperMacros.h> #include <complex.h> typedef complex<int> Complex; class ComplexNumberTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( ComplexNumberTest ); CPPUNIT_TEST( testEquality ); CPPUNIT_TEST( testAddition ); CPPUNIT_TEST_SUITE_END(); 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_NAMED_REGISTRATION( ComplexNumberTest, "ComplexNumberTest" ); CppUnit::Test *suite() { CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); registry.registerFactory( &CppUnit::TestFactoryRegistry::getRegistry( "ComplexNumberTest" ) ); return registry.makeTest(); } int main( int argc, char **argv) { // Strangely, there should a code like this?? //////////////////////////////////////////////////////////////////////// //////////////////// Complex x; //////////////////////////////////////////////////////////////////////// //////////////////// // if command line contains "-selftest" then this is the post build check // => the output must be in the compiler error format. bool selfTest = (argc > 1) && (std::string("-selftest") == argv[1]); CppUnit::TextUi::TestRunner runner; runner.addTest( suite() ); // Add the top suite to the test runner if ( selfTest ) { // Change the default outputter to a compiler error format outputter // The test runner owns the new outputter. runner.setOutputter( CppUnit::CompilerOutputter::defaultOutputter( &runner.result(), std::cerr ) ); } // Run the test. bool wasSucessful = runner.run("",false); // Return error code 1 if the one off test failed. return wasSucessful ? 0 : 1; } |