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
24 #include "wine/test.h"
29 static void test_InterlockedCompareExchange(void)
34 res
= InterlockedCompareExchange( &dest
, 1, 0 );
35 ok( res
== 0 && dest
== 1,
36 "Expected 0 and 1, got %ld and %ld", res
, dest
);
39 res
= InterlockedCompareExchange( &dest
, 2, 0 );
40 ok( res
== 1 && dest
== 1,
41 "Expected 1 and 1, got %ld and %ld", res
, dest
);
44 static void test_InterlockedDecrement(void)
49 res
= InterlockedDecrement( &dest
);
50 ok( res
== 0 && dest
== 0,
51 "Expected 0 and 0, got %ld and %ld", res
, dest
);
54 res
= InterlockedDecrement( &dest
);
55 ok( res
== -1 && dest
== -1,
56 "Expected -1 and -1, got %ld and %ld", res
, dest
);
59 res
= InterlockedDecrement( &dest
);
60 ok( res
== -2 && dest
== -2,
61 "Expected -2 and -2, got %ld and %ld", res
, dest
);
64 static void test_InterlockedExchange(void)
69 res
= InterlockedExchange( &dest
, 1 );
70 ok( res
== 0 && dest
== 1,
71 "Expected 0 and 1, got %ld and %ld", res
, dest
);
74 res
= InterlockedExchange( &dest
, 2 );
75 ok( res
== 1 && dest
== 2,
76 "Expected 1 and 2, got %ld and %ld", res
, dest
);
79 res
= InterlockedExchange( &dest
, -1 );
80 ok( res
== 1 && dest
== -1,
81 "Expected 1 and -1, got %ld and %ld", res
, dest
);
84 static void test_InterlockedExchangeAdd(void)
89 res
= InterlockedExchangeAdd( &dest
, 1 );
90 ok( res
== 0 && dest
== 1,
91 "Expected 0 and 1, got %ld and %ld", res
, dest
);
94 res
= InterlockedExchangeAdd( &dest
, 2 );
95 ok( res
== 1 && dest
== 3,
96 "Expected 1 and 3, got %ld and %ld", res
, dest
);
99 res
= InterlockedExchangeAdd( &dest
, -1 );
100 ok( res
== 1 && dest
== 0,
101 "Expected 1 and 0, got %ld and %ld", res
, dest
);
104 static void test_InterlockedIncrement(void)
109 res
= InterlockedIncrement( &dest
);
110 ok( res
== -1 && dest
== -1,
111 "Expected -1 and -1, got %ld and %ld", res
, dest
);
114 res
= InterlockedIncrement( &dest
);
115 ok( res
== 0 && dest
== 0,
116 "Expected 0 and 0, got %ld and %ld", res
, dest
);
119 res
= InterlockedIncrement( &dest
);
120 ok( res
== 1 && dest
== 1,
121 "Expected 1 and 1, got %ld and %ld", res
, dest
);
126 test_InterlockedCompareExchange();
127 test_InterlockedDecrement();
128 test_InterlockedExchange();
129 test_InterlockedExchangeAdd();
130 test_InterlockedIncrement();