summaryrefslogtreecommitdiff
path: root/tests/check/elements/libvisual.c
blob: 40ee37c86dc86b906e1e4c6fe59e150cbd46799d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* GStreamer unit test for libvisual plugin
 *
 * Copyright (C) 2007 Tim-Philipp Müller <tim at centricular net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gst/check/gstcheck.h>

static gboolean
filter_func (GstPluginFeature * feature, gpointer user_data)
{
  return (g_str_has_prefix (GST_OBJECT_NAME (feature), "libvisual_"));
}

static void
test_shutdown_for_factory (const gchar * factory_name)
{
  GstElement *pipeline, *src, *q, *ac, *vis, *cf, *q2, *sink;
  GstCaps *caps;
  guint i;

  pipeline = gst_pipeline_new (NULL);

  src = gst_check_setup_element ("audiotestsrc");
  q = gst_check_setup_element ("queue");
  ac = gst_check_setup_element ("audioconvert");

  GST_INFO ("Using %s", factory_name);
  vis = gst_check_setup_element (factory_name);

  cf = gst_check_setup_element ("capsfilter");
  caps = gst_caps_new_simple ("video/x-raw", "width", G_TYPE_INT, 64,
      "height", G_TYPE_INT, 64, "framerate", GST_TYPE_FRACTION, 15, 1, NULL);
  g_object_set (cf, "caps", caps, NULL);
  gst_caps_unref (caps);

  q2 = gst_check_setup_element ("queue");
  gst_object_set_name (GST_OBJECT (q2), "queue2");
  sink = gst_check_setup_element ("fakesink");

  /* don't want to sync against the clock, the more throughput the better */
  g_object_set (src, "is-live", FALSE, NULL);
  g_object_set (sink, "sync", FALSE, NULL);

  gst_bin_add_many (GST_BIN (pipeline), src, q, ac, vis, cf, q2, sink, NULL);
  fail_if (!gst_element_link_many (src, q, ac, vis, cf, q2, sink, NULL));

  /* now, wait until pipeline is running and then shut it down again; repeat;
   * this makes sure we can shut down cleanly while stuff is going on in the
   * chain function */
  for (i = 0; i < 50; ++i) {
    gst_element_set_state (pipeline, GST_STATE_PAUSED);
    gst_element_get_state (pipeline, NULL, NULL, -1);
    gst_element_set_state (pipeline, GST_STATE_PLAYING);
    g_usleep (100);
    gst_element_set_state (pipeline, GST_STATE_NULL);
  }

  gst_object_unref (pipeline);
}

GST_START_TEST (test_shutdown)
{
  const gchar *factory_to_test;

  factory_to_test = g_getenv ("LIBVISUAL_UNIT_TEST_FACTORY");

  if (factory_to_test == NULL) {
    GList *list, *l;

    list = gst_registry_feature_filter (gst_registry_get (), filter_func,
        FALSE, NULL);

    if (list == NULL) {
      g_print ("No libvisual plugins installed.\n");
      return;
    }
    for (l = list; l != NULL; l = l->next) {
      test_shutdown_for_factory (GST_OBJECT_NAME (l->data));
    }
    gst_plugin_feature_list_free (list);
  } else {
    test_shutdown_for_factory (factory_to_test);
  }
}

GST_END_TEST;

static Suite *
libvisual_suite (void)
{
  Suite *s = suite_create ("libvisual");
  TCase *tc_chain = tcase_create ("general");

  suite_add_tcase (s, tc_chain);

  /* set one manually, since we're currently built as uninst program with
   * the default timeout of 3 seconds, which is way too short */
  tcase_set_timeout (tc_chain, 30);

  tcase_add_test (tc_chain, test_shutdown);

  return s;
}

GST_CHECK_MAIN (libvisual);