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