X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Finvite-join.c;h=e3f85ed69a09569780b01a977fba402d7cd9d9d8;hb=963c5055505f2fc117cd5efa06eaa02c9b2bf85d;hp=d2f3396657f0606c5953141a4cf76e3b0b38fbe6;hpb=9a2520c36431a8a5fd90451e97f488c22f4decc5;p=meshlink diff --git a/test/invite-join.c b/test/invite-join.c index d2f33966..e3f85ed6 100644 --- a/test/invite-join.c +++ b/test/invite-join.c @@ -1,3 +1,7 @@ +#ifdef NDEBUG +#undef NDEBUG +#endif + #include #include #include @@ -46,7 +50,8 @@ int main() { meshlink_set_node_status_cb(mesh1, status_cb); - meshlink_add_address(mesh1, "localhost"); + assert(meshlink_set_canonical_address(mesh1, meshlink_get_self(mesh1), "localhost", NULL)); + char *baz_url = meshlink_invite(mesh1, NULL, "baz"); assert(baz_url); @@ -136,6 +141,39 @@ int main() { assert(meshlink_join(mesh3, quux_url)); free(quux_url); + // Check that adding duplicate addresses get removed correctly + + assert(meshlink_add_invitation_address(mesh1, "localhost", portstr + 1)); + corge_url = meshlink_invite(mesh1, NULL, "corge"); + assert(corge_url); + char *localhost = strstr(corge_url, "localhost"); + assert(localhost); + assert(!strstr(localhost + 1, "localhost")); + free(corge_url); + + // Check that resetting and adding multiple, different invitation address works + + meshlink_clear_invitation_addresses(mesh1); + assert(meshlink_add_invitation_address(mesh1, "1.invalid.", "12345")); + assert(meshlink_add_invitation_address(mesh1, "2.invalid.", NULL)); + assert(meshlink_add_invitation_address(mesh1, "3.invalid.", NULL)); + assert(meshlink_add_invitation_address(mesh1, "4.invalid.", NULL)); + assert(meshlink_add_invitation_address(mesh1, "5.invalid.", NULL)); + char *grault_url = meshlink_invite(mesh1, NULL, "grault"); + assert(grault_url); + localhost = strstr(grault_url, "localhost"); + assert(localhost); + char *invalid1 = strstr(grault_url, "1.invalid.:12345"); + assert(invalid1); + char *invalid5 = strstr(grault_url, "5.invalid."); + assert(invalid5); + + // Check that explicitly added invitation addresses come before others, in the order they were specified. + + assert(invalid1 < invalid5); + assert(invalid5 < localhost); + free(grault_url); + // Clean up. meshlink_close(mesh3);