X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fencrypted.c;h=ac0dfa92023afdb77a47a49170444b76fc3eeb69;hb=4b6c01b1d5383b1a7417244a31ad4652aab2d5db;hp=e51debd65e210d6b70b4165d5a0dd1e374736812;hpb=fa05f996c5500c056a36c1d43e33a407f876643c;p=meshlink diff --git a/test/encrypted.c b/test/encrypted.c index e51debd6..ac0dfa92 100644 --- a/test/encrypted.c +++ b/test/encrypted.c @@ -1,60 +1,38 @@ +#ifdef NDEBUG +#undef NDEBUG +#endif + #include #include #include #include #include +#include +#include #include "meshlink.h" +#include "utils.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); -} - -int main() { +int main(void) { 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 +40,16 @@ int main() { // Destroy the mesh. - if(!meshlink_destroy("encrypted_conf")) { - fprintf(stderr, "Could not destroy configuration\n"); - return 1; - } + assert(meshlink_destroy("encrypted_conf")); + + DIR *dir = opendir("encrypted_conf"); + assert(dir); + struct dirent *ent; - if(!access("encrypted_conf", F_OK) || errno != ENOENT) { - fprintf(stderr, "Configuration not fully destroyed\n"); - return 1; + while((ent = readdir(dir))) { + fprintf(stderr, "%s\n", ent->d_name); + assert(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")); } - return 0; + closedir(dir); }