1 /* GStreamer Editing Services
3 * Copyright (C) <2019> Mathieu Duponchelle <mathieu@centricular.com>
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.
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.
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., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include "test-utils.h"
23 #include <gst/check/gstcheck.h>
25 GST_START_TEST (test_add)
27 GESMarkerList *markerlist;
31 markerlist = ges_marker_list_new ();
32 marker = ges_marker_list_add (markerlist, 42);
34 ASSERT_OBJECT_REFCOUNT (marker, "marker list", 1);
36 g_object_ref (marker);
38 ASSERT_OBJECT_REFCOUNT (marker, "marker list + local ref", 2);
40 g_object_unref (markerlist);
42 ASSERT_OBJECT_REFCOUNT (marker, "local ref", 1);
44 g_object_unref (marker);
51 GST_START_TEST (test_remove)
53 GESMarkerList *markerlist;
57 markerlist = ges_marker_list_new ();
58 marker = ges_marker_list_add (markerlist, 42);
60 g_object_ref (marker);
62 fail_unless_equals_int (ges_marker_list_size (markerlist), 1);
64 fail_unless (ges_marker_list_remove (markerlist, marker));
65 fail_unless_equals_int (ges_marker_list_size (markerlist), 0);
67 ASSERT_OBJECT_REFCOUNT (marker, "local ref", 1);
69 fail_if (ges_marker_list_remove (markerlist, marker));
71 g_object_unref (marker);
73 g_object_unref (markerlist);
82 marker_added_cb (GESMarkerList * mlist, GstClockTime position,
83 GESMarker * marker, gboolean * called)
85 fail_unless_equals_int (position, 42);
87 ASSERT_OBJECT_REFCOUNT (marker, "local ref + signal", 2);
91 GST_START_TEST (test_signal_marker_added)
95 gboolean called = FALSE;
99 mlist = ges_marker_list_new ();
100 g_signal_connect (mlist, "marker-added", G_CALLBACK (marker_added_cb),
102 marker = ges_marker_list_add (mlist, 42);
103 ASSERT_OBJECT_REFCOUNT (marker, "local ref", 1);
104 fail_unless (called == TRUE);
105 g_signal_handlers_disconnect_by_func (mlist, marker_added_cb, &called);
107 g_object_unref (mlist);
116 marker_removed_cb (GESMarkerList * mlist, GESMarker * marker, gboolean * called)
118 ASSERT_OBJECT_REFCOUNT (marker, "local ref + signal", 2);
122 GST_START_TEST (test_signal_marker_removed)
124 GESMarkerList *mlist;
126 gboolean called = FALSE;
130 mlist = ges_marker_list_new ();
131 marker = ges_marker_list_add (mlist, 42);
133 ASSERT_OBJECT_REFCOUNT (marker, "local ref", 1);
135 g_signal_connect (mlist, "marker-removed", G_CALLBACK (marker_removed_cb),
138 fail_unless (ges_marker_list_remove (mlist, marker));
140 fail_unless (called == TRUE);
142 g_signal_handlers_disconnect_by_func (mlist, marker_removed_cb, &called);
144 g_object_unref (mlist);
153 marker_moved_cb (GESMarkerList * mlist, GstClockTime position,
154 GESMarker * marker, gboolean * called)
156 fail_unless_equals_int (position, 42);
158 ASSERT_OBJECT_REFCOUNT (marker, "local ref + signal", 2);
162 GST_START_TEST (test_signal_marker_moved)
164 GESMarkerList *mlist;
166 gboolean called = FALSE;
170 mlist = ges_marker_list_new ();
171 g_signal_connect (mlist, "marker-moved", G_CALLBACK (marker_moved_cb),
174 marker = ges_marker_list_add (mlist, 10);
175 ASSERT_OBJECT_REFCOUNT (marker, "local ref", 1);
177 fail_unless (ges_marker_list_move (mlist, marker, 42));
179 fail_unless (called == TRUE);
181 g_signal_handlers_disconnect_by_func (mlist, marker_moved_cb, &called);
183 g_object_unref (mlist);
191 GST_START_TEST (test_get_markers)
193 GESMarkerList *markerlist;
194 GESMarker *marker1, *marker2, *marker3, *marker4;
199 markerlist = ges_marker_list_new ();
200 marker1 = ges_marker_list_add (markerlist, 0);
201 marker2 = ges_marker_list_add (markerlist, 10);
202 marker3 = ges_marker_list_add (markerlist, 20);
203 marker4 = ges_marker_list_add (markerlist, 30);
205 markers = ges_marker_list_get_markers (markerlist);
207 ASSERT_OBJECT_REFCOUNT (marker1, "local ref + markers", 2);
208 ASSERT_OBJECT_REFCOUNT (marker2, "local ref + markers", 2);
209 ASSERT_OBJECT_REFCOUNT (marker3, "local ref + markers", 2);
210 ASSERT_OBJECT_REFCOUNT (marker4, "local ref + markers", 2);
212 fail_unless (g_list_index (markers, marker1) == 0);
213 fail_unless (g_list_index (markers, marker2) == 1);
214 fail_unless (g_list_index (markers, marker3) == 2);
215 fail_unless (g_list_index (markers, marker4) == 3);
217 g_list_foreach (markers, (GFunc) gst_object_unref, NULL);
218 g_list_free (markers);
220 g_object_unref (markerlist);
228 GST_START_TEST (test_move_marker)
230 GESMarkerList *markerlist;
231 GESMarker *marker_a, *marker_b;
232 GstClockTime position;
237 markerlist = ges_marker_list_new ();
239 marker_a = ges_marker_list_add (markerlist, 10);
240 marker_b = ges_marker_list_add (markerlist, 30);
242 fail_unless (ges_marker_list_move (markerlist, marker_a, 20));
244 g_object_get (marker_a, "position", &position, NULL);
245 fail_unless_equals_int (position, 20);
247 range = ges_marker_list_get_markers (markerlist);
249 fail_unless (g_list_index (range, marker_a) == 0);
250 fail_unless (g_list_index (range, marker_b) == 1);
252 g_list_foreach (range, (GFunc) gst_object_unref, NULL);
255 fail_unless (ges_marker_list_move (markerlist, marker_a, 35));
257 range = ges_marker_list_get_markers (markerlist);
259 fail_unless (g_list_index (range, marker_b) == 0);
260 fail_unless (g_list_index (range, marker_a) == 1);
262 g_list_foreach (range, (GFunc) gst_object_unref, NULL);
265 fail_unless (ges_marker_list_move (markerlist, marker_a, 30));
267 g_object_get (marker_a, "position", &position, NULL);
268 fail_unless_equals_int (position, 30);
270 g_object_get (marker_b, "position", &position, NULL);
271 fail_unless_equals_int (position, 30);
273 fail_unless_equals_int (ges_marker_list_size (markerlist), 2);
275 ges_marker_list_remove (markerlist, marker_a);
277 fail_unless (!ges_marker_list_move (markerlist, marker_a, 20));
279 g_object_unref (markerlist);
286 GST_START_TEST (test_serialize_deserialize)
288 GESMarkerList *markerlist1, *markerlist2;
289 gchar *metas1, *metas2;
290 GESTimeline *timeline1, *timeline2;
294 timeline1 = ges_timeline_new_audio_video ();
296 markerlist1 = ges_marker_list_new ();
297 ges_marker_list_add (markerlist1, 0);
298 ges_marker_list_add (markerlist1, 10);
300 ASSERT_OBJECT_REFCOUNT (markerlist1, "local ref", 1);
302 fail_unless (ges_meta_container_set_marker_list (GES_META_CONTAINER
303 (timeline1), "ges-test", markerlist1));
305 ASSERT_OBJECT_REFCOUNT (markerlist1, "GstStructure + local ref", 2);
308 ges_meta_container_get_marker_list (GES_META_CONTAINER (timeline1),
311 fail_unless (markerlist1 == markerlist2);
313 ASSERT_OBJECT_REFCOUNT (markerlist1, "GstStructure + getter + local ref", 3);
315 g_object_unref (markerlist2);
317 ASSERT_OBJECT_REFCOUNT (markerlist1, "GstStructure + local ref", 2);
319 timeline2 = ges_timeline_new_audio_video ();
321 metas1 = ges_meta_container_metas_to_string (GES_META_CONTAINER (timeline1));
322 ges_meta_container_add_metas_from_string (GES_META_CONTAINER (timeline2),
324 metas2 = ges_meta_container_metas_to_string (GES_META_CONTAINER (timeline2));
326 fail_unless_equals_string (metas1, metas2);
331 fail_unless (ges_meta_container_set_marker_list (GES_META_CONTAINER
332 (timeline1), "ges-test", NULL));
334 ASSERT_OBJECT_REFCOUNT (markerlist1, "local ref", 1);
336 g_object_unref (markerlist1);
337 g_object_unref (timeline1);
338 g_object_unref (timeline2);
348 Suite *s = suite_create ("ges-marker-list");
349 TCase *tc_chain = tcase_create ("markerlist");
351 suite_add_tcase (s, tc_chain);
353 tcase_add_test (tc_chain, test_add);
354 tcase_add_test (tc_chain, test_remove);
355 tcase_add_test (tc_chain, test_signal_marker_added);
356 tcase_add_test (tc_chain, test_signal_marker_removed);
357 tcase_add_test (tc_chain, test_signal_marker_moved);
358 tcase_add_test (tc_chain, test_get_markers);
359 tcase_add_test (tc_chain, test_move_marker);
360 tcase_add_test (tc_chain, test_serialize_deserialize);
365 GST_CHECK_MAIN (ges);