one item list with structure
authorThomas Vander Stichele <thomas@apestaart.org>
Fri, 6 Aug 2004 19:03:50 +0000 (19:03 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Fri, 6 Aug 2004 19:03:50 +0000 (19:03 +0000)
Original commit message from CVS:
one item list with structure

ChangeLog
gst/gst.override
testsuite/caps.py
testsuite/test_caps.py

index a8189da..cb37c44 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2004-08-06  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+       * gst/gst.override:
+       * testsuite/caps.py:
+         one item list with structure is valid too
+
+2004-08-06  Thomas Vander Stichele  <thomas at apestaart dot org>
+
        * gst/gst.defs:
        * gst/gst.override:
        * testsuite/caps.py:
index 439f2d0..ae8eeb0 100644 (file)
@@ -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;
index b5569a1..cc5cc75 100644 (file)
@@ -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')
index b5569a1..cc5cc75 100644 (file)
@@ -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')