Thread: boost::test Libraries

  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446

    boost::test Libraries

    I confess I'm a little afraid of going back to boost bug reports and regression tests pages. I get lost in there very easily and can't make most of the information given. It's my fault, I know. But until I get more knowledgeable about these things, they will keep giving me an headache.

    So, in hoping someone here uses Boost::Test, and uses it under MinGW 3.4.5, I need to know if you are experiencing the same problem as I am...

    Library: libboost_unit_test_framework-mgw34-1_34 (static and DLL, debug and release)

    Linking my tests with the release static library or with the release DLL gives me an Access Violation at runtime. Only with the debug versions of these libraries can I make my tests work.

    (2)
    In fact, even with the debug version, some tests end up also originating Access Violations at runtime. This is a typical example:

    Code:
    #include <boost/test/unit_test.hpp>
    using namespace boost::unit_test;
    
    void free_test_function()
    {
        BOOST_CHECK(2 == 1);
    
        int* p = (int*)0;
        BOOST_CHECK( *p == 0 ); // Access violation here
    }
    
    test_suite* init_unit_test_suite( int, char* [] ) {
        framework::master_test_suite().p_name.value = "Unit test example 02";
    
        framework::master_test_suite().add( BOOST_TEST_CASE( &free_test_function ), 2 );
    
        return 0;
    }

    If you are just passing by this thread , naturally an Access Violation is expected. However, BOOST_CHECK has the capability of catching that.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Mario F. View Post

    If you are just passing by this thread , naturally an Access Violation is expected. However, BOOST_CHECK has the capability of catching that.
    Are you sure about that? I know it can catch an exception, but an access violation? Surely that would cause undefined behaviour, and the program will fall over.

    I don't see why you would test for such a case anyway.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    The test is merely indicative of its ability to catch system level errors. It was actually taken from one of the library example files. I believe a more useful usage would be to actually test bad memory access as part of the unit testing.

    The expected behavior is:
    // reports 'unknown location(0): fatal error in "free_test_function": memory access violation
    // d:\source code\boost\libs\test\example\unit_test_example_02. cpp(25): last checkpoint'
    After which, the test application does exit abruptly with a boost::exit_exception_failure code which is the code associated with uncaught exceptions and fatal errors.

    Naturally this is my interpretation of the documentation and it may be flawed.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    ok, I've had a look into this.
    compiling the attached file initially, I get the same runtime access violation.

    Having a quick scout around the web, I found this page.

    When I set the /EHa option it works as expected. I don't have mingw, but from a look at the g++ docs I'd say you could try the -fnon-call-exceptions switch.

    HTH.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Chaos! Thanks a bunch mate!

    It didn't work with that switch but I think I can take it from here. You pointed me in the right direction. I'll investigate further.

    In the end, if this is a problem with mingw, there's always the possibility of compiling my unit tests on VS since they are completely separate from the main project.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GCC: Compiling with both static and shared libraries
    By eatwithaspork in forum C Programming
    Replies: 4
    Last Post: 06-23-2008, 01:48 PM
  2. Replies: 7
    Last Post: 05-13-2008, 03:47 AM
  3. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  4. Libraries and headers
    By darksaidin in forum C++ Programming
    Replies: 10
    Last Post: 07-23-2003, 06:24 AM
  5. QT and external libraries
    By Quacker in forum Linux Programming
    Replies: 1
    Last Post: 04-08-2003, 07:02 AM