
Hello all, is there anyone, who knows the Boost Unit Testing Framework (UTF)? I am developing a project that uses wxWidgets library and I would like to test some aspects where wxWidgets stuff is involved. The problem is that wxWidgets like to implement the main() function via IMPLEMENT_APP macro and I have found quite troublesome to work around that. When one lets UTF to generate the main() function, everything is very easy. The question is: There must be some sane way how to initialize UTF and launch a testsuite when wxWidgets are ready. I also know that I should supply the framework with argc and argv since the verbosity of the test module output can be tweaked. I have learned so far that I have to implement function init_unit_test_suite( int argc, char* argv[] (but I don't have an idea how), and that I have to register test cases (that should be OK) and to create some master test suite. Am I missing something here as well? I haven't found anything in the documentation that would lead me to the result, could you help me and possibly extend the documentation a little bit so wxWidgets users could start using UTF massively? :-) Regards, Matej

Matěj Týč
Hello all, is there anyone, who knows the Boost Unit Testing Framework (UTF)?
Well, I know a bit. What version r u planning to use? Did you read latest docs?
I am developing a project that uses wxWidgets library and I would like to test some aspects where wxWidgets stuff is involved. The problem is that wxWidgets like to implement the main() function via IMPLEMENT_APP macro and I have found quite troublesome to work around that. When one lets UTF to generate the main() function, everything is very easy. The question is: There must be some sane way how to initialize UTF and launch a testsuite when wxWidgets are ready.
Yes. There is such a way.
I also know that I should supply the framework with argc and argv since the verbosity of the test module output can be tweaked. I have learned so far that I have to implement function init_unit_test_suite( int argc, char* argv[]
Not necessarily.
(but I don't have an idea how), and that I have to register test cases (that should be OK) and to create some master test suite. Am I missing something here as well?
You would usually register test units manually inside the init_unit_test_suite.
I haven't found anything in the documentation that would lead me to the result, could you help me and possibly extend the documentation a little bit so wxWidgets users could start using UTF massively?
Simplest approach is to use dynamic library variant of the UTF (http://www.boost.org/doc/libs/1_37_0/libs/test/doc/html/utf/user-guide/usage...) and follow example 9 on this page: http://www.boost.org/doc/libs/1_37_0/libs/test/doc/html/utf/user-guide/test-... There is an ability to use automated registration for test units as well if you opt to. HTH, Gennadiy
Regards, Matej

Hello, thank you for your reply, I was able to get going.
Well, I know a bit. What version r u planning to use? Did you read latest docs? I use the latest version of Boost and I also read the latest docs. I seem to be somewhat lost there, though...
Simplest approach is to use dynamic library variant of the UTF I have noticed that I don't have to pass any libraries to the compiler and everything links fine when #defining BOOST_TEST_DYN_LINK, however it takes a lot of time to compile. I am on Linux and I use autotools that pass the -lboost_unit_test_framework-mt flag to the linker. However, I still get undefined references or compilation errors when BOOST_TEST_DYN_LINK is not defined...
There is an ability to use automated registration for test units as well if you opt to. Yes, I would actually like the computer to do some work for me. I have used some BOOST_AUTO_TEST_CASE and BOOST_AUTO_TEST_SUITE macros, but I still have to supply an init function to boost::unit_test::unit_test_main, right? What is its name? I can't know that since it should be autogenerated.
Thank you for your help! Matej

Matěj Týč
Simplest approach is to use dynamic library variant of the UTF I have noticed that I don't have to pass any libraries to the compiler and everything links fine when #defining BOOST_TEST_DYN_LINK, however
I believe you still have to, isn't it?
it takes a lot of time to compile. I am on Linux and I use autotools that pass the -lboost_unit_test_framework-mt flag to the linker.
What does this lead to? I mean will it link with static or shared library?
However, I still get undefined references or compilation errors when BOOST_TEST_DYN_LINK is not defined...
Please post them.
There is an ability to use automated registration for test units as well if you opt to. Yes, I would actually like the computer to do some work for me. I have used some BOOST_AUTO_TEST_CASE and BOOST_AUTO_TEST_SUITE macros, but I still have to supply an init function to boost::unit_test::unit_test_main, right?
Yes. Even if it's empty.
What is its name?
it's not restricted. Only signature. I can't know that since it should be autogenerated. No. It can be, not "should be". Gennadiy

Simplest approach is to use dynamic library variant of the UTF I have noticed that I don't have to pass any libraries to the compiler and everything links fine when #defining BOOST_TEST_DYN_LINK, however
I believe you still have to, isn't it? I don't have to. When I copy the contents of Example 9 into a cpp file and then run g++ on it, if the macro BOOST_TEST_DYN_LINK is #defined, I have to wait a little bit, but I get no linking errors at all. I just run 'g++ file.cpp' with no additional parameters... And it works even when BOOST_TEST_NO_LIB is #defined. Strange, isn't it?
it takes a lot of time to compile. I am on Linux and I use autotools that pass the -lboost_unit_test_framework-mt flag to the linker.
What does this lead to? I mean will it link with static or shared library? It should mean the dynamic one (they have the same name, but shared
Thank you for your reply, linking is the default one. But this probably has no effect) When you #define BOOST_TEST_DYN_LINK, you don't have to worry about linking (see above). When you don't #define BOOST_TEST_DYN_LINK, you get quite a lot of errors about wrong parameters (still when compiling the Example 9 from the boost manual). These are those errors (after #defining BOOST_TEST_NO_MAIN): test.cpp: In function 'int main(int, char**)': test.cpp:34: error: invalid conversion from 'bool (*)()' to 'boost::unit_test::test_suite* (*)(int, char**)' test.cpp:34: error: initializing argument 1 of 'int boost::unit_test::unit_test_main(boost::unit_test::test_suite* (*)(int, char**), int, char**)' Example 9: http://www.boost.org/doc/libs/1_37_0/libs/test/doc/html/utf/user-guide/test-...
However, I still get undefined references or compilation errors when BOOST_TEST_DYN_LINK is not defined...
Please post them.
Let's forget about undefined references, the problem seems to be that the library has different function forms depending whether the BOOST_TEST_DYN_LINK is #defined or not. What is annoying is that It takes quite a long time to compile the tests and I suspect that some invisible linking or compilation of Boost testing library is taking place there. Any ideas? Regarding automatic registration: I had problems with it because I have not #defined the BOOST_TEST_DYN_LIN symbol. Now everything seems to be OK to me. Thank you very much for your help. How could I contribute to the documentation? I think that what I have learned may be useful to others Matej

Matěj Týč
Example 9: http://www.boost.org/doc/libs/1_37_0/libs/test/doc/html/utf/user-guide/test-...
Argh! It looks like there is a bug in this example. It uses single header variant of UTF and is trying to define BOOST_TEST_DYN_LINK, which obviously incorrect and will never work. This should explain a lot of strange behavior you experience (like for example lack of errors if you don't link with library) Please remove /included/ from include statement and try again. Let me know how it works for you. Gennadiy

Thank you for your reply,
It looks like there is a bug in this example....
Please remove /included/ from include statement and try again. Let me know how it works for you.
Yes, you were right - now it works nicely for me, many thanks! I think that a section in the documentation or an example like "how to use Boost UTF if you already have a main() function you can't get rid of" could be appretiated by many... Regards, Matej
participants (2)
-
Gennadiy Rozental
-
Matěj Týč