]> git.meshlink.io Git - meshlink/blobdiff - test/trio.c
Clean up resources in the test cases.
[meshlink] / test / trio.c
index bfeb4f6effecb6d384228981aa5d9cdc91c1f959..41aa4fb6215795ae736a41e745414bcfe89dc5f2 100644 (file)
@@ -1,6 +1,7 @@
 #define _GNU_SOURCE
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
@@ -12,6 +13,8 @@
 #include "utils.h"
 
 static void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) {
+       (void)mesh;
+
        static struct timeval tv0;
        struct timeval tv;
 
@@ -32,6 +35,9 @@ static void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const ch
 static bool received = false;
 
 static void receive_cb(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len) {
+       (void)mesh;
+       (void)source;
+
        fprintf(stderr, "RECEIVED SOMETHING\n");
 
        if(len == 5 && !memcmp(data, "Hello", 5)) {
@@ -39,7 +45,7 @@ static void receive_cb(meshlink_handle_t *mesh, meshlink_node_t *source, const v
        }
 }
 
-int main(int argc, char *argv[]) {
+int main() {
        // Create three instances.
 
        const char *name[3] = {"foo", "bar", "baz"};
@@ -47,12 +53,14 @@ int main(int argc, char *argv[]) {
        char *data[3];
 
        for(int i = 0; i < 3; i++) {
-               char *path;
-               asprintf(&path, "trio_conf.%d", i);
-               assert(path);
+               char *path = NULL;
+               assert(asprintf(&path, "trio_conf.%d", i) != -1 && path);
 
                mesh[i] = meshlink_open(path, name[i], "trio", DEV_CLASS_BACKBONE);
                assert(mesh[i]);
+               free(path);
+
+               meshlink_add_address(mesh[i], "localhost");
 
                data[i] = meshlink_export(mesh[i]);
                assert(data[i]);
@@ -76,7 +84,8 @@ int main(int argc, char *argv[]) {
        // start the nodes
 
        for(int i = 0; i < 3; i++) {
-               meshlink_start(mesh[i]);
+               free(data[i]);
+               assert(meshlink_start(mesh[i]));
        }
 
        // the nodes should now learn about each other
@@ -94,6 +103,7 @@ int main(int argc, char *argv[]) {
        devtool_edge_t *edges = NULL;
        size_t nedges = 0;
        assert_after((edges = devtool_get_all_edges(mesh[1], edges, &nedges), nedges == 3), 15);
+       free(edges);
 
        // Stop the first node
 
@@ -117,7 +127,7 @@ int main(int argc, char *argv[]) {
        meshlink_set_log_cb(mesh[1], MESHLINK_DEBUG, log_cb);
 
        for(int i = 1; i < 3; i++) {
-               meshlink_start(mesh[i]);
+               assert(meshlink_start(mesh[i]));
        }
 
        assert(meshlink_get_node(mesh[1], name[2]));