Tizen 2.1 base
[profile/ivi/gst-plugins-ugly0.10.git] / tests / check / pipelines / lame.c
1 /* GStreamer
2  *
3  * unit test for lame
4  *
5  * Copyright (C) 2007 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 <gst/check/gstcheck.h>
24 #include <gst/check/gstbufferstraw.h>
25
26 #ifndef GST_DISABLE_PARSE
27
28 GST_START_TEST (test_format)
29 {
30   GstElement *bin;
31   GstPad *pad;
32   gchar *pipe_str;
33   GstBuffer *buffer;
34   GError *error = NULL;
35
36   pipe_str = g_strdup_printf ("audiotestsrc num-buffers=1 "
37       "! audio/x-raw-int, rate=22050, channels=1 "
38       "! lame bitrate=24 mode=3 " "! audio/mpeg,rate=22050 ! fakesink");
39
40   bin = gst_parse_launch (pipe_str, &error);
41   fail_unless (bin != NULL, "Error parsing pipeline: %s",
42       error ? error->message : "(invalid error)");
43   g_free (pipe_str);
44
45   /* get the pad */
46   {
47     GstElement *sink = gst_bin_get_by_name (GST_BIN (bin), "fakesink0");
48
49     fail_unless (sink != NULL, "Could not get fakesink out of bin");
50     pad = gst_element_get_static_pad (sink, "sink");
51     fail_unless (pad != NULL, "Could not get pad out of fakesink");
52     gst_object_unref (sink);
53   }
54
55   gst_buffer_straw_start_pipeline (bin, pad);
56
57   buffer = gst_buffer_straw_get_buffer (bin, pad);
58
59   gst_buffer_straw_stop_pipeline (bin, pad);
60
61   gst_buffer_unref (buffer);
62   gst_object_unref (pad);
63   gst_object_unref (bin);
64 }
65
66 GST_END_TEST;
67
68 GST_START_TEST (test_caps_proxy)
69 {
70   GstElement *bin;
71   GstPad *pad;
72   gchar *pipe_str;
73   GstBuffer *buffer;
74   GError *error = NULL;
75
76   pipe_str = g_strdup_printf ("audiotestsrc num-buffers=1 "
77       "! audio/x-raw-int,rate=48000,channels=1 "
78       "! audioresample "
79       "! lamemp3enc ! audio/mpeg,rate=(int){22050,44100} ! fakesink");
80
81   bin = gst_parse_launch (pipe_str, &error);
82   fail_unless (bin != NULL, "Error parsing pipeline: %s",
83       error ? error->message : "(invalid error)");
84   g_free (pipe_str);
85
86   /* get the pad */
87   {
88     GstElement *sink = gst_bin_get_by_name (GST_BIN (bin), "fakesink0");
89
90     fail_unless (sink != NULL, "Could not get fakesink out of bin");
91     pad = gst_element_get_static_pad (sink, "sink");
92     fail_unless (pad != NULL, "Could not get pad out of fakesink");
93     gst_object_unref (sink);
94   }
95
96   gst_buffer_straw_start_pipeline (bin, pad);
97
98   buffer = gst_buffer_straw_get_buffer (bin, pad);
99
100   gst_buffer_straw_stop_pipeline (bin, pad);
101
102   gst_buffer_unref (buffer);
103   gst_object_unref (pad);
104   gst_object_unref (bin);
105 }
106
107 GST_END_TEST;
108
109 #endif /* #ifndef GST_DISABLE_PARSE */
110
111 Suite *
112 lame_suite (void)
113 {
114   Suite *s = suite_create ("lame");
115   TCase *tc_chain = tcase_create ("general");
116
117   suite_add_tcase (s, tc_chain);
118
119 #ifndef GST_DISABLE_PARSE
120   tcase_add_test (tc_chain, test_format);
121   tcase_add_test (tc_chain, test_caps_proxy);
122 #endif
123
124   return s;
125 }
126
127 int
128 main (int argc, char **argv)
129 {
130   int nf;
131
132   Suite *s = lame_suite ();
133   SRunner *sr = srunner_create (s);
134
135   gst_check_init (&argc, &argv);
136
137   srunner_run_all (sr, CK_NORMAL);
138   nf = srunner_ntests_failed (sr);
139   srunner_free (sr);
140
141   return nf;
142 }