]> Pileus Git - ~andy/gtk/blobdiff - gtk/tests/builder.c
tests: add a test for GtkLevelBar GtkBuildable implementation
[~andy/gtk] / gtk / tests / builder.c
index 1c0acaa8a636c76db0e697748eb216a7f67fb603..563d422b216cc5a628bf9bdc420a5a2b64395a68 100644 (file)
@@ -14,9 +14,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <string.h>
@@ -1050,7 +1048,7 @@ test_child_properties (void)
   GtkBuilder * builder;
   const gchar buffer1[] =
     "<interface>"
-    "  <object class=\"GtkVBox\" id=\"vbox1\">"
+    "  <object class=\"GtkBox\" id=\"vbox1\">"
     "    <child>"
     "      <object class=\"GtkLabel\" id=\"label1\"/>"
     "      <packing>"
@@ -1071,7 +1069,7 @@ test_child_properties (void)
   
   builder = builder_new_from_string (buffer1, -1, NULL);
   vbox = gtk_builder_get_object (builder, "vbox1");
-  g_assert (GTK_IS_VBOX (vbox));
+  g_assert (GTK_IS_BOX (vbox));
 
   label = gtk_builder_get_object (builder, "label1");
   g_assert (GTK_IS_LABEL (label));
@@ -1220,22 +1218,13 @@ test_icon_view (void)
     "    </child>"
     "  </object>"
     "</interface>";
-  GObject *window, *iconview, *renderer;
-  gchar *text;
+  GObject *window, *iconview;
   
   builder = builder_new_from_string (buffer, -1, NULL);
   iconview = gtk_builder_get_object (builder, "iconview1");
   g_assert (iconview);
   g_assert (GTK_IS_ICON_VIEW (iconview));
 
-  gtk_widget_realize (GTK_WIDGET (iconview));
-
-  renderer = gtk_builder_get_object (builder, "renderer1");
-  g_object_get (renderer, "text", &text, NULL);
-  g_assert (text);
-  g_assert (strcmp (text, "test") == 0);
-  g_free (text);
-    
   window = gtk_builder_get_object (builder, "window1");
   gtk_widget_destroy (GTK_WIDGET (window));
   g_object_unref (builder);
@@ -1721,7 +1710,7 @@ test_window (void)
 static void
 test_value_from_string (void)
 {
-  GValue value = { 0 };
+  GValue value = G_VALUE_INIT;
   GError *error = NULL;
   GtkBuilder *builder;
 
@@ -2503,11 +2492,9 @@ test_file (const gchar *filename)
 
       if (GTK_IS_DIALOG (obj))
        {
-         int response;
-
          g_print ("Running dialog %s.\n",
                   gtk_widget_get_name (GTK_WIDGET (obj)));
-         response = gtk_dialog_run (GTK_DIALOG (obj));
+         gtk_dialog_run (GTK_DIALOG (obj));
        }
       else if (GTK_IS_WINDOW (obj))
        {
@@ -2528,7 +2515,6 @@ static void
 test_message_area (void)
 {
   GtkBuilder *builder;
-  GError *error;
   GObject *obj, *obj1;
   const gchar buffer[] =
     "<interface>"
@@ -2539,6 +2525,9 @@ test_message_area (void)
     "          <object class=\"GtkLabel\" id=\"content\">"
     "            <property name=\"label\" translatable=\"yes\">Message</property>"
     "          </object>"
+    "          <packing>"
+    "            <property name='expand'>False</property>"
+    "          </packing>"
     "        </child>"
     "      </object>"
     "    </child>"
@@ -2558,9 +2547,7 @@ test_message_area (void)
     "  </object>"
     "</interface>";
 
-  error = NULL;
   builder = builder_new_from_string (buffer, -1, NULL);
-  g_assert (error == NULL);
   obj = gtk_builder_get_object (builder, "infobar1");
   g_assert (GTK_IS_INFO_BAR (obj));
   obj1 = gtk_builder_get_object (builder, "content");
@@ -2574,6 +2561,150 @@ test_message_area (void)
   g_object_unref (builder);
 }
 
+static void
+test_gmenu (void)
+{
+  GtkBuilder *builder;
+  GObject *obj, *obj1;
+  const gchar buffer[] =
+    "<interface>"
+    "  <object class=\"GtkWindow\" id=\"window\">"
+    "  </object>"
+    "  <menu id='edit-menu'>"
+    "    <section>"
+    "      <item>"
+    "        <attribute name='label'>Undo</attribute>"
+    "        <attribute name='action'>undo</attribute>"
+    "      </item>"
+    "      <item>"
+    "        <attribute name='label'>Redo</attribute>"
+    "        <attribute name='action'>redo</attribute>"
+    "      </item>"
+    "    </section>"
+    "    <section></section>"
+    "    <section>"
+    "      <attribute name='label'>Copy &amp; Paste</attribute>"
+    "      <item>"
+    "        <attribute name='label'>Cut</attribute>"
+    "        <attribute name='action'>cut</attribute>"
+    "      </item>"
+    "      <item>"
+    "        <attribute name='label'>Copy</attribute>"
+    "        <attribute name='action'>copy</attribute>"
+    "      </item>"
+    "      <item>"
+    "        <attribute name='label'>Paste</attribute>"
+    "        <attribute name='action'>paste</attribute>"
+    "      </item>"
+    "    </section>"
+    "    <item><link name='section' id='blargh'>"
+    "      <item>"
+    "        <attribute name='label'>Bold</attribute>"
+    "        <attribute name='action'>bold</attribute>"
+    "      </item>"
+    "      <submenu>"
+    "        <attribute name='label'>Language</attribute>"
+    "        <item>"
+    "          <attribute name='label'>Latin</attribute>"
+    "          <attribute name='action'>lang</attribute>"
+    "          <attribute name='target'>'latin'</attribute>"
+    "        </item>"
+    "        <item>"
+    "          <attribute name='label'>Greek</attribute>"
+    "          <attribute name='action'>lang</attribute>"
+    "          <attribute name='target'>'greek'</attribute>"
+    "        </item>"
+    "        <item>"
+    "          <attribute name='label'>Urdu</attribute>"
+    "          <attribute name='action'>lang</attribute>"
+    "          <attribute name='target'>'urdu'</attribute>"
+    "        </item>"
+    "      </submenu>"
+    "    </link></item>"
+    "  </menu>"
+    "</interface>";
+
+  builder = builder_new_from_string (buffer, -1, NULL);
+  obj = gtk_builder_get_object (builder, "window");
+  g_assert (GTK_IS_WINDOW (obj));
+  obj1 = gtk_builder_get_object (builder, "edit-menu");
+  g_assert (G_IS_MENU_MODEL (obj1));
+  obj1 = gtk_builder_get_object (builder, "blargh");
+  g_assert (G_IS_MENU_MODEL (obj1));
+  g_object_unref (builder);
+}
+
+static void
+test_level_bar (void)
+{
+  GtkBuilder *builder;
+  GError *error = NULL;
+  GObject *obj, *obj1;
+  const gchar buffer1[] =
+    "<interface>"
+    "  <object class=\"GtkWindow\" id=\"window\">"
+    "    <child>"
+    "      <object class=\"GtkLevelBar\" id=\"levelbar\">"
+    "        <property name=\"value\">4.70</property>"
+    "        <property name=\"min-value\">2</property>"
+    "        <property name=\"max-value\">5</property>"
+    "        <offsets>"
+    "          <offset name=\"low\" value=\"2.25\"/>"
+    "          <offset name=\"custom\" value=\"3\"/>"
+    "          <offset name=\"high\" value=\"3\"/>"
+    "        </offsets>"
+    "      </object>"
+    "    </child>"
+    "  </object>"
+    "</interface>";
+  const gchar buffer2[] =
+    "<interface>"
+    "  <object class=\"GtkLevelBar\" id=\"levelbar\">"
+    "    <offsets>"
+    "      <offset name=\"low\" bogus_attr=\"foo\"/>"
+    "    </offsets>"
+    "  </object>"
+    "</interface>";
+  const gchar buffer3[] =
+    "<interface>"
+    "  <object class=\"GtkLevelBar\" id=\"levelbar\">"
+    "    <offsets>"
+    "      <offset name=\"low\" value=\"1\"/>"
+    "    </offsets>"
+    "    <bogus_tag>"
+    "    </bogus_tag>"
+    "  </object>"
+    "</interface>";
+
+  builder = gtk_builder_new ();
+  gtk_builder_add_from_string (builder, buffer1, -1, &error);
+  g_assert (error == NULL);
+
+  obj = gtk_builder_get_object (builder, "window");
+  g_assert (GTK_IS_WINDOW (obj));
+  obj1 = gtk_builder_get_object (builder, "levelbar");
+  g_assert (GTK_IS_LEVEL_BAR (obj1));
+  g_object_unref (builder);
+
+  error = NULL;
+  builder = gtk_builder_new ();
+  gtk_builder_add_from_string (builder, buffer2, -1, &error);
+  g_assert (g_error_matches (error,
+                             GTK_BUILDER_ERROR,
+                             GTK_BUILDER_ERROR_INVALID_ATTRIBUTE));
+  g_error_free (error);
+  g_object_unref (builder);
+
+  error = NULL;
+  builder = gtk_builder_new ();
+  gtk_builder_add_from_string (builder, buffer3, -1, &error);
+  g_assert (g_error_matches (error,
+                             GTK_BUILDER_ERROR,
+                             GTK_BUILDER_ERROR_UNHANDLED_TAG));
+  g_error_free (error);
+  g_object_unref (builder);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -2620,6 +2751,9 @@ main (int argc, char **argv)
   g_test_add_func ("/Builder/Menus", test_menus);
   g_test_add_func ("/Builder/MessageArea", test_message_area);
   g_test_add_func ("/Builder/MessageDialog", test_message_dialog);
+  g_test_add_func ("/Builder/GMenu", test_gmenu);
+  g_test_add_func ("/Builder/LevelBar", test_level_bar);
 
   return g_test_run();
 }
+