From b6acbfe0a1c0de6fde75b414f56f8d61dcf72aa4 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 10 Jan 2005 19:02:53 +0000 Subject: [PATCH] fix callback args so tests work Original commit message from CVS: fix callback args so tests work --- gst/gst.override | 18 ++++++++++++++---- testsuite/test_probe.py | 25 +++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/gst/gst.override b/gst/gst.override index 38803e050e..cdc2d48474 100644 --- a/gst/gst.override +++ b/gst/gst.override @@ -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) { diff --git a/testsuite/test_probe.py b/testsuite/test_probe.py index 648b678009..486561f5de 100644 --- a/testsuite/test_probe.py +++ b/testsuite/test_probe.py @@ -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()