1 /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 Copyright (C) 2009-2015 Red Hat, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18 #include <config.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <common/log.h>
22 #include <spice.h>
23
24 static unsigned int watches_created = 0;
25 static unsigned int timers_created = 0;
26
27 static SpiceWatch *const dummy_watch = (SpiceWatch*)(uintptr_t)0xdeadbeef;
28 static SpiceTimer *const dummy_timer = (SpiceTimer*)(uintptr_t)0xbeefdead;
29
30 static SpiceTimer*
timer_add(SPICE_GNUC_UNUSED SpiceTimerFunc func,SPICE_GNUC_UNUSED void * opaque)31 timer_add(SPICE_GNUC_UNUSED SpiceTimerFunc func,
32 SPICE_GNUC_UNUSED void *opaque)
33 {
34 ++timers_created;
35 return dummy_timer;
36 }
37
38 static void
timer_start(SPICE_GNUC_UNUSED SpiceTimer * timer,SPICE_GNUC_UNUSED uint32_t ms)39 timer_start(SPICE_GNUC_UNUSED SpiceTimer *timer,
40 SPICE_GNUC_UNUSED uint32_t ms)
41 {
42 spice_assert(timer == dummy_timer);
43 }
44
45 static void
timer_cancel(SPICE_GNUC_UNUSED SpiceTimer * timer)46 timer_cancel(SPICE_GNUC_UNUSED SpiceTimer *timer)
47 {
48 spice_assert(timer == dummy_timer);
49 }
50
51 static void
timer_remove(SPICE_GNUC_UNUSED SpiceTimer * timer)52 timer_remove(SPICE_GNUC_UNUSED SpiceTimer *timer)
53 {
54 spice_assert(timer == dummy_timer);
55 }
56
57 static SpiceWatch *
watch_add(SPICE_GNUC_UNUSED int fd,SPICE_GNUC_UNUSED int event_mask,SPICE_GNUC_UNUSED SpiceWatchFunc func,SPICE_GNUC_UNUSED void * opaque)58 watch_add(SPICE_GNUC_UNUSED int fd,
59 SPICE_GNUC_UNUSED int event_mask,
60 SPICE_GNUC_UNUSED SpiceWatchFunc func,
61 SPICE_GNUC_UNUSED void *opaque)
62 {
63 ++watches_created;
64 return dummy_watch;
65 }
66
67 static void
watch_update_mask(SPICE_GNUC_UNUSED SpiceWatch * watch,SPICE_GNUC_UNUSED int event_mask)68 watch_update_mask(SPICE_GNUC_UNUSED SpiceWatch *watch,
69 SPICE_GNUC_UNUSED int event_mask)
70 {
71 spice_assert(watch == dummy_watch);
72 }
73
74 static void
watch_remove(SPICE_GNUC_UNUSED SpiceWatch * watch)75 watch_remove(SPICE_GNUC_UNUSED SpiceWatch *watch)
76 {
77 spice_assert(watch == dummy_watch);
78 }
79
80 static void
channel_event(SPICE_GNUC_UNUSED int event,SPICE_GNUC_UNUSED SpiceChannelEventInfo * info)81 channel_event(SPICE_GNUC_UNUSED int event,
82 SPICE_GNUC_UNUSED SpiceChannelEventInfo *info)
83 {
84 }
85
main(void)86 int main(void)
87 {
88 SpiceServer *server = spice_server_new();
89 SpiceCoreInterface core;
90
91 memset(&core, 0, sizeof(core));
92 core.base.major_version = SPICE_INTERFACE_CORE_MAJOR;
93 core.timer_add = timer_add;
94 core.timer_start = timer_start;
95 core.timer_cancel = timer_cancel;
96 core.timer_remove = timer_remove;
97 core.watch_add = watch_add;
98 core.watch_update_mask = watch_update_mask;
99 core.watch_remove = watch_remove;
100 core.channel_event = channel_event;
101
102 spice_server_set_port(server, 5911);
103 spice_server_init(server, &core);
104
105 spice_server_destroy(server);
106
107 // should have created some timers and watch
108 spice_assert(watches_created > 0);
109 spice_assert(timers_created > 0);
110
111 return 0;
112 }
113