13 #include "meshlink-tiny.h"
17 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
19 // Check that the first time we need to supply a name
21 assert(meshlink_destroy("basic_conf"));
23 meshlink_handle_t *mesh = meshlink_open("basic_conf", NULL, "basic", DEV_CLASS_BACKBONE);
26 // Open a new meshlink instance.
28 mesh = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE);
31 // Check that we can't open a second instance of the same node.
33 meshlink_handle_t *mesh2 = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE);
36 // Check that we cannot destroy an instance that is in use.
38 assert(!meshlink_destroy("basic_conf"));
40 // Check that our own node exists.
42 meshlink_node_t *self = meshlink_get_self(mesh);
44 assert(!strcmp(self->name, "foo"));
46 // Start and stop the mesh.
48 assert(meshlink_start(mesh));
52 // Make sure we can start and stop the mesh again.
54 assert(meshlink_start(mesh));
55 assert(meshlink_start(mesh));
59 // Close the mesh and open it again, now with a different name parameter.
62 mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
65 // Open it without providing a name
67 mesh = meshlink_open("basic_conf", NULL, "basic", DEV_CLASS_BACKBONE);
70 self = meshlink_get_self(mesh);
72 assert(!strcmp(mesh->name, "foo"));
73 assert(!strcmp(self->name, "foo"));
75 // Check that the name is ignored now, and that we still are "foo".
77 assert(!meshlink_get_node(mesh, "bar"));
78 self = meshlink_get_self(mesh);
80 assert(!strcmp(self->name, "foo"));
82 // Start and stop the mesh.
84 assert(meshlink_start(mesh));
88 // Check that messing with the config directory will create a new instance.
90 assert(unlink("basic_conf/current/meshlink.conf") == 0);
91 mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
93 assert(!meshlink_get_node(mesh, "foo"));
94 self = meshlink_get_self(mesh);
96 assert(!strcmp(self->name, "bar"));
97 assert(access("basic_conf/new", X_OK) == -1 && errno == ENOENT);
100 assert(rename("basic_conf/current", "basic_conf/new") == 0);
101 mesh = meshlink_open("basic_conf", "baz", "basic", DEV_CLASS_BACKBONE);
103 assert(!meshlink_get_node(mesh, "bar"));
104 self = meshlink_get_self(mesh);
106 assert(!strcmp(self->name, "baz"));
107 assert(access("basic_conf/new", X_OK) == -1 && errno == ENOENT);
108 meshlink_close(mesh);
112 assert(meshlink_destroy("basic_conf"));
114 // Check that the configuration directory is completely empty.
116 DIR *dir = opendir("basic_conf");
120 while((ent = readdir(dir))) {
121 assert(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."));
126 // Check that we can destroy it again.
128 assert(meshlink_destroy("basic_conf"));