gpointing-device-settings r221 - in trunk: src test



Author: hiikezoe
Date: Sun Mar 15 02:57:51 2009
New Revision: 221
URL: http://svn.gnome.org/viewvc/gpointing-device-settings?rev=221&view=rev

Log:
gpds_xinput_utils_get_device_info now needs GError.

Modified:
   trunk/src/gpds-xinput-utils.c
   trunk/src/gpds-xinput-utils.h
   trunk/test/test-xinput-utils.c

Modified: trunk/src/gpds-xinput-utils.c
==============================================================================
--- trunk/src/gpds-xinput-utils.c	(original)
+++ trunk/src/gpds-xinput-utils.c	Sun Mar 15 02:57:51 2009
@@ -36,7 +36,7 @@
 }
 
 XDeviceInfo *
-gpds_xinput_utils_get_device_info (const gchar *device_name)
+gpds_xinput_utils_get_device_info (const gchar *device_name, GError **error)
 {
     XDeviceInfo *device_infos;
     gint i, n_device_infos;
@@ -54,6 +54,11 @@
 
     XFreeDeviceList(device_infos);
 
+    g_set_error(error,
+                GPDS_XINPUT_UTILS_ERROR,
+                GPDS_XINPUT_UTILS_ERROR_NO_DEVICE,
+                _("No %s found."), device_name);
+
     return NULL;
 }
 
@@ -64,14 +69,9 @@
     XAnyClassInfo *class_info;
     gint i;
 
-    device_info = gpds_xinput_utils_get_device_info(device_name);
-    if (!device_info) {
-        g_set_error(error,
-                    GPDS_XINPUT_UTILS_ERROR,
-                    GPDS_XINPUT_UTILS_ERROR_NO_DEVICE,
-                    _("No %s found."), device_name);
+    device_info = gpds_xinput_utils_get_device_info(device_name, error);
+    if (!device_info)
         return -1;
-    }
 
     for (i = 0, class_info = device_info->inputclassinfo;
          i < device_info->num_classes;
@@ -93,14 +93,9 @@
     XDeviceInfo *device_info;
     XDevice *device;
 
-    device_info = gpds_xinput_utils_get_device_info(device_name);
-    if (!device_info) {
-        g_set_error(error,
-                    GPDS_XINPUT_UTILS_ERROR,
-                    GPDS_XINPUT_UTILS_ERROR_NO_DEVICE,
-                    _("No %s found."), device_name);
+    device_info = gpds_xinput_utils_get_device_info(device_name, error);
+    if (!device_info)
         return NULL;
-    }
 
     gdk_error_trap_push();
     device = XOpenDevice(GDK_DISPLAY(), device_info->id);
@@ -135,7 +130,7 @@
 gboolean
 gpds_xinput_utils_exist_device (const gchar *device_name)
 {
-    return gpds_xinput_utils_get_device_info(device_name) ? TRUE : FALSE;
+    return gpds_xinput_utils_get_device_info(device_name, NULL) ? TRUE : FALSE;
 }
 
 /*

Modified: trunk/src/gpds-xinput-utils.h
==============================================================================
--- trunk/src/gpds-xinput-utils.h	(original)
+++ trunk/src/gpds-xinput-utils.h	Sun Mar 15 02:57:51 2009
@@ -36,7 +36,8 @@
 } GpdsXInputUtilsError;
 
 GQuark       gpds_xinput_utils_error_quark              (void);
-XDeviceInfo *gpds_xinput_utils_get_device_info          (const gchar *device_name);
+XDeviceInfo *gpds_xinput_utils_get_device_info          (const gchar *device_name,
+                                                         GError **error);
 XDevice     *gpds_xinput_utils_open_device              (const gchar *device_name, GError **error);
 Atom         gpds_xinput_utils_get_float_atom           (GError **error);
 gshort       gpds_xinput_utils_get_device_num_buttons   (const gchar *device_name, GError **error);

Modified: trunk/test/test-xinput-utils.c
==============================================================================
--- trunk/test/test-xinput-utils.c	(original)
+++ trunk/test/test-xinput-utils.c	Sun Mar 15 02:57:51 2009
@@ -7,9 +7,11 @@
 void test_get_float_atom (void);
 void test_get_device_info (void);
 void test_open_device (void);
+void test_open_no_device (void);
 void test_get_device_num_buttons (void);
 
 static GError *error;
+static GError *expected_error;
 static XDevice *device;
 
 #define DEVICE_NAME "Macintosh mouse button emulation"
@@ -19,6 +21,7 @@
 {
     error = NULL;
     device = NULL;
+    expected_error = NULL;
 }
 
 void
@@ -27,6 +30,7 @@
     if (device)
         XCloseDevice(GDK_DISPLAY(), device);
     g_clear_error(&error);
+    g_clear_error(&expected_error);
 }
 
 void
@@ -46,8 +50,10 @@
 test_get_device_info (void)
 {
     XDeviceInfo *device_info = NULL; 
-    device_info = gpds_xinput_utils_get_device_info(DEVICE_NAME);
+    device_info = gpds_xinput_utils_get_device_info(DEVICE_NAME, &error);
     cut_assert(device_info);
+
+    gcut_assert_error(error);
 }
 
 void
@@ -60,6 +66,17 @@
 }
 
 void
+test_open_no_device (void)
+{
+    expected_error = g_error_new(GPDS_XINPUT_UTILS_ERROR,
+                                 GPDS_XINPUT_UTILS_ERROR_NO_DEVICE,
+                                 "No Invalid device found.");
+    device = gpds_xinput_utils_open_device("Invalid device", &error);
+
+    gcut_assert_equal_error(expected_error, error);
+}
+
+void
 test_get_device_num_buttons (void)
 {
     gshort n_buttons;



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