]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/test-network.c
network: Export family, first_address and last_address in Python
[people/ms/libloc.git] / src / test-network.c
index c49c3ef4038a23c56bb75d136d275ced3b40fbc9..d38f13dd74605bc6cbfd039ef98b09e054b2422b 100644 (file)
@@ -46,7 +46,7 @@ int main(int argc, char** argv) {
 
        // Create a network
        struct loc_network* network1;
-       err = loc_network_new_from_string(ctx, &network1, "2001:db8::/32");
+       err = loc_network_new_from_string(ctx, &network1, "2001:db8::1/32");
        if (err) {
                fprintf(stderr, "Could not create the network\n");
                exit(EXIT_FAILURE);
@@ -65,6 +65,29 @@ int main(int argc, char** argv) {
                exit(EXIT_FAILURE);
        }
 
+       // Check if the first and last addresses are correct
+       char* string = loc_network_format_first_address(network1);
+       if (!string) {
+               fprintf(stderr, "Did get NULL instead of a string for the first address\n");
+               exit(EXIT_FAILURE);
+       }
+
+       if (strcmp(string, "2001:db8::") != 0) {
+               fprintf(stderr, "Got an incorrect first address: %s\n", string);
+               exit(EXIT_FAILURE);
+       }
+
+       string = loc_network_format_last_address(network1);
+       if (!string) {
+               fprintf(stderr, "Did get NULL instead of a string for the last address\n");
+               exit(EXIT_FAILURE);
+       }
+
+       if (strcmp(string, "2001:db8:ffff:ffff:ffff:ffff:ffff:ffff") != 0) {
+               fprintf(stderr, "Got an incorrect last address: %s\n", string);
+               exit(EXIT_FAILURE);
+       }
+
        struct loc_network* network2;
        err = loc_network_new_from_string(ctx, &network2, "2001:db8:ffff::/48");
        if (err) {