// JobUpdater_t.cxx #include "dial_sched/JobUpdater.h" #include "dial_sched/Scheduler_t.h" #include #include #include using std::string; using std::cout; using std::endl; using dial::JobUpdater; void msg(string txt) { cout << "*** "; cout << txt; cout << " ***" << endl; } bool check(int val, int exp =0) { if ( val == exp ) return true; cout << "Expected " << exp << "; found " << val << endl; return false; } int JobUpdater_t() { msg("Create scheduler"); TestScheduler sch; msg("Create updater"); JobUpdater up(sch); cout << up << endl; assert( up.is_valid() ); assert( ! up.is_updating() ); assert( check(up.error()) ); assert( up.loop_count() == 0 ); msg("Start"); up.start(); cout << up << endl; assert( check(up.error()) ); assert( up.is_valid() ); assert( up.is_updating() ); msg("Give updater time to update"); for ( int i=0; i<10; ++i ) { if ( up.loop_count() > 0 ) break; sleep(1); } cout << up << endl; assert( check(up.error()) ); cout << up << endl; assert( up.is_valid() ); assert( up.is_updating() ); assert( up.loop_count() > 0 ); msg("Stop"); up.stop(); assert( check(up.error()) ); cout << up << endl; assert( up.is_valid() ); assert( ! up.is_updating() ); assert( up.loop_count() > 0 ); return 0; } #ifdef CTEST_MAIN int main() { return JobUpdater_t(); } #endif