]> git.meshlink.io Git - meshlink/blobdiff - test/basicpp.cpp
Refactor the non-blackbox test suite.
[meshlink] / test / basicpp.cpp
index 4d126cf58dde2e2af42c0beb02317b375e3e8caf..c52f394ae247871a251d09d283ed713a01e7fb5d 100644 (file)
@@ -2,6 +2,7 @@
 #include <iostream>
 #include <unistd.h>
 #include <cerrno>
+#include <cassert>
 
 #include "meshlink++.h"
 
@@ -10,20 +11,15 @@ using namespace std;
 int main() {
        // Open a new meshlink instance.
 
-       meshlink::mesh mesh;
-       mesh.open("basicpp_conf", "foo", "basicpp", DEV_CLASS_BACKBONE);
+       assert(meshlink::destroy("basicpp_conf"));
+       meshlink::mesh mesh("basicpp_conf", "foo", "basicpp", DEV_CLASS_BACKBONE);
+       assert(mesh.isOpen());
 
        // Check that our own node exists.
 
        meshlink::node *self = mesh.get_self();
-       if(!self) {
-               cerr << "Foo does not know about itself\n";
-               return 1;
-       }
-       if(strcmp(self->name, "foo")) {
-               cerr << "Foo thinks its name is " << self->name << "\n";
-               return 1;
-       }
+       assert(self);
+       assert(!strcmp(self->name, "foo"));
 
        // Disable local discovery.
 
@@ -31,63 +27,35 @@ int main() {
 
        // Start and stop the mesh.
 
-       if(!mesh.start()) {
-               cerr << "Foo could not start\n";
-               return 1;
-       }
+       assert(mesh.start());
        mesh.stop();
 
        // Make sure we can start and stop the mesh again.
 
-       if(!mesh.start()) {
-               cerr << "Foo could not start twice\n";
-               return 1;
-       }
+       assert(mesh.start());
        mesh.stop();
 
        // Close the mesh and open it again, now with a different name parameter.
 
        mesh.close();
+       assert(mesh.open("basicpp_conf", "bar", "basicpp", DEV_CLASS_BACKBONE));
 
        // Check that the name is ignored now, and that we still are "foo".
 
-       mesh.open("basicpp_conf", "bar", "basicpp", DEV_CLASS_BACKBONE);
-
-       if(mesh.get_node("bar")) {
-               cerr << "Foo knows about bar, it shouldn't\n";
-               return 1;
-       }
-
+       assert(!mesh.get_node("bar"));
        self = mesh.get_self();
-       if(!self) {
-               cerr << "Foo doesn't know about itself the second time\n";
-               return 1;
-       }
-       if(strcmp(self->name, "foo")) {
-               cerr << "Foo thinks its name is " << self->name << " the second time\n";
-               return 1;
-       }
+       assert(self);
+       assert(!strcmp(self->name, "foo"));
 
        // Start and stop the mesh.
 
        mesh.enable_discovery(false);
 
-       if(!mesh.start()) {
-               cerr << "Foo could not start a third time\n";
-               return 1;
-       }
-
+       assert(mesh.start());
        mesh.stop();
 
-       if(!meshlink::destroy("basicpp_conf")) {
-               cerr << "Could not destroy configuration\n";
-               return 1;
-       }
-
-       if(!access("basic.conf", F_OK) || errno != ENOENT) {
-               cerr << "Configuration not fully destroyed\n";
-               return 1;
-       }
+       assert(meshlink::destroy("basicpp_conf"));
+       assert(access("basic.conf", F_OK) == -1 && errno == ENOENT);
 
        return 0;
 }