Boost logo

Boost Testing :

Subject: Re: [Boost-testing] How to test callbacks / non-blocking calls?
From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2009-06-19 02:38:32

 <ariasgore <at>> writes:

> Hello Gennadiy,
> as far as I got the auto registering I thought that only doing
> the tests in BOOST_AUTO_TEST_CASE will be
> noticed by Boost::Test.

The check should occur while test case is being executed. That said it can be
done in some callback which is being invoked.
> void myFunc(const char * text)
> {
> }
> {
> mocksocket m;
> MySocket my(1000); // listen on port 1000
> my.callback(myFunc); // register callback
> // the myFunc callback will be called in lets say 20 seconds later,
> // socket delay or communication with a remote host that is far away.
> // even if mock objects would accelerate this part, it would still not
> // be in-sync with the Test-case body
> m.send("foo");
> // test finished after 4 ms
> }
> Will that work anyhow? Since the boost_check is done in a method myFunc that
is not directly executed in the
> BOOST_AUTO_TEST_CASE(foo) function scope. The BOOST_AUTO_TEST_CASE(foo) needs
4 ms to complete,
> whereas the socket communication takes up to 20 seconds to process. How can
boost::test notice anything
> of myFunc if the test and the whole programm is already finished after 4 ms ?

Can't you wait till communication is completed? In worse case you can wait on
conditional variable and trigger it inside the callback.


Boost-testing list run by mbergal at