blob: e2fdc66918e2f47c8c5c8dd9eb6b22b2e980cddb [file] [log] [blame]
Tom Sepezb7cb36a2015-02-13 16:54:48 -08001#!/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
6import optparse
7import os
8import re
9import subprocess
10import sys
11
Tom Sepez30762ce2015-04-09 13:37:02 -070012import common
13
Tom Sepezb7cb36a2015-02-13 16:54:48 -080014# Nomenclature:
15# x_root - "x"
16# x_filename - "x.ext"
17# x_path - "path/to/a/b/c/x.ext"
18# c_dir - "path/to/a/b/c"
19
20def generate_and_test(input_filename, source_dir, working_dir,
Tom Sepez30762ce2015-04-09 13:37:02 -070021 fixup_path, pdfium_test_path, text_diff_path):
Tom Sepezb7cb36a2015-02-13 16:54:48 -080022 input_root, _ = os.path.splitext(input_filename)
23 input_path = os.path.join(source_dir, input_root + '.in')
24 pdf_path = os.path.join(working_dir, input_root + '.pdf')
25 txt_path = os.path.join(working_dir, input_root + '.txt')
26 expected_path = os.path.join(source_dir, input_root + '_expected.txt')
27 try:
Tom Sepez30762ce2015-04-09 13:37:02 -070028 sys.stdout.flush()
Tom Sepezb7cb36a2015-02-13 16:54:48 -080029 subprocess.check_call(
Tom Sepez30762ce2015-04-09 13:37:02 -070030 [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path])
Tom Sepezb7cb36a2015-02-13 16:54:48 -080031 with open(txt_path, 'w') as outfile:
32 subprocess.check_call([pdfium_test_path, pdf_path], stdout=outfile)
Tom Sepez30762ce2015-04-09 13:37:02 -070033 subprocess.check_call(
34 [sys.executable, text_diff_path, expected_path, txt_path])
Tom Sepezb7cb36a2015-02-13 16:54:48 -080035 except subprocess.CalledProcessError as e:
36 print "FAILURE: " + input_filename + "; " + str(e)
Tom Sepeza8fd0e82015-03-17 13:30:11 -070037 return False
38 return True
Tom Sepezb7cb36a2015-02-13 16:54:48 -080039
40def main():
41 parser = optparse.OptionParser()
42 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'),
43 help='relative path from the base source directory')
44 options, args = parser.parse_args()
Dan Sinclair456b9232015-10-28 17:12:33 -040045
Tom Sepez30762ce2015-04-09 13:37:02 -070046 finder = common.DirectoryFinder(options.build_dir)
47 fixup_path = finder.ScriptPath('fixup_pdf_template.py')
48 text_diff_path = finder.ScriptPath('text_diff.py')
49 source_dir = finder.TestingDir(os.path.join('resources', 'javascript'))
50 pdfium_test_path = finder.ExecutablePath('pdfium_test')
Bruce Dawson56ba4292015-06-01 14:53:02 -070051 if not os.path.exists(pdfium_test_path):
52 print "FAILURE: Can't find test executable '%s'" % pdfium_test_path
53 print "Use --build-dir to specify its location."
54 return 1
Tom Sepez30762ce2015-04-09 13:37:02 -070055 working_dir = finder.WorkingDir(os.path.join('testing', 'javascript'))
Tom Sepezb7cb36a2015-02-13 16:54:48 -080056 if not os.path.exists(working_dir):
57 os.makedirs(working_dir)
58
Dan Sinclair456b9232015-10-28 17:12:33 -040059 input_files = []
60 if len(args):
61 for file_name in args:
62 input_files.append(file_name.replace(".pdf", ".in"))
63 else:
64 input_files = os.listdir(source_dir)
65
Tom Sepez30762ce2015-04-09 13:37:02 -070066 failures = []
Tom Sepezb7cb36a2015-02-13 16:54:48 -080067 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$')
Dan Sinclair456b9232015-10-28 17:12:33 -040068 for input_filename in input_files:
Tom Sepezb7cb36a2015-02-13 16:54:48 -080069 if input_file_re.match(input_filename):
70 input_path = os.path.join(source_dir, input_filename)
71 if os.path.isfile(input_path):
Tom Sepeza8fd0e82015-03-17 13:30:11 -070072 if not generate_and_test(input_filename, source_dir, working_dir,
Tom Sepez30762ce2015-04-09 13:37:02 -070073 fixup_path, pdfium_test_path, text_diff_path):
74 failures.append(input_path)
Tom Sepeza8fd0e82015-03-17 13:30:11 -070075
Tom Sepez30762ce2015-04-09 13:37:02 -070076 if failures:
Lei Zhangd44f1072015-07-16 18:46:57 -070077 failures.sort()
Tom Sepez30762ce2015-04-09 13:37:02 -070078 print '\n\nSummary of Failures:'
79 for failure in failures:
80 print failure
81 return 1
82 return 0
Tom Sepezb7cb36a2015-02-13 16:54:48 -080083
84
85if __name__ == '__main__':
86 sys.exit(main())