tests/check/: use the new macro
[platform/upstream/gstreamer.git] / tests / check / libs / controller.c
1 /* GStreamer
2  *
3  * unit test for the controller library
4  *
5  * Copyright (C) <2005> Stefan Kost <ensonic at users dot sf dor net>
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
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 #include <gst/gst.h>
27 #include <gst/check/gstcheck.h>
28 #include <gst/controller/gstcontroller.h>
29
30 /* LOCAL TEST ELEMENT */
31
32 enum
33 {
34   ARG_ULONG = 1,
35   ARG_FLOAT,
36   ARG_DOUBLE,
37   ARG_BOOLEAN,
38   ARG_READONLY,
39   ARG_STATIC,
40   ARG_CONSTRUCTONLY,
41   ARG_COUNT
42 };
43
44 #define GST_TYPE_TEST_MONO_SOURCE            (gst_test_mono_source_get_type ())
45 #define GST_TEST_MONO_SOURCE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_TEST_MONO_SOURCE, GstTestMonoSource))
46 #define GST_TEST_MONO_SOURCE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_TEST_MONO_SOURCE, GstTestMonoSourceClass))
47 #define GST_IS_TEST_MONO_SOURCE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TEST_MONO_SOURCE))
48 #define GST_IS_TEST_MONO_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_TEST_MONO_SOURCE))
49 #define GST_TEST_MONO_SOURCE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_TEST_MONO_SOURCE, GstTestMonoSourceClass))
50
51 typedef struct _GstTestMonoSource GstTestMonoSource;
52 typedef struct _GstTestMonoSourceClass GstTestMonoSourceClass;
53
54 struct _GstTestMonoSource
55 {
56   GstElement parent;
57   gulong val_ulong;
58   gfloat val_float;
59   gdouble val_double;
60   gboolean val_boolean;
61 };
62 struct _GstTestMonoSourceClass
63 {
64   GstElementClass parent_class;
65 };
66
67 GType gst_test_mono_source_get_type (void);
68
69 static void
70 gst_test_mono_source_get_property (GObject * object,
71     guint property_id, GValue * value, GParamSpec * pspec)
72 {
73   GstTestMonoSource *self = GST_TEST_MONO_SOURCE (object);
74
75   switch (property_id) {
76     case ARG_ULONG:
77       g_value_set_ulong (value, self->val_ulong);
78       break;
79     case ARG_FLOAT:
80       g_value_set_float (value, self->val_float);
81       break;
82     case ARG_DOUBLE:
83       g_value_set_double (value, self->val_double);
84       break;
85     case ARG_BOOLEAN:
86       g_value_set_boolean (value, self->val_boolean);
87       break;
88     default:
89       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
90       break;
91   }
92 }
93
94 static void
95 gst_test_mono_source_set_property (GObject * object,
96     guint property_id, const GValue * value, GParamSpec * pspec)
97 {
98   GstTestMonoSource *self = GST_TEST_MONO_SOURCE (object);
99
100   switch (property_id) {
101     case ARG_ULONG:
102       self->val_ulong = g_value_get_ulong (value);
103       break;
104     case ARG_FLOAT:
105       self->val_float = g_value_get_float (value);
106       break;
107     case ARG_DOUBLE:
108       self->val_double = g_value_get_double (value);
109       break;
110     case ARG_BOOLEAN:
111       self->val_boolean = g_value_get_boolean (value);
112       break;
113     case ARG_CONSTRUCTONLY:
114       break;
115     default:
116       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
117       break;
118   }
119 }
120
121 static void
122 gst_test_mono_source_class_init (GstTestMonoSourceClass * klass)
123 {
124   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
125
126   gobject_class->set_property = gst_test_mono_source_set_property;
127   gobject_class->get_property = gst_test_mono_source_get_property;
128
129   g_object_class_install_property (gobject_class, ARG_ULONG,
130       g_param_spec_ulong ("ulong",
131           "ulong prop",
132           "ulong number parameter for the test_mono_source",
133           0, G_MAXULONG, 0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
134
135   g_object_class_install_property (gobject_class, ARG_FLOAT,
136       g_param_spec_float ("float",
137           "float prop",
138           "float number parameter for the test_mono_source",
139           0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
140
141   g_object_class_install_property (gobject_class, ARG_DOUBLE,
142       g_param_spec_double ("double",
143           "double prop",
144           "double number parameter for the test_mono_source",
145           0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
146
147   g_object_class_install_property (gobject_class, ARG_BOOLEAN,
148       g_param_spec_boolean ("boolean",
149           "boolean prop",
150           "boolean parameter for the test_mono_source",
151           FALSE, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
152
153   g_object_class_install_property (gobject_class, ARG_READONLY,
154       g_param_spec_ulong ("readonly",
155           "readonly prop",
156           "readonly parameter for the test_mono_source",
157           0, G_MAXULONG, 0, G_PARAM_READABLE | GST_PARAM_CONTROLLABLE));
158
159   g_object_class_install_property (gobject_class, ARG_STATIC,
160       g_param_spec_ulong ("static",
161           "static prop",
162           "static parameter for the test_mono_source",
163           0, G_MAXULONG, 0, G_PARAM_READWRITE));
164
165   g_object_class_install_property (gobject_class, ARG_CONSTRUCTONLY,
166       g_param_spec_ulong ("construct-only",
167           "construct-only prop",
168           "construct-only parameter for the test_mono_source",
169           0, G_MAXULONG, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
170 }
171
172 static void
173 gst_test_mono_source_base_init (GstTestMonoSourceClass * klass)
174 {
175   static const GstElementDetails details = {
176     "Monophonic source for unit tests",
177     "Source/Audio/MonoSource",
178     "Use in unit tests",
179     "Stefan Kost <ensonic@users.sf.net>"
180   };
181   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
182
183   gst_element_class_set_details (element_class, &details);
184 }
185
186 GType
187 gst_test_mono_source_get_type (void)
188 {
189   static GType type = 0;
190
191   if (type == 0) {
192     static const GTypeInfo info = {
193       (guint16) sizeof (GstTestMonoSourceClass),
194       (GBaseInitFunc) gst_test_mono_source_base_init,   // base_init
195       NULL,                     // base_finalize
196       (GClassInitFunc) gst_test_mono_source_class_init, // class_init
197       NULL,                     // class_finalize
198       NULL,                     // class_data
199       (guint16) sizeof (GstTestMonoSource),
200       0,                        // n_preallocs
201       NULL,                     // instance_init
202       NULL                      // value_table
203     };
204     type =
205         g_type_register_static (GST_TYPE_ELEMENT, "GstTestMonoSource", &info,
206         0);
207   }
208   return type;
209 }
210
211 static gboolean
212 plugin_init (GstPlugin * plugin)
213 {
214   gboolean res = TRUE;
215
216   res &= gst_element_register (plugin, "testmonosource", GST_RANK_NONE,
217       GST_TYPE_TEST_MONO_SOURCE);
218   return res;
219 }
220
221 GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR,
222     GST_VERSION_MINOR,
223     "gst-test",
224     "controller test plugin - several unit test support elements",
225     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
226
227 /*
228 static void __attribute__ ((constructor))
229 _gst_plugin_static_init__plugin_init (void)
230 {
231   static GstPluginDesc plugin_desc_ = {
232     GST_VERSION_MAJOR,
233     GST_VERSION_MINOR,
234     "gst-test",
235     "controller test plugin - several unit test support elements",
236     plugin_init,
237     VERSION,
238     GST_LICENSE,
239     PACKAGE,
240     GST_PACKAGE,
241     GST_ORIGIN,
242     GST_PADDING_INIT
243   };
244   _gst_plugin_register_static (&plugin_desc_);
245 }
246 */
247 /* TESTS */
248 /* double init should not harm */
249 GST_START_TEST (controller_init)
250 {
251   gst_controller_init (NULL, NULL);
252 }
253
254 GST_END_TEST;
255
256 /* tests for an element with no controlled params */
257 GST_START_TEST (controller_new_fail1)
258 {
259   GstController *ctrl;
260   GstElement *elem;
261
262   elem = gst_element_factory_make ("fakesrc", "test_source");
263
264   /* that property should not exist */
265   ctrl = gst_controller_new (G_OBJECT (elem), "_schrompf_", NULL);
266   fail_unless (ctrl == NULL, NULL);
267
268   gst_object_unref (elem);
269 }
270
271 GST_END_TEST;
272
273 /* tests for an element with controlled params, but none given */
274 GST_START_TEST (controller_new_fail2)
275 {
276   GstController *ctrl;
277   GstElement *elem;
278
279   elem = gst_element_factory_make ("testmonosource", "test_source");
280
281   /* no property given */
282   ctrl = gst_controller_new (G_OBJECT (elem), NULL);
283   fail_unless (ctrl == NULL, NULL);
284
285   gst_object_unref (elem);
286 }
287
288 GST_END_TEST;
289
290 /* tests for readonly params */
291 GST_START_TEST (controller_new_fail3)
292 {
293   GstController *ctrl;
294   GstElement *elem;
295
296   elem = gst_element_factory_make ("testmonosource", "test_source");
297
298   /* that property should exist and but is readonly */
299   ASSERT_CRITICAL (ctrl =
300       gst_controller_new (G_OBJECT (elem), "readonly", NULL));
301   fail_unless (ctrl == NULL, NULL);
302
303   gst_object_unref (elem);
304 }
305
306 GST_END_TEST;
307
308 /* tests for static params */
309 GST_START_TEST (controller_new_fail4)
310 {
311   GstController *ctrl;
312   GstElement *elem;
313
314   elem = gst_element_factory_make ("testmonosource", "test_source");
315
316   /* that property should exist and but is not controlable */
317   ASSERT_CRITICAL (ctrl = gst_controller_new (G_OBJECT (elem), "static", NULL));
318   fail_unless (ctrl == NULL, NULL);
319
320   gst_object_unref (elem);
321 }
322
323 GST_END_TEST;
324
325 /* tests for static params */
326 GST_START_TEST (controller_new_fail5)
327 {
328   GstController *ctrl;
329   GstElement *elem;
330
331   elem = gst_element_factory_make ("testmonosource", "test_source");
332
333   /* that property should exist and but is construct-only */
334   ASSERT_CRITICAL (ctrl =
335       gst_controller_new (G_OBJECT (elem), "construct-only", NULL));
336   fail_unless (ctrl == NULL, NULL);
337
338   gst_object_unref (elem);
339 }
340
341 GST_END_TEST;
342
343
344 /* tests for an element with controlled params */
345 GST_START_TEST (controller_new_okay1)
346 {
347   GstController *ctrl;
348   GstElement *elem;
349
350   elem = gst_element_factory_make ("testmonosource", "test_source");
351
352   /* that property should exist and should be controllable */
353   ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
354   fail_unless (ctrl != NULL, NULL);
355
356   GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
357   g_object_unref (ctrl);
358   gst_object_unref (elem);
359 }
360
361 GST_END_TEST;
362
363 /* tests for an element with several controlled params */
364 GST_START_TEST (controller_new_okay2)
365 {
366   GstController *ctrl;
367   GstElement *elem;
368
369   elem = gst_element_factory_make ("testmonosource", "test_source");
370
371   /* that property should exist and should be controllable */
372   ctrl = gst_controller_new (G_OBJECT (elem), "ulong", "double", "float", NULL);
373   fail_unless (ctrl != NULL, NULL);
374
375   GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
376   g_object_unref (ctrl);
377   gst_object_unref (elem);
378 }
379
380 GST_END_TEST;
381
382 /* controlling several params should return the same controller */
383 GST_START_TEST (controller_new_okay3)
384 {
385   GstController *ctrl1, *ctrl2, *ctrl3;
386   GstElement *elem;
387
388   elem = gst_element_factory_make ("testmonosource", "test_source");
389
390   /* that property should exist and should be controllable */
391   ctrl1 = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
392   fail_unless (ctrl1 != NULL, NULL);
393
394   /* that property should exist and should be controllable */
395   ctrl2 = gst_controller_new (G_OBJECT (elem), "double", NULL);
396   fail_unless (ctrl2 != NULL, NULL);
397   fail_unless (ctrl1 == ctrl2, NULL);
398
399   /* that property should exist and should be controllable */
400   ctrl3 = gst_controller_new (G_OBJECT (elem), "float", NULL);
401   fail_unless (ctrl3 != NULL, NULL);
402   fail_unless (ctrl1 == ctrl3, NULL);
403
404   GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl1)->ref_count);
405   g_object_unref (ctrl1);
406   gst_object_unref (elem);
407 }
408
409 GST_END_TEST;
410
411 /* controlling a params twice should be handled */
412 GST_START_TEST (controller_param_twice)
413 {
414   GstController *ctrl;
415   GstElement *elem;
416   gboolean res;
417
418   elem = gst_element_factory_make ("testmonosource", "test_source");
419
420   /* that property should exist and should be controllable */
421   ctrl = gst_controller_new (G_OBJECT (elem), "ulong", "ulong", NULL);
422   fail_unless (ctrl != NULL, NULL);
423
424   /* it should have been added at least once, let remove it */
425   res = gst_controller_remove_properties (ctrl, "ulong", NULL);
426   fail_unless (res, NULL);
427
428   /* removing it agian should not work */
429   res = gst_controller_remove_properties (ctrl, "ulong", NULL);
430   fail_unless (!res, NULL);
431
432   GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
433   g_object_unref (ctrl);
434   gst_object_unref (elem);
435 }
436
437 GST_END_TEST;
438
439 /* tests if we cleanup properly */
440 GST_START_TEST (controller_finalize)
441 {
442   GstController *ctrl;
443   GstElement *elem;
444
445   elem = gst_element_factory_make ("testmonosource", "test_source");
446
447   /* that property should exist and should be controllable */
448   ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
449   fail_unless (ctrl != NULL, NULL);
450
451   /* free the controller */
452   g_object_unref (ctrl);
453
454   /* object shouldn't have a controller anymore */
455   ctrl = gst_object_get_controller (G_OBJECT (elem));
456   fail_unless (ctrl == NULL, NULL);
457
458   gst_object_unref (elem);
459 }
460
461 GST_END_TEST;
462
463 /* test timed value handling without interpolation */
464 GST_START_TEST (controller_interpolate_none)
465 {
466   GstController *ctrl;
467   GstElement *elem;
468   gboolean res;
469   GValue val_ulong = { 0, };
470
471   elem = gst_element_factory_make ("testmonosource", "test_source");
472
473   /* that property should exist and should be controllable */
474   ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
475   fail_unless (ctrl != NULL, NULL);
476
477   /* set interpolation mode */
478   gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_NONE);
479
480   /* set control values */
481   g_value_init (&val_ulong, G_TYPE_ULONG);
482   g_value_set_ulong (&val_ulong, 0);
483   res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
484   fail_unless (res, NULL);
485   g_value_set_ulong (&val_ulong, 100);
486   res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
487   fail_unless (res, NULL);
488
489   /* now pull in values for some timestamps */
490   gst_controller_sync_values (ctrl, 0 * GST_SECOND);
491   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
492   gst_controller_sync_values (ctrl, 1 * GST_SECOND);
493   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
494   gst_controller_sync_values (ctrl, 2 * GST_SECOND);
495   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
496
497   GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
498   g_object_unref (ctrl);
499   gst_object_unref (elem);
500 }
501
502 GST_END_TEST;
503
504 /* test timed value handling in trigger mode */
505 GST_START_TEST (controller_interpolate_trigger)
506 {
507   GstController *ctrl;
508   GstElement *elem;
509   gboolean res;
510   GValue val_ulong = { 0, };
511
512   elem = gst_element_factory_make ("testmonosource", "test_source");
513
514   /* that property should exist and should be controllable */
515   ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
516   fail_unless (ctrl != NULL, NULL);
517
518   /* set interpolation mode */
519   gst_controller_set_interpolation_mode (ctrl, "ulong",
520       GST_INTERPOLATE_TRIGGER);
521
522   /* set control values */
523   g_value_init (&val_ulong, G_TYPE_ULONG);
524   g_value_set_ulong (&val_ulong, 50);
525   res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
526   fail_unless (res, NULL);
527   g_value_set_ulong (&val_ulong, 100);
528   res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
529   fail_unless (res, NULL);
530
531   /* now pull in values for some timestamps */
532   gst_controller_sync_values (ctrl, 0 * GST_SECOND);
533   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
534   GST_TEST_MONO_SOURCE (elem)->val_ulong = 0;
535   gst_controller_sync_values (ctrl, 1 * GST_SECOND);
536   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
537   gst_controller_sync_values (ctrl, 2 * GST_SECOND);
538   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
539
540   GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
541   g_object_unref (ctrl);
542   gst_object_unref (elem);
543 }
544
545 GST_END_TEST;
546
547 /* test timed value handling with linear interpolation */
548 GST_START_TEST (controller_interpolate_linear)
549 {
550   GstController *ctrl;
551   GstElement *elem;
552   gboolean res;
553   GValue val_ulong = { 0, };
554
555   elem = gst_element_factory_make ("testmonosource", "test_source");
556
557   /* that property should exist and should be controllable */
558   ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
559   fail_unless (ctrl != NULL, NULL);
560
561   /* set interpolation mode */
562   gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_LINEAR);
563
564   /* set control values */
565   g_value_init (&val_ulong, G_TYPE_ULONG);
566   g_value_set_ulong (&val_ulong, 0);
567   res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
568   fail_unless (res, NULL);
569   g_value_set_ulong (&val_ulong, 100);
570   res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
571   fail_unless (res, NULL);
572
573   /* now pull in values for some timestamps */
574   gst_controller_sync_values (ctrl, 0 * GST_SECOND);
575   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
576   gst_controller_sync_values (ctrl, 1 * GST_SECOND);
577   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
578   gst_controller_sync_values (ctrl, 2 * GST_SECOND);
579   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
580
581   GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
582   g_object_unref (ctrl);
583   gst_object_unref (elem);
584 }
585
586 GST_END_TEST;
587
588 /* test _unset() */
589 GST_START_TEST (controller_unset)
590 {
591   GstController *ctrl;
592   GstElement *elem;
593   gboolean res;
594   GValue val_ulong = { 0, };
595
596   elem = gst_element_factory_make ("testmonosource", "test_source");
597
598   /* that property should exist and should be controllable */
599   ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
600   fail_unless (ctrl != NULL, NULL);
601
602   /* set interpolation mode */
603   gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_NONE);
604
605   /* set control values */
606   g_value_init (&val_ulong, G_TYPE_ULONG);
607   g_value_set_ulong (&val_ulong, 0);
608   res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
609   fail_unless (res, NULL);
610   g_value_set_ulong (&val_ulong, 100);
611   res = gst_controller_set (ctrl, "ulong", 1 * GST_SECOND, &val_ulong);
612   fail_unless (res, NULL);
613   g_value_set_ulong (&val_ulong, 50);
614   res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
615   fail_unless (res, NULL);
616
617   /* verify values */
618   gst_controller_sync_values (ctrl, 0 * GST_SECOND);
619   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
620   gst_controller_sync_values (ctrl, 1 * GST_SECOND);
621   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
622   gst_controller_sync_values (ctrl, 2 * GST_SECOND);
623   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
624
625   /* unset second */
626   res = gst_controller_unset (ctrl, "ulong", 1 * GST_SECOND);
627   fail_unless (res, NULL);
628
629   /* verify value again */
630   gst_controller_sync_values (ctrl, 1 * GST_SECOND);
631   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
632   gst_controller_sync_values (ctrl, 2 * GST_SECOND);
633   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
634
635   GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
636   g_object_unref (ctrl);
637   gst_object_unref (elem);
638 }
639
640 GST_END_TEST;
641
642 /* test _unset_all() */
643 GST_START_TEST (controller_unset_all)
644 {
645   GstController *ctrl;
646   GstElement *elem;
647   gboolean res;
648   GValue val_ulong = { 0, };
649
650   elem = gst_element_factory_make ("testmonosource", "test_source");
651
652   /* that property should exist and should be controllable */
653   ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
654   fail_unless (ctrl != NULL, NULL);
655
656   /* set interpolation mode */
657   gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_NONE);
658
659   /* set control values */
660   g_value_init (&val_ulong, G_TYPE_ULONG);
661   g_value_set_ulong (&val_ulong, 0);
662   res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
663   fail_unless (res, NULL);
664   g_value_set_ulong (&val_ulong, 100);
665   res = gst_controller_set (ctrl, "ulong", 1 * GST_SECOND, &val_ulong);
666   fail_unless (res, NULL);
667
668   /* verify values */
669   gst_controller_sync_values (ctrl, 0 * GST_SECOND);
670   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
671   gst_controller_sync_values (ctrl, 1 * GST_SECOND);
672   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
673
674   /* unset second */
675   res = gst_controller_unset_all (ctrl, "ulong");
676   fail_unless (res, NULL);
677
678   /* verify value again */
679   gst_controller_sync_values (ctrl, 1 * GST_SECOND);
680   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
681
682   GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
683   g_object_unref (ctrl);
684   gst_object_unref (elem);
685 }
686
687 GST_END_TEST;
688
689 /* test live value handling */
690 GST_START_TEST (controller_live)
691 {
692   GstController *ctrl;
693   GstElement *elem;
694   gboolean res;
695   GValue val_ulong = { 0, };
696
697   elem = gst_element_factory_make ("testmonosource", "test_source");
698
699   /* that property should exist and should be controllable */
700   ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
701   fail_unless (ctrl != NULL, NULL);
702
703   /* set interpolation mode */
704   gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_LINEAR);
705
706   /* set control values */
707   g_value_init (&val_ulong, G_TYPE_ULONG);
708   g_value_set_ulong (&val_ulong, 0);
709   res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
710   fail_unless (res, NULL);
711   g_value_set_ulong (&val_ulong, 100);
712   res = gst_controller_set (ctrl, "ulong", 4 * GST_SECOND, &val_ulong);
713   fail_unless (res, NULL);
714   g_value_set_ulong (&val_ulong, 200);
715   res = gst_controller_set (ctrl, "ulong", 8 * GST_SECOND, &val_ulong);
716   fail_unless (res, NULL);
717
718   /* verify value */
719   gst_controller_sync_values (ctrl, 2 * GST_SECOND);
720   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
721
722   /* set live value */
723   g_object_set (elem, "ulong", 500, NULL);
724
725   /* we should still get the live value */
726   gst_controller_sync_values (ctrl, 3 * GST_SECOND);
727   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 500, NULL);
728
729   /* we should not get the live value anymore */
730   gst_controller_sync_values (ctrl, 4 * GST_SECOND);
731   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
732   gst_controller_sync_values (ctrl, 6 * GST_SECOND);
733   fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 150, NULL);
734
735   GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
736   g_object_unref (ctrl);
737   gst_object_unref (elem);
738 }
739
740 GST_END_TEST;
741
742 /* tests if we can run helper methods against any GObject */
743 GST_START_TEST (controller_helper_any_gobject)
744 {
745   GstElement *elem;
746   gboolean res;
747
748   elem = gst_element_factory_make ("bin", "test_elem");
749
750   /* that element is not controllable */
751   res = gst_object_sync_values (G_OBJECT (elem), 0LL);
752   fail_unless (res == FALSE, NULL);
753
754   gst_object_unref (elem);
755 }
756
757 GST_END_TEST;
758
759
760 Suite *
761 gst_controller_suite (void)
762 {
763   Suite *s = suite_create ("Controller");
764   TCase *tc = tcase_create ("general");
765
766   suite_add_tcase (s, tc);
767   tcase_add_test (tc, controller_init);
768   tcase_add_test (tc, controller_new_fail1);
769   tcase_add_test (tc, controller_new_fail2);
770   tcase_add_test (tc, controller_new_fail3);
771   tcase_add_test (tc, controller_new_fail4);
772   tcase_add_test (tc, controller_new_fail5);
773   tcase_add_test (tc, controller_new_okay1);
774   tcase_add_test (tc, controller_new_okay2);
775   tcase_add_test (tc, controller_new_okay3);
776   tcase_add_test (tc, controller_param_twice);
777   tcase_add_test (tc, controller_finalize);
778   tcase_add_test (tc, controller_interpolate_none);
779   tcase_add_test (tc, controller_interpolate_trigger);
780   tcase_add_test (tc, controller_interpolate_linear);
781   tcase_add_test (tc, controller_unset);
782   tcase_add_test (tc, controller_unset_all);
783   tcase_add_test (tc, controller_live);
784   tcase_add_test (tc, controller_helper_any_gobject);
785
786   return s;
787 }
788
789 GST_CHECK_MAIN (gst_controller);