os/ossrv/glib/tests/qsort-test.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/glib/tests/qsort-test.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,49 @@
     1.4 +/* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
     1.5 +#undef G_DISABLE_ASSERT
     1.6 +#undef G_LOG_DOMAIN
     1.7 +
     1.8 +#include <glib.h>
     1.9 +
    1.10 +#include <stdio.h>
    1.11 +#ifdef __SYMBIAN32__
    1.12 +#include "mrt2_glib2_test.h"
    1.13 +#endif /*__SYMBIAN32__*/
    1.14 +
    1.15 +
    1.16 +#define SIZE 100000
    1.17 +
    1.18 +guint32 array[SIZE];
    1.19 +
    1.20 +static gint
    1.21 +sort (gconstpointer a, gconstpointer b, gpointer user_data)
    1.22 +{
    1.23 +  return *(guint32*)a < *(guint32*)b ? -1 : 1;
    1.24 +}
    1.25 +
    1.26 +int
    1.27 +main ()
    1.28 +{
    1.29 +  int i;
    1.30 +
    1.31 +  #ifdef __SYMBIAN32__
    1.32 +  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);
    1.33 +  g_set_print_handler(mrtPrintHandler);
    1.34 +  #endif /*__SYMBIAN32__*/
    1.35 +	  
    1.36 +
    1.37 +  for (i = 0; i < SIZE; i++)
    1.38 +    array[i] = g_random_int ();
    1.39 +
    1.40 +  g_qsort_with_data (array, SIZE, sizeof (guint32), sort, NULL);
    1.41 +
    1.42 +  for (i = 0; i < SIZE - 1; i++)
    1.43 +    g_assert (array[i] <= array[i+1]);
    1.44 +
    1.45 +  /* 0 elemenents is a valid case */
    1.46 +  g_qsort_with_data (array, 0, sizeof (guint32), sort, NULL);
    1.47 +
    1.48 +#ifdef __SYMBIAN32__
    1.49 +  testResultXml("qsort-test");
    1.50 +#endif /* EMULATOR */
    1.51 +  return 0;
    1.52 +}