From d9530cb82aa3e24b78bde4e73b364944520946d6 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Fri, 11 Sep 2009 11:48:17 +0000 Subject: [PATCH] * morituri/common/checksum.py: * morituri/test/Makefile.am: * morituri/test/test_common_checksum.py (added): Add a check to make sure that checksumming an empty file doesn't hang. Fix the hang. --- ChangeLog | 8 ++++++++ morituri/common/checksum.py | 11 +++++++++-- morituri/test/Makefile.am | 1 + morituri/test/test_common_checksum.py | 27 +++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 morituri/test/test_common_checksum.py diff --git a/ChangeLog b/ChangeLog index d86be72..c2d6295 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-09-11 Thomas Vander Stichele + + * morituri/common/checksum.py: + * morituri/test/Makefile.am: + * morituri/test/test_common_checksum.py (added): + Add a check to make sure that checksumming an empty file doesn't + hang. Fix the hang. + 2009-09-08 Thomas Vander Stichele * morituri.spec.in: diff --git a/morituri/common/checksum.py b/morituri/common/checksum.py index 84996b6..4938af3 100644 --- a/morituri/common/checksum.py +++ b/morituri/common/checksum.py @@ -82,7 +82,13 @@ class ChecksumTask(task.Task): if self._frameLength < 0: self.debug('query duration') - length, qformat = sink.query_duration(gst.FORMAT_DEFAULT) + try: + length, qformat = sink.query_duration(gst.FORMAT_DEFAULT) + except gst.QueryError, e: + self.exception = e + self.stop() + return + # wavparse 0.10.14 returns in bytes if qformat == gst.FORMAT_BYTES: self.debug('query returned in BYTES format') @@ -176,7 +182,7 @@ class ChecksumTask(task.Task): if not self._last: # see http://bugzilla.gnome.org/show_bug.cgi?id=578612 print 'ERROR: not a single buffer gotten' - raise + #raise else: self._checksum = self._checksum % 2 ** 32 self.debug("last offset %r", self._last.offset) @@ -328,6 +334,7 @@ class TRMTask(task.Task): def _bus_error_cb(self, bus, message): error = message.parse_error() + # FIXME: handle properly print error def _new_buffer_cb(self, sink): diff --git a/morituri/test/Makefile.am b/morituri/test/Makefile.am index 5cec124..6021e74 100644 --- a/morituri/test/Makefile.am +++ b/morituri/test/Makefile.am @@ -4,6 +4,7 @@ EXTRA_DIST = \ __init__.py \ common.py \ test_common_accurip.py \ + test_common_checksum.py \ test_common_program.py \ test_common_renamer.py \ test_image_cue.py \ diff --git a/morituri/test/test_common_checksum.py b/morituri/test/test_common_checksum.py new file mode 100644 index 0000000..dd720a8 --- /dev/null +++ b/morituri/test/test_common_checksum.py @@ -0,0 +1,27 @@ +# -*- Mode: Python; test-case-name: morituri.test.test_common_checksum -*- +# vi:si:et:sw=4:sts=4:ts=4 + +import os +import unittest +import tempfile + +import gobject +gobject.threads_init() + +import gst + +from morituri.common import task, checksum + +def h(i): + return "0x%08x" % i + +class EmptyTestCase(unittest.TestCase): + def testEmpty(self): + # this test makes sure that checksumming empty files doesn't hang + self.runner = task.SyncRunner(verbose=False) + fd, path = tempfile.mkstemp(suffix='morituri.test.empty') + checksumtask = checksum.ChecksumTask(path) + # FIXME: do we want a specific error for this ? + self.assertRaises(gst.QueryError, self.runner.run, + checksumtask, verbose=False) + os.unlink(path)