diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/samples/descriptions.txt | 7 | ||||
-rw-r--r-- | tests/samples/test1.pdf | bin | 0 -> 247680 bytes | |||
-rw-r--r-- | tests/samples/test1.zip | bin | 0 -> 1425748 bytes | |||
-rw-r--r-- | tests/samples/test1_normalized.pdf | bin | 0 -> 166153 bytes | |||
-rwxr-xr-x | tests/test_pdf_add_data.py | 21 | ||||
-rwxr-xr-x | tests/test_pdf_normalisation.py | 26 | ||||
-rwxr-xr-x | tests/test_pdf_rebuild.py | 19 | ||||
-rwxr-xr-x | tests/test_polyglot_pdfzip.py | 23 | ||||
-rwxr-xr-x | tests/test_rebuild_zip.py | 20 | ||||
-rwxr-xr-x | tests/test_zip.py | 21 |
10 files changed, 137 insertions, 0 deletions
diff --git a/tests/samples/descriptions.txt b/tests/samples/descriptions.txt new file mode 100644 index 0000000..6d57430 --- /dev/null +++ b/tests/samples/descriptions.txt @@ -0,0 +1,7 @@ +== Zip files == + +test1.zip: deux fichiers et commentaire global. + +== Pdf files == + +test1.pdf: fichier des impots.
\ No newline at end of file diff --git a/tests/samples/test1.pdf b/tests/samples/test1.pdf Binary files differnew file mode 100644 index 0000000..3e79ae1 --- /dev/null +++ b/tests/samples/test1.pdf diff --git a/tests/samples/test1.zip b/tests/samples/test1.zip Binary files differnew file mode 100644 index 0000000..cd93f9d --- /dev/null +++ b/tests/samples/test1.zip diff --git a/tests/samples/test1_normalized.pdf b/tests/samples/test1_normalized.pdf Binary files differnew file mode 100644 index 0000000..e955cb1 --- /dev/null +++ b/tests/samples/test1_normalized.pdf diff --git a/tests/test_pdf_add_data.py b/tests/test_pdf_add_data.py new file mode 100755 index 0000000..eb12d93 --- /dev/null +++ b/tests/test_pdf_add_data.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sys +sys.path.append("../") + +import logging +from PdfFileTransformer import Pdf + + +input_file = "./samples/test1.pdf" +output_file = "./samples/test1_out.pdf" + +logging.basicConfig(level=logging.DEBUG) + +p = Pdf(input_file) +p.insert_new_obj_stream_at_start(b'A' * 140) +p.insert_new_obj_stream_at_end(b'B' * 120) +f = open(output_file, 'wb') +f.write(p.get_build_buffer()) +f.close() diff --git a/tests/test_pdf_normalisation.py b/tests/test_pdf_normalisation.py new file mode 100755 index 0000000..aba197e --- /dev/null +++ b/tests/test_pdf_normalisation.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sys +sys.path.append("../") +import logging +from PdfFileTransformer.PyPDF2 import PdfFileReader, PdfFileWriter + + +input_file = "./samples/test1.pdf" +output_file = "./samples/test1_out.pdf" + +logging.basicConfig(level=logging.DEBUG) + +f_input = open(input_file, "rb") +reader = PdfFileReader(f_input) + +f_output = open(output_file, "wb") +writer = PdfFileWriter() + +writer.appendPagesFromReader(reader) +writer.setHeader(b"%PDF-1.5") +writer.write(f_output) + +f_input.close() +f_output.close() diff --git a/tests/test_pdf_rebuild.py b/tests/test_pdf_rebuild.py new file mode 100755 index 0000000..29b31c3 --- /dev/null +++ b/tests/test_pdf_rebuild.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sys +sys.path.append("../") + +from PdfFileTransformer import Pdf +import logging + +input_file = "./samples/test1.pdf" +output_file = "./samples/test1_out.pdf" + +logging.basicConfig(level=logging.DEBUG) + + +p = Pdf(input_file) +f = open(output_file, 'wb') +f.write(p.get_build_buffer()) +f.close() diff --git a/tests/test_polyglot_pdfzip.py b/tests/test_polyglot_pdfzip.py new file mode 100755 index 0000000..f4a3ff2 --- /dev/null +++ b/tests/test_polyglot_pdfzip.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sys +sys.path.append("../") + +from PdfFileTransformer import Pdf +from ZipFileTransformer import Zip +from PolyglotFile import PolyglotPdfZip +import logging + +input_file_pdf = "./samples/test1.pdf" +input_file_zip = "./samples/test1.zip" +output_file = "./samples/test1_out.pdf" + +logging.basicConfig(level=logging.DEBUG) + + +p = Pdf(input_file_pdf) +z = Zip(input_file_zip) +a = PolyglotPdfZip(p, z) +a.generate() +a.write(output_file) diff --git a/tests/test_rebuild_zip.py b/tests/test_rebuild_zip.py new file mode 100755 index 0000000..ceb04a1 --- /dev/null +++ b/tests/test_rebuild_zip.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sys +sys.path.append("../") + +import tempfile + +from ZipFileTransformer import Zip, ZipFile + +input_file = "./samples/test1.zip" +output_file = "./samples/test1_out.zip" + +zi = ZipFile(input_file,"r") +zo = ZipFile(output_file,"w") +zo.writestr(' ',b'AAAAAAAAAAAAAAAAAAAAAA',0) +for zipinfo in zi.infolist(): + zo.writestr(zipinfo, zi.read(zipinfo)) +zi.close() +zo.close()
\ No newline at end of file diff --git a/tests/test_zip.py b/tests/test_zip.py new file mode 100755 index 0000000..81b8f6e --- /dev/null +++ b/tests/test_zip.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sys +sys.path.append("../") + +import tempfile + +from ZipFileTransformer import Zip + +input_file = "./samples/test1.zip" +output_file = tempfile.mktemp() +print("Output: " + output_file) + +z = Zip(input_file) +a = bytearray(b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA') +b = bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB') +z.add_data_to_file(a, b, False) +g = open(output_file, "wb") +g.write(a + z.get_local_file_data() + b + z.get_data_after_central_directory()) +g.close() |