make tests not dynamic link against /lib/libglib
[platform/upstream/glib.git] / tests / queue-test.c
index 688b56e..448e8bd 100644 (file)
@@ -1,14 +1,15 @@
 #undef G_DISABLE_ASSERT
 #undef G_LOG_DOMAIN
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-#include <glib.h>
-
 #include <time.h>
 #include <stdlib.h>
 
+#include <glib.h>
+
+
+static gboolean verbose = FALSE;
+
+
 static void
 check_integrity (GQueue *queue)
 {
@@ -225,7 +226,9 @@ random_test (int seed)
   QueueOp op;
   QueueInfo queues[N_QUEUES];
 
-  g_print ("seed: %d\n", seed);
+  if (verbose)
+    g_print ("seed: %d\n", seed);
+
   g_random_set_seed (seed);
   
   for (i = 0; i < N_QUEUES; ++i)
@@ -748,6 +751,9 @@ int main(int argc, gchar *args[])
   gpointer data;
   int i;
   
+  if (argc > 1 && args[1][0] == '-' && args[1][1] == 'v')
+    verbose = TRUE;
+
   q = g_queue_new ();
   
   g_assert (g_queue_is_empty (q) == TRUE);
@@ -927,14 +933,30 @@ int main(int argc, gchar *args[])
   g_queue_foreach (q2, remove_item, q2);
   check_integrity (q2);
   check_integrity (q);
+
+  /* some checks for off by one errors */  
+  g_queue_push_tail (q, GINT_TO_POINTER (1234));
+  check_integrity (q);
+  node = g_queue_peek_tail_link (q);
+  g_assert (node != NULL && node->data == GINT_TO_POINTER (1234));
+  node = g_queue_peek_nth_link (q, g_queue_get_length (q));
+  g_assert (node == NULL);
+  node = g_queue_peek_nth_link (q, g_queue_get_length (q) - 1);
+  g_assert (node->data == GINT_TO_POINTER (1234));
+  node = g_queue_pop_nth_link (q, g_queue_get_length (q));
+  g_assert (node == NULL);
+  node = g_queue_pop_nth_link (q, g_queue_get_length (q) - 1);
+  g_assert (node != NULL && node->data == GINT_TO_POINTER (1234));
   
   g_queue_free (q);
 
+  if (argc > 2 && args[1][0] == '-' && args[1][1] == 'v')
+    random_test (strtol (args[2], NULL, 0));    
   if (argc > 1)
     random_test (strtol (args[1], NULL, 0));
   else
-    random_test (time (0));
-  
+    random_test (time (0));  
+
   return 0;
 }