]> git.meshlink.io Git - meshlink/blobdiff - test/basic.c
Allow meshlink_open() to be called with a NULL name.
[meshlink] / test / basic.c
index bf8ff772af73db120cadbc2d54403fb36b512d26..bc93de09c68e32508dab5ce5bb27391dec875bca 100644 (file)
 int main() {
        meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
 
-       // Open a new meshlink instance.
+       // Check that the first time we need to supply a name
 
        assert(meshlink_destroy("basic_conf"));
-       meshlink_handle_t *mesh = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE);
+
+       meshlink_handle_t *mesh = meshlink_open("basic_conf", NULL, "basic", DEV_CLASS_BACKBONE);
+       assert(!mesh);
+
+       // Open a new meshlink instance.
+
+       mesh = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE);
        assert(mesh);
 
        // Check that we can't open a second instance of the same node.
@@ -74,10 +80,17 @@ int main() {
 
        meshlink_close(mesh);
        mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
+       assert(!mesh);
+
+       // Open it without providing a name
+
+       mesh = meshlink_open("basic_conf", NULL, "basic", DEV_CLASS_BACKBONE);
        assert(mesh);
 
        self = meshlink_get_self(mesh);
        assert(self);
+       assert(!strcmp(mesh->name, "foo"));
+       assert(!strcmp(self->name, "foo"));
 
        // Check that we remembered we were reachable