[NTFS]
[reactos.git] / rostests / apitests / 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 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27
28 static void test_InterlockedCompareExchange(void)
29 {
30 LONG dest, res;
31
32 dest = 0;
33 res = InterlockedCompareExchange( &dest, 1, 0 );
34 ok( res == 0 && dest == 1,
35 "Expected 0 and 1, got %ld and %ld", res, dest );
36
37 dest = 1;
38 res = InterlockedCompareExchange( &dest, 2, 0 );
39 ok( res == 1 && dest == 1,
40 "Expected 1 and 1, got %ld and %ld", res, dest );
41 }
42
43 static void test_InterlockedDecrement(void)
44 {
45 LONG dest, res;
46
47 dest = 1;
48 res = InterlockedDecrement( &dest );
49 ok( res == 0 && dest == 0,
50 "Expected 0 and 0, got %ld and %ld", res, dest );
51
52 dest = 0;
53 res = InterlockedDecrement( &dest );
54 ok( res == -1 && dest == -1,
55 "Expected -1 and -1, got %ld and %ld", res, dest );
56
57 dest = -1;
58 res = InterlockedDecrement( &dest );
59 ok( res == -2 && dest == -2,
60 "Expected -2 and -2, got %ld and %ld", res, dest );
61 }
62
63 static void test_InterlockedExchange(void)
64 {
65 LONG dest, res;
66
67 dest = 0;
68 res = InterlockedExchange( &dest, 1 );
69 ok( res == 0 && dest == 1,
70 "Expected 0 and 1, got %ld and %ld", res, dest );
71
72 dest = 1;
73 res = InterlockedExchange( &dest, 2 );
74 ok( res == 1 && dest == 2,
75 "Expected 1 and 2, got %ld and %ld", res, dest );
76
77 dest = 1;
78 res = InterlockedExchange( &dest, -1 );
79 ok( res == 1 && dest == -1,
80 "Expected 1 and -1, got %ld and %ld", res, dest );
81 }
82
83 static void test_InterlockedExchangeAdd(void)
84 {
85 LONG dest, res;
86
87 dest = 0;
88 res = InterlockedExchangeAdd( &dest, 1 );
89 ok( res == 0 && dest == 1,
90 "Expected 0 and 1, got %ld and %ld", res, dest );
91
92 dest = 1;
93 res = InterlockedExchangeAdd( &dest, 2 );
94 ok( res == 1 && dest == 3,
95 "Expected 1 and 3, got %ld and %ld", res, dest );
96
97 dest = 1;
98 res = InterlockedExchangeAdd( &dest, -1 );
99 ok( res == 1 && dest == 0,
100 "Expected 1 and 0, got %ld and %ld", res, dest );
101 }
102
103 static void test_InterlockedIncrement(void)
104 {
105 LONG dest, res;
106
107 dest = -2;
108 res = InterlockedIncrement( &dest );
109 ok( res == -1 && dest == -1,
110 "Expected -1 and -1, got %ld and %ld", res, dest );
111
112 dest = -1;
113 res = InterlockedIncrement( &dest );
114 ok( res == 0 && dest == 0,
115 "Expected 0 and 0, got %ld and %ld", res, dest );
116
117 dest = 0;
118 res = InterlockedIncrement( &dest );
119 ok( res == 1 && dest == 1,
120 "Expected 1 and 1, got %ld and %ld", res, dest );
121 }
122
123 START_TEST(interlck)
124 {
125 test_InterlockedCompareExchange();
126 test_InterlockedDecrement();
127 test_InterlockedExchange();
128 test_InterlockedExchangeAdd();
129 test_InterlockedIncrement();
130 }