7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for common::EventHandler"
10 #include <boost/test/unit_test.hpp>
11 #include <boost/thread.hpp>
23 using namespace boost;
44 options.
add(
"iteration", 0u);
46 for(
Uint iter = 0; iter < 10; ++iter )
49 std::cout <<
" - iter [" << iter <<
"]" << std::endl;
53 boost::this_thread::sleep(boost::posix_time::milliseconds(100));
57 options[
"iteration"].change_value( iter );
62 Core::instance().event_handler().raise_event(
"iteration_done", f );
70 std::cout <<
" - writting results file " << std::endl;
76 options.
add(
"file",
URI(
"file:///localhost/path/to/file.txt") );
79 Core::instance().event_handler().raise_event(
"file_written", f );
98 Core::instance().event_handler().connect_to_event(
"file_written",
111 std::cout <<
" + EVENT + uploading file [" << filepath.
string() <<
"]" << std::endl;
139 display_iteration( current_iter );
146 std::cout <<
" + EVENT + current iteration [" << iter <<
"]" << std::endl;
151 Core::instance().event_handler().connect_to_event(
"iteration_done",
158 connection(
"iteration_done")->disconnect();
172 Core::instance().initiate(boost::unit_test::framework::master_test_suite().argc,
173 boost::unit_test::framework::master_test_suite().argv);
178 Core::instance().terminate();
193 BOOST_AUTO_TEST_SUITE( event_handler_test_suite )
201 std::cout <<
"raise_event" << std::endl;
207 BOOST_CHECK ( display.triggered == 0 );
208 BOOST_CHECK (
writer.triggered == 0 );
214 BOOST_CHECK ( display.triggered == 0 );
215 BOOST_CHECK (
writer.triggered == 1 );
224 std::cout <<
"connect_to_event" << std::endl;
230 BOOST_CHECK ( display.triggered == 0 );
231 BOOST_CHECK (
writer.triggered == 0 );
235 display.start_displaying();
239 BOOST_CHECK ( display.triggered == 10 );
240 BOOST_CHECK (
writer.triggered == 0 );
246 BOOST_CHECK ( display.triggered == 10 );
247 BOOST_CHECK (
writer.triggered == 1 );
256 std::cout <<
"disconnect_from_event" << std::endl;
260 display.start_displaying();
264 BOOST_CHECK ( display.triggered == 10 );
265 BOOST_CHECK (
writer.triggered == 0 );
269 display.stop_displaying();
273 BOOST_CHECK ( display.triggered == 10 );
274 BOOST_CHECK (
writer.triggered == 0 );
281 BOOST_AUTO_TEST_SUITE_END()
Abstracts the use of XML when adding options to a signal frame.
void display_iteration(Uint iter)
external boost library namespace
Classes that implement the XML protocol for use in COOLFluiD.
void on_file_written(SignalArgs &args)
void on_iteration_done(SignalArgs &args)
SignalFrame create_frame(const std::string &name=std::string(), const URI &sender=URI(), const URI &receiver=URI()) const
Creates a frame and puts the options in an "options" map.
Uint triggered
for unit test to check how often the event was triggered
BOOST_FIXTURE_TEST_CASE(raise_event, local_fixture)
Uint triggered
for unit test to check how often the event was triggered
Top-level namespace for coolfluid.
const TYPE value(const std::string &opt_name) const
Get the value of the option with given name.
unsigned int Uint
typedef for unsigned int
BOOST_GLOBAL_FIXTURE(GlobalFixture) BOOST_AUTO_TEST_CASE(MeshStats)
Accumulate some statistics about the cell volumes.
SelectOptionType< T >::type & add(const std::string &name, const T &default_value=T())
Most basic kernel library.
std::string string() const