1
# PiTiVi , Non-linear video editor
3
# tests/test_timeline.py
5
# Copyright (c) 2009, Alessandro Decina <alessandro.decina@collabora.co.uk>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU Lesser General Public
9
# License as published by the Free Software Foundation; either
10
# version 2.1 of the License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# Lesser General Public License for more details.
17
# You should have received a copy of the GNU Lesser General Public
18
# License along with this program; if not, write to the
19
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20
# Boston, MA 02110-1301, USA.
22
from unittest import TestCase
23
from pitivi.utils import Seeker
27
class StubSeeker(Seeker):
30
def _scheduleSeek(self, position, format):
31
# mock Seeker._scheduleSeek so that we don't need a mainloop
32
seek_id = self.seek_id
38
class TestSeeker(TestCase):
41
self.seek_position = None
42
self.seek_format = None
45
def seek_cb(seeker, position, format):
47
self.seek_position = position
48
self.seek_format = format
50
seeker = StubSeeker(timeout=10)
51
seeker.connect('seek', seek_cb)
53
# first seek should happen immediately
55
self.failUnlessEqual(self.seek_count, 1)
56
self.failUnlessEqual(self.seek_position, 1)
57
self.failUnlessEqual(self.seek_format, gst.FORMAT_TIME)
58
self.failUnlessEqual(seeker.pending_seek_id, 0)
59
self.failUnlessEqual(seeker.position, None)
60
self.failUnlessEqual(seeker.format, None)
62
# second seek is queued
63
seeker.seek(2, gst.FORMAT_BYTES)
64
self.failUnlessEqual(seeker.pending_seek_id, 0)
65
self.failUnlessEqual(seeker.position, 2)
66
self.failUnlessEqual(seeker.format, gst.FORMAT_BYTES)
68
# ... until the timeout triggers
69
seeker._seekTimeoutCb()
70
self.failUnlessEqual(self.seek_count, 2)
71
self.failUnlessEqual(self.seek_position, 2)
72
self.failUnlessEqual(self.seek_format, gst.FORMAT_BYTES)
73
self.failUnlessEqual(seeker.pending_seek_id, None)
74
self.failUnlessEqual(seeker.position, None)
75
self.failUnlessEqual(seeker.format, None)
77
# do another first-seek
79
self.failUnlessEqual(seeker.pending_seek_id, 1)
80
self.failUnlessEqual(self.seek_count, 3)
81
self.failUnlessEqual(seeker.position, None)
82
self.failUnlessEqual(seeker.format, None)
84
# timeout with None position
85
seeker._seekTimeoutCb()