check/: Added checks.
[platform/upstream/gstreamer.git] / tests / check / gst / gstpad.c
1 /* GStreamer
2  * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
3  *
4  * gstpad.c: Unit test for GstPad
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 #include "../gstcheck.h"
23
24 START_TEST (test_link)
25 {
26   GstPad *src, *sink;
27   GstPadTemplate *srct;         //, *sinkt;
28   GstCaps *srcc;
29
30   GstPadLinkReturn ret;
31   gchar *name;
32
33   src = gst_pad_new ("source", GST_PAD_SRC);
34   fail_if (src == NULL);
35
36   name = gst_pad_get_name (src);
37   fail_unless (strcmp (name, "source") == 0);
38
39   sink = gst_pad_new ("sink", GST_PAD_SINK);
40   fail_if (sink == NULL);
41
42   /* linking without templates should fail */
43   ret = gst_pad_link (src, sink);
44   fail_unless (ret == GST_PAD_LINK_NOFORMAT);
45
46   ASSERT_CRITICAL (gst_pad_get_pad_template (NULL));
47
48   srct = gst_pad_get_pad_template (src);
49   fail_unless (srct == NULL);
50
51   /* create caps */
52   srcc = gst_caps_new_any ();
53   gst_pad_set_caps (src, srcc);
54   gst_pad_set_caps (sink, srcc);
55
56   /* linking with any caps should succeed */
57   ret = gst_pad_link (src, sink);
58   fail_unless (ret == GST_PAD_LINK_OK);
59 }
60
61 END_TEST
62 /* threaded link/unlink */
63 /* use globals */
64     GstPad * src, *sink;
65
66 void
67 thread_link_unlink (gpointer data)
68 {
69   THREAD_START ();
70
71   while (THREAD_TEST_RUNNING ()) {
72     gst_pad_link (src, sink);
73     gst_pad_unlink (src, sink);
74     THREAD_SWITCH ();
75   }
76 }
77
78 START_TEST (test_link_unlink_threaded)
79 {
80   GstCaps *caps;
81   int i;
82
83   src = gst_pad_new ("source", GST_PAD_SRC);
84   fail_if (src == NULL);
85   sink = gst_pad_new ("sink", GST_PAD_SINK);
86   fail_if (sink == NULL);
87
88   caps = gst_caps_new_any ();
89   gst_pad_set_caps (src, caps);
90   gst_pad_set_caps (sink, caps);
91
92   MAIN_START_THREADS (5, thread_link_unlink, NULL);
93   for (i = 0; i < 1000; ++i) {
94     gst_pad_is_linked (src);
95     gst_pad_is_linked (sink);
96     THREAD_SWITCH ();
97   }
98   MAIN_STOP_THREADS ();
99 }
100 END_TEST Suite *
101 gst_pad_suite (void)
102 {
103   Suite *s = suite_create ("GstPad");
104   TCase *tc_chain = tcase_create ("general");
105
106   suite_add_tcase (s, tc_chain);
107   tcase_add_test (tc_chain, test_link);
108   tcase_add_test (tc_chain, test_link_unlink_threaded);
109   return s;
110 }
111
112 int
113 main (int argc, char **argv)
114 {
115   int nf;
116
117   Suite *s = gst_pad_suite ();
118   SRunner *sr = srunner_create (s);
119
120   gst_check_init (&argc, &argv);
121
122   srunner_run_all (sr, CK_NORMAL);
123   nf = srunner_ntests_failed (sr);
124   srunner_free (sr);
125
126   return nf;
127 }