2 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
4 * gststructure.c: Unit tests for GstStructure
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include <gst/check/gstcheck.h>
26 GST_START_TEST (test_from_string_int)
28 const char *strings[] = {
29 "video/x-raw-rgb, width = (int) 123456",
30 "video/x-raw-rgb, stride = (int) -123456",
31 "video/x-raw-rgb, red_mask = (int) 0xFFFF",
32 "video/x-raw-rgb, red_mask = (int) 0x0000FFFF",
33 "video/x-raw-rgb, red_mask = (int) 0x7FFFFFFF",
34 "video/x-raw-rgb, red_mask = (int) 0x80000000",
35 "video/x-raw-rgb, red_mask = (int) 0xFF000000",
37 * gst-launch ... ! "video/x-raw-rgb, red_mask=(int)0xFF000000" ! ... */
38 "video/x-raw-rgb,\\ red_mask=(int)0xFF000000",
50 GstStructure *structure;
53 for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
60 structure = gst_structure_from_string (s, NULL);
61 fail_if (structure == NULL, "Could not get structure from string %s", s);
62 name = gst_structure_nth_field_name (structure, 0);
63 fail_unless (gst_structure_get_int (structure, name, &value));
64 fail_unless (value == results[i],
65 "Value %d is not the expected result %d for string %s",
66 value, results[i], s);
69 gst_structure_free (structure);
75 /* Test type conversions from string */
76 GST_START_TEST (test_from_string)
78 GstStructure *structure;
82 s = "test-string,value=1";
83 structure = gst_structure_from_string (s, NULL);
84 fail_if (structure == NULL, "Could not get structure from string %s", s);
85 fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL);
86 fail_unless (G_VALUE_HOLDS_INT (val));
87 gst_structure_free (structure);
89 s = "test-string,value=1.0";
90 structure = gst_structure_from_string (s, NULL);
91 fail_if (structure == NULL, "Could not get structure from string %s", s);
92 fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL);
93 fail_unless (G_VALUE_HOLDS_DOUBLE (val));
94 gst_structure_free (structure);
96 s = "test-string,value=1/1";
97 structure = gst_structure_from_string (s, NULL);
98 fail_if (structure == NULL, "Could not get structure from string %s", s);
99 fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL);
100 fail_unless (GST_VALUE_HOLDS_FRACTION (val));
101 gst_structure_free (structure);
103 s = "test-string,value=bar";
104 structure = gst_structure_from_string (s, NULL);
105 fail_if (structure == NULL, "Could not get structure from string %s", s);
106 fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL);
107 fail_unless (G_VALUE_HOLDS_STRING (val));
108 gst_structure_free (structure);
113 GST_START_TEST (test_complete_structure)
115 GstStructure *structure;
118 s = "GstEventSeek, rate=(double)1, format=(GstFormat)GST_FORMAT_TIME, flags=(GstSeekFlags)GST_SEEK_FLAGS_NONE, cur_type=(GstSeekType)GST_SEEK_TYPE_SET, cur=(gint64)1000000000, stop_type=(GstSeekType)GST_SEEK_TYPE_NONE, stop=(gint64)0";
119 structure = gst_structure_from_string (s, NULL);
120 fail_if (structure == NULL, "Could not get structure from string %s", s);
121 /* FIXME: TODO: add checks for correct serialization of members ? */
122 gst_structure_free (structure);
127 GST_START_TEST (test_structure_new)
133 s = gst_structure_new ("name", "key", G_TYPE_STRING, "value", NULL);
134 fail_unless (strcmp (gst_structure_get_string (s, "key"), "value") == 0);
135 gst_structure_free (s);
137 domain = g_quark_from_string ("test");
138 e = g_error_new (domain, 0, "a test error");
139 s = gst_structure_new ("name", "key", GST_TYPE_G_ERROR, e, NULL);
141 gst_structure_free (s);
147 gst_structure_suite (void)
149 Suite *s = suite_create ("GstStructure");
150 TCase *tc_chain = tcase_create ("general");
152 suite_add_tcase (s, tc_chain);
153 tcase_add_test (tc_chain, test_from_string_int);
154 tcase_add_test (tc_chain, test_from_string);
155 tcase_add_test (tc_chain, test_complete_structure);
156 tcase_add_test (tc_chain, test_structure_new);
160 GST_CHECK_MAIN (gst_structure);