X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=test%2Fbasicpp.cpp;h=ff49e3d428f749e9d7d9845c6176d494ed47782f;hp=c52f394ae247871a251d09d283ed713a01e7fb5d;hb=6c897377f68fc23ca9a8b23a6ca204517998b2e9;hpb=690df24583e0da336a826b2ad30967cfe9c22277 diff --git a/test/basicpp.cpp b/test/basicpp.cpp index c52f394a..ff49e3d4 100644 --- a/test/basicpp.cpp +++ b/test/basicpp.cpp @@ -3,59 +3,72 @@ #include #include #include +#include #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; }