2bb9d25e769bc6f951aa86cc4a95af061ca950df
[reactos.git] / rostests / winetests / kernel32 / interlck.c
1 /*
2 * Unit test suite for interlocked functions.
3 *
4 * Copyright 2006 Hervé Poussineau
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <stdarg.h>
22
23 #undef __ROS_LONG64__
24 #include "wine/test.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28
29 static void test_InterlockedCompareExchange(void)
30 {
31 LONG dest, res;
32
33 dest = 0;
34 res = InterlockedCompareExchange( &dest, 1, 0 );
35 ok( res == 0 && dest == 1,
36 "Expected 0 and 1, got %ld and %ld", res, dest );
37
38 dest = 1;
39 res = InterlockedCompareExchange( &dest, 2, 0 );
40 ok( res == 1 && dest == 1,
41 "Expected 1 and 1, got %ld and %ld", res, dest );
42 }
43
44 static void test_InterlockedDecrement(void)
45 {
46 LONG dest, res;
47
48 dest = 1;
49 res = InterlockedDecrement( &dest );
50 ok( res == 0 && dest == 0,
51 "Expected 0 and 0, got %ld and %ld", res, dest );
52
53 dest = 0;
54 res = InterlockedDecrement( &dest );
55 ok( res == -1 && dest == -1,
56 "Expected -1 and -1, got %ld and %ld", res, dest );
57
58 dest = -1;
59 res = InterlockedDecrement( &dest );
60 ok( res == -2 && dest == -2,
61 "Expected -2 and -2, got %ld and %ld", res, dest );
62 }
63
64 static void test_InterlockedExchange(void)
65 {
66 LONG dest, res;
67
68 dest = 0;
69 res = InterlockedExchange( &dest, 1 );
70 ok( res == 0 && dest == 1,
71 "Expected 0 and 1, got %ld and %ld", res, dest );
72
73 dest = 1;
74 res = InterlockedExchange( &dest, 2 );
75 ok( res == 1 && dest == 2,
76 "Expected 1 and 2, got %ld and %ld", res, dest );
77
78 dest = 1;
79 res = InterlockedExchange( &dest, -1 );
80 ok( res == 1 && dest == -1,
81 "Expected 1 and -1, got %ld and %ld", res, dest );
82 }
83
84 static void test_InterlockedExchangeAdd(void)
85 {
86 LONG dest, res;
87
88 dest = 0;
89 res = InterlockedExchangeAdd( &dest, 1 );
90 ok( res == 0 && dest == 1,
91 "Expected 0 and 1, got %ld and %ld", res, dest );
92
93 dest = 1;
94 res = InterlockedExchangeAdd( &dest, 2 );
95 ok( res == 1 && dest == 3,
96 "Expected 1 and 3, got %ld and %ld", res, dest );
97
98 dest = 1;
99 res = InterlockedExchangeAdd( &dest, -1 );
100 ok( res == 1 && dest == 0,
101 "Expected 1 and 0, got %ld and %ld", res, dest );
102 }
103
104 static void test_InterlockedIncrement(void)
105 {
106 LONG dest, res;
107
108 dest = -2;
109 res = InterlockedIncrement( &dest );
110 ok( res == -1 && dest == -1,
111 "Expected -1 and -1, got %ld and %ld", res, dest );
112
113 dest = -1;
114 res = InterlockedIncrement( &dest );
115 ok( res == 0 && dest == 0,
116 "Expected 0 and 0, got %ld and %ld", res, dest );
117
118 dest = 0;
119 res = InterlockedIncrement( &dest );
120 ok( res == 1 && dest == 1,
121 "Expected 1 and 1, got %ld and %ld", res, dest );
122 }
123
124 START_TEST(interlck)
125 {
126 test_InterlockedCompareExchange();
127 test_InterlockedDecrement();
128 test_InterlockedExchange();
129 test_InterlockedExchangeAdd();
130 test_InterlockedIncrement();
131 }