From: Guus Sliepen Date: Sun, 1 Jun 2014 12:28:34 +0000 (+0200) Subject: Add test cases for importing/exporting data and inviting/joining nodes. X-Git-Url: http://git.meshlink.io/?a=commitdiff_plain;h=c2b5ef48a8433db03569f621a431857d06fe1d85;hp=132c36964b2538409bbbd0b3d43386d9077a5e07;p=meshlink Add test cases for importing/exporting data and inviting/joining nodes. --- diff --git a/test/Makefile.am b/test/Makefile.am index 2b72a0a4..3862607e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,11 +1,19 @@ TESTS = \ - basic.test + basic.test \ + import-export.test \ + invite-join.test dist_check_SCRIPTS = $(TESTS) AM_CPPFLAGS = -I../src -check_PROGRAMS = basic +check_PROGRAMS = basic import-export invite-join basic_SOURCES = basic.c basic_LDADD = ../src/libmeshlink.la + +import_export_SOURCES = import-export.c +import_export_LDADD = ../src/libmeshlink.la + +invite_join_SOURCES = invite-join.c +invite_join_LDADD = ../src/libmeshlink.la diff --git a/test/import-export.c b/test/import-export.c new file mode 100644 index 00000000..f7ecf521 --- /dev/null +++ b/test/import-export.c @@ -0,0 +1,73 @@ +#include +#include +#include + +#include "meshlink.h" + +volatile bool bar_reachable = false; + +void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { + if(!strcmp(node->name, "bar")) + bar_reachable = reachable; +} + +int main(int argc, char *argv[]) { + // Open two new meshlink instance. + + meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo"); + if(!mesh1) + return 1; + + meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar"); + if(!mesh2) + return 1; + + // Import and export both side's data + + meshlink_add_address(mesh1, "localhost"); + meshlink_add_address(mesh2, "localhost"); + + char *data = meshlink_export(mesh1); + + if(!meshlink_import(mesh2, data)) + return 1; + + free(data); + + data = meshlink_export(mesh2); + + if(!meshlink_import(mesh1, data)) + return 1; + + free(data); + + // Start both instances + + meshlink_set_node_status_cb(mesh1, status_cb); + + if(!meshlink_start(mesh1)) + return 1; + + if(!meshlink_start(mesh2)) + return 1; + + // Wait for the two to connect. + + for(int i = 0; i < 20; i++) { + sleep(1); + if(bar_reachable) + break; + } + + if(!bar_reachable) + return 1; + + // Clean up. + + meshlink_stop(mesh2); + meshlink_stop(mesh1); + meshlink_close(mesh2); + meshlink_close(mesh1); + + return 0; +} diff --git a/test/import-export.test b/test/import-export.test new file mode 100755 index 00000000..48b57536 --- /dev/null +++ b/test/import-export.test @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -Rf import_export_conf* +./import-export diff --git a/test/invite-join.c b/test/invite-join.c new file mode 100644 index 00000000..bf3800e3 --- /dev/null +++ b/test/invite-join.c @@ -0,0 +1,66 @@ +#include +#include +#include + +#include "meshlink.h" + +volatile bool baz_reachable = false; + +void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { + if(!strcmp(node->name, "baz")) + baz_reachable = reachable; +} + +int main(int argc, char *argv[]) { + // Open two new meshlink instance. + + meshlink_handle_t *mesh1 = meshlink_open("invite_join_conf.1", "foo"); + if(!mesh1) + return 1; + + meshlink_handle_t *mesh2 = meshlink_open("invite_join_conf.2", "bar"); + if(!mesh2) + return 1; + + // Start the first instance and have it generate an invitation. + + meshlink_set_node_status_cb(mesh1, status_cb); + + if(!meshlink_start(mesh1)) + return 1; + + meshlink_add_address(mesh1, "localhost"); + char *url = meshlink_invite(mesh1, "baz"); + if(!url) + return 1; + + // Have the second instance join the first. + + if(!meshlink_join(mesh2, url)) + return 1; + + free(url); + + if(!meshlink_start(mesh2)) + return 1; + + // Wait for the two to connect. + + for(int i = 0; i < 20; i++) { + sleep(1); + if(baz_reachable) + break; + } + + if(!baz_reachable) + return 1; + + // Clean up. + + meshlink_stop(mesh2); + meshlink_stop(mesh1); + meshlink_close(mesh2); + meshlink_close(mesh1); + + return 0; +} diff --git a/test/invite-join.test b/test/invite-join.test new file mode 100755 index 00000000..56f2363b --- /dev/null +++ b/test/invite-join.test @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -Rf invite_join_conf* +./invite-join