fix callback args so tests work
authorThomas Vander Stichele <thomas@apestaart.org>
Mon, 10 Jan 2005 19:02:53 +0000 (19:02 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Mon, 10 Jan 2005 19:02:53 +0000 (19:02 +0000)
Original commit message from CVS:
fix callback args so tests work

gst/gst.override
testsuite/test_probe.py

index 38803e0..cdc2d48 100644 (file)
@@ -627,17 +627,27 @@ probe_handler_marshal(GstProbe *probe, GstData **data, gpointer user_data)
     PyGILState_STATE state;
     PyObject *callback, *args;
     PyObject *ret;
+    PyObject *py_user_data;
     gboolean res;
+    gint len, i;
 
     g_return_val_if_fail(user_data != NULL, FALSE);
 
     state = pyg_gil_state_ensure();
 
-    callback = PyTuple_GetItem((PyObject *)user_data, 0);
-    args = Py_BuildValue("(NNO)",
+    py_user_data = (PyObject *) user_data;
+
+    callback = PyTuple_GetItem(py_user_data, 0);
+    args = Py_BuildValue("(NN)",
         pyg_boxed_new(GST_TYPE_PROBE, probe, TRUE, TRUE),
-        pyg_boxed_new(GST_TYPE_DATA, *data, TRUE, TRUE),
-        PyTuple_GetItem((PyObject *)user_data, 1));
+        pyg_boxed_new(GST_TYPE_DATA, *data, TRUE, TRUE));
+
+    len = PyTuple_Size(py_user_data);
+    for (i = 1; i < len; ++i) {
+        PyObject *tuple = args;
+        args = PySequence_Concat(tuple, PyTuple_GetItem(py_user_data, i));
+        Py_DECREF(tuple);
+    }
     ret = PyObject_CallObject(callback, args);
 
     if (!ret) {
index 648b678..486561f 100644 (file)
@@ -19,7 +19,16 @@ class ProbeTest(unittest.TestCase):
         self.assertRaises(TypeError, probe.perform, None)
         self.assertRaises(TypeError, probe.perform, "nodata")
 
-    def testPerform(self):
+    def testPerformNoArg(self):
+        probe = gst.Probe(True, self._probe_callback_no_arg)
+        buffer = gst.Buffer()
+        probe.perform(buffer)
+        self.assertEqual(self._no_arg, None)
+
+    def _probe_callback_no_arg(self, probe, data):
+        self._no_arg = None
+
+    def testPerformOneArg(self):
         probe = gst.Probe(True, self._probe_callback, "yeeha")
         buffer = gst.Buffer()
         probe.perform(buffer)
@@ -28,6 +37,18 @@ class ProbeTest(unittest.TestCase):
     def _probe_callback(self, probe, data, result):
         self._probe_result = result
         return True
-   
+
+    def testPerformTwoArgs(self):
+        probe = gst.Probe(True, self._probe_callback_two, "yeeha", "works")
+        buffer = gst.Buffer()
+        probe.perform(buffer)
+        self.assertEqual(self._probe_result1, "yeeha")
+        self.assertEqual(self._probe_result2, "works")
+
+    def _probe_callback_two(self, probe, data, result1, result2):
+        self._probe_result1 = result1
+        self._probe_result2 = result2
+        return True
+    
 if __name__ == "__main__":
     unittest.main()