Boost logo

Boost Testing :

Subject: Re: [Boost-testing] How to test callbacks / non-blocking calls?
From: ariasgore_at_[hidden]
Date: 2009-06-19 02:03:54


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.

In my scenario I am testing a socket communication, which is known to be async.

If I do something like:

void myFunc(const char * text)
{
  BOOST_CHECK_STH_THAT_FAILED()

}
BOOST_AUTO_TEST_CASE(foo)
{
  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 ?

Thank you
Sam

-------- Original-Nachricht --------
> Datum: Thu, 18 Jun 2009 17:20:33 +0000 (UTC)
> Von: Gennadiy Rozental <rogeeff_at_[hidden]>
> An: boost-testing_at_[hidden]
> Betreff: Re: [Boost-testing] How to test callbacks / non-blocking calls?

> <ariasgore <at> gmx.de> writes:
>
> > void mmyFunc(const char * text)
> > {
> > // compare
> > }
> > BOOST_AUTO_TEST_CASE(foo)
> > {
> > mocksocket m;
> > MySocket my(1000); // listen on port 1000
> > my.callback(myFunc); // register callback
> > m.send("foo");
> >
> > BOOST_CHECK_??
> > // test case ended
>
> What exactly you want to check here?
>
> > }
> >
> > So my test cannot be executed at once in the case
> > since the callback most probably fires too late. What are
>
> What do you mean by too late? after you exit from the case?
>
> > workarounds for such scenarios?
>
>
> Why don't you perform checks inside the callback?
>
>
> Gennadiy
>
> _______________________________________________
> Boost-Testing mailing list
> Boost-Testing_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-testing

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

Boost-testing list run by mbergal at meta-comm.com