Debian Codegraph @

tests/check/ges/titles.c

raw
1 /* GStreamer Editing Services
2 * Copyright (C) 2010 Brandon Lewis <[email protected]>
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 "test-utils.h"
21 #include <ges/ges.h>
22 #include <gst/check/gstcheck.h>
23
24 GST_START_TEST (test_title_source_basic)
25 {
26 GESTitleClip *source;
27
28 ges_init ();
29
30 source = ges_title_clip_new ();
31 fail_unless (source != NULL);
32
33 gst_object_unref (source);
34
35 ges_deinit ();
36 }
37
38 GST_END_TEST;
39
40 GST_START_TEST (test_title_source_properties)
41 {
42 GESClip *clip;
43 GESTrack *track;
44 GESTimeline *timeline;
45 GESLayer *layer;
46 GESTrackElement *trackelement;
47
48 ges_init ();
49
50 track = GES_TRACK (ges_video_track_new ());
51 fail_unless (track != NULL);
52 layer = ges_layer_new ();
53 fail_unless (layer != NULL);
54 timeline = ges_timeline_new ();
55 fail_unless (timeline != NULL);
56 fail_unless (ges_timeline_add_layer (timeline, layer));
57 fail_unless (ges_timeline_add_track (timeline, track));
58 ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1);
59
60 clip = (GESClip *) ges_title_clip_new ();
61 fail_unless (clip != NULL);
62
63 /* Set some properties */
64 g_object_set (clip, "start", (guint64) 42, "duration", (guint64) 51,
65 "in-point", (guint64) 12, NULL);
66 assert_equals_uint64 (_START (clip), 42);
67 assert_equals_uint64 (_DURATION (clip), 51);
68 /* the clip can have a non-zero in-point, but this won't affect any
69 * of the core children because they have their has-internal-source set
70 * to FALSE */
71 assert_equals_uint64 (_INPOINT (clip), 12);
72
73 ges_layer_add_clip (layer, GES_CLIP (clip));
74 ges_timeline_commit (timeline);
75 assert_equals_int (g_list_length (GES_CONTAINER_CHILDREN (clip)), 1);
76 trackelement = GES_CONTAINER_CHILDREN (clip)->data;
77 fail_unless (trackelement != NULL);
78 fail_unless (GES_TIMELINE_ELEMENT_PARENT (trackelement) ==
79 GES_TIMELINE_ELEMENT (clip));
80 fail_unless (ges_track_element_get_track (trackelement) == track);
81
82 /* Check that trackelement has the same properties */
83 assert_equals_uint64 (_START (trackelement), 42);
84 assert_equals_uint64 (_DURATION (trackelement), 51);
85 assert_equals_uint64 (_INPOINT (trackelement), 0);
86
87 /* And let's also check that it propagated correctly to GNonLin */
88 nle_object_check (ges_track_element_get_nleobject (trackelement), 42, 51, 0,
89 51, MIN_NLE_PRIO + TRANSITIONS_HEIGHT, TRUE);
90
91 /* Change more properties, see if they propagate */
92 g_object_set (clip, "start", (guint64) 420, "duration", (guint64) 510,
93 "in-point", (guint64) 120, NULL);
94 ges_timeline_commit (timeline);
95 assert_equals_uint64 (_START (clip), 420);
96 assert_equals_uint64 (_DURATION (clip), 510);
97 assert_equals_uint64 (_INPOINT (clip), 120);
98 assert_equals_uint64 (_START (trackelement), 420);
99 assert_equals_uint64 (_DURATION (trackelement), 510);
100 assert_equals_uint64 (_INPOINT (trackelement), 0);
101
102 /* And let's also check that it propagated correctly to GNonLin */
103 nle_object_check (ges_track_element_get_nleobject (trackelement), 420, 510,
104 0, 510, MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0, TRUE);
105
106 ges_container_remove (GES_CONTAINER (clip),
107 GES_TIMELINE_ELEMENT (trackelement));
108 gst_object_unref (timeline);
109
110 ges_deinit ();
111 }
112
113 GST_END_TEST;
114
115 GST_START_TEST (test_title_source_in_layer)
116 {
117 GESTimeline *timeline;
118 GESLayer *layer;
119 GESTrack *a, *v;
120 GESTrackElement *track_element;
121 GESTitleClip *source;
122 gchar *text;
123 gint halign, valign;
124 guint32 color;
125 gdouble xpos;
126 gdouble ypos;
127
128 ges_init ();
129
130 timeline = ges_timeline_new ();
131 layer = ges_layer_new ();
132 a = GES_TRACK (ges_audio_track_new ());
133 v = GES_TRACK (ges_video_track_new ());
134
135 ges_timeline_add_track (timeline, a);
136 ges_timeline_add_track (timeline, v);
137 ges_timeline_add_layer (timeline, layer);
138
139 source = ges_title_clip_new ();
140
141 g_object_set (source, "duration", (guint64) GST_SECOND, NULL);
142
143 ges_layer_add_clip (layer, (GESClip *) source);
144
145 /* specifically test the text property */
146 g_object_set (source, "text", (gchar *) "some text", NULL);
147 g_object_get (source, "text", &text, NULL);
148 assert_equals_string ("some text", text);
149 g_free (text);
150
151 track_element =
152 ges_clip_find_track_element (GES_CLIP (source), v, GES_TYPE_TITLE_SOURCE);
153
154 /* test the font-desc property */
155 g_object_set (source, "font-desc", (gchar *) "sans 72", NULL);
156 g_object_get (source, "font-desc", &text, NULL);
157 assert_equals_string ("sans 72", text);
158 g_free (text);
159
160 /* test halign and valign */
161 g_object_set (source, "halignment", (gint)
162 GES_TEXT_HALIGN_LEFT, "valignment", (gint) GES_TEXT_VALIGN_TOP, NULL);
163 g_object_get (source, "halignment", &halign, "valignment", &valign, NULL);
164 assert_equals_int (halign, GES_TEXT_HALIGN_LEFT);
165 assert_equals_int (valign, GES_TEXT_VALIGN_TOP);
166
167 assert_equals_int (ges_title_source_get_halignment
168 (GES_TITLE_SOURCE (track_element)), GES_TEXT_HALIGN_LEFT);
169 assert_equals_int (ges_title_source_get_valignment
170 (GES_TITLE_SOURCE (track_element)), GES_TEXT_VALIGN_TOP);
171
172 /* test color */
173 g_object_set (source, "color", (gint) 2147483647, NULL);
174 g_object_get (source, "color", &color, NULL);
175 assert_equals_int (color, 2147483647);
176
177 color = ges_title_source_get_text_color (GES_TITLE_SOURCE (track_element));
178 assert_equals_int (color, 2147483647);
179
180 /* test xpos */
181 g_object_set (source, "xpos", (gdouble) 0.25, NULL);
182 g_object_get (source, "xpos", &xpos, NULL);
183 assert_equals_float (xpos, 0.25);
184
185 xpos = ges_title_source_get_xpos (GES_TITLE_SOURCE (track_element));
186 assert_equals_float (xpos, 0.25);
187
188 /* test ypos */
189 g_object_set (source, "ypos", (gdouble) 0.66, NULL);
190 g_object_get (source, "ypos", &ypos, NULL);
191 assert_equals_float (ypos, 0.66);
192
193 xpos = ges_title_source_get_xpos (GES_TITLE_SOURCE (track_element));
194 assert_equals_float (ypos, 0.66);
195
196 GST_DEBUG ("removing the source");
197
198 ges_layer_remove_clip (layer, (GESClip *) source);
199
200 GST_DEBUG ("removing the layer");
201
202 gst_object_unref (track_element);
203 gst_object_unref (timeline);
204
205 ges_deinit ();
206 }
207
208 GST_END_TEST;
209
210 static Suite *
211 ges_suite (void)
212 {
213 Suite *s = suite_create ("ges-titles");
214 TCase *tc_chain = tcase_create ("titles");
215
216 suite_add_tcase (s, tc_chain);
217
218 tcase_add_test (tc_chain, test_title_source_basic);
219 tcase_add_test (tc_chain, test_title_source_properties);
220 tcase_add_test (tc_chain, test_title_source_in_layer);
221
222 return s;
223 }
224
225 GST_CHECK_MAIN (ges);