|
1 /* |
|
2 * Portions copyright (c) 2006-2009 Nokia Corporation. All rights reserved. |
|
3 */ |
|
4 #undef G_DISABLE_ASSERT |
|
5 #undef G_LOG_DOMAIN |
|
6 |
|
7 #include <glib.h> |
|
8 #ifdef __SYMBIAN32__ |
|
9 #include "mrt2_glib2_test.h" |
|
10 #endif /*__SYMBIAN32__*/ |
|
11 |
|
12 |
|
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 */ |
|
15 |
|
16 int |
|
17 main (int argc, |
|
18 char *argv[]) |
|
19 { |
|
20 gint i; |
|
21 gint atomic = -5; |
|
22 gpointer atomic_pointer = NULL; |
|
23 gpointer biggest_pointer = (gpointer)((gsize)atomic_pointer - 1); |
|
24 |
|
25 #ifdef __SYMBIAN32__ |
|
26 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); |
|
27 g_set_print_handler(mrtPrintHandler); |
|
28 #endif /*__SYMBIAN32__*/ |
|
29 |
|
30 for (i = 0; i < 15; i++) |
|
31 g_atomic_int_inc (&atomic); |
|
32 g_assert (atomic == 10); |
|
33 for (i = 0; i < 9; i++) |
|
34 g_assert (!g_atomic_int_dec_and_test (&atomic)); |
|
35 g_assert (g_atomic_int_dec_and_test (&atomic)); |
|
36 g_assert (atomic == 0); |
|
37 |
|
38 g_assert (g_atomic_int_exchange_and_add (&atomic, 5) == 0); |
|
39 g_assert (atomic == 5); |
|
40 |
|
41 g_assert (g_atomic_int_exchange_and_add (&atomic, -10) == 5); |
|
42 g_assert (atomic == -5); |
|
43 |
|
44 g_atomic_int_add (&atomic, 20); |
|
45 g_assert (atomic == 15); |
|
46 |
|
47 g_atomic_int_add (&atomic, -35); |
|
48 g_assert (atomic == -20); |
|
49 |
|
50 g_assert (atomic == g_atomic_int_get (&atomic)); |
|
51 |
|
52 g_assert (g_atomic_int_compare_and_exchange (&atomic, -20, 20)); |
|
53 g_assert (atomic == 20); |
|
54 |
|
55 g_assert (!g_atomic_int_compare_and_exchange (&atomic, 42, 12)); |
|
56 g_assert (atomic == 20); |
|
57 |
|
58 g_assert (g_atomic_int_compare_and_exchange (&atomic, 20, G_MAXINT)); |
|
59 g_assert (atomic == G_MAXINT); |
|
60 |
|
61 g_assert (g_atomic_int_compare_and_exchange (&atomic, G_MAXINT, G_MININT)); |
|
62 g_assert (atomic == G_MININT); |
|
63 |
|
64 g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer, |
|
65 NULL, biggest_pointer)); |
|
66 g_assert (atomic_pointer == biggest_pointer); |
|
67 |
|
68 g_assert (atomic_pointer == g_atomic_pointer_get (&atomic_pointer)); |
|
69 |
|
70 g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer, |
|
71 biggest_pointer, NULL)); |
|
72 g_assert (atomic_pointer == NULL); |
|
73 |
|
74 #ifdef __SYMBIAN32__ |
|
75 testResultXml("atomic-test"); |
|
76 #endif /* EMULATOR */ |
|
77 |
|
78 return 0; |
|
79 } |