tests: videorate: remove obsolete color-matrix caps field
[platform/upstream/gstreamer.git] / tests / check / elements / audiotestsrc.c
1 /* GStreamer
2  *
3  * unit test for audiotestsrc
4  *
5  * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <unistd.h>
24
25 #include <gst/check/gstcheck.h>
26 #include <gst/audio/audio.h>
27
28 /* For ease of programming we use globals to keep refs for our floating
29  * src and sink pads we create; otherwise we always have to do get_pad,
30  * get_peer, and then remove references in every test function */
31 static GstPad *mysinkpad;
32
33
34 #define CAPS_TEMPLATE_STRING            \
35     "audio/x-raw, "                     \
36     "format = (string) "GST_AUDIO_NE(S16)", "   \
37     "channels = (int) 1, "              \
38     "rate = (int) [ 1,  MAX ]"
39
40 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
41     GST_PAD_SINK,
42     GST_PAD_ALWAYS,
43     GST_STATIC_CAPS (CAPS_TEMPLATE_STRING)
44     );
45
46 static GstElement *
47 setup_audiotestsrc (void)
48 {
49   GstElement *audiotestsrc;
50
51   GST_DEBUG ("setup_audiotestsrc");
52   audiotestsrc = gst_check_setup_element ("audiotestsrc");
53   mysinkpad = gst_check_setup_sink_pad (audiotestsrc, &sinktemplate);
54   gst_pad_set_active (mysinkpad, TRUE);
55
56   return audiotestsrc;
57 }
58
59 static void
60 cleanup_audiotestsrc (GstElement * audiotestsrc)
61 {
62   GST_DEBUG ("cleanup_audiotestsrc");
63
64   g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
65   g_list_free (buffers);
66   buffers = NULL;
67
68   gst_pad_set_active (mysinkpad, FALSE);
69   gst_check_teardown_sink_pad (audiotestsrc);
70   gst_check_teardown_element (audiotestsrc);
71 }
72
73 GST_START_TEST (test_all_waves)
74 {
75   GstElement *audiotestsrc;
76   GObjectClass *oclass;
77   GParamSpec *property;
78   GEnumValue *values;
79   guint j = 0;
80
81   audiotestsrc = setup_audiotestsrc ();
82   oclass = G_OBJECT_GET_CLASS (audiotestsrc);
83   property = g_object_class_find_property (oclass, "wave");
84   fail_unless (G_IS_PARAM_SPEC_ENUM (property));
85   values = G_ENUM_CLASS (g_type_class_ref (property->value_type))->values;
86
87
88   while (values[j].value_name) {
89     GST_DEBUG_OBJECT (audiotestsrc, "testing wave %s", values[j].value_name);
90     g_object_set (audiotestsrc, "wave", values[j].value, NULL);
91
92     fail_unless (gst_element_set_state (audiotestsrc,
93             GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
94         "could not set to playing");
95
96     g_mutex_lock (check_mutex);
97     while (g_list_length (buffers) < 10)
98       g_cond_wait (check_cond, check_mutex);
99     g_mutex_unlock (check_mutex);
100
101     gst_element_set_state (audiotestsrc, GST_STATE_READY);
102
103     g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
104     g_list_free (buffers);
105     buffers = NULL;
106     ++j;
107   }
108
109   /* cleanup */
110   cleanup_audiotestsrc (audiotestsrc);
111 }
112
113 GST_END_TEST;
114
115 static Suite *
116 audiotestsrc_suite (void)
117 {
118   Suite *s = suite_create ("audiotestsrc");
119   TCase *tc_chain = tcase_create ("general");
120
121   suite_add_tcase (s, tc_chain);
122   tcase_add_test (tc_chain, test_all_waves);
123
124   return s;
125 }
126
127 GST_CHECK_MAIN (audiotestsrc);