tizen 2.0 init
[framework/multimedia/gst-plugins-base0.10.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
27 /* For ease of programming we use globals to keep refs for our floating
28  * src and sink pads we create; otherwise we always have to do get_pad,
29  * get_peer, and then remove references in every test function */
30 static GstPad *mysinkpad;
31
32
33 #define CAPS_TEMPLATE_STRING            \
34     "audio/x-raw-int, "                 \
35     "channels = (int) 1, "              \
36     "rate = (int) [ 1,  MAX ], "        \
37     "endianness = (int) BYTE_ORDER, "   \
38     "width = (int) 16, "                \
39     "depth = (int) 16, "                \
40     "signed = (bool) TRUE"
41
42 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
43     GST_PAD_SINK,
44     GST_PAD_ALWAYS,
45     GST_STATIC_CAPS (CAPS_TEMPLATE_STRING)
46     );
47
48 static GstElement *
49 setup_audiotestsrc (void)
50 {
51   GstElement *audiotestsrc;
52
53   GST_DEBUG ("setup_audiotestsrc");
54   audiotestsrc = gst_check_setup_element ("audiotestsrc");
55   mysinkpad = gst_check_setup_sink_pad (audiotestsrc, &sinktemplate, NULL);
56   gst_pad_set_active (mysinkpad, TRUE);
57
58   return audiotestsrc;
59 }
60
61 static void
62 cleanup_audiotestsrc (GstElement * audiotestsrc)
63 {
64   GST_DEBUG ("cleanup_audiotestsrc");
65
66   g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
67   g_list_free (buffers);
68   buffers = NULL;
69
70   gst_pad_set_active (mysinkpad, FALSE);
71   gst_check_teardown_sink_pad (audiotestsrc);
72   gst_check_teardown_element (audiotestsrc);
73 }
74
75 GST_START_TEST (test_all_waves)
76 {
77   GstElement *audiotestsrc;
78   GObjectClass *oclass;
79   GParamSpec *property;
80   GEnumValue *values;
81   guint j = 0;
82
83   audiotestsrc = setup_audiotestsrc ();
84   oclass = G_OBJECT_GET_CLASS (audiotestsrc);
85   property = g_object_class_find_property (oclass, "wave");
86   fail_unless (G_IS_PARAM_SPEC_ENUM (property));
87   values = G_ENUM_CLASS (g_type_class_ref (property->value_type))->values;
88
89
90   while (values[j].value_name) {
91     GST_DEBUG_OBJECT (audiotestsrc, "testing wave %s", values[j].value_name);
92     g_object_set (audiotestsrc, "wave", values[j].value, NULL);
93
94     fail_unless (gst_element_set_state (audiotestsrc,
95             GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
96         "could not set to playing");
97
98     g_mutex_lock (check_mutex);
99     while (g_list_length (buffers) < 10)
100       g_cond_wait (check_cond, check_mutex);
101     g_mutex_unlock (check_mutex);
102
103     gst_element_set_state (audiotestsrc, GST_STATE_READY);
104
105     g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
106     g_list_free (buffers);
107     buffers = NULL;
108     ++j;
109   }
110
111   /* cleanup */
112   cleanup_audiotestsrc (audiotestsrc);
113 }
114
115 GST_END_TEST;
116
117 static Suite *
118 audiotestsrc_suite (void)
119 {
120   Suite *s = suite_create ("audiotestsrc");
121   TCase *tc_chain = tcase_create ("general");
122
123   suite_add_tcase (s, tc_chain);
124   tcase_add_test (tc_chain, test_all_waves);
125
126   return s;
127 }
128
129 GST_CHECK_MAIN (audiotestsrc);