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., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <gst/check/gstcheck.h>
25 
26 static gboolean
filter_func(GstPluginFeature * feature,gpointer user_data)27 filter_func (GstPluginFeature * feature, gpointer user_data)
28 {
29   return (g_str_has_prefix (GST_OBJECT_NAME (feature), "libvisual_"));
30 }
31 
32 static void
test_shutdown_for_factory(const gchar * factory_name)33 test_shutdown_for_factory (const gchar * factory_name)
34 {
35   GstElement *pipeline, *src, *q, *ac, *vis, *cf, *q2, *sink;
36   GstCaps *caps;
37   guint i;
38 
39   pipeline = gst_pipeline_new (NULL);
40 
41   src = gst_check_setup_element ("audiotestsrc");
42   q = gst_check_setup_element ("queue");
43   ac = gst_check_setup_element ("audioconvert");
44 
45   GST_INFO ("Using %s", factory_name);
46   vis = gst_check_setup_element (factory_name);
47 
48   cf = gst_check_setup_element ("capsfilter");
49   caps = gst_caps_new_simple ("video/x-raw", "width", G_TYPE_INT, 64,
50       "height", G_TYPE_INT, 64, "framerate", GST_TYPE_FRACTION, 15, 1, NULL);
51   g_object_set (cf, "caps", caps, NULL);
52   gst_caps_unref (caps);
53 
54   q2 = gst_check_setup_element ("queue");
55   gst_object_set_name (GST_OBJECT (q2), "queue2");
56   sink = gst_check_setup_element ("fakesink");
57 
58   /* don't want to sync against the clock, the more throughput the better */
59   g_object_set (src, "is-live", FALSE, NULL);
60   g_object_set (sink, "sync", FALSE, NULL);
61 
62   gst_bin_add_many (GST_BIN (pipeline), src, q, ac, vis, cf, q2, sink, NULL);
63   fail_if (!gst_element_link_many (src, q, ac, vis, cf, q2, sink, NULL));
64 
65   /* now, wait until pipeline is running and then shut it down again; repeat;
66    * this makes sure we can shut down cleanly while stuff is going on in the
67    * chain function */
68   for (i = 0; i < 50; ++i) {
69     gst_element_set_state (pipeline, GST_STATE_PAUSED);
70     gst_element_get_state (pipeline, NULL, NULL, -1);
71     gst_element_set_state (pipeline, GST_STATE_PLAYING);
72     g_usleep (100);
73     gst_element_set_state (pipeline, GST_STATE_NULL);
74   }
75 
76   gst_object_unref (pipeline);
77 }
78 
GST_START_TEST(test_shutdown)79 GST_START_TEST (test_shutdown)
80 {
81   const gchar *factory_to_test;
82 
83   factory_to_test = g_getenv ("LIBVISUAL_UNIT_TEST_FACTORY");
84 
85   if (factory_to_test == NULL) {
86     GList *list, *l;
87 
88     list = gst_registry_feature_filter (gst_registry_get (), filter_func,
89         FALSE, NULL);
90 
91     if (list == NULL) {
92       g_print ("No libvisual plugins installed.\n");
93       return;
94     }
95     for (l = list; l != NULL; l = l->next) {
96       test_shutdown_for_factory (GST_OBJECT_NAME (l->data));
97     }
98     gst_plugin_feature_list_free (list);
99   } else {
100     test_shutdown_for_factory (factory_to_test);
101   }
102 }
103 
104 GST_END_TEST;
105 
106 static Suite *
libvisual_suite(void)107 libvisual_suite (void)
108 {
109   Suite *s = suite_create ("libvisual");
110   TCase *tc_chain = tcase_create ("general");
111 
112   suite_add_tcase (s, tc_chain);
113 
114   /* set one manually, since we're currently built as uninst program with
115    * the default timeout of 3 seconds, which is way too short */
116   tcase_set_timeout (tc_chain, 30);
117 
118   tcase_add_test (tc_chain, test_shutdown);
119 
120   return s;
121 }
122 
123 GST_CHECK_MAIN (libvisual);
124