|
1 /* GStreamer unit tests for subparse |
|
2 * |
|
3 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> |
|
4 * |
|
5 * This library is free software; you can redistribute it and/or |
|
6 * modify it under the terms of the GNU Library General Public |
|
7 * License as published by the Free Software Foundation; either |
|
8 * version 2 of the License, or (at your option) any later version. |
|
9 * |
|
10 * This library is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 * Library General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Library General Public |
|
16 * License along with this library; if not, write to the |
|
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
18 * Boston, MA 02111-1307, USA. |
|
19 */ |
|
20 |
|
21 #ifdef HAVE_CONFIG_H |
|
22 # include <config.h> |
|
23 #endif |
|
24 |
|
25 |
|
26 #include <gst/gst_global.h> |
|
27 #include <gst/check/gstcheck.h> |
|
28 |
|
29 #include <string.h> |
|
30 |
|
31 #ifndef EMULATOR |
|
32 #define assert_failed *(get_assert_failed()) |
|
33 #define fp_std_log *(get_fp_std_log()) |
|
34 #define xmlfile *(get_xmlfile()) |
|
35 #endif |
|
36 |
|
37 #define LOG_FILE "c:\\logs\\subparse_log1.txt" |
|
38 #include "std_log_result.h" |
|
39 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
40 |
|
41 #include "libgstreamer_wsd_solution.h" |
|
42 |
|
43 #if EMULATOR |
|
44 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 void create_xml(int result) |
|
51 { |
|
52 if(result) |
|
53 assert_failed = 1; |
|
54 |
|
55 testResultXml(xmlfile); |
|
56 close_log_file(); |
|
57 } |
|
58 |
|
59 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", |
|
60 GST_PAD_SINK, |
|
61 GST_PAD_ALWAYS, |
|
62 GST_STATIC_CAPS ("text/plain; text/x-pango-markup") |
|
63 ); |
|
64 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", |
|
65 GST_PAD_SRC, |
|
66 GST_PAD_ALWAYS, |
|
67 GST_STATIC_CAPS ("ANY") |
|
68 ); |
|
69 |
|
70 static GstElement *subparse; |
|
71 static GstPad *mysrcpad, *mysinkpad; |
|
72 |
|
73 static GstBuffer * |
|
74 buffer_from_static_string (const gchar * s) |
|
75 { |
|
76 GstBuffer *buf; |
|
77 |
|
78 buf = gst_buffer_new (); |
|
79 GST_BUFFER_DATA (buf) = (guint8 *) s; |
|
80 GST_BUFFER_SIZE (buf) = strlen (s); |
|
81 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY); |
|
82 |
|
83 return buf; |
|
84 } |
|
85 |
|
86 typedef struct |
|
87 { |
|
88 const gchar *in; |
|
89 GstClockTime from_ts; |
|
90 GstClockTime to_ts; |
|
91 const gchar *out; |
|
92 } SubParseInputChunk; |
|
93 |
|
94 static SubParseInputChunk srt_input[] = { |
|
95 { |
|
96 "1\n00:00:01,000 --> 00:00:02,000\nOne\n\n", |
|
97 1 * GST_SECOND, 2 * GST_SECOND, "One"}, { |
|
98 "2\n00:00:02,000 --> 00:00:03,000\nTwo\n\n", |
|
99 2 * GST_SECOND, 3 * GST_SECOND, "Two"}, { |
|
100 "3\n00:00:03,000 --> 00:00:04,000\nThree\n\n", |
|
101 3 * GST_SECOND, 4 * GST_SECOND, "Three"}, { |
|
102 "4\n00:00:04,000 --> 00:00:05,000\nFour\n\n", |
|
103 4 * GST_SECOND, 5 * GST_SECOND, "Four"}, { |
|
104 "5\n00:00:05,000 --> 00:00:06,000\nFive\n\n", |
|
105 5 * GST_SECOND, 6 * GST_SECOND, "Five"}, { |
|
106 /* markup should be preserved */ |
|
107 "6\n00:00:06,000 --> 00:00:07,000\n<i>Six</i>\n\n", |
|
108 6 * GST_SECOND, 7 * GST_SECOND, "<i>Six</i>"}, { |
|
109 /* open markup tags should be closed */ |
|
110 "7\n00:00:07,000 --> 00:00:08,000\n<i>Seven\n\n", |
|
111 7 * GST_SECOND, 8 * GST_SECOND, "<i>Seven</i>"}, { |
|
112 /* open markup tags should be closed (II) */ |
|
113 "8\n00:00:08,000 --> 00:00:09,000\n<b><i>Eight\n\n", |
|
114 8 * GST_SECOND, 9 * GST_SECOND, "<b><i>Eight</i></b>"}, { |
|
115 /* broken markup should be fixed */ |
|
116 "9\n00:00:09,000 --> 00:00:10,000\n</b>\n\n", |
|
117 9 * GST_SECOND, 10 * GST_SECOND, ""}, { |
|
118 "10\n00:00:10,000 --> 00:00:11,000\n</b></i>\n\n", |
|
119 10 * GST_SECOND, 11 * GST_SECOND, ""}, { |
|
120 "11\n00:00:11,000 --> 00:00:12,000\n<i>xyz</b></i>\n\n", |
|
121 11 * GST_SECOND, 12 * GST_SECOND, "<i>xyz</i>"}, { |
|
122 "12\n00:00:12,000 --> 00:00:13,000\n<i>xyz</b>\n\n", |
|
123 12 * GST_SECOND, 13 * GST_SECOND, "<i>xyz</i>"}, { |
|
124 /* skip a few chunk numbers here, the numbers shouldn't matter */ |
|
125 "24\n00:01:00,000 --> 00:02:00,000\nYep, still here\n\n", |
|
126 60 * GST_SECOND, 120 * GST_SECOND, "Yep, still here"}, { |
|
127 /* make sure stuff is escaped properly, but allowed markup stays intact */ |
|
128 "25\n00:03:00,000 --> 00:04:00,000\ngave <i>Rock & Roll</i> to\n\n", |
|
129 180 * GST_SECOND, 240 * GST_SECOND, "gave <i>Rock & Roll</i> to"}, { |
|
130 "26\n00:04:00,000 --> 00:05:00,000\n<i>Rock & Roll</i>\n\n", |
|
131 240 * GST_SECOND, 300 * GST_SECOND, "<i>Rock & Roll</i>"}, { |
|
132 "27\n00:06:00,000 --> 00:08:00,000\nRock & Roll\n\n", |
|
133 360 * GST_SECOND, 480 * GST_SECOND, "Rock & Roll"}, { |
|
134 "28\n00:10:00,000 --> 00:11:00,000\n" |
|
135 "<font \"#0000FF\"><joj>This is </xxx>in blue but <5</font>\n\n", |
|
136 600 * GST_SECOND, 660 * GST_SECOND, "This is in blue but <5"} |
|
137 }; |
|
138 |
|
139 /* starts with chunk number 0 (not exactly according to spec) */ |
|
140 static SubParseInputChunk srt_input0[] = { |
|
141 { |
|
142 "0\n00:00:01,000 --> 00:00:02,000\nOne\n\n", |
|
143 1 * GST_SECOND, 2 * GST_SECOND, "One"}, { |
|
144 "1\n00:00:02,000 --> 00:00:03,000\nTwo\n\n", |
|
145 2 * GST_SECOND, 3 * GST_SECOND, "Two"}, { |
|
146 "2\n00:00:03,000 --> 00:00:04,000\nThree\n\n", |
|
147 3 * GST_SECOND, 4 * GST_SECOND, "Three"} |
|
148 }; |
|
149 |
|
150 static void |
|
151 setup_subparse (void) |
|
152 { |
|
153 subparse = gst_check_setup_element ("subparse"); |
|
154 |
|
155 mysrcpad = gst_check_setup_src_pad (subparse, &srctemplate, NULL); |
|
156 mysinkpad = gst_check_setup_sink_pad (subparse, &sinktemplate, NULL); |
|
157 |
|
158 gst_pad_set_active (mysrcpad, TRUE); |
|
159 gst_pad_set_active (mysinkpad, TRUE); |
|
160 |
|
161 fail_unless_equals_int (gst_element_set_state (subparse, GST_STATE_PLAYING), |
|
162 GST_STATE_CHANGE_SUCCESS); |
|
163 } |
|
164 |
|
165 static void |
|
166 teardown_subparse (void) |
|
167 { |
|
168 GST_DEBUG ("cleaning up"); |
|
169 |
|
170 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); |
|
171 g_list_free (buffers); |
|
172 buffers = NULL; |
|
173 |
|
174 gst_pad_set_active (mysrcpad, FALSE); |
|
175 gst_pad_set_active (mysinkpad, FALSE); |
|
176 gst_check_teardown_sink_pad (subparse); |
|
177 gst_check_teardown_src_pad (subparse); |
|
178 gst_check_teardown_element (subparse); |
|
179 subparse = NULL; |
|
180 mysrcpad = NULL; |
|
181 mysinkpad = NULL; |
|
182 } |
|
183 |
|
184 static void |
|
185 test_srt_do_test (SubParseInputChunk * input, guint start_idx, guint num) |
|
186 { |
|
187 guint n; |
|
188 |
|
189 GST_LOG ("srt test: start_idx = %u, num = %u", start_idx, num); |
|
190 |
|
191 setup_subparse (); |
|
192 |
|
193 for (n = start_idx; n < start_idx + num; ++n) { |
|
194 GstBuffer *buf; |
|
195 |
|
196 buf = buffer_from_static_string (input[n].in); |
|
197 fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); |
|
198 } |
|
199 |
|
200 gst_pad_push_event (mysrcpad, gst_event_new_eos ()); |
|
201 |
|
202 fail_unless_equals_int (g_list_length (buffers), num); |
|
203 |
|
204 for (n = start_idx; n < start_idx + num; ++n) { |
|
205 const GstStructure *buffer_caps_struct; |
|
206 GstBuffer *buf; |
|
207 gchar *out; |
|
208 guint out_size; |
|
209 |
|
210 buf = g_list_nth_data (buffers, n - start_idx); |
|
211 fail_unless (buf != NULL); |
|
212 fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf), NULL); |
|
213 fail_unless (GST_BUFFER_DURATION_IS_VALID (buf), NULL); |
|
214 fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts); |
|
215 fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf), |
|
216 input[n].to_ts - input[n].from_ts); |
|
217 out = (gchar *) GST_BUFFER_DATA (buf); |
|
218 out_size = GST_BUFFER_SIZE (buf); |
|
219 /* shouldn't have trailing newline characters */ |
|
220 fail_if (out_size > 0 && out[out_size - 1] == '\n'); |
|
221 /* shouldn't include NUL-terminator in data size */ |
|
222 fail_if (out_size > 0 && out[out_size - 1] == '\0'); |
|
223 /* but should still have a NUL-terminator behind the declared data */ |
|
224 fail_unless_equals_int (out[out_size], '\0'); |
|
225 /* make sure out string matches expected string */ |
|
226 fail_unless_equals_string (out, input[n].out); |
|
227 /* check caps */ |
|
228 fail_unless (GST_BUFFER_CAPS (buf) != NULL); |
|
229 buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); |
|
230 fail_unless_equals_string (gst_structure_get_name (buffer_caps_struct), |
|
231 "text/x-pango-markup"); |
|
232 } |
|
233 |
|
234 teardown_subparse (); |
|
235 } |
|
236 |
|
237 void test_srt() |
|
238 { |
|
239 |
|
240 test_srt_do_test (srt_input, 0, G_N_ELEMENTS (srt_input)); |
|
241 xmlfile = "subparse_test_srt"; |
|
242 std_log(LOG_FILENAME_LINE, "Test Started test_srt"); |
|
243 /* make sure everything works fine if we don't start with chunk 1 */ |
|
244 test_srt_do_test (srt_input, 1, G_N_ELEMENTS (srt_input) - 1); |
|
245 test_srt_do_test (srt_input, 2, G_N_ELEMENTS (srt_input) - 2); |
|
246 test_srt_do_test (srt_input, 3, G_N_ELEMENTS (srt_input) - 3); |
|
247 test_srt_do_test (srt_input, 4, G_N_ELEMENTS (srt_input) - 4); |
|
248 |
|
249 /* try with empty input, immediate EOS */ |
|
250 test_srt_do_test (srt_input, 5, G_N_ELEMENTS (srt_input) - 5); |
|
251 |
|
252 /* try with chunk number 0 (which is not exactly according to spec) */ |
|
253 test_srt_do_test (srt_input0, 0, G_N_ELEMENTS (srt_input0)); |
|
254 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
255 create_xml(0); |
|
256 |
|
257 } |
|
258 |
|
259 |
|
260 static void |
|
261 do_test (SubParseInputChunk * input, guint num, const gchar * media_type) |
|
262 { |
|
263 guint n; |
|
264 |
|
265 setup_subparse (); |
|
266 |
|
267 for (n = 0; n < num; ++n) { |
|
268 GstBuffer *buf; |
|
269 |
|
270 buf = buffer_from_static_string (input[n].in); |
|
271 fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); |
|
272 } |
|
273 |
|
274 gst_pad_push_event (mysrcpad, gst_event_new_eos ()); |
|
275 |
|
276 fail_unless_equals_int (g_list_length (buffers), num); |
|
277 |
|
278 for (n = 0; n < num; ++n) { |
|
279 const GstStructure *buffer_caps_struct; |
|
280 GstBuffer *buf; |
|
281 gchar *out; |
|
282 guint out_size; |
|
283 |
|
284 buf = g_list_nth_data (buffers, n); |
|
285 fail_unless (buf != NULL); |
|
286 fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf), NULL); |
|
287 fail_unless (GST_BUFFER_DURATION_IS_VALID (buf), NULL); |
|
288 fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts); |
|
289 fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf), |
|
290 input[n].to_ts - input[n].from_ts); |
|
291 out = (gchar *) GST_BUFFER_DATA (buf); |
|
292 out_size = GST_BUFFER_SIZE (buf); |
|
293 /* shouldn't have trailing newline characters */ |
|
294 fail_if (out_size > 0 && out[out_size - 1] == '\n'); |
|
295 /* shouldn't include NUL-terminator in data size */ |
|
296 fail_if (out_size > 0 && out[out_size - 1] == '\0'); |
|
297 /* but should still have a NUL-terminator behind the declared data */ |
|
298 fail_unless_equals_int (out[out_size], '\0'); |
|
299 /* make sure out string matches expected string */ |
|
300 fail_unless_equals_string (out, input[n].out); |
|
301 /* check caps */ |
|
302 fail_unless (GST_BUFFER_CAPS (buf) != NULL); |
|
303 buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); |
|
304 fail_unless_equals_string (gst_structure_get_name (buffer_caps_struct), |
|
305 media_type); |
|
306 } |
|
307 |
|
308 teardown_subparse (); |
|
309 } |
|
310 |
|
311 static void |
|
312 test_tmplayer_do_test (SubParseInputChunk * input, guint num) |
|
313 { |
|
314 do_test (input, num, "text/plain"); |
|
315 } |
|
316 |
|
317 static void |
|
318 test_microdvd_do_test (SubParseInputChunk * input, guint num) |
|
319 { |
|
320 do_test (input, num, "text/x-pango-markup"); |
|
321 } |
|
322 |
|
323 void test_tmplayer_multiline() |
|
324 { |
|
325 |
|
326 static SubParseInputChunk tmplayer_multiline_input[] = { |
|
327 { |
|
328 "00:00:10,1=This is the Earth at a time\n" |
|
329 "00:00:10,2=when the dinosaurs roamed...\n" "00:00:13,1=\n", |
|
330 10 * GST_SECOND, 13 * GST_SECOND, |
|
331 "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { |
|
332 "00:00:14,1=a lush and fertile planet.\n" "00:00:16,1=\n", |
|
333 14 * GST_SECOND, 16 * GST_SECOND, |
|
334 "a lush and fertile planet."} |
|
335 }; |
|
336 |
|
337 xmlfile = "subparse_test_tmplayer_multiline"; |
|
338 std_log(LOG_FILENAME_LINE, "Test Started test_tmplayer_multiline"); |
|
339 |
|
340 test_tmplayer_do_test (tmplayer_multiline_input, |
|
341 G_N_ELEMENTS (tmplayer_multiline_input)); |
|
342 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
343 create_xml(0); |
|
344 |
|
345 } |
|
346 |
|
347 |
|
348 |
|
349 void test_tmplayer_multiline_with_bogus_lines() |
|
350 { |
|
351 |
|
352 static SubParseInputChunk tmplayer_multiline_b_input[] = { |
|
353 { |
|
354 "00:00:10,1=This is the Earth at a time\n" |
|
355 "Yooboo wabahablablahuguug bogus line hello test 1-2-3-4\n" |
|
356 "00:00:10,2=when the dinosaurs roamed...\n" "00:00:13,1=\n", |
|
357 10 * GST_SECOND, 13 * GST_SECOND, |
|
358 "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { |
|
359 "00:00:14,1=a lush and fertile planet.\n" "00:00:16,1=\n", |
|
360 14 * GST_SECOND, 16 * GST_SECOND, |
|
361 "a lush and fertile planet."} |
|
362 }; |
|
363 |
|
364 xmlfile = "subparse_test_tmplayer_multiline_with_bogus_lines"; |
|
365 std_log(LOG_FILENAME_LINE, "Test Started test_tmplayer_multiline_with_bogus_lines"); |
|
366 |
|
367 test_tmplayer_do_test (tmplayer_multiline_b_input, |
|
368 G_N_ELEMENTS (tmplayer_multiline_b_input)); |
|
369 |
|
370 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
371 create_xml(0); |
|
372 } |
|
373 |
|
374 |
|
375 |
|
376 void test_tmplayer_style1() |
|
377 { |
|
378 |
|
379 static SubParseInputChunk tmplayer_style1_input[] = { |
|
380 { |
|
381 "00:00:10:This is the Earth at a time|when the dinosaurs roamed...\n" |
|
382 "00:00:13:\n", |
|
383 10 * GST_SECOND, 13 * GST_SECOND, |
|
384 "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { |
|
385 "00:00:14:a lush and fertile planet.\n" "00:00:16:\n", |
|
386 14 * GST_SECOND, 16 * GST_SECOND, |
|
387 "a lush and fertile planet."} |
|
388 }; |
|
389 xmlfile = "subparse_test_tmplayer_style1"; |
|
390 std_log(LOG_FILENAME_LINE, "Test Started test_tmplayer_style1"); |
|
391 test_tmplayer_do_test (tmplayer_style1_input, |
|
392 G_N_ELEMENTS (tmplayer_style1_input)); |
|
393 |
|
394 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
395 create_xml(0); |
|
396 } |
|
397 |
|
398 |
|
399 |
|
400 void test_tmplayer_style2() |
|
401 { |
|
402 |
|
403 static SubParseInputChunk tmplayer_style2_input[] = { |
|
404 { |
|
405 "00:00:10=This is the Earth at a time|when the dinosaurs roamed...\n" |
|
406 "00:00:13=\n", |
|
407 10 * GST_SECOND, 13 * GST_SECOND, |
|
408 "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { |
|
409 "00:00:14=a lush and fertile planet.\n" "00:00:16=\n", |
|
410 14 * GST_SECOND, 16 * GST_SECOND, |
|
411 "a lush and fertile planet."} |
|
412 }; |
|
413 xmlfile = "subparse_test_tmplayer_style2"; |
|
414 std_log(LOG_FILENAME_LINE, "Test Started test_tmplayer_style2"); |
|
415 test_tmplayer_do_test (tmplayer_style2_input, |
|
416 G_N_ELEMENTS (tmplayer_style2_input)); |
|
417 |
|
418 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
419 create_xml(0); |
|
420 |
|
421 } |
|
422 |
|
423 |
|
424 |
|
425 void test_tmplayer_style3() |
|
426 { |
|
427 |
|
428 static SubParseInputChunk tmplayer_style3_input[] = { |
|
429 { |
|
430 "0:00:10:This is the Earth at a time|when the dinosaurs roamed...\n" |
|
431 "0:00:13:\n", |
|
432 10 * GST_SECOND, 13 * GST_SECOND, |
|
433 "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { |
|
434 "0:00:14:a lush and fertile planet.\n" "0:00:16:\n", |
|
435 14 * GST_SECOND, 16 * GST_SECOND, |
|
436 "a lush and fertile planet."} |
|
437 }; |
|
438 xmlfile = "subparse_test_tmplayer_style3"; |
|
439 std_log(LOG_FILENAME_LINE, "Test Started test_tmplayer_style3"); |
|
440 test_tmplayer_do_test (tmplayer_style3_input, |
|
441 G_N_ELEMENTS (tmplayer_style3_input)); |
|
442 |
|
443 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
444 create_xml(0); |
|
445 } |
|
446 |
|
447 |
|
448 |
|
449 void test_tmplayer_style4() |
|
450 { |
|
451 |
|
452 static SubParseInputChunk tmplayer_style4_input[] = { |
|
453 { |
|
454 "0:00:10=This is the Earth at a time|when the dinosaurs roamed...\n" |
|
455 "0:00:13=\n", |
|
456 10 * GST_SECOND, 13 * GST_SECOND, |
|
457 "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { |
|
458 "0:00:14=a lush and fertile planet.\n" "0:00:16=\n", |
|
459 14 * GST_SECOND, 16 * GST_SECOND, |
|
460 "a lush and fertile planet."} |
|
461 }; |
|
462 |
|
463 xmlfile = "subparse_test_tmplayer_style4"; |
|
464 std_log(LOG_FILENAME_LINE, "Test Started test_tmplayer_style4"); |
|
465 |
|
466 test_tmplayer_do_test (tmplayer_style4_input, |
|
467 G_N_ELEMENTS (tmplayer_style4_input)); |
|
468 |
|
469 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
470 create_xml(0); |
|
471 } |
|
472 |
|
473 |
|
474 |
|
475 void test_tmplayer_style4_with_bogus_lines() |
|
476 { |
|
477 |
|
478 static SubParseInputChunk tmplayer_style4b_input[] = { |
|
479 { |
|
480 "0:00:10=This is the Earth at a time|when the dinosaurs roamed...\n" |
|
481 "# This is a bogus line with a comment and should just be skipped\n" |
|
482 "0:00:13=\n", |
|
483 10 * GST_SECOND, 13 * GST_SECOND, |
|
484 "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { |
|
485 "0:00:14=a lush and fertile planet.\n" |
|
486 " \n" |
|
487 "0:00:16=\n", |
|
488 14 * GST_SECOND, 16 * GST_SECOND, |
|
489 "a lush and fertile planet."} |
|
490 }; |
|
491 xmlfile = "subparse_test_tmplayer_style4_with_bogus_lines"; |
|
492 std_log(LOG_FILENAME_LINE, "Test Started test_tmplayer_style4_with_bogus_lines"); |
|
493 test_tmplayer_do_test (tmplayer_style4b_input, |
|
494 G_N_ELEMENTS (tmplayer_style4b_input)); |
|
495 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
496 create_xml(0); |
|
497 } |
|
498 |
|
499 |
|
500 |
|
501 void test_microdvd_with_italics() |
|
502 { |
|
503 |
|
504 static SubParseInputChunk microdvd_italics[] = { |
|
505 { |
|
506 "{1}{1}25.000 movie info: XVID 608x256 25.0fps 699.0 MB|" |
|
507 "/SubEdit b.4060(http://subedit.com.pl)/\n" |
|
508 "{100}{200}/italics/|not italics\n", |
|
509 4 * GST_SECOND, 8 * GST_SECOND, |
|
510 "<span style=\"italic\">italics</span>\n" "<span>not italics</span>"} |
|
511 }; |
|
512 xmlfile = "subparse_test_microdvd_with_italics"; |
|
513 std_log(LOG_FILENAME_LINE, "Test Started test_microdvd_with_italics"); |
|
514 test_microdvd_do_test (microdvd_italics, G_N_ELEMENTS (microdvd_italics)); |
|
515 |
|
516 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
517 create_xml(0); |
|
518 } |
|
519 |
|
520 |
|
521 |
|
522 void test_microdvd_with_fps() |
|
523 { |
|
524 |
|
525 static SubParseInputChunk microdvd_input[] = { |
|
526 { |
|
527 "{1}{1}12.500\n{100}{200}- Hi, Eddie.|- Hiya, Scotty.\n", |
|
528 8 * GST_SECOND, 16 * GST_SECOND, |
|
529 "<span>- Hi, Eddie.</span>\n<span>- Hiya, Scotty.</span>"}, { |
|
530 "{1250}{1350}- Cold enough for you?|- Well, I'm only faintly alive. " |
|
531 "It's 25 below\n", |
|
532 100 * GST_SECOND, 108 * GST_SECOND, |
|
533 "<span>- Cold enough for you?</span>\n" |
|
534 "<span>- Well, I'm only faintly alive. It's 25 below</span>"} |
|
535 }; |
|
536 xmlfile = "subparse_test_microdvd_with_fps"; |
|
537 std_log(LOG_FILENAME_LINE, "Test Started test_microdvd_with_fps"); |
|
538 test_microdvd_do_test (microdvd_input, G_N_ELEMENTS (microdvd_input)); |
|
539 |
|
540 /* and the same with ',' instead of '.' as floating point divider */ |
|
541 microdvd_input[0].in = |
|
542 "{1}{1}12,500\n{100}{200}- Hi, Eddie.|- Hiya, Scotty.\n"; |
|
543 test_microdvd_do_test (microdvd_input, G_N_ELEMENTS (microdvd_input)); |
|
544 |
|
545 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
546 create_xml(0); |
|
547 } |
|
548 |
|
549 |
|
550 |
|
551 void test_mpl2() |
|
552 { |
|
553 |
|
554 SubParseInputChunk mpl2_input[] = { |
|
555 { |
|
556 "[123][456] This is the Earth at a time|when the dinosaurs roamed\n", |
|
557 (123 * GST_SECOND) / 10, (456 * GST_SECOND) / 10, |
|
558 "This is the Earth at a time\nwhen the dinosaurs roamed"}, { |
|
559 "[1234][5678]a lush and fertile planet.\n", |
|
560 (1234 * GST_SECOND) / 10, (5678 * GST_SECOND) / 10, |
|
561 "a lush and fertile planet."}, { |
|
562 "[12345][27890] /Italic|Normal\n", |
|
563 (12345 * GST_SECOND) / 10, (27890 * GST_SECOND) / 10, |
|
564 "<i>Italic</i>\nNormal"}, { |
|
565 "[32345][37890]/Italic|/Italic\n", |
|
566 (32345 * GST_SECOND) / 10, (37890 * GST_SECOND) / 10, |
|
567 "<i>Italic</i>\n<i>Italic</i>"}, { |
|
568 "[42345][47890] Normal|/Italic", |
|
569 (42345 * GST_SECOND) / 10, (47890 * GST_SECOND) / 10, |
|
570 "Normal\n<i>Italic</i>"} |
|
571 }; |
|
572 |
|
573 xmlfile = "subparse_test_mp12"; |
|
574 std_log(LOG_FILENAME_LINE, "Test Started test_mp2"); |
|
575 |
|
576 do_test (mpl2_input, G_N_ELEMENTS (mpl2_input), "text/x-pango-markup"); |
|
577 |
|
578 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
579 create_xml(0); |
|
580 } |
|
581 |
|
582 |
|
583 |
|
584 void test_subviewer() |
|
585 { |
|
586 |
|
587 SubParseInputChunk subviewer_input[] = { |
|
588 { |
|
589 "[INFORMATION]\n" |
|
590 "[TITLE]xxxxxxxxxx\n" |
|
591 "[AUTHOR]xxxxxxxx\n" |
|
592 "[SOURCE]xxxxxxxxxxxxxxxx\n" |
|
593 "[FILEPATH]\n" |
|
594 "[DELAY]0\n" |
|
595 "[COMMENT]\n" |
|
596 "[END INFORMATION]\n" |
|
597 "[SUBTITLE]\n" |
|
598 "[COLF]&HFFFFFF,[STYLE]bd,[SIZE]18,[FONT]Arial\n" |
|
599 "00:00:41.00,00:00:44.40\n" |
|
600 "The Age of Gods was closing.\n" |
|
601 "Eternity had come to an end.\n" |
|
602 "\n", 41 * GST_SECOND, 44 * GST_SECOND + 40 * GST_MSECOND, |
|
603 "The Age of Gods was closing.\nEternity had come to an end."}, { |
|
604 "00:00:55.00,00:00:58.40\n" |
|
605 "The heavens shook as the armies\n" |
|
606 "of Falis, God of Light...\n\n", 55 * GST_SECOND, |
|
607 58 * GST_SECOND + 40 * GST_MSECOND, |
|
608 "The heavens shook as the armies\nof Falis, God of Light..."} |
|
609 }; |
|
610 |
|
611 xmlfile = "subparse_test_subviewer"; |
|
612 std_log(LOG_FILENAME_LINE, "Test Started test_subviewer"); |
|
613 |
|
614 do_test (subviewer_input, G_N_ELEMENTS (subviewer_input), "text/plain"); |
|
615 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
616 create_xml(0); |
|
617 } |
|
618 |
|
619 |
|
620 |
|
621 void test_subviewer2() |
|
622 { |
|
623 |
|
624 SubParseInputChunk subviewer2_input[] = { |
|
625 { |
|
626 "[INFORMATION]\n" |
|
627 "[TITLE]xxxxxxxxxx\n" |
|
628 "[AUTHOR]xxxxxxxxxx\n" |
|
629 "[SOURCE]xxxxxxxxxx\n" |
|
630 "[PRG]\n" |
|
631 "[FILEPATH]\n" |
|
632 "[DELAY]0\n" |
|
633 "[CD TRACK]0\n" |
|
634 "[COMMENT]\n" |
|
635 "[END INFORMATION]\n" |
|
636 "[SUBTITLE]\n" |
|
637 "[COLF]&H00FFFF,[STYLE]no,[SIZE]12,[FONT]Courier New\n" |
|
638 "00:00:07.00,00:00:11.91\n" |
|
639 "THERE IS A PLACE ON EARTH WHERE IT[br]IS STILL THE MORNING OF LIFE...\n\n", |
|
640 7 * GST_SECOND, 11 * GST_SECOND + 91 * GST_MSECOND, |
|
641 "THERE IS A PLACE ON EARTH WHERE IT\nIS STILL THE MORNING OF LIFE..."}, { |
|
642 "00:00:12.48,00:00:15.17\n" |
|
643 "AND THE GREAT HERDS RUN FREE.[br]SO WHAT?!\n\n", |
|
644 12 * GST_SECOND + 48 * GST_MSECOND, |
|
645 15 * GST_SECOND + 17 * GST_MSECOND, |
|
646 "AND THE GREAT HERDS RUN FREE.\nSO WHAT?!"} |
|
647 }; |
|
648 |
|
649 xmlfile = "subparse_test_subviewer2"; |
|
650 std_log(LOG_FILENAME_LINE, "Test Started test_subviewer2"); |
|
651 |
|
652 do_test (subviewer2_input, G_N_ELEMENTS (subviewer2_input), "text/plain"); |
|
653 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
654 create_xml(0); |
|
655 } |
|
656 |
|
657 |
|
658 |
|
659 /* TODO: |
|
660 * - add/modify tests so that lines aren't dogfed to the parsers in complete |
|
661 * lines or sets of complete lines, but rather in random chunks |
|
662 */ |
|
663 |
|
664 /*static Suite * |
|
665 subparse_suite (void) |
|
666 { |
|
667 Suite *s = suite_create ("subparse"); |
|
668 TCase *tc_chain = tcase_create ("general"); |
|
669 |
|
670 suite_add_tcase (s, tc_chain); |
|
671 |
|
672 tcase_add_test (tc_chain, test_srt); |
|
673 tcase_add_test (tc_chain, test_tmplayer_multiline); |
|
674 tcase_add_test (tc_chain, test_tmplayer_multiline_with_bogus_lines); |
|
675 tcase_add_test (tc_chain, test_tmplayer_style1); |
|
676 tcase_add_test (tc_chain, test_tmplayer_style2); |
|
677 tcase_add_test (tc_chain, test_tmplayer_style3); |
|
678 tcase_add_test (tc_chain, test_tmplayer_style4); |
|
679 tcase_add_test (tc_chain, test_tmplayer_style4_with_bogus_lines); |
|
680 tcase_add_test (tc_chain, test_microdvd_with_fps); |
|
681 tcase_add_test (tc_chain, test_microdvd_with_italics); |
|
682 tcase_add_test (tc_chain, test_mpl2); |
|
683 tcase_add_test (tc_chain, test_subviewer); |
|
684 tcase_add_test (tc_chain, test_subviewer2); |
|
685 return s; |
|
686 } |
|
687 |
|
688 */ |
|
689 |
|
690 #if 1 |
|
691 void (*fn[13]) (void) = { |
|
692 test_srt, |
|
693 test_tmplayer_multiline, |
|
694 test_tmplayer_multiline_with_bogus_lines, |
|
695 test_tmplayer_style1, |
|
696 test_tmplayer_style2, |
|
697 test_tmplayer_style3, |
|
698 test_tmplayer_style4, |
|
699 test_tmplayer_style4_with_bogus_lines, |
|
700 test_microdvd_with_fps, |
|
701 test_microdvd_with_italics, |
|
702 test_mpl2, |
|
703 test_subviewer, |
|
704 test_subviewer2 |
|
705 }; |
|
706 |
|
707 char *args[] = { |
|
708 "test_srt", |
|
709 "test_tmplayer_multiline", |
|
710 "test_tmplayer_multiline_with_bogus_lines", |
|
711 "test_tmplayer_style1", |
|
712 "test_tmplayer_style2", |
|
713 "test_tmplayer_style3", |
|
714 "test_tmplayer_style4", |
|
715 "test_tmplayer_style4_with_bogus_lines", |
|
716 "test_microdvd_with_fps", |
|
717 "test_microdvd_with_italics", |
|
718 "test_mpl2", |
|
719 "test_subviewer", |
|
720 "test_subviewer2" |
|
721 }; |
|
722 |
|
723 GST_CHECK_MAIN (subparse); |
|
724 |
|
725 #endif |
|
726 |
|
727 #if 0 |
|
728 int main() |
|
729 { |
|
730 gst_check_init (NULL, NULL); |
|
731 // test_srt(); |
|
732 // test_tmplayer_multiline(); |
|
733 // test_tmplayer_multiline_with_bogus_lines(); |
|
734 // test_tmplayer_style1(); |
|
735 // test_tmplayer_style2(); |
|
736 // test_tmplayer_style3(); |
|
737 // test_tmplayer_style4(); |
|
738 // test_tmplayer_style4_with_bogus_lines(); |
|
739 // test_microdvd_with_fps(); |
|
740 // test_microdvd_with_italics(); |
|
741 // test_mpl2(); |
|
742 // test_subviewer(); |
|
743 // test_subviewer2(); |
|
744 } |
|
745 #endif |