2 * Copyright (C) 2008 Nokia Corporation and its subsidary(-ies)
3 * contact: <stefan.kost@nokia.com>
5 * gstpreset.c: Unit test for GstPreset
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.
28 #include <glib/gstdio.h>
29 #include <gst/check/gstcheck.h>
33 static GType gst_preset_test_get_type (void);
35 #define GST_TYPE_PRESET_TEST (gst_preset_test_get_type ())
36 #define GST_PRESET_TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PRESET_TEST, GstPresetTest))
37 #define GST_PRESET_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PRESET_TEST, GstPresetTestClass))
38 #define GST_IS_PRESET_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PRESET_TEST))
39 #define GST_IS_PRESET_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PRESET_TEST))
40 #define GST_PRESET_TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PRESET_TEST, GstPresetTestClass))
41 #define GST_PRESET_TEST_NAME "preset-test"
48 typedef struct _GstPresetTest
55 typedef struct _GstPresetTestClass
57 GstElementClass parent_class;
61 gst_preset_test_get_property (GObject * object, guint property_id,
62 GValue * value, GParamSpec * pspec)
64 GstPresetTest *self = GST_PRESET_TEST (object);
66 switch (property_id) {
68 g_value_set_int (value, self->test);
71 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
77 gst_preset_test_set_property (GObject * object, guint property_id,
78 const GValue * value, GParamSpec * pspec)
80 GstPresetTest *self = GST_PRESET_TEST (object);
82 switch (property_id) {
84 self->test = g_value_get_int (value);
90 gst_preset_test_class_init (GObjectClass * klass)
92 klass->set_property = gst_preset_test_set_property;
93 klass->get_property = gst_preset_test_get_property;
95 g_object_class_install_property (klass, PROP_TEST,
96 g_param_spec_int ("test",
98 "test parameter for preset test",
99 G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
103 gst_preset_test_base_init (GstPresetTestClass * klass)
105 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
107 gst_element_class_set_details_simple (element_class,
108 "Element for unit tests",
109 "Testing", "Use in unit tests", "Stefan Kost <stefan.kost@nokia.com>");
113 gst_preset_test_get_type (void)
115 static volatile gsize preset_test_type = 0;
117 if (g_once_init_enter (&preset_test_type)) {
119 const GTypeInfo info = {
120 sizeof (GstPresetTestClass),
121 (GBaseInitFunc) gst_preset_test_base_init, /* base_init */
122 NULL, /* base_finalize */
123 (GClassInitFunc) gst_preset_test_class_init, /* class_init */
124 NULL, /* class_finalize */
125 NULL, /* class_data */
126 sizeof (GstPresetTest),
128 NULL, /* instance_init */
129 NULL /* value_table */
131 const GInterfaceInfo preset_interface_info = {
132 NULL, /* interface_init */
133 NULL, /* interface_finalize */
134 NULL /* interface_data */
136 type = g_type_register_static (GST_TYPE_ELEMENT, "GstPresetTest", &info, 0);
137 g_type_add_interface_static (type, GST_TYPE_PRESET, &preset_interface_info);
138 g_once_init_leave (&preset_test_type, type);
140 return preset_test_type;
144 gst_preset_test_plugin_init (GstPlugin * plugin)
146 gst_element_register (plugin, GST_PRESET_TEST_NAME, GST_RANK_NONE,
147 GST_TYPE_PRESET_TEST);
152 GST_START_TEST (test_check)
156 elem = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
157 fail_unless (GST_IS_PRESET (elem));
159 gst_object_unref (elem);
164 GST_START_TEST (test_load)
169 elem = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
170 res = gst_preset_load_preset (GST_PRESET (elem), "does-not-exist");
173 gst_object_unref (elem);
178 GST_START_TEST (test_add)
184 elem = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
185 g_object_set (elem, "test", 5, NULL);
187 res = gst_preset_save_preset (GST_PRESET (elem), "test");
190 res = gst_preset_load_preset (GST_PRESET (elem), "test");
192 g_object_get (elem, "test", &val, NULL);
193 fail_unless (val == 5);
195 gst_object_unref (elem);
201 GST_START_TEST (test_del)
206 elem = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
207 res = gst_preset_save_preset (GST_PRESET (elem), "test");
210 res = gst_preset_delete_preset (GST_PRESET (elem), "test");
213 res = gst_preset_load_preset (GST_PRESET (elem), "test");
216 gst_object_unref (elem);
221 GST_START_TEST (test_two_instances)
223 GstElement *elem1, *elem2;
227 elem1 = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
228 g_object_set (elem1, "test", 5, NULL);
230 res = gst_preset_save_preset (GST_PRESET (elem1), "test");
233 elem2 = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
234 res = gst_preset_load_preset (GST_PRESET (elem2), "test");
236 g_object_get (elem2, "test", &val, NULL);
237 fail_unless (val == 5);
239 gst_object_unref (elem1);
240 gst_object_unref (elem2);
247 remove_preset_file (void)
249 gchar *preset_file_name;
251 preset_file_name = g_build_filename (g_get_user_data_dir (),
252 "gstreamer-" GST_MAJORMINOR, "presets", "GstPresetTest.prs", NULL);
253 g_unlink (preset_file_name);
254 g_free (preset_file_name);
260 remove_preset_file ();
261 gst_plugin_register_static (GST_VERSION_MAJOR,
264 "preset test plugin",
265 gst_preset_test_plugin_init,
266 VERSION, GST_LICENSE, PACKAGE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
272 remove_preset_file ();
277 gst_preset_suite (void)
279 Suite *s = suite_create ("GstPreset");
280 TCase *tc = tcase_create ("preset");
282 gboolean can_write = FALSE;
284 /* check if we can create presets */
285 gst_dir = g_build_filename (g_get_user_data_dir (),
286 "gstreamer-" GST_MAJORMINOR, NULL);
287 can_write = (g_access (gst_dir, R_OK | W_OK | X_OK) == 0);
290 suite_add_tcase (s, tc);
291 tcase_add_test (tc, test_check);
292 tcase_add_test (tc, test_load);
294 tcase_add_test (tc, test_add);
295 tcase_add_test (tc, test_del);
296 tcase_add_test (tc, test_two_instances);
298 tcase_add_unchecked_fixture (tc, test_setup, test_teardown);
303 GST_CHECK_MAIN (gst_preset);