1 /* GStreamer GstParamSpec unit tests
2 * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
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.
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.
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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include <gst/check/gstcheck.h>
24 /* some minimal dummy object */
25 #define GST_TYPE_DUMMY_OBJ gst_dummy_obj_get_type()
33 typedef GstElementClass GstDummyObjClass;
35 GType gst_dummy_obj_get_type (void);
36 G_DEFINE_TYPE (GstDummyObj, gst_dummy_obj, GST_TYPE_ELEMENT);
39 gst_dummy_obj_get_property (GObject * obj, guint prop_id, GValue * val,
42 gst_dummy_obj_set_property (GObject * obj, guint prop_id, const GValue * val,
46 gst_dummy_obj_class_init (GstDummyObjClass * klass)
48 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
50 gobject_class->get_property = gst_dummy_obj_get_property;
51 gobject_class->set_property = gst_dummy_obj_set_property;
54 /* default value is out of bounds, should print a warning */
55 g_object_class_install_property (gobject_class, 1,
56 gst_param_spec_fraction ("ratio", "ratio", "ratio", 0, 1, 2, 1,
57 16, 4, G_PARAM_READWRITE)););
59 /* should be within bounds */
60 g_object_class_install_property (gobject_class, 2,
61 gst_param_spec_fraction ("other-ratio", "other ratio", "other ratio",
62 0, 1, 2, 1, 16, 9, G_PARAM_READWRITE));
64 g_object_class_install_property (gobject_class, 3,
65 g_param_spec_boolean ("foo", "foo", "foo", TRUE, G_PARAM_READWRITE));
69 gst_dummy_obj_init (GstDummyObj * obj)
71 /* nothing to do there */
75 gst_dummy_obj_set_property (GObject * obj, guint prop_id, const GValue * val,
78 GstDummyObj *dobj = (GstDummyObj *) obj;
80 fail_unless_equals_int (prop_id, 2);
81 dobj->num = gst_value_get_fraction_numerator (val);
82 dobj->denom = gst_value_get_fraction_denominator (val);
86 gst_dummy_obj_get_property (GObject * obj, guint prop_id, GValue * val,
89 GstDummyObj *dobj = (GstDummyObj *) obj;
91 fail_unless_equals_int (prop_id, 2);
92 gst_value_set_fraction (val, dobj->num, dobj->denom);
95 GST_START_TEST (test_param_spec_fraction)
101 obj = g_object_new (GST_TYPE_DUMMY_OBJ, "other-ratio", 15, 8, NULL);
103 g_value_init (&val, GST_TYPE_FRACTION);
104 g_object_get_property (G_OBJECT (obj), "other-ratio", &val);
105 fail_unless_equals_int (gst_value_get_fraction_numerator (&val), 15);
106 fail_unless_equals_int (gst_value_get_fraction_denominator (&val), 8);
107 g_value_unset (&val);
109 g_object_get (obj, "other-ratio", &n, &d, NULL);
110 fail_unless_equals_int (n, 15);
111 fail_unless_equals_int (d, 8);
113 g_object_unref (obj);
116 GST_END_TEST static Suite *
117 gst_param_spec_suite (void)
119 Suite *s = suite_create ("GstParamSpec");
120 TCase *tc_chain = tcase_create ("general");
122 suite_add_tcase (s, tc_chain);
123 tcase_add_test (tc_chain, test_param_spec_fraction);
128 GST_CHECK_MAIN (gst_param_spec);