]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/test-dhcp-server.c
sd-dhcp-server: add basic functionality for creating/destroying server instance
[thirdparty/systemd.git] / src / libsystemd-network / test-dhcp-server.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright (C) 2013 Intel Corporation. All rights reserved.
7 Copyright (C) 2014 Tom Gundersen
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include <assert.h>
24 #include <errno.h>
25
26 #include "sd-event.h"
27 #include "event-util.h"
28
29 #include "sd-dhcp-server.h"
30 #include "dhcp-server-internal.h"
31
32 static void test_basic(sd_event *event) {
33 _cleanup_dhcp_server_unref_ sd_dhcp_server *server = NULL;
34
35 assert_se(sd_dhcp_server_new(&server) >= 0);
36 assert_se(server);
37
38 assert_se(sd_dhcp_server_attach_event(server, event, 0) >= 0);
39 assert_se(sd_dhcp_server_attach_event(server, event, 0) == -EBUSY);
40 assert_se(sd_dhcp_server_get_event(server) == event);
41 assert_se(sd_dhcp_server_detach_event(server) >= 0);
42 assert_se(!sd_dhcp_server_get_event(server));
43 assert_se(sd_dhcp_server_attach_event(server, NULL, 0) >= 0);
44 assert_se(sd_dhcp_server_attach_event(server, NULL, 0) == -EBUSY);
45
46 assert_se(sd_dhcp_server_ref(server) == server);
47 assert_se(!sd_dhcp_server_unref(server));
48 }
49
50 int main(int argc, char *argv[]) {
51 _cleanup_event_unref_ sd_event *e;
52
53 log_set_max_level(LOG_DEBUG);
54 log_parse_environment();
55 log_open();
56
57 assert_se(sd_event_new(&e) >= 0);
58
59 test_basic(e);
60
61 return 0;
62 }