gtk+ r19682 - in branches/gtk-2-12: . gtk tests



Author: johan
Date: Sat Mar  1 13:53:39 2008
New Revision: 19682
URL: http://svn.gnome.org/viewvc/gtk+?rev=19682&view=rev

Log:
2008-02-29  Johan Dahlin  <johan gnome org>

        Merged from trunk:

        * gtk/gtkbuilder.c:
        * gtk/gtkbuilderparser.c:
        * gtk/gtkbuilderprivate.h:
        Do not use g_error for a few more errors, instead set
        the GError sent in through add_from_file/add_from_string.
        * tests/buildertest.c:
        Add a couple of new parsing tests.
        (#519199, Pavel Syomin)



Modified:
   branches/gtk-2-12/ChangeLog
   branches/gtk-2-12/gtk/gtkbuilder.c
   branches/gtk-2-12/gtk/gtkbuilderparser.c
   branches/gtk-2-12/gtk/gtkbuilderprivate.h
   branches/gtk-2-12/tests/buildertest.c

Modified: branches/gtk-2-12/gtk/gtkbuilder.c
==============================================================================
--- branches/gtk-2-12/gtk/gtkbuilder.c	(original)
+++ branches/gtk-2-12/gtk/gtkbuilder.c	Sat Mar  1 13:53:39 2008
@@ -334,7 +334,8 @@
 static GObject *
 gtk_builder_get_internal_child (GtkBuilder  *builder,
                                 ObjectInfo  *info,
-                                const gchar *childname)
+                                const gchar *childname,
+				GError      **error)
 {
   GObject *obj = NULL;
 
@@ -359,14 +360,19 @@
     };
 
   if (!obj)
-    g_error ("Unknown internal child: %s\n", childname);
-
+    {
+      g_set_error (error,
+		   GTK_BUILDER_ERROR,
+		   GTK_BUILDER_ERROR_INVALID_VALUE,
+		   "Unknown internal child: %s", childname);
+    }
   return obj;
 }
 
 GObject *
 _gtk_builder_construct (GtkBuilder *builder,
-                        ObjectInfo *info)
+                        ObjectInfo *info,
+			GError **error)
 {
   GArray *parameters, *construct_parameters;
   GType object_type;
@@ -379,7 +385,14 @@
   g_assert (info->class_name != NULL);
   object_type = gtk_builder_get_type_from_name (builder, info->class_name);
   if (object_type == G_TYPE_INVALID)
-    g_error ("Invalid type: %s", info->class_name);
+    {
+      g_set_error (error,
+		   GTK_BUILDER_ERROR,
+		   GTK_BUILDER_ERROR_INVALID_VALUE,
+		   "Invalid object type `%s'",
+		   info->class_name);
+      return NULL;
+    }
 
   gtk_builder_get_parameters (builder, object_type,
                               info->id,
@@ -393,9 +406,17 @@
 
       constructor = gtk_builder_get_object (builder, info->constructor);
       if (constructor == NULL)
-        g_error ("Unknown constructor for %s: %s\n", info->id,
-                 info->constructor);
-
+	{
+	  g_set_error (error,
+		       GTK_BUILDER_ERROR,
+		       GTK_BUILDER_ERROR_INVALID_VALUE,
+		       "Unknown object constructor for %s: %s",
+		       info->id,
+		       info->constructor);
+	  g_array_free (parameters, TRUE);
+	  g_array_free (construct_parameters, TRUE);
+	  return NULL;
+	}
       obj = gtk_buildable_construct_child (GTK_BUILDABLE (constructor),
                                            builder,
                                            info->id);
@@ -407,7 +428,13 @@
   else if (info->parent && ((ChildInfo*)info->parent)->internal_child != NULL)
     {
       gchar *childname = ((ChildInfo*)info->parent)->internal_child;
-      obj = gtk_builder_get_internal_child (builder, info, childname);
+      obj = gtk_builder_get_internal_child (builder, info, childname, error);
+      if (!obj)
+	{
+	  g_array_free (parameters, TRUE);
+	  g_array_free (construct_parameters, TRUE);
+	  return NULL;
+	}
       if (construct_parameters->len)
         g_warning ("Can't pass in construct-only parameters to %s", childname);
       g_object_ref (obj);

Modified: branches/gtk-2-12/gtk/gtkbuilderparser.c
==============================================================================
--- branches/gtk-2-12/gtk/gtkbuilderparser.c	(original)
+++ branches/gtk-2-12/gtk/gtkbuilderparser.c	Sat Mar  1 13:53:39 2008
@@ -182,8 +182,9 @@
 }
 
 static GObject *
-builder_construct (ParserData *data,
-                   ObjectInfo *object_info)
+builder_construct (ParserData  *data,
+                   ObjectInfo  *object_info,
+		   GError     **error)
 {
   GObject *object;
 
@@ -194,7 +195,10 @@
 
   object_info->properties = g_slist_reverse (object_info->properties);
 
-  object = _gtk_builder_construct (data->builder, object_info);
+  object = _gtk_builder_construct (data->builder, object_info, error);
+  if (!object)
+    return NULL;
+
   g_assert (G_IS_OBJECT (object));
 
   object_info->object = object;
@@ -345,7 +349,7 @@
 
   child_info->parent = (CommonInfo*)object_info;
 
-  object_info->object = builder_construct (data, object_info);
+  object_info->object = builder_construct (data, object_info, error);
 }
 
 static void
@@ -643,8 +647,13 @@
     {
       ObjectInfo* object_info = (ObjectInfo*)parent_info;
       if (!object_info->object)
-	object_info->object = _gtk_builder_construct (data->builder,
-						      object_info);
+	{
+	  object_info->object = _gtk_builder_construct (data->builder,
+							object_info,
+							error);
+	  if (!object_info->object)
+	    return TRUE; /* A GError is already set */
+	}
       g_assert (object_info->object);
       object = object_info->object;
       child = NULL;
@@ -803,8 +812,12 @@
       ObjectInfo *object_info = state_pop_info (data, ObjectInfo);
       ChildInfo* child_info = state_peek_info (data, ChildInfo);
 
-      object_info->object = builder_construct (data, object_info);
-
+      object_info->object = builder_construct (data, object_info, error);
+      if (!object_info->object)
+	{
+	  free_object_info (object_info);
+	  return;
+	}
       if (child_info)
         child_info->object = object_info->object;
 

Modified: branches/gtk-2-12/gtk/gtkbuilderprivate.h
==============================================================================
--- branches/gtk-2-12/gtk/gtkbuilderprivate.h	(original)
+++ branches/gtk-2-12/gtk/gtkbuilderprivate.h	Sat Mar  1 13:53:39 2008
@@ -103,7 +103,8 @@
                                        gsize length,
                                        GError **error);
 GObject * _gtk_builder_construct (GtkBuilder *builder,
-                                  ObjectInfo *info);
+                                  ObjectInfo *info,
+				  GError    **error);
 void      _gtk_builder_add (GtkBuilder *builder,
                             ChildInfo *child_info);
 void      _gtk_builder_add_signals (GtkBuilder *builder,

Modified: branches/gtk-2-12/tests/buildertest.c
==============================================================================
--- branches/gtk-2-12/tests/buildertest.c	(original)
+++ branches/gtk-2-12/tests/buildertest.c	Sat Mar  1 13:53:39 2008
@@ -76,6 +76,27 @@
   g_return_val_if_fail (error->code == GTK_BUILDER_ERROR_INVALID_TAG, FALSE);
   g_error_free (error);
 
+  error = NULL;
+  gtk_builder_add_from_string (builder, "<interface><object class=\"Unknown\" id=\"a\"></object></interface>", -1, &error);
+  g_assert (error != NULL);
+  g_assert (error->domain == GTK_BUILDER_ERROR);
+  g_assert (error->code == GTK_BUILDER_ERROR_INVALID_VALUE);
+  g_error_free (error);
+
+  error = NULL;
+  gtk_builder_add_from_string (builder, "<interface><object class=\"GtkWidget\" id=\"a\" constructor=\"none\"></object></interface>", -1, &error);
+  g_assert (error != NULL);
+  g_assert (error->domain == GTK_BUILDER_ERROR);
+  g_assert (error->code == GTK_BUILDER_ERROR_INVALID_VALUE);
+  g_error_free (error);
+
+  error = NULL;
+  gtk_builder_add_from_string (builder, "<interface><object class=\"GtkButton\" id=\"a\"><child internal-child=\"foobar\"><object class=\"GtkButton\" id=\"int\"/></child></object></interface>", -1, &error);
+  g_assert (error != NULL);
+  g_assert (error->domain == GTK_BUILDER_ERROR);
+  g_assert (error->code == GTK_BUILDER_ERROR_INVALID_VALUE);
+  g_error_free (error);
+
   g_object_unref (builder);
   
   return TRUE;
@@ -1858,7 +1879,6 @@
   g_print ("Testing parser\n");
   if (!test_parser ())
     g_error ("test_parser failed");
-
   g_print ("Testing types\n");
   if (!test_types ())
     g_error ("test_types failed");



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