caps: improve _do_simplify
[platform/upstream/gstreamer.git] / tests / check / gst / gstparamspecs.c
1 /* GStreamer GstParamSpec unit tests
2  * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gst/check/gstcheck.h>
21 #include <gst/gst.h>
22 #include <string.h>
23
24 /* some minimal dummy object */
25 #define GST_TYPE_DUMMY_OBJ gst_dummy_obj_get_type()
26
27 typedef struct
28 {
29   GstElement parent;
30   guint num, denom;
31 } GstDummyObj;
32
33 typedef GstElementClass GstDummyObjClass;
34
35 GType gst_dummy_obj_get_type (void);
36 G_DEFINE_TYPE (GstDummyObj, gst_dummy_obj, GST_TYPE_ELEMENT);
37
38 static void
39 gst_dummy_obj_get_property (GObject * obj, guint prop_id, GValue * val,
40     GParamSpec * pspec);
41 static void
42 gst_dummy_obj_set_property (GObject * obj, guint prop_id, const GValue * val,
43     GParamSpec * pspec);
44
45 static void
46 gst_dummy_obj_class_init (GstDummyObjClass * klass)
47 {
48   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
49
50   gobject_class->get_property = gst_dummy_obj_get_property;
51   gobject_class->set_property = gst_dummy_obj_set_property;
52
53   ASSERT_CRITICAL (
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)););
58
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));
63
64   g_object_class_install_property (gobject_class, 3,
65       g_param_spec_boolean ("foo", "foo", "foo", TRUE, G_PARAM_READWRITE));
66 }
67
68 static void
69 gst_dummy_obj_init (GstDummyObj * obj)
70 {
71   /* nothing to do there */
72 }
73
74 static void
75 gst_dummy_obj_set_property (GObject * obj, guint prop_id, const GValue * val,
76     GParamSpec * pspec)
77 {
78   GstDummyObj *dobj = (GstDummyObj *) obj;
79
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);
83 }
84
85 static void
86 gst_dummy_obj_get_property (GObject * obj, guint prop_id, GValue * val,
87     GParamSpec * pspec)
88 {
89   GstDummyObj *dobj = (GstDummyObj *) obj;
90
91   fail_unless_equals_int (prop_id, 2);
92   gst_value_set_fraction (val, dobj->num, dobj->denom);
93 }
94
95 GST_START_TEST (test_param_spec_fraction)
96 {
97   GObject *obj;
98   GValue val = { 0, };
99   gint n = 0, d = 0;
100
101   obj = g_object_new (GST_TYPE_DUMMY_OBJ, "other-ratio", 15, 8, NULL);
102
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);
108
109   g_object_get (obj, "other-ratio", &n, &d, NULL);
110   fail_unless_equals_int (n, 15);
111   fail_unless_equals_int (d, 8);
112
113   g_object_unref (obj);
114 }
115
116 GST_END_TEST static Suite *
117 gst_param_spec_suite (void)
118 {
119   Suite *s = suite_create ("GstParamSpec");
120   TCase *tc_chain = tcase_create ("general");
121
122   suite_add_tcase (s, tc_chain);
123   tcase_add_test (tc_chain, test_param_spec_fraction);
124
125   return s;
126 }
127
128 GST_CHECK_MAIN (gst_param_spec);