2005-09-01 10:36:07 +00:00
|
|
|
# -*- Mode: Python -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
#
|
|
|
|
# gst-python - Python bindings for GStreamer
|
|
|
|
# Copyright (C) 2002 David I. Lehn
|
|
|
|
# Copyright (C) 2004 Johan Dahlin
|
|
|
|
# Copyright (C) 2005 Edward Hervey
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library 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
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2005-06-17 10:59:47 +00:00
|
|
|
try:
|
|
|
|
from dl import RTLD_LAZY, RTLD_GLOBAL
|
|
|
|
except ImportError:
|
|
|
|
# dl doesn't seem to be available on 64bit systems
|
|
|
|
try:
|
|
|
|
from DLFCN import RTLD_LAZY, RTLD_GLOBAL
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2004-03-08 19:22:15 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2005-09-28 13:29:52 +00:00
|
|
|
import gc
|
2004-03-08 19:22:15 +00:00
|
|
|
import unittest
|
|
|
|
|
2004-05-24 10:30:05 +00:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
|
|
|
|
import gobject
|
2004-08-06 17:38:42 +00:00
|
|
|
try:
|
|
|
|
gobject.threads_init()
|
|
|
|
except:
|
|
|
|
print "WARNING: gobject doesn't have threads_init, no threadsafety"
|
2004-05-24 10:30:05 +00:00
|
|
|
|
2004-04-16 13:56:39 +00:00
|
|
|
# Don't insert before .
|
2005-06-17 10:59:47 +00:00
|
|
|
# sys.path.insert(1, os.path.join('..'))
|
2004-03-17 12:41:08 +00:00
|
|
|
|
2004-04-16 13:56:39 +00:00
|
|
|
# Load GST and make sure we load it from the current build
|
2005-06-17 10:59:47 +00:00
|
|
|
sys.setdlopenflags(RTLD_LAZY | RTLD_GLOBAL)
|
2004-03-17 12:41:08 +00:00
|
|
|
|
2005-06-17 10:59:47 +00:00
|
|
|
topbuilddir = os.path.abspath(os.path.join('..'))
|
|
|
|
topsrcdir = os.path.abspath(os.path.join('..'))
|
|
|
|
if topsrcdir.endswith('_build'):
|
|
|
|
topsrcdir = os.path.dirname(topsrcdir)
|
|
|
|
|
|
|
|
# gst's __init__.py is in topsrcdir/gst
|
|
|
|
path = os.path.abspath(os.path.join(topsrcdir, 'gst'))
|
2004-04-16 13:56:39 +00:00
|
|
|
import gst
|
2005-06-17 10:59:47 +00:00
|
|
|
file = gst.__file__
|
|
|
|
assert file.startswith(path), 'bad gst path: %s' % file
|
2004-03-17 12:41:08 +00:00
|
|
|
|
2005-06-17 10:59:47 +00:00
|
|
|
# gst's interfaces and play are in topbuilddir/gst
|
|
|
|
path = os.path.abspath(os.path.join(topbuilddir, 'gst'))
|
2004-03-17 12:41:08 +00:00
|
|
|
try:
|
2004-04-16 13:56:39 +00:00
|
|
|
import gst.interfaces
|
2004-03-17 12:41:08 +00:00
|
|
|
except ImportError:
|
2005-06-17 10:59:47 +00:00
|
|
|
# hack: we import it from our builddir/gst/.libs instead; ugly
|
|
|
|
import interfaces
|
|
|
|
gst.interfaces = interfaces
|
|
|
|
file = gst.interfaces.__file__
|
|
|
|
assert file.startswith(path), 'bad gst.interfaces path: %s' % file
|
2004-03-17 12:41:08 +00:00
|
|
|
|
2004-11-23 10:16:58 +00:00
|
|
|
# testhelper needs ltihooks
|
2005-06-17 10:59:47 +00:00
|
|
|
import ltihooks
|
2004-11-23 10:16:58 +00:00
|
|
|
import testhelper
|
2005-06-17 10:59:47 +00:00
|
|
|
ltihooks.uninstall()
|
2004-11-23 10:16:58 +00:00
|
|
|
|
2004-05-01 15:35:32 +00:00
|
|
|
_stderr = None
|
|
|
|
|
|
|
|
def disable_stderr():
|
|
|
|
global _stderr
|
|
|
|
_stderr = file('/tmp/stderr', 'w+')
|
|
|
|
sys.stderr = os.fdopen(os.dup(2), 'w')
|
|
|
|
os.close(2)
|
|
|
|
os.dup(_stderr.fileno())
|
|
|
|
|
|
|
|
def enable_stderr():
|
|
|
|
global _stderr
|
|
|
|
|
|
|
|
os.close(2)
|
|
|
|
os.dup(sys.stderr.fileno())
|
|
|
|
_stderr.seek(0, 0)
|
|
|
|
data = _stderr.read()
|
|
|
|
_stderr.close()
|
|
|
|
os.remove('/tmp/stderr')
|
|
|
|
return data
|
2004-05-03 16:17:38 +00:00
|
|
|
|
|
|
|
def run_silent(function, *args, **kwargs):
|
|
|
|
disable_stderr()
|
|
|
|
|
|
|
|
try:
|
|
|
|
function(*args, **kwargs)
|
|
|
|
except Exception, exc:
|
|
|
|
enable_stderr()
|
|
|
|
raise exc
|
|
|
|
|
|
|
|
output = enable_stderr()
|
|
|
|
|
|
|
|
return output
|
2005-09-28 13:29:52 +00:00
|
|
|
|
|
|
|
class TestCase(unittest.TestCase):
|
2005-09-28 15:48:10 +00:00
|
|
|
|
2005-10-13 15:56:16 +00:00
|
|
|
_types = [gst.Object, gst.MiniObject]
|
2005-09-28 15:48:10 +00:00
|
|
|
|
2005-09-28 13:29:52 +00:00
|
|
|
def gccollect(self):
|
|
|
|
# run the garbage collector
|
2005-09-28 14:20:03 +00:00
|
|
|
ret = 0
|
2005-09-28 13:29:52 +00:00
|
|
|
gst.debug('garbage collecting')
|
2005-09-28 14:20:03 +00:00
|
|
|
while True:
|
|
|
|
c = gc.collect()
|
|
|
|
ret += c
|
|
|
|
if c == 0: break
|
2005-09-30 08:23:13 +00:00
|
|
|
gst.debug('done garbage collecting, %d objects' % ret)
|
2005-09-28 14:20:03 +00:00
|
|
|
return ret
|
2005-09-28 13:29:52 +00:00
|
|
|
|
|
|
|
def gctrack(self):
|
|
|
|
# store all gst objects in the gc in a tracking dict
|
|
|
|
# call before doing any allocation in your test, from setUp
|
2005-09-28 15:48:10 +00:00
|
|
|
gst.debug('tracking gc GstObjects for types %r' % self._types)
|
2005-09-28 13:29:52 +00:00
|
|
|
self.gccollect()
|
|
|
|
self._tracked = {}
|
2005-09-28 15:48:10 +00:00
|
|
|
for c in self._types:
|
2005-09-28 13:29:52 +00:00
|
|
|
self._tracked[c] = [o for o in gc.get_objects() if isinstance(o, c)]
|
|
|
|
|
|
|
|
def gcverify(self):
|
|
|
|
# verify no new gst objects got added to the gc
|
|
|
|
# call after doing all cleanup in your test, from tearDown
|
2005-09-28 15:48:10 +00:00
|
|
|
gst.debug('verifying gc GstObjects for types %r' % self._types)
|
2005-09-28 13:29:52 +00:00
|
|
|
new = []
|
2005-09-28 15:48:10 +00:00
|
|
|
for c in self._types:
|
2005-09-28 13:29:52 +00:00
|
|
|
objs = [o for o in gc.get_objects() if isinstance(o, c)]
|
|
|
|
new.extend([o for o in objs if o not in self._tracked[c]])
|
|
|
|
|
|
|
|
self.failIf(new, new)
|
2005-10-05 16:19:13 +00:00
|
|
|
#self.failIf(new, ["%r:%d" % (type(o), id(o)) for o in new])
|
2005-09-28 13:29:52 +00:00
|
|
|
del self._tracked
|
2005-09-28 15:48:10 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Override me by chaining up to me at the start of your setUp.
|
|
|
|
"""
|
2005-10-05 22:33:50 +00:00
|
|
|
gst.debug('%s.%s' % (self.__class__.__name__,
|
|
|
|
self.__testMethodName))
|
2005-09-28 15:48:10 +00:00
|
|
|
self.gctrack()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Override me by chaining up to me at the end of your tearDown.
|
|
|
|
"""
|
2005-10-05 22:33:50 +00:00
|
|
|
gst.debug('%s.%s' % (self.__class__.__name__,
|
|
|
|
self.__testMethodName))
|
2005-09-28 15:48:10 +00:00
|
|
|
self.gccollect()
|
|
|
|
self.gcverify()
|