]> git.meshlink.io Git - meshlink/commitdiff
Add test cases for importing/exporting data and inviting/joining nodes.
authorGuus Sliepen <guus@meshlink.io>
Sun, 1 Jun 2014 12:28:34 +0000 (14:28 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sun, 1 Jun 2014 12:28:34 +0000 (14:28 +0200)
test/Makefile.am
test/import-export.c [new file with mode: 0644]
test/import-export.test [new file with mode: 0755]
test/invite-join.c [new file with mode: 0644]
test/invite-join.test [new file with mode: 0755]

index 2b72a0a49b9885f0b905d177c8eb32c1c562cda2..3862607e835e188107b06e6831f61d6a30d905ca 100644 (file)
@@ -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 (file)
index 0000000..f7ecf52
--- /dev/null
@@ -0,0 +1,73 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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 (executable)
index 0000000..48b5753
--- /dev/null
@@ -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 (file)
index 0000000..bf3800e
--- /dev/null
@@ -0,0 +1,66 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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 (executable)
index 0000000..56f2363
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+rm -Rf invite_join_conf*
+./invite-join