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