[glade] Added toplevel-order test



commit 4f3680881f4399f8a3ae35de838b66be70a2d8bb
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Fri Nov 15 22:45:46 2013 -0300

    Added toplevel-order test

 tests/Makefile.am                |   24 ++++++-
 tests/toplevel-order.c           |  154 ++++++++++++++++++++++++++++++++++++++
 tests/toplevel_order_test.glade  |    9 ++
 tests/toplevel_order_test2.glade |   11 +++
 tests/toplevel_order_test3.glade |    9 ++
 tests/toplevel_order_test4.glade |   14 ++++
 tests/toplevel_order_test5.glade |   36 +++++++++
 tests/toplevel_order_test6.glade |  117 +++++++++++++++++++++++++++++
 8 files changed, 372 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 80f034c..4d829ab 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,10 @@
 include $(top_srcdir)/glade-rules.mk
 
+TEST_PROGS = \
+       create-widgets \
+       add-child \
+       toplevel-order
+
 noinst_PROGRAMS = $(TEST_PROGS)
 
 progs_cppflags = \
@@ -20,7 +25,6 @@ progs_ldadd = $(top_builddir)/gladeui/libgladeui-2.la
 
 # Test that GladeWidgets and thier runtime objects
 # are created and finalized properly
-TEST_PROGS              = create-widgets
 create_widgets_CPPFLAGS = $(progs_cppflags)
 create_widgets_CFLAGS   = $(progs_cflags)
 create_widgets_LDFLAGS  = $(progs_libs)
@@ -30,12 +34,28 @@ create_widgets_SOURCES  = create-widgets.c
 # Test that various types of container widgets
 # successfully parent child types via the
 # GladeWidget / adaptor code
-TEST_PROGS        += add-child
 add_child_CPPFLAGS = $(progs_cppflags)
 add_child_CFLAGS   = $(progs_cflags)
 add_child_LDFLAGS  = $(progs_libs)
 add_child_LDADD    = $(progs_ldadd)
 add_child_SOURCES  = add-child.c
 
+# Test toplevel order in xml output
+toplevel_order_CPPFLAGS = $(progs_cppflags)
+toplevel_order_CFLAGS   = $(progs_cflags)
+toplevel_order_LDFLAGS  = $(progs_libs)
+toplevel_order_LDADD    = $(progs_ldadd)
+toplevel_order_SOURCES  = toplevel-order.c
+TOPLEVEL_ORDER_FILES = \
+       toplevel_order_test.glade \
+       toplevel_order_test1.glade \
+       toplevel_order_test2.glade \
+       toplevel_order_test3.glade \
+       toplevel_order_test4.glade \
+       toplevel_order_test5.glade \
+       toplevel_order_test6.glade
+
+EXTRA_DIST = $(TOPLEVEL_ORDER_FILES)
+
 TESTS = $(TEST_PROGS)
 TESTS_ENVIRONMENT=$(GLADE_TEST_ENVIRONMENT)
diff --git a/tests/toplevel-order.c b/tests/toplevel-order.c
new file mode 100644
index 0000000..64a0c76
--- /dev/null
+++ b/tests/toplevel-order.c
@@ -0,0 +1,154 @@
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <glib-object.h>
+#include <stdarg.h>
+#include <gladeui/glade-tsort.h>
+#include <gladeui/glade-app.h>
+
+typedef struct
+{
+  GList *nodes;
+  _NodeEdge *edges;
+  gchar **orig_nodes;
+} TsortData;
+
+static void
+tsort_data_free (gpointer udata)
+{
+  TsortData *data = udata;
+  g_list_free (data->nodes);
+  _node_edge_free (data->edges);
+  g_free (data);
+}
+
+static void
+test_tsort_order (gconstpointer userdata)
+{
+  TsortData *data = (gpointer) userdata;
+  gchar **orig_nodes = data->orig_nodes;
+  GList *nodes, *l;
+  
+  nodes = _glade_tsort (&data->nodes, &data->edges);
+
+  for (l = nodes; l && *orig_nodes; l = g_list_next (l), orig_nodes++)
+    g_assert_cmpstr (l->data, ==, *orig_nodes);
+
+  /* make sure all items where tested */
+  g_assert (l == NULL && *orig_nodes == NULL);
+
+  g_list_free (nodes);
+}
+
+static void
+add_tsort_test_real (const gchar *path, gchar *nodes[], gchar *edges[][2])
+{
+  TsortData *data = g_new0(TsortData, 1);
+  gint i;
+
+  /* insert sorted alphabetically */
+  for (i = 0; nodes[i]; i++)
+    data->nodes = g_list_insert_sorted (data->nodes, nodes[i], (GCompareFunc)g_strcmp0);
+
+  for (i = 0; edges[i][0]; i++)
+    data->edges = _node_edge_prepend (data->edges, edges[i][0], edges[i][1]);
+
+  data->orig_nodes = nodes;
+
+  g_test_add_data_func_full (path, data, test_tsort_order, tsort_data_free);
+}
+
+#define add_tsort_test(nodes, edges) add_tsort_test_real ("/Tsort/"#nodes, nodes, edges)
+
+static void
+test_toplevel_order (gconstpointer userdata)
+{
+  gchar **data = (gpointer) userdata;
+  gchar *project_path = *data;
+  gchar **names = &data[1];
+  GladeProject *project;
+  GList *toplevels, *l;
+  gchar *temp_path;
+
+  g_assert (g_close (g_file_open_tmp ("glade-toplevel-order-XXXXXX.glade", &temp_path, NULL), NULL));
+  /* Load project */
+  g_assert ((project = glade_project_load (project_path)));
+
+  /* And save it, order should be the same */
+  g_assert (glade_project_save (project, temp_path, NULL));
+  g_object_unref (project);
+
+  /* Reload saved project */
+  g_assert ((project = glade_project_load (temp_path)));
+
+  g_unlink (temp_path);
+
+  /* And get toplevels to check order */
+  g_assert ((toplevels = glade_project_toplevels (project)));
+
+  for (l = toplevels; l && names; l = g_list_next (l), names++)
+    {
+      GladeWidget *toplevel;
+      g_assert ((toplevel = glade_widget_get_from_gobject (l->data)));
+      g_assert_cmpstr (glade_widget_get_name (toplevel), ==, *names);
+    }
+
+  /* make sure all items where tested */
+  g_assert (!l && !*names);
+  
+  g_list_free (toplevels);
+  g_object_unref (project);
+  g_free (temp_path);
+}
+
+#define add_project_test(data) g_test_add_data_func_full ("/ToplevelOrder/"#data, data, test_toplevel_order, 
NULL);
+
+/* _glade_tsort() test cases */
+
+/* the array must be properly ordered, since it will be used to test order */
+static gchar *tsort_test[] = {"bbb", "ccc", "aaa", NULL };
+
+static gchar *tsort_test_edges[][2] = { {"ccc","aaa"}, { NULL, NULL} };
+
+/* GladeProject toplevel order test */
+static gchar *order_test[] = {"toplevel_order_test.glade",
+  "bbb", "ccc", "aaa", NULL};
+
+static gchar *order_test2[] = {"toplevel_order_test2.glade",
+  "aa", "bbb", "ccc", "aaa", "ddd", NULL };
+
+static gchar *order_test3[] = {"toplevel_order_test3.glade",
+  "aaa", "ccc", "bbb", NULL };
+
+/* toplevels with circular dependencies get ordered alphabetically at the end */
+static gchar *order_test4[] = {"toplevel_order_test4.glade",
+  "aa", "bbb", "cc", "ddd", "aaa", "ccc", NULL };
+
+/* children dependency */
+static gchar *order_test5[] = {"toplevel_order_test5.glade",
+  "xaction", "awindow", NULL };
+
+/* Commonly used widgets with dependencies */
+static gchar *order_test6[] = {"toplevel_order_test6.glade",
+  "iconfactory", "label_a", "label_b", "asizegroup", "label_c", "xaction",
+  "xactiongroup", "anotherwindow", "xentrybuffer", "xliststore", "treeview",
+  "zaccelgroup", "awindow", NULL };
+
+int
+main (int argc, char *argv[])
+{
+  gtk_test_init (&argc, &argv, NULL);
+
+  glade_init ();
+  glade_app_get ();
+
+  add_tsort_test (tsort_test, tsort_test_edges);
+  
+  add_project_test (order_test);
+  add_project_test (order_test2);
+  add_project_test (order_test3);
+  add_project_test (order_test4);
+  add_project_test (order_test5);
+  add_project_test (order_test6);
+  
+  return g_test_run ();
+}
diff --git a/tests/toplevel_order_test.glade b/tests/toplevel_order_test.glade
new file mode 100644
index 0000000..187bdea
--- /dev/null
+++ b/tests/toplevel_order_test.glade
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <object class="GtkWindow" id="aaa">
+    <property name="transient_for">ccc</property>
+  </object>
+  <object class="GtkWindow" id="bbb"/>
+  <object class="GtkWindow" id="ccc"/>
+</interface>
diff --git a/tests/toplevel_order_test2.glade b/tests/toplevel_order_test2.glade
new file mode 100644
index 0000000..621fb4a
--- /dev/null
+++ b/tests/toplevel_order_test2.glade
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <object class="GtkWindow" id="aa"/>
+  <object class="GtkWindow" id="aaa">
+    <property name="transient_for">ccc</property>
+  </object>
+  <object class="GtkWindow" id="bbb"/>
+  <object class="GtkWindow" id="ccc"/>
+  <object class="GtkWindow" id="ddd"/>
+</interface>
diff --git a/tests/toplevel_order_test3.glade b/tests/toplevel_order_test3.glade
new file mode 100644
index 0000000..fc6acd4
--- /dev/null
+++ b/tests/toplevel_order_test3.glade
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <object class="GtkWindow" id="aaa"/>
+  <object class="GtkWindow" id="bbb"/>
+  <object class="GtkWindow" id="ccc">
+    <property name="transient_for">aaa</property>
+  </object>
+</interface>
diff --git a/tests/toplevel_order_test4.glade b/tests/toplevel_order_test4.glade
new file mode 100644
index 0000000..c4869d9
--- /dev/null
+++ b/tests/toplevel_order_test4.glade
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <object class="GtkWindow" id="aa"/>
+  <object class="GtkWindow" id="aaa">
+    <property name="transient_for">ccc</property>
+  </object>
+  <object class="GtkWindow" id="bbb"/>
+  <object class="GtkWindow" id="cc"/>
+  <object class="GtkWindow" id="ccc">
+    <property name="transient_for">aaa</property>
+  </object>
+  <object class="GtkWindow" id="ddd"/>
+</interface>
diff --git a/tests/toplevel_order_test5.glade b/tests/toplevel_order_test5.glade
new file mode 100644
index 0000000..ccfeb63
--- /dev/null
+++ b/tests/toplevel_order_test5.glade
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.0 on Fri Nov  1 11:46:21 2013 -->
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <object class="GtkAction" id="xaction"/>
+  <object class="GtkWindow" id="awindow">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkBox" id="box1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <object class="GtkButton" id="button1">
+            <property name="label" translatable="yes">button</property>
+            <property name="related_action">xaction</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/tests/toplevel_order_test6.glade b/tests/toplevel_order_test6.glade
new file mode 100644
index 0000000..8f8cac9
--- /dev/null
+++ b/tests/toplevel_order_test6.glade
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.0 on Fri Nov  1 11:43:04 2013 -->
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <object class="GtkIconFactory" id="iconfactory"/>
+  <object class="GtkLabel" id="label_a">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="margin_bottom">5</property>
+    <property name="label" translatable="yes">label_a</property>
+  </object>
+  <object class="GtkLabel" id="label_b">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="label" translatable="yes">label_b</property>
+  </object>
+  <object class="GtkSizeGroup" id="asizegroup">
+    <widgets>
+      <widget name="label_b"/>
+      <widget name="label_a"/>
+    </widgets>
+  </object>
+  <object class="GtkLabel" id="label_c">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="label" translatable="yes">label_c</property>
+  </object>
+  <object class="GtkAction" id="xaction"/>
+  <object class="GtkActionGroup" id="xactiongroup">
+    <child>
+      <object class="GtkAction" id="action1"/>
+    </child>
+  </object>
+  <object class="GtkWindow" id="anotherwindow">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkBox" id="box2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkButton" id="button1">
+            <property name="related_action">xaction</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="button2">
+            <property name="label" translatable="yes">button</property>
+            <property name="related_action">action1</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkEntryBuffer" id="xentrybuffer"/>
+  <object class="GtkListStore" id="xliststore"/>
+  <object class="GtkTreeView" id="treeview">
+    <property name="visible">True</property>
+    <property name="can_focus">True</property>
+    <property name="model">xliststore</property>
+    <child internal-child="selection">
+      <object class="GtkTreeSelection" id="treeview-selection1"/>
+    </child>
+  </object>
+  <object class="GtkAccelGroup" id="zaccelgroup"/>
+  <object class="GtkWindow" id="awindow">
+    <property name="can_focus">False</property>
+    <accel-groups>
+      <group name="zaccelgroup"/>
+    </accel-groups>
+    <child>
+      <object class="GtkBox" id="box1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <object class="GtkEntry" id="entry1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="buffer">xentrybuffer</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>


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