]> git.meshlink.io Git - meshlink/blobdiff - test/basicpp.cpp
Fix all compiler warnings found using -Wall -W -pedantic.
[meshlink] / test / basicpp.cpp
index e1c103663b91b8e4903b39a20710cb5518e57561..4d126cf58dde2e2af42c0beb02317b375e3e8caf 100644 (file)
@@ -1,22 +1,21 @@
 #include <cstring>
 #include <iostream>
+#include <unistd.h>
+#include <cerrno>
 
 #include "meshlink++.h"
 
 using namespace std;
 
-int main(int argc, char *argv[]) {
+int main() {
        // Open a new meshlink instance.
 
-       meshlink::mesh *mesh = meshlink::open<meshlink::mesh>("basicpp_conf", "foo", "basicpp");
-       if(!mesh) {
-               cerr << "Could not initialize configuration for foo\n";
-               return 1;
-       }
+       meshlink::mesh mesh;
+       mesh.open("basicpp_conf", "foo", "basicpp", DEV_CLASS_BACKBONE);
 
        // Check that our own node exists.
 
-       meshlink::node *self = mesh->get_node("foo");
+       meshlink::node *self = mesh.get_self();
        if(!self) {
                cerr << "Foo does not know about itself\n";
                return 1;
@@ -26,40 +25,40 @@ int main(int argc, char *argv[]) {
                return 1;
        }
 
+       // Disable local discovery.
+
+       mesh.enable_discovery(false);
+
        // Start and stop the mesh.
 
-       if(!mesh->start()) {
+       if(!mesh.start()) {
                cerr << "Foo could not start\n";
                return 1;
        }
-       mesh->stop();
+       mesh.stop();
 
        // Make sure we can start and stop the mesh again.
 
-       if(!mesh->start()) {
+       if(!mesh.start()) {
                cerr << "Foo could not start twice\n";
                return 1;
        }
-       mesh->stop();
+       mesh.stop();
 
        // Close the mesh and open it again, now with a different name parameter.
 
-       meshlink::close(mesh);
+       mesh.close();
 
        // Check that the name is ignored now, and that we still are "foo".
 
-       mesh = meshlink::open<meshlink::mesh>("basic_conf", "bar", "basicpp");
-       if(!mesh) {
-               cerr << "Could not open configuration for foo a second time\n";
-               return 1;
-       }
+       mesh.open("basicpp_conf", "bar", "basicpp", DEV_CLASS_BACKBONE);
 
-       if(mesh->get_node("bar")) {
+       if(mesh.get_node("bar")) {
                cerr << "Foo knows about bar, it shouldn't\n";
                return 1;
        }
 
-       self = mesh->get_node("foo");
+       self = mesh.get_self();
        if(!self) {
                cerr << "Foo doesn't know about itself the second time\n";
                return 1;
@@ -71,15 +70,24 @@ int main(int argc, char *argv[]) {
 
        // Start and stop the mesh.
 
-       if(!mesh->start()) {
+       mesh.enable_discovery(false);
+
+       if(!mesh.start()) {
                cerr << "Foo could not start a third time\n";
                return 1;
        }
-       mesh->stop();
 
-       // That's it.
+       mesh.stop();
+
+       if(!meshlink::destroy("basicpp_conf")) {
+               cerr << "Could not destroy configuration\n";
+               return 1;
+       }
 
-       meshlink::close(mesh);
+       if(!access("basic.conf", F_OK) || errno != ENOENT) {
+               cerr << "Configuration not fully destroyed\n";
+               return 1;
+       }
 
        return 0;
 }