diff options
Diffstat (limited to 'tests/check/elements/capsfilter.c')
-rw-r--r-- | tests/check/elements/capsfilter.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/tests/check/elements/capsfilter.c b/tests/check/elements/capsfilter.c index 3e1d0e2..410a486 100644 --- a/tests/check/elements/capsfilter.c +++ b/tests/check/elements/capsfilter.c @@ -78,6 +78,155 @@ GST_START_TEST (test_unfixed_downstream_caps) GST_END_TEST; +GST_START_TEST (test_caps_property) +{ + GstElement *filter; + GstCaps *filter_caps, *caps; + const gchar *caps_str; + + filter = gst_check_setup_element ("capsfilter"); + + /* verify that the set caps are actually set */ + caps_str = "audio/x-raw, rate=(int)44100, channels=(int)1"; + + filter_caps = gst_caps_from_string (caps_str); + fail_unless (GST_IS_CAPS (filter_caps)); + g_object_set (filter, "caps", filter_caps, NULL); + + g_object_get (filter, "caps", &caps, NULL); + fail_unless (gst_caps_is_equal (caps, filter_caps)); + gst_caps_unref (caps); + gst_caps_unref (filter_caps); + + /* verify that new caps set replace the old ones */ + caps_str = "video/x-raw, width=(int)320, height=(int)240"; + + filter_caps = gst_caps_from_string (caps_str); + fail_unless (GST_IS_CAPS (filter_caps)); + g_object_set (filter, "caps", filter_caps, NULL); + + g_object_get (filter, "caps", &caps, NULL); + fail_unless (gst_caps_is_equal (caps, filter_caps)); + gst_caps_unref (caps); + gst_caps_unref (filter_caps); + + /* make sure that NULL caps is interpreted as ANY */ + g_object_set (filter, "caps", NULL, NULL); + + g_object_get (filter, "caps", &filter_caps, NULL); + fail_unless (gst_caps_is_any (filter_caps)); + gst_caps_unref (filter_caps); + + gst_object_unref (filter); +} + +GST_END_TEST; + +GST_START_TEST (test_caps_query) +{ + GstElement *filter; + GstCaps *filter_caps; + const gchar *caps_str; + GstQuery *query; + GstCaps *caps; + + filter = gst_check_setup_element ("capsfilter"); + + /* set some caps, do a caps query with a filter resulting in no + * intersecting caps */ + caps_str = "audio/x-raw, rate=(int)44100, channels=(int)1"; + + filter_caps = gst_caps_from_string (caps_str); + fail_unless (GST_IS_CAPS (filter_caps)); + g_object_set (filter, "caps", filter_caps, NULL); + gst_caps_unref (filter_caps); + + caps_str = "video/x-raw, width=(int)320, height=(int)240"; + filter_caps = gst_caps_from_string (caps_str); + query = gst_query_new_caps (filter_caps); + gst_caps_unref (filter_caps); + fail_unless (gst_element_query (filter, query)); + gst_query_parse_caps_result (query, &caps); + fail_unless (gst_caps_is_empty (caps)); + gst_query_unref (query); + + gst_object_unref (filter); +} + +GST_END_TEST; + +GST_START_TEST (test_accept_caps_query) +{ + GstElement *filter; + GstCaps *filter_caps; + const gchar *caps_str; + GstQuery *query; + gboolean accepted; + GstPad *sinkpad; + GstPad *srcpad; + + filter = gst_check_setup_element ("capsfilter"); + + /* set some caps on (both pads of) the capsfilter */ + caps_str = "audio/x-raw, rate=(int)44100, channels=(int)1"; + + filter_caps = gst_caps_from_string (caps_str); + fail_unless (GST_IS_CAPS (filter_caps)); + g_object_set (filter, "caps", filter_caps, NULL); + gst_caps_unref (filter_caps); + + sinkpad = gst_element_get_static_pad (filter, "sink"); + + /* check that the set caps are acceptable on the sinkpad */ + caps_str = "audio/x-raw, rate=(int)44100, channels=(int)1"; + filter_caps = gst_caps_from_string (caps_str); + query = gst_query_new_accept_caps (filter_caps); + gst_caps_unref (filter_caps); + fail_unless (gst_pad_query (sinkpad, query)); + gst_query_parse_accept_caps_result (query, &accepted); + fail_unless (accepted); + gst_query_unref (query); + + /* and that unrelated caps are not acceptable */ + caps_str = "video/x-raw, width=(int)320, height=(int)240"; + filter_caps = gst_caps_from_string (caps_str); + query = gst_query_new_accept_caps (filter_caps); + gst_caps_unref (filter_caps); + fail_unless (gst_pad_query (sinkpad, query)); + gst_query_parse_accept_caps_result (query, &accepted); + fail_unless (!accepted); + gst_query_unref (query); + + gst_object_unref (sinkpad); + + /* now do the same for the src pad (which has the same caps) */ + srcpad = gst_element_get_static_pad (filter, "src"); + + caps_str = "audio/x-raw, rate=(int)44100, channels=(int)1"; + filter_caps = gst_caps_from_string (caps_str); + query = gst_query_new_accept_caps (filter_caps); + gst_caps_unref (filter_caps); + fail_unless (gst_pad_query (srcpad, query)); + gst_query_parse_accept_caps_result (query, &accepted); + fail_unless (accepted); + gst_query_unref (query); + + caps_str = "video/x-raw, width=(int)320, height=(int)240"; + filter_caps = gst_caps_from_string (caps_str); + query = gst_query_new_accept_caps (filter_caps); + gst_caps_unref (filter_caps); + fail_unless (gst_pad_query (srcpad, query)); + gst_query_parse_accept_caps_result (query, &accepted); + fail_unless (!accepted); + gst_query_unref (query); + + gst_object_unref (srcpad); + + gst_object_unref (filter); +} + +GST_END_TEST; + static Suite * capsfilter_suite (void) { @@ -86,6 +235,9 @@ capsfilter_suite (void) suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_unfixed_downstream_caps); + tcase_add_test (tc_chain, test_caps_property); + tcase_add_test (tc_chain, test_caps_query); + tcase_add_test (tc_chain, test_accept_caps_query); return s; } |