summaryrefslogtreecommitdiff
path: root/tests/check/elements/autodetect.c
blob: 0eb798b1e4347eebb4f97b00bc8a1a69cbe50c16 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* GStreamer unit test for the autodetect elements
 *
 * Copyright (C) <2006> Tim-Philipp Müller <tim 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <gst/check/gstcheck.h>

GST_START_TEST (test_autovideosink_ghostpad_error_case)
{
  GstStateChangeReturn state_ret;
  GstElement *pipeline, *src, *filter, *sink;
  GstCaps *caps;

  /* check that there's a usable video sink (think of build bot case) */
  sink = gst_element_factory_make ("autovideosink", NULL);
  state_ret = gst_element_set_state (sink, GST_STATE_READY);

  /* need to set state back to NULL, or our test won't work since we
   * already have detected the real caps in ready and then linking fails */
  gst_element_set_state (sink, GST_STATE_NULL);

  if (state_ret != GST_STATE_CHANGE_SUCCESS) {
    GST_WARNING ("No usable video sink, skipping test");
    gst_object_unref (sink);
    return;
  }

  pipeline = gst_pipeline_new ("pipeline");
  src = gst_element_factory_make ("fakesrc", NULL);
  filter = gst_element_factory_make ("capsfilter", NULL);

  caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC,
      GST_MAKE_FOURCC ('A', 'C', 'D', 'C'), NULL);

  g_object_set (filter, "caps", caps, NULL);
  gst_caps_unref (caps);

  gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL);

  fail_unless (gst_element_link (src, filter), "Failed to link src to filter");
  fail_unless (gst_element_link (filter, sink),
      "Failed to link filter to sink");

  /* this should fail, there's no such format */
  state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
  fail_unless (state_ret == GST_STATE_CHANGE_FAILURE,
      "pipeline _set_state() to PAUSED succeeded but should have failed");

  /* so, we hit an error and try to shut down the pipeline; this shouldn't
   * deadlock or block anywhere when autovideosink resets the ghostpad
   * targets etc. */
  state_ret = gst_element_set_state (pipeline, GST_STATE_NULL);
  fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS,
      "State change on pipeline failed");

  /* clean up */
  gst_object_unref (pipeline);
}

GST_END_TEST;

/* disable this for now, too many valgrind suppressions needed for libasound */
#if 0
GST_START_TEST (test_autoaudiosink_ghostpad_error_case)
{
  GstStateChangeReturn state_ret;
  GstElement *pipeline, *src, *filter, *sink;
  GstCaps *caps;

  /* check that there's a usable audio sink (think of build bot case) */
  sink = gst_element_factory_make ("autoaudiosink", NULL);
  state_ret = gst_element_set_state (sink, GST_STATE_READY);

  /* need to set state back to NULL, or our test won't work since we
   * already have detected the real caps in ready and then linking fails */
  gst_element_set_state (sink, GST_STATE_NULL);

  if (state_ret != GST_STATE_CHANGE_SUCCESS) {
    GST_WARNING ("No usable audio sink, skipping test");
    gst_object_unref (sink);
    return;
  }

  pipeline = gst_pipeline_new ("pipeline");
  src = gst_element_factory_make ("fakesrc", NULL);
  filter = gst_element_factory_make ("capsfilter", NULL);

  caps = gst_caps_new_simple ("audio/x-raw-int", "width", G_TYPE_INT, 42, NULL);

  g_object_set (filter, "caps", caps, NULL);
  gst_caps_unref (caps);

  gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL);

  fail_unless (gst_element_link (src, filter));
  fail_unless (gst_element_link (filter, sink));

  /* this should fail, there's no such width (hopefully) */
  state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
  fail_unless (state_ret == GST_STATE_CHANGE_FAILURE,
      "pipeline _set_state() to PAUSED succeeded but should have failed");

  /* so, we hit an error and try to shut down the pipeline; this shouldn't
   * deadlock or block anywhere when autoaudiosink resets the ghostpad
   * targets etc. */
  state_ret = gst_element_set_state (pipeline, GST_STATE_NULL);
  fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS);

  /* clean up */
  gst_object_unref (pipeline);
}

GST_END_TEST;
#endif

static Suite *
autodetect_suite (void)
{
  guint maj, min, mic, nano;

  Suite *s = suite_create ("autodetect");
  TCase *tc_chain = tcase_create ("general");

  suite_add_tcase (s, tc_chain);

  gst_version (&maj, &min, &mic, &nano);

  /* requires fixes from 0.10.10.1, but don't want to add a hard dependency
   * in configure.ac just for this yet */
  if (maj > 0 || min > 10 || mic > 10 || (mic == 10 && nano > 0)) {
    tcase_add_test (tc_chain, test_autovideosink_ghostpad_error_case);
    /* tcase_add_test (tc_chain, test_autoaudiosink_ghostpad_error_case); */
  }

  return s;
}

GST_CHECK_MAIN (autodetect);