# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Compares the image output of a test to the expected image output using
fuzzy matching.
"""

import errno
import logging
import os
import shutil
import subprocess

from layout_package import path_utils
from layout_package import test_failures
from test_types import test_type_base

class FuzzyImageDiff(test_type_base.TestTypeBase):
  def CompareOutput(self, filename, proc, output, test_args):
    """Implementation of CompareOutput that checks the output image and
    checksum against the expected files from the LayoutTest directory.
    """
    failures = []

    # If we didn't produce a hash file, this test must be text-only.
    if test_args.hash is None:
      return failures

    expected_png_file = path_utils.ExpectedFilename(filename,
                                                    '.png',
                                                    self._platform)

    if test_args.show_sources:
      logging.debug('Using %s' % expected_png_file)

    # Also report a missing expected PNG file.
    if not os.path.isfile(expected_png_file):
      failures.append(test_failures.FailureMissingImage(self))

    # Run the fuzzymatcher
    r = subprocess.call(['fuzzymatch', test_args.png_path, expected_png_file])
    print '  fuzzymatch returned', r
    if r != 0:
      failures.append(test_failures.FailureFuzzyFailure(self))

    return failures


Fix build: missed a file
Fix build: missed a file

TBR=tony

Review URL: http://codereview.chromium.org/13209


git-svn-id: http://src.chromium.org/svn/trunk/src@6449 4ff67af0-8c30-449e-8e8b-ad334ec8d88c

Former-commit-id: b919e44b1d44926606de27cb569e7ad1b4724989