[model/wip/api-redesign] Added missing test files



commit 815cbe1830fd2e0a2bd60f19974040f898eac024
Author: Alberto Ruiz <aruiz gnome org>
Date:   Sun Oct 28 02:54:59 2012 +0100

    Added missing test files

 tests/Makefile.am        |    9 +++
 tests/test-simple-list.c |  144 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..c581b2e
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,9 @@
+check_PROGRAMS = test-simplelist
+
+TESTS = $(check_PROGRAMS)
+
+test_simplelist_SOURCES = test-simple-list.c
+
+test_simplelist_CFLAGS = $(gobject_CFLAGS) -I$(top_srcdir)/model
+test_simplelist_LDADD = $(top_builddir)/model/libmodel.la 
+test_simplelist_LDFLAGS = $(gobject_LIBS)
diff --git a/tests/test-simple-list.c b/tests/test-simple-list.c
new file mode 100644
index 0000000..c931be4
--- /dev/null
+++ b/tests/test-simple-list.c
@@ -0,0 +1,144 @@
+#include <model.h>
+#include <model-implementation.h>
+#include <glib.h>
+
+GMainLoop *ml;
+
+void
+insert_insert_cb (ModelSimpleList *sl,
+                  gulong           pos,
+                  gulong           rem,
+                  gulong           ins,
+                  gboolean         more,
+                  gpointer         user_data)
+{
+  *((gboolean*)user_data) = TRUE;
+
+  g_assert (pos == 0);
+  g_assert (ins == 1);
+  g_assert (rem == 0);
+
+  return;
+}
+
+void
+insert_append_cb (ModelSimpleList *sl,
+                  gulong           pos,
+                  gulong           rem,
+                  gulong           ins,
+                  gboolean         more,
+                  gpointer         user_data)
+{
+  *((gboolean*)user_data) = TRUE;
+
+  g_assert (pos == 1);
+  g_assert (ins == 1);
+  g_assert (rem == 0);
+
+  g_main_loop_quit (ml);
+  return;
+}
+
+void
+insert_remove_cb (ModelSimpleList *sl,
+                  gulong           pos,
+                  gulong           rem,
+                  gulong           ins,
+                  gboolean         more,
+                  gpointer         user_data)
+{
+  *((gboolean*)user_data) = TRUE;
+
+  g_assert (pos == 1);
+  g_assert (ins == 0);
+  g_assert (rem == 1);
+
+  g_main_loop_quit (ml);
+  return;
+}
+
+gboolean
+timeout (gpointer user_data)
+{
+  g_main_loop_quit (ml);
+  return FALSE;
+}
+
+void
+callback_called (gboolean* called)
+{
+  guint id;
+  id = g_idle_add_full (G_PRIORITY_LOW, timeout, called, NULL);
+  g_main_loop_run (ml);
+  g_assert (*called);
+  *called = FALSE;
+  g_source_remove (id);
+}
+
+void insert ()
+{
+  guint id;
+  gboolean called = FALSE;
+
+  ModelSimpleList *sl = model_simple_list_new ();
+
+  /* Test insert and its callback */
+  id = g_signal_connect (sl, "changed", G_CALLBACK (insert_insert_cb), &called);
+  model_simple_list_insert (sl, 0, G_OBJECT (sl));
+  callback_called (&called);
+  g_signal_handler_disconnect (sl, id);
+
+  /* Test content and n_children upon insert */
+  g_assert (model_list_n_children (MODEL_LIST (sl)) == 1);
+  g_assert (G_OBJECT(sl) == model_list_get_child (MODEL_LIST (sl), 0));
+
+  /* Test append and its callback */
+  id = g_signal_connect (sl, "changed", G_CALLBACK (insert_append_cb), &called);
+  model_simple_list_append (sl, G_OBJECT(sl));
+  callback_called (&called);
+  g_signal_handler_disconnect (sl, id);
+
+  /* Test content and n_children upon insert */
+  g_assert(model_list_n_children (MODEL_LIST (sl)) == 2);
+  g_assert(G_OBJECT(sl) == model_list_get_child (MODEL_LIST (sl), 1));
+
+  g_object_unref (sl);
+}
+
+void splice ()
+{
+  int i;
+  ModelSimpleList *sl = model_simple_list_new ();
+
+  GObject* abcd[4] = {model_integer_new (1), model_integer_new (2), model_integer_new (3), model_integer_new (4)};
+  GObject* bc[4]   = {abcd[1],abcd[2]};
+
+  g_object_ref(abcd[0]);
+  g_object_ref(abcd[1]);
+  g_object_ref(abcd[2]);
+  g_object_ref(abcd[3]);
+
+  model_simple_list_splice (sl, 0, 0, abcd, 4, FALSE);
+  g_assert(model_list_n_children (MODEL_LIST (sl)) == 4);
+  model_simple_list_splice (sl, 0, 4, NULL, 0, FALSE);
+  g_assert(model_list_n_children (MODEL_LIST (sl)) == 0);
+
+  g_object_unref(sl);
+
+  for (i = 0; i < 4; i++)
+    g_object_unref (abcd[i]);
+}
+
+int main (int argc, char** argv)
+{
+  g_type_init ();
+  g_test_init (&argc, &argv, NULL);
+
+  ml = g_main_loop_new (NULL, FALSE);
+  g_test_add_func("/model/list/simple/splice", splice);
+  g_test_add_func("/model/list/simple/insert", insert);
+
+  g_test_run ();
+  g_main_loop_unref (ml);
+  return 0;
+}



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