glib/tests/qsort-test.c
changeset 18 47c74d1534e1
child 34 5fae379060a7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/glib/tests/qsort-test.c	Fri Apr 16 16:46:38 2010 +0300
@@ -0,0 +1,65 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+
+#undef G_DISABLE_ASSERT
+#undef G_LOG_DOMAIN
+
+#include <glib.h>
+
+#include <stdio.h>
+#ifdef __SYMBIAN32__
+#include "mrt2_glib2_test.h"
+#endif /*__SYMBIAN32__*/
+
+
+#define SIZE 100000
+
+guint32 array[SIZE];
+
+static gint
+sort (gconstpointer a, gconstpointer b, gpointer user_data)
+{
+  return *(guint32*)a < *(guint32*)b ? -1 : 1;
+}
+
+int
+main ()
+{
+  int i;
+
+  #ifdef __SYMBIAN32__
+  g_log_set_handler (NULL,  G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
+  g_set_print_handler(mrtPrintHandler);
+  #endif /*__SYMBIAN32__*/
+	  
+
+  for (i = 0; i < SIZE; i++)
+    array[i] = g_random_int ();
+
+  g_qsort_with_data (array, SIZE, sizeof (guint32), sort, NULL);
+
+  for (i = 0; i < SIZE - 1; i++)
+    g_assert (array[i] <= array[i+1]);
+
+  /* 0 elemenents is a valid case */
+  g_qsort_with_data (array, 0, sizeof (guint32), sort, NULL);
+
+#ifdef __SYMBIAN32__
+  testResultXml("qsort-test");
+#endif /* EMULATOR */
+  return 0;
+}