751e79a82d2b97b4668a153cf8b69c4182b57f27
[framework/multimedia/gst-plugins-base0.10.git] / tests / check / pipelines / vorbisdec.c
1 /* GStreamer
2  *
3  * unit test for vorbisdec
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 static GMainLoop *loop;
29 static gint messages = 0;
30
31 static void
32 element_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
33 {
34   gchar *s;
35
36   s = gst_structure_to_string (gst_message_get_structure (message));
37   GST_DEBUG ("Received message: %s", s);
38   g_free (s);
39
40   messages++;
41 }
42
43 static void
44 eos_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
45 {
46   GST_DEBUG ("Received eos");
47   g_main_loop_quit (loop);
48 }
49
50 GST_START_TEST (test_timestamps)
51 {
52   GstElement *pipeline;
53   gchar *pipe_str;
54   GstBus *bus;
55   GError *error = NULL;
56
57   pipe_str = g_strdup_printf ("audiotestsrc num-buffers=100"
58       " ! audio/x-raw-int,rate=44100 ! audioconvert ! vorbisenc ! vorbisdec"
59       " ! identity check-imperfect-timestamp=TRUE ! fakesink");
60
61   pipeline = gst_parse_launch (pipe_str, &error);
62   fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
63       error ? error->message : "(invalid error)");
64   g_free (pipe_str);
65
66   bus = gst_element_get_bus (pipeline);
67   fail_if (bus == NULL);
68   gst_bus_add_signal_watch (bus);
69   g_signal_connect (bus, "message::element", (GCallback) element_message_cb,
70       NULL);
71   g_signal_connect (bus, "message::eos", (GCallback) eos_message_cb, NULL);
72
73   gst_element_set_state (pipeline, GST_STATE_PLAYING);
74
75   /* run until we receive EOS */
76   loop = g_main_loop_new (NULL, FALSE);
77
78   g_main_loop_run (loop);
79
80   gst_element_set_state (pipeline, GST_STATE_NULL);
81
82   fail_if (messages > 0, "Received imperfect timestamp messages");
83   gst_object_unref (pipeline);
84 }
85
86 GST_END_TEST;
87 #endif /* #ifndef GST_DISABLE_PARSE */
88
89 static Suite *
90 vorbisenc_suite (void)
91 {
92   Suite *s = suite_create ("vorbisenc");
93   TCase *tc_chain = tcase_create ("general");
94
95   suite_add_tcase (s, tc_chain);
96 #ifndef GST_DISABLE_PARSE
97   tcase_add_test (tc_chain, test_timestamps);
98 #endif
99
100   return s;
101 }
102
103 int
104 main (int argc, char **argv)
105 {
106   int nf;
107
108   Suite *s = vorbisenc_suite ();
109   SRunner *sr = srunner_create (s);
110
111   gst_check_init (&argc, &argv);
112
113   srunner_run_all (sr, CK_NORMAL);
114   nf = srunner_ntests_failed (sr);
115   srunner_free (sr);
116
117   return nf;
118 }