X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fbasicpp.cpp;h=c0550ecf71027e07f1de4cb5f751138c3536419d;hb=4b6c01b1d5383b1a7417244a31ad4652aab2d5db;hp=3a0c75ac016fd4db7a5bf25a26c93b55be0e4246;hpb=89d675c474a6717d9daa8b5d9ff2c0f2c03666f9;p=meshlink diff --git a/test/basicpp.cpp b/test/basicpp.cpp index 3a0c75ac..c0550ecf 100644 --- a/test/basicpp.cpp +++ b/test/basicpp.cpp @@ -2,86 +2,76 @@ #include #include #include +#include +#include #include "meshlink++.h" using namespace std; -int main(int argc, char *argv[]) { +int main(void) { + assert(meshlink::destroy("basicpp_conf")); + // Open a new meshlink instance. - meshlink::mesh mesh; - mesh.open("basicpp_conf", "foo", "basicpp", DEV_CLASS_BACKBONE); + { + 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_node("foo"); - 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; - } + meshlink::node *self = mesh.get_self(); + assert(self); + assert(!strcmp(self->name, "foo")); - // Start and stop the mesh. + // Disable local discovery. - if(!mesh.start()) { - cerr << "Foo could not start\n"; - return 1; - } - mesh.stop(); + mesh.enable_discovery(false); - // Make sure we can start and stop the mesh again. + // Start and stop the mesh. - if(!mesh.start()) { - cerr << "Foo could not start twice\n"; - return 1; - } - mesh.stop(); + assert(mesh.start()); + mesh.stop(); - // Close the mesh and open it again, now with a different name parameter. + // Make sure we can start and stop the mesh again. - mesh.close(); + assert(mesh.start()); + mesh.stop(); - // Check that the name is ignored now, and that we still are "foo". + // Close the mesh and open it again, now with a different name parameter. - mesh.open("basic_conf", "bar", "basicpp", DEV_CLASS_BACKBONE); + mesh.close(); + assert(!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; - } + // Open it without giving a name. - self = mesh.get_node("foo"); - 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(mesh.open("basicpp_conf", nullptr, "basicpp", DEV_CLASS_BACKBONE)); - // Start and stop the mesh. + // Check that the name is ignored now, and that we still are "foo". - if(!mesh.start()) { - cerr << "Foo could not start a third time\n"; - return 1; - } + self = mesh.get_self(); + assert(self); + assert(!strcmp(self->name, "foo")); - mesh.stop(); + // Start and stop the mesh. - if(!meshlink::destroy("basicpp_conf")) { - cerr << "Could not destroy configuration\n"; - return 1; + mesh.enable_discovery(false); + + assert(mesh.start()); + mesh.stop(); } - if(!access("basic.conf", F_OK) || errno != ENOENT) { - cerr << "Configuration not fully destroyed\n"; - return 1; + // Destroy the mesh. + + assert(meshlink::destroy("basicpp_conf")); + + 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; }