Skip to content

Commit

Permalink
Added a test for building massive files (#142)
Browse files Browse the repository at this point in the history
* Added a test for building massive files

Not automated yet, just the code
  • Loading branch information
AndreRenaud authored Sep 27, 2023
1 parent 6d0359c commit 7cf4e88
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ endif

TESTPROG=testprog$(EXE_SUFFIX)

default: $(TESTPROG)
default: $(TESTPROG) tests/massive-file$(EXE_SUFFIX)

$(TESTPROG): pdfgen$(O_SUFFIX) tests/main$(O_SUFFIX) tests/penguin$(O_SUFFIX) tests/rgb$(O_SUFFIX)
$(CC) $(CFLAGS_EXE) $@ pdfgen$(O_SUFFIX) tests/main$(O_SUFFIX) tests/penguin$(O_SUFFIX) tests/rgb$(O_SUFFIX) $(LFLAGS)

tests/massive-file$(EXE_SUFFIX): tests/massive-file.c pdfgen.c
$(CC) -I. -g -o $@ tests/massive-file.c pdfgen.c

tests/fuzz-dstr: tests/fuzz-dstr.c pdfgen.c
$(CLANG) -I. -g -o $@ $< -fsanitize=fuzzer,address,undefined,integer

Expand Down Expand Up @@ -66,7 +69,7 @@ check-fuzz-%: tests/fuzz-% FORCE
fuzz-check: check-fuzz-image-data check-fuzz-image-file check-fuzz-header check-fuzz-text check-fuzz-dstr check-fuzz-barcode

format: FORCE
$(CLANG_FORMAT) -i pdfgen.c pdfgen.h tests/main.c tests/fuzz-*.c
$(CLANG_FORMAT) -i pdfgen.c pdfgen.h tests/main.c tests/fuzz-*.c tests/massive-file.c

docs: FORCE
doxygen docs/pdfgen.dox 2>&1 | tee doxygen.log
Expand All @@ -75,5 +78,5 @@ docs: FORCE
FORCE:

clean:
rm -f *$(O_SUFFIX) tests/*$(O_SUFFIX) $(TESTPROG) *.gcda *.gcno *.gcov tests/*.gcda tests/*.gcno output.pdf output.txt tests/fuzz-header tests/fuzz-text tests/fuzz-image-data tests/fuzz-image-file output.pdftk fuzz-image-file.pdf fuzz-image-data.pdf fuzz-image.dat doxygen.log tests/penguin.c fuzz.pdf output.ps output.ppm output-barcodes.txt
rm -f *$(O_SUFFIX) tests/*$(O_SUFFIX) $(TESTPROG) *.gcda *.gcno *.gcov tests/*.gcda tests/*.gcno output.pdf output.txt tests/fuzz-header tests/fuzz-text tests/fuzz-image-data tests/fuzz-image-file test/massive-file output.pdftk fuzz-image-file.pdf fuzz-image-data.pdf fuzz-image.dat doxygen.log tests/penguin.c fuzz.pdf output.ps output.ppm output-barcodes.txt
rm -rf docs/html docs/latex fuzz-artifacts infer-out coverage-html
27 changes: 27 additions & 0 deletions tests/massive-file.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "pdfgen.h"
#include <stdlib.h>

int main(int argc, char **argv)
{
struct pdf_doc *pdf = pdf_create(PDF_A4_WIDTH, PDF_A4_HEIGHT, NULL);
int pagecount = 10;
char filename[128];

if (argc > 1) {
pagecount = atoi(argv[1]);
}
pdf_set_font(pdf, "Times-Roman");
for (int i = 0; i < pagecount; i++) {
char str[64];
pdf_append_page(pdf);
sprintf(str, "page %d", i);
pdf_add_text(pdf, NULL, str, 12, 50, 20, PDF_BLACK);

pdf_add_image_file(pdf, NULL, 100, 500, 50, 150, "data/penguin.jpg");
}

sprintf(filename, "massive-%d.pdf", pagecount);
pdf_save(pdf, filename);
pdf_destroy(pdf);
return 0;
}

0 comments on commit 7cf4e88

Please sign in to comment.