OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 import os | |
7 import subprocess | |
8 import sys | |
9 | |
10 class PNGDiffer(): | |
11 def __init__(self, os_name, pdfium_diff_path): | |
12 self.pdfium_diff_path = pdfium_diff_path | |
13 self.actual_template = '.pdf.%d.png' | |
Lei Zhang
2015/04/02 23:16:20
this can be a class constant
Tom Sepez
2015/04/03 18:13:14
Done.
| |
14 self.expected_template = '_expected' + self.actual_template | |
15 # os_name to be used shortly for platform-specifc result files. | |
16 | |
17 def HasDifferences(self, input_filename, source_dir, working_dir): | |
18 input_root, _ = os.path.splitext(input_filename) | |
19 actual_path_template = os.path.join( | |
20 working_dir, input_root + self.actual_template) | |
21 expected_path_template = os.path.join( | |
22 source_dir, input_root + self.expected_template) | |
23 i = 0 | |
24 try: | |
25 while True: | |
26 actual_path = actual_path_template % i; | |
27 expected_path = expected_path_template % i; | |
28 if not os.path.exists(expected_path): | |
29 if i == 0: | |
30 print "WARNING: no expected results files for " + input_filename | |
31 break | |
32 print "Checking " + actual_path | |
33 sys.stdout.flush() | |
34 subprocess.check_call( | |
35 [self.pdfium_diff_path, expected_path, actual_path]) | |
36 i += 1 | |
37 except subprocess.CalledProcessError as e: | |
38 print "FAILURE: " + input_filename + "; " + str(e) | |
39 return True | |
40 return False | |
41 | |
42 | |
43 # Testing. | |
Lei Zhang
2015/04/02 23:16:20
Other python projects within the chromium-sphere p
Tom Sepez
2015/04/03 18:13:15
Comment is misleading. This makes a command-line
| |
44 def main(argv): | |
45 if sys.platform.startswith('linux'): | |
Lei Zhang
2015/04/02 23:16:20
This can go in to common.py since we use it everyw
Tom Sepez
2015/04/03 18:13:14
Done.
| |
46 os_name = 'linux' | |
47 elif sys.platform.startswith('win'): | |
48 os_name = 'win' | |
49 elif sys.platform.startswith('darwin'): | |
50 os_name = 'mac' | |
51 else: | |
52 print 'Confused, can not determine OS, aborting.' | |
53 return 1 | |
54 | |
55 if len(argv) != 4: | |
56 print "usage: %s <filename> <source-dir> <working-dir>" % argv[0] | |
57 return 1 | |
58 | |
59 # Expect |my_dir| to be .../pdfium/testing/tools. | |
60 my_dir = os.path.dirname(os.path.realpath(__file__)) | |
61 testing_dir = os.path.dirname(my_dir) | |
62 pdfium_dir = os.path.dirname(testing_dir) | |
63 if (os.path.basename(my_dir) != 'tools' or | |
64 os.path.basename(testing_dir) != 'testing'): | |
65 print 'Confused, can not find pdfium root directory, aborting.' | |
66 return 1 | |
67 | |
68 # Find path to build directory. This depends on whether this is a | |
69 # standalone build vs. a build as part of a chromium checkout. For | |
70 # standalone, we expect a path like .../pdfium/out/Debug, but for | |
71 # chromium, we expect a path like .../src/out/Debug two levels | |
72 # higher (to skip over the third_party/pdfium path component under | |
73 # which chromium sticks pdfium). | |
74 base_dir = pdfium_dir | |
75 one_up_dir = os.path.dirname(base_dir) | |
76 two_up_dir = os.path.dirname(one_up_dir) | |
77 if (os.path.basename(two_up_dir) == 'src' and | |
78 os.path.basename(one_up_dir) == 'third_party'): | |
79 base_dir = two_up_dir | |
80 build_dir = os.path.join(base_dir, 'out', 'Debug') | |
81 | |
82 # Compiled binaries are found under the build path. | |
83 pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff') | |
84 if sys.platform.startswith('win'): | |
85 pdfium_diff_path = pdfium_diff_path + '.exe' | |
86 | |
87 differ = PNGDiffer(os_name, pdfium_diff_path) | |
88 if differ.HasDifferences(argv[1], argv[2], argv[3]): | |
89 print "Returned true" | |
90 | |
91 return 0 | |
92 | |
93 if __name__ == '__main__': | |
94 sys.exit(main(sys.argv)) | |
OLD | NEW |