17 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
19 // Open a new meshlink instance.
21 assert(meshlink_destroy("basic_conf"));
22 meshlink_handle_t *mesh = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE);
25 // Check that we can't open a second instance of the same node.
27 meshlink_handle_t *mesh2 = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE);
30 // Check that we cannot destroy an instance that is in use.
32 assert(!meshlink_destroy("basic_conf"));
34 // Check that our own node exists.
36 meshlink_node_t *self = meshlink_get_self(mesh);
38 assert(!strcmp(self->name, "foo"));
40 // Check that we are not reachable.
42 time_t last_reachable;
43 time_t last_unreachable;
44 assert(!meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
45 assert(!last_reachable);
46 assert(!last_unreachable);
48 // Start and stop the mesh.
50 assert(meshlink_start(mesh));
52 // Check that we are now reachable
54 assert(meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
55 assert(last_reachable);
56 assert(!last_unreachable);
60 // Check that we are no longer reachable.
62 assert(!meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
63 assert(last_reachable);
64 assert(last_unreachable);
66 // Make sure we can start and stop the mesh again.
68 assert(meshlink_start(mesh));
69 assert(meshlink_start(mesh));
73 // Close the mesh and open it again, now with a different name parameter.
76 mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
79 self = meshlink_get_self(mesh);
82 // Check that we remembered we were reachable
84 assert(!meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
85 assert(last_reachable);
86 assert(last_unreachable);
88 // Check that the name is ignored now, and that we still are "foo".
90 assert(!meshlink_get_node(mesh, "bar"));
91 self = meshlink_get_self(mesh);
93 assert(!strcmp(self->name, "foo"));
95 // Start and stop the mesh.
97 assert(meshlink_start(mesh));
101 // Check that messing with the config directory will create a new instance.
103 assert(unlink("basic_conf/current/meshlink.conf") == 0);
104 mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
106 assert(!meshlink_get_node(mesh, "foo"));
107 self = meshlink_get_self(mesh);
109 assert(!strcmp(self->name, "bar"));
110 assert(access("basic_conf/new", X_OK) == -1 && errno == ENOENT);
111 meshlink_close(mesh);
113 assert(rename("basic_conf/current", "basic_conf/new") == 0);
114 mesh = meshlink_open("basic_conf", "baz", "basic", DEV_CLASS_BACKBONE);
116 assert(!meshlink_get_node(mesh, "bar"));
117 self = meshlink_get_self(mesh);
119 assert(!strcmp(self->name, "baz"));
120 assert(access("basic_conf/new", X_OK) == -1 && errno == ENOENT);
121 meshlink_close(mesh);
125 assert(meshlink_destroy("basic_conf"));
127 // Check that the configuration directory is completely empty.
129 DIR *dir = opendir("basic_conf");
133 while((ent = readdir(dir))) {
134 assert(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."));
139 // Check that we can destroy it again.
141 assert(meshlink_destroy("basic_conf"));