|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #undef G_DISABLE_ASSERT |
|
18 #undef G_LOG_DOMAIN |
|
19 |
|
20 #include <glib.h> |
|
21 #include <stdio.h> |
|
22 |
|
23 #ifdef SYMBIAN |
|
24 #include "mrt2_glib2_test.h" |
|
25 #endif /*SYMBIAN*/ |
|
26 |
|
27 |
|
28 /* Obviously we can't test that the operations are atomic, but we can |
|
29 * at least test, that they do, what they ought to do */ |
|
30 |
|
31 int |
|
32 main (int argc, |
|
33 char *argv[]) |
|
34 { |
|
35 gint i; |
|
36 gint atomic = -5; |
|
37 gpointer atomic_pointer = NULL; |
|
38 |
|
39 gpointer biggest_pointer = (gpointer)((gsize)atomic_pointer - 1); |
|
40 |
|
41 #ifdef SYMBIAN |
|
42 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); |
|
43 g_set_print_handler(mrtPrintHandler); |
|
44 #endif /*SYMBIAN*/ |
|
45 |
|
46 for (i = 0; i < 15; i++) |
|
47 g_atomic_int_inc (&atomic); |
|
48 g_assert (atomic == 10); |
|
49 for (i = 0; i < 9; i++) |
|
50 g_assert (!g_atomic_int_dec_and_test (&atomic)); |
|
51 g_assert (g_atomic_int_dec_and_test (&atomic)); |
|
52 g_assert (atomic == 0); |
|
53 |
|
54 g_assert (g_atomic_int_exchange_and_add (&atomic, 5) == 0); |
|
55 g_assert (atomic == 5); |
|
56 |
|
57 g_assert (g_atomic_int_exchange_and_add (&atomic, -10) == 5); |
|
58 g_assert (atomic == -5); |
|
59 |
|
60 g_atomic_int_add (&atomic, 20); |
|
61 g_assert (atomic == 15); |
|
62 |
|
63 g_atomic_int_add (&atomic, -35); |
|
64 g_assert (atomic == -20); |
|
65 |
|
66 g_assert (atomic == g_atomic_int_get (&atomic)); |
|
67 |
|
68 g_assert (g_atomic_int_compare_and_exchange (&atomic, -20, 20)); |
|
69 g_assert (atomic == 20); |
|
70 |
|
71 g_assert (!g_atomic_int_compare_and_exchange (&atomic, 42, 12)); |
|
72 g_assert (atomic == 20); |
|
73 |
|
74 g_assert (g_atomic_int_compare_and_exchange (&atomic, 20, G_MAXINT)); |
|
75 g_assert (atomic == G_MAXINT); |
|
76 |
|
77 g_assert (g_atomic_int_compare_and_exchange (&atomic, G_MAXINT, G_MININT)); |
|
78 g_assert (atomic == G_MININT); |
|
79 |
|
80 g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer, |
|
81 NULL, biggest_pointer)); |
|
82 g_assert (atomic_pointer == biggest_pointer); |
|
83 |
|
84 g_assert (atomic_pointer == g_atomic_pointer_get (&atomic_pointer)); |
|
85 |
|
86 g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer, |
|
87 biggest_pointer, NULL)); |
|
88 g_assert (atomic_pointer == NULL); |
|
89 |
|
90 #ifdef SYMBIAN |
|
91 testResultXml("atomic-test"); |
|
92 #endif /* EMULATOR */ |
|
93 |
|
94 return 0; |
|
95 } |