From f2a5a97ac37836d90b3da14342112db6f363363c Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Thu, 27 Oct 2005 09:51:18 +0000 Subject: [PATCH] add gst.QueryError and use it Original commit message from CVS: * gst/gstelement.override: * gst/pygstexception.c: * gst/pygstexception.h: * testsuite/test_element.py: add gst.QueryError and use it * testsuite/test_pad.py: add some tests that show comparison between two different Python objects wrapping the same MiniObject --- ChangeLog | 11 +++++++++++ gst/gstelement.override | 14 +++++++------- gst/pygstexception.c | 14 ++++++++++++++ gst/pygstexception.h | 1 + testsuite/test_element.py | 4 ++-- testsuite/test_pad.py | 12 ++++++++++-- 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 33c3b1e..f8b6f36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2005-10-27 Thomas Vander Stichele + * gst/gstelement.override: + * gst/pygstexception.c: + * gst/pygstexception.h: + * testsuite/test_element.py: + add gst.QueryError and use it + * testsuite/test_pad.py: + add some tests that show comparison between two different + Python objects wrapping the same MiniObject + +2005-10-27 Thomas Vander Stichele + * gst/gst.override: * gst/pygstminiobject.c: remove the hash table for miniobjects - since we can't get notified diff --git a/gst/gstelement.override b/gst/gstelement.override index 3fc24e0..9e575f6 100644 --- a/gst/gstelement.override +++ b/gst/gstelement.override @@ -374,15 +374,15 @@ _wrap_gst_element_query_position (PyGObject *self, PyObject *args) } ret = PyList_New(0); - if ((gst_element_query_position(GST_ELEMENT (self->obj), (GstFormat*) &format, &cur))) { - PyList_Append(ret, PyLong_FromLongLong(cur)); - PyList_Append(ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, format )); - } else { - g_print("FIXME: query failed\n"); - Py_INCREF(Py_None); - ret = Py_None; + if (!(gst_element_query_position(GST_ELEMENT (self->obj), (GstFormat*) &format, &cur))) { + PyErr_Format(PyGstExc_QueryError, + "query failed"); + return NULL; } + PyList_Append(ret, PyLong_FromLongLong(cur)); + PyList_Append(ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, format )); + return ret; } %% diff --git a/gst/pygstexception.c b/gst/pygstexception.c index 0c880b7..5fec47b 100644 --- a/gst/pygstexception.c +++ b/gst/pygstexception.c @@ -26,6 +26,7 @@ PyObject *PyGstExc_LinkError = NULL; PyObject *PyGstExc_AddError = NULL; +PyObject *PyGstExc_QueryError = NULL; PyObject *PyGstExc_RemoveError = NULL; PyObject *PyGstExc_PluginNotFoundError = NULL; @@ -189,6 +190,18 @@ pygst_exceptions_register_classes(PyObject *d) goto exception; Py_DECREF(PyGstExc_RemoveError); + + /* register gst.QueryError */ + PyGstExc_QueryError = PyErr_NewException("gst.QueryError", + PyExc_Exception, NULL); + if (PyGstExc_QueryError == NULL) + goto exception; + + if (PyDict_SetItemString(d, "QueryError", PyGstExc_QueryError) < 0) + goto exception; + + Py_DECREF(PyGstExc_QueryError); + /* register gst.PluginNotFoundError */ dict = PyDict_New(); @@ -219,6 +232,7 @@ exception: Py_XDECREF(PyGstExc_LinkError); Py_XDECREF(PyGstExc_AddError); Py_XDECREF(PyGstExc_RemoveError); + Py_XDECREF(PyGstExc_QueryError); Py_XDECREF(PyGstExc_PluginNotFoundError); return; diff --git a/gst/pygstexception.h b/gst/pygstexception.h index bd50cf5..5228703 100644 --- a/gst/pygstexception.h +++ b/gst/pygstexception.h @@ -27,6 +27,7 @@ extern PyObject *PyGstExc_LinkError; extern PyObject *PyGstExc_AddError; extern PyObject *PyGstExc_RemoveError; +extern PyObject *PyGstExc_QueryError; extern PyObject *PyGstExc_PluginNotFoundError; void pygst_exceptions_register_classes(PyObject *d); diff --git a/testsuite/test_element.py b/testsuite/test_element.py index 7c94dbb..a1b8826 100644 --- a/testsuite/test_element.py +++ b/testsuite/test_element.py @@ -197,8 +197,8 @@ class QueryTest(TestCase): self.assertEquals(sys.getrefcount(self.element), 3) assert res assert res[0] == 0 - res = self.element.query_position(gst.FORMAT_TIME) - assert not res + self.assertRaises(gst.QueryError, self.element.query_position, + gst.FORMAT_TIME) self.gccollect() class QueueTest(TestCase): diff --git a/testsuite/test_pad.py b/testsuite/test_pad.py index b492991..0276459 100644 --- a/testsuite/test_pad.py +++ b/testsuite/test_pad.py @@ -128,14 +128,22 @@ class PadPushLinkedTest(TestCase): self.assertEquals(len(self.buffers), 0) def testTrueProbe(self): - id = self.src.add_buffer_probe(self._probe_handler, True) + probe_id = self.src.add_buffer_probe(self._probe_handler, True) self.buffer = gst.Buffer() self.assertEquals(self.buffer.__grefcount__, 1) self.assertEquals(self.src.push(self.buffer), gst.FLOW_OK) # one refcount is held by our scope, another is held on # self.buffers through _chain_func self.assertEquals(self.buffer.__grefcount__, 2) - self.src.remove_buffer_probe(id) + + # they are not the same Python object ... + self.failIf(self.buffer is self.buffers[0]) + self.failIf(id(self.buffer) == id(self.buffers[0])) + # ... but they wrap the same GstBuffer + self.failUnless(self.buffer == self.buffers[0]) + self.assertEquals(repr(self.buffer), repr(self.buffers[0])) + + self.src.remove_buffer_probe(probe_id) self.assertEquals(len(self.buffers), 1) self.buffers = None self.assertEquals(self.buffer.__grefcount__, 1) -- 2.7.4