aboutsummaryrefslogtreecommitdiffstats
path: root/test.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-04-08 17:45:01 +0200
committerMattias Andrée <maandree@kth.se>2021-04-08 17:45:01 +0200
commit2adf7222ce021748b0edc4a9c5a32375a5b0d124 (patch)
treeb3f0b683a23e969a744fcfdf43352c6498985f69 /test.c
parentAdd readme (diff)
downloadlibcontacts-2adf7222ce021748b0edc4a9c5a32375a5b0d124.tar.gz
libcontacts-2adf7222ce021748b0edc4a9c5a32375a5b0d124.tar.bz2
libcontacts-2adf7222ce021748b0edc4a9c5a32375a5b0d124.tar.xz
Add test for libcontacts_get_path
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'test.c')
-rw-r--r--test.c47
1 files changed, 47 insertions, 0 deletions
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;
+}