1 /* GStreamer
2  *
3  * unit test for the valve element
4  *
5  * Copyright 2009 Collabora Ltd.
6  *  @author: Olivier Crete <olivier.crete@collabora.co.uk>
7  * Copyright 2009 Nokia Corp.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 
28 #include <gst/check/gstcheck.h>
29 #include <gst/check/gstharness.h>
30 #include <gst/gst.h>
31 
GST_START_TEST(test_valve_basic)32 GST_START_TEST (test_valve_basic)
33 {
34   GstHarness *h = gst_harness_new ("valve");
35 
36   gst_harness_set_src_caps_str (h, "mycaps");
37 
38   /* when not dropping, we don't drop buffers.... */
39   g_object_set (h->element, "drop", FALSE, NULL);
40   fail_unless_equals_int (GST_FLOW_OK, gst_harness_push (h, gst_buffer_new ()));
41   fail_unless_equals_int (GST_FLOW_OK, gst_harness_push (h, gst_buffer_new ()));
42   fail_unless_equals_int (2, gst_harness_buffers_received (h));
43 
44   /* when dropping, the buffers don't make it through */
45   g_object_set (h->element, "drop", TRUE, NULL);
46   fail_unless_equals_int (3, gst_harness_events_received (h));
47   fail_unless_equals_int (GST_FLOW_OK, gst_harness_push (h, gst_buffer_new ()));
48   fail_unless_equals_int (GST_FLOW_OK, gst_harness_push (h, gst_buffer_new ()));
49   fail_unless_equals_int (2, gst_harness_buffers_received (h));
50 
51   gst_harness_teardown (h);
52 }
53 
54 GST_END_TEST;
55 
GST_START_TEST(test_valve_upstream_events_dont_send_sticky)56 GST_START_TEST (test_valve_upstream_events_dont_send_sticky)
57 {
58   GstHarness *h = gst_harness_new ("valve");
59 
60   /* set to drop */
61   g_object_set (h->element, "drop", TRUE, NULL);
62 
63   /* set caps to trigger sticky-events being pushed to valve */
64   gst_harness_set_src_caps_str (h, "mycaps");
65 
66   /* verify no events have made it through yet */
67   fail_unless_equals_int (0, gst_harness_events_received (h));
68 
69   /* stop dropping */
70   g_object_set (h->element, "drop", FALSE, NULL);
71 
72   /* send an upstream event and verify that no
73      downstream events was pushed as a result of this */
74   gst_harness_push_upstream_event (h, gst_event_new_reconfigure ());
75   fail_unless_equals_int (0, gst_harness_events_received (h));
76 
77   /* push a buffer, and verify this pushes the sticky events */
78   fail_unless_equals_int (GST_FLOW_OK, gst_harness_push (h, gst_buffer_new ()));
79   fail_unless_equals_int (3, gst_harness_events_received (h));
80 
81   gst_harness_teardown (h);
82 }
83 
84 GST_END_TEST;
85 
86 static Suite *
valve_suite(void)87 valve_suite (void)
88 {
89   Suite *s = suite_create ("valve");
90   TCase *tc_chain;
91 
92   tc_chain = tcase_create ("valve_basic");
93   tcase_add_test (tc_chain, test_valve_basic);
94   tcase_add_test (tc_chain, test_valve_upstream_events_dont_send_sticky);
95 
96   suite_add_tcase (s, tc_chain);
97 
98   return s;
99 }
100 
101 GST_CHECK_MAIN (valve)
102