3 * unit test for the controller library
5 * Copyright (C) <2005> Stefan Kost <ensonic at users dot sf dor net>
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.
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.
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.
27 #include <gst/check/gstcheck.h>
28 #include <gst/controller/gstcontroller.h>
30 /* LOCAL TEST ELEMENT */
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))
51 typedef struct _GstTestMonoSource GstTestMonoSource;
52 typedef struct _GstTestMonoSourceClass GstTestMonoSourceClass;
54 struct _GstTestMonoSource
62 struct _GstTestMonoSourceClass
64 GstElementClass parent_class;
67 GType gst_test_mono_source_get_type (void);
70 gst_test_mono_source_get_property (GObject * object,
71 guint property_id, GValue * value, GParamSpec * pspec)
73 GstTestMonoSource *self = GST_TEST_MONO_SOURCE (object);
75 switch (property_id) {
77 g_value_set_ulong (value, self->val_ulong);
80 g_value_set_float (value, self->val_float);
83 g_value_set_double (value, self->val_double);
86 g_value_set_boolean (value, self->val_boolean);
89 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
95 gst_test_mono_source_set_property (GObject * object,
96 guint property_id, const GValue * value, GParamSpec * pspec)
98 GstTestMonoSource *self = GST_TEST_MONO_SOURCE (object);
100 switch (property_id) {
102 self->val_ulong = g_value_get_ulong (value);
105 self->val_float = g_value_get_float (value);
108 self->val_double = g_value_get_double (value);
111 self->val_boolean = g_value_get_boolean (value);
113 case ARG_CONSTRUCTONLY:
116 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
122 gst_test_mono_source_class_init (GstTestMonoSourceClass * klass)
124 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
126 gobject_class->set_property = gst_test_mono_source_set_property;
127 gobject_class->get_property = gst_test_mono_source_get_property;
129 g_object_class_install_property (gobject_class, ARG_ULONG,
130 g_param_spec_ulong ("ulong",
132 "ulong number parameter for the test_mono_source",
133 0, G_MAXULONG, 0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
135 g_object_class_install_property (gobject_class, ARG_FLOAT,
136 g_param_spec_float ("float",
138 "float number parameter for the test_mono_source",
139 0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
141 g_object_class_install_property (gobject_class, ARG_DOUBLE,
142 g_param_spec_double ("double",
144 "double number parameter for the test_mono_source",
145 0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
147 g_object_class_install_property (gobject_class, ARG_BOOLEAN,
148 g_param_spec_boolean ("boolean",
150 "boolean parameter for the test_mono_source",
151 FALSE, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
153 g_object_class_install_property (gobject_class, ARG_READONLY,
154 g_param_spec_ulong ("readonly",
156 "readonly parameter for the test_mono_source",
157 0, G_MAXULONG, 0, G_PARAM_READABLE | GST_PARAM_CONTROLLABLE));
159 g_object_class_install_property (gobject_class, ARG_STATIC,
160 g_param_spec_ulong ("static",
162 "static parameter for the test_mono_source",
163 0, G_MAXULONG, 0, G_PARAM_READWRITE));
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));
173 gst_test_mono_source_base_init (GstTestMonoSourceClass * klass)
175 static const GstElementDetails details = {
176 "Monophonic source for unit tests",
177 "Source/Audio/MonoSource",
179 "Stefan Kost <ensonic@users.sf.net>"
181 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
183 gst_element_class_set_details (element_class, &details);
187 gst_test_mono_source_get_type (void)
189 static GType 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
199 (guint16) sizeof (GstTestMonoSource),
201 NULL, // instance_init
205 g_type_register_static (GST_TYPE_ELEMENT, "GstTestMonoSource", &info,
212 plugin_init (GstPlugin * plugin)
216 res &= gst_element_register (plugin, "testmonosource", GST_RANK_NONE,
217 GST_TYPE_TEST_MONO_SOURCE);
221 GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR,
224 "controller test plugin - several unit test support elements",
225 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
228 static void __attribute__ ((constructor))
229 _gst_plugin_static_init__plugin_init (void)
231 static GstPluginDesc plugin_desc_ = {
235 "controller test plugin - several unit test support elements",
244 _gst_plugin_register_static (&plugin_desc_);
248 /* double init should not harm */
249 GST_START_TEST (controller_init)
251 gst_controller_init (NULL, NULL);
252 gst_controller_init (NULL, NULL);
253 gst_controller_init (NULL, NULL);
254 gst_controller_init (NULL, NULL);
259 /* tests for an element with no controlled params */
260 GST_START_TEST (controller_new_fail1)
265 gst_controller_init (NULL, NULL);
267 elem = gst_element_factory_make ("fakesrc", "test_source");
269 /* that property should not exist */
270 ctrl = gst_controller_new (G_OBJECT (elem), "_schrompf_", NULL);
271 fail_unless (ctrl == NULL, NULL);
273 gst_object_unref (elem);
278 /* tests for an element with controlled params, but none given */
279 GST_START_TEST (controller_new_fail2)
284 gst_controller_init (NULL, NULL);
286 elem = gst_element_factory_make ("testmonosource", "test_source");
288 /* no property given */
289 ctrl = gst_controller_new (G_OBJECT (elem), NULL);
290 fail_unless (ctrl == NULL, NULL);
292 gst_object_unref (elem);
297 /* tests for readonly params */
298 GST_START_TEST (controller_new_fail3)
303 gst_controller_init (NULL, NULL);
305 elem = gst_element_factory_make ("testmonosource", "test_source");
307 /* that property should exist and but is readonly */
308 ASSERT_CRITICAL (ctrl =
309 gst_controller_new (G_OBJECT (elem), "readonly", NULL));
310 fail_unless (ctrl == NULL, NULL);
312 gst_object_unref (elem);
317 /* tests for static params */
318 GST_START_TEST (controller_new_fail4)
323 gst_controller_init (NULL, NULL);
325 elem = gst_element_factory_make ("testmonosource", "test_source");
327 /* that property should exist and but is not controlable */
328 ASSERT_CRITICAL (ctrl = gst_controller_new (G_OBJECT (elem), "static", NULL));
329 fail_unless (ctrl == NULL, NULL);
331 gst_object_unref (elem);
336 /* tests for static params */
337 GST_START_TEST (controller_new_fail5)
342 gst_controller_init (NULL, NULL);
344 elem = gst_element_factory_make ("testmonosource", "test_source");
346 /* that property should exist and but is construct-only */
347 ASSERT_CRITICAL (ctrl =
348 gst_controller_new (G_OBJECT (elem), "construct-only", NULL));
349 fail_unless (ctrl == NULL, NULL);
351 gst_object_unref (elem);
357 /* tests for an element with controlled params */
358 GST_START_TEST (controller_new_okay1)
363 gst_controller_init (NULL, NULL);
365 elem = gst_element_factory_make ("testmonosource", "test_source");
367 /* that property should exist and should be controllable */
368 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
369 fail_unless (ctrl != NULL, NULL);
371 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
372 g_object_unref (ctrl);
373 gst_object_unref (elem);
378 /* tests for an element with several controlled params */
379 GST_START_TEST (controller_new_okay2)
381 GstController *ctrl, *ctrl2, *ctrl3;
384 gst_controller_init (NULL, NULL);
386 elem = gst_element_factory_make ("testmonosource", "test_source");
388 /* that property should exist and should be controllable */
389 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", "double", "float", NULL);
390 fail_unless (ctrl != NULL, NULL);
392 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
393 fail_unless (G_OBJECT (ctrl)->ref_count == 1);
395 ctrl2 = gst_controller_new (G_OBJECT (elem), "boolean", NULL);
396 fail_unless (ctrl2 != NULL, NULL);
397 fail_unless (ctrl2 == ctrl, NULL);
399 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
400 fail_unless (G_OBJECT (ctrl)->ref_count == 2);
402 /* trying to control the same properties again should correctly
403 * increase the refcount of the object returned as well */
405 gst_controller_new (G_OBJECT (elem), "ulong", "double", "float", NULL);
406 fail_unless (ctrl3 != NULL, NULL);
407 fail_unless (ctrl3 == ctrl, NULL);
409 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
410 fail_unless (G_OBJECT (ctrl)->ref_count == 3);
412 g_object_unref (ctrl);
413 g_object_unref (ctrl2);
414 g_object_unref (ctrl3);
415 gst_object_unref (elem);
420 /* controlling several params should return the same controller */
421 GST_START_TEST (controller_new_okay3)
423 GstController *ctrl1, *ctrl2, *ctrl3;
426 gst_controller_init (NULL, NULL);
428 elem = gst_element_factory_make ("testmonosource", "test_source");
430 /* that property should exist and should be controllable */
431 ctrl1 = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
432 fail_unless (ctrl1 != NULL, NULL);
434 /* that property should exist and should be controllable */
435 ctrl2 = gst_controller_new (G_OBJECT (elem), "double", NULL);
436 fail_unless (ctrl2 != NULL, NULL);
437 fail_unless (ctrl1 == ctrl2, NULL);
439 /* that property should exist and should be controllable */
440 ctrl3 = gst_controller_new (G_OBJECT (elem), "float", NULL);
441 fail_unless (ctrl3 != NULL, NULL);
442 fail_unless (ctrl1 == ctrl3, NULL);
444 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl1)->ref_count);
445 fail_unless (G_OBJECT (ctrl1)->ref_count == 3);
446 g_object_unref (ctrl1);
447 g_object_unref (ctrl2);
448 g_object_unref (ctrl3);
449 gst_object_unref (elem);
454 /* controlling a params twice should be handled */
455 GST_START_TEST (controller_param_twice)
461 gst_controller_init (NULL, NULL);
463 elem = gst_element_factory_make ("testmonosource", "test_source");
465 /* that property should exist and should be controllable */
466 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", "ulong", NULL);
467 fail_unless (ctrl != NULL, NULL);
469 /* it should have been added at least once, let remove it */
470 res = gst_controller_remove_properties (ctrl, "ulong", NULL);
471 fail_unless (res, NULL);
473 /* removing it agian should not work */
474 res = gst_controller_remove_properties (ctrl, "ulong", NULL);
475 fail_unless (!res, NULL);
477 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
478 g_object_unref (ctrl);
479 gst_object_unref (elem);
484 /* tests if we cleanup properly */
485 GST_START_TEST (controller_finalize)
490 gst_controller_init (NULL, NULL);
492 elem = gst_element_factory_make ("testmonosource", "test_source");
494 /* that property should exist and should be controllable */
495 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
496 fail_unless (ctrl != NULL, NULL);
498 /* free the controller */
499 g_object_unref (ctrl);
501 /* object shouldn't have a controller anymore */
502 ctrl = gst_object_get_controller (G_OBJECT (elem));
503 fail_unless (ctrl == NULL, NULL);
505 gst_object_unref (elem);
510 /* test timed value handling without interpolation */
511 GST_START_TEST (controller_interpolate_none)
516 GValue val_ulong = { 0, };
518 gst_controller_init (NULL, NULL);
520 elem = gst_element_factory_make ("testmonosource", "test_source");
522 /* that property should exist and should be controllable */
523 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
524 fail_unless (ctrl != NULL, NULL);
526 /* set interpolation mode */
527 gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_NONE);
529 /* set control values */
530 g_value_init (&val_ulong, G_TYPE_ULONG);
531 g_value_set_ulong (&val_ulong, 0);
532 res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
533 fail_unless (res, NULL);
534 g_value_set_ulong (&val_ulong, 100);
535 res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
536 fail_unless (res, NULL);
538 /* now pull in values for some timestamps */
539 gst_controller_sync_values (ctrl, 0 * GST_SECOND);
540 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
541 gst_controller_sync_values (ctrl, 1 * GST_SECOND);
542 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
543 gst_controller_sync_values (ctrl, 2 * GST_SECOND);
544 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
546 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
547 g_object_unref (ctrl);
548 gst_object_unref (elem);
553 /* test timed value handling in trigger mode */
554 GST_START_TEST (controller_interpolate_trigger)
559 GValue val_ulong = { 0, };
561 gst_controller_init (NULL, NULL);
563 elem = gst_element_factory_make ("testmonosource", "test_source");
565 /* that property should exist and should be controllable */
566 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
567 fail_unless (ctrl != NULL, NULL);
569 /* set interpolation mode */
570 gst_controller_set_interpolation_mode (ctrl, "ulong",
571 GST_INTERPOLATE_TRIGGER);
573 /* set control values */
574 g_value_init (&val_ulong, G_TYPE_ULONG);
575 g_value_set_ulong (&val_ulong, 50);
576 res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
577 fail_unless (res, NULL);
578 g_value_set_ulong (&val_ulong, 100);
579 res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
580 fail_unless (res, NULL);
582 /* now pull in values for some timestamps */
583 gst_controller_sync_values (ctrl, 0 * GST_SECOND);
584 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
585 GST_TEST_MONO_SOURCE (elem)->val_ulong = 0;
586 gst_controller_sync_values (ctrl, 1 * GST_SECOND);
587 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
588 gst_controller_sync_values (ctrl, 2 * GST_SECOND);
589 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
591 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
592 g_object_unref (ctrl);
593 gst_object_unref (elem);
598 /* test timed value handling with linear interpolation */
599 GST_START_TEST (controller_interpolate_linear)
604 GValue val_ulong = { 0, };
606 gst_controller_init (NULL, NULL);
608 elem = gst_element_factory_make ("testmonosource", "test_source");
610 /* that property should exist and should be controllable */
611 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
612 fail_unless (ctrl != NULL, NULL);
614 /* set interpolation mode */
615 gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_LINEAR);
617 /* set control values */
618 g_value_init (&val_ulong, G_TYPE_ULONG);
619 g_value_set_ulong (&val_ulong, 0);
620 res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
621 fail_unless (res, NULL);
622 g_value_set_ulong (&val_ulong, 100);
623 res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
624 fail_unless (res, NULL);
626 /* now pull in values for some timestamps */
627 gst_controller_sync_values (ctrl, 0 * GST_SECOND);
628 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
629 gst_controller_sync_values (ctrl, 1 * GST_SECOND);
630 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
631 gst_controller_sync_values (ctrl, 2 * GST_SECOND);
632 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
634 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
635 g_object_unref (ctrl);
636 gst_object_unref (elem);
641 /* make sure we don't crash when someone sets an unsupported interpolation
643 GST_START_TEST (controller_interpolate_unimplemented)
648 gst_controller_init (NULL, NULL);
650 elem = gst_element_factory_make ("testmonosource", "test_source");
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);
656 /* set unsupported interpolation mode */
657 gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_CUBIC);
659 /* set another unsupported interpolation mode */
660 gst_controller_set_interpolation_mode (ctrl, "ulong",
661 GST_INTERPOLATE_QUADRATIC);
663 /* set completely bogus interpolation mode */
664 gst_controller_set_interpolation_mode (ctrl, "ulong",
665 (GstInterpolateMode) 93871);
667 g_object_unref (ctrl);
668 gst_object_unref (elem);
674 GST_START_TEST (controller_unset)
679 GValue val_ulong = { 0, };
681 gst_controller_init (NULL, NULL);
683 elem = gst_element_factory_make ("testmonosource", "test_source");
685 /* that property should exist and should be controllable */
686 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
687 fail_unless (ctrl != NULL, NULL);
689 /* set interpolation mode */
690 gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_NONE);
692 /* set control values */
693 g_value_init (&val_ulong, G_TYPE_ULONG);
694 g_value_set_ulong (&val_ulong, 0);
695 res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
696 fail_unless (res, NULL);
697 g_value_set_ulong (&val_ulong, 100);
698 res = gst_controller_set (ctrl, "ulong", 1 * GST_SECOND, &val_ulong);
699 fail_unless (res, NULL);
700 g_value_set_ulong (&val_ulong, 50);
701 res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
702 fail_unless (res, NULL);
705 gst_controller_sync_values (ctrl, 0 * GST_SECOND);
706 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
707 gst_controller_sync_values (ctrl, 1 * GST_SECOND);
708 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
709 gst_controller_sync_values (ctrl, 2 * GST_SECOND);
710 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
713 res = gst_controller_unset (ctrl, "ulong", 1 * GST_SECOND);
714 fail_unless (res, NULL);
716 /* verify value again */
717 gst_controller_sync_values (ctrl, 1 * GST_SECOND);
718 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
719 gst_controller_sync_values (ctrl, 2 * GST_SECOND);
720 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
722 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
723 g_object_unref (ctrl);
724 gst_object_unref (elem);
729 /* test _unset_all() */
730 GST_START_TEST (controller_unset_all)
735 GValue val_ulong = { 0, };
737 gst_controller_init (NULL, NULL);
739 elem = gst_element_factory_make ("testmonosource", "test_source");
741 /* that property should exist and should be controllable */
742 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
743 fail_unless (ctrl != NULL, NULL);
745 /* set interpolation mode */
746 gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_NONE);
748 /* set control values */
749 g_value_init (&val_ulong, G_TYPE_ULONG);
750 g_value_set_ulong (&val_ulong, 0);
751 res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
752 fail_unless (res, NULL);
753 g_value_set_ulong (&val_ulong, 100);
754 res = gst_controller_set (ctrl, "ulong", 1 * GST_SECOND, &val_ulong);
755 fail_unless (res, NULL);
758 gst_controller_sync_values (ctrl, 0 * GST_SECOND);
759 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
760 gst_controller_sync_values (ctrl, 1 * GST_SECOND);
761 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
764 res = gst_controller_unset_all (ctrl, "ulong");
765 fail_unless (res, NULL);
767 /* verify value again */
768 gst_controller_sync_values (ctrl, 1 * GST_SECOND);
769 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL);
771 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
772 g_object_unref (ctrl);
773 gst_object_unref (elem);
778 /* test live value handling */
779 GST_START_TEST (controller_live)
784 GValue val_ulong = { 0, };
786 gst_controller_init (NULL, NULL);
788 elem = gst_element_factory_make ("testmonosource", "test_source");
790 /* that property should exist and should be controllable */
791 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
792 fail_unless (ctrl != NULL, NULL);
794 /* set interpolation mode */
795 gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_LINEAR);
797 /* set control values */
798 g_value_init (&val_ulong, G_TYPE_ULONG);
799 g_value_set_ulong (&val_ulong, 0);
800 res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
801 fail_unless (res, NULL);
802 g_value_set_ulong (&val_ulong, 100);
803 res = gst_controller_set (ctrl, "ulong", 4 * GST_SECOND, &val_ulong);
804 fail_unless (res, NULL);
805 g_value_set_ulong (&val_ulong, 200);
806 res = gst_controller_set (ctrl, "ulong", 8 * GST_SECOND, &val_ulong);
807 fail_unless (res, NULL);
810 gst_controller_sync_values (ctrl, 2 * GST_SECOND);
811 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL);
814 g_object_set (elem, "ulong", 500, NULL);
816 /* we should still get the live value */
817 gst_controller_sync_values (ctrl, 3 * GST_SECOND);
818 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 500, NULL);
820 /* we should not get the live value anymore */
821 gst_controller_sync_values (ctrl, 4 * GST_SECOND);
822 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL);
823 gst_controller_sync_values (ctrl, 6 * GST_SECOND);
824 fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 150, NULL);
826 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
827 g_object_unref (ctrl);
828 gst_object_unref (elem);
833 /* tests if we can run helper methods against any GObject */
834 GST_START_TEST (controller_helper_any_gobject)
839 gst_controller_init (NULL, NULL);
841 elem = gst_element_factory_make ("bin", "test_elem");
843 /* that element is not controllable */
844 res = gst_object_sync_values (G_OBJECT (elem), 0LL);
845 fail_unless (res == FALSE, NULL);
847 gst_object_unref (elem);
852 GST_START_TEST (controller_misc)
859 gst_controller_init (NULL, NULL);
861 /* test that an invalid timestamp throws a warning of some sort */
862 elem = gst_element_factory_make ("testmonosource", "test_source");
864 /* that property should exist and should be controllable */
865 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
866 fail_unless (ctrl != NULL, NULL);
868 /* set interpolation mode */
869 gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_LINEAR);
871 /* set control value */
872 tval = g_new0 (GstTimedValue, 1);
873 tval->timestamp = GST_CLOCK_TIME_NONE;
874 g_value_init (&tval->value, G_TYPE_ULONG);
875 g_value_set_ulong (&tval->value, 0);
877 list = g_slist_append (list, tval);
879 ASSERT_WARNING (fail_if (gst_controller_set_from_list (ctrl, "ulong", list)));
881 /* try again with a valid stamp, should work now */
883 fail_unless (gst_controller_set_from_list (ctrl, "ulong", list));
885 /* allocated GstTimedValue now belongs to the controller, but list not */
886 g_value_unset (&tval->value);
889 g_object_unref (ctrl);
890 gst_object_unref (elem);
895 GST_START_TEST (controller_refcount_new_list)
897 GstController *ctrl, *ctrl2;
901 gst_controller_init (NULL, NULL);
903 /* that property should exist and should be controllable */
904 elem = gst_element_factory_make ("testmonosource", "test_source");
905 list = g_list_append (NULL, "ulong");
906 ctrl = gst_controller_new_list (G_OBJECT (elem), list);
907 fail_unless (ctrl != NULL, NULL);
908 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
909 fail_unless (G_OBJECT (ctrl)->ref_count == 1);
911 g_object_unref (ctrl);
912 gst_object_unref (elem);
914 /* try the same property twice, make sure the refcount is still 1 */
915 elem = gst_element_factory_make ("testmonosource", "test_source");
916 list = g_list_append (NULL, "ulong");
917 list = g_list_append (list, "ulong");
918 ctrl = gst_controller_new_list (G_OBJECT (elem), list);
919 fail_unless (ctrl != NULL, NULL);
920 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
921 fail_unless (G_OBJECT (ctrl)->ref_count == 1);
923 g_object_unref (ctrl);
924 gst_object_unref (elem);
926 /* try two properties, make sure the refcount is still 1 */
927 elem = gst_element_factory_make ("testmonosource", "test_source");
928 list = g_list_append (NULL, "ulong");
929 list = g_list_append (list, "boolean");
930 ctrl = gst_controller_new_list (G_OBJECT (elem), list);
931 fail_unless (ctrl != NULL, NULL);
932 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
933 fail_unless (G_OBJECT (ctrl)->ref_count == 1);
935 g_object_unref (ctrl);
936 gst_object_unref (elem);
938 /* try _new_list with existing controller */
939 elem = gst_element_factory_make ("testmonosource", "test_source");
940 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
941 fail_unless (ctrl != NULL, NULL);
942 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
943 list = g_list_append (NULL, "ulong");
944 ctrl2 = gst_controller_new_list (G_OBJECT (elem), list);
945 fail_unless (ctrl2 != NULL, NULL);
946 fail_unless (ctrl == ctrl2, NULL);
947 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
948 fail_unless (G_OBJECT (ctrl)->ref_count == 2);
950 g_object_unref (ctrl);
951 g_object_unref (ctrl2);
952 gst_object_unref (elem);
954 /* try _new_list first and then _new */
955 elem = gst_element_factory_make ("testmonosource", "test_source");
956 list = g_list_append (NULL, "ulong");
957 ctrl = gst_controller_new_list (G_OBJECT (elem), list);
958 fail_unless (ctrl != NULL, NULL);
959 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
960 ctrl2 = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
961 fail_unless (ctrl2 != NULL, NULL);
962 fail_unless (ctrl == ctrl2, NULL);
963 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
964 fail_unless (G_OBJECT (ctrl)->ref_count == 2);
966 g_object_unref (ctrl);
967 g_object_unref (ctrl2);
968 gst_object_unref (elem);
974 /* test retrieval of an array of values with get_value_array() */
975 GST_START_TEST (controller_interpolate_linear_value_array)
980 GValue val_ulong = { 0, };
981 GstValueArray values = { 0, };
983 gst_controller_init (NULL, NULL);
985 elem = gst_element_factory_make ("testmonosource", "test_source");
987 /* that property should exist and should be controllable */
988 ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL);
989 fail_unless (ctrl != NULL, NULL);
991 /* set interpolation mode */
992 gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_LINEAR);
994 /* set control values */
995 g_value_init (&val_ulong, G_TYPE_ULONG);
996 g_value_set_ulong (&val_ulong, 0);
997 res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong);
998 fail_unless (res, NULL);
999 g_value_set_ulong (&val_ulong, 100);
1000 res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong);
1001 fail_unless (res, NULL);
1003 /* now pull in values for some timestamps */
1004 values.property_name = "ulong";
1005 values.nbsamples = 3;
1006 values.sample_interval = GST_SECOND;
1007 values.values = (gpointer) g_new (gulong, 3);
1009 fail_unless (gst_controller_get_value_array (ctrl, 0, &values));
1010 fail_unless_equals_int (((gulong *) values.values)[0], 0);
1011 fail_unless_equals_int (((gulong *) values.values)[1], 50);
1012 fail_unless_equals_int (((gulong *) values.values)[2], 100);
1014 GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count);
1015 g_free (values.values);
1016 g_object_unref (ctrl);
1017 gst_object_unref (elem);
1023 gst_controller_suite (void)
1025 Suite *s = suite_create ("Controller");
1026 TCase *tc = tcase_create ("general");
1028 suite_add_tcase (s, tc);
1029 tcase_add_test (tc, controller_init);
1030 tcase_add_test (tc, controller_refcount_new_list);
1031 tcase_add_test (tc, controller_new_fail1);
1032 tcase_add_test (tc, controller_new_fail2);
1033 tcase_add_test (tc, controller_new_fail3);
1034 tcase_add_test (tc, controller_new_fail4);
1035 tcase_add_test (tc, controller_new_fail5);
1036 tcase_add_test (tc, controller_new_okay1);
1037 tcase_add_test (tc, controller_new_okay2);
1038 tcase_add_test (tc, controller_new_okay3);
1039 tcase_add_test (tc, controller_param_twice);
1040 tcase_add_test (tc, controller_finalize);
1041 tcase_add_test (tc, controller_interpolate_none);
1042 tcase_add_test (tc, controller_interpolate_trigger);
1043 tcase_add_test (tc, controller_interpolate_linear);
1044 tcase_add_test (tc, controller_interpolate_unimplemented);
1045 tcase_add_test (tc, controller_unset);
1046 tcase_add_test (tc, controller_unset_all);
1047 tcase_add_test (tc, controller_live);
1048 tcase_add_test (tc, controller_helper_any_gobject);
1049 tcase_add_test (tc, controller_misc);
1050 tcase_add_test (tc, controller_interpolate_linear_value_array);
1055 GST_CHECK_MAIN (gst_controller);