mirror of
				https://bitbucket.org/jsuto/piler.git
				synced 2025-10-31 02:12:27 +01:00 
			
		
		
		
	| @@ -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 | ||||
|   | ||||
| @@ -2,21 +2,7 @@ | ||||
|  * check_rules.c, SJ | ||||
|  */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
| #include <sys/stat.h> | ||||
| #include <unistd.h> | ||||
| #include <locale.h> | ||||
| #include <stdbool.h> | ||||
| #include <assert.h> | ||||
| #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<sizeof(tests)/sizeof(struct digest_test); i++){ | ||||
|  | ||||
|       if(stat(tests[i].s, &st) != 0){ | ||||
|          fprintf(stderr, "%s is not found, skipping\n", tests[i].s); | ||||
|       if(setup_and_parse_message(&sdata, &state, &data, tests[i].s, cfg) == 1){ | ||||
|          continue; | ||||
|       } | ||||
|  | ||||
|       init_session_data(&sdata, cfg); | ||||
|   | ||||
|       sdata.delivered = 0; | ||||
|       sdata.tot_len = st.st_size; | ||||
|  | ||||
|       snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", tests[i].s); | ||||
|       snprintf(sdata.filename, SMALLBUFSIZE-1, "%s", tests[i].s); | ||||
|       snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", tests[i].s); | ||||
|  | ||||
|       state = parse_message(&sdata, 1, &data, cfg); | ||||
|       post_parse(&sdata, &state, cfg); | ||||
|  | ||||
|       make_digests(&sdata, cfg); | ||||
|  | ||||
|       //printf("%s => body digest: %s, digest: %s\n", tests[i].s, sdata.bodydigest, sdata.digest); | ||||
| @@ -137,4 +108,3 @@ int main(){ | ||||
|  | ||||
|    return 0; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -2,13 +2,7 @@ | ||||
|  * check_mydomains.c, SJ | ||||
|  */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <sys/stat.h> | ||||
| #include <unistd.h> | ||||
| #include <locale.h> | ||||
| #include <stdbool.h> | ||||
| #include <assert.h> | ||||
| #include "../src/piler.h" | ||||
| #include "test.h" | ||||
|  | ||||
|  | ||||
| char *domains[] = { | ||||
| @@ -133,4 +127,3 @@ int main(){ | ||||
|  | ||||
|    return 0; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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<sizeof(tests)/sizeof(struct parser_test); i++){ | ||||
|  | ||||
|       if(stat(tests[i].s, &st) != 0){ | ||||
|          fprintf(stderr, "%s is not found, skipping\n", tests[i].s); | ||||
|       if(setup_and_parse_message(&sdata, &state, &data, tests[i].s, cfg) == 1){ | ||||
|          continue; | ||||
|       } | ||||
|  | ||||
|       init_session_data(&sdata, cfg); | ||||
|   | ||||
|       sdata.delivered = 0; | ||||
|       sdata.tot_len = st.st_size; | ||||
|  | ||||
|       snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", tests[i].s); | ||||
|       snprintf(sdata.filename, SMALLBUFSIZE-1, "%s", tests[i].s); | ||||
|       snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", tests[i].s); | ||||
|  | ||||
|       state = parse_message(&sdata, 1, &data, cfg); | ||||
|       post_parse(&sdata, &state, cfg); | ||||
|  | ||||
|       for(j=1; j<=state.n_attachments; j++){ | ||||
|          unlink(state.attachments[j].internalname); | ||||
|       } | ||||
| @@ -112,5 +97,3 @@ int main(){ | ||||
|  | ||||
|    return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -2,14 +2,7 @@ | ||||
|  * check_rules.c, SJ | ||||
|  */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
| #include <sys/stat.h> | ||||
| #include <unistd.h> | ||||
| #include <locale.h> | ||||
| #include <stdbool.h> | ||||
| #include <assert.h> | ||||
| #include "../src/piler.h" | ||||
| #include "test.h" | ||||
|  | ||||
|  | ||||
| struct rule_test { | ||||
| @@ -178,4 +171,3 @@ int main(){ | ||||
|  | ||||
|    return 0; | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										36
									
								
								unit_tests/common.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								unit_tests/common.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| /* | ||||
|  * common.c | ||||
|  */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
| #include <sys/stat.h> | ||||
| #include <unistd.h> | ||||
| #include <locale.h> | ||||
| #include <stdbool.h> | ||||
| #include <assert.h> | ||||
| #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; | ||||
| } | ||||
| @@ -2,24 +2,7 @@ | ||||
|  * smtp.c, SJ | ||||
|  */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include <sys/time.h> | ||||
| #include <sys/types.h> | ||||
| #include <sys/stat.h> | ||||
| #include <sys/socket.h> | ||||
| #include <netdb.h> | ||||
| #include <arpa/inet.h> | ||||
| #include <netinet/in.h> | ||||
| #include <fcntl.h> | ||||
| #include <locale.h> | ||||
| #include <getopt.h> | ||||
| #include <stdbool.h> | ||||
| #include <assert.h> | ||||
| #include <openssl/ssl.h> | ||||
| #include <openssl/err.h> | ||||
| #include "../src/piler.h" | ||||
| #include "test.h" | ||||
|  | ||||
|  | ||||
| extern char *optarg; | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user