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



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

Log:
gpds_gconf_get_string returns allocated memory.

Modified:
   trunk/src/gpds-gconf.c
   trunk/src/gpds-gconf.h
   trunk/src/gpds-ui.c
   trunk/src/gpds-ui.h
   trunk/test/test-gconf.c

Modified: trunk/src/gpds-gconf.c
==============================================================================
--- trunk/src/gpds-gconf.c	(original)
+++ trunk/src/gpds-gconf.c	Sun Mar 15 02:57:59 2009
@@ -71,7 +71,7 @@
 }
 
 gboolean
-gpds_gconf_get_string (GConfClient *gconf, const gchar *key, const gchar **value)
+gpds_gconf_get_string (GConfClient *gconf, const gchar *key, gchar **value)
 {
     GConfValue *gconf_value;
     gboolean exist_value = FALSE;
@@ -79,7 +79,7 @@
     gconf_value = gconf_client_get(gconf, key, NULL);
     if (gconf_value) {
         if (gconf_value->type == GCONF_VALUE_STRING) {
-            *value = gconf_value_get_string(gconf_value);
+            *value = g_strdup(gconf_value_get_string(gconf_value));
             exist_value = TRUE;
         }
         gconf_value_free(gconf_value);

Modified: trunk/src/gpds-gconf.h
==============================================================================
--- trunk/src/gpds-gconf.h	(original)
+++ trunk/src/gpds-gconf.h	Sun Mar 15 02:57:59 2009
@@ -38,7 +38,7 @@
                                            gboolean *value);
 gboolean     gpds_gconf_get_string        (GConfClient *gconf,
                                            const gchar *key,
-                                           const gchar **value);
+                                           gchar **value);
 
 G_END_DECLS
 

Modified: trunk/src/gpds-ui.c
==============================================================================
--- trunk/src/gpds-ui.c	(original)
+++ trunk/src/gpds-ui.c	Sun Mar 15 02:57:59 2009
@@ -364,7 +364,7 @@
 }
 
 gboolean
-gpds_ui_get_gconf_string (GpdsUI *ui, const gchar *key, const gchar **value)
+gpds_ui_get_gconf_string (GpdsUI *ui, const gchar *key, gchar **value)
 {
     gchar *gconf_key;
     gboolean exist_value = FALSE;

Modified: trunk/src/gpds-ui.h
==============================================================================
--- trunk/src/gpds-ui.h	(original)
+++ trunk/src/gpds-ui.h	Sun Mar 15 02:57:59 2009
@@ -90,7 +90,7 @@
                                            const gchar *value);
 gboolean     gpds_ui_get_gconf_string     (GpdsUI *ui,
                                            const gchar *key,
-                                           const gchar **value);
+                                           gchar **value);
 
 G_END_DECLS
 

Modified: trunk/test/test-gconf.c
==============================================================================
--- trunk/test/test-gconf.c	(original)
+++ trunk/test/test-gconf.c	Sun Mar 15 02:57:59 2009
@@ -5,17 +5,19 @@
 void test_get_key_from_path (void);
 void test_get_non_existent (void);
 
-static const gchar *key;
+static gchar *gconf_key;
 static gboolean boolean_value;
 static gint int_value;
-static const gchar *string_value;
+static gchar *string_value;
 static GConfClient *gconf;
+static GError *error;
 
 void
 setup (void)
 {
-    key = NULL;
+    gconf_key = NULL;
     string_value = NULL;
+    error = NULL;
 
     gconf = gconf_client_get_default();
 }
@@ -23,28 +25,72 @@
 void
 teardown (void)
 {
+    if (gconf_key)
+        gconf_client_unset(gconf, gconf_key, NULL);
+    g_free(gconf_key);
+    g_free(string_value);
     g_object_unref(gconf);
+    g_clear_error(&error);
 }
 
 void
 test_get_key_from_path (void)
 {
+    const gchar *key;
     key = gpds_gconf_get_key_from_path("/desktop/gnome/peripherals/TPPS 47@2 32@IBM 32@TrackPoint/middle_button_emulation");
     cut_assert_equal_string("middle_button_emulation", key);
 }
 
+static gchar *
+make_unique_key (void)
+{
+    const gchar *unique_key;
+
+    unique_key = cut_take_string(gconf_unique_key());
+    return gconf_concat_dir_and_key("/", unique_key);
+}
+
 void
 test_get_non_existent (void)
 {
-    gchar *unique_key;
+    gconf_key = make_unique_key();
+
+    cut_assert_false(gpds_gconf_get_boolean(gconf, gconf_key, &boolean_value));
+    cut_assert_false(gpds_gconf_get_int(gconf, gconf_key, &int_value));
+    cut_assert_false(gpds_gconf_get_string(gconf, gconf_key, &string_value));
+}
+
+void
+test_boolean (void)
+{
+    gconf_key = make_unique_key();
+    gconf_client_set_bool(gconf, gconf_key, TRUE, &error);
+    gcut_assert_error(error);
+
+    cut_assert_true(gpds_gconf_get_boolean(gconf, gconf_key, &boolean_value));
+    cut_assert_true(boolean_value);
+}
+
+void
+test_int (void)
+{
+    gconf_key = make_unique_key();
+    gconf_client_set_int(gconf, gconf_key, 99, &error);
+    gcut_assert_error(error);
+
+    cut_assert_true(gpds_gconf_get_int(gconf, gconf_key, &int_value));
+    cut_assert_equal_int(99, int_value);
+}
+
+void
+test_string (void)
+{
+    gconf_key = make_unique_key();
+    gconf_client_set_string(gconf, gconf_key, "string", &error);
+    gcut_assert_error(error);
 
-    unique_key = gconf_unique_key();
-    key = gconf_concat_dir_and_key("/", unique_key);
-    g_free(unique_key);
-
-    cut_assert_false(gpds_gconf_get_boolean(gconf, key, &boolean_value));
-    cut_assert_false(gpds_gconf_get_int(gconf, key, &int_value));
-    cut_assert_false(gpds_gconf_get_string(gconf, key, &string_value));
+    cut_assert_true(gpds_gconf_get_string(gconf, gconf_key, &string_value));
+    cut_assert_equal_string("string", string_value);
 }
 
 /*



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