def test_read_checksum(self):
        # Test a file with the comment.
        filehandle = StringIO.StringIO('''\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x03 \x00\x00\x02X\x08\x02\x00\x00\x00\x15\x14\x15'\x00\x00\x00)tEXtchecksum\x003c4134fe2739880353f91c5b84cadbaaC\xb8?\xec\x00\x00\x16\xfeIDATx\x9c\xed\xdd[\x8cU\xe5\xc1\xff\xf15T\x18\x0ea,)\xa6\x80XZ<\x10\n\xd6H\xc4V\x88}\xb5\xa9\xd6r\xd5\x0bki0\xa6\xb5ih\xd2\xde\x98PHz\xd1\x02=\\q#\x01\x8b\xa5rJ\x8b\x88i\xacM\xc5h\x8cbMk(\x1ez@!\x0c\xd5\xd2\xc2\xb44\x1c\x848\x1dF(\xeb\x7f\xb1\xff\xd9\xef~g\xd6\xde3\xe0o\x10\xec\xe7sa6{\xd6z\xd6\xb3\xd7\xf3\xa8_7\xdbM[Y\x96\x05\x00\x009\xc3\xde\xeb\t\x00\x00\xbc\xdf\x08,\x00\x800\x81\x05\x00\x10&\xb0\x00\x00\xc2\x04\x16\x00@\x98\xc0\x02\x00\x08\x13X\x00\x00a\x02\x0b\x00 Lx01\x00\x84\t,\x00\x800\x81\x05\x00\x10\xd64\xb0\xda\x9a\xdb\xb6m\xdb\xb4i\xd3\xfa\x9fr\xf3\xcd7\x0f\xe5T\x07\xe5\xd4\xa9''')
        checksum = read_checksum_from_png.read_checksum(filehandle)
        self.assertEqual('3c4134fe2739880353f91c5b84cadbaa', checksum)

        # Test a file without the comment.
        filehandle = StringIO.StringIO('''\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x03 \x00\x00\x02X\x08\x02\x00\x00\x00\x15\x14\x15'\x00\x00\x16\xfeIDATx\x9c\xed\xdd[\x8cU\xe5\xc1\xff\xf15T\x18\x0ea,)\xa6\x80XZ<\x10\n\xd6H\xc4V\x88}\xb5\xa9\xd6r\xd5\x0bki0\xa6\xb5ih\xd2\xde\x98PHz\xd1\x02=\\q#\x01\x8b\xa5rJ\x8b\x88i\xacM\xc5h\x8cbMk(\x1ez@!\x0c\xd5\xd2\xc2\xb44\x1c\x848\x1dF(\xeb\x7f\xb1\xff\xd9\xef~g\xd6\xde3\xe0o\x10\xec\xe7sa6{\xd6z\xd6\xb3\xd7\xf3\xa8_7\xdbM[Y\x96\x05\x00\x009\xc3\xde\xeb\t\x00\x00\xbc\xdf\x08,\x00\x800\x81\x05\x00\x10&\xb0\x00\x00\xc2\x04\x16\x00@\x98\xc0\x02\x00\x08\x13X\x00\x00a\x02\x0b\x00 Lx01\x00\x84\t,\x00\x800\x81\x05\x00\x10\xd64\xb0\xda\x9a\xdb\xb6m\xdb\xb4i\xd3\xfa\x9fr\xf3\xcd7\x0f\xe5T\x07\xe5\xd4\xa9S\x8b\x17/\x1e?~\xfc\xf8\xf1\xe3\xef\xbf\xff\xfe\xf7z:M5\xbb\x87\x17\xcbUZ\x8f|V\xd7\xbd\x10\xb6\xcd{b\x88\xf6j\xb3\x9b?\x14\x9b\xa1>\xe6\xf9\xd9\xcf\x00\x17\x93''')
        checksum = read_checksum_from_png.read_checksum(filehandle)
        self.assertIsNone(checksum)
Exemplo n.º 2
0
    def check(self, inline=None):
        errorstr = ""
        config_file_path = ""
        detection = self._detector.display_name()

        if self._fs.exists(self._file_path) and self._file_path.endswith("-expected.png"):
            with self._fs.open_binary_file_for_reading(self._file_path) as filehandle:
                if not read_checksum_from_png.read_checksum(filehandle):
                    self._handle_style_error(0, 'image/png', 5, "Image lacks a checksum. Generate pngs using run-webkit-tests to ensure they have a checksum.")

        if detection == "git":
            (file_missing, autoprop_missing, png_missing) = checksvnconfigfile.check(self._host, self._fs)
            config_file_path = checksvnconfigfile.config_file_path(self._host, self._fs)

            if file_missing:
                self._handle_style_error(0, 'image/png', 5, "There is no SVN config file. (%s)" % config_file_path)
            elif autoprop_missing and png_missing:
                self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_autoprop(config_file_path) + checksvnconfigfile.errorstr_png(config_file_path))
            elif autoprop_missing:
                self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_autoprop(config_file_path))
            elif png_missing:
                self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_png(config_file_path))

        elif detection == "svn":
            prop_get = self._detector.propget("svn:mime-type", self._file_path)
            if prop_get != "image/png":
                errorstr = "Set the svn:mime-type property (svn propset svn:mime-type image/png %s)." % self._file_path
                self._handle_style_error(0, 'image/png', 5, errorstr)
Exemplo n.º 3
0
 def check(self, inline=None):
     if self._fs.exists(self._file_path) and self._file_path.endswith("-expected.png"):
         with self._fs.open_binary_file_for_reading(self._file_path) as filehandle:
             if not read_checksum_from_png.read_checksum(filehandle):
                 self._handle_style_error(
                     0, 'image/png', 5,
                     "Image lacks a checksum. Generate pngs using run-webkit-tests to ensure they have a checksum.")
Exemplo n.º 4
0
 def check(self, inline=None):
     if self._fs.exists(self._file_path) and self._file_path.endswith('-expected.png'):
         with self._fs.open_binary_file_for_reading(self._file_path) as filehandle:
             if not read_checksum_from_png.read_checksum(filehandle):
                 self._handle_style_error(
                     0, 'image/png', 5,
                     'Image lacks a checksum. Generate pngs using run-webkit-tests to ensure they have a checksum.')
Exemplo n.º 5
0
Arquivo: png.py Projeto: GhostQ/GitSB
    def check(self, inline=None):
        errorstr = ""
        config_file_path = ""
        detection = self._detector.display_name()

        if self._fs.exists(self._file_path) and self._file_path.endswith("-expected.png"):
            with self._fs.open_binary_file_for_reading(self._file_path) as filehandle:
                if not read_checksum_from_png.read_checksum(filehandle):
                    self._handle_style_error(0, 'image/png', 5, "Image lacks a checksum. Generate pngs using run-webkit-tests to ensure they have a checksum.")

        if detection == "git":
            (file_missing, autoprop_missing, png_missing) = checksvnconfigfile.check(self._host, self._fs)
            config_file_path = checksvnconfigfile.config_file_path(self._host, self._fs)

            if file_missing:
                self._handle_style_error(0, 'image/png', 5, "There is no SVN config file. (%s)" % config_file_path)
            elif autoprop_missing and png_missing:
                self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_autoprop(config_file_path) + checksvnconfigfile.errorstr_png(config_file_path))
            elif autoprop_missing:
                self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_autoprop(config_file_path))
            elif png_missing:
                self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_png(config_file_path))

        elif detection == "svn":
            prop_get = self._detector.propget("svn:mime-type", self._file_path)
            if prop_get != "image/png":
                errorstr = "Set the svn:mime-type property (svn propset svn:mime-type image/png %s)." % self._file_path
                self._handle_style_error(0, 'image/png', 5, errorstr)
Exemplo n.º 6
0
    def check(self, inline=None):
        errorstr = ""
        config_file_path = ""
        detection = self._detector.display_name()

        if self._fs.exists(self._file_path):
            with self._fs.open_binary_file_for_reading(self._file_path) as filehandle:
                if not read_checksum_from_png.read_checksum(filehandle):
                    self._handle_style_error(0, 'image/png', 5, "Image lacks a checksum. Generate pngs using run-webkit-tests to ensure they have a checksum.")

        if detection == "git":
            config_file_path = self._config_file_path()
            there_is_enable_line = False
            there_is_png_line = False

            try:
                config_file = self._fs.read_text_file(config_file_path)
            except IOError:
                errorstr = "There is no " + config_file_path
                self._handle_style_error(0, 'image/png', 5, errorstr)
                return

            errorstr_autoprop = "Have to enable auto props in the subversion config file (" + config_file_path + " \"enable-auto-props = yes\"). "
            errorstr_png = "Have to set the svn:mime-type in the subversion config file (" + config_file_path + " \"*.png = svn:mime-type=image/png\")."

            for line in config_file.split('\n'):
                if not there_is_enable_line:
                    match = re.search("^\s*enable-auto-props\s*=\s*yes", line)
                    if match:
                        there_is_enable_line = True
                        errorstr_autoprop = ""
                        continue

                if not there_is_png_line:
                    match = re.search("^\s*\*\.png\s*=\s*svn:mime-type=image/png", line)
                    if match:
                        there_is_png_line = True
                        errorstr_png = ""
                        continue

            errorstr = errorstr_autoprop + errorstr_png
            if errorstr:
                self._handle_style_error(0, 'image/png', 5, errorstr)

        elif detection == "svn":
            prop_get = self._detector.propget("svn:mime-type", self._file_path)
            if prop_get != "image/png":
                errorstr = "Set the svn:mime-type property (svn propset svn:mime-type image/png " + self._file_path + ")."
                self._handle_style_error(0, 'image/png', 5, errorstr)
Exemplo n.º 7
0
Arquivo: png.py Projeto: dzhshf/WebKit
    def check(self, inline=None):
        errorstr = ""
        config_file_path = ""
        detection = self._detector.display_name()

        if self._fs.exists(self._file_path) and self._file_path.endswith("-expected.png"):
            with self._fs.open_binary_file_for_reading(self._file_path) as filehandle:
                if not read_checksum_from_png.read_checksum(filehandle):
                    self._handle_style_error(0, 'image/png', 5, "Image lacks a checksum. Generate pngs using run-webkit-tests to ensure they have a checksum.")

        if detection == "git":
            config_file_path = self._config_file_path()
            there_is_enable_line = False
            there_is_png_line = False

            try:
                config_file = self._fs.read_text_file(config_file_path)
            except IOError:
                errorstr = "There is no " + config_file_path
                self._handle_style_error(0, 'image/png', 5, errorstr)
                return

            errorstr_autoprop = "Have to enable auto props in the subversion config file (" + config_file_path + " \"enable-auto-props = yes\"). "
            errorstr_png = "Have to set the svn:mime-type in the subversion config file (" + config_file_path + " \"*.png = svn:mime-type=image/png\")."

            for line in config_file.split('\n'):
                if not there_is_enable_line:
                    match = re.search("^\s*enable-auto-props\s*=\s*yes", line)
                    if match:
                        there_is_enable_line = True
                        errorstr_autoprop = ""
                        continue

                if not there_is_png_line:
                    match = re.search("^\s*\*\.png\s*=\s*svn:mime-type=image/png", line)
                    if match:
                        there_is_png_line = True
                        errorstr_png = ""
                        continue

            errorstr = errorstr_autoprop + errorstr_png
            if errorstr:
                self._handle_style_error(0, 'image/png', 5, errorstr)

        elif detection == "svn":
            prop_get = self._detector.propget("svn:mime-type", self._file_path)
            if prop_get != "image/png":
                errorstr = "Set the svn:mime-type property (svn propset svn:mime-type image/png " + self._file_path + ")."
                self._handle_style_error(0, 'image/png', 5, errorstr)
Exemplo n.º 8
0
    def output_for_test(self, test_input, is_reftest):
        port = self._port
        if self._options.virtual_test_suite_name:
            test_input.test_name = test_input.test_name.replace(
                self._options.virtual_test_suite_base,
                self._options.virtual_test_suite_name)
        actual_text = port.expected_text(test_input.test_name)
        actual_audio = port.expected_audio(test_input.test_name)
        actual_image = None
        actual_checksum = None
        if is_reftest:
            # Make up some output for reftests.
            actual_text = 'reference text\n'
            actual_checksum = 'mock-checksum'
            actual_image = 'blank'
            if test_input.test_name.endswith('-mismatch.html'):
                actual_text = 'not reference text\n'
                actual_checksum = 'not-mock-checksum'
                actual_image = 'not blank'
        elif test_input.should_run_pixel_test and test_input.image_hash:
            actual_checksum = port.expected_checksum(test_input.test_name)
            actual_image = port.expected_image(test_input.test_name)

        if self._options.actual_directory:
            actual_path = port.host.filesystem.join(
                self._options.actual_directory, test_input.test_name)
            root, _ = port.host.filesystem.splitext(actual_path)
            text_path = root + '-actual.txt'
            if port.host.filesystem.exists(text_path):
                actual_text = port.host.filesystem.read_binary_file(text_path)
            audio_path = root + '-actual.wav'
            if port.host.filesystem.exists(audio_path):
                actual_audio = port.host.filesystem.read_binary_file(
                    audio_path)
            image_path = root + '-actual.png'
            if port.host.filesystem.exists(image_path):
                actual_image = port.host.filesystem.read_binary_file(
                    image_path)
                with port.host.filesystem.open_binary_file_for_reading(
                        image_path) as filehandle:
                    actual_checksum = read_checksum_from_png.read_checksum(
                        filehandle)

        return DriverOutput(actual_text, actual_image, actual_checksum,
                            actual_audio)
Exemplo n.º 9
0
    def output_for_test(self, test_input, is_reftest):
        port = self._port
        if self._options.virtual_test_suite_name:
            test_input.test_name = test_input.test_name.replace(
                self._options.virtual_test_suite_base, self._options.virtual_test_suite_name
            )
        actual_text = port.expected_text(test_input.test_name)
        actual_audio = port.expected_audio(test_input.test_name)
        actual_image = None
        actual_checksum = None
        if is_reftest:
            # Make up some output for reftests.
            actual_text = "reference text\n"
            actual_checksum = "mock-checksum"
            actual_image = "blank"
            if test_input.test_name.endswith("-mismatch.html"):
                actual_text = "not reference text\n"
                actual_checksum = "not-mock-checksum"
                actual_image = "not blank"
        elif test_input.should_run_pixel_test and test_input.image_hash:
            actual_checksum = port.expected_checksum(test_input.test_name)
            actual_image = port.expected_image(test_input.test_name)

        if self._options.actual_directory:
            actual_path = port._filesystem.join(self._options.actual_directory, test_input.test_name)
            root, _ = port._filesystem.splitext(actual_path)
            text_path = root + "-actual.txt"
            if port._filesystem.exists(text_path):
                actual_text = port._filesystem.read_binary_file(text_path)
            audio_path = root + "-actual.wav"
            if port._filesystem.exists(audio_path):
                actual_audio = port._filesystem.read_binary_file(audio_path)
            image_path = root + "-actual.png"
            if port._filesystem.exists(image_path):
                actual_image = port._filesystem.read_binary_file(image_path)
                with port._filesystem.open_binary_file_for_reading(image_path) as filehandle:
                    actual_checksum = read_checksum_from_png.read_checksum(filehandle)

        return DriverOutput(actual_text, actual_image, actual_checksum, actual_audio)
Exemplo n.º 10
0
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from __future__ import with_statement
import sys

from blinkpy.common import add_webkitpy  # pylint: disable=unused-import
from webkitpy.common import read_checksum_from_png


if '__main__' == __name__:
    for filename in sys.argv[1:]:
        with open(filename, 'r') as filehandle:
            print "%s: %s" % (read_checksum_from_png.read_checksum(filehandle), filename)