[glib] Move slist tests to the test framework
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Move slist tests to the test framework
- Date: Tue, 6 Jul 2010 03:16:22 +0000 (UTC)
commit 5123bc69e75418c9192a94d802fca76b18444233
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jul 5 21:06:28 2010 -0400
Move slist tests to the test framework
glib/tests/Makefile.am | 3 +
glib/tests/slist.c | 179 ++++++++++++++++++++++++++++++++++++++++++
tests/Makefile.am | 3 -
tests/slist-test.c | 204 ------------------------------------------------
4 files changed, 182 insertions(+), 207 deletions(-)
---
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 626aa9b..8ebbf77 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -102,6 +102,9 @@ convert_LDADD = $(progs_ldadd)
TEST_PROGS += list
list_LDADD = $(progs_ldadd)
+TEST_PROGS += slist
+slist_LDADD = $(progs_ldadd)
+
if OS_UNIX
# some testing of gtester funcitonality
diff --git a/glib/tests/slist.c b/glib/tests/slist.c
new file mode 100644
index 0000000..071f5d5
--- /dev/null
+++ b/glib/tests/slist.c
@@ -0,0 +1,179 @@
+#include <glib.h>
+
+#define SIZE 50
+#define NUMBER_MIN 0000
+#define NUMBER_MAX 9999
+
+
+static guint32 array[SIZE];
+
+
+static gint
+sort (gconstpointer p1, gconstpointer p2)
+{
+ gint32 a, b;
+
+ a = GPOINTER_TO_INT (p1);
+ b = GPOINTER_TO_INT (p2);
+
+ return (a > b ? +1 : a == b ? 0 : -1);
+}
+
+/*
+ * gslist sort tests
+ */
+static void
+test_slist_sort (void)
+{
+ GSList *slist = NULL;
+ gint i;
+
+ for (i = 0; i < SIZE; i++)
+ slist = g_slist_append (slist, GINT_TO_POINTER (array[i]));
+
+ slist = g_slist_sort (slist, sort);
+ for (i = 0; i < SIZE - 1; i++)
+ {
+ gpointer p1, p2;
+
+ p1 = g_slist_nth_data (slist, i);
+ p2 = g_slist_nth_data (slist, i+1);
+
+ g_assert (GPOINTER_TO_INT (p1) <= GPOINTER_TO_INT (p2));
+ }
+
+ g_slist_free (slist);
+}
+
+static void
+test_slist_sort_with_data (void)
+{
+ GSList *slist = NULL;
+ gint i;
+
+ for (i = 0; i < SIZE; i++)
+ slist = g_slist_append (slist, GINT_TO_POINTER (array[i]));
+
+ slist = g_slist_sort_with_data (slist, (GCompareDataFunc)sort, NULL);
+ for (i = 0; i < SIZE - 1; i++)
+ {
+ gpointer p1, p2;
+
+ p1 = g_slist_nth_data (slist, i);
+ p2 = g_slist_nth_data (slist, i+1);
+
+ g_assert (GPOINTER_TO_INT (p1) <= GPOINTER_TO_INT (p2));
+ }
+
+ g_slist_free (slist);
+}
+
+static void
+test_slist_insert_sorted (void)
+{
+ GSList *slist = NULL;
+ gint i;
+
+ for (i = 0; i < SIZE; i++)
+ slist = g_slist_insert_sorted (slist, GINT_TO_POINTER (array[i]), sort);
+
+ for (i = 0; i < SIZE - 1; i++)
+ {
+ gpointer p1, p2;
+
+ p1 = g_slist_nth_data (slist, i);
+ p2 = g_slist_nth_data (slist, i+1);
+
+ g_assert (GPOINTER_TO_INT (p1) <= GPOINTER_TO_INT (p2));
+ }
+
+ g_slist_free (slist);
+}
+
+static void
+test_slist_insert_sorted_with_data (void)
+{
+ GSList *slist = NULL;
+ gint i;
+
+ for (i = 0; i < SIZE; i++)
+ slist = g_slist_insert_sorted_with_data (slist,
+ GINT_TO_POINTER (array[i]),
+ (GCompareDataFunc)sort,
+ NULL);
+
+ for (i = 0; i < SIZE - 1; i++)
+ {
+ gpointer p1, p2;
+
+ p1 = g_slist_nth_data (slist, i);
+ p2 = g_slist_nth_data (slist, i+1);
+
+ g_assert (GPOINTER_TO_INT (p1) <= GPOINTER_TO_INT (p2));
+ }
+
+ g_slist_free (slist);
+}
+
+static void
+test_slist_reverse (void)
+{
+ GSList *slist = NULL;
+ GSList *st;
+ gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ gint i;
+
+ for (i = 0; i < 10; i++)
+ slist = g_slist_append (slist, &nums[i]);
+
+ slist = g_slist_reverse (slist);
+
+ for (i = 0; i < 10; i++)
+ {
+ st = g_slist_nth (slist, i);
+ g_assert (*((gint*) st->data) == (9 - i));
+ }
+
+ g_slist_free (slist);
+}
+
+static void
+test_slist_nth (void)
+{
+ GSList *slist = NULL;
+ GSList *st;
+ gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ gint i;
+
+ for (i = 0; i < 10; i++)
+ slist = g_slist_append (slist, &nums[i]);
+
+ for (i = 0; i < 10; i++)
+ {
+ st = g_slist_nth (slist, i);
+ g_assert (*((gint*) st->data) == i);
+ }
+
+ g_slist_free (slist);
+}
+
+int
+main (int argc, char *argv[])
+{
+ gint i;
+
+ g_test_init (&argc, &argv, NULL);
+
+ /* Create an array of random numbers. */
+ for (i = 0; i < SIZE; i++)
+ array[i] = g_test_rand_int_range (NUMBER_MIN, NUMBER_MAX);
+
+ g_test_add_func ("/slist/sort", test_slist_sort);
+ g_test_add_func ("/slist/sort-with-data", test_slist_sort_with_data);
+ g_test_add_func ("/slist/insert-sorted", test_slist_insert_sorted);
+ g_test_add_func ("/slist/insert-sorted-with-data", test_slist_insert_sorted_with_data);
+ g_test_add_func ("/slist/reverse", test_slist_reverse);
+ g_test_add_func ("/slist/nth", test_slist_nth);
+
+ return g_test_run ();
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2e623c2..c4e05b4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -94,7 +94,6 @@ test_programs = \
env-test \
gio-test \
iochannel-test \
- list-test \
mainloop-test \
mapping-test \
markup-collect \
@@ -107,7 +106,6 @@ test_programs = \
qsort-test \
relation-test \
shell-test \
- slist-test \
slice-test \
slice-color \
slice-concurrent \
@@ -162,7 +160,6 @@ asyncqueue_test_LDADD = $(thread_ldadd)
qsort_test_LDADD = $(progs_ldadd)
relation_test_LDADD = $(progs_ldadd)
shell_test_LDADD = $(progs_ldadd)
-slist_test_LDADD = $(progs_ldadd)
slice_test_SOURCES = slice-test.c memchunks.c
slice_test_LDADD = $(thread_ldadd)
slice_color_SOURCES = slice-color.c memchunks.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]