From 2adf7222ce021748b0edc4a9c5a32375a5b0d124 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 8 Apr 2021 17:45:01 +0200 Subject: Add test for libcontacts_get_path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- test.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test.c (limited to 'test.c') diff --git a/test.c b/test.c new file mode 100644 index 0000000..fd3c3db --- /dev/null +++ b/test.c @@ -0,0 +1,47 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +#define TEST(EXPR)\ + do {\ + errno = 0;\ + if (EXPR)\ + break;\ + fprintf(stderr, "Failure at line %i, with errno = %i (%s): %s\n", __LINE__, errno, strerror(errno), #EXPR);\ + exit(1);\ + } while (0) + + +int +main(void) +{ + struct passwd user; + char *s; + + TEST(libcontacts_get_path("", NULL) == NULL && errno == EINVAL); + memset(&user, 0, sizeof(user)); + TEST(libcontacts_get_path("", &user) == NULL && errno == EINVAL); + user.pw_dir = ""; + TEST(libcontacts_get_path("", &user) == NULL && errno == EINVAL); + user.pw_dir = "/var/empty"; + TEST(libcontacts_get_path(NULL, &user) == NULL && errno == EINVAL); + user.pw_dir = "/var/empty"; + TEST((s = libcontacts_get_path("", &user)) && !strcmp(s, "/var/empty/.config/contacts/")); + free(s); + TEST((s = libcontacts_get_path("someone", &user)) && !strcmp(s, "/var/empty/.config/contacts/someone")); + free(s); + /* TODO test ENOMEM case */ + + user.pw_dir = ".testdir"; + TEST(!mkdir(user.pw_dir, 0777)); + + /* TODO test libcontacts_list_contacts */ + /* TODO test libcontacts_parse_contact */ + /* TODO test libcontacts_load_contact */ + /* TODO test libcontacts_load_contacts */ + /* TODO test libcontacts_format_contact */ + /* TODO test libcontacts_save_contact */ + + /* TODO check for memory leaks */ + return 0; +} -- cgit v1.2.3-70-g09d2