]> git.meshlink.io Git - meshlink/blobdiff - test/basicpp.cpp
Use a separate lockfile to lock the configuration directory.
[meshlink] / test / basicpp.cpp
index c52f394ae247871a251d09d283ed713a01e7fb5d..ff49e3d428f749e9d7d9845c6176d494ed47782f 100644 (file)
@@ -3,59 +3,72 @@
 #include <unistd.h>
 #include <cerrno>
 #include <cassert>
+#include <dirent.h>
 
 #include "meshlink++.h"
 
 using namespace std;
 
 int main() {
+       assert(meshlink::destroy("basicpp_conf"));
+
        // Open a new meshlink instance.
 
-       assert(meshlink::destroy("basicpp_conf"));
-       meshlink::mesh mesh("basicpp_conf", "foo", "basicpp", DEV_CLASS_BACKBONE);
-       assert(mesh.isOpen());
+       {
+               meshlink::mesh mesh("basicpp_conf", "foo", "basicpp", DEV_CLASS_BACKBONE);
+               assert(mesh.isOpen());
 
-       // Check that our own node exists.
+               // Check that our own node exists.
 
-       meshlink::node *self = mesh.get_self();
-       assert(self);
-       assert(!strcmp(self->name, "foo"));
+               meshlink::node *self = mesh.get_self();
+               assert(self);
+               assert(!strcmp(self->name, "foo"));
 
-       // Disable local discovery.
+               // Disable local discovery.
 
-       mesh.enable_discovery(false);
+               mesh.enable_discovery(false);
 
-       // Start and stop the mesh.
+               // Start and stop the mesh.
 
-       assert(mesh.start());
-       mesh.stop();
+               assert(mesh.start());
+               mesh.stop();
 
-       // Make sure we can start and stop the mesh again.
+               // Make sure we can start and stop the mesh again.
 
-       assert(mesh.start());
-       mesh.stop();
+               assert(mesh.start());
+               mesh.stop();
 
-       // Close the mesh and open it again, now with a different name parameter.
+               // 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));
+               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".
+               // Check that the name is ignored now, and that we still are "foo".
 
-       assert(!mesh.get_node("bar"));
-       self = mesh.get_self();
-       assert(self);
-       assert(!strcmp(self->name, "foo"));
+               assert(!mesh.get_node("bar"));
+               self = mesh.get_self();
+               assert(self);
+               assert(!strcmp(self->name, "foo"));
 
-       // Start and stop the mesh.
+               // Start and stop the mesh.
 
-       mesh.enable_discovery(false);
+               mesh.enable_discovery(false);
 
-       assert(mesh.start());
-       mesh.stop();
+               assert(mesh.start());
+               mesh.stop();
+       }
+
+       // Destroy the mesh.
 
        assert(meshlink::destroy("basicpp_conf"));
-       assert(access("basic.conf", F_OK) == -1 && errno == ENOENT);
+
+       DIR *dir = opendir("basicpp_conf");
+       assert(dir);
+       struct dirent *ent;
+       while((ent = readdir(dir))) {
+               assert(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."));
+       }
+       closedir(dir);
 
        return 0;
 }