summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Janik <timj@gtk.org>1999-07-24 18:50:58 +0000
committerTim Janik <timj@src.gnome.org>1999-07-24 18:50:58 +0000
commit87c7aeb93bd654776f59805a342ad913031034f3 (patch)
tree4f43e0cefcbe83a51ffe9aeb24f3386f519a071d /tests
parentc8a28b935ca605ece11c65564ad1d3918786dd07 (diff)
downloadglib-87c7aeb93bd654776f59805a342ad913031034f3.tar.gz
18:36. incorporated proposed cleanups from gtk-devel-list.
Sat Jul 24 20:11:35 1999 Tim Janik <timj@gtk.org> * merged GLib 1.3.0 with glib-1.2.3 from Fri Jul 16 22:18:36. * incorporated proposed cleanups from gtk-devel-list. * bumped version number to GLib-1.3.1 * glib.h: * gqueue.c: * gstring.c: * glist.c: removed string tokenisation (we got g_strsplit() and g_strjoin() already) and readline functions. s/g_list_delete/g_list_delete_link. implemented g_slist_delete_link. removed notion of g_ATEXIT() macro in glib.h, this is an *internal* macro, g_atexit() is provided for public consumption. added GTrashStack inline utility functions. reimplement double eneded queues. removed GStack implementation, people can use a queue or a (singly) linked list for this task. deprecated g_strescape(), we need the SunOS variants here. * gdate.c: added DEBUG_MSG() macro to wrap old messages. * *.*: CVS merges. * upgrade to libtool 1.3.3.
Diffstat (limited to 'tests')
-rw-r--r--tests/.cvsignore1
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/queue-test.c148
-rw-r--r--tests/stack-test.c51
4 files changed, 93 insertions, 112 deletions
diff --git a/tests/.cvsignore b/tests/.cvsignore
index b0f11eec9..96958a1fa 100644
--- a/tests/.cvsignore
+++ b/tests/.cvsignore
@@ -34,7 +34,6 @@ dirname-test
type-test
strfunc-test
queue-test
-stack-test
date-test
rand-test
thread-test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cd59973e4..1398ede01 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,6 +5,9 @@ EXTRA_DIST = \
makefile.msc \
makefile.cygwin
+EXTRA_DIST = \
+ makefile.msc
+
TESTS = \
array-test \
date-test \
@@ -16,7 +19,6 @@ TESTS = \
rand-test \
relation-test \
slist-test \
- stack-test \
strfunc-test \
string-test \
thread-test \
@@ -35,7 +37,6 @@ queue_test_LDADD = $(top_builddir)/libglib.la
rand_test_LDADD = $(top_builddir)/libglib.la
relation_test_LDADD = $(top_builddir)/libglib.la
slist_test_LDADD = $(top_builddir)/libglib.la
-stack_test_LDADD = $(top_builddir)/libglib.la
strfunc_test_LDADD = $(top_builddir)/libglib.la
string_test_LDADD = $(top_builddir)/libglib.la
thread_test_LDADD = $(top_builddir)/libglib.la \
diff --git a/tests/queue-test.c b/tests/queue-test.c
index 6985bcc22..21f47d9f9 100644
--- a/tests/queue-test.c
+++ b/tests/queue-test.c
@@ -6,75 +6,107 @@
int main()
{
GQueue *q;
+ GList *node;
+ gpointer data;
- q = g_queue_new ();
+ q = g_queue_create ();
- g_assert (g_queue_empty (q) == TRUE);
+ g_assert (g_queue_is_empty (q) == TRUE);
- g_queue_push (q, GINT_TO_POINTER (1));
- g_assert (g_list_length (q->list) == 1);
- g_queue_push (q, GINT_TO_POINTER (2));
- g_assert (g_list_length (q->list) == 2);
- g_queue_push (q, GINT_TO_POINTER (3));
- g_assert (g_list_length (q->list) == 3);
- g_queue_push (q, GINT_TO_POINTER (4));
- g_assert (g_list_length (q->list) == 4);
- g_queue_push (q, GINT_TO_POINTER (5));
- g_assert (g_list_length (q->list) == 5);
+ g_queue_push_head (q, GINT_TO_POINTER (2));
+ g_assert (g_queue_peek_head (q) == GINT_TO_POINTER (2));
+ g_assert (g_queue_is_empty (q) == FALSE);
+ g_assert (g_list_length (q->head) == 1);
+ g_assert (q->head == q->tail);
+ g_queue_push_head (q, GINT_TO_POINTER (1));
+ g_assert (q->head->next == q->tail);
+ g_assert (q->tail->prev == q->head);
+ g_assert (g_list_length (q->head) == 2);
+ g_assert (q->tail->data == GINT_TO_POINTER (2));
+ g_assert (q->head->data == GINT_TO_POINTER (1));
+ g_queue_push_tail (q, GINT_TO_POINTER (3));
+ g_assert (g_list_length (q->head) == 3);
+ g_assert (q->head->data == GINT_TO_POINTER (1));
+ g_assert (q->head->next->data == GINT_TO_POINTER (2));
+ g_assert (q->head->next->next == q->tail);
+ g_assert (q->head->next == q->tail->prev);
+ g_assert (q->tail->data == GINT_TO_POINTER (3));
+ g_queue_push_tail (q, GINT_TO_POINTER (4));
+ g_assert (g_list_length (q->head) == 4);
+ g_assert (q->head->data == GINT_TO_POINTER (1));
+ g_assert (g_queue_peek_tail (q) == GINT_TO_POINTER (4));
+ g_queue_push_tail (q, GINT_TO_POINTER (5));
+ g_assert (g_list_length (q->head) == 5);
- g_assert (g_queue_empty (q) == FALSE);
+ g_assert (g_queue_is_empty (q) == FALSE);
- g_assert (g_queue_index (q, GINT_TO_POINTER (2)) == 1);
- g_assert (g_queue_index (q, GINT_TO_POINTER (142)) == -1);
+ g_assert (q->length == 5);
+ g_assert (q->head->prev == NULL);
+ g_assert (q->head->data == GINT_TO_POINTER (1));
+ g_assert (q->head->next->data == GINT_TO_POINTER (2));
+ g_assert (q->head->next->next->data == GINT_TO_POINTER (3));
+ g_assert (q->head->next->next->next->data == GINT_TO_POINTER (4));
+ g_assert (q->head->next->next->next->next->data == GINT_TO_POINTER (5));
+ g_assert (q->head->next->next->next->next->next == NULL);
+ g_assert (q->head->next->next->next->next == q->tail);
+ g_assert (q->tail->data == GINT_TO_POINTER (5));
+ g_assert (q->tail->prev->data == GINT_TO_POINTER (4));
+ g_assert (q->tail->prev->prev->data == GINT_TO_POINTER (3));
+ g_assert (q->tail->prev->prev->prev->data == GINT_TO_POINTER (2));
+ g_assert (q->tail->prev->prev->prev->prev->data == GINT_TO_POINTER (1));
+ g_assert (q->tail->prev->prev->prev->prev->prev == NULL);
+ g_assert (q->tail->prev->prev->prev->prev == q->head);
+ g_assert (g_queue_peek_tail (q) == GINT_TO_POINTER (5));
+ g_assert (g_queue_peek_head (q) == GINT_TO_POINTER (1));
- g_assert (g_queue_peek (q) == GINT_TO_POINTER (1));
- g_assert (g_queue_peek_front (q) == GINT_TO_POINTER (1));
- g_assert (g_queue_peek_back (q) == GINT_TO_POINTER (5));
+ g_assert (g_queue_pop_head (q) == GINT_TO_POINTER (1));
+ g_assert (g_list_length (q->head) == 4 && q->length == 4);
+ g_assert (g_queue_pop_tail (q) == GINT_TO_POINTER (5));
+ g_assert (g_list_length (q->head) == 3);
+ g_assert (g_queue_pop_head_link (q)->data == GINT_TO_POINTER (2));
+ g_assert (g_list_length (q->head) == 2);
+ g_assert (g_queue_pop_tail (q) == GINT_TO_POINTER (4));
+ g_assert (g_list_length (q->head) == 1);
+ g_assert (g_queue_pop_head_link (q)->data == GINT_TO_POINTER (3));
+ g_assert (g_list_length (q->head) == 0);
+ g_assert (g_queue_pop_tail (q) == NULL);
+ g_assert (g_list_length (q->head) == 0);
+ g_assert (g_queue_pop_head (q) == NULL);
+ g_assert (g_list_length (q->head) == 0);
- g_assert (g_queue_pop (q) == GINT_TO_POINTER (1));
- g_assert (g_list_length (q->list) == 4);
- g_assert (g_queue_pop (q) == GINT_TO_POINTER (2));
- g_assert (g_list_length (q->list) == 3);
- g_assert (g_queue_pop (q) == GINT_TO_POINTER (3));
- g_assert (g_list_length (q->list) == 2);
- g_assert (g_queue_pop (q) == GINT_TO_POINTER (4));
- g_assert (g_list_length (q->list) == 1);
- g_assert (g_queue_pop (q) == GINT_TO_POINTER (5));
- g_assert (g_list_length (q->list) == 0);
- g_assert (g_queue_pop (q) == NULL);
- g_assert (g_list_length (q->list) == 0);
- g_assert (g_queue_pop (q) == NULL);
- g_assert (g_list_length (q->list) == 0);
-
- g_assert (g_queue_empty (q) == TRUE);
+ g_assert (g_queue_is_empty (q) == TRUE);
/************************/
- g_queue_push_front (q, GINT_TO_POINTER (1));
- g_assert (g_list_length (q->list) == 1);
- g_queue_push_front (q, GINT_TO_POINTER (2));
- g_assert (g_list_length (q->list) == 2);
- g_queue_push_front (q, GINT_TO_POINTER (3));
- g_assert (g_list_length (q->list) == 3);
- g_queue_push_front (q, GINT_TO_POINTER (4));
- g_assert (g_list_length (q->list) == 4);
- g_queue_push_front (q, GINT_TO_POINTER (5));
- g_assert (g_list_length (q->list) == 5);
+ g_queue_push_head (q, GINT_TO_POINTER (1));
+ g_assert (g_list_length (q->head) == 1 && 1 == q->length);
+ g_queue_push_head (q, GINT_TO_POINTER (2));
+ g_assert (g_list_length (q->head) == 2 && 2 == q->length);
+ g_queue_push_head (q, GINT_TO_POINTER (3));
+ g_assert (g_list_length (q->head) == 3 && 3 == q->length);
+ g_queue_push_head (q, GINT_TO_POINTER (4));
+ g_assert (g_list_length (q->head) == 4 && 4 == q->length);
+ g_queue_push_head (q, GINT_TO_POINTER (5));
+ g_assert (g_list_length (q->head) == 5 && 5 == q->length);
- g_assert (g_queue_pop_front (q) == GINT_TO_POINTER (5));
- g_assert (g_list_length (q->list) == 4);
- g_assert (g_queue_pop_front (q) == GINT_TO_POINTER (4));
- g_assert (g_list_length (q->list) == 3);
- g_assert (g_queue_pop_front (q) == GINT_TO_POINTER (3));
- g_assert (g_list_length (q->list) == 2);
- g_assert (g_queue_pop_front (q) == GINT_TO_POINTER (2));
- g_assert (g_list_length (q->list) == 1);
- g_assert (g_queue_pop_front (q) == GINT_TO_POINTER (1));
- g_assert (g_list_length (q->list) == 0);
- g_assert (g_queue_pop_front (q) == NULL);
- g_assert (g_list_length (q->list) == 0);
- g_assert (g_queue_pop_front (q) == NULL);
- g_assert (g_list_length (q->list) == 0);
+ g_assert (g_queue_pop_head (q) == GINT_TO_POINTER (5));
+ g_assert (g_list_length (q->head) == 4);
+ node = q->tail;
+ g_assert (node == g_queue_pop_tail_link (q));
+ g_assert (g_list_length (q->head) == 3);
+ data = q->head->data;
+ g_assert (data == g_queue_pop_head (q));
+ g_assert (g_list_length (q->head) == 2);
+ g_assert (g_queue_pop_tail (q) == GINT_TO_POINTER (2));
+ g_assert (g_list_length (q->head) == 1);
+ g_assert (q->head == q->tail);
+ g_assert (g_queue_pop_tail (q) == GINT_TO_POINTER (3));
+ g_assert (g_list_length (q->head) == 0);
+ g_assert (g_queue_pop_head (q) == NULL);
+ g_assert (g_queue_pop_head_link (q) == NULL);
+ g_assert (g_list_length (q->head) == 0);
+ g_assert (g_queue_pop_tail_link (q) == NULL);
+ g_assert (g_list_length (q->head) == 0);
g_queue_free (q);
diff --git a/tests/stack-test.c b/tests/stack-test.c
deleted file mode 100644
index f29378ba3..000000000
--- a/tests/stack-test.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <glib.h>
-
-int main()
-{
- GStack *s;
-
- s = g_stack_new ();
-
- g_assert (g_stack_empty (s) == TRUE);
-
- g_stack_push (s, GINT_TO_POINTER (1));
- g_assert (g_list_length (s->list) == 1);
- g_stack_push (s, GINT_TO_POINTER (2));
- g_assert (g_list_length (s->list) == 2);
- g_stack_push (s, GINT_TO_POINTER (3));
- g_assert (g_list_length (s->list) == 3);
- g_stack_push (s, GINT_TO_POINTER (4));
- g_assert (g_list_length (s->list) == 4);
- g_stack_push (s, GINT_TO_POINTER (5));
- g_assert (g_list_length (s->list) == 5);
-
- g_assert (g_stack_index (s, GINT_TO_POINTER (2)) == 3);
-
- g_assert (g_stack_empty (s) == FALSE);
-
- g_assert (g_stack_peek (s) == GINT_TO_POINTER (5));
-
- g_assert (g_stack_pop (s) == GINT_TO_POINTER (5));
- g_assert (g_list_length (s->list) == 4);
- g_assert (g_stack_pop (s) == GINT_TO_POINTER (4));
- g_assert (g_list_length (s->list) == 3);
- g_assert (g_stack_pop (s) == GINT_TO_POINTER (3));
- g_assert (g_list_length (s->list) == 2);
- g_assert (g_stack_pop (s) == GINT_TO_POINTER (2));
- g_assert (g_list_length (s->list) == 1);
- g_assert (g_stack_pop (s) == GINT_TO_POINTER (1));
- g_assert (g_list_length (s->list) == 0);
- g_assert (g_stack_pop (s) == NULL);
- g_assert (g_list_length (s->list) == 0);
- g_assert (g_stack_pop (s) == NULL);
- g_assert (g_list_length (s->list) == 0);
-
- g_stack_free (s);
-
- return 0;
-}
-