gpointing-device-settings r250 - trunk/test



Author: hiikezoe
Date: Sun Mar 22 04:36:27 2009
New Revision: 250
URL: http://svn.gnome.org/viewvc/gpointing-device-settings?rev=250&view=rev

Log:
added widget response tests.

Added:
   trunk/test/test-ui-widget.c
Modified:
   trunk/test/Makefile.am
   trunk/test/gpds-test-suite.c
   trunk/test/test-ui.c

Modified: trunk/test/Makefile.am
==============================================================================
--- trunk/test/Makefile.am	(original)
+++ trunk/test/Makefile.am	Sun Mar 22 04:36:27 2009
@@ -10,6 +10,7 @@
 	test-xinput-utils.la	        \
 	test-module.la		        \
 	test-ui.la                      \
+	test-ui-widget.la               \
 	test-utils.la
 endif
 
@@ -44,6 +45,7 @@
 test_xinput_utils_la_SOURCES = test-xinput-utils.c
 test_module_la_SOURCES = test-module.c
 test_ui_la_SOURCES = test-ui.c
+test_ui_widget_la_SOURCES = test-ui-widget.c
 test_utils_la_SOURCES = test-utils.c
 
 echo-cutter:

Modified: trunk/test/gpds-test-suite.c
==============================================================================
--- trunk/test/gpds-test-suite.c	(original)
+++ trunk/test/gpds-test-suite.c	Sun Mar 22 04:36:27 2009
@@ -1,5 +1,6 @@
 #include <gcutter.h>
 #include <gtk/gtk.h>
+#include "gpds-ui.h"
 
 void gpds_test_warmup (void);
 void gpds_test_cooldown (void);
@@ -8,11 +9,13 @@
 gpds_test_warmup (void)
 {
     gtk_init(0, NULL);
+    gpds_uis_load();
 }
 
 void
 gpds_test_cooldown (void)
 {
+    gpds_uis_unload();
 }
 
 /*

Added: trunk/test/test-ui-widget.c
==============================================================================
--- (empty file)
+++ trunk/test/test-ui-widget.c	Sun Mar 22 04:36:27 2009
@@ -0,0 +1,315 @@
+#include "gpds-ui.h"
+
+#include <gcutter.h>
+#include "gpds-xinput.h"
+#include "gpds-gconf.h"
+
+void data_toggle_button (void);
+void test_toggle_button (gconstpointer data);
+void data_spin_button (void);
+void test_spin_button (gconstpointer data);
+
+static GError *error;
+static GpdsUI *ui;
+static GtkWidget *widget;
+static GtkWidget *window;
+static GpdsXInput *xinput;
+static gint *values;
+
+static gboolean wheel_emulation;
+static gboolean middle_button_emulation;
+static gint wheel_emulation_button;
+static gint wheel_emulation_timeout;
+static gint wheel_emulation_inertia;
+
+#define DEVICE_NAME "Macintosh mouse button emulation"
+
+static void
+set_int_property_of_xinput (const gchar *property_name,
+                            gint format_type,
+                            gint *values,
+                            guint n_values)
+{
+    xinput = gpds_xinput_new(DEVICE_NAME);
+    gpds_xinput_set_int_properties_by_name_with_format_type(xinput,
+                                                            property_name,
+                                                            format_type,
+                                                            &error,
+                                                            values, n_values);
+    gcut_assert_error(error);
+    g_object_unref(xinput);
+    xinput = NULL;
+}
+
+void
+cut_startup (void)
+{
+    ui = gpds_ui_new("mouse",
+                     "device-name", DEVICE_NAME,
+                     NULL);
+    gpds_ui_build(ui, NULL);
+
+    widget = gpds_ui_get_content_widget(ui, NULL);
+
+    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    gtk_container_add(GTK_CONTAINER(window), widget);
+    gtk_widget_show_all(window);
+}
+
+void
+cut_shutdown (void)
+{
+    if (ui)
+        g_object_unref(ui);
+    if (window)
+        gtk_widget_destroy(window);
+    if (xinput)
+        g_object_unref(xinput);
+    g_free(values);
+}
+
+static gboolean
+get_boolean_property_of_xinput (const gchar *property_name)
+{
+    gulong n_values;
+
+    xinput = gpds_xinput_new(DEVICE_NAME);
+    gpds_xinput_get_int_properties_by_name(xinput,
+                                           property_name,
+                                           &error,
+                                           &values, &n_values);
+    gcut_assert_error(error);
+
+    g_object_unref(xinput);
+    xinput = NULL;
+
+    return values[0] != 0;
+}
+
+static gint
+get_int_property_of_xinput (const gchar *property_name)
+{
+    gulong n_values;
+
+    xinput = gpds_xinput_new(DEVICE_NAME);
+    gpds_xinput_get_int_properties_by_name(xinput,
+                                           property_name,
+                                           &error,
+                                           &values, &n_values);
+    gcut_assert_error(error);
+
+    g_object_unref(xinput);
+    xinput = NULL;
+
+    return values[0];
+}
+
+static void
+preserve_initial_values (void)
+{
+    wheel_emulation = 
+        get_boolean_property_of_xinput("Evdev Wheel Emulation");
+    middle_button_emulation = 
+        get_boolean_property_of_xinput("Evdev Middle Button Emulation");
+    wheel_emulation_timeout = 
+        get_int_property_of_xinput("Evdev Wheel Emulation Timeout");
+    wheel_emulation_button = 
+        get_int_property_of_xinput("Evdev Wheel Emulation Button");
+    wheel_emulation_inertia = 
+        get_int_property_of_xinput("Evdev Wheel Emulation Inertia");
+}
+
+static void
+restore_initial_values (void)
+{
+    set_int_property_of_xinput("Evdev Wheel Emulation", 8,
+                               &wheel_emulation, 1);
+    set_int_property_of_xinput("Evdev Middle Button Emulation", 8,
+                               &middle_button_emulation, 1);
+    set_int_property_of_xinput("Evdev Wheel Emulation Timeout", 16,
+                               &wheel_emulation_timeout, 1);
+    set_int_property_of_xinput("Evdev Wheel Emulation Button", 8,
+                               &wheel_emulation_button, 1);
+    set_int_property_of_xinput("Evdev Wheel Emulation Inertia", 16,
+                               &wheel_emulation_inertia, 1);
+}
+
+static void
+unset_all_gconf_keys (void)
+{
+    GConfClient *gconf;
+    gchar *escape_key, *gconf_key;
+
+    escape_key = gconf_escape_key(DEVICE_NAME, -1);
+    gconf_key = g_strdup_printf("%s/%s",
+                                GPDS_GCONF_DIR,
+                                escape_key);
+    g_free(escape_key);
+
+    gconf = gconf_client_get_default();
+    gconf_client_recursive_unset(gconf, 
+                                 gconf_key,
+                                 0,
+                                 NULL);
+    g_free(gconf_key);
+    g_object_unref(gconf);
+}
+
+void
+setup (void)
+{
+    error = NULL;
+    preserve_initial_values();
+
+    unset_all_gconf_keys();
+}
+
+void
+teardown (void)
+{
+    unset_all_gconf_keys();
+    restore_initial_values();
+
+    if (error)
+        g_clear_error(&error);
+}
+
+static gboolean
+cb_idle (gpointer data)
+{
+    gboolean *idle_received = data;
+
+    *idle_received = TRUE;
+
+    return FALSE;
+}
+
+static void
+wait_action (void)
+{
+    guint idle_id;
+    gboolean idle_received = FALSE;
+
+    idle_id = g_idle_add_full(G_PRIORITY_LOW,
+                              cb_idle,
+                              &idle_received, NULL);
+    while (!idle_received)
+        g_main_context_iteration(NULL, FALSE);
+}
+
+static GtkWidget *
+get_widget (const gchar *id)
+{
+    GtkBuilder *builder;
+
+    builder = gpds_ui_get_builder(GPDS_UI(ui));
+
+    return GTK_WIDGET(gtk_builder_get_object(builder, id));
+}
+
+void
+data_toggle_button (void)
+{
+    gcut_add_datum("wheel emulation",
+                   "widget-name", G_TYPE_STRING, "wheel_emulation",
+                   "xinput-name", G_TYPE_STRING, "Evdev Wheel Emulation",
+                   NULL);
+    gcut_add_datum("middle button emulation",
+                   "widget-name", G_TYPE_STRING, "middle_button_emulation",
+                   "xinput-name", G_TYPE_STRING, "Evdev Middle Button Emulation",
+                   NULL);
+}
+
+void
+test_toggle_button (gconstpointer data)
+{
+    GtkWidget *button;
+    gboolean widget_value;
+    gboolean xinput_value;
+    const gchar *widget_name;
+    const gchar *xinput_name;
+
+    widget_name = gcut_data_get_string(data, "widget-name");
+    xinput_name = gcut_data_get_string(data, "xinput-name");
+
+    button = get_widget(widget_name);
+    cut_assert_true(GTK_IS_TOGGLE_BUTTON(button));
+
+    xinput_value = get_boolean_property_of_xinput(xinput_name);
+    widget_value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
+    cut_assert_equal_int(xinput_value, widget_value);
+
+    gtk_test_widget_click(button, 1, 0);
+    wait_action();
+    xinput_value = get_boolean_property_of_xinput(xinput_name);
+    cut_assert_equal_int(xinput_value, !widget_value);
+}
+
+void
+data_spin_button (void)
+{
+    gcut_add_datum("wheel emulation timeout",
+                   "widget-name", G_TYPE_STRING, "wheel_emulation_timeout",
+                   "xinput-name", G_TYPE_STRING, "Evdev Wheel Emulation Timeout",
+                   "box-name", G_TYPE_STRING, "wheel_emulation_box",
+                   NULL);
+    gcut_add_datum("wheel emulation inertia",
+                   "widget-name", G_TYPE_STRING, "wheel_emulation_inertia",
+                   "xinput-name", G_TYPE_STRING, "Evdev Wheel Emulation Inertia",
+                   "box-name", G_TYPE_STRING, "wheel_emulation_box",
+                   NULL);
+    gcut_add_datum("middle button timeout",
+                   "widget-name", G_TYPE_STRING, "middle_button_timeout",
+                   "xinput-name", G_TYPE_STRING, "Evdev Middle Button Timeout",
+                   "box-name", G_TYPE_STRING, "middle_button_emulation_box",
+                   NULL);
+}
+
+static void
+enable_widget (const gchar *widget_name)
+{
+    GtkWidget *widget;
+
+    widget = get_widget(widget_name);
+    if (widget)
+        gtk_widget_set_sensitive(widget, TRUE);
+    wait_action();
+}
+
+void
+test_spin_button (gconstpointer data)
+{
+    GtkWidget *button;
+    gint widget_value;
+    gint xinput_value;
+    gdouble increment_step, increment_page;
+    const gchar *widget_name;
+    const gchar *xinput_name;
+    const gchar *box_name;
+
+    widget_name = gcut_data_get_string(data, "widget-name");
+    xinput_name = gcut_data_get_string(data, "xinput-name");
+    box_name = gcut_data_get_string(data, "box-name");
+
+    enable_widget(box_name);
+
+    button = get_widget(widget_name);
+    cut_assert_true(GTK_IS_SPIN_BUTTON(button));
+
+    gtk_spin_button_get_increments(GTK_SPIN_BUTTON(button),
+                                   &increment_step,
+                                   &increment_page);
+    xinput_value = get_int_property_of_xinput(xinput_name);
+    widget_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(button));
+    cut_assert_equal_int(xinput_value, widget_value);
+
+    gtk_test_spin_button_click(GTK_SPIN_BUTTON(button), 1, TRUE);
+    wait_action();
+    xinput_value = get_int_property_of_xinput(xinput_name);
+    widget_value += increment_step;
+    cut_assert_equal_int(xinput_value, widget_value);
+}
+
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/

Modified: trunk/test/test-ui.c
==============================================================================
--- trunk/test/test-ui.c	(original)
+++ trunk/test/test-ui.c	Sun Mar 22 04:36:27 2009
@@ -1,7 +1,6 @@
 #include "gpds-ui.h"
 
 #include <gcutter.h>
-#include "gpds-xinput.h"
 
 void test_names (void);
 void test_new (void);
@@ -10,9 +9,6 @@
 void test_build (void);
 void test_get_content_widget (void);
 void test_get_icon_pixbuf (void);
-void test_create_window (void);
-void test_wheel_emulation (void);
-void test_wheel_emulation_timeout (void);
 
 static GError *error;
 static GpdsUI *ui;
@@ -20,25 +16,10 @@
 static GList *expected_names;
 static GtkWidget *widget;
 static GdkPixbuf *pixbuf;
-static GtkWidget *window;
-static GpdsXInput *xinput;
-static gint *values;
 
 #define DEVICE_NAME "Macintosh mouse button emulation"
 
 void
-cut_startup (void)
-{
-    gpds_uis_load();
-}
-
-void
-cut_shutdown (void)
-{
-    gpds_uis_unload();
-}
-
-void
 setup (void)
 {
     ui = NULL;
@@ -47,9 +28,6 @@
     names = NULL;
     expected_names = NULL;
     pixbuf = NULL;
-    window = NULL;
-    xinput = NULL;
-    values = NULL;
 }
 
 void
@@ -64,11 +42,6 @@
         g_object_unref(pixbuf);
     if (error)
         g_clear_error(&error);
-    if (window)
-        gtk_widget_destroy(window);
-    if (xinput)
-        g_object_unref(xinput);
-    g_free(values);
 }
 
 void
@@ -142,122 +115,6 @@
     cut_assert_true(GDK_IS_PIXBUF(pixbuf));
 }
 
-static GtkWidget *
-get_widget (const gchar *id)
-{
-    GtkBuilder *builder;
-
-    builder = gpds_ui_get_builder(GPDS_UI(ui));
-
-    return GTK_WIDGET(gtk_builder_get_object(builder, id));
-}
-
-void
-test_create_window (void)
-{
-    cut_trace(test_get_content_widget());
-    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-    gtk_container_add(GTK_CONTAINER(window), widget);
-    gtk_widget_show_all(window);
-}
-
-static gboolean
-get_boolean_property_of_xinput (const gchar *property_name)
-{
-    gulong n_values;
-
-    xinput = gpds_xinput_new(DEVICE_NAME);
-    gpds_xinput_get_int_properties_by_name(xinput,
-                                   property_name,
-                                   &error,
-                                   &values, &n_values);
-    gcut_assert_error(error);
-
-    return values[0] != 0;
-}
-
-static gint
-get_int_property_of_xinput (const gchar *property_name)
-{
-    gulong n_values;
-
-    xinput = gpds_xinput_new(DEVICE_NAME);
-    gpds_xinput_get_int_properties_by_name(xinput,
-                                   property_name,
-                                   &error,
-                                   &values, &n_values);
-    gcut_assert_error(error);
-
-    return values[0];
-}
-
-static gboolean
-cb_idle (gpointer data)
-{
-    gboolean *idle_received = data;
-
-    *idle_received = TRUE;
-
-    return FALSE;
-}
-
-static void
-wait_action (void)
-{
-    guint idle_id;
-    gboolean idle_received = FALSE;
-
-    idle_id = g_idle_add_full(G_PRIORITY_LOW,
-                              cb_idle,
-                              &idle_received, NULL);
-    while (!idle_received)
-        g_main_context_iteration(NULL, FALSE);
-}
-
-void
-test_wheel_emulation (void)
-{
-    GtkWidget *button;
-    gboolean active;
-    gboolean current_value;
-
-    cut_trace(test_create_window());
-
-    button = get_widget("wheel_emulation");
-    cut_assert_true(GTK_IS_TOGGLE_BUTTON(button));
-
-    current_value = get_boolean_property_of_xinput("Evdev Wheel Emulation");
-    active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
-    cut_assert_equal_int(current_value, active);
-
-    gtk_test_widget_click(button, 1, 0);
-    wait_action();
-    current_value = get_boolean_property_of_xinput("Evdev Wheel Emulation");
-    cut_assert_equal_int(current_value, !active);
-}
-
-void
-test_wheel_emulation_timeout (void)
-{
-    GtkWidget *button;
-    gint widget_value;
-    gint xinput_value;
-
-    cut_trace(test_create_window());
-
-    button = get_widget("wheel_emulation_timeout");
-    cut_assert_true(GTK_IS_SPIN_BUTTON(button));
-
-    xinput_value = get_int_property_of_xinput("Evdev Wheel Emulation Timeout");
-    widget_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(button));
-    cut_assert_equal_int(xinput_value, widget_value);
-
-    gtk_test_spin_button_click(GTK_SPIN_BUTTON(button), 1, FALSE);
-    wait_action();
-    xinput_value = get_int_property_of_xinput("Evdev Wheel Emulation Timeout");
-    /* cut_assert_equal_int(xinput_value, widget_value + 50);*/
-}
-
 /*
 vi:ts=4:nowrap:ai:expandtab:sw=4
 */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]