os/ossrv/glib/tsrc/BC/tests/atomic-test.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/glib/tsrc/BC/tests/atomic-test.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,80 @@
     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 +#include <stdio.h>
    1.10 +
    1.11 +#ifdef SYMBIAN
    1.12 +#include "mrt2_glib2_test.h"
    1.13 +#endif /*SYMBIAN*/
    1.14 +
    1.15 +
    1.16 +/* Obviously we can't test that the operations are atomic, but we can
    1.17 + * at least test, that they do, what they ought to do */
    1.18 +
    1.19 +int 
    1.20 +main (int   argc,
    1.21 +      char *argv[])
    1.22 +{
    1.23 +  gint i;
    1.24 +  gint atomic = -5;
    1.25 +  gpointer atomic_pointer = NULL;
    1.26 +  
    1.27 +  gpointer biggest_pointer = (gpointer)((gsize)atomic_pointer - 1);
    1.28 +  
    1.29 +  #ifdef SYMBIAN
    1.30 +  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.31 +  g_set_print_handler(mrtPrintHandler);
    1.32 +  #endif /*SYMBIAN*/
    1.33 +
    1.34 +  for (i = 0; i < 15; i++)
    1.35 +    g_atomic_int_inc (&atomic);
    1.36 +  g_assert (atomic == 10);
    1.37 +  for (i = 0; i < 9; i++)
    1.38 +    g_assert (!g_atomic_int_dec_and_test (&atomic));
    1.39 +  g_assert (g_atomic_int_dec_and_test (&atomic));
    1.40 +  g_assert (atomic == 0);
    1.41 +
    1.42 +  g_assert (g_atomic_int_exchange_and_add (&atomic, 5) == 0);
    1.43 +  g_assert (atomic == 5);
    1.44 +
    1.45 +  g_assert (g_atomic_int_exchange_and_add (&atomic, -10) == 5);
    1.46 +  g_assert (atomic == -5);
    1.47 +
    1.48 +  g_atomic_int_add (&atomic, 20);
    1.49 +  g_assert (atomic == 15);
    1.50 +
    1.51 +  g_atomic_int_add (&atomic, -35);
    1.52 +  g_assert (atomic == -20);
    1.53 +
    1.54 +  g_assert (atomic == g_atomic_int_get (&atomic));
    1.55 +
    1.56 +  g_assert (g_atomic_int_compare_and_exchange (&atomic, -20, 20));
    1.57 +  g_assert (atomic == 20);
    1.58 +  
    1.59 +  g_assert (!g_atomic_int_compare_and_exchange (&atomic, 42, 12));
    1.60 +  g_assert (atomic == 20);
    1.61 +  
    1.62 +  g_assert (g_atomic_int_compare_and_exchange (&atomic, 20, G_MAXINT));
    1.63 +  g_assert (atomic == G_MAXINT);
    1.64 +
    1.65 +  g_assert (g_atomic_int_compare_and_exchange (&atomic, G_MAXINT, G_MININT));
    1.66 +  g_assert (atomic == G_MININT);
    1.67 +
    1.68 +  g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer, 
    1.69 +						   NULL, biggest_pointer));
    1.70 +  g_assert (atomic_pointer == biggest_pointer);
    1.71 +
    1.72 +  g_assert (atomic_pointer == g_atomic_pointer_get (&atomic_pointer));
    1.73 +
    1.74 +  g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer, 
    1.75 +						   biggest_pointer, NULL));
    1.76 +  g_assert (atomic_pointer == NULL);
    1.77 +  
    1.78 +  #ifdef SYMBIAN
    1.79 +  testResultXml("atomic-test");
    1.80 +  #endif /* EMULATOR */
    1.81 +  
    1.82 +  return 0;
    1.83 +}