wrap gst.Element.get_state, returning a tuple add tests for it

Original commit message from CVS:
wrap gst.Element.get_state, returning a tuple
add tests for it
This commit is contained in:
Thomas Vander Stichele 2005-09-08 15:13:06 +00:00
parent 4132069a83
commit 83f80e9942
3 changed files with 61 additions and 7 deletions

View file

@ -1,3 +1,10 @@
2005-09-08 Thomas Vander Stichele <thomas at apestaart dot org>
* gst/gstelement.override:
* testsuite/test_bin.py:
wrap gst.Element.get_state, returning a tuple
add tests for it
2005-09-08 Thomas Vander Stichele <thomas at apestaart dot org>
* gst/gst.defs:

View file

@ -113,16 +113,45 @@ override gst_element_get_state kwargs
static PyObject *
_wrap_gst_element_get_state(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "timeout", NULL };
GstState state;
GstStateChangeReturn ret;
GstState pending;
GstStateChangeReturn ret;
PyObject *timeout;
GTimeVal *timevalp = NULL;
GTimeVal timeval;
PyObject *tuple;
/* Only returns the state for the time being */
ret = gst_element_get_state(GST_ELEMENT (self->obj), &state, NULL, NULL);
if (!ret) {
PyErr_SetString(PyExc_RuntimeError, "Element is in an error state");
return NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O:GstElement.get_state", kwlist,
&timeout)) {
PyErr_SetString(PyExc_RuntimeError, "Timeout not specified correctly");
return NULL;
}
return pyg_enum_from_gtype(GST_TYPE_STATE, state);
if (timeout != Py_None) {
gdouble timeoutd;
if (!PyFloat_Check (timeout)) {
PyErr_SetString(PyExc_TypeError, "Timeout not specified as double");
return NULL;
}
timeoutd = PyFloat_AsDouble (timeout);
timeval.tv_sec = (glong) timeoutd;
timeval.tv_usec = (glong) ((timeoutd - (gdouble) timeval.tv_sec)
* 1000.0 * 1000.0);
timevalp = &timeval;
}
ret = gst_element_get_state(GST_ELEMENT (self->obj), &state, &pending,
&timeval);
tuple = Py_BuildValue("OOO",
pyg_enum_from_gtype (GST_TYPE_STATE_CHANGE_RETURN, ret),
pyg_enum_from_gtype (GST_TYPE_STATE, state),
pyg_enum_from_gtype (GST_TYPE_STATE, pending));
return tuple;
}
%%
/* override gst_element_query kwargs */

View file

@ -52,5 +52,23 @@ class BinSubclassTest(unittest.TestCase):
bin.set_state(gst.STATE_PLAYING)
self.failUnless(bin._state_changed)
# test get_state with no timeout
(ret, state, pending) = bin.get_state(None)
self.failIfEqual(ret, gst.STATE_CHANGE_FAILURE)
if ret == gst.STATE_CHANGE_SUCCESS:
self.assertEquals(state, gst.STATE_PLAYING)
self.assertEquals(pending, gst.STATE_VOID_PENDING)
# test get_state with a timeout
(ret, state, pending) = bin.get_state(0.1)
self.failIfEqual(ret, gst.STATE_CHANGE_FAILURE)
if ret == gst.STATE_CHANGE_SUCCESS:
self.assertEquals(state, gst.STATE_PLAYING)
self.assertEquals(pending, gst.STATE_VOID_PENDING)
(ret, state, pending) = bin.get_state(timeout=0.1)
if __name__ == "__main__":
unittest.main()