2 * Unit test suite for interlocked functions.
4 * Copyright 2006 Hervé Poussineau
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.
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.
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
23 static void test_InterlockedCompareExchange(void)
28 res
= InterlockedCompareExchange( &dest
, 1, 0 );
29 ok( res
== 0 && dest
== 1,
30 "Expected 0 and 1, got %ld and %ld", res
, dest
);
33 res
= InterlockedCompareExchange( &dest
, 2, 0 );
34 ok( res
== 1 && dest
== 1,
35 "Expected 1 and 1, got %ld and %ld", res
, dest
);
38 static void test_InterlockedDecrement(void)
43 res
= InterlockedDecrement( &dest
);
44 ok( res
== 0 && dest
== 0,
45 "Expected 0 and 0, got %ld and %ld", res
, dest
);
48 res
= InterlockedDecrement( &dest
);
49 ok( res
== -1 && dest
== -1,
50 "Expected -1 and -1, got %ld and %ld", res
, dest
);
53 res
= InterlockedDecrement( &dest
);
54 ok( res
== -2 && dest
== -2,
55 "Expected -2 and -2, got %ld and %ld", res
, dest
);
58 static void test_InterlockedExchange(void)
63 res
= InterlockedExchange( &dest
, 1 );
64 ok( res
== 0 && dest
== 1,
65 "Expected 0 and 1, got %ld and %ld", res
, dest
);
68 res
= InterlockedExchange( &dest
, 2 );
69 ok( res
== 1 && dest
== 2,
70 "Expected 1 and 2, got %ld and %ld", res
, dest
);
73 res
= InterlockedExchange( &dest
, -1 );
74 ok( res
== 1 && dest
== -1,
75 "Expected 1 and -1, got %ld and %ld", res
, dest
);
78 static void test_InterlockedExchangeAdd(void)
83 res
= InterlockedExchangeAdd( &dest
, 1 );
84 ok( res
== 0 && dest
== 1,
85 "Expected 0 and 1, got %ld and %ld", res
, dest
);
88 res
= InterlockedExchangeAdd( &dest
, 2 );
89 ok( res
== 1 && dest
== 3,
90 "Expected 1 and 3, got %ld and %ld", res
, dest
);
93 res
= InterlockedExchangeAdd( &dest
, -1 );
94 ok( res
== 1 && dest
== 0,
95 "Expected 1 and 0, got %ld and %ld", res
, dest
);
98 static void test_InterlockedIncrement(void)
103 res
= InterlockedIncrement( &dest
);
104 ok( res
== -1 && dest
== -1,
105 "Expected -1 and -1, got %ld and %ld", res
, dest
);
108 res
= InterlockedIncrement( &dest
);
109 ok( res
== 0 && dest
== 0,
110 "Expected 0 and 0, got %ld and %ld", res
, dest
);
113 res
= InterlockedIncrement( &dest
);
114 ok( res
== 1 && dest
== 1,
115 "Expected 1 and 1, got %ld and %ld", res
, dest
);
120 test_InterlockedCompareExchange();
121 test_InterlockedDecrement();
122 test_InterlockedExchange();
123 test_InterlockedExchangeAdd();
124 test_InterlockedIncrement();