chiark / gitweb /
Fix a few return codes in error paths
[elogind.git] / src / network / test-network.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2013 Tom Gundersen <teg@jklm.no>
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 "networkd.h"
23
24 static void test_link(Manager *manager, struct udev_device *loopback) {
25         Link *link = NULL;
26
27         assert_se(link_new(manager, loopback, &link) >= 0);
28         assert_se(link);
29 }
30
31 static void test_load_config(Manager *manager) {
32 /*  TODO: should_reload, is false if the config dirs do not exist, so
33  *        so we can't do this test here, move it to a test for paths_check_timestamps
34  *        directly
35  *
36  *        assert_se(network_should_reload(manager) == true);
37 */
38         assert_se(manager_load_config(manager) >= 0);
39         assert_se(manager_should_reload(manager) == false);
40 }
41
42 static void test_network_get(Manager *manager, struct udev_device *loopback) {
43         Network *network;
44
45         /* let's assume that the test machine does not have a .network file
46            that applies to the loopback device... */
47         assert_se(network_get(manager, loopback, &network) == -ENOENT);
48         assert_se(!network);
49 }
50
51 int main(void) {
52         _cleanup_manager_free_ Manager *manager = NULL;
53         struct udev *udev;
54         struct udev_device *loopback;
55
56         assert_se(manager_new(&manager) >= 0);
57
58         test_load_config(manager);
59
60         udev = udev_new();
61         assert_se(udev);
62
63         loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
64         assert_se(loopback);
65         assert_se(udev_device_get_ifindex(loopback) == 1);
66
67         test_network_get(manager, loopback);
68
69         test_link(manager, loopback);
70
71         assert_se(manager_udev_listen(manager) >= 0);
72         assert_se(manager_udev_enumerate_links(manager) >= 0);
73         assert_se(manager_rtnl_listen(manager) >= 0);
74
75         udev_device_unref(loopback);
76         udev_unref(udev);
77 }