1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*============================================================================ |
6 | ** |
7 | ** Source: releasesemaphore/test1/createsemaphore.c |
8 | ** |
9 | ** Purpose: Check that ReleaseSemaphore fails when using a semaphore handle |
10 | ** which has been closed by a call to CloseHandle. Check that |
11 | ** ReleaseSemaphore fails when using a ReleaseCount of zero or less than |
12 | ** zero. |
13 | ** |
14 | ** |
15 | **==========================================================================*/ |
16 | |
17 | #include <palsuite.h> |
18 | |
19 | HANDLE hSemaphore; |
20 | |
21 | int __cdecl main (int argc, char **argv) |
22 | { |
23 | if(0 != (PAL_Initialize(argc, argv))) |
24 | { |
25 | return (FAIL); |
26 | } |
27 | hSemaphore = CreateSemaphoreA (NULL, 1, 2, NULL); |
28 | |
29 | if (NULL == hSemaphore) |
30 | { |
31 | Fail("PALSUITE ERROR: CreateSemaphoreA ('%p' '%ld' '%ld' " |
32 | "'%p') returned NULL.\nGetLastError returned %d.\n" , |
33 | NULL, 1, 2, NULL, GetLastError()); |
34 | } |
35 | |
36 | if(ReleaseSemaphore(hSemaphore, 0, NULL)) |
37 | { |
38 | Fail("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " |
39 | "call returned %d\nwhen it should have returned " |
40 | "%d.\nGetLastError returned %d.\n" , |
41 | hSemaphore, 0, NULL, FALSE, TRUE, GetLastError()); |
42 | } |
43 | |
44 | if(ReleaseSemaphore(hSemaphore, -1, NULL)) |
45 | { |
46 | Fail("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " |
47 | "call returned %d\nwhen it should have returned " |
48 | "%d.\nGetLastError returned %d.\n" , |
49 | hSemaphore, -1, NULL, TRUE, FALSE, GetLastError()); |
50 | } |
51 | |
52 | if(!CloseHandle(hSemaphore)) |
53 | { |
54 | Fail("PALSUITE ERROR: CloseHandle(%p) call failed. GetLastError " |
55 | "returned %d.\n" , hSemaphore, GetLastError()); |
56 | } |
57 | |
58 | if(ReleaseSemaphore(hSemaphore, 1, NULL)) |
59 | { |
60 | Fail("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " |
61 | "call incremented semaphore %p count\nafter the handle " |
62 | "was closed by a call to CloseHandle.\n GetLastError returned " |
63 | "%d.\n" , hSemaphore, -1, NULL, hSemaphore, GetLastError()); |
64 | } |
65 | |
66 | PAL_Terminate(); |
67 | return (PASS); |
68 | } |
69 | |