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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #include <gst/check/gstcheck.h>
21 
22 #include <gst/gst.h>
23 
24 static void
run_check_for_file(const gchar * file_name,gboolean push_mode)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 | GST_MESSAGE_ERROR, -1);
79   if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
80     GError *err;
81     gchar *dbg;
82 
83     gst_message_parse_error (msg, &err, &dbg);
84     gst_object_default_error (GST_MESSAGE_SRC (msg), err, dbg);
85     g_error ("%s (%s)", err->message, dbg);
86     g_error_free (err);
87     g_free (dbg);
88   }
89   gst_message_unref (msg);
90   gst_object_unref (bus);
91 
92   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
93       GST_STATE_CHANGE_SUCCESS);
94   gst_object_unref (pipeline);
95 
96   g_free (path);
97 }
98 
99 #if 0
100 GST_START_TEST (test_parse_file_pull)
101 {
102   run_check_for_file ("pinknoise-vorbis.mkv", TRUE);
103 }
104 
105 GST_END_TEST;
106 #endif
107 
GST_START_TEST(test_parse_file_push)108 GST_START_TEST (test_parse_file_push)
109 {
110   run_check_for_file ("pinknoise-vorbis.mkv", FALSE);
111 }
112 
113 GST_END_TEST;
114 
115 static Suite *
matroskaparse_suite(void)116 matroskaparse_suite (void)
117 {
118   Suite *s = suite_create ("matroskaparse");
119   TCase *tc_chain = tcase_create ("general");
120 
121   suite_add_tcase (s, tc_chain);
122 #if 0
123   tcase_add_test (tc_chain, test_parse_file_pull);
124 #endif
125   tcase_add_test (tc_chain, test_parse_file_push);
126 
127   return s;
128 }
129 
130 GST_CHECK_MAIN (matroskaparse)
131