mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
check/: copy over from 0.8, and add two with bitmasks specified with (int) 0xFF...
Original commit message from CVS: * check/Makefile.am: * check/gst/capslist.h: copy over from 0.8, and add two with bitmasks specified with (int) 0xFF... * check/gst/gstcaps.c: (START_TEST), (gst_caps_suite): add test to parse everything from capslist.h * check/gst/gststructure.c: (START_TEST), (gst_value_suite), (main): add test for structure deserialization * check/gst/gstvalue.c: (START_TEST), (gst_value_suite): add tests for deserialization of strings to int types * gst/gststructure.c: (gst_structure_nth_field_name): * gst/gststructure.h: add a way to get the name of a field referenced by index * gst/gstvalue.c: (gst_value_deserialize_int_helper): instead of checking if the resulting long long lies between min and max, we check if the long long would fit into a number of bytes for the final type. This fixes cases where a string represents 2^32 - 1, which when cast to int would be the (valid) -1, but is bigger than G_MAXINT
This commit is contained in:
parent
8952d2c571
commit
c3efeeb64c
14 changed files with 533 additions and 23 deletions
24
ChangeLog
24
ChangeLog
|
@ -1,3 +1,27 @@
|
|||
2005-06-22 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* check/Makefile.am:
|
||||
* check/gst/capslist.h:
|
||||
copy over from 0.8, and add two with bitmasks specified with
|
||||
(int) 0xFF...
|
||||
* check/gst/gstcaps.c: (START_TEST), (gst_caps_suite):
|
||||
add test to parse everything from capslist.h
|
||||
* check/gst/gststructure.c: (START_TEST), (gst_value_suite),
|
||||
(main):
|
||||
add test for structure deserialization
|
||||
* check/gst/gstvalue.c: (START_TEST), (gst_value_suite):
|
||||
add tests for deserialization of strings to int types
|
||||
* gst/gststructure.c: (gst_structure_nth_field_name):
|
||||
* gst/gststructure.h:
|
||||
add a way to get the name of a field referenced by index
|
||||
* gst/gstvalue.c: (gst_value_deserialize_int_helper):
|
||||
instead of checking if the resulting long long lies between
|
||||
min and max, we check if the long long would fit into
|
||||
a number of bytes for the final type.
|
||||
This fixes cases where a string represents 2^32 - 1, which
|
||||
when cast to int would be the (valid) -1, but is bigger than
|
||||
G_MAXINT
|
||||
|
||||
2005-06-22 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* gst/parse/grammar.y:
|
||||
|
|
|
@ -34,6 +34,7 @@ TESTS = $(top_builddir)/tools/gst-register \
|
|||
gst/gstobject \
|
||||
gst/gstpad \
|
||||
gst/gstsystemclock \
|
||||
gst/gststructure \
|
||||
gst/gsttag \
|
||||
gst/gstvalue \
|
||||
pipelines/simple_launch_lines \
|
||||
|
|
20
check/gst/capslist.h
Normal file
20
check/gst/capslist.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <glib.h>
|
||||
|
||||
/* defines an array of strings named caps_list, that contains a list of caps for
|
||||
general tests. So if you don't know what caps to use to write a test, just
|
||||
include this file */
|
||||
|
||||
static const gchar *caps_list[] = {
|
||||
"audio/x-adpcm, layout=(string)quicktime; audio/x-adpcm, layout=(string)quicktime; audio/x-adpcm, layout=(string)wav; audio/x-adpcm, layout=(string)wav; audio/x-adpcm, layout=(string)dk3; audio/x-adpcm, layout=(string)dk3; audio/x-adpcm, layout=(string)dk4; audio/x-adpcm, layout=(string)dk4; audio/x-adpcm, layout=(string)westwood; audio/x-adpcm, layout=(string)westwood; audio/x-adpcm, layout=(string)smjpeg; audio/x-adpcm, layout=(string)smjpeg; audio/x-adpcm, layout=(string)microsoft; audio/x-adpcm, layout=(string)microsoft; audio/x-adpcm, layout=(string)4xm; audio/x-adpcm, layout=(string)4xm; audio/x-adpcm, layout=(string)xa; audio/x-adpcm, layout=(string)xa; audio/x-adpcm, layout=(string)adx; audio/x-adpcm, layout=(string)adx; audio/x-adpcm, layout=(string)ea; audio/x-adpcm, layout=(string)ea; audio/x-adpcm, layout=(string)g726; audio/x-adpcm, layout=(string)g726",
|
||||
"video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)I420; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)YUY2; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)24, depth=(int)24, red_mask=(int)16711680, green_mask=(int)65280, blue_mask=(int)255, endianness=(int)4321; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)24, depth=(int)24, red_mask=(int)255, green_mask=(int)65280, blue_mask=(int)16711680, endianness=(int)4321; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)Y42B; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)32, depth=(int)24, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, endianness=(int)4321; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)YUV9; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)Y41B; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)16, depth=(int)16, red_mask=(int)63488, green_mask=(int)2016, blue_mask=(int)31, endianness=(int)1234; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)16, depth=(int)15, red_mask=(int)31744, green_mask=(int)992, blue_mask=(int)31, endianness=(int)1234",
|
||||
"video/x-raw-yuv, format=(fourcc){ YUY2, I420 }, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]; video/x-jpeg, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-divx, divxversion=(int)[ 3, 5 ], width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-xvid, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-3ivx, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-msmpeg, msmpegversion=(int)[ 41, 43 ], width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/mpeg, mpegversion=(int)1, systemstream=(boolean)false, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-h263, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-dv, systemstream=(boolean)false, width=(int)720, height=(int){ 576, 480 }; video/x-huffyuv, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]",
|
||||
"video/x-raw-yuv, format=(fourcc){ YUY2, I420 }, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]; image/jpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-divx, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], divxversion=(int)[ 3, 5 ]; video/x-xvid, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-3ivx, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-msmpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], msmpegversion=(int)[ 41, 43 ]; video/mpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], mpegversion=(int)1, systemstream=(boolean)false; video/x-h263, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-dv, width=(int)720, height=(int){ 576, 480 }, systemstream=(boolean)false; video/x-huffyuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]",
|
||||
"video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]; video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)-16777216, green_mask=(int)16711680, blue_mask=(int)65280, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]",
|
||||
"video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]",
|
||||
"video/x-raw-yuv, format=(fourcc){ I420 }, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]",
|
||||
"video/x-raw-rgb, bpp = (int) 32, depth = (int) 24, endianness = (int) BIG_ENDIAN, red_mask = (int) 0x000000FF, framerate = (double) [ 0, max ]",
|
||||
"video/x-raw-rgb, bpp = (int) 32, depth = (int) 24, endianness = (int) BIG_ENDIAN, red_mask = (int) 0xFF000000, framerate = (double) [ 0, max ]",
|
||||
"ANY",
|
||||
"EMPTY"
|
||||
};
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gstcaps.c: Unit test for GstCaps
|
||||
*
|
||||
|
@ -21,7 +22,22 @@
|
|||
|
||||
|
||||
#include "../gstcheck.h"
|
||||
#include "capslist.h"
|
||||
|
||||
START_TEST (test_from_string)
|
||||
{
|
||||
GstCaps *caps;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (caps_list); i++) {
|
||||
caps = gst_caps_from_string (caps_list[i]);
|
||||
fail_if (caps == NULL,
|
||||
"Could not create caps from string %s\n", caps_list[i]);
|
||||
g_free (caps);
|
||||
}
|
||||
}
|
||||
|
||||
END_TEST;
|
||||
|
||||
START_TEST (test_buffer)
|
||||
{
|
||||
|
@ -37,7 +53,8 @@ START_TEST (test_buffer)
|
|||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
END_TEST
|
||||
END_TEST;
|
||||
|
||||
START_TEST (test_double_append)
|
||||
{
|
||||
GstStructure *s1;
|
||||
|
@ -49,7 +66,8 @@ START_TEST (test_double_append)
|
|||
ASSERT_CRITICAL (gst_caps_append_structure (c1, s1));
|
||||
}
|
||||
|
||||
END_TEST
|
||||
END_TEST;
|
||||
|
||||
START_TEST (test_mutability)
|
||||
{
|
||||
GstStructure *s1;
|
||||
|
@ -76,13 +94,17 @@ START_TEST (test_mutability)
|
|||
fail_unless (gst_structure_get_int (s1, "rate", &ret));
|
||||
fail_unless (ret == 1);
|
||||
}
|
||||
END_TEST Suite *
|
||||
|
||||
END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_caps_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstCaps");
|
||||
TCase *tc_chain = tcase_create ("mutability");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_from_string);
|
||||
tcase_add_test (tc_chain, test_double_append);
|
||||
tcase_add_test (tc_chain, test_mutability);
|
||||
tcase_add_test (tc_chain, test_buffer);
|
||||
|
|
94
check/gst/gststructure.c
Normal file
94
check/gst/gststructure.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gststructure.c: Unit tests for GstStructure
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "../gstcheck.h"
|
||||
|
||||
|
||||
START_TEST (test_from_string_int)
|
||||
{
|
||||
const char *strings[] = {
|
||||
"video/x-raw-rgb, width = (int) 123456",
|
||||
"video/x-raw-rgb, stride = (int) -123456",
|
||||
"video/x-raw-rgb, red_mask = (int) 0xFFFF",
|
||||
"video/x-raw-rgb, red_mask = (int) 0x0000FFFF",
|
||||
"video/x-raw-rgb, red_mask = (int) 0x7FFFFFFF",
|
||||
"video/x-raw-rgb, red_mask = (int) 0x80000000",
|
||||
"video/x-raw-rgb, red_mask = (int) 0xFF000000",
|
||||
};
|
||||
gint results[] = {
|
||||
123456,
|
||||
-123456,
|
||||
0xFFFF,
|
||||
0xFFFF,
|
||||
0x7FFFFFFF,
|
||||
0x80000000,
|
||||
0xFF000000,
|
||||
};
|
||||
GstStructure *structure;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||
const char *s;
|
||||
const gchar *name;
|
||||
gint value;
|
||||
|
||||
s = strings[i];
|
||||
|
||||
structure = gst_structure_from_string (s, NULL);
|
||||
fail_if (structure == NULL, "Could not get structure from string %s", s);
|
||||
name = gst_structure_nth_field_name (structure, 0);
|
||||
fail_unless (gst_structure_get_int (structure, name, &value));
|
||||
fail_unless (value == results[i],
|
||||
"Value %d is not the expected result %d for string %s",
|
||||
value, results[i], s);
|
||||
}
|
||||
}
|
||||
|
||||
END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_value_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstStructure");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_from_string_int);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_value_suite ();
|
||||
SRunner *sr = srunner_create (s);
|
||||
|
||||
gst_check_init (&argc, &argv);
|
||||
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
nf = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
|
||||
return nf;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2004> David Schleef <david at schleef dot org>
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gstvalue.c: Unit tests for GstValue
|
||||
*
|
||||
|
@ -36,13 +37,97 @@ END_TEST;
|
|||
START_TEST (test_deserialize_gint64)
|
||||
{
|
||||
GValue value = { 0 };
|
||||
const char *string = "12345678901";
|
||||
|
||||
const char *strings[] = {
|
||||
"12345678901",
|
||||
"-12345678901",
|
||||
};
|
||||
gint64 results[] = {
|
||||
12345678901LL,
|
||||
-12345678901LL,
|
||||
};
|
||||
int i;
|
||||
|
||||
g_value_init (&value, G_TYPE_INT64);
|
||||
fail_unless (gst_value_deserialize (&value, string));
|
||||
fail_unless (g_value_get_int64 (&value) == 12345678901LL,
|
||||
"resulting value is %" G_GINT64_FORMAT ", not %s", value, string);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||
fail_unless (gst_value_deserialize (&value, strings[i]),
|
||||
"could not deserialize %s (%d)", strings[i], i);
|
||||
fail_unless (g_value_get_int64 (&value) == results[i],
|
||||
"resulting value is %" G_GINT64_FORMAT ", not %" G_GINT64_FORMAT
|
||||
", for string %s (%d)", value, results[i], strings[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
END_TEST;
|
||||
|
||||
START_TEST (test_deserialize_gint)
|
||||
{
|
||||
GValue value = { 0 };
|
||||
const char *strings[] = {
|
||||
"-",
|
||||
"123456",
|
||||
"-123456",
|
||||
"0xFFFF",
|
||||
"0x0000FFFF",
|
||||
/* a positive long long, serializing to highest possible positive sint */
|
||||
"0x7FFFFFFF",
|
||||
/* a positive long long, serializing to lowest possible negative sint */
|
||||
"0x80000000",
|
||||
/* a negative long long, serializing to lowest possible negative sint */
|
||||
"0xFFFFFFFF80000000",
|
||||
"0xFF000000",
|
||||
/* a positive long long serializing to -1 */
|
||||
"0xFFFFFFFF",
|
||||
/* a negative long long serializing to -1 */
|
||||
"0xFFFFFFFFFFFFFFFF",
|
||||
"0xEFFFFFFF",
|
||||
};
|
||||
gint results[] = {
|
||||
0,
|
||||
123456,
|
||||
-123456,
|
||||
0xFFFF,
|
||||
0xFFFF,
|
||||
0x7FFFFFFF,
|
||||
0x80000000,
|
||||
0x80000000,
|
||||
0xFF000000,
|
||||
-1,
|
||||
-1,
|
||||
0xEFFFFFFF,
|
||||
};
|
||||
int i;
|
||||
|
||||
g_value_init (&value, G_TYPE_INT);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||
fail_unless (gst_value_deserialize (&value, strings[i]),
|
||||
"could not deserialize %s (%d)", strings[i], i);
|
||||
fail_unless (g_value_get_int (&value) == results[i],
|
||||
"resulting value is %d, not %d, for string %s (%d)",
|
||||
g_value_get_int (&value), results[i], strings[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
END_TEST;
|
||||
|
||||
START_TEST (test_deserialize_gint_failures)
|
||||
{
|
||||
GValue value = { 0 };
|
||||
const char *strings[] = {
|
||||
"0x0000000100000000", /* lowest long long that cannot fit in 32 bits */
|
||||
"0xF000000000000000",
|
||||
"0xFFFFFFF000000000",
|
||||
"0xFFFFFFFF00000000",
|
||||
};
|
||||
int i;
|
||||
|
||||
g_value_init (&value, G_TYPE_INT);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||
fail_if (gst_value_deserialize (&value, strings[i]),
|
||||
"deserialized %s (%d), while it should have failed", strings[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
END_TEST;
|
||||
|
@ -134,6 +219,8 @@ gst_value_suite (void)
|
|||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_deserialize_buffer);
|
||||
tcase_add_test (tc_chain, test_deserialize_gint);
|
||||
tcase_add_test (tc_chain, test_deserialize_gint_failures);
|
||||
tcase_add_test (tc_chain, test_deserialize_gint64);
|
||||
tcase_add_test (tc_chain, test_string);
|
||||
tcase_add_test (tc_chain, test_deserialize_string);
|
||||
|
|
|
@ -685,6 +685,21 @@ gst_structure_n_fields (const GstStructure * structure)
|
|||
return structure->fields->len;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_structure_nth_field_name:
|
||||
* @structure: a #GstStructure
|
||||
*
|
||||
* Returns: the name of the given field number, counting from 0 onwards.
|
||||
*/
|
||||
const gchar *
|
||||
gst_structure_nth_field_name (const GstStructure * structure, guint index)
|
||||
{
|
||||
GstStructureField *field;
|
||||
|
||||
field = GST_STRUCTURE_FIELD (structure, index);
|
||||
return g_quark_to_string (field->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_structure_foreach:
|
||||
* @structure: a #GstStructure
|
||||
|
@ -1459,10 +1474,12 @@ gst_structure_parse_value (gchar * str,
|
|||
/**
|
||||
* gst_structure_from_string:
|
||||
* @string: a string representation of a #GstStructure.
|
||||
* @end: FIXME, deduce from code
|
||||
* @end: pointer to store the end of the string in.
|
||||
*
|
||||
* Creates a #GstStructure from a string representation.
|
||||
*
|
||||
* If end is not NULL, a pointer to the place inside the given string
|
||||
* where parsing ended will be returned.
|
||||
*
|
||||
* Returns: a new #GstStructure
|
||||
*/
|
||||
GstStructure *
|
||||
|
|
|
@ -109,6 +109,7 @@ gboolean gst_structure_map_in_place (GstStructure
|
|||
GstStructureMapFunc func,
|
||||
gpointer user_data);
|
||||
gint gst_structure_n_fields (const GstStructure *structure);
|
||||
const gchar * gst_structure_nth_field_name (const GstStructure *structure, guint index);
|
||||
gboolean gst_structure_has_field (const GstStructure *structure,
|
||||
const gchar *fieldname);
|
||||
gboolean gst_structure_has_field_typed (const GstStructure *structure,
|
||||
|
|
|
@ -1022,12 +1022,17 @@ gst_value_serialize_ ## _type (const GValue * value) \
|
|||
return (char *) g_value_get_string (&val); \
|
||||
}
|
||||
|
||||
/* deserialize the given s into to as a long long.
|
||||
* check if the result is actually storeable in the given size number of
|
||||
* bytes.
|
||||
*/
|
||||
static gboolean
|
||||
gst_value_deserialize_int_helper (long long *to, const char *s, long long min,
|
||||
long long max)
|
||||
long long max, int size)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
char *end;
|
||||
long long mask = -1;
|
||||
|
||||
*to = gst_strtoll (s, &end, 0);
|
||||
if (*end == 0) {
|
||||
|
@ -1051,8 +1056,23 @@ gst_value_deserialize_int_helper (long long *to, const char *s, long long min,
|
|||
}
|
||||
}
|
||||
if (ret) {
|
||||
if (*to < min || *to > max) {
|
||||
ret = FALSE;
|
||||
/* by definition, a long long fits into a long long; so ignore those */
|
||||
if (size != sizeof (mask)) {
|
||||
if (*to >= 0) {
|
||||
/* for positive numbers, we create a mask of 1's outside of the range
|
||||
* and 0's inside the range. An and will thus keep only 1 bits
|
||||
* outside of the range */
|
||||
mask <<= (size * 8);
|
||||
if ((mask & *to) != 0) {
|
||||
ret = FALSE;
|
||||
}
|
||||
} else {
|
||||
/* for negative numbers, we do a 2's complement version */
|
||||
mask <<= ((size * 8) - 1);
|
||||
if ((mask & *to) != mask) {
|
||||
ret = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -1067,8 +1087,8 @@ gst_value_deserialize_ ## _type (GValue * dest, const char *s) \
|
|||
long long x; \
|
||||
\
|
||||
if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
|
||||
G_MAX ## _macro)) { \
|
||||
g_value_set_ ## _type (dest, x); \
|
||||
G_MAX ## _macro, sizeof (g ## _type))) { \
|
||||
g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
|
||||
return TRUE; \
|
||||
} else { \
|
||||
return FALSE; \
|
||||
|
|
|
@ -34,6 +34,7 @@ TESTS = $(top_builddir)/tools/gst-register \
|
|||
gst/gstobject \
|
||||
gst/gstpad \
|
||||
gst/gstsystemclock \
|
||||
gst/gststructure \
|
||||
gst/gsttag \
|
||||
gst/gstvalue \
|
||||
pipelines/simple_launch_lines \
|
||||
|
|
20
tests/check/gst/capslist.h
Normal file
20
tests/check/gst/capslist.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <glib.h>
|
||||
|
||||
/* defines an array of strings named caps_list, that contains a list of caps for
|
||||
general tests. So if you don't know what caps to use to write a test, just
|
||||
include this file */
|
||||
|
||||
static const gchar *caps_list[] = {
|
||||
"audio/x-adpcm, layout=(string)quicktime; audio/x-adpcm, layout=(string)quicktime; audio/x-adpcm, layout=(string)wav; audio/x-adpcm, layout=(string)wav; audio/x-adpcm, layout=(string)dk3; audio/x-adpcm, layout=(string)dk3; audio/x-adpcm, layout=(string)dk4; audio/x-adpcm, layout=(string)dk4; audio/x-adpcm, layout=(string)westwood; audio/x-adpcm, layout=(string)westwood; audio/x-adpcm, layout=(string)smjpeg; audio/x-adpcm, layout=(string)smjpeg; audio/x-adpcm, layout=(string)microsoft; audio/x-adpcm, layout=(string)microsoft; audio/x-adpcm, layout=(string)4xm; audio/x-adpcm, layout=(string)4xm; audio/x-adpcm, layout=(string)xa; audio/x-adpcm, layout=(string)xa; audio/x-adpcm, layout=(string)adx; audio/x-adpcm, layout=(string)adx; audio/x-adpcm, layout=(string)ea; audio/x-adpcm, layout=(string)ea; audio/x-adpcm, layout=(string)g726; audio/x-adpcm, layout=(string)g726",
|
||||
"video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)I420; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)YUY2; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)24, depth=(int)24, red_mask=(int)16711680, green_mask=(int)65280, blue_mask=(int)255, endianness=(int)4321; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)24, depth=(int)24, red_mask=(int)255, green_mask=(int)65280, blue_mask=(int)16711680, endianness=(int)4321; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)Y42B; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)32, depth=(int)24, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, endianness=(int)4321; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)YUV9; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)Y41B; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)16, depth=(int)16, red_mask=(int)63488, green_mask=(int)2016, blue_mask=(int)31, endianness=(int)1234; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)16, depth=(int)15, red_mask=(int)31744, green_mask=(int)992, blue_mask=(int)31, endianness=(int)1234",
|
||||
"video/x-raw-yuv, format=(fourcc){ YUY2, I420 }, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]; video/x-jpeg, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-divx, divxversion=(int)[ 3, 5 ], width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-xvid, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-3ivx, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-msmpeg, msmpegversion=(int)[ 41, 43 ], width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/mpeg, mpegversion=(int)1, systemstream=(boolean)false, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-h263, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-dv, systemstream=(boolean)false, width=(int)720, height=(int){ 576, 480 }; video/x-huffyuv, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]",
|
||||
"video/x-raw-yuv, format=(fourcc){ YUY2, I420 }, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]; image/jpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-divx, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], divxversion=(int)[ 3, 5 ]; video/x-xvid, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-3ivx, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-msmpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], msmpegversion=(int)[ 41, 43 ]; video/mpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], mpegversion=(int)1, systemstream=(boolean)false; video/x-h263, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-dv, width=(int)720, height=(int){ 576, 480 }, systemstream=(boolean)false; video/x-huffyuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]",
|
||||
"video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]; video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)-16777216, green_mask=(int)16711680, blue_mask=(int)65280, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]",
|
||||
"video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]",
|
||||
"video/x-raw-yuv, format=(fourcc){ I420 }, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]",
|
||||
"video/x-raw-rgb, bpp = (int) 32, depth = (int) 24, endianness = (int) BIG_ENDIAN, red_mask = (int) 0x000000FF, framerate = (double) [ 0, max ]",
|
||||
"video/x-raw-rgb, bpp = (int) 32, depth = (int) 24, endianness = (int) BIG_ENDIAN, red_mask = (int) 0xFF000000, framerate = (double) [ 0, max ]",
|
||||
"ANY",
|
||||
"EMPTY"
|
||||
};
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gstcaps.c: Unit test for GstCaps
|
||||
*
|
||||
|
@ -21,7 +22,22 @@
|
|||
|
||||
|
||||
#include "../gstcheck.h"
|
||||
#include "capslist.h"
|
||||
|
||||
START_TEST (test_from_string)
|
||||
{
|
||||
GstCaps *caps;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (caps_list); i++) {
|
||||
caps = gst_caps_from_string (caps_list[i]);
|
||||
fail_if (caps == NULL,
|
||||
"Could not create caps from string %s\n", caps_list[i]);
|
||||
g_free (caps);
|
||||
}
|
||||
}
|
||||
|
||||
END_TEST;
|
||||
|
||||
START_TEST (test_buffer)
|
||||
{
|
||||
|
@ -37,7 +53,8 @@ START_TEST (test_buffer)
|
|||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
END_TEST
|
||||
END_TEST;
|
||||
|
||||
START_TEST (test_double_append)
|
||||
{
|
||||
GstStructure *s1;
|
||||
|
@ -49,7 +66,8 @@ START_TEST (test_double_append)
|
|||
ASSERT_CRITICAL (gst_caps_append_structure (c1, s1));
|
||||
}
|
||||
|
||||
END_TEST
|
||||
END_TEST;
|
||||
|
||||
START_TEST (test_mutability)
|
||||
{
|
||||
GstStructure *s1;
|
||||
|
@ -76,13 +94,17 @@ START_TEST (test_mutability)
|
|||
fail_unless (gst_structure_get_int (s1, "rate", &ret));
|
||||
fail_unless (ret == 1);
|
||||
}
|
||||
END_TEST Suite *
|
||||
|
||||
END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_caps_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstCaps");
|
||||
TCase *tc_chain = tcase_create ("mutability");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_from_string);
|
||||
tcase_add_test (tc_chain, test_double_append);
|
||||
tcase_add_test (tc_chain, test_mutability);
|
||||
tcase_add_test (tc_chain, test_buffer);
|
||||
|
|
94
tests/check/gst/gststructure.c
Normal file
94
tests/check/gst/gststructure.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gststructure.c: Unit tests for GstStructure
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "../gstcheck.h"
|
||||
|
||||
|
||||
START_TEST (test_from_string_int)
|
||||
{
|
||||
const char *strings[] = {
|
||||
"video/x-raw-rgb, width = (int) 123456",
|
||||
"video/x-raw-rgb, stride = (int) -123456",
|
||||
"video/x-raw-rgb, red_mask = (int) 0xFFFF",
|
||||
"video/x-raw-rgb, red_mask = (int) 0x0000FFFF",
|
||||
"video/x-raw-rgb, red_mask = (int) 0x7FFFFFFF",
|
||||
"video/x-raw-rgb, red_mask = (int) 0x80000000",
|
||||
"video/x-raw-rgb, red_mask = (int) 0xFF000000",
|
||||
};
|
||||
gint results[] = {
|
||||
123456,
|
||||
-123456,
|
||||
0xFFFF,
|
||||
0xFFFF,
|
||||
0x7FFFFFFF,
|
||||
0x80000000,
|
||||
0xFF000000,
|
||||
};
|
||||
GstStructure *structure;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||
const char *s;
|
||||
const gchar *name;
|
||||
gint value;
|
||||
|
||||
s = strings[i];
|
||||
|
||||
structure = gst_structure_from_string (s, NULL);
|
||||
fail_if (structure == NULL, "Could not get structure from string %s", s);
|
||||
name = gst_structure_nth_field_name (structure, 0);
|
||||
fail_unless (gst_structure_get_int (structure, name, &value));
|
||||
fail_unless (value == results[i],
|
||||
"Value %d is not the expected result %d for string %s",
|
||||
value, results[i], s);
|
||||
}
|
||||
}
|
||||
|
||||
END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_value_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("GstStructure");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_from_string_int);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = gst_value_suite ();
|
||||
SRunner *sr = srunner_create (s);
|
||||
|
||||
gst_check_init (&argc, &argv);
|
||||
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
nf = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
|
||||
return nf;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2004> David Schleef <david at schleef dot org>
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* gstvalue.c: Unit tests for GstValue
|
||||
*
|
||||
|
@ -36,13 +37,97 @@ END_TEST;
|
|||
START_TEST (test_deserialize_gint64)
|
||||
{
|
||||
GValue value = { 0 };
|
||||
const char *string = "12345678901";
|
||||
|
||||
const char *strings[] = {
|
||||
"12345678901",
|
||||
"-12345678901",
|
||||
};
|
||||
gint64 results[] = {
|
||||
12345678901LL,
|
||||
-12345678901LL,
|
||||
};
|
||||
int i;
|
||||
|
||||
g_value_init (&value, G_TYPE_INT64);
|
||||
fail_unless (gst_value_deserialize (&value, string));
|
||||
fail_unless (g_value_get_int64 (&value) == 12345678901LL,
|
||||
"resulting value is %" G_GINT64_FORMAT ", not %s", value, string);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||
fail_unless (gst_value_deserialize (&value, strings[i]),
|
||||
"could not deserialize %s (%d)", strings[i], i);
|
||||
fail_unless (g_value_get_int64 (&value) == results[i],
|
||||
"resulting value is %" G_GINT64_FORMAT ", not %" G_GINT64_FORMAT
|
||||
", for string %s (%d)", value, results[i], strings[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
END_TEST;
|
||||
|
||||
START_TEST (test_deserialize_gint)
|
||||
{
|
||||
GValue value = { 0 };
|
||||
const char *strings[] = {
|
||||
"-",
|
||||
"123456",
|
||||
"-123456",
|
||||
"0xFFFF",
|
||||
"0x0000FFFF",
|
||||
/* a positive long long, serializing to highest possible positive sint */
|
||||
"0x7FFFFFFF",
|
||||
/* a positive long long, serializing to lowest possible negative sint */
|
||||
"0x80000000",
|
||||
/* a negative long long, serializing to lowest possible negative sint */
|
||||
"0xFFFFFFFF80000000",
|
||||
"0xFF000000",
|
||||
/* a positive long long serializing to -1 */
|
||||
"0xFFFFFFFF",
|
||||
/* a negative long long serializing to -1 */
|
||||
"0xFFFFFFFFFFFFFFFF",
|
||||
"0xEFFFFFFF",
|
||||
};
|
||||
gint results[] = {
|
||||
0,
|
||||
123456,
|
||||
-123456,
|
||||
0xFFFF,
|
||||
0xFFFF,
|
||||
0x7FFFFFFF,
|
||||
0x80000000,
|
||||
0x80000000,
|
||||
0xFF000000,
|
||||
-1,
|
||||
-1,
|
||||
0xEFFFFFFF,
|
||||
};
|
||||
int i;
|
||||
|
||||
g_value_init (&value, G_TYPE_INT);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||
fail_unless (gst_value_deserialize (&value, strings[i]),
|
||||
"could not deserialize %s (%d)", strings[i], i);
|
||||
fail_unless (g_value_get_int (&value) == results[i],
|
||||
"resulting value is %d, not %d, for string %s (%d)",
|
||||
g_value_get_int (&value), results[i], strings[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
END_TEST;
|
||||
|
||||
START_TEST (test_deserialize_gint_failures)
|
||||
{
|
||||
GValue value = { 0 };
|
||||
const char *strings[] = {
|
||||
"0x0000000100000000", /* lowest long long that cannot fit in 32 bits */
|
||||
"0xF000000000000000",
|
||||
"0xFFFFFFF000000000",
|
||||
"0xFFFFFFFF00000000",
|
||||
};
|
||||
int i;
|
||||
|
||||
g_value_init (&value, G_TYPE_INT);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||
fail_if (gst_value_deserialize (&value, strings[i]),
|
||||
"deserialized %s (%d), while it should have failed", strings[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
END_TEST;
|
||||
|
@ -134,6 +219,8 @@ gst_value_suite (void)
|
|||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_deserialize_buffer);
|
||||
tcase_add_test (tc_chain, test_deserialize_gint);
|
||||
tcase_add_test (tc_chain, test_deserialize_gint_failures);
|
||||
tcase_add_test (tc_chain, test_deserialize_gint64);
|
||||
tcase_add_test (tc_chain, test_string);
|
||||
tcase_add_test (tc_chain, test_deserialize_string);
|
||||
|
|
Loading…
Reference in a new issue