From 32538f9ed2315c2eb304212bca0809ec258efa06 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Tue, 22 Nov 2005 12:35:42 +0000 Subject: [PATCH] check/gst/capslist.h: Comment test cases Original commit message from CVS: * check/gst/capslist.h: Comment test cases * check/gst/gststructure.c: (GST_START_TEST), (gst_structure_suite): Test automatic value type detection in gst_structure_from_string. * gst/gststructure.c: (gst_structure_parse_value): Add fraction as a type we try and guess automatically in caps/structure strings. --- ChangeLog | 11 +++++++++++ check/gst/capslist.h | 3 +++ check/gst/gststructure.c | 32 ++++++++++++++++++++++++++++++++ gst/gststructure.c | 3 ++- tests/check/gst/capslist.h | 3 +++ tests/check/gst/gststructure.c | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e10c0fe..4090c29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-11-22 Jan Schmidt + + * check/gst/capslist.h: + Comment test cases + * check/gst/gststructure.c: (GST_START_TEST), + (gst_structure_suite): + Test automatic value type detection in gst_structure_from_string. + * gst/gststructure.c: (gst_structure_parse_value): + Add fraction as a type we try and guess automatically in + caps/structure strings. + 2005-11-22 Andy Wingo patch by: Torsten Schoenfeld diff --git a/check/gst/capslist.h b/check/gst/capslist.h index 6e7beda..b8458e6 100644 --- a/check/gst/capslist.h +++ b/check/gst/capslist.h @@ -15,11 +15,14 @@ static const gchar *caps_list[] = { "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 ]", "video/x-raw-rgb,\\ bpp=(int)32", + /* Test fraction type */ "test/gst-fraction, fraction = (fraction) 1/8", "test/gst-fraction, fraction = (fraction) MIN", "test/gst-fraction, fraction = (fraction) MAX", + /* Test fraction range */ "test/gst-fraction-range, fraction = (fraction) [ 1/3, 1/4 ]", "test/gst-fraction-range, fraction = (fraction) [ MIN, MAX ]", + /* Test lists of fractions and fraction ranges */ "test/gst-fraction-range, fraction = (fraction) { [ 1/3, 1/4 ], 1/8 }", "test/gst-fraction-range, fraction = (fraction) { [ 1/3, 1/4 ], [ 1/8, 2/8 ] }", "ANY", diff --git a/check/gst/gststructure.c b/check/gst/gststructure.c index dc0137b..60342be 100644 --- a/check/gst/gststructure.c +++ b/check/gst/gststructure.c @@ -72,6 +72,37 @@ GST_START_TEST (test_from_string_int) GST_END_TEST; +/* Test type conversions from string */ +GST_START_TEST (test_from_string) +{ + GstStructure *structure; + const gchar *s; + const GValue *val; + + s = "test-string,value=1"; + structure = gst_structure_from_string (s, NULL); + fail_if (structure == NULL, "Could not get structure from string %s", s); + fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL); + fail_unless (G_VALUE_HOLDS_INT (val)); + gst_structure_free (structure); + + s = "test-string,value=1.0"; + structure = gst_structure_from_string (s, NULL); + fail_if (structure == NULL, "Could not get structure from string %s", s); + fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL); + fail_unless (G_VALUE_HOLDS_DOUBLE (val)); + gst_structure_free (structure); + + s = "test-string,value=1/1"; + structure = gst_structure_from_string (s, NULL); + fail_if (structure == NULL, "Could not get structure from string %s", s); + fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL); + fail_unless (GST_VALUE_HOLDS_FRACTION (val)); + gst_structure_free (structure); +} + +GST_END_TEST; + Suite * gst_value_suite (void) { @@ -110,6 +141,7 @@ gst_structure_suite (void) suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_from_string_int); + tcase_add_test (tc_chain, test_from_string); tcase_add_test (tc_chain, test_structure_new); return s; } diff --git a/gst/gststructure.c b/gst/gststructure.c index 5141cab..f09d817 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -1633,7 +1633,8 @@ gst_structure_parse_value (gchar * str, c = *value_end; *value_end = 0; if (type == G_TYPE_INVALID) { - GType try_types[] = { G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_STRING }; + GType try_types[] = + { G_TYPE_INT, G_TYPE_DOUBLE, GST_TYPE_FRACTION, G_TYPE_STRING }; int i; for (i = 0; i < 3; i++) { diff --git a/tests/check/gst/capslist.h b/tests/check/gst/capslist.h index 6e7beda..b8458e6 100644 --- a/tests/check/gst/capslist.h +++ b/tests/check/gst/capslist.h @@ -15,11 +15,14 @@ static const gchar *caps_list[] = { "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 ]", "video/x-raw-rgb,\\ bpp=(int)32", + /* Test fraction type */ "test/gst-fraction, fraction = (fraction) 1/8", "test/gst-fraction, fraction = (fraction) MIN", "test/gst-fraction, fraction = (fraction) MAX", + /* Test fraction range */ "test/gst-fraction-range, fraction = (fraction) [ 1/3, 1/4 ]", "test/gst-fraction-range, fraction = (fraction) [ MIN, MAX ]", + /* Test lists of fractions and fraction ranges */ "test/gst-fraction-range, fraction = (fraction) { [ 1/3, 1/4 ], 1/8 }", "test/gst-fraction-range, fraction = (fraction) { [ 1/3, 1/4 ], [ 1/8, 2/8 ] }", "ANY", diff --git a/tests/check/gst/gststructure.c b/tests/check/gst/gststructure.c index dc0137b..60342be 100644 --- a/tests/check/gst/gststructure.c +++ b/tests/check/gst/gststructure.c @@ -72,6 +72,37 @@ GST_START_TEST (test_from_string_int) GST_END_TEST; +/* Test type conversions from string */ +GST_START_TEST (test_from_string) +{ + GstStructure *structure; + const gchar *s; + const GValue *val; + + s = "test-string,value=1"; + structure = gst_structure_from_string (s, NULL); + fail_if (structure == NULL, "Could not get structure from string %s", s); + fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL); + fail_unless (G_VALUE_HOLDS_INT (val)); + gst_structure_free (structure); + + s = "test-string,value=1.0"; + structure = gst_structure_from_string (s, NULL); + fail_if (structure == NULL, "Could not get structure from string %s", s); + fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL); + fail_unless (G_VALUE_HOLDS_DOUBLE (val)); + gst_structure_free (structure); + + s = "test-string,value=1/1"; + structure = gst_structure_from_string (s, NULL); + fail_if (structure == NULL, "Could not get structure from string %s", s); + fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL); + fail_unless (GST_VALUE_HOLDS_FRACTION (val)); + gst_structure_free (structure); +} + +GST_END_TEST; + Suite * gst_value_suite (void) { @@ -110,6 +141,7 @@ gst_structure_suite (void) suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_from_string_int); + tcase_add_test (tc_chain, test_from_string); tcase_add_test (tc_chain, test_structure_new); return s; } -- 2.7.4