chiark / gitweb /
libsystemd-dhcp: Add capability to print out test steps
[elogind.git] / src / libsystemd-dhcp / test-dhcp-client.c
index 7400cc6837e72b48fd22692d031f7beab871cab9..32c79ebb68e496feb17fdf9c0393bbe83c4863f0 100644 (file)
@@ -38,16 +38,26 @@ static struct ether_addr mac_addr = {
         .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}
 };
 
+static bool verbose = false;
 static int test_fd[2];
 
 static void test_request_basic(sd_event *e)
 {
+        int r;
+
         sd_dhcp_client *client;
 
-        client = sd_dhcp_client_new(e);
+        if (verbose)
+                printf("* %s\n", __FUNCTION__);
+
+        r = sd_dhcp_client_new(&client);
 
+        assert(r >= 0);
         assert(client);
 
+        r = sd_dhcp_client_attach_event(client, e, 0);
+        assert(r >= 0);
+
         assert(sd_dhcp_client_set_request_option(NULL, 0) == -EINVAL);
         assert(sd_dhcp_client_set_request_address(NULL, NULL) == -EINVAL);
         assert(sd_dhcp_client_set_index(NULL, 0) == -EINVAL);
@@ -85,6 +95,7 @@ static void test_request_basic(sd_event *e)
         assert(sd_dhcp_client_set_request_option(client, 33) == 0);
         assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
         assert(sd_dhcp_client_set_request_option(client, 44) == 0);
+        assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
 }
 
 static uint16_t client_checksum(void *buf, int len)
@@ -119,13 +130,10 @@ static void test_checksum(void)
                 0xff, 0xff, 0xff, 0xff
         };
 
-        uint8_t check[2] = {
-                0x78, 0xae
-        };
+        if (verbose)
+                printf("* %s\n", __FUNCTION__);
 
-        uint16_t *val = (uint16_t *)check;
-
-        assert(client_checksum(&buf, 20) == *val);
+        assert(client_checksum(&buf, 20) == be16toh(0x78ae));
 }
 
 static int check_options(uint8_t code, uint8_t len, const uint8_t *option,
@@ -190,14 +198,32 @@ int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link)
         return test_fd[0];
 }
 
+int dhcp_network_bind_udp_socket(int index, be32_t address, uint16_t port)
+{
+        return 0;
+}
+
+int dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port,
+                                 const void *packet, size_t len)
+{
+        return 0;
+}
+
 static void test_discover_message(sd_event *e)
 {
         sd_dhcp_client *client;
-        int res;
+        int res, r;
 
-        client = sd_dhcp_client_new(e);
+        if (verbose)
+                printf("* %s\n", __FUNCTION__);
+
+        r = sd_dhcp_client_new(&client);
+        assert(r >= 0);
         assert(client);
 
+        r = sd_dhcp_client_attach_event(client, e, 0);
+        assert(r >= 0);
+
         assert(sd_dhcp_client_set_index(client, 42) >= 0);
         assert(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);