Why does CppUnit give me seg faults?

This is a discussion on Why does CppUnit give me seg faults? within the C++ Programming forums, part of the General Programming Boards category; I've narrowed the seg fault down to 3 lines of code that I've commented out below. If I uncomment any ...

  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
    21,390
    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 09:44 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 04:27 AM
  3. Seg Faults at Random
    By mrpickle in forum C Programming
    Replies: 5
    Last Post: 01-15-2004, 02:42 PM
  4. Radiohead rule
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-18-2002, 06:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21