]> git.meshlink.io Git - meshlink/blob - test/basicpp.cpp
es compiliert, aber failed immernoch. :-( was ist da los???
[meshlink] / test / basicpp.cpp
1 #include <cstring>
2 #include <iostream>
3
4 #include "meshlink++.h"
5
6 using namespace std;
7
8 int main(int argc, char *argv[]) {
9         // Open a new meshlink instance.
10
11         meshlink::mesh *mesh = meshlink::open<meshlink::mesh>("basicpp_conf", "foo");
12         if(!mesh) {
13                 cerr << "Could not initialize configuration for foo\n";
14                 return 1;
15         }
16
17         // Check that our own node exists.
18
19         meshlink::node *self = mesh->get_node("foo");
20         if(!self) {
21                 cerr << "Foo does not know about itself\n";
22                 return 1;
23         }
24         if(strcmp(self->name, "foo")) {
25                 cerr << "Foo thinks its name is " << self->name << "\n";
26                 return 1;
27         }
28
29         // Start and stop the mesh.
30
31         if(!mesh->start()) {
32                 cerr << "Foo could not start\n";
33                 return 1;
34         }
35         mesh->stop();
36
37         // Make sure we can start and stop the mesh again.
38
39         if(!mesh->start()) {
40                 cerr << "Foo could not start twice\n";
41                 return 1;
42         }
43         mesh->stop();
44
45         // Close the mesh and open it again, now with a different name parameter.
46
47         meshlink::close(mesh);
48
49         // Check that the name is ignored now, and that we still are "foo".
50
51         mesh = meshlink::open<meshlink::mesh>("basic_conf", "bar");
52         if(!mesh) {
53                 cerr << "Could not open configuration for foo a second time\n";
54                 return 1;
55         }
56
57         if(mesh->get_node("bar")) {
58                 cerr << "Foo knows about bar, it shouldn't\n";
59                 return 1;
60         }
61
62         self = mesh->get_node("foo");
63         if(!self) {
64                 cerr << "Foo doesn't know about itself the second time\n";
65                 return 1;
66         }
67         if(strcmp(self->name, "foo")) {
68                 cerr << "Foo thinks its name is " << self->name << " the second time\n";
69                 return 1;
70         }
71
72         // Start and stop the mesh.
73
74         if(!mesh->start()) {
75                 cerr << "Foo could not start a third time\n";
76                 return 1;
77         }
78         mesh->stop();
79
80         // That's it.
81
82         meshlink::close(mesh);
83
84         return 0;
85 }