]> git.meshlink.io Git - meshlink/blob - test/basic.c
Add devclass argument to calls to meshlink_open() in all tests.
[meshlink] / test / basic.c
1 #include <stdio.h>
2 #include <string.h>
3
4 #include "meshlink.h"
5
6 int main(int argc, char *argv[]) {
7         // Open a new meshlink instance.
8
9         meshlink_handle_t *mesh = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE);
10         if(!mesh) {
11                 fprintf(stderr, "Could not initialize configuration for foo\n");
12                 return 1;
13         }
14
15         // Check that our own node exists.
16
17         meshlink_node_t *self = meshlink_get_node(mesh, "foo");
18         if(!self) {
19                 fprintf(stderr, "Foo does not know about itself\n");
20                 return 1;
21         }
22         if(strcmp(self->name, "foo")) {
23                 fprintf(stderr, "Foo thinks its name is %s\n", self->name);
24                 return 1;
25         }
26
27         // Start and stop the mesh.
28
29         if(!meshlink_start(mesh)) {
30                 fprintf(stderr, "Foo could not start\n");
31                 return 1;
32         }
33         meshlink_stop(mesh);
34
35         // Make sure we can start and stop the mesh again.
36
37         if(!meshlink_start(mesh)) {
38                 fprintf(stderr, "Foo could not start twice\n");
39                 return 1;
40         }
41         meshlink_stop(mesh);
42
43         // Close the mesh and open it again, now with a different name parameter.
44
45         meshlink_close(mesh);
46
47         // Check that the name is ignored now, and that we still are "foo".
48
49         mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
50         if(!mesh) {
51                 fprintf(stderr, "Could not open configuration for foo a second time\n");
52                 return 1;
53         }
54
55         if(meshlink_get_node(mesh, "bar")) {
56                 fprintf(stderr, "Foo knows about bar, it shouldn't\n");
57                 return 1;
58         }
59
60         self = meshlink_get_node(mesh, "foo");
61         if(!self) {
62                 fprintf(stderr, "Foo doesn't know about itself the second time\n");
63                 return 1;
64         }
65         if(strcmp(self->name, "foo")) {
66                 fprintf(stderr, "Foo thinks its name is %s the second time\n", self->name);
67                 return 1;
68         }
69
70         // Start and stop the mesh.
71
72         if(!meshlink_start(mesh)) {
73                 fprintf(stderr, "Foo could not start a third time\n");
74                 return 1;
75         }
76         meshlink_stop(mesh);
77
78         // That's it.
79
80         meshlink_close(mesh);
81
82         return 0;
83 }