mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-05 17:09:48 +00:00
128 lines
3 KiB
C
128 lines
3 KiB
C
|
/* GStreamer
|
||
|
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||
|
*
|
||
|
* gstpad.c: Unit test for GstPad
|
||
|
*
|
||
|
* 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_link)
|
||
|
{
|
||
|
GstPad *src, *sink;
|
||
|
GstPadTemplate *srct; //, *sinkt;
|
||
|
GstCaps *srcc;
|
||
|
|
||
|
GstPadLinkReturn ret;
|
||
|
gchar *name;
|
||
|
|
||
|
src = gst_pad_new ("source", GST_PAD_SRC);
|
||
|
fail_if (src == NULL);
|
||
|
|
||
|
name = gst_pad_get_name (src);
|
||
|
fail_unless (strcmp (name, "source") == 0);
|
||
|
|
||
|
sink = gst_pad_new ("sink", GST_PAD_SINK);
|
||
|
fail_if (sink == NULL);
|
||
|
|
||
|
/* linking without templates should fail */
|
||
|
ret = gst_pad_link (src, sink);
|
||
|
fail_unless (ret == GST_PAD_LINK_NOFORMAT);
|
||
|
|
||
|
ASSERT_CRITICAL (gst_pad_get_pad_template (NULL));
|
||
|
|
||
|
srct = gst_pad_get_pad_template (src);
|
||
|
fail_unless (srct == NULL);
|
||
|
|
||
|
/* create caps */
|
||
|
srcc = gst_caps_new_any ();
|
||
|
gst_pad_set_caps (src, srcc);
|
||
|
gst_pad_set_caps (sink, srcc);
|
||
|
|
||
|
/* linking with any caps should succeed */
|
||
|
ret = gst_pad_link (src, sink);
|
||
|
fail_unless (ret == GST_PAD_LINK_OK);
|
||
|
}
|
||
|
|
||
|
END_TEST
|
||
|
/* threaded link/unlink */
|
||
|
/* use globals */
|
||
|
GstPad * src, *sink;
|
||
|
|
||
|
void
|
||
|
thread_link_unlink (gpointer data)
|
||
|
{
|
||
|
THREAD_START ();
|
||
|
|
||
|
while (THREAD_TEST_RUNNING ()) {
|
||
|
gst_pad_link (src, sink);
|
||
|
gst_pad_unlink (src, sink);
|
||
|
THREAD_SWITCH ();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
START_TEST (test_link_unlink_threaded)
|
||
|
{
|
||
|
GstCaps *caps;
|
||
|
int i;
|
||
|
|
||
|
src = gst_pad_new ("source", GST_PAD_SRC);
|
||
|
fail_if (src == NULL);
|
||
|
sink = gst_pad_new ("sink", GST_PAD_SINK);
|
||
|
fail_if (sink == NULL);
|
||
|
|
||
|
caps = gst_caps_new_any ();
|
||
|
gst_pad_set_caps (src, caps);
|
||
|
gst_pad_set_caps (sink, caps);
|
||
|
|
||
|
MAIN_START_THREADS (5, thread_link_unlink, NULL);
|
||
|
for (i = 0; i < 1000; ++i) {
|
||
|
gst_pad_is_linked (src);
|
||
|
gst_pad_is_linked (sink);
|
||
|
THREAD_SWITCH ();
|
||
|
}
|
||
|
MAIN_STOP_THREADS ();
|
||
|
}
|
||
|
END_TEST Suite *
|
||
|
gst_pad_suite (void)
|
||
|
{
|
||
|
Suite *s = suite_create ("GstPad");
|
||
|
TCase *tc_chain = tcase_create ("general");
|
||
|
|
||
|
suite_add_tcase (s, tc_chain);
|
||
|
tcase_add_test (tc_chain, test_link);
|
||
|
tcase_add_test (tc_chain, test_link_unlink_threaded);
|
||
|
return s;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
main (int argc, char **argv)
|
||
|
{
|
||
|
int nf;
|
||
|
|
||
|
Suite *s = gst_pad_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;
|
||
|
}
|