sl@0: /* sl@0: * Portions copyright (c) 2006-2009 Nokia Corporation. All rights reserved. sl@0: */ sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: #include sl@0: #ifdef __SYMBIAN32__ sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*__SYMBIAN32__*/ sl@0: sl@0: sl@0: /* Obviously we can't test that the operations are atomic, but we can sl@0: * at least test, that they do, what they ought to do */ sl@0: sl@0: int sl@0: main (int argc, sl@0: char *argv[]) sl@0: { sl@0: gint i; sl@0: gint atomic = -5; sl@0: gpointer atomic_pointer = NULL; sl@0: gpointer biggest_pointer = (gpointer)((gsize)atomic_pointer - 1); sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: 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); sl@0: g_set_print_handler(mrtPrintHandler); sl@0: #endif /*__SYMBIAN32__*/ sl@0: sl@0: for (i = 0; i < 15; i++) sl@0: g_atomic_int_inc (&atomic); sl@0: g_assert (atomic == 10); sl@0: for (i = 0; i < 9; i++) sl@0: g_assert (!g_atomic_int_dec_and_test (&atomic)); sl@0: g_assert (g_atomic_int_dec_and_test (&atomic)); sl@0: g_assert (atomic == 0); sl@0: sl@0: g_assert (g_atomic_int_exchange_and_add (&atomic, 5) == 0); sl@0: g_assert (atomic == 5); sl@0: sl@0: g_assert (g_atomic_int_exchange_and_add (&atomic, -10) == 5); sl@0: g_assert (atomic == -5); sl@0: sl@0: g_atomic_int_add (&atomic, 20); sl@0: g_assert (atomic == 15); sl@0: sl@0: g_atomic_int_add (&atomic, -35); sl@0: g_assert (atomic == -20); sl@0: sl@0: g_assert (atomic == g_atomic_int_get (&atomic)); sl@0: sl@0: g_assert (g_atomic_int_compare_and_exchange (&atomic, -20, 20)); sl@0: g_assert (atomic == 20); sl@0: sl@0: g_assert (!g_atomic_int_compare_and_exchange (&atomic, 42, 12)); sl@0: g_assert (atomic == 20); sl@0: sl@0: g_assert (g_atomic_int_compare_and_exchange (&atomic, 20, G_MAXINT)); sl@0: g_assert (atomic == G_MAXINT); sl@0: sl@0: g_assert (g_atomic_int_compare_and_exchange (&atomic, G_MAXINT, G_MININT)); sl@0: g_assert (atomic == G_MININT); sl@0: sl@0: g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer, sl@0: NULL, biggest_pointer)); sl@0: g_assert (atomic_pointer == biggest_pointer); sl@0: sl@0: g_assert (atomic_pointer == g_atomic_pointer_get (&atomic_pointer)); sl@0: sl@0: g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer, sl@0: biggest_pointer, NULL)); sl@0: g_assert (atomic_pointer == NULL); sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("atomic-test"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return 0; sl@0: }