6 #include <dispatch/dispatch.h>
8 #include "dispatch_test.h"
12 test_start("Dispatch Source Timer, bit 31");
14 dispatch_queue_t main_q
= dispatch_get_main_queue();
15 test_ptr("dispatch_get_main_queue", main_q
, dispatch_get_current_queue());
18 struct timeval start_time
;
20 gettimeofday(&start_time
, NULL
);
21 dispatch_source_attr_t attr
= dispatch_source_attr_create();
22 dispatch_source_attr_set_finalizer(attr
, ^(dispatch_source_t ds
) {
23 struct timeval end_time
;
24 gettimeofday(&end_time
, NULL
);
25 test_ptr_notnull("finalizer ran", ds
);
26 // XXX: check, s/b 2.0799... seconds, which is <4 seconds
27 // when it could end on a bad boundry.
28 test_long_less_than("needs to finish faster than 4 seconds", end_time
.tv_sec
- start_time
.tv_sec
, 4);
29 // And it has to take at least two seconds...
30 test_long_less_than("can't finish faster than 2 seconds", 1, end_time
.tv_sec
- start_time
.tv_sec
);
34 dispatch_source_t s
= dispatch_source_timer_create(DISPATCH_TIMER_INTERVAL
,
39 ^(dispatch_event_t ev
) {
41 if (dispatch_event_get_error(ev
, &err
)) {
42 test_errno("dispatch_event_get_error", err
, ECANCELED
);
43 dispatch_release(dispatch_event_get_source(ev
));
45 fprintf(stderr
, "%d\n", ++i
);
46 dispatch_cancel(dispatch_event_get_source(ev
));
49 test_ptr_notnull("dispatch_source_timer_create", s
);
51 dispatch_release(attr
);