Index: gio/gemblemedicon.c
===================================================================
--- gio/gemblemedicon.c	(revision 7617)
+++ gio/gemblemedicon.c	(working copy)
@@ -29,6 +29,7 @@
 
 #include "gemblemedicon.h"
 #include "glibintl.h"
+#include "gioerror.h"
 
 #include "gioalias.h"
 
@@ -237,11 +238,125 @@ g_emblemed_icon_equal (GIcon *icon1,
   return list1 == NULL && list2 == NULL;
 }
 
+static gchar **
+g_emblemed_icon_to_tokens (GIcon *icon,
+                           gint  *out_version)
+{
+  GEmblemedIcon *emblemed_icon = G_EMBLEMED_ICON (icon);
+  gchar **tokens;
+  GPtrArray *array;
+  GList *l;
+  char *s;
+  char *e;
+
+  /* GEmblemedIcons are encoded as
+   *
+   *   <encoded_icon> [<encoded_emblem_icon>]*
+   */
+
+  g_return_val_if_fail (out_version != NULL, NULL);
+
+  *out_version = 0;
+
+  array = g_ptr_array_new ();
+
+  s = g_icon_to_string (emblemed_icon->icon);
+  e = g_uri_escape_string (s, NULL, TRUE);
+  g_ptr_array_add (array, e);
+  g_free (s);
+
+  for (l = emblemed_icon->emblems; l != NULL; l = l->next)
+    {
+      GIcon *emblem_icon = G_ICON (l->data);
+
+      s = g_icon_to_string (emblem_icon);
+      e = g_uri_escape_string (s, NULL, TRUE);
+      g_ptr_array_add (array, e);
+      g_free (s);
+    }
+
+  g_ptr_array_add (array, NULL);
+  tokens = (gchar **) g_ptr_array_free (array, FALSE);
+
+  return tokens;
+}
+
+static GIcon *
+g_emblemed_icon_from_tokens (gchar  **tokens,
+                             gint     num_tokens,
+                             gint     version,
+                             GError **error)
+{
+  GEmblemedIcon *emblemed_icon;
+  char *s;
+  int n;
+
+  emblemed_icon = NULL;
+
+  if (version != 0)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Can't handle version %d of GEmblemedIcon encoding"),
+                   version);
+      goto fail;
+    }
+
+  if (num_tokens < 1)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Malformed number of tokens (%d) in GEmblemedIcon encoding"),
+                   num_tokens);
+      goto fail;
+    }
+
+  emblemed_icon = g_object_new (G_TYPE_EMBLEMED_ICON, NULL);
+  s = g_uri_unescape_string (tokens[0], NULL);
+  emblemed_icon->icon = g_icon_new_for_string (s, error);
+  g_free (s);
+  if (emblemed_icon->icon == NULL)
+    goto fail;
+
+  for (n = 1; n < num_tokens; n++)
+    {
+      GIcon *emblem;
+
+      s = g_uri_unescape_string (tokens[n], NULL);
+      emblem = g_icon_new_for_string (s, error);
+      g_free (s);
+      if (emblem == NULL)
+        goto fail;
+
+      if (!G_IS_EMBLEM (emblem))
+        {
+          g_set_error_literal (error,
+                               G_IO_ERROR,
+                               G_IO_ERROR_INVALID_ARGUMENT,
+                               _("Expected a GEmblem for GEmblemedIcon"));
+          goto fail;
+        }
+
+      emblemed_icon->emblems = g_list_append (emblemed_icon->emblems, emblem);
+    }
+
+  return G_ICON (emblemed_icon);
+
+ fail:
+  if (emblemed_icon != NULL)
+    g_object_unref (emblemed_icon);
+  return NULL;
+}
+
 static void
 g_emblemed_icon_icon_iface_init (GIconIface *iface)
 {
   iface->hash = g_emblemed_icon_hash;
   iface->equal = g_emblemed_icon_equal;
+  iface->to_tokens = g_emblemed_icon_to_tokens;
+  iface->from_tokens = g_emblemed_icon_from_tokens;
 }
 
 #define __G_EMBLEMED_ICON_C__
Index: gio/gfileicon.c
===================================================================
--- gio/gfileicon.c	(revision 7617)
+++ gio/gfileicon.c	(working copy)
@@ -29,6 +29,7 @@
 #include "gloadableicon.h"
 #include "ginputstream.h"
 #include "gsimpleasyncresult.h"
+#include "gioerror.h"
 
 #include "gioalias.h"
 
@@ -202,12 +203,75 @@ g_file_icon_equal (GIcon *icon1,
   return g_file_equal (file1->file, file2->file);
 }
 
+static gchar **
+g_file_icon_to_tokens (GIcon *icon,
+                       gint  *out_version)
+{
+  GFileIcon *file_icon = G_FILE_ICON (icon);
+  char *escaped_uri;
+  char *uri;
+  char **tokens;
 
+  g_return_val_if_fail (out_version != NULL, NULL);
+
+  *out_version = 0;
+
+  uri = g_file_get_uri (file_icon->file);
+  escaped_uri = g_uri_escape_string (uri, NULL, TRUE);
+  g_free (uri);
+
+  tokens = g_new0 (char *, 2);
+  tokens[0] = escaped_uri;
+  tokens[1] = NULL;
+
+  return tokens;
+}
+
+static GIcon *
+g_file_icon_from_tokens (gchar  **tokens,
+                         gint     num_tokens,
+                         gint     version,
+                         GError **error)
+{
+  GIcon *icon;
+  GFile *file;
+
+  icon = NULL;
+
+  if (version != 0)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Can't handle version %d of GFileIcon encoding"),
+                   version);
+      goto out;
+    }
+
+  if (num_tokens != 1)
+    {
+      g_set_error_literal (error,
+                           G_IO_ERROR,
+                           G_IO_ERROR_INVALID_ARGUMENT,
+                           _("Malformed input data for GFileIcon"));
+      goto out;
+    }
+
+  file = g_file_new_for_uri (tokens[0]);
+  icon = g_file_icon_new (file);
+  g_object_unref (file);
+
+ out:
+  return icon;
+}
+
 static void
 g_file_icon_icon_iface_init (GIconIface *iface)
 {
   iface->hash = g_file_icon_hash;
   iface->equal = g_file_icon_equal;
+  iface->to_tokens = g_file_icon_to_tokens;
+  iface->from_tokens = g_file_icon_from_tokens;
 }
 
 
Index: gio/gicon.c
===================================================================
--- gio/gicon.c	(revision 7617)
+++ gio/gicon.c	(working copy)
@@ -21,20 +21,31 @@
  */
 
 #include "config.h"
+#include <stdlib.h>
+#include <string.h>
+
 #include "gicon.h"
+#include "gthemedicon.h"
+#include "gfileicon.h"
+#include "gemblemedicon.h"
+#include "gfile.h"
+#include "gioerror.h"
 
 #include "glibintl.h"
 
 #include "gioalias.h"
 
+#define G_ICON_SERIALIZATION_MAGIC0 "GIconSerialization0 "
+
 /**
  * SECTION:gicon
  * @short_description: Interface for icons
  * @include: gio/gio.h
  *
- * #GIcon is a very minimal interface for icons. It provides functions 
- * for checking the equality of two icons and hashing of icons.
- * 
+ * #GIcon is a very minimal interface for icons. It provides functions
+ * for checking the equality of two icons, hashing of icons and
+ * serializing an icon to and from strings.
+ *
  * #GIcon does not provide the actual pixmap for the icon as this is out 
  * of GIO's scope, however implementations of #GIcon may contain the name 
  * of an icon (see #GThemedIcon), or the path to an icon (see #GLoadableIcon). 
@@ -42,6 +53,13 @@
  * To obtain a hash of a #GIcon, see g_icon_hash().
  * 
  * To check if two #GIcons are equal, see g_icon_equal().
+ *
+ * For serializing a #GIcon, use g_icon_to_string() and
+ * g_icon_new_for_string().
+ *
+ * If your application or library provides one or more #GIcon
+ * implementations you need to ensure that each #GType is registered
+ * with the type system prior to calling g_icon_new_for_string().
  **/
 
 static void g_icon_base_init (gpointer g_class);
@@ -140,5 +158,298 @@ g_icon_equal (GIcon *icon1,
   return (* iface->equal) (icon1, icon2);
 }
 
+static char *
+_g_icon_to_string_tokenized (GIcon *icon)
+{
+  char *s;
+  char *ret;
+  char **tokens;
+  gint version;
+  GIconIface *icon_iface;
+
+  g_return_val_if_fail (icon != NULL, NULL);
+  g_return_val_if_fail (G_IS_ICON (icon), NULL);
+
+  ret = NULL;
+
+  icon_iface = G_ICON_GET_IFACE (icon);
+
+  if (icon_iface->to_tokens == NULL)
+    {
+      goto out;
+    }
+
+  tokens = icon_iface->to_tokens (icon, &version);
+  g_assert (tokens != NULL);
+
+  s = g_strjoinv (" ", tokens);
+  /* format: TypeName Version <token_0> .. <token_N-1> */
+  ret = g_strdup_printf ("%s %d %s",
+                         g_type_name (G_TYPE_FROM_INSTANCE (icon)),
+                         version,
+                         s);
+  g_strfreev (tokens);
+  g_free (s);
+
+ out:
+  return ret;
+}
+
+/**
+ * g_icon_to_string:
+ * @icon: a #GIcon.
+ *
+ * Generates a textual representation of @icon that can be used for
+ * serialization such as when passing @icon to a different process or
+ * saving it to persistent storage. Use g_icon_new_for_string() to
+ * get @icon back from the returned string.
+ *
+ * The encoding of the returned string is proprietary to #GIcon except
+ * in the following two cases
+ *
+ * <itemizedlist>
+ * <listitem><para>
+ *     If @icon is a #GFileIcon, the returned string is a native path
+ *     (such as <literal>/path/to/my icon.png</literal>) without escaping
+ *     if the #GFile for @icon is a native file.  If the file is not
+ *     native, the returned string is the result of g_file_get_uri()
+ *     (such as <literal>sftp://path/to/my%%20icon.png</literal>).
+ * </para></listitem>
+ * <listitem><para>
+ *    If @icon is a #GThemedIcon with exactly one name, the encoding is
+ *    simply the name (such as <literal>network-server</literal>).
+ * </para></listitem>
+ * </itemizedlist>
+ *
+ * Returns: An allocated NUL-terminated string or %NULL if @icon can't
+ * be serialized. Use g_free() to free.
+ *
+ * Since: 2.20
+ */
+gchar *
+g_icon_to_string (GIcon *icon)
+{
+  gchar *ret;
+
+  g_return_val_if_fail (icon != NULL, NULL);
+  g_return_val_if_fail (G_IS_ICON (icon), NULL);
+
+  ret = NULL;
+
+  if (G_IS_FILE_ICON (icon))
+    {
+      GFile *file;
+
+      file = g_file_icon_get_file (G_FILE_ICON (icon));
+      if (g_file_is_native (file))
+        ret = g_file_get_path (file);
+      else
+        ret = g_file_get_uri (file);
+    }
+  else if (G_IS_THEMED_ICON (icon))
+    {
+      gchar **names;
+
+      g_object_get (icon,
+                    "names", &names,
+                    NULL);
+
+      if (names != NULL)
+        {
+          if (g_strv_length (names) == 1)
+            {
+              char *s;
+              s = g_strdup (names[0]);
+              ret = g_uri_escape_string (s, NULL, TRUE);
+              g_free (s);
+            }
+          g_strfreev (names);
+        }
+    }
+
+  if (ret == NULL)
+    {
+      char *s;
+      s = _g_icon_to_string_tokenized (icon);
+      ret = g_strdup_printf (G_ICON_SERIALIZATION_MAGIC0 "%s", s);
+      g_free (s);
+    }
+
+#if 0
+  g_print ("serialized icon with hash 0x%x into '%s'\n", g_icon_hash (icon), ret);
+#endif
+
+  return ret;
+}
+
+static GIcon *
+_g_icon_new_from_tokens (char   **tokens,
+                         GError **error)
+{
+  GIcon *icon;
+  GType type;
+  gpointer klass;
+  GIconIface *icon_iface;
+  gint version;
+  char *endp;
+  int num_tokens;
+
+  icon = NULL;
+  klass = NULL;
+
+  num_tokens = g_strv_length (tokens);
+
+  if (num_tokens < 2)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Wrong number of tokens (%d)"),
+                   num_tokens);
+      goto out;
+    }
+
+  type = g_type_from_name (tokens[0]);
+  if (type == 0)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("No type for class name %s"),
+                   tokens[0]);
+      goto out;
+    }
+
+  if (!g_type_is_a (type, G_TYPE_ICON))
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Type %s does not implement the GIcon interface"),
+                   tokens[0]);
+      goto out;
+    }
+
+  klass = g_type_class_ref (type);
+  if (klass == NULL)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Type %s is not classed"),
+                   tokens[0]);
+      goto out;
+    }
+
+  version = strtol (tokens[1], &endp, 10);
+  if (endp == NULL || *endp != '\0')
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Malformed version number: %s"),
+                   tokens[1]);
+      goto out;
+    }
+
+  icon_iface = g_type_interface_peek (klass, G_TYPE_ICON);
+  g_assert (icon_iface != NULL);
+
+  if (icon_iface->from_tokens == NULL)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Type %s does not implement from_tokens() on the GIcon interface"),
+                   tokens[0]);
+      goto out;
+    }
+
+  icon = icon_iface->from_tokens (tokens + 2, num_tokens - 2, version, error);
+
+ out:
+  if (klass != NULL)
+    {
+      g_type_class_unref (klass);
+    }
+  return icon;
+}
+
+static void
+_ensure_builtin_icon_types (void)
+{
+  static volatile GType t;
+  t = g_themed_icon_get_type ();
+  t = g_file_icon_get_type ();
+  t = g_emblemed_icon_get_type ();
+  t = g_emblem_get_type ();
+}
+
+/**
+ * g_icon_new_for_string:
+ * @str: A string obtained via g_icon_to_string().
+ * @error: Return location for error.
+ *
+ * Generate a #GIcon instance from @str. This function can fail if
+ * @str is not valid - see g_icon_to_string() for discussion.
+ *
+ * Returns: An object implementing the #GIcon interface or %NULL if
+ * @error is set.
+ *
+ * Since: 2.20
+ **/
+GIcon *
+g_icon_new_for_string (const gchar   *str,
+                       GError       **error)
+{
+  GIcon *icon;
+
+  g_return_val_if_fail (str != NULL, NULL);
+
+  _ensure_builtin_icon_types ();
+
+  icon = NULL;
+
+  if (g_str_has_prefix (str, G_ICON_SERIALIZATION_MAGIC0))
+    {
+      gchar **tokens;
+      /* handle tokenized encoding */
+      tokens = g_strsplit (str + sizeof (G_ICON_SERIALIZATION_MAGIC0) - 1, " ", 0);
+      icon = _g_icon_new_from_tokens (tokens, error);
+      g_strfreev (tokens);
+    }
+  else
+    {
+      gchar *scheme;
+
+      /* handle special GFileIcon and GThemedIcon cases */
+      scheme = g_uri_parse_scheme (str);
+      if (scheme != NULL || str[0] == '/')
+        {
+          GFile *location;
+          location = g_file_new_for_commandline_arg (str);
+          icon = g_file_icon_new (location);
+          g_object_unref (location);
+        }
+      else
+        {
+          icon = g_themed_icon_new (str);
+        }
+      g_free (scheme);
+    }
+
+#if 0
+  if (icon != NULL)
+    g_print ("deserialized icon with hash 0x%x from '%s'\n", g_icon_hash (icon), str);
+  else
+    g_print ("couldn't deserialize icon from '%s': %s\n",
+             str,
+             error != NULL && *error != NULL ? (*error)->message : "(error not set)");
+#endif
+
+  return icon;
+}
+
+
 #define __G_ICON_C__
 #include "gioaliasdef.c"
Index: gio/gicon.h
===================================================================
--- gio/gicon.h	(revision 7617)
+++ gio/gicon.h	(working copy)
@@ -48,6 +48,12 @@ typedef struct _GIconIface GIconIface;
  * @g_iface: The parent interface.
  * @hash: A hash for a given #GIcon.
  * @equal: Checks if two #GIcon<!-- -->s are equal.
+ * @to_tokens: Serializes a #GIcon into tokens. The tokens must not
+ * contain any whitespace. Don't implement if the #GIcon can't be
+ * serialized (Since 2.20).
+ * @from_tokens: Constructs a #GIcon from tokens. Set the #GError if
+ * the tokens are malformed. Don't implement if the #GIcon can't be
+ * serialized (Since 2.20).
  *
  * GIconIface is used to implement GIcon types for various
  * different systems. See #GThemedIcon and #GLoadableIcon for
@@ -59,16 +65,25 @@ struct _GIconIface
 
   /* Virtual Table */
 
-  guint    (* hash)  (GIcon *icon);
-  gboolean (* equal) (GIcon *icon1,
-                      GIcon *icon2);
+  guint       (* hash)        (GIcon   *icon);
+  gboolean    (* equal)       (GIcon   *icon1,
+                               GIcon   *icon2);
+  gchar **    (* to_tokens)   (GIcon   *icon,
+                               gint    *out_version);
+  GIcon *     (* from_tokens) (gchar  **tokens,
+                               gint     num_tokens,
+                               gint     version,
+                               GError **error);
 };
 
-GType    g_icon_get_type (void) G_GNUC_CONST;
+GType    g_icon_get_type  (void) G_GNUC_CONST;
 
-guint    g_icon_hash     (gconstpointer  icon);
-gboolean g_icon_equal    (GIcon         *icon1,
-                          GIcon         *icon2);
+guint    g_icon_hash            (gconstpointer  icon);
+gboolean g_icon_equal           (GIcon         *icon1,
+                                 GIcon         *icon2);
+gchar   *g_icon_to_string       (GIcon         *icon);
+GIcon   *g_icon_new_for_string  (const gchar   *str,
+                                 GError       **error);
 
 G_END_DECLS
 
Index: gio/gthemedicon.c
===================================================================
--- gio/gthemedicon.c	(revision 7617)
+++ gio/gthemedicon.c	(working copy)
@@ -26,6 +26,7 @@
 
 #include "gthemedicon.h"
 #include "gicon.h"
+#include "gioerror.h"
 #include "glibintl.h"
 
 #include "gioalias.h"
@@ -458,11 +459,74 @@ g_themed_icon_equal (GIcon *icon1,
   return themed1->names[i] == NULL && themed2->names[i] == NULL;
 }
 
+
+static gchar **
+g_themed_icon_to_tokens (GIcon *icon,
+                         gint  *out_version)
+{
+  GThemedIcon *themed_icon = G_THEMED_ICON (icon);
+  GPtrArray *array;
+  gchar **tokens;
+  int n;
+
+  g_return_val_if_fail (out_version != NULL, NULL);
+
+  *out_version = 0;
+
+  array = g_ptr_array_new ();
+  for (n = 0; themed_icon->names[n] != NULL; n++)
+    {
+      g_ptr_array_add (array, g_uri_escape_string (themed_icon->names[n], NULL, TRUE));
+    }
+
+  g_ptr_array_add (array, NULL);
+  tokens = (gchar **) g_ptr_array_free (array, FALSE);
+  return tokens;
+}
+
+static GIcon *
+g_themed_icon_from_tokens (gchar  **tokens,
+                           gint     num_tokens,
+                           gint     version,
+                           GError **error)
+{
+  GIcon *icon;
+  gchar **names;
+  int n;
+
+  icon = NULL;
+
+  if (version != 0)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Can't handle version %d of GThemedIcon encoding"),
+                   version);
+      goto out;
+    }
+
+  names = g_new0 (gchar *, num_tokens + 1);
+  for (n = 0; n < num_tokens; n++)
+    {
+      names[n] = g_uri_unescape_string (tokens[n], NULL);
+    }
+  names[n] = NULL;
+
+  icon = g_themed_icon_new_from_names (names, num_tokens);
+  g_strfreev (names);
+
+ out:
+  return icon;
+}
+
 static void
 g_themed_icon_icon_iface_init (GIconIface *iface)
 {
   iface->hash = g_themed_icon_hash;
   iface->equal = g_themed_icon_equal;
+  iface->to_tokens = g_themed_icon_to_tokens;
+  iface->from_tokens = g_themed_icon_from_tokens;
 }
 
 #define __G_THEMED_ICON_C__
Index: gio/gio.symbols
===================================================================
--- gio/gio.symbols	(revision 7617)
+++ gio/gio.symbols	(working copy)
@@ -470,6 +470,8 @@ g_filter_output_stream_get_base_stream
 g_icon_get_type  G_GNUC_CONST
 g_icon_hash 
 g_icon_equal 
+g_icon_to_string
+g_icon_new_for_string
 #endif
 #endif
 
Index: docs/reference/gio/gio-sections.txt
===================================================================
--- docs/reference/gio/gio-sections.txt	(revision 7617)
+++ docs/reference/gio/gio-sections.txt	(working copy)
@@ -353,6 +353,8 @@ GIcon
 GIconIface
 g_icon_hash
 g_icon_equal
+g_icon_to_string
+g_icon_new_for_string
 <SUBSECTION Standard>
 G_ICON
 G_IS_ICON
Index: gio/tests/Makefile.am
===================================================================
--- gio/tests/Makefile.am	(revision 7617)
+++ gio/tests/Makefile.am	(working copy)
@@ -22,7 +22,8 @@ TEST_PROGS +=	 		\
 	g-file 			\
 	g-file-info 		\
 	data-input-stream 	\
-	data-output-stream 
+	data-output-stream 	\
+	g-icon
 
 if OS_UNIX
 TEST_PROGS += live-g-file unix-streams desktop-app-info
@@ -46,6 +47,9 @@ data_input_stream_LDADD		= $(progs_ldadd)
 data_output_stream_SOURCES	= data-output-stream.c
 data_output_stream_LDADD	= $(progs_ldadd)
 
+g_icon_SOURCES	= g-icon.c
+g_icon_LDADD	= $(progs_ldadd)
+
 live_g_file_SOURCES	  = live-g-file.c
 live_g_file_LDADD	  = $(progs_ldadd)
 
--- /dev/null	2008-10-20 23:08:12.798044021 -0400
+++ gio/tests/g-icon.c	2008-10-20 14:20:54.000000000 -0400
@@ -0,0 +1,241 @@
+/* GLib testing framework examples and tests
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * This work is provided "as is"; redistribution and modification
+ * in whole or in part, in any medium, physical or electronic is
+ * permitted without restriction.
+ *
+ * This work is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * In no event shall the authors or contributors be liable for any
+ * direct, indirect, incidental, special, exemplary, or consequential
+ * damages (including, but not limited to, procurement of substitute
+ * goods or services; loss of use, data, or profits; or business
+ * interruption) however caused and on any theory of liability, whether
+ * in contract, strict liability, or tort (including negligence or
+ * otherwise) arising in any way out of the use of this software, even
+ * if advised of the possibility of such damage.
+ *
+ * Authors: David Zeuthen <davidz@redhat.com>
+ */
+
+#include <glib/glib.h>
+#include <gio/gio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void
+test_g_icon_serialize (void)
+{
+  GIcon *icon;
+  GIcon *icon2;
+  GIcon *icon3;
+  GIcon *icon4;
+  GIcon *icon5;
+  GEmblem *emblem1;
+  GEmblem *emblem2;
+  const char *uri;
+  GFile *location;
+  char *data;
+  GError *error;
+
+  error = NULL;
+
+  /* check that GFileIcon and GThemedIcon serialize to the encoding specified */
+
+  uri = "file:///some/native/path/to/an/icon.png";
+  location = g_file_new_for_uri (uri);
+  icon = g_file_icon_new (location);
+  data = g_icon_to_string (icon);
+  g_assert_cmpstr (data, ==, "/some/native/path/to/an/icon.png");
+  icon2 = g_icon_new_for_string (data, &error);
+  g_assert_no_error (error);
+  g_assert (g_icon_equal (icon, icon2));
+  g_free (data);
+  g_object_unref (icon);
+  g_object_unref (icon2);
+  g_object_unref (location);
+
+  uri = "file:///some/native/path/to/an/icon with spaces.png";
+  location = g_file_new_for_uri (uri);
+  icon = g_file_icon_new (location);
+  data = g_icon_to_string (icon);
+  g_assert_cmpstr (data, ==, "/some/native/path/to/an/icon with spaces.png");
+  icon2 = g_icon_new_for_string (data, &error);
+  g_assert_no_error (error);
+  g_assert (g_icon_equal (icon, icon2));
+  g_free (data);
+  g_object_unref (icon);
+  g_object_unref (icon2);
+  g_object_unref (location);
+
+  uri = "sftp:///some/non-native/path/to/an/icon.png";
+  location = g_file_new_for_uri (uri);
+  icon = g_file_icon_new (location);
+  data = g_icon_to_string (icon);
+  g_assert_cmpstr (data, ==, "sftp:///some/non-native/path/to/an/icon.png");
+  icon2 = g_icon_new_for_string (data, &error);
+  g_assert_no_error (error);
+  g_assert (g_icon_equal (icon, icon2));
+  g_free (data);
+  g_object_unref (icon);
+  g_object_unref (icon2);
+  g_object_unref (location);
+
+  uri = "sftp:///some/non-native/path/to/an/icon with spaces.png";
+  location = g_file_new_for_uri (uri);
+  icon = g_file_icon_new (location);
+  data = g_icon_to_string (icon);
+  g_assert_cmpstr (data, ==, "sftp:///some/non-native/path/to/an/icon%20with%20spaces.png");
+  icon2 = g_icon_new_for_string (data, &error);
+  g_assert_no_error (error);
+  g_assert (g_icon_equal (icon, icon2));
+  g_free (data);
+  g_object_unref (icon);
+  g_object_unref (icon2);
+  g_object_unref (location);
+
+  icon = g_themed_icon_new ("network-server");
+  data = g_icon_to_string (icon);
+  g_assert_cmpstr (data, ==, "network-server");
+  icon2 = g_icon_new_for_string (data, &error);
+  g_assert_no_error (error);
+  g_assert (g_icon_equal (icon, icon2));
+  g_free (data);
+  g_object_unref (icon);
+  g_object_unref (icon2);
+
+  /* Check that we can serialize from well-known specified formats */
+  icon = g_icon_new_for_string ("network-server", &error);
+  g_assert_no_error (error);
+  icon2 = g_themed_icon_new ("network-server");
+  g_assert (g_icon_equal (icon, icon2));
+  g_object_unref (icon);
+  g_object_unref (icon2);
+
+  icon = g_icon_new_for_string ("/path/to/somewhere.png", &error);
+  g_assert_no_error (error);
+  location = g_file_new_for_commandline_arg ("/path/to/somewhere.png");
+  icon2 = g_file_icon_new (location);
+  g_assert (g_icon_equal (icon, icon2));
+  g_object_unref (icon);
+  g_object_unref (icon2);
+  g_object_unref (location);
+
+  icon = g_icon_new_for_string ("/path/to/somewhere with whitespace.png", &error);
+  g_assert_no_error (error);
+  data = g_icon_to_string (icon);
+  g_assert_cmpstr (data, ==, "/path/to/somewhere with whitespace.png");
+  g_free (data);
+  location = g_file_new_for_commandline_arg ("/path/to/somewhere with whitespace.png");
+  icon2 = g_file_icon_new (location);
+  g_assert (g_icon_equal (icon, icon2));
+  g_object_unref (location);
+  g_object_unref (icon2);
+  location = g_file_new_for_commandline_arg ("/path/to/somewhere%20with%20whitespace.png");
+  icon2 = g_file_icon_new (location);
+  g_assert (!g_icon_equal (icon, icon2));
+  g_object_unref (location);
+  g_object_unref (icon2);
+  g_object_unref (icon);
+
+  icon = g_icon_new_for_string ("sftp:///path/to/somewhere.png", &error);
+  g_assert_no_error (error);
+  data = g_icon_to_string (icon);
+  g_assert_cmpstr (data, ==, "sftp:///path/to/somewhere.png");
+  g_free (data);
+  location = g_file_new_for_commandline_arg ("sftp:///path/to/somewhere.png");
+  icon2 = g_file_icon_new (location);
+  g_assert (g_icon_equal (icon, icon2));
+  g_object_unref (icon);
+  g_object_unref (icon2);
+  g_object_unref (location);
+
+  icon = g_icon_new_for_string ("sftp:///path/to/somewhere with whitespace.png", &error);
+  g_assert_no_error (error);
+  data = g_icon_to_string (icon);
+  g_assert_cmpstr (data, ==, "sftp:///path/to/somewhere%20with%20whitespace.png");
+  g_free (data);
+  location = g_file_new_for_commandline_arg ("sftp:///path/to/somewhere with whitespace.png");
+  icon2 = g_file_icon_new (location);
+  g_assert (g_icon_equal (icon, icon2));
+  g_object_unref (location);
+  g_object_unref (icon2);
+  location = g_file_new_for_commandline_arg ("sftp:///path/to/somewhere%20with%20whitespace.png");
+  icon2 = g_file_icon_new (location);
+  g_assert (g_icon_equal (icon, icon2));
+  g_object_unref (location);
+  g_object_unref (icon2);
+  g_object_unref (icon);
+
+  /* Check that GThemedIcon serialization works */
+
+  icon = g_themed_icon_new ("network-server");
+  g_themed_icon_append_name (G_THEMED_ICON (icon), "computer");
+  data = g_icon_to_string (icon);
+  icon2 = g_icon_new_for_string (data, &error);
+  g_assert_no_error (error);
+  g_assert (g_icon_equal (icon, icon2));
+  g_free (data);
+  g_object_unref (icon);
+  g_object_unref (icon2);
+
+  icon = g_themed_icon_new ("icon name with whitespace");
+  g_themed_icon_append_name (G_THEMED_ICON (icon), "computer");
+  data = g_icon_to_string (icon);
+  icon2 = g_icon_new_for_string (data, &error);
+  g_assert_no_error (error);
+  g_assert (g_icon_equal (icon, icon2));
+  g_free (data);
+  g_object_unref (icon);
+  g_object_unref (icon2);
+
+  icon = g_themed_icon_new_with_default_fallbacks ("network-server-xyz");
+  g_themed_icon_append_name (G_THEMED_ICON (icon), "computer");
+  data = g_icon_to_string (icon);
+  icon2 = g_icon_new_for_string (data, &error);
+  g_assert_no_error (error);
+  g_assert (g_icon_equal (icon, icon2));
+  g_free (data);
+  g_object_unref (icon);
+  g_object_unref (icon2);
+
+  /* Check that GEmblemedIcon serialization works */
+
+  icon = g_themed_icon_new ("face-smirk");
+  icon2 = g_themed_icon_new ("emblem-important");
+  g_themed_icon_append_name (G_THEMED_ICON (icon2), "emblem-shared");
+  location = g_file_new_for_uri ("file:///some/path/somewhere.png");
+  icon3 = g_file_icon_new (location);
+  g_object_unref (location);
+  emblem1 = g_emblem_new_with_origin (icon2, G_EMBLEM_ORIGIN_DEVICE);
+  emblem2 = g_emblem_new_with_origin (icon3, G_EMBLEM_ORIGIN_LIVEMETADATA);
+  icon4 = g_emblemed_icon_new (icon, emblem1);
+  g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (icon4), emblem2);
+  data = g_icon_to_string (icon4);
+  icon5 = g_icon_new_for_string (data, &error);
+  g_assert_no_error (error);
+  g_assert (g_icon_equal (icon4, icon5));
+  g_object_unref (emblem1);
+  g_object_unref (emblem2);
+  g_object_unref (icon);
+  g_object_unref (icon2);
+  g_object_unref (icon3);
+  g_object_unref (icon4);
+  g_object_unref (icon5);
+}
+
+int
+main (int   argc,
+      char *argv[])
+{
+  g_type_init ();
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/g-icon/serialize", test_g_icon_serialize);
+
+  return g_test_run();
+}
