Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost unit testing main function?

How do I define my own main() function when testing with boost?

Boost is using it's own main function, but I'm using a custom memory manager and it needs to be initialized before any memory is allocated, otherwise I'll get errors.

like image 933
NomenNescio Avatar asked Sep 21 '12 11:09

NomenNescio


2 Answers

I do not believe you actually need your own main. I think you are much better off with global fixture:

struct AllocatorSetup {
    AllocatorSetup()   { /* setup your allocator here */ }
    ~AllocatorSetup()  { /* shutdown your allocator/check memory leaks here */ }
};

BOOST_GLOBAL_FIXTURE( AllocatorSetup );
like image 175
Gennadiy Rozental Avatar answered Oct 26 '22 09:10

Gennadiy Rozental


You have to define

BOOST_TEST_NO_MAIN

before the boost includes.

BOOST_TEST_MAIN

is the default. http://www.boost.org/doc/libs/1_36_0/libs/test/doc/html/utf/compilation.html

like image 26
NomenNescio Avatar answered Oct 26 '22 09:10

NomenNescio