libmoost
|
00001 /* vim:set ts=3 sw=3 sts=3 et: */ 00028 // Include boost test framework required headers 00029 #include <boost/test/unit_test.hpp> 00030 #include <boost/test/test_tools.hpp> 00031 00032 // Include CRT/STL required header(s) 00033 00034 // Include thrift headers 00035 00036 // Include application required header(s) 00037 #include "../../include/moost/utils/fixed_interval_timer.hpp" 00038 00039 // Imported required namespace(s) 00040 using namespace moost::utils; 00041 00042 // Name the test suite 00043 BOOST_AUTO_TEST_SUITE( MoostUtilsFixedIntervalTimerTest ) 00044 00045 // Define the test fixture 00046 struct Fixture 00047 { 00048 // C_tor 00049 Fixture() 00050 { 00051 } 00052 00053 // D_tor 00054 ~Fixture() 00055 { 00056 } 00057 }; 00058 00059 BOOST_FIXTURE_TEST_CASE( test_utils_callback_timer_future, Fixture ) 00060 { 00061 fixed_interval_timer fit(boost::posix_time::milliseconds(500)); 00062 00063 fixed_interval_timer::future_t f1; 00064 fixed_interval_timer::future_t f2; 00065 00066 BOOST_CHECK(!f1.is_ready()); 00067 BOOST_CHECK(!f2.is_ready()); 00068 00069 fit.notify(f1); 00070 00071 BOOST_CHECK(!f1.is_ready()); 00072 BOOST_CHECK(!f2.is_ready()); 00073 00074 boost::thread::sleep( 00075 boost::posix_time::microsec_clock::universal_time() + 00076 boost::posix_time::seconds(1)); 00077 00078 BOOST_CHECK(f1.is_ready()); 00079 BOOST_CHECK(!f2.is_ready()); 00080 00081 fit.notify(f2); 00082 00083 BOOST_CHECK(f1.is_ready()); 00084 BOOST_CHECK(!f2.is_ready()); 00085 00086 boost::thread::sleep( 00087 boost::posix_time::microsec_clock::universal_time() + 00088 boost::posix_time::seconds(1)); 00089 00090 BOOST_CHECK(f1.is_ready()); 00091 BOOST_CHECK(f2.is_ready()); 00092 } 00093 00094 BOOST_FIXTURE_TEST_CASE( test_utils_callback_timer_signal, Fixture ) 00095 { 00096 fixed_interval_timer fit(boost::posix_time::milliseconds(500)); 00097 00098 fixed_interval_timer::signal_t s1; 00099 fixed_interval_timer::signal_t s2; 00100 00101 BOOST_CHECK(!s1.is_ready()); 00102 BOOST_CHECK(!s2.is_ready()); 00103 00104 fit.notify(s1); 00105 00106 BOOST_CHECK(!s1.is_ready()); 00107 BOOST_CHECK(!s2.is_ready()); 00108 00109 boost::thread::sleep( 00110 boost::posix_time::microsec_clock::universal_time() + 00111 boost::posix_time::seconds(1)); 00112 00113 BOOST_CHECK(s1.is_ready()); 00114 BOOST_CHECK(!s2.is_ready()); 00115 00116 fit.notify(s2); 00117 00118 BOOST_CHECK(s1.is_ready()); 00119 BOOST_CHECK(!s2.is_ready()); 00120 00121 boost::thread::sleep( 00122 boost::posix_time::microsec_clock::universal_time() + 00123 boost::posix_time::seconds(1)); 00124 00125 BOOST_CHECK(s1.is_ready()); 00126 BOOST_CHECK(s2.is_ready()); 00127 } 00128 00129 00130 // Define end of test suite 00131 BOOST_AUTO_TEST_SUITE_END()