diff options
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | libcontacts.h | 2 | ||||
-rw-r--r-- | test.c | 47 |
5 files changed, 62 insertions, 5 deletions
@@ -7,3 +7,5 @@ *.lo *.dll *.dylib +/test +/.testdir @@ -43,8 +43,9 @@ HDR =\ LOBJ = $(OBJ:.o=.lo) -all: libcontacts.a libcontacts.$(LIBEXT) +all: libcontacts.a libcontacts.$(LIBEXT) test $(OBJ): $($@:.o=.c) $(HDR) +test.o: test.c $(HDR) libcontacts.a: $(OBJ) -rm -f -- $@ @@ -60,6 +61,14 @@ libcontacts.$(LIBEXT): $(LOBJ) .c.lo: $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS) +test: test.o libcontacts.a + $(CC) -o $@ test.o libcontacts.a $(LDFLAGS) + +check: test + @rm -rf -- .testdir + ./test + @rm -rf -- .testdir + install: libcontacts.a libcontacts.$(LIBEXT) mkdir -p -- "$(DESTDIR)$(PREFIX)/lib" mkdir -p -- "$(DESTDIR)$(PREFIX)/include" @@ -77,9 +86,9 @@ uninstall: -rm -f -- "$(DESTDIR)$(PREFIX)/include/libcontacts.h" clean: - -rm -f -- *.o *.a *.lo *.so *.dylib *.dll *.su + -rm -rf -- *.o *.a *.lo *.so *.dylib *.dll *.su test .testdir .SUFFIXES: .SUFFIXES: .c .o .lo -.PHONY: all install uninstall clean +.PHONY: all check install uninstall clean @@ -1,3 +1,2 @@ Add support for different calendars Add man pages -Add tests diff --git a/libcontacts.h b/libcontacts.h index 6eb4054..877840d 100644 --- a/libcontacts.h +++ b/libcontacts.h @@ -295,7 +295,7 @@ int libcontacts_list_contacts(char ***, const struct passwd *); int libcontacts_load_contact(const char *, struct libcontacts_contact *, const struct passwd *); /* errno = 0 if malformatted */ int libcontacts_load_contacts(struct libcontacts_contact ***, const struct passwd *); int libcontacts_save_contact(struct libcontacts_contact *, const struct passwd *); -int libcontacts_same_number(const char *, const char *, const char *, const char *); +int libcontacts_same_number(const char *, const char *, const char *, const char *); /* might be removed in the future */ char *libcontacts_get_path(const char *, const struct passwd *); int libcontacts_parse_contact(char *, struct libcontacts_contact *); /* does not load .id, not stored in file, but is the filename */ @@ -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; +} |