| 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 os | 6 import os |
| 7 import subprocess | 7 import subprocess |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 class PNGDiffer(): | 10 class PNGDiffer(): |
| 11 ACTUAL_TEMPLATE = '.pdf.%d.png' | 11 ACTUAL_TEMPLATE = '.pdf.%d.png' |
| 12 EXPECTED_TEMPLATE = '_expected' + ACTUAL_TEMPLATE | 12 EXPECTED_TEMPLATE = '_expected' + ACTUAL_TEMPLATE |
| 13 PLATFORM_EXPECTED_TEMPLATE = '_expected_%s' + ACTUAL_TEMPLATE |
| 13 | 14 |
| 14 def __init__(self, finder): | 15 def __init__(self, finder): |
| 15 self.pdfium_diff_path = finder.ExecutablePath('pdfium_diff') | 16 self.pdfium_diff_path = finder.ExecutablePath('pdfium_diff') |
| 17 self.os_name = finder.os_name |
| 16 | 18 |
| 17 def HasDifferences(self, input_filename, source_dir, working_dir): | 19 def HasDifferences(self, input_filename, source_dir, working_dir): |
| 18 input_root, _ = os.path.splitext(input_filename) | 20 input_root, _ = os.path.splitext(input_filename) |
| 19 actual_path_template = os.path.join( | 21 actual_path_template = os.path.join( |
| 20 working_dir, input_root + self.ACTUAL_TEMPLATE) | 22 working_dir, input_root + self.ACTUAL_TEMPLATE) |
| 21 expected_path_template = os.path.join( | 23 expected_path_template = os.path.join( |
| 22 source_dir, input_root + self.EXPECTED_TEMPLATE) | 24 source_dir, input_root + self.EXPECTED_TEMPLATE) |
| 25 platform_expected_path_template = os.path.join( |
| 26 source_dir, input_root + self.PLATFORM_EXPECTED_TEMPLATE) |
| 23 i = 0 | 27 i = 0 |
| 24 try: | 28 try: |
| 25 while True: | 29 while True: |
| 26 actual_path = actual_path_template % i; | 30 actual_path = actual_path_template % i |
| 27 expected_path = expected_path_template % i; | 31 expected_path = expected_path_template % i |
| 28 if not os.path.exists(expected_path): | 32 platform_expected_path = ( |
| 33 platform_expected_path_template % (self.os_name, i)) |
| 34 if os.path.exists(platform_expected_path): |
| 35 expected_path = platform_expected_path |
| 36 elif not os.path.exists(expected_path): |
| 29 if i == 0: | 37 if i == 0: |
| 30 print "WARNING: no expected results files for " + input_filename | 38 print "WARNING: no expected results files for " + input_filename |
| 31 break | 39 break |
| 32 print "Checking " + actual_path | 40 print "Checking " + actual_path |
| 33 sys.stdout.flush() | 41 sys.stdout.flush() |
| 34 subprocess.check_call( | 42 subprocess.check_call( |
| 35 [self.pdfium_diff_path, expected_path, actual_path]) | 43 [self.pdfium_diff_path, expected_path, actual_path]) |
| 36 i += 1 | 44 i += 1 |
| 37 except subprocess.CalledProcessError as e: | 45 except subprocess.CalledProcessError as e: |
| 38 print "FAILURE: " + input_filename + "; " + str(e) | 46 print "FAILURE: " + input_filename + "; " + str(e) |
| 39 return True | 47 return True |
| 40 return False | 48 return False |
| OLD | NEW |