|
1 /* GStreamer unit test for libvisual plugin |
|
2 * |
|
3 * Copyright (C) 2007 Tim-Philipp Müller <tim at centricular net> |
|
4 * |
|
5 * This library is free software; you can redistribute it and/or |
|
6 * modify it under the terms of the GNU Library General Public |
|
7 * License as published by the Free Software Foundation; either |
|
8 * version 2 of the License, or (at your option) any later version. |
|
9 * |
|
10 * This library is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 * Library General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Library General Public |
|
16 * License along with this library; if not, write to the |
|
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
18 * Boston, MA 02111-1307, USA. |
|
19 */ |
|
20 |
|
21 #include <gst/check/gstcheck.h> |
|
22 |
|
23 static gboolean |
|
24 filter_func (GstPluginFeature * feature, gpointer user_data) |
|
25 { |
|
26 return (g_str_has_prefix (GST_PLUGIN_FEATURE_NAME (feature), "libvisual_")); |
|
27 } |
|
28 |
|
29 static void |
|
30 test_shutdown_for_factory (const gchar * factory_name) |
|
31 { |
|
32 GstElement *pipeline, *src, *q, *ac, *vis, *cf, *q2, *sink; |
|
33 GstCaps *caps; |
|
34 guint i; |
|
35 |
|
36 pipeline = gst_pipeline_new (NULL); |
|
37 |
|
38 src = gst_check_setup_element ("audiotestsrc"); |
|
39 q = gst_check_setup_element ("queue"); |
|
40 ac = gst_check_setup_element ("audioconvert"); |
|
41 |
|
42 GST_INFO ("Using %s", factory_name); |
|
43 vis = gst_check_setup_element (factory_name); |
|
44 |
|
45 cf = gst_check_setup_element ("capsfilter"); |
|
46 caps = gst_caps_new_simple ("video/x-raw-rgb", "width", G_TYPE_INT, 320, |
|
47 "height", G_TYPE_INT, 240, "framerate", GST_TYPE_FRACTION, 15, 1, NULL); |
|
48 g_object_set (cf, "caps", caps, NULL); |
|
49 gst_caps_unref (caps); |
|
50 |
|
51 q2 = gst_check_setup_element ("queue"); |
|
52 gst_object_set_name (GST_OBJECT (q2), "queue2"); |
|
53 sink = gst_check_setup_element ("fakesink"); |
|
54 |
|
55 /* don't want to sync against the clock, the more throughput the better */ |
|
56 g_object_set (src, "is-live", FALSE, NULL); |
|
57 g_object_set (sink, "sync", FALSE, NULL); |
|
58 |
|
59 gst_bin_add_many (GST_BIN (pipeline), src, q, ac, vis, cf, q2, sink, NULL); |
|
60 fail_if (!gst_element_link_many (src, q, ac, vis, cf, q2, sink, NULL)); |
|
61 |
|
62 /* now, wait until pipeline is running and then shut it down again; repeat; |
|
63 * this makes sure we can shut down cleanly while stuff is going on in the |
|
64 * chain function */ |
|
65 for (i = 0; i < 50; ++i) { |
|
66 gst_element_set_state (pipeline, GST_STATE_PAUSED); |
|
67 gst_element_get_state (pipeline, NULL, NULL, -1); |
|
68 gst_element_set_state (pipeline, GST_STATE_PLAYING); |
|
69 g_usleep (100); |
|
70 gst_element_set_state (pipeline, GST_STATE_NULL); |
|
71 } |
|
72 |
|
73 gst_object_unref (pipeline); |
|
74 } |
|
75 |
|
76 GST_START_TEST (test_shutdown) |
|
77 { |
|
78 const gchar *factory_to_test; |
|
79 |
|
80 factory_to_test = g_getenv ("LIBVISUAL_UNIT_TEST_FACTORY"); |
|
81 |
|
82 if (factory_to_test == NULL) { |
|
83 GList *list, *l; |
|
84 |
|
85 list = gst_default_registry_feature_filter (filter_func, FALSE, NULL); |
|
86 if (list == NULL) { |
|
87 g_print ("No libvisual plugins installed.\n"); |
|
88 return; |
|
89 } |
|
90 for (l = list; l != NULL; l = l->next) { |
|
91 test_shutdown_for_factory (GST_PLUGIN_FEATURE_NAME (l->data)); |
|
92 } |
|
93 gst_plugin_feature_list_free (list); |
|
94 } else { |
|
95 test_shutdown_for_factory (factory_to_test); |
|
96 } |
|
97 } |
|
98 |
|
99 GST_END_TEST; |
|
100 |
|
101 static Suite * |
|
102 libvisual_suite (void) |
|
103 { |
|
104 Suite *s = suite_create ("libvisual"); |
|
105 TCase *tc_chain = tcase_create ("general"); |
|
106 |
|
107 suite_add_tcase (s, tc_chain); |
|
108 |
|
109 /* set one manually, since we're currently built as uninst program with |
|
110 * the default timeout of 3 seconds, which is way too short */ |
|
111 tcase_set_timeout (tc_chain, 30); |
|
112 |
|
113 tcase_add_test (tc_chain, test_shutdown); |
|
114 |
|
115 return s; |
|
116 } |
|
117 |
|
118 GST_CHECK_MAIN (libvisual); |