tizen 2.0 init
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / elements / matroskaparse.c
1 /* GStreamer unit tests for matroskaparse
2  * Copyright (C) 2011 Tim-Philipp Müller  <tim centricular net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gst/check/gstcheck.h>
21
22 #include <gst/gst.h>
23
24 static void
25 run_check_for_file (const gchar * file_name, gboolean push_mode)
26 {
27   GstStateChangeReturn state_ret;
28   GstMessage *msg;
29   GstElement *src, *sep, *sink, *matroskaparse, *pipeline;
30   GstBus *bus;
31   gchar *path;
32
33   pipeline = gst_pipeline_new ("pipeline");
34   fail_unless (pipeline != NULL, "Failed to create pipeline!");
35
36   bus = gst_element_get_bus (pipeline);
37
38   src = gst_element_factory_make ("filesrc", "filesrc");
39   fail_unless (src != NULL, "Failed to create 'filesrc' element!");
40
41   if (push_mode) {
42     sep = gst_element_factory_make ("queue", "queue");
43     fail_unless (sep != NULL, "Failed to create 'queue' element");
44   } else {
45     sep = gst_element_factory_make ("identity", "identity");
46     fail_unless (sep != NULL, "Failed to create 'identity' element");
47   }
48
49   matroskaparse = gst_element_factory_make ("matroskaparse", "matroskaparse");
50   fail_unless (matroskaparse != NULL, "Failed to create matroskaparse element");
51
52   sink = gst_element_factory_make ("fakesink", "fakesink");
53   fail_unless (sink != NULL, "Failed to create 'fakesink' element!");
54
55   gst_bin_add_many (GST_BIN (pipeline), src, sep, matroskaparse, sink, NULL);
56
57   fail_unless (gst_element_link (src, sep));
58   fail_unless (gst_element_link (sep, matroskaparse));
59   fail_unless (gst_element_link (matroskaparse, sink));
60
61   path = g_build_filename (GST_TEST_FILES_PATH, file_name, NULL);
62   GST_LOG ("reading file '%s'", path);
63   g_object_set (src, "location", path, NULL);
64
65   state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
66   fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
67
68   if (state_ret == GST_STATE_CHANGE_ASYNC) {
69     GST_LOG ("waiting for pipeline to reach PAUSED state");
70     state_ret = gst_element_get_state (pipeline, NULL, NULL, -1);
71     fail_unless_equals_int (state_ret, GST_STATE_CHANGE_SUCCESS);
72   }
73
74   GST_LOG ("PAUSED, let's play a little..");
75   state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
76   fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
77
78   msg = gst_bus_poll (bus, GST_MESSAGE_EOS, -1);
79   fail_unless (msg != NULL, "Expected EOS message on bus! (%s)", file_name);
80
81   gst_message_unref (msg);
82   gst_object_unref (bus);
83
84   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
85       GST_STATE_CHANGE_SUCCESS);
86   gst_object_unref (pipeline);
87
88   g_free (path);
89 }
90
91 GST_START_TEST (test_parse_file_pull)
92 {
93   run_check_for_file ("pinknoise-vorbis.mkv", TRUE);
94 }
95
96 GST_END_TEST;
97
98 GST_START_TEST (test_parse_file_push)
99 {
100   run_check_for_file ("pinknoise-vorbis.mkv", FALSE);
101 }
102
103 GST_END_TEST;
104
105 static Suite *
106 matroskaparse_suite (void)
107 {
108   Suite *s = suite_create ("matroskaparse");
109   TCase *tc_chain = tcase_create ("general");
110
111   suite_add_tcase (s, tc_chain);
112   tcase_add_test (tc_chain, test_parse_file_pull);
113   tcase_add_test (tc_chain, test_parse_file_push);
114
115   return s;
116 }
117
118 GST_CHECK_MAIN (matroskaparse)