2 * Copyright (C) 2011 Red Hat Inc.
3 * Copyright (C) 2012 SUSE LLC.
6 * Mike Gorse <mgorse@suse.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
26 set_value (GtkWidget *widget,
29 if (GTK_IS_LEVEL_BAR (widget))
30 gtk_level_bar_set_value (GTK_LEVEL_BAR (widget), value);
31 else if (GTK_IS_RANGE (widget))
33 GtkAdjustment *adjustment = gtk_range_get_adjustment (GTK_RANGE (widget));
34 gtk_adjustment_set_value (adjustment, value);
36 else if (GTK_IS_SPIN_BUTTON (widget))
38 GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
39 gtk_adjustment_set_value (adjustment, value);
50 notify_cb (GObject *obj,
51 GParamSpec *pspec, NotifyData *data)
55 g_free (data->last_name);
56 data->last_name = g_strdup (pspec->name);
60 test_basic (GtkWidget *widget)
62 NotifyData notify_data;
63 AtkObject *atk_object;
68 atk_object = gtk_widget_get_accessible (widget);
69 atk_value = ATK_VALUE (atk_object);
71 memset (¬ify_data, 0, sizeof (notify_data));
72 g_signal_connect (atk_object, "notify", G_CALLBACK (notify_cb), ¬ify_data);
73 set_value (widget, value);
74 g_assert_cmpint (notify_data.count, ==, 1);
75 g_assert_cmpstr (notify_data.last_name, ==, "accessible-value");
77 memset (&ret, 0, sizeof (ret));
78 atk_value_get_current_value (atk_value, &ret);
79 g_assert_cmpfloat (g_value_get_double (&ret), ==, value);
81 g_free (notify_data.last_name);
82 g_signal_handlers_disconnect_by_func (atk_object, G_CALLBACK (notify_cb), ¬ify_data);
86 setup_test (GtkWidget *widget)
88 set_value (widget, 0);
92 add_value_test (const gchar *prefix,
93 GTestFixtureFunc test_func,
98 path = g_strdup_printf ("%s/%s", prefix, G_OBJECT_TYPE_NAME (widget));
99 g_test_add_vtable (path,
101 g_object_ref (widget),
102 (GTestFixtureFunc) setup_test,
103 (GTestFixtureFunc) test_func,
104 (GTestFixtureFunc) g_object_unref);
109 add_value_tests (GtkWidget *widget)
111 g_object_ref_sink (widget);
112 add_value_test ("/value/basic", (GTestFixtureFunc) test_basic, widget);
113 g_object_unref (widget);
117 main (int argc, char *argv[])
119 gtk_test_init (&argc, &argv, NULL);
121 g_test_bug_base ("http://bugzilla.gnome.org/");
123 add_value_tests (gtk_spin_button_new_with_range (0, 100, 1));
124 add_value_tests (gtk_level_bar_new_for_interval (0, 100));
126 return g_test_run ();