]> git.saurik.com Git - apple/libdispatch.git/blob - testing/dispatch_timer_oneshot.c
libdispatch-84.5.5.tar.gz
[apple/libdispatch.git] / testing / dispatch_timer_oneshot.c
1 #include <stdlib.h>
2 #include <assert.h>
3 #include <stdio.h>
4 #include <string.h>
5
6 #include <dispatch/dispatch.h>
7
8 #include "dispatch_test.h"
9
10 static void
11 oneshot(void* context __attribute__((unused)), dispatch_event_t de)
12 {
13 dispatch_source_t ds = dispatch_event_get_source(de);
14 test_ptr_notnull("dispatch_event_get_source", ds);
15
16 if (!dispatch_event_get_error(de, NULL)) {
17 long canceled = dispatch_testcancel(ds);
18 test_long("dispatch_testcancel", canceled, 0);
19
20 dispatch_release(ds);
21 test_stop();
22 }
23 }
24
25 int
26 main(void)
27 {
28 test_start("Dispatch Timer One-Shot");
29
30 dispatch_source_t s;
31
32 s = dispatch_source_timer_create_f(DISPATCH_TIMER_ONESHOT,
33 (uint64_t)1000000000ull, // 1s
34 0,
35 NULL,
36 dispatch_get_concurrent_queue(0),
37 NULL,
38 &oneshot);
39
40 dispatch_main();
41
42 return 0;
43 }