diff --git a/unit_tests/Makefile.in b/unit_tests/Makefile.in index 9dad2c25..cbe53c89 100644 --- a/unit_tests/Makefile.in +++ b/unit_tests/Makefile.in @@ -19,12 +19,13 @@ DEFS = @defs@ INCDIR = -I. -I.. -I../.. -I../../src -I../src @INCDIR@ @sql_includes@ LIBDIR = -L. @LIBDIR@ @LDFLAGS@ -L../src LIBS = @LIBS@ @sql_libs@ +OBJS = common.o RUNNING_USER = @RUNNING_USER@ RUNNING_GROUP = `@id_bin@ -gn $(RUNNING_USER)` INSTALL = @INSTALL@ -all: check_parser_utils check_rules check_digest check_mydomains check_parser check_decoder check_hash check_misc check_attachments smtp +all: $(OBJS) check_parser_utils check_rules check_digest check_mydomains check_parser check_decoder check_hash check_misc check_attachments smtp check_parser_utils: check_parser_utils.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) @@ -33,13 +34,13 @@ check_rules: check_rules.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) check_digest: check_digest.c ../src/libpiler.a - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) + $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< $(OBJS) -lpiler $(LIBS) $(LIBDIR) check_mydomains: check_mydomains.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) check_parser: check_parser.c ../src/libpiler.a - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) + $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< $(OBJS) -lpiler $(LIBS) $(LIBDIR) check_decoder: check_decoder.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) @@ -56,11 +57,14 @@ check_attachments: check_attachments.c ../src/libpiler.a smtp: smtp.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) +%.o: $(srcdir)/%.c + $(CC) $(CFLAGS) -fPIC $(INCDIR) $(DEFS) -c $< -o $@ + install: @echo clean: - rm -f check_parser_utils check_rules check_digest check_mydomains check_parser check_decoder check_hash check_misc check_attachments smtp + rm -f check_parser_utils check_rules check_digest check_mydomains check_parser check_decoder check_hash check_misc check_attachments smtp *.o distclean: clean rm -f Makefile diff --git a/unit_tests/check_digest.c b/unit_tests/check_digest.c index ccd1fa6a..23f490a9 100644 --- a/unit_tests/check_digest.c +++ b/unit_tests/check_digest.c @@ -2,21 +2,7 @@ * check_rules.c, SJ */ -#include -#include -#include -#include -#include -#include -#include -#include "../src/piler.h" - - -struct digest_test { - char s[SMALLBUFSIZE]; - char *digest1; - char *digest2; -}; +#include "test.h" struct digest_test tests[] = { @@ -70,7 +56,6 @@ static void test_make_digests(struct config *cfg){ struct session_data sdata; struct parser_state state; struct data data; - struct stat st; if(open_database(&sdata, cfg) == ERR){ @@ -80,24 +65,10 @@ static void test_make_digests(struct config *cfg){ for(i=0; i body digest: %s, digest: %s\n", tests[i].s, sdata.bodydigest, sdata.digest); @@ -137,4 +108,3 @@ int main(){ return 0; } - diff --git a/unit_tests/check_mydomains.c b/unit_tests/check_mydomains.c index 5ec627f9..3ae726e1 100644 --- a/unit_tests/check_mydomains.c +++ b/unit_tests/check_mydomains.c @@ -2,13 +2,7 @@ * check_mydomains.c, SJ */ -#include -#include -#include -#include -#include -#include -#include "../src/piler.h" +#include "test.h" char *domains[] = { @@ -133,4 +127,3 @@ int main(){ return 0; } - diff --git a/unit_tests/check_parser.c b/unit_tests/check_parser.c index e0833b41..edcb743b 100644 --- a/unit_tests/check_parser.c +++ b/unit_tests/check_parser.c @@ -21,7 +21,6 @@ struct parser_test { static void test_parser(struct config *cfg){ unsigned int i; int j; - struct stat st; struct session_data sdata; struct parser_state state; struct data data; @@ -55,24 +54,10 @@ static void test_parser(struct config *cfg){ for(i=0; i -#include -#include -#include -#include -#include -#include -#include "../src/piler.h" +#include "test.h" struct rule_test { @@ -178,4 +171,3 @@ int main(){ return 0; } - diff --git a/unit_tests/common.c b/unit_tests/common.c new file mode 100644 index 00000000..ca8c4e34 --- /dev/null +++ b/unit_tests/common.c @@ -0,0 +1,36 @@ +/* + * common.c + */ + +#include +#include +#include +#include +#include +#include +#include +#include "../src/piler.h" + + +int setup_and_parse_message(struct session_data *sdata, struct parser_state *state, struct data *data, char *filename, struct config *cfg){ + struct stat st; + + if(stat(filename, &st) != 0){ + fprintf(stderr, "%s is not found, skipping\n", filename); + return 1; + } + + init_session_data(sdata, cfg); + + sdata->delivered = 0; + sdata->tot_len = st.st_size; + + snprintf(sdata->ttmpfile, SMALLBUFSIZE-1, "%s", filename); + snprintf(sdata->filename, SMALLBUFSIZE-1, "%s", filename); + snprintf(sdata->tmpframe, SMALLBUFSIZE-1, "%s.m", filename); + + *state = parse_message(sdata, 1, data, cfg); + post_parse(sdata, state, cfg); + + return 0; +} diff --git a/unit_tests/smtp.c b/unit_tests/smtp.c index 2c7fd3c4..acb6337d 100644 --- a/unit_tests/smtp.c +++ b/unit_tests/smtp.c @@ -2,24 +2,7 @@ * smtp.c, SJ */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../src/piler.h" +#include "test.h" extern char *optarg; diff --git a/unit_tests/test.h b/unit_tests/test.h index f8911b33..7002a098 100644 --- a/unit_tests/test.h +++ b/unit_tests/test.h @@ -50,3 +50,4 @@ struct digest_test { #define TEST_HEADER() printf("%s() ", __func__); #define TEST_FOOTER() printf(" OK\n"); +int setup_and_parse_message(struct session_data *sdata, struct parser_state *state, struct data *data, char *filename, struct config *cfg);