def HasDifferences(self, input_filename, source_dir, working_dir): path_templates = PathTemplates(input_filename, source_dir, working_dir) i = 0 while True: actual_path = path_templates.GetActualPath(i) expected_path = path_templates.GetExpectedPath(i) # PDFium tests should be platform independent. Platform based results are # used to capture platform dependent implementations. platform_expected_path = path_templates.GetPlatformExpectedPath( self.os_name, i) if (not os.path.exists(expected_path) and not os.path.exists(platform_expected_path)): if i == 0: print "WARNING: no expected results files for " + input_filename break print "Checking " + actual_path sys.stdout.flush() if os.path.exists(expected_path): error = common.RunCommand( [self.pdfium_diff_path, expected_path, actual_path]) else: error = 1 if error: # When failed, we check against platform based results. if os.path.exists(platform_expected_path): error = common.RunCommand([ self.pdfium_diff_path, platform_expected_path, actual_path ]) if error: print "FAILURE: " + input_filename + "; " + str(error) return True i += 1 return False
def TestText(self, input_filename, input_root, expected_txt_path, pdf_path): txt_path = os.path.join(self.working_dir, input_root + '.txt') with open(txt_path, 'w') as outfile: cmd_to_run = [ self.pdfium_test_path, '--send-events', '--time=' + TEST_SEED_TIME ] if self.options.disable_javascript: cmd_to_run.append('--disable-javascript') cmd_to_run.append(pdf_path) subprocess.check_call(cmd_to_run, stdout=outfile) # If the expected file does not exist, the output is expected to be empty. if not os.path.exists(expected_txt_path): return self._VerifyEmptyText(txt_path) # If JavaScript is disabled, the output should be empty. # However, if the test is suppressed and JavaScript is disabled, do not # verify that the text is empty so the suppressed test does not surprise. if (self.options.disable_javascript and not self.test_suppressor.IsResultSuppressed(input_filename)): return self._VerifyEmptyText(txt_path) cmd = [ sys.executable, self.text_diff_path, expected_txt_path, txt_path ] return common.RunCommand(cmd)
def Regenerate(self, input_filename, source_dir, working_dir, platform_only): path_templates = PathTemplates(input_filename, source_dir, working_dir) for page in itertools.count(): # Loop through the generated page images. Stop when there is a page # missing a png, which means the document ended. actual_path = path_templates.GetActualPath(page) if not os.path.isfile(actual_path): break platform_expected_path = path_templates.GetPlatformExpectedPath( self.os_name, page) # If there is a platform expected png, we will overwrite it. Otherwise, # overwrite the generic png in "all" mode, or do nothing in "platform" # mode. if os.path.exists(platform_expected_path): expected_path = platform_expected_path elif not platform_only: expected_path = path_templates.GetExpectedPath(page) else: continue shutil.copyfile(actual_path, expected_path) common.RunCommand(['optipng', expected_path])
def test_one_file(input_filename, source_dir, working_dir, pdfium_test_path, image_differ, drmem_wrapper, redirect_output=False): input_path = os.path.join(source_dir, input_filename) pdf_path = os.path.join(working_dir, input_filename) # Remove any existing generated images from previous runs. actual_images = image_differ.GetActualFiles( input_filename, source_dir, working_dir) for image in actual_images: if os.path.exists(image): os.remove(image) shutil.copyfile(input_path, pdf_path) sys.stdout.flush() # add Dr. Memory wrapper if exist # remove .pdf suffix cmd_to_run = common.DrMemoryWrapper(drmem_wrapper, os.path.splitext(input_filename)[0]) cmd_to_run.extend([pdfium_test_path, '--png', pdf_path]) # run test error = common.RunCommand(cmd_to_run, redirect_output) if error: print "FAILURE: " + input_filename + "; " + str(error) return False return not image_differ.HasDifferences(input_filename, source_dir, working_dir, redirect_output)
def HasDifferences(self, input_filename, source_dir, working_dir, redirect_output=False): template_paths = self._GetTemplatePaths( input_filename, source_dir, working_dir) actual_path_template = template_paths[0]; expected_path_template = template_paths[1] platform_expected_path_template = template_paths[2] i = 0 while True: actual_path = actual_path_template % i expected_path = expected_path_template % i platform_expected_path = ( platform_expected_path_template % (self.os_name, i)) if os.path.exists(platform_expected_path): expected_path = platform_expected_path elif not os.path.exists(expected_path): if i == 0: print "WARNING: no expected results files for " + input_filename break print "Checking " + actual_path sys.stdout.flush() error = common.RunCommand( [self.pdfium_diff_path, expected_path, actual_path], redirect_output) if error: print "FAILURE: " + input_filename + "; " + str(error) return True i += 1 return False
def _RunImageDiffCommand(self, expected_path, actual_path): if not os.path.exists(expected_path): return NotFoundError('%s does not exist.' % expected_path) cmd = [self.pdfium_diff_path] if self.reverse_byte_order: cmd.append('--reverse-byte-order') cmd.extend([expected_path, actual_path]) return common.RunCommand(cmd)
def TestText(self, input_root, expected_txt_path, pdf_path): txt_path = os.path.join(self.working_dir, input_root + '.txt') with open(txt_path, 'w') as outfile: cmd_to_run = [self.pdfium_test_path, pdf_path] subprocess.check_call(cmd_to_run, stdout=outfile) cmd = [sys.executable, self.text_diff_path, expected_txt_path, txt_path] return common.RunCommand(cmd)
def HasDifferences(self, input_filename, source_dir, working_dir): path_templates = PathTemplates(input_filename, source_dir, working_dir) for page in itertools.count(): actual_path = path_templates.GetActualPath(page) expected_path = path_templates.GetExpectedPath(page) # PDFium tests should be platform independent. Platform based results are # used to capture platform dependent implementations. platform_expected_path = path_templates.GetPlatformExpectedPath( self.os_name, page) if (not os.path.exists(expected_path) and not os.path.exists(platform_expected_path)): if page == 0: print "WARNING: no expected results files for " + input_filename if os.path.exists(actual_path): print( 'FAILURE: Missing expected result for 0-based page %d of %s' % (page, input_filename)) return True break print "Checking " + actual_path sys.stdout.flush() if os.path.exists(expected_path): cmd = [self.pdfium_diff_path] if self.reverse_byte_order: cmd.append('--reverse-byte-order') cmd.extend([expected_path, actual_path]) error = common.RunCommand(cmd) else: error = 1 if error: # When failed, we check against platform based results. if os.path.exists(platform_expected_path): cmd = [self.pdfium_diff_path] if self.reverse_byte_order: cmd.append('--reverse-byte-order') cmd.extend([platform_expected_path, actual_path]) error = common.RunCommand(cmd) if error: print "FAILURE: " + input_filename + "; " + str(error) return True return False
def TestText(self, input_root, expected_txt_path, pdf_path): txt_path = os.path.join(self.working_dir, input_root + '.txt') with open(txt_path, 'w') as outfile: # add Dr. Memory wrapper if exist cmd_to_run = common.DrMemoryWrapper(self.drmem_wrapper, input_root) cmd_to_run.extend([self.pdfium_test_path, pdf_path]) subprocess.check_call(cmd_to_run, stdout=outfile) cmd = [ sys.executable, self.text_diff_path, expected_txt_path, txt_path ] return common.RunCommand(cmd)
def TestText(self, input_root, expected_txt_path, pdf_path): txt_path = os.path.join(self.working_dir, input_root + '.txt') with open(txt_path, 'w') as outfile: cmd_to_run = [ self.pdfium_test_path, '--send-events', '--time=' + TEST_SEED_TIME, pdf_path ] subprocess.check_call(cmd_to_run, stdout=outfile) if not os.path.exists(expected_txt_path): return self._VerifyEmptyText(txt_path) cmd = [sys.executable, self.text_diff_path, expected_txt_path, txt_path] return common.RunCommand(cmd)
def Generate(self, source_dir, input_filename, input_root, pdf_path): original_path = os.path.join(source_dir, input_filename) input_path = os.path.join(source_dir, input_root + '.in') input_event_path = os.path.join(source_dir, input_root + '.evt') if os.path.exists(input_event_path): output_event_path = os.path.splitext(pdf_path)[0] + '.evt' shutil.copyfile(input_event_path, output_event_path) if not os.path.exists(input_path): if os.path.exists(original_path): shutil.copyfile(original_path, pdf_path) return None sys.stdout.flush() return common.RunCommand( [sys.executable, self.fixup_path, '--output-dir=' + self.working_dir, input_path])
def TestPixel(self, input_root, pdf_path): cmd_to_run = common.DrMemoryWrapper(self.drmem_wrapper, input_root) cmd_to_run.extend( [self.pdfium_test_path, '--send-events', '--png', pdf_path]) return common.RunCommand(cmd_to_run)