add gst.QueryError and use it
authorThomas Vander Stichele <thomas@apestaart.org>
Thu, 27 Oct 2005 09:51:18 +0000 (09:51 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Thu, 27 Oct 2005 09:51:18 +0000 (09:51 +0000)
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
gst/gstelement.override
gst/pygstexception.c
gst/pygstexception.h
testsuite/test_element.py
testsuite/test_pad.py

index 33c3b1e..f8b6f36 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2005-10-27  Thomas Vander Stichele  <thomas (at) apestaart (dot) org>
 
+       * 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  <thomas (at) apestaart (dot) org>
+
        * gst/gst.override:
        * gst/pygstminiobject.c:
          remove the hash table for miniobjects - since we can't get notified
index 3fc24e0..9e575f6 100644 (file)
@@ -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;
 }
 %%
index 0c880b7..5fec47b 100644 (file)
@@ -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;
index bd50cf5..5228703 100644 (file)
@@ -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);
index 7c94dbb..a1b8826 100644 (file)
@@ -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):
index b492991..0276459 100644 (file)
@@ -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)