How to unit test a call-back function? (C++ Boost Unit test) -


i want unit test client/server function. client calls server, server calls callback function. like:

void callback() {     boost_success(); // test successful if called }  boost_auto_test_case( connectiontest_clientcallback ) {     callserver(); // server work , call callback()     sleep(20);     boost_fail("server hasn't called callback() within specified time limit."); } 

but above won't work because callback() called during of tests. there better way this?

in callback function set variable:

void callback() {     callbackcalled = true; } 

and test in test:

boost_auto_test_case( connectiontest_clientcallback ) {     callbackcalled = false;     callserver(); // server work , call callback()     sleep(20);     if (callbackcalled)         boost_success();     else         boost_fail("server hasn't called callback() within specified time limit."); } 

edit: better solution suggested kizzx2:

boost_auto_test_case( connectiontest_clientcallback ) {     callbackcalled = false;     callserver(); // server work , call callback()     sleep(20);     boost_check_message(callbackcalled, "server hasn't called callback() within specified time limit."); } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -