X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fbasicpp.cpp;h=2f4e5c84a12d727349f751540ac33a60d26c160d;hb=0f0bea383106de1a896905fdf8a56f55265bce74;hp=c52f394ae247871a251d09d283ed713a01e7fb5d;hpb=9a2520c36431a8a5fd90451e97f488c22f4decc5;p=meshlink diff --git a/test/basicpp.cpp b/test/basicpp.cpp index c52f394a..2f4e5c84 100644 --- a/test/basicpp.cpp +++ b/test/basicpp.cpp @@ -3,59 +3,75 @@ #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)); + // Open it without giving a name. - // Check that the name is ignored now, and that we still are "foo". + assert(mesh.open("basicpp_conf", nullptr, "basicpp", DEV_CLASS_BACKBONE)); - assert(!mesh.get_node("bar")); - self = mesh.get_self(); - assert(self); - assert(!strcmp(self->name, "foo")); + // Check that the name is ignored now, and that we still are "foo". - // Start and stop the mesh. + self = mesh.get_self(); + assert(self); + assert(!strcmp(self->name, "foo")); - mesh.enable_discovery(false); + // Start and stop the mesh. - assert(mesh.start()); - mesh.stop(); + mesh.enable_discovery(false); + + 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; }