|
1 /* GStreamer |
|
2 * |
|
3 * unit test for fakesrc |
|
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 #include <gst/gst_global.h> |
|
23 #include <unistd.h> |
|
24 |
|
25 #include <gst/check/gstcheck.h> |
|
26 #include <libgstreamer_wsd_macros.h> |
|
27 |
|
28 #define LOG_FILE "c:\\logs\\fakesrc_log1.txt" |
|
29 #include "std_log_result.h" |
|
30 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
31 |
|
32 void create_xml(int result) |
|
33 { |
|
34 if(result) |
|
35 assert_failed = 1; |
|
36 |
|
37 testResultXml(xmlfile); |
|
38 close_log_file(); |
|
39 } |
|
40 |
|
41 #include "libgstreamer_wsd_solution.h" |
|
42 |
|
43 #if EMULATOR |
|
44 static GET_GLOBAL_VAR_FROM_TLS(buffers,gstcheck,GList*) |
|
45 #define buffers (*GET_GSTREAMER_WSD_VAR_NAME(buffers,gstcheck,g)()) |
|
46 #else |
|
47 extern GList *buffers; |
|
48 #endif |
|
49 |
|
50 static gboolean have_eos = FALSE; |
|
51 |
|
52 static GstPad *mysinkpad; |
|
53 |
|
54 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", |
|
55 GST_PAD_SINK, |
|
56 GST_PAD_ALWAYS, |
|
57 GST_STATIC_CAPS_ANY); |
|
58 |
|
59 static gboolean |
|
60 event_func (GstPad * pad, GstEvent * event) |
|
61 { |
|
62 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) { |
|
63 have_eos = TRUE; |
|
64 gst_event_unref (event); |
|
65 return TRUE; |
|
66 } |
|
67 |
|
68 gst_event_unref (event); |
|
69 return FALSE; |
|
70 } |
|
71 |
|
72 static GstElement * |
|
73 setup_fakesrc (void) |
|
74 { |
|
75 GstElement *fakesrc; |
|
76 |
|
77 GST_DEBUG ("setup_fakesrc"); |
|
78 fakesrc = gst_check_setup_element ("fakesrc"); |
|
79 mysinkpad = gst_check_setup_sink_pad (fakesrc, &sinktemplate, NULL); |
|
80 gst_pad_set_event_function (mysinkpad, event_func); |
|
81 gst_pad_set_active (mysinkpad, TRUE); |
|
82 return fakesrc; |
|
83 } |
|
84 |
|
85 static void |
|
86 cleanup_fakesrc (GstElement * fakesrc) |
|
87 { |
|
88 gst_pad_set_active (mysinkpad, FALSE); |
|
89 gst_check_teardown_sink_pad (fakesrc); |
|
90 gst_check_teardown_element (fakesrc); |
|
91 } |
|
92 |
|
93 void test_num_buffers() |
|
94 { |
|
95 GstElement *src; |
|
96 int i; |
|
97 |
|
98 xmlfile = "fakesrc_test_num_buffers"; |
|
99 std_log(LOG_FILENAME_LINE, "Test Started test_num_buffers"); |
|
100 |
|
101 src = setup_fakesrc (); |
|
102 g_object_set (G_OBJECT (src), "num-buffers", 3, NULL); |
|
103 fail_unless (gst_element_set_state (src, |
|
104 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
105 "could not set to playing"); |
|
106 |
|
107 |
|
108 |
|
109 while (!have_eos) { |
|
110 g_usleep (1000); |
|
111 } |
|
112 |
|
113 fail_unless (g_list_length (buffers) == 3); |
|
114 |
|
115 |
|
116 |
|
117 gst_check_drop_buffers (); |
|
118 |
|
119 fail_unless (gst_element_set_state (src, |
|
120 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); |
|
121 |
|
122 /* cleanup */ |
|
123 cleanup_fakesrc (src); |
|
124 |
|
125 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
126 create_xml(0); |
|
127 } |
|
128 |
|
129 |
|
130 |
|
131 void test_sizetype_empty() |
|
132 { |
|
133 GstElement *src; |
|
134 GList *l; |
|
135 |
|
136 xmlfile = "fakesrc_test_sizetype_empty"; |
|
137 std_log(LOG_FILENAME_LINE, "Test Started test_sizetype_empty"); |
|
138 src = setup_fakesrc (); |
|
139 |
|
140 g_object_set (G_OBJECT (src), "sizetype", 1, NULL); |
|
141 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL); |
|
142 |
|
143 fail_unless (gst_element_set_state (src, |
|
144 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
145 "could not set to playing"); |
|
146 |
|
147 while (!have_eos) { |
|
148 g_usleep (1000); |
|
149 } |
|
150 |
|
151 fail_unless (g_list_length (buffers) == 100); |
|
152 |
|
153 l = buffers; |
|
154 while (l) { |
|
155 GstBuffer *buf = l->data; |
|
156 |
|
157 fail_unless (GST_BUFFER_SIZE (buf) == 0); |
|
158 |
|
159 l = l->next; |
|
160 } |
|
161 gst_check_drop_buffers (); |
|
162 |
|
163 fail_unless (gst_element_set_state (src, |
|
164 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); |
|
165 |
|
166 /* cleanup */ |
|
167 cleanup_fakesrc (src); |
|
168 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
169 create_xml(0); |
|
170 } |
|
171 |
|
172 //GST_END_TEST; |
|
173 |
|
174 void test_sizetype_fixed() |
|
175 { |
|
176 GstElement *src; |
|
177 GList *l; |
|
178 int i; |
|
179 |
|
180 xmlfile = "fakesrc_test_sizetype_fixed"; |
|
181 std_log(LOG_FILENAME_LINE, "Test Started test_sizetype_fixed"); |
|
182 src = setup_fakesrc (); |
|
183 |
|
184 g_object_set (G_OBJECT (src), "sizetype", 2, NULL); |
|
185 g_object_set (G_OBJECT (src), "sizemax", 8192, NULL); |
|
186 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL); |
|
187 |
|
188 fail_unless (gst_element_set_state (src, |
|
189 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
190 "could not set to playing"); |
|
191 |
|
192 while (!have_eos) { |
|
193 g_usleep (1000); |
|
194 } |
|
195 |
|
196 fail_unless (g_list_length (buffers) == 100); |
|
197 |
|
198 |
|
199 l = buffers; |
|
200 while (l) { |
|
201 GstBuffer *buf = l->data; |
|
202 |
|
203 fail_unless (GST_BUFFER_SIZE (buf) == 8192); |
|
204 |
|
205 l = l->next; |
|
206 } |
|
207 gst_check_drop_buffers (); |
|
208 |
|
209 fail_unless (gst_element_set_state (src, |
|
210 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); |
|
211 |
|
212 /* cleanup */ |
|
213 cleanup_fakesrc (src); |
|
214 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
215 create_xml(0); |
|
216 } |
|
217 |
|
218 |
|
219 |
|
220 void test_sizetype_random() |
|
221 { |
|
222 GstElement *src; |
|
223 GList *l; |
|
224 |
|
225 xmlfile = "fakesrc_test_sizetype_random"; |
|
226 std_log(LOG_FILENAME_LINE, "Test Started test_sizetype_random"); |
|
227 src = setup_fakesrc (); |
|
228 |
|
229 g_object_set (G_OBJECT (src), "sizetype", 3, NULL); |
|
230 g_object_set (G_OBJECT (src), "sizemin", 4096, NULL); |
|
231 g_object_set (G_OBJECT (src), "sizemax", 8192, NULL); |
|
232 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL); |
|
233 |
|
234 fail_unless (gst_element_set_state (src, |
|
235 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
236 "could not set to playing"); |
|
237 |
|
238 while (!have_eos) { |
|
239 g_usleep (1000); |
|
240 } |
|
241 |
|
242 fail_unless (g_list_length (buffers) == 100); |
|
243 |
|
244 l = buffers; |
|
245 while (l) { |
|
246 GstBuffer *buf = l->data; |
|
247 |
|
248 fail_if (GST_BUFFER_SIZE (buf) > 8192); |
|
249 fail_if (GST_BUFFER_SIZE (buf) < 4096); |
|
250 |
|
251 l = l->next; |
|
252 } |
|
253 gst_check_drop_buffers (); |
|
254 |
|
255 fail_unless (gst_element_set_state (src, |
|
256 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); |
|
257 |
|
258 /* cleanup */ |
|
259 cleanup_fakesrc (src); |
|
260 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
261 create_xml(0); |
|
262 } |
|
263 |
|
264 |
|
265 |
|
266 void test_no_preroll() |
|
267 { |
|
268 GstElement *src; |
|
269 GstStateChangeReturn ret; |
|
270 |
|
271 xmlfile = "fakesrc_test_no_preroll"; |
|
272 std_log(LOG_FILENAME_LINE, "Test Started test_no_preroll"); |
|
273 src = setup_fakesrc (); |
|
274 |
|
275 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL); |
|
276 |
|
277 ret = gst_element_set_state (src, GST_STATE_PAUSED); |
|
278 |
|
279 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, |
|
280 "error going to paused the first time"); |
|
281 |
|
282 ret = gst_element_set_state (src, GST_STATE_PAUSED); |
|
283 |
|
284 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, |
|
285 "error going to paused the second time"); |
|
286 |
|
287 fail_unless (gst_element_set_state (src, |
|
288 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); |
|
289 |
|
290 /* cleanup */ |
|
291 cleanup_fakesrc (src); |
|
292 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
293 create_xml(0); |
|
294 } |
|
295 |
|
296 //GST_END_TEST; |
|
297 |
|
298 //void |
|
299 //fakesrc_suite (void) |
|
300 //{ |
|
301 ///* Suite *s = suite_create ("fakesrc"); |
|
302 // TCase *tc_chain = tcase_create ("general"); |
|
303 // |
|
304 // suite_add_tcase (s, tc_chain); |
|
305 // tcase_add_test (tc_chain, test_num_buffers); |
|
306 // tcase_add_test (tc_chain, test_sizetype_empty); |
|
307 // tcase_add_test (tc_chain, test_sizetype_fixed); |
|
308 // tcase_add_test (tc_chain, test_sizetype_random); |
|
309 // tcase_add_test (tc_chain, test_no_preroll); |
|
310 //*/ |
|
311 // |
|
312 // test_sizetype_empty(); |
|
313 // create_xml(0); |
|
314 // return; |
|
315 //} |
|
316 |
|
317 void (*fn[5]) (void) = { |
|
318 test_num_buffers, |
|
319 test_sizetype_empty, |
|
320 test_sizetype_fixed, |
|
321 test_sizetype_random, |
|
322 test_no_preroll |
|
323 }; |
|
324 |
|
325 char *args[] = { |
|
326 "test_num_buffers", |
|
327 "test_sizetype_empty", |
|
328 "test_sizetype_fixed", |
|
329 "test_sizetype_random", |
|
330 "test_no_preroll" |
|
331 }; |
|
332 |
|
333 GST_CHECK_MAIN (fakesrc); |
|
334 |
|
335 //int main (int argc, char **argv) |
|
336 //{ |
|
337 // gst_check_init (&argc, &argv); |
|
338 // test_num_buffers (); |
|
339 // test_sizetype_empty(); |
|
340 // test_sizetype_fixed(); |
|
341 // test_sizetype_random(); |
|
342 // test_no_preroll(); |
|
343 //} |
|
344 |