void run(){ // we should be executed on the main queue MU_ASSERT_EQUAL_HEX(QDispatch::currentQueue().native(), dispatch_get_main_queue()); // assert that we can really get the timer MU_ASSERT_EQUAL_HEX(QDispatchTimer::current(), tested_timer); // test the timer interval (but only after the second run // as the first one will be started immediately if(counter > 0) { long diff = checked_time.elapsed(); MU_DESC_ASSERT_LESS_THAN_EQUAL("timer not too late", diff, 3*1000); MU_DESC_ASSERT_LESS_THAN_EQUAL("timer not too early", 1*1000, diff); } checked_time.restart(); // only pass when the timer fired at least 5 times MU_MESSAGE("\t%i", counter); if(counter < 5) counter++; else { MU_PASS(""); } }
extern "C" void Qt_dispatch_source_signal_lambda(){ char argv[] = "test"; int argc = 1; QDispatchApplication app(argc, (char**)&argv); MU_BEGIN_TEST(Qt_dispatch_source_signal_lambda); EmitterLambda object; // configure the source QDispatchSource src(new QDispatchSourceTypeSignal(&object, SIGNAL(ready()))); src.setTargetQueue(QDispatch::globalQueue(QDispatch::LOW)); src.setHandler([=]{ MU_MESSAGE("Signal was emitted"); if(QDispatch::currentQueue().native() == dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0)) MU_MESSAGE("Executed on low global queue"); else if(QDispatch::currentQueue().native() == dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) MU_MESSAGE("Executed on default global queue"); else if(QDispatch::currentQueue().native() == dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) MU_MESSAGE("Executed on high global queue"); else if(QDispatch::currentQueue().native() == dispatch_get_main_queue()) MU_MESSAGE("Executed on main queue"); MU_ASSERT_EQUAL_HEX(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), QDispatch::currentQueue().native()); MU_PASS(""); }); // trigger the signal object.notify(); app.exec(); MU_END_TEST; }
void run(){ // we should be executed on the global default queue MU_ASSERT_EQUAL_HEX(QDispatch::currentQueue().native(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)); // assert the requested timeout interval long diff = checked_time.elapsed(); MU_DESC_ASSERT_LESS_THAN_EQUAL("single-shot not too late", diff, 3* 1000); MU_DESC_ASSERT_LESS_THAN_EQUAL("single-shot not too early", 1*1000, diff); // now test wether we can create a periodic timer MU_MESSAGE("Testing periodic timer"); tested_timer = new QDispatchTimer(2000); MU_ASSERT_NOT_NULL(tested_timer); tested_timer->setHandler(new testPeriodic); tested_timer->setTargetQueue(QDispatch::mainQueue()); checked_time.restart(); tested_timer->start(); }