Update contrib.
1 /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. */
2 #undef G_DISABLE_ASSERT
9 #include "mrt2_glib2_test.h"
13 /* Obviously we can't test that the operations are atomic, but we can
14 * at least test, that they do, what they ought to do */
22 gpointer atomic_pointer = NULL;
24 gpointer biggest_pointer = (gpointer)((gsize)atomic_pointer - 1);
27 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);
28 g_set_print_handler(mrtPrintHandler);
31 for (i = 0; i < 15; i++)
32 g_atomic_int_inc (&atomic);
33 g_assert (atomic == 10);
34 for (i = 0; i < 9; i++)
35 g_assert (!g_atomic_int_dec_and_test (&atomic));
36 g_assert (g_atomic_int_dec_and_test (&atomic));
37 g_assert (atomic == 0);
39 g_assert (g_atomic_int_exchange_and_add (&atomic, 5) == 0);
40 g_assert (atomic == 5);
42 g_assert (g_atomic_int_exchange_and_add (&atomic, -10) == 5);
43 g_assert (atomic == -5);
45 g_atomic_int_add (&atomic, 20);
46 g_assert (atomic == 15);
48 g_atomic_int_add (&atomic, -35);
49 g_assert (atomic == -20);
51 g_assert (atomic == g_atomic_int_get (&atomic));
53 g_assert (g_atomic_int_compare_and_exchange (&atomic, -20, 20));
54 g_assert (atomic == 20);
56 g_assert (!g_atomic_int_compare_and_exchange (&atomic, 42, 12));
57 g_assert (atomic == 20);
59 g_assert (g_atomic_int_compare_and_exchange (&atomic, 20, G_MAXINT));
60 g_assert (atomic == G_MAXINT);
62 g_assert (g_atomic_int_compare_and_exchange (&atomic, G_MAXINT, G_MININT));
63 g_assert (atomic == G_MININT);
65 g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer,
66 NULL, biggest_pointer));
67 g_assert (atomic_pointer == biggest_pointer);
69 g_assert (atomic_pointer == g_atomic_pointer_get (&atomic_pointer));
71 g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer,
72 biggest_pointer, NULL));
73 g_assert (atomic_pointer == NULL);
76 testResultXml("atomic-test");