From 8ddbb158e37944a852a9b74e3493b3e35df9587a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 28 Jan 2012 19:54:10 +0100 Subject: [PATCH] Implement test suite with check --- Makefile | 5 ++++- README | 1 + config.c | 1 - main.c | 29 +++++++++++++++++++++++++++ tests/Makefile | 50 ++++++++++++++++++++++++++++++++++++++++++++++ tests/config.mk | 6 ++++++ tests/test_utils.c | 31 ++++++++++++++++++++++++++++ tests/tests.c | 22 ++++++++++++++++++++ zathura.c | 23 --------------------- 9 files changed, 143 insertions(+), 25 deletions(-) create mode 100644 main.c create mode 100644 tests/Makefile create mode 100644 tests/config.mk create mode 100644 tests/test_utils.c create mode 100644 tests/tests.c diff --git a/Makefile b/Makefile index ce6e765..1015e41 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ include config.mk include common.mk PROJECT = zathura -SOURCE = $(shell find . -iname "*.c" -a ! -iname "database-*") +SOURCE = $(shell find . -iname "*.c" -a ! -iname "database-*" ! -path "*tests*") OBJECTS = $(patsubst %.c, %.o, $(SOURCE)) DOBJECTS = $(patsubst %.c, %.do, $(SOURCE)) @@ -70,6 +70,9 @@ valgrind: debug gdb: debug cgdb ${PROJECT}-debug +tests: ${OBJECTS} + $(QUIET)make -C tests + dist: clean $(QUIET)mkdir -p ${PROJECT}-${VERSION} $(QUIET)cp -R LICENSE Makefile config.mk README \ diff --git a/README b/README index 34492e0..3192c4d 100644 --- a/README +++ b/README @@ -8,6 +8,7 @@ Requirements gtk2 (>= 2.18.6) girara sqlite3 +check (for tests) Please note that you need to have a working pkg-config installation and that the Makefile is only compatible with GNU make. If you don't have a working diff --git a/config.c b/config.c index 425c58e..0f21cbb 100644 --- a/config.c +++ b/config.c @@ -143,7 +143,6 @@ config_load_default(zathura_t* zathura) girara_inputbar_command_add(gsession, "write!", NULL, cmd_savef, NULL, "Save document (and force overwriting)"); girara_inputbar_command_add(gsession, "export", NULL, cmd_export, cc_export, "Save attachments"); - girara_special_command_add(gsession, '/', cmd_search, true, FORWARD, NULL); girara_special_command_add(gsession, '?', cmd_search, true, BACKWARD, NULL); diff --git a/main.c b/main.c new file mode 100644 index 0000000..be57800 --- /dev/null +++ b/main.c @@ -0,0 +1,29 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include + +#include "zathura.h" + +/* main function */ +int main(int argc, char* argv[]) +{ + g_thread_init(NULL); + gdk_threads_init(); + gtk_init(&argc, &argv); + + zathura_t* zathura = zathura_init(argc, argv); + if (zathura == NULL) { + fprintf(stderr, "error: could not initialize zathura\n"); + return -1; + } + + gdk_threads_enter(); + gtk_main(); + gdk_threads_leave(); + + zathura_free(zathura); + + return 0; +} + diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..adc6262 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,50 @@ +# See LICENSE file for license and copyright information + +include ../config.mk +include ../common.mk +include config.mk + +PROJECT = tests +SOURCE = tests.c $(wildcard test_*.c) +OBJECTS = ${SOURCE:.c=.o} + +ZSOURCE = $(shell find ../ -iname "*.c" -a ! -iname "database-*" ! -iname "main.c" ! -path "*tests*") +ZOBJECTS = ${ZSOURCE:.c=.o} + +ifeq (${DATABASE}, sqlite) +ZSOURCE += ../database-sqlite.c +else +ifeq (${DATABASE}, plain) +ZSOURCE += ../database-plain.c +endif +endif + +all: options ${PROJECT} run + +run: + $(QUIET)./${PROJECT} + +options: + @echo ${PROJECT} build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "DFLAGS = ${DFLAGS}" + @echo "CC = ${CC}" + +%.o: %.c + $(ECHO) CC $< + @mkdir -p .depend + $(QUIET)${CC} -c -I.. ${CPPFLAGS} ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep + +${PROJECT}: ${OBJECTS} + $(ECHO) CC -o $@ + $(QUIET)${CC} ${SFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${ZOBJECTS} ${LIBS} + +${OBJECTS}: ../config.mk + +clean: + $(QUIET)rm -rf ${OBJECTS} ${PROJECT} + +.PHONY: all options clean debug + +-include $(wildcard .depend/*.dep) diff --git a/tests/config.mk b/tests/config.mk new file mode 100644 index 0000000..12780b6 --- /dev/null +++ b/tests/config.mk @@ -0,0 +1,6 @@ +# See LICENSE file for license and copyright information + +CHECK_INC ?= $(shell pkg-config --cflags check) +CHECK_LIB ?= $(shell pkg-config --libs check) + +LIBS += ${CHECK_LIB} diff --git a/tests/test_utils.c b/tests/test_utils.c new file mode 100644 index 0000000..a760e15 --- /dev/null +++ b/tests/test_utils.c @@ -0,0 +1,31 @@ +/* See LICENSE file for license and copyright information */ + +#include + +#include "../utils.h" + +START_TEST(test_file_exists_null) { + fail_unless(file_exists(NULL) == false); +} END_TEST + +START_TEST(test_file_get_extension_null) { + fail_unless(file_get_extension(NULL) == false); +} END_TEST + +Suite* suite_utils() +{ + TCase* tcase = NULL; + Suite* suite = suite_create("Utils"); + + /* file exists */ + tcase = tcase_create("file_exists"); + tcase_add_test(tcase, test_file_exists_null); + suite_add_tcase(suite, tcase); + + /* file exists */ + tcase = tcase_create("file_get_extension"); + tcase_add_test(tcase, test_file_get_extension_null); + suite_add_tcase(suite, tcase); + + return suite; +} diff --git a/tests/tests.c b/tests/tests.c new file mode 100644 index 0000000..f6a8dd6 --- /dev/null +++ b/tests/tests.c @@ -0,0 +1,22 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include + +#define UNUSED(x) GIRARA_UNUSED(x) + +Suite* suite_utils(); + +int main(int UNUSED(argc), char *UNUSED(argv[])) +{ + Suite* suite = NULL; + SRunner* suite_runner = NULL; + + /* test utils */ + suite = suite_utils(); + suite_runner = srunner_create(suite); + srunner_run_all(suite_runner, CK_NORMAL); + srunner_free(suite_runner); + + return 0; +} diff --git a/zathura.c b/zathura.c index 5901c7d..7b84a1a 100644 --- a/zathura.c +++ b/zathura.c @@ -613,26 +613,3 @@ page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) gtk_widget_show_all(zathura->ui.page_view); } - -/* main function */ -int main(int argc, char* argv[]) -{ - g_thread_init(NULL); - gdk_threads_init(); - gtk_init(&argc, &argv); - - zathura_t* zathura = zathura_init(argc, argv); - if (zathura == NULL) { - printf("error: could not initialize zathura\n"); - return -1; - } - - gdk_threads_enter(); - gtk_main(); - gdk_threads_leave(); - - zathura_free(zathura); - - return 0; -} -