fix broken test due to upstream openjpeg test suite changes, closes #308

removed test_NR_broken3_jp2_dump, it is mostly just an extreme duplicate
case of test_NR_broken_jp2_dump.  It must be skipped on 32bit platforms
anyway.

refactored some NR_broken tests, consolidating them
This commit is contained in:
John Evans 2015-01-01 09:07:19 -05:00
commit 3e723605b9
3 changed files with 14 additions and 117 deletions

View file

@ -102,28 +102,6 @@ class TestWarnings(unittest.TestCase):
with self.assertWarnsRegex(UserWarning, regex):
Jp2k(jfile)
def test_NR_broken_jp2_dump(self):
"""
The colr box has a ridiculously incorrect box length.
"""
jfile = opj_data_file('input/nonregression/broken.jp2')
regex = re.compile(r'''b'colr'\sbox\shas\sincorrect\sbox\slength\s
\(\d+\)''',
re.VERBOSE)
with self.assertWarnsRegex(UserWarning, regex):
Jp2k(jfile)
def test_NR_broken2_jp2_dump(self):
"""
Invalid marker ID on codestream.
"""
jfile = opj_data_file('input/nonregression/broken2.jp2')
regex = re.compile(r'''Invalid\smarker\sid\sencountered\sat\sbyte\s
\d+\sin\scodestream:\s*"0x[a-fA-F0-9]{4}"''',
re.VERBOSE)
with self.assertWarnsRegex(UserWarning, regex):
Jp2k(jfile)
def test_bad_rsiz(self):
"""Should warn if RSIZ is bad. Issue196"""
filename = opj_data_file('input/nonregression/edf_c2_1002767.jp2')

View file

@ -359,11 +359,14 @@ class TestSuiteWarns(MetadataBase):
jpdata = jp2k[:]
self.assertEqual(jpdata.shape, (512, 768, 3))
def test_NR_broken_jp2_dump(self):
jfile = opj_data_file('input/nonregression/broken.jp2')
def test_NR_broken1_jp2_dump(self):
jfile = opj_data_file('input/nonregression/broken1.jp2')
with self.assertWarns(UserWarning):
# colr box has bad length.
# The colr box has a ridiculously incorrect box length.
regex = re.compile(r'''b'colr'\sbox\shas\sincorrect\sbox\slength\s
\(\d+\)''',
re.VERBOSE)
with self.assertWarnsRegex(UserWarning, regex):
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@ -584,13 +587,16 @@ class TestSuite2point0(unittest.TestCase):
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
def test_NR_DEC_broken2_jp2_5_decode(self):
# Null pointer access
"""
Invalid marker ID on codestream, Null pointer access upon read.
"""
jfile = opj_data_file('input/nonregression/broken2.jp2')
regex = re.compile(r'''Invalid\smarker\sid\sencountered\sat\sbyte\s
\d+\sin\scodestream:\s*"0x[a-fA-F0-9]{4}"''',
re.VERBOSE)
with self.assertRaises(IOError):
with self.assertWarns(UserWarning):
# Invalid marker ID.
with self.assertWarnsRegex(UserWarning, regex):
Jp2k(jfile)[:]
self.assertTrue(True)
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
def test_NR_DEC_broken4_jp2_7_decode(self):

View file

@ -2919,93 +2919,6 @@ class TestSuiteWarns(MetadataBase):
self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC')
@unittest.skipIf(sys.maxsize < 2**32, 'Do not run on 32-bit platforms')
def test_NR_broken3_jp2_dump(self):
"""
NR_broken3_jp2_dump
The file in question here has a colr box with an erroneous box
length of over 1GB. Don't run it on 32-bit platforms.
"""
jfile = opj_data_file('input/nonregression/broken3.jp2')
with self.assertWarns(UserWarning):
# Bad box length.
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c'])
ids = [box.box_id for box in jp2.box[2].box]
self.assertEqual(ids, ['ihdr', 'colr'])
self.verifySignatureBox(jp2.box[0])
self.verify_filetype_box(jp2.box[1], FileTypeBox())
ihdr = glymur.jp2box.ImageHeaderBox(152, 203, num_components=3)
self.verifyImageHeaderBox(jp2.box[2].box[0], ihdr)
colr = glymur.jp2box.ColourSpecificationBox(colorspace=SRGB)
self.verifyColourSpecificationBox(jp2.box[2].box[1], colr)
c = jp2.box[3].main_header
ids = [x.marker_id for x in c.segment]
expected = ['SOC', 'SIZ', 'CME', 'COD', 'QCD', 'QCC', 'QCC']
self.assertEqual(ids, expected)
kwargs = {'rsiz': 0, 'xysiz': (203, 152), 'xyosiz': (0, 0),
'xytsiz': (203, 152), 'xytosiz': (0, 0),
'bitdepth': (8, 8, 8),
'signed': (False, False, False),
'xyrsiz': [(1, 1, 1), (1, 1, 1)]}
self.verifySizSegment(c.segment[1],
glymur.codestream.SIZsegment(**kwargs))
pargs = RCME_ISO_8859_1, "Creator: JasPer Vers)on 1.701.0".encode()
self.verifyCMEsegment(c.segment[2], CMEsegment(*pargs))
# COD: Coding style default
self.assertFalse(c.segment[3].scod & 2) # no sop
self.assertFalse(c.segment[3].scod & 4) # no eph
self.assertEqual(c.segment[3].spcod[0], glymur.core.LRCP)
self.assertEqual(c.segment[3].layers, 1) # layers = 1
self.assertEqual(c.segment[3].spcod[3], 1) # mct
self.assertEqual(c.segment[3].spcod[4], 5) # level
self.assertEqual(tuple(c.segment[3].code_block_size),
(64, 64)) # cblk
self.verify_codeblock_style(c.segment[3].spcod[7],
[False, False, False, False, False, False])
self.assertEqual(c.segment[3].spcod[8],
glymur.core.WAVELET_XFORM_5X3_REVERSIBLE)
self.assertEqual(len(c.segment[3].spcod), 9)
# QCD: Quantization default
self.assertEqual(c.segment[4].sqcd & 0x1f, 0)
self.assertEqual(c.segment[4].guard_bits, 2)
self.assertEqual(c.segment[4].mantissa, [0] * 16)
self.assertEqual(c.segment[4].exponent,
[8] + [9, 9, 10] * 5)
# QCC: Quantization component
# associated component
self.assertEqual(c.segment[5].cqcc, 1)
self.assertEqual(c.segment[5].guard_bits, 2)
# quantization type
self.assertEqual(c.segment[5].sqcc & 0x1f, 0) # none
self.assertEqual(c.segment[5].mantissa, [0] * 16)
self.assertEqual(c.segment[5].exponent,
[8] + [9, 9, 10] * 5)
# QCC: Quantization component
# associated component
self.assertEqual(c.segment[6].cqcc, 2)
self.assertEqual(c.segment[6].guard_bits, 2)
# quantization type
self.assertEqual(c.segment[6].sqcc & 0x1f, 0) # none
self.assertEqual(c.segment[6].mantissa, [0] * 16)
self.assertEqual(c.segment[6].exponent,
[8] + [9, 9, 10] * 5)
def test_NR_broken2_jp2_dump(self):
"""
Invalid marker ID in the codestream.