ref: 772a43f4c2b165678555d4df17c10353d2f4d92b
parent: e9f34ef5f075d8845fafe47f81c2c4337f2fd3c0
author: Sebastian Rasmussen <[email protected]>
date: Fri Jun 21 11:02:02 EDT 2019
jbig2dec: Verify file hashes of test files during testing. Previously jbig2dec would accept any file with the same name.
--- a/test_jbig2dec.py
+++ b/test_jbig2dec.py
@@ -4,6 +4,7 @@
import os, re
import sys, time
+import hashlib
class SelfTest:
'generic class for self tests'
@@ -160,11 +161,18 @@
def runTest(self):
'''jbig2dec should return proper document hashes for known files'''
+ # verify that the input file hash is correct
+ sha1 = hashlib.sha1()
+ with open(self.file, 'rb') as f:
+ sha1.update(f.read())
+ self.assertEqual(self.file_hash, sha1.hexdigest())
+
# invoke jbig2dec on our file
instance = os.popen('./jbig2dec -q -o /dev/null --hash ' + self.file)
lines = instance.readlines()
exit_code = instance.close()
self.failIf(exit_code, 'jbig2dec should exit normally')
+
# test here for correct hash
hash_pattern = re.compile('[0-9a-f]{%d}' % len(decode_hash))
for line in lines: