]> git.meshlink.io Git - meshlink/blob - test/basicpp.cpp
Refactor the non-blackbox test suite.
[meshlink] / test / basicpp.cpp
1 #include <cstring>
2 #include <iostream>
3 #include <unistd.h>
4 #include <cerrno>
5 #include <cassert>
6
7 #include "meshlink++.h"
8
9 using namespace std;
10
11 int main() {
12         // Open a new meshlink instance.
13
14         assert(meshlink::destroy("basicpp_conf"));
15         meshlink::mesh mesh("basicpp_conf", "foo", "basicpp", DEV_CLASS_BACKBONE);
16         assert(mesh.isOpen());
17
18         // Check that our own node exists.
19
20         meshlink::node *self = mesh.get_self();
21         assert(self);
22         assert(!strcmp(self->name, "foo"));
23
24         // Disable local discovery.
25
26         mesh.enable_discovery(false);
27
28         // Start and stop the mesh.
29
30         assert(mesh.start());
31         mesh.stop();
32
33         // Make sure we can start and stop the mesh again.
34
35         assert(mesh.start());
36         mesh.stop();
37
38         // Close the mesh and open it again, now with a different name parameter.
39
40         mesh.close();
41         assert(mesh.open("basicpp_conf", "bar", "basicpp", DEV_CLASS_BACKBONE));
42
43         // Check that the name is ignored now, and that we still are "foo".
44
45         assert(!mesh.get_node("bar"));
46         self = mesh.get_self();
47         assert(self);
48         assert(!strcmp(self->name, "foo"));
49
50         // Start and stop the mesh.
51
52         mesh.enable_discovery(false);
53
54         assert(mesh.start());
55         mesh.stop();
56
57         assert(meshlink::destroy("basicpp_conf"));
58         assert(access("basic.conf", F_OK) == -1 && errno == ENOENT);
59
60         return 0;
61 }