Thread: Why does CppUnit give me seg faults?

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545

    Why does CppUnit give me seg faults?

    I've narrowed the seg fault down to 3 lines of code that I've commented out below. If I uncomment any of these lines I get a seg fault.
    Code:
    int main( int argc, char* argv[] )
    {
    	if ( argc != 3 )
    	{
    		std::cerr << "Usage: sample <host> <port>" << std::endl;
    		return 1;
    	}
    
    	/// Create a new TestSuite & add the sample test.
    	CppUnit::TestSuite testSuite( "Sample Test" );
    	SampleTest sampleTest( argv[1], argv[2] );
    //	testSuite.addTest( &sampleTest );
    
    	/// Adds the test to the list of test to run
    	CppUnit::TextUi::TestRunner runner;
    	CppUnit::XmlOutputter xmlOutput( &runner.result(), std::cerr );
    //	runner.setOutputter( &xmlOutput );
    //	runner.addTest( &testSuite );
    	runner.run();
    
    	return 0;
    }
    This is the first time I've tried using CppUnit, so I'm probably not using it right...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    According to an example from their cookbook, CppUnit::TestSuite::addTest takes a pointer to a dynamically allocated test object.

    EDIT:
    Yeah, considering that there is a TestSuite::deleteContents member function that destroys all the tests in the suite, passing a pointer to a stack allocated object would be wrong.
    Last edited by laserlight; 01-23-2009 at 10:44 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    OK, I thought it might be something like that, but the CppUnit documentation really sucks. It would certainly be nice if they told you who is responsible for deleting pointers...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    17

    Want to know the usage of cppunit library

    Quote Originally Posted by laserlight View Post
    According to an example from their cookbook, CppUnit::TestSuite::addTest takes a pointer to a dynamically allocated test object.

    EDIT:
    Yeah, considering that there is a TestSuite::deleteContents member function that destroys all the tests in the suite, passing a pointer to a stack allocated object would be wrong.
    Hi Laser,
    I want to use CPPUNIT for C programming unit testing? where i will get complete information about its usage? i am completely new to this kind of stuff.

    Thanks in advance for your help.

    Regards,
    Siddu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg faults. structs. pointers.
    By ominub in forum C Programming
    Replies: 12
    Last Post: 05-03-2009, 07:04 PM
  2. Getting a seg fault
    By ammochck21 in forum C Programming
    Replies: 11
    Last Post: 01-23-2009, 05:27 AM
  3. Seg Faults at Random
    By mrpickle in forum C Programming
    Replies: 5
    Last Post: 01-15-2004, 03:42 PM
  4. Radiohead rule
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-18-2002, 07:37 PM