chiark / gitweb /
sd-dhcp6-client: Add basic DHCPv6 test cases
[elogind.git] / src / libsystemd-network / test-dhcp6-client.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) 2014 Intel Corporation. All rights reserved.
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <stdbool.h>
23 #include <stdio.h>
24
25 #include "macro.h"
26 #include "sd-event.h"
27 #include "event-util.h"
28
29 #include "sd-dhcp6-client.h"
30 #include "dhcp6-protocol.h"
31
32 static struct ether_addr mac_addr = {
33         .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}
34 };
35
36 static bool verbose = false;
37
38 static int test_client_basic(sd_event *e) {
39         sd_dhcp6_client *client;
40
41         if (verbose)
42                 printf("* %s\n", __FUNCTION__);
43
44         assert_se(sd_dhcp6_client_new(&client) >= 0);
45         assert_se(client);
46
47         assert_se(sd_dhcp6_client_attach_event(client, e, 0) >= 0);
48
49         assert_se(sd_dhcp6_client_set_index(client, 15) == 0);
50         assert_se(sd_dhcp6_client_set_index(client, -42) == -EINVAL);
51         assert_se(sd_dhcp6_client_set_index(client, -1) == 0);
52         assert_se(sd_dhcp6_client_set_index(client, 42) >= 0);
53
54         assert_se(sd_dhcp6_client_set_mac(client, &mac_addr) >= 0);
55
56         assert_se(sd_dhcp6_client_set_callback(client, NULL, NULL) >= 0);
57
58         assert_se(sd_dhcp6_client_detach_event(client) >= 0);
59         assert_se(!sd_dhcp6_client_unref(client));
60
61         return 0;
62 }
63
64 int main(int argc, char *argv[]) {
65         _cleanup_event_unref_ sd_event *e;
66
67         assert_se(sd_event_new(&e) >= 0);
68
69         log_set_max_level(LOG_DEBUG);
70         log_parse_environment();
71         log_open();
72
73         test_client_basic(e);
74
75         return 0;
76 }