]> git.meshlink.io Git - meshlink/blob - test/basicpp.cpp
Add support for black/whitelisting by name, and forgetting nodes.
[meshlink] / test / basicpp.cpp
1 #include <cstring>
2 #include <iostream>
3 #include <unistd.h>
4 #include <cerrno>
5 #include <cassert>
6 #include <dirent.h>
7
8 #include "meshlink++.h"
9
10 using namespace std;
11
12 int main() {
13         assert(meshlink::destroy("basicpp_conf"));
14
15         // Open a new meshlink instance.
16
17         {
18                 meshlink::mesh mesh("basicpp_conf", "foo", "basicpp", DEV_CLASS_BACKBONE);
19                 assert(mesh.isOpen());
20
21                 // Check that our own node exists.
22
23                 meshlink::node *self = mesh.get_self();
24                 assert(self);
25                 assert(!strcmp(self->name, "foo"));
26
27                 // Disable local discovery.
28
29                 mesh.enable_discovery(false);
30
31                 // Start and stop the mesh.
32
33                 assert(mesh.start());
34                 mesh.stop();
35
36                 // Make sure we can start and stop the mesh again.
37
38                 assert(mesh.start());
39                 mesh.stop();
40
41                 // Close the mesh and open it again, now with a different name parameter.
42
43                 mesh.close();
44                 assert(mesh.open("basicpp_conf", "bar", "basicpp", DEV_CLASS_BACKBONE));
45
46                 // Check that the name is ignored now, and that we still are "foo".
47
48                 assert(!mesh.get_node("bar"));
49                 self = mesh.get_self();
50                 assert(self);
51                 assert(!strcmp(self->name, "foo"));
52
53                 // Start and stop the mesh.
54
55                 mesh.enable_discovery(false);
56
57                 assert(mesh.start());
58                 mesh.stop();
59         }
60
61         // Destroy the mesh.
62
63         assert(meshlink::destroy("basicpp_conf"));
64
65         DIR *dir = opendir("basicpp_conf");
66         assert(dir);
67         struct dirent *ent;
68         while((ent = readdir(dir))) {
69                 assert(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."));
70         }
71         closedir(dir);
72
73         return 0;
74 }