X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=test%2Fencrypted.c;h=17b2fd80a7fc81f1a11ffdd30672758f97b2929a;hp=e51debd65e210d6b70b4165d5a0dd1e374736812;hb=9a2520c36431a8a5fd90451e97f488c22f4decc5;hpb=ea20fcfcded669ce8fbbda3a1f93f354ed254603 diff --git a/test/encrypted.c b/test/encrypted.c index e51debd6..17b2fd80 100644 --- a/test/encrypted.c +++ b/test/encrypted.c @@ -3,58 +3,31 @@ #include #include #include +#include #include "meshlink.h" - -void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - static struct timeval tv0; - struct timeval tv; - - if(tv0.tv_sec == 0) { - gettimeofday(&tv0, NULL); - } - - gettimeofday(&tv, NULL); - fprintf(stderr, "%u.%.03u ", (unsigned int)(tv.tv_sec - tv0.tv_sec), (unsigned int)tv.tv_usec / 1000); - - if(mesh) { - fprintf(stderr, "(%s) ", mesh->name); - } - - fprintf(stderr, "[%d] %s\n", level, text); -} +#include "utils.h" int main() { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Open a new meshlink instance. + assert(meshlink_destroy("encrypted_conf")); meshlink_handle_t *mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5); - - if(!mesh) { - fprintf(stderr, "Could not initialize configuration for foo\n"); - return 1; - } + assert(mesh); // Close the mesh and open it again, now with a different key. meshlink_close(mesh); mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "wrong", 5); - - if(mesh) { - fprintf(stderr, "Could open mesh with the wrong key\n"); - return 1; - } + assert(!mesh); // Open it again, now with the right key. mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5); - - if(!mesh) { - fprintf(stderr, "Could not open mesh with the right key\n"); - return 1; - } + assert(mesh); // That's it. @@ -62,15 +35,6 @@ int main() { // Destroy the mesh. - if(!meshlink_destroy("encrypted_conf")) { - fprintf(stderr, "Could not destroy configuration\n"); - return 1; - } - - if(!access("encrypted_conf", F_OK) || errno != ENOENT) { - fprintf(stderr, "Configuration not fully destroyed\n"); - return 1; - } - - return 0; + assert(meshlink_destroy("encrypted_conf")); + assert(access("encrypted_conf", F_OK) == -1 && errno == ENOENT); }