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