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, pdfium_diff_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 actual_path_template = os.path.join(working_dir, input_root + '.pdf.%d.ppm') | 23 actual_path_template = os.path.join(working_dir, input_root + '.pdf.%d.png') |
24 expected_path_template = os.path.join(source_dir, | 24 expected_path_template = os.path.join(source_dir, |
25 input_root + '_expected.pdf.%d.ppm') | 25 input_root + '_expected.pdf.%d.png') |
26 try: | 26 try: |
27 subprocess.check_call( | 27 subprocess.check_call( |
28 [fixup_path, '--output-dir=' + working_dir, input_path]) | 28 [fixup_path, '--output-dir=' + working_dir, input_path]) |
29 subprocess.check_call([pdfium_test_path, '--ppm', pdf_path]) | 29 subprocess.check_call([pdfium_test_path, '--png', pdf_path]) |
30 i = 0; | 30 i = 0; |
31 while True: | 31 while True: |
32 expected_path = expected_path_template % i; | 32 expected_path = expected_path_template % i; |
33 actual_path = actual_path_template % i; | 33 actual_path = actual_path_template % i; |
34 if not os.path.exists(expected_path): | 34 if not os.path.exists(expected_path): |
| 35 if i == 0: |
| 36 print "WARNING: no expected results files found for " + input_filename |
35 break | 37 break |
36 subprocess.check_call(['diff', expected_path, actual_path]) | 38 print "Checking " + actual_path |
| 39 subprocess.check_call([pdfium_diff_path, expected_path, actual_path]) |
37 i += 1 | 40 i += 1 |
38 except subprocess.CalledProcessError as e: | 41 except subprocess.CalledProcessError as e: |
39 print "FAILURE: " + input_filename + "; " + str(e) | 42 print "FAILURE: " + input_filename + "; " + str(e) |
40 | 43 |
41 def main(): | 44 def main(): |
42 parser = optparse.OptionParser() | 45 parser = optparse.OptionParser() |
43 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), | 46 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), |
44 help='relative path from the base source directory') | 47 help='relative path from the base source directory') |
45 options, args = parser.parse_args() | 48 options, args = parser.parse_args() |
46 | 49 |
(...skipping 21 matching lines...) Expand all Loading... |
68 base_dir = pdfium_dir | 71 base_dir = pdfium_dir |
69 one_up_dir = os.path.dirname(base_dir) | 72 one_up_dir = os.path.dirname(base_dir) |
70 two_up_dir = os.path.dirname(one_up_dir) | 73 two_up_dir = os.path.dirname(one_up_dir) |
71 if (os.path.basename(two_up_dir) == 'src' and | 74 if (os.path.basename(two_up_dir) == 'src' and |
72 os.path.basename(one_up_dir) == 'third_party'): | 75 os.path.basename(one_up_dir) == 'third_party'): |
73 base_dir = two_up_dir | 76 base_dir = two_up_dir |
74 build_dir = os.path.join(base_dir, options.build_dir) | 77 build_dir = os.path.join(base_dir, options.build_dir) |
75 | 78 |
76 # Compiled binaries are found under the build path. | 79 # Compiled binaries are found under the build path. |
77 pdfium_test_path = os.path.join(build_dir, 'pdfium_test') | 80 pdfium_test_path = os.path.join(build_dir, 'pdfium_test') |
| 81 pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff') |
78 if sys.platform.startswith('win'): | 82 if sys.platform.startswith('win'): |
79 pdfium_test_path = pdfium_test_path + '.exe' | 83 pdfium_test_path = pdfium_test_path + '.exe' |
| 84 pdfium_diff_path = pdfium_diff_path + '.exe' |
80 # TODO(tsepez): Mac may require special handling here. | 85 # TODO(tsepez): Mac may require special handling here. |
81 | 86 |
82 # Place generated files under the build directory, not source directory. | 87 # Place generated files under the build directory, not source directory. |
83 gen_dir = os.path.join(build_dir, 'gen', 'pdfium') | 88 gen_dir = os.path.join(build_dir, 'gen', 'pdfium') |
84 working_dir = os.path.join(gen_dir, 'testing', 'pixel') | 89 working_dir = os.path.join(gen_dir, 'testing', 'pixel') |
85 if not os.path.exists(working_dir): | 90 if not os.path.exists(working_dir): |
86 os.makedirs(working_dir) | 91 os.makedirs(working_dir) |
87 | 92 |
88 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') | 93 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') |
89 for input_filename in os.listdir(source_dir): | 94 for input_filename in os.listdir(source_dir): |
90 if input_file_re.match(input_filename): | 95 if input_file_re.match(input_filename): |
91 input_path = os.path.join(source_dir, input_filename) | 96 input_path = os.path.join(source_dir, input_filename) |
92 if os.path.isfile(input_path): | 97 if os.path.isfile(input_path): |
93 generate_and_test(input_filename, source_dir, working_dir, | 98 generate_and_test(input_filename, source_dir, working_dir, |
94 fixup_path, pdfium_test_path) | 99 fixup_path, pdfium_test_path, pdfium_diff_path) |
95 return 0 | 100 return 0 |
96 | 101 |
97 | 102 |
98 if __name__ == '__main__': | 103 if __name__ == '__main__': |
99 sys.exit(main()) | 104 sys.exit(main()) |
OLD | NEW |