mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-26 20:26:01 +01:00
Implement test suite with check
This commit is contained in:
parent
226dfae14c
commit
8ddbb158e3
9 changed files with 143 additions and 25 deletions
5
Makefile
5
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 \
|
||||
|
|
1
README
1
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
|
||||
|
|
1
config.c
1
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);
|
||||
|
||||
|
|
29
main.c
Normal file
29
main.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* See LICENSE file for license and copyright information */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
50
tests/Makefile
Normal file
50
tests/Makefile
Normal file
|
@ -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)
|
6
tests/config.mk
Normal file
6
tests/config.mk
Normal file
|
@ -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}
|
31
tests/test_utils.c
Normal file
31
tests/test_utils.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* See LICENSE file for license and copyright information */
|
||||
|
||||
#include <check.h>
|
||||
|
||||
#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;
|
||||
}
|
22
tests/tests.c
Normal file
22
tests/tests.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* See LICENSE file for license and copyright information */
|
||||
|
||||
#include <check.h>
|
||||
#include <girara/macros.h>
|
||||
|
||||
#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;
|
||||
}
|
23
zathura.c
23
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue