| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The PDFium Authors. All rights reserved. | 2 # Copyright 2015 The PDFium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import optparse | 6 import optparse |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| 11 | 11 |
| 12 # Nomenclature: | 12 # Nomenclature: |
| 13 # x_root - "x" | 13 # x_root - "x" |
| 14 # x_filename - "x.ext" | 14 # x_filename - "x.ext" |
| 15 # x_path - "path/to/a/b/c/x.ext" | 15 # x_path - "path/to/a/b/c/x.ext" |
| 16 # c_dir - "path/to/a/b/c" | 16 # c_dir - "path/to/a/b/c" |
| 17 | 17 |
| 18 def generate_and_test(input_filename, source_dir, working_dir, | 18 def generate_and_test(input_filename, source_dir, working_dir, |
| 19 fixup_path, pdfium_test_path): | 19 fixup_path, pdfium_test_path): |
| 20 input_root, _ = os.path.splitext(input_filename) | 20 input_root, _ = os.path.splitext(input_filename) |
| 21 input_path = os.path.join(source_dir, input_root + '.in') | 21 input_path = os.path.join(source_dir, input_root + '.in') |
| 22 pdf_path = os.path.join(working_dir, input_root + '.pdf') | 22 pdf_path = os.path.join(working_dir, input_root + '.pdf') |
| 23 txt_path = os.path.join(working_dir, input_root + '.txt') | 23 txt_path = os.path.join(working_dir, input_root + '.txt') |
| 24 expected_path = os.path.join(source_dir, input_root + '_expected.txt') | 24 expected_path = os.path.join(source_dir, input_root + '_expected.txt') |
| 25 try: | 25 try: |
| 26 sys.stdout.flush() |
| 26 subprocess.check_call( | 27 subprocess.check_call( |
| 27 [fixup_path, '--output-dir=' + working_dir, input_path]) | 28 [fixup_path, '--output-dir=' + working_dir, input_path]) |
| 28 with open(txt_path, 'w') as outfile: | 29 with open(txt_path, 'w') as outfile: |
| 29 subprocess.check_call([pdfium_test_path, pdf_path], stdout=outfile) | 30 subprocess.check_call([pdfium_test_path, pdf_path], stdout=outfile) |
| 30 subprocess.check_call(['diff', expected_path, txt_path]) | 31 subprocess.check_call(['diff', expected_path, txt_path]) |
| 31 except subprocess.CalledProcessError as e: | 32 except subprocess.CalledProcessError as e: |
| 32 print "FAILURE: " + input_filename + "; " + str(e) | 33 print "FAILURE: " + input_filename + "; " + str(e) |
| 33 return False | 34 return False |
| 34 return True | 35 return True |
| 35 | 36 |
| 36 def main(): | 37 def main(): |
| 37 parser = optparse.OptionParser() | 38 parser = optparse.OptionParser() |
| 38 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), | 39 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), |
| 39 help='relative path from the base source directory') | 40 help='relative path from the base source directory') |
| 40 options, args = parser.parse_args() | 41 options, args = parser.parse_args() |
| 41 | 42 |
| 42 # Expect |my_dir| to be .../pdfium/testing/tools. | 43 # Expect |my_dir| to be .../pdfium/testing/tools. |
| 43 my_dir = os.path.dirname(os.path.realpath(__file__)) | 44 my_dir = os.path.dirname(os.path.realpath(__file__)) |
| 44 testing_dir = os.path.dirname(my_dir) | 45 testing_dir = os.path.dirname(my_dir) |
| 45 pdfium_dir = os.path.dirname(testing_dir) | 46 pdfium_dir = os.path.dirname(testing_dir) |
| 46 if (os.path.basename(my_dir) != 'tools' or | 47 if (os.path.basename(my_dir) != 'tools' or |
| 47 os.path.basename(testing_dir) != 'testing'): | 48 os.path.basename(testing_dir) != 'testing'): |
| 48 print 'Confused, can not find pdfium root directory, aborting.' | 49 print 'Confused, can not find pdfium root directory, aborting.' |
| 49 return 1 | 50 return 2 |
| 50 | 51 |
| 51 # Other scripts are found in the same directory as this one. | 52 # Other scripts are found in the same directory as this one. |
| 52 fixup_path = os.path.join(my_dir, 'fixup_pdf_template.py') | 53 fixup_path = os.path.join(my_dir, 'fixup_pdf_template.py') |
| 53 | 54 |
| 54 # test files are in .../pdfium/testing/resources/javascript. | 55 # test files are in .../pdfium/testing/resources/javascript. |
| 55 source_dir = os.path.join(testing_dir, 'resources', 'javascript') | 56 source_dir = os.path.join(testing_dir, 'resources', 'javascript') |
| 56 | 57 |
| 57 # Find path to build directory. This depends on whether this is a | 58 # Find path to build directory. This depends on whether this is a |
| 58 # standalone build vs. a build as part of a chromium checkout. For | 59 # standalone build vs. a build as part of a chromium checkout. For |
| 59 # standalone, we expect a path like .../pdfium/out/Debug, but for | 60 # standalone, we expect a path like .../pdfium/out/Debug, but for |
| (...skipping 13 matching lines...) Expand all Loading... |
| 73 if sys.platform.startswith('win'): | 74 if sys.platform.startswith('win'): |
| 74 pdfium_test_path = pdfium_test_path + '.exe' | 75 pdfium_test_path = pdfium_test_path + '.exe' |
| 75 # TODO(tsepez): Mac may require special handling here. | 76 # TODO(tsepez): Mac may require special handling here. |
| 76 | 77 |
| 77 # Place generated files under the build directory, not source directory. | 78 # Place generated files under the build directory, not source directory. |
| 78 gen_dir = os.path.join(build_dir, 'gen', 'pdfium') | 79 gen_dir = os.path.join(build_dir, 'gen', 'pdfium') |
| 79 working_dir = os.path.join(gen_dir, 'testing', 'javascript') | 80 working_dir = os.path.join(gen_dir, 'testing', 'javascript') |
| 80 if not os.path.exists(working_dir): | 81 if not os.path.exists(working_dir): |
| 81 os.makedirs(working_dir) | 82 os.makedirs(working_dir) |
| 82 | 83 |
| 83 os_exit_code = 0 | 84 failures = [] |
| 84 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') | 85 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') |
| 85 for input_filename in os.listdir(source_dir): | 86 for input_filename in os.listdir(source_dir): |
| 86 if input_file_re.match(input_filename): | 87 if input_file_re.match(input_filename): |
| 87 input_path = os.path.join(source_dir, input_filename) | 88 input_path = os.path.join(source_dir, input_filename) |
| 88 if os.path.isfile(input_path): | 89 if os.path.isfile(input_path): |
| 89 if not generate_and_test(input_filename, source_dir, working_dir, | 90 if not generate_and_test(input_filename, source_dir, working_dir, |
| 90 fixup_path, pdfium_test_path): | 91 fixup_path, pdfium_test_path): |
| 91 os_exit_code = 1 | 92 failures.append(input_path) |
| 92 | 93 |
| 93 return os_exit_code | 94 if failures: |
| 95 print '\n\nSummary of Failures:' |
| 96 for failure in failures: |
| 97 print failure |
| 98 return 2 |
| 99 return 0 |
| 94 | 100 |
| 95 | 101 |
| 96 if __name__ == '__main__': | 102 if __name__ == '__main__': |
| 97 sys.exit(main()) | 103 sys.exit(main()) |
| OLD | NEW |