1 /* GStreamer
2 *
3 * unit test for switchbin element
4 * Copyright (C) 2018 Jan Schmidt <jan@centricular.com>
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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <gst/gst.h>
27 #include <gst/check/gstcheck.h>
28 #include <gst/check/gstharness.h>
29
GST_START_TEST(test_switchbin_simple)30 GST_START_TEST (test_switchbin_simple)
31 {
32 GstBus *bus;
33 GstElement *switchbin, *e0, *e1;
34 GstCaps *c0, *c1;
35 GstHarness *h;
36 guint path_index;
37
38 GstBuffer *in_buf;
39 GstBuffer *out_buf;
40
41 bus = gst_bus_new ();
42
43 switchbin = gst_element_factory_make ("switchbin", NULL);
44 fail_unless (switchbin != NULL);
45 g_object_set (switchbin, "num-paths", 2, NULL);
46 gst_element_set_bus (switchbin, bus);
47 h = gst_harness_new_with_element (switchbin, "sink", "src");
48
49 e0 = gst_element_factory_make ("identity", NULL);
50 c0 = gst_caps_from_string ("audio/x-raw,format=S16LE,rate=48000,channels=2");
51 e1 = gst_element_factory_make ("identity", NULL);
52 c1 = gst_caps_from_string ("audio/x-raw,format=S16LE,rate=44100,channels=1");
53
54 /* switchbin owns the elements after this */
55 gst_child_proxy_set (GST_CHILD_PROXY (switchbin),
56 "path0::element", e0, "path0::caps", c0,
57 "path1::element", e1, "path1::caps", c1, NULL);
58
59 /* Create a small buffer push it in, pull it out,
60 * and check the switchbin selected the right path for these caps */
61 gst_harness_set_src_caps (h, c0);
62 in_buf = gst_harness_create_buffer (h, 480);
63 gst_harness_push (h, in_buf);
64 out_buf = gst_harness_pull (h);
65 fail_unless (in_buf == out_buf);
66 gst_buffer_unref (out_buf);
67 g_object_get (switchbin, "current-path", &path_index, NULL);
68 fail_unless (path_index == 0);
69
70 /* Change caps, push more */
71 gst_harness_set_src_caps (h, c1);
72 in_buf = gst_harness_create_buffer (h, 480);
73 gst_harness_push (h, in_buf);
74 out_buf = gst_harness_pull (h);
75 fail_unless (in_buf == out_buf);
76 gst_buffer_unref (out_buf);
77 g_object_get (switchbin, "current-path", &path_index, NULL);
78 fail_unless (path_index == 1);
79
80 while (TRUE) {
81 GstMessage *msg = gst_bus_pop (bus);
82 if (!msg)
83 break;
84
85 GST_DEBUG ("got message %s",
86 gst_message_type_get_name (GST_MESSAGE_TYPE (msg)));
87 fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
88 gst_message_unref (msg);
89 }
90
91 gst_harness_teardown (h);
92 gst_bus_set_flushing (bus, TRUE);
93 gst_object_unref (bus);
94 gst_object_unref (switchbin);
95 }
96
97 GST_END_TEST;
98
99 static Suite *
switchbin_suite(void)100 switchbin_suite (void)
101 {
102 Suite *s = suite_create ("switchbin");
103 TCase *tc_basic = tcase_create ("general");
104
105 suite_add_tcase (s, tc_basic);
106 tcase_add_test (tc_basic, test_switchbin_simple);
107
108 return s;
109 }
110
111 GST_CHECK_MAIN (switchbin);
112