Added a few more Unicode digits from Unicode version 4.1.
[wine] / dlls / kernel / tests / sync.c
1 /*
2  * Synchronization tests
3  *
4  * Copyright 2005 Mike McCormack for CodeWeavers
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 #include <stdlib.h>
23 #include <stdio.h>
24 #include <windef.h>
25 #include <winbase.h>
26
27 #include "wine/test.h"
28
29 static void test_signalandwait(void)
30 {
31     DWORD (WINAPI *pSignalObjectAndWait)(HANDLE, HANDLE, DWORD, BOOL);
32     HMODULE kernel32;
33     DWORD r;
34     HANDLE event[2], semaphore[2], file;
35
36     kernel32 = GetModuleHandle("kernel32");
37     pSignalObjectAndWait = (void*) GetProcAddress(kernel32, "SignalObjectAndWait");
38
39     if (!pSignalObjectAndWait)
40         return;
41
42     /* invalid parameters */
43     r = pSignalObjectAndWait(NULL, NULL, 0, 0);
44     if (r == ERROR_INVALID_FUNCTION)
45     {
46         trace("SignalObjectAndWait not implemented, skipping tests\n");
47         return; /* Win98/ME */
48     }
49     ok( r == WAIT_FAILED, "should fail\n");
50
51     event[0] = CreateEvent(NULL, 0, 0, NULL);
52     event[1] = CreateEvent(NULL, 1, 1, NULL);
53
54     ok( event[0] && event[1], "failed to create event flags\n");
55
56     r = pSignalObjectAndWait(event[0], NULL, 0, FALSE);
57     ok( r == WAIT_FAILED, "should fail\n");
58
59     r = pSignalObjectAndWait(NULL, event[0], 0, FALSE);
60     ok( r == WAIT_FAILED, "should fail\n");
61
62
63     /* valid parameters */
64     r = pSignalObjectAndWait(event[0], event[1], 0, FALSE);
65     ok( r == WAIT_OBJECT_0, "should succeed\n");
66
67     /* event[0] is now signalled */
68     r = pSignalObjectAndWait(event[0], event[0], 0, FALSE);
69     ok( r == WAIT_OBJECT_0, "should succeed\n");
70
71     /* event[0] is not signalled */
72     r = WaitForSingleObject(event[0], 0);
73     ok( r == WAIT_TIMEOUT, "event was signalled\n");
74
75     r = pSignalObjectAndWait(event[0], event[0], 0, FALSE);
76     ok( r == WAIT_OBJECT_0, "should succeed\n");
77
78     /* clear event[1] and check for a timeout */
79     ok(ResetEvent(event[1]), "failed to clear event[1]\n");
80     r = pSignalObjectAndWait(event[0], event[1], 0, FALSE);
81     ok( r == WAIT_TIMEOUT, "should timeout\n");
82
83     CloseHandle(event[0]);
84     CloseHandle(event[1]);
85
86
87     /* semaphores */
88     semaphore[0] = CreateSemaphore( NULL, 0, 1, NULL );
89     semaphore[1] = CreateSemaphore( NULL, 1, 1, NULL );
90     ok( semaphore[0] && semaphore[1], "failed to create semaphore\n");
91
92     r = pSignalObjectAndWait(semaphore[0], semaphore[1], 0, FALSE);
93     ok( r == WAIT_OBJECT_0, "should succeed\n");
94
95     r = pSignalObjectAndWait(semaphore[0], semaphore[1], 0, FALSE);
96     ok( r == WAIT_FAILED, "should fail\n");
97
98     r = ReleaseSemaphore(semaphore[0],1,NULL);
99     ok( r == FALSE, "should fail\n");
100
101     r = ReleaseSemaphore(semaphore[1],1,NULL);
102     ok( r == TRUE, "should succeed\n");
103
104     CloseHandle(semaphore[0]);
105     CloseHandle(semaphore[1]);
106
107     /* try a registry key */
108     file = CreateFile("x", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 
109         FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL);
110     r = pSignalObjectAndWait(file, file, 0, FALSE);
111     ok( r == WAIT_FAILED, "should fail\n");
112     todo_wine {
113     ok( ERROR_INVALID_HANDLE == GetLastError(), "should return invalid handle error\n");
114     }
115     CloseHandle(file);
116 }
117
118 START_TEST(sync)
119 {
120     test_signalandwait();
121 }