aboutsummaryrefslogtreecommitdiffstats
path: root/unittest/Bug173387_TestCase.py
blob: 6ce8f89f20f6e73b4dbb22ca544a69812dc9e15d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
# -*- coding: utf-8 -*-

# ******************************************************************************
#
# Copyright (C) 2008 Olivier Tilloy <olivier@tilloy.net>
#
# This file is part of the pyexiv2 distribution.
#
# pyexiv2 is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# pyexiv2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyexiv2; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
#
#
# File:      Bug173387_TestCase.py
# Author(s): Olivier Tilloy <olivier@tilloy.net>
#
# ******************************************************************************

import unittest
import testutils
import os.path
import pyexiv2

class Bug173387_TestCase(unittest.TestCase):

    """
    Test case for bug #173387.

    Summary: Error reading Exif.Photo.UserComment.
    Description: Trying to read the value of EXIF tag 'Exif.Photo.UserComment'
    fails if the comment is not encoded as an ASCII string.
    Fix: fixed with revision 77.
    """

    def testEmptyUserComment(self):
        """
        Test reading a so-called "empty" user comment (full of \x00 characters).
        """
        # Check that the reference file is not corrupted
        filename = os.path.join('data', 'bug173387_empty_usercomment.jpg')
        md5sum = '75e5f18aece0955b518cefe1ffd30b7c'
        self.assert_(testutils.CheckFileSum(filename, md5sum))

        image = pyexiv2.Image(filename)
        image.readMetadata()
        self.assertEqual(image['Exif.Photo.UserComment'], '\x00' * 256)

    def testCorruptedUserComment(self):
        """
        Test reading a corrupted user comment (full of non printable
        characters).
        """
        # Check that the reference file is not corrupted
        filename = os.path.join('data', 'bug173387_corrupted_usercomment.jpg')
        md5sum = '8007ac7357213fd2787bc817a6d7cd1d'
        self.assert_(testutils.CheckFileSum(filename, md5sum))

        image = pyexiv2.Image(filename)
        image.readMetadata()
        evalue = 'charset="InvalidCharsetId" \xff\xff\xaa\x00X\x00@\x00a\x00@\xff\xbb\x00x\x14F9\x05\x00\x08\xff\xcc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xdd\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00<\x00\x00\x00\x00\x00\x00\x00X\x02\x00\x00s\x00\x00\x00\x00\x00\x00\x00@\xb2#\x8c\x00\x00\x00\x01J\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8c\x1e\x00\x00p:\xac\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00<R\x14\x8cx$\x03\x8cDR\x14\x8c\xa8+\x14\x8c\x00\x00\x00\x00x.\x14\x8c\x00\x00\x00\x00\x00\x00\x00\x00\x98s\x01\x00\x10\x00\x00\x00\x18\x08\x15\x8c `\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x03\xe7\x00\x08\x00\x00\x02\x00@\x00\x00\t\x05\x00\x00\x19\x03\x00\x00\x03\x06\x10\x01\x80\x84\x1a\x8c\x08O\x1a\x8c\xf0L\x1a\x8c\x00\x00\x00\x00\x00\x00\x00\x00\x80D\x1a\x8c\x01\x00\x00\x00\xf0\x94\x15\xac'
        self.assertEqual(image['Exif.Photo.UserComment'], evalue)