]>
Commit | Line | Data |
---|---|---|
1 | #include <sys/time.h> | |
2 | #include <mach/mach.h> | |
3 | #include <mach/mach_host.h> | |
4 | ||
5 | #include <darwintest.h> | |
6 | ||
7 | static void | |
8 | do_test(int notify_type, void (^trigger_block)(void)) | |
9 | { | |
10 | mach_port_t port; | |
11 | T_ASSERT_MACH_SUCCESS(mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port), NULL); | |
12 | ||
13 | T_ASSERT_MACH_SUCCESS(host_request_notification(mach_host_self(), notify_type, port), NULL); | |
14 | ||
15 | trigger_block(); | |
16 | ||
17 | struct { | |
18 | mach_msg_header_t hdr; | |
19 | mach_msg_trailer_t trailer; | |
20 | } message = { .hdr = { | |
21 | .msgh_bits = 0, | |
22 | .msgh_size = sizeof(mach_msg_header_t), | |
23 | .msgh_remote_port = MACH_PORT_NULL, | |
24 | .msgh_local_port = port, | |
25 | .msgh_voucher_port = MACH_PORT_NULL, | |
26 | .msgh_id = 0, | |
27 | }}; | |
28 | ||
29 | T_ASSERT_EQ(MACH_RCV_TOO_LARGE, mach_msg_receive(&message.hdr), NULL); | |
30 | mach_msg_destroy(&message.hdr); | |
31 | } | |
32 | ||
33 | T_DECL(host_notify_calendar_change, "host_request_notification(HOST_NOTIFY_CALENDAR_CHANGE)", T_META_CHECK_LEAKS(false), T_META_LTEPHASE(LTE_POSTINIT)) | |
34 | { | |
35 | do_test(HOST_NOTIFY_CALENDAR_CHANGE, ^{ | |
36 | struct timeval tm; | |
37 | if (gettimeofday(&tm, NULL) != 0 || settimeofday(&tm, NULL) != 0) { | |
38 | T_SKIP("Unable to settimeofday()"); | |
39 | } | |
40 | }); | |
41 | } | |
42 | ||
43 | T_DECL(host_notify_calendar_set, "host_request_notification(HOST_NOTIFY_CALENDAR_SET)", T_META_CHECK_LEAKS(false), T_META_LTEPHASE(LTE_POSTINIT)) | |
44 | { | |
45 | do_test(HOST_NOTIFY_CALENDAR_SET, ^{ | |
46 | struct timeval tm; | |
47 | if (gettimeofday(&tm, NULL) != 0 || settimeofday(&tm, NULL) != 0) { | |
48 | T_SKIP("Unable to settimeofday()"); | |
49 | } | |
50 | }); | |
51 | } |