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 // Check that we are not reachable.
48 time_t last_reachable;
49 time_t last_unreachable;
50 assert(!meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
51 assert(!last_reachable);
52 assert(!last_unreachable);
54 // Start and stop the mesh.
56 assert(meshlink_start(mesh));
58 // Check that we are now reachable
60 assert(meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
61 assert(last_reachable);
62 assert(!last_unreachable);
66 // Check that we are no longer reachable.
68 assert(!meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
69 assert(last_reachable);
70 assert(last_unreachable);
72 // Make sure we can start and stop the mesh again.
74 assert(meshlink_start(mesh));
75 assert(meshlink_start(mesh));
79 // Close the mesh and open it again, now with a different name parameter.
82 mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
85 // Open it without providing a name
87 mesh = meshlink_open("basic_conf", NULL, "basic", DEV_CLASS_BACKBONE);
90 self = meshlink_get_self(mesh);
92 assert(!strcmp(mesh->name, "foo"));
93 assert(!strcmp(self->name, "foo"));
95 // Check that we remembered we were reachable
97 assert(!meshlink_get_node_reachability(mesh, self, &last_reachable, &last_unreachable));
98 assert(last_reachable);
99 assert(last_unreachable);
101 // Check that the name is ignored now, and that we still are "foo".
103 assert(!meshlink_get_node(mesh, "bar"));
104 self = meshlink_get_self(mesh);
106 assert(!strcmp(self->name, "foo"));
108 // Start and stop the mesh.
110 assert(meshlink_start(mesh));
112 meshlink_close(mesh);
114 // Check that messing with the config directory will create a new instance.
116 assert(unlink("basic_conf/current/meshlink.conf") == 0);
117 mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
119 assert(!meshlink_get_node(mesh, "foo"));
120 self = meshlink_get_self(mesh);
122 assert(!strcmp(self->name, "bar"));
123 assert(access("basic_conf/new", X_OK) == -1 && errno == ENOENT);
124 meshlink_close(mesh);
126 assert(rename("basic_conf/current", "basic_conf/new") == 0);
127 mesh = meshlink_open("basic_conf", "baz", "basic", DEV_CLASS_BACKBONE);
129 assert(!meshlink_get_node(mesh, "bar"));
130 self = meshlink_get_self(mesh);
132 assert(!strcmp(self->name, "baz"));
133 assert(access("basic_conf/new", X_OK) == -1 && errno == ENOENT);
134 meshlink_close(mesh);
138 assert(meshlink_destroy("basic_conf"));
140 // Check that the configuration directory is completely empty.
142 DIR *dir = opendir("basic_conf");
146 while((ent = readdir(dir))) {
147 assert(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."));
152 // Check that we can destroy it again.
154 assert(meshlink_destroy("basic_conf"));