]> git.meshlink.io Git - meshlink/blob - test/basic.c
Refactor the non-blackbox test suite.
[meshlink] / test / basic.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <errno.h>
5 #include <sys/time.h>
6 #include <assert.h>
7
8 #include "meshlink.h"
9 #include "utils.h"
10
11 int main() {
12         meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
13
14         // Open a new meshlink instance.
15
16         assert(meshlink_destroy("basic_conf"));
17         meshlink_handle_t *mesh = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE);
18         assert(mesh);
19
20         meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb);
21
22         // Check that our own node exists.
23
24         meshlink_node_t *self = meshlink_get_self(mesh);
25         assert(self);
26         assert(!strcmp(self->name, "foo"));
27
28         // Start and stop the mesh.
29
30         assert(meshlink_start(mesh));
31         meshlink_stop(mesh);
32
33         // Make sure we can start and stop the mesh again.
34
35         assert(meshlink_start(mesh));
36         meshlink_stop(mesh);
37
38         // Close the mesh and open it again, now with a different name parameter.
39
40         meshlink_close(mesh);
41         mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
42         assert(mesh);
43
44         // Check that the name is ignored now, and that we still are "foo".
45
46         assert(!meshlink_get_node(mesh, "bar"));
47         self = meshlink_get_self(mesh);
48         assert(self);
49         assert(!strcmp(self->name, "foo"));
50
51         // Start and stop the mesh.
52
53         assert(meshlink_start(mesh));
54         meshlink_stop(mesh);
55
56         // That's it.
57
58         meshlink_close(mesh);
59
60         // Destroy the mesh.
61
62         assert(meshlink_destroy("basic_conf"));
63         assert(access("basic_conf", F_OK) == -1 && errno == ENOENT);
64 }