The main function of testing the gain module?

How to define own main() function when testing with boost?

Boost uses its own main function, but I use my own memory manager, and it must be initialized before any memory is allocated, otherwise I will get errors.

+8
c ++ boost unit-testing
source share
4 answers

I do not believe that you really need your main. I think you are much better off with global mounts :

 struct AllocatorSetup { AllocatorSetup() { /* setup your allocator here */ } ~AllocatorSetup() { /* shutdown your allocator/check memory leaks here */ } }; BOOST_GLOBAL_FIXTURE( AllocatorSetup ); 
+11
source share

You must identify

BOOST_TEST_NO_MAIN

before turning on boost.

BOOST_TEST_MAIN

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

+8
source share

You can define a static object, and its constructor will execute before main:

 class Alloc_Setup { Alloc_Setup() { // Your init code } ~Alloc_Setup() { // Your cleanup } }; Alloc_Setup setup; int main() {} // (generated by boost) 
0
source share

Memory can be allocated up to main :

 static int* x = new int(1); int main() { return *x; } 

And you can also make your memory manager a global variable,
but you cannot force a certain order of initialization of global variables. (at least in standard C ++)

On Windows, you can put the memory manager in a DLL and it will be initialized before the entry point of the application is called, but still something else can allocate memory earlier - another DLL or CRT of your DLL.

-one
source share

All Articles