[Boost] [Test] [1.38] "can't use testing tools before framework is initialized"

Hi, I am trying to integrate boost.test into an existing test program with its own framework. Therefore I'd like to use that program's main. I am currently running into this runtime error when calling BOOST_WARN_MESSAGE(1, "string"). I have tried three different things to avoid this condition: 1) I declared a TEST_SUITE using the BOOST_AUTO_TEST_SUITE() and END() macros. Probably not what I want because I want my own main to keep control, but figured it would generate a main that would allow the initialization to happen. 2) I called init_unit_test_suite( argc, argv ). Even though it was called, I am still getting this. 3) I defined a cpp_main(). This never got called. I was hoping that the existence of this symbol would cause initialization to happen elsewhere. My desired control flow is to have this test program in control and to use the BOOST logging tools. I am trying to slip in boost.test with a minimum of changes to this program. I have hooked its logging function to call boost logging facilities instead; just can't get past this problem. Thanks for any help! Greg

Greg Christopher wrote:
Hi, I am trying to integrate boost.test into an existing test program with its own framework. Therefore I'd like to use that program's main.
Simplest way to get this is to use dynamic variant of UTF.
I am currently running into this runtime error when calling BOOST_WARN_MESSAGE(1, "string"). I have tried three different things to avoid this condition:
Where do you call it from? The error indicate exactly what the problem is.
1) I declared a TEST_SUITE using the BOOST_AUTO_TEST_SUITE() and END() macros. Probably not what I want because I want my own main to keep control, but figured it would generate a main that would allow the initialization to happen.
This has nothing to do with main. You can use auto registration tools and have your own main.
2) I called init_unit_test_suite( argc, argv ). Even though it was called, I am still getting this.
You are not supposed to call this function manually.
3) I defined a cpp_main(). This never got called. I was hoping that the existence of this symbol would cause initialization to happen elsewhere.
Wow, you adventurous. I recommend reading docs first.
My desired control flow is to have this test program in control and to use the BOOST logging tools. I am trying to slip in boost.test with a minimum of changes to this program. I have hooked its logging function to call boost logging facilities instead; just can't get past this problem.
1. Here is an example that defines main: http://tinyurl.com/qmve47. This example does not use automated tools, but it might as well. 2. You may not need main. You can do your initialization either in global fixture in in test suite initialization function (like in example above) HTH, Gennadiy

________________________________________ From: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] On Behalf Of Gennadiy Rozental [rogeeff@gmail.com] Sent: Sunday, May 17, 2009 3:23 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [Boost] [Test] [1.38] "can't use testing tools before framework is initialized" Greg Christopher wrote:
Hi, I am trying to integrate boost.test into an existing test program with its own framework. Therefore I'd like to use that program's main.
Simplest way to get this is to use dynamic variant of UTF.
I am currently running into this runtime error when calling BOOST_WARN_MESSAGE(1, "string"). I have tried three different things to avoid this condition:
Where do you call it from? The error indicate exactly what the problem is. Greg>This was called from a function that is called from WinMain in this application.
1) I declared a TEST_SUITE using the BOOST_AUTO_TEST_SUITE() and END() macros. Probably not what I want because I want my own main to keep control, but figured it would generate a main that would allow the initialization to happen.
This has nothing to do with main. You can use auto registration tools and have your own main.
2) I called init_unit_test_suite( argc, argv ). Even though it was called, I am still getting this.
You are not supposed to call this function manually. Sorry- I misread that document. If anything, I should implement it.
3) I defined a cpp_main(). This never got called. I was hoping that the existence of this symbol would cause initialization to happen elsewhere.
Wow, you adventurous. I recommend reading docs first. Greg>For instance, this page? http://www.boost.org/doc/libs/1_39_0/libs/test/doc/html/prg-exec-monitor.htm... I didn't dream up cpp_main(); the docs lead me to believe it would be called by the framework. In the situation where it would be called, initialization would happen first- at least my understanding.
My desired control flow is to have this test program in control and to use the BOOST logging tools. I am trying to slip in boost.test with a minimum of changes to this program. I have hooked its logging function to call boost logging facilities instead; just can't get past this problem.
1. Here is an example that defines main: http://tinyurl.com/qmve47. This example does not use automated tools, but it might as well. Greg> Thanks- looks like as long as I get the test framework to call us, we'll be ok. -Greg

AMDG Greg Christopher wrote:
3) I defined a cpp_main(). This never got called. I was hoping that the existence of this symbol would cause initialization to happen elsewhere.
Wow, you adventurous. I recommend reading docs first.
Greg>For instance, this page? http://www.boost.org/doc/libs/1_39_0/libs/test/doc/html/prg-exec-monitor.htm...
I didn't dream up cpp_main(); the docs lead me to believe it would be called by the framework. In the situation where it would be called, initialization would happen first- at least my understanding.
The program execution monitor is a separate component. In Christ, Steven Watanabe

My desired control flow is to have this test program in control
and to use the BOOST logging tools. I am trying to slip in boost.test with a minimum of changes to this program. I have hooked its logging function to call boost logging facilities instead; just can't get past this problem.
1. Here is an example that defines main: http://tinyurl.com/qmve47. This example does not use automated tools, but it might as well.
2. You may not need main. You can do your initialization either in global fixture in in test suite initialization function (like in example above)
Thanks for the great tip- I have organized the program to work this way. The sample code doesn't quite work, I had to cast the initialization function that is passed into unit_test_main (boost::unit_test::init_unit_test_func) .. I did that and I got pretty far but there is a strange runtime error that happens here: test_unit& get( test_unit_id id, test_unit_type t ) { test_unit* res = s_frk_impl().m_test_units[id]; if( (res->p_type & t) == 0 ) throw internal_error( "Invalid test unit type" ); return *res; } The test case I added was simpler and had no parameters to pass: framework::master_test_suite().add( BOOST_TEST_CASE(TestMain) ); That happens successfully but the main test program never gets called and execution stops at the location above. I saw this link: http://lists.boost.org/Archives/boost/2006/03/102592.php Looks like I do need to autoregister a test suite first? I tried registering one with no luck. Thanks for all your help! Greg

2. You may not need main. You can do your initialization either in global fixture or in test suite initialization function (like in example above)
Thanks for the great tip- I have organized the program to work this way. The sample code doesn't quite work, I had to cast the initialization function that is passed into unit_test_main (boost::unit_test::init_unit_test_func).
Cast to what? init function has right signature.
I did that and I got pretty far but there is a strange runtime error that happens here:
test_unit& get( test_unit_id id, test_unit_type t ) { test_unit* res = s_frk_impl().m_test_units[id];
if( (res->p_type & t) == 0 ) throw internal_error( "Invalid test unit type" );
return *res; }
What the error message?
The test case I added was simpler and had no parameters to pass:
framework::master_test_suite().add( BOOST_TEST_CASE(TestMain) );
Please post simple example. I do not follow what is your problem. By the way what version of Boost r u using?
That happens successfully but the main test program never gets called and execution stops at the location above.
I saw this link: http://lists.boost.org/Archives/boost/2006/03/102592.php
This issue fixed since. And it was just an issue with proper error report.
Looks like I do need to autoregister a test suite first? I tried registering one with no luck.
No you don't. Gennadiy

2. You may not need main. You can do your initialization either in global fixture or in test suite initialization function (like in example above)
Thanks for the great tip- I have organized the program to work this way. The sample code doesn't quite work, I had to cast the initialization function that is passed into unit_test_main (boost::unit_test::init_unit_test_func).
Cast to what? init function has right signature. Greg > The cast is right above you. Yes the signature matched- bool return; void arguments. But VS2008 still complained that I could not pass that into unit_test_main. The cast worked fine, the function got called no problem.
I did that and I got pretty far but there is a strange runtime error that happens here:
test_unit& get( test_unit_id id, test_unit_type t ) { test_unit* res = s_frk_impl().m_test_units[id];
if( (res->p_type & t) == 0 ) throw internal_error( "Invalid test unit type" );
return *res; }
What the error message? Greg> "Invalid test unit type" . ?! Since I was debugging the program, it stopped on the exception. If I just let it run, that's pretty much the error message. What does that message mean? Somewhere else I saw on the net that it could mean there is no test suite defined but I am hoping I don't need to do that.
The test case I added was simpler and had no parameters to pass:
framework::master_test_suite().add( BOOST_TEST_CASE(TestMain) );
Please post simple example. I do not follow what is your problem. By the way what version of Boost r u using? Greg > 1.38 as the subject says. TestMain is simply a function that returns an int and gets passed a void. I trust the above line is the correct way to add such a function?
That happens successfully but the main test program never gets called and execution stops at the location above.
I saw this link: http://lists.boost.org/Archives/boost/2006/03/102592.php
This issue fixed since. And it was just an issue with proper error report.
Looks like I do need to autoregister a test suite first? I tried registering one with no luck.
No you don't. Greg> good. To summarize: -The framework is throwing saying "Invalid unit test type" -I am not defining suites or test cases other than the code you've seen which manually adds them using master_test_suite.add() -Boost is 1.38 Since I haven't really defined a unit test other than to pass a function, maybe there is some step I need to take? Greg

________________________________________ From: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] On Behalf Of Gennadiy Rozental [rogeeff@gmail.com] Sent: Monday, May 18, 2009 6:21 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [Boost] [Test] [1.38] "can't use testing tools before framework is initialized"
2. You may not need main. You can do your initialization either in global fixture or in test suite initialization function (like in example above)
Thanks for the great tip- I have organized the program to work this way. The sample code doesn't quite work, I had to cast the initialization function that is passed into unit_test_main (boost::unit_test::init_unit_test_func).
Cast to what? init function has right signature.
I did that and I got pretty far but there is a strange runtime error that happens here:
test_unit& get( test_unit_id id, test_unit_type t ) { test_unit* res = s_frk_impl().m_test_units[id];
if( (res->p_type & t) == 0 ) throw internal_error( "Invalid test unit type" );
return *res; }
What the error message?
The test case I added was simpler and had no parameters to pass:
framework::master_test_suite().add( BOOST_TEST_CASE(TestMain) );
Please post simple example. I do not follow what is your problem. Greg>Here is sample code that reproduces the problem: Greg> http://pastebin.com/f58f7694e Thanks, Greg

FYI- still looking for help on this execution issue- sample code is posted as requested:
Please post simple example. I do not follow what is your problem.
Greg>Here is sample code that reproduces the problem:
Greg> http://pastebin.com/f58f7694e
Thanks, Greg

Greg Christopher wrote:
FYI- still looking for help on this execution issue- sample code is posted as requested:
I've checked in 3 different examples of external function main usage
into examples directory. Here is one:
#ifndef BOOST_TEST_DYN_LINK
#define BOOST_TEST_DYN_LINK
#endif
#include
participants (3)
-
Gennadiy Rozental
-
Greg Christopher
-
Steven Watanabe