X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fbasicpp.cpp;h=c52f394ae247871a251d09d283ed713a01e7fb5d;hb=9a2520c36431a8a5fd90451e97f488c22f4decc5;hp=e1c103663b91b8e4903b39a20710cb5518e57561;hpb=e84f94c95b02f1ab18f0ab09e8cdc9427b00df14;p=meshlink diff --git a/test/basicpp.cpp b/test/basicpp.cpp index e1c10366..c52f394a 100644 --- a/test/basicpp.cpp +++ b/test/basicpp.cpp @@ -1,85 +1,61 @@ #include #include +#include +#include +#include #include "meshlink++.h" using namespace std; -int main(int argc, char *argv[]) { +int main() { // Open a new meshlink instance. - meshlink::mesh *mesh = meshlink::open("basicpp_conf", "foo", "basicpp"); - if(!mesh) { - cerr << "Could not initialize configuration for foo\n"; - return 1; - } + 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_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")); + + // Disable local discovery. + + mesh.enable_discovery(false); // Start and stop the mesh. - if(!mesh->start()) { - cerr << "Foo could not start\n"; - return 1; - } - mesh->stop(); + 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; - } - mesh->stop(); + assert(mesh.start()); + mesh.stop(); // Close the mesh and open it again, now with a different name parameter. - meshlink::close(mesh); + 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 = meshlink::open("basic_conf", "bar", "basicpp"); - if(!mesh) { - cerr << "Could not open configuration for foo a second time\n"; - return 1; - } - - if(mesh->get_node("bar")) { - cerr << "Foo knows about bar, it shouldn't\n"; - return 1; - } - - 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.get_node("bar")); + self = mesh.get_self(); + assert(self); + assert(!strcmp(self->name, "foo")); // Start and stop the mesh. - if(!mesh->start()) { - cerr << "Foo could not start a third time\n"; - return 1; - } - mesh->stop(); + mesh.enable_discovery(false); - // That's it. + assert(mesh.start()); + mesh.stop(); - meshlink::close(mesh); + assert(meshlink::destroy("basicpp_conf")); + assert(access("basic.conf", F_OK) == -1 && errno == ENOENT); return 0; }