From f59e0690f67d52d7bff9932415732eee1a90bbaa Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Fri, 6 Aug 2004 19:03:50 +0000 Subject: [PATCH] one item list with structure Original commit message from CVS: one item list with structure --- ChangeLog | 6 ++++++ gst/gst.override | 37 +++++++++++++++++++++---------------- testsuite/caps.py | 10 ++++++++++ testsuite/test_caps.py | 10 ++++++++++ 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index a8189da..cb37c44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2004-08-06 Thomas Vander Stichele + * gst/gst.override: + * testsuite/caps.py: + one item list with structure is valid too + +2004-08-06 Thomas Vander Stichele + * gst/gst.defs: * gst/gst.override: * testsuite/caps.py: diff --git a/gst/gst.override b/gst/gst.override index 439f2d0..ae8eeb0 100644 --- a/gst/gst.override +++ b/gst/gst.override @@ -398,30 +398,35 @@ _wrap_gst_caps_new_empty(PyGBoxed *self, PyObject *args, PyObject *kwargs) self->free_on_dealloc = FALSE; if (len == 0) { + /* 0 length creates a new empty caps */ self->boxed = gst_caps_new_empty(); + goto beach; } else if (len == 1) { + /* 1 length is either a string or a structure */ item = PyTuple_GetItem(args, 0); - if (!PyString_Check(item)) { - PyErr_SetString(PyExc_TypeError, "argument must be a string"); + if (PyString_Check(item)) { + self->boxed = gst_caps_from_string(PyString_AsString(item)); + goto beach; + } else if (!pyg_boxed_check(item, GST_TYPE_STRUCTURE)) { + PyErr_SetString(PyExc_TypeError, "argument must be a string or a GstStructure"); return -1; } - self->boxed = gst_caps_from_string(PyString_AsString(item)); - } else { - self->boxed = gst_caps_new_empty(); - for (i = 0; i < len; i++) - { - item = PyTuple_GetItem(args, i); - if (!pyg_boxed_check(item, GST_TYPE_STRUCTURE)) - { - PyErr_SetString(PyExc_TypeError, "argument must be a GstStructure"); - gst_caps_free(self->boxed); - return -1; - } - gst_caps_append_structure(self->boxed, pyg_boxed_get(item, GstStructure)); + } + /* it's either one GstStructure or several whatevers */ + self->boxed = gst_caps_new_empty(); + for (i = 0; i < len; i++) + { + item = PyTuple_GetItem(args, i); + if (!pyg_boxed_check(item, GST_TYPE_STRUCTURE)) + { + PyErr_SetString(PyExc_TypeError, "argument must be a GstStructure"); + gst_caps_free(self->boxed); + return -1; } + gst_caps_append_structure(self->boxed, pyg_boxed_get(item, GstStructure)); } - +beach: if (!self->boxed) { PyErr_SetString(PyExc_RuntimeError, "could not create GstCaps object"); return -1; diff --git a/testsuite/caps.py b/testsuite/caps.py index b5569a1..cc5cc75 100644 --- a/testsuite/caps.py +++ b/testsuite/caps.py @@ -32,6 +32,16 @@ class CapsTest(unittest.TestCase): assert isinstance(caps[0]['width'], int) assert caps[0]['width'] == 10 + def testCapsConstructFromStructure(self): + struct = gst.structure_from_string('video/x-raw-yuv,width=10') + caps = gst.Caps(struct) + assert isinstance(caps, gst.Caps) + assert len(caps) == 1 + assert isinstance(caps[0], gst.Structure) + assert caps[0].get_name() == 'video/x-raw-yuv' + assert isinstance(caps[0]['width'], int) + assert caps[0]['width'] == 10 + def testCapsConstructFromStructures(self): struct1 = gst.structure_from_string('video/x-raw-yuv,width=10') struct2 = gst.structure_from_string('video/x-raw-rgb,height=20.0') diff --git a/testsuite/test_caps.py b/testsuite/test_caps.py index b5569a1..cc5cc75 100644 --- a/testsuite/test_caps.py +++ b/testsuite/test_caps.py @@ -32,6 +32,16 @@ class CapsTest(unittest.TestCase): assert isinstance(caps[0]['width'], int) assert caps[0]['width'] == 10 + def testCapsConstructFromStructure(self): + struct = gst.structure_from_string('video/x-raw-yuv,width=10') + caps = gst.Caps(struct) + assert isinstance(caps, gst.Caps) + assert len(caps) == 1 + assert isinstance(caps[0], gst.Structure) + assert caps[0].get_name() == 'video/x-raw-yuv' + assert isinstance(caps[0]['width'], int) + assert caps[0]['width'] == 10 + def testCapsConstructFromStructures(self): struct1 = gst.structure_from_string('video/x-raw-yuv,width=10') struct2 = gst.structure_from_string('video/x-raw-rgb,height=20.0') -- 2.7.4