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: ReleaseMutex/test3/ReleaseMutex.c |
8 | ** |
9 | ** Purpose: Test failure code for ReleaseMutex. |
10 | ** |
11 | ** Dependencies: CreateMutex |
12 | ** ReleaseMutex |
13 | ** CreateThread |
14 | ** |
15 | |
16 | ** |
17 | **=========================================================*/ |
18 | |
19 | #include <palsuite.h> |
20 | |
21 | DWORD dwTestResult; /* global for test result */ |
22 | |
23 | DWORD dwThreadId; /* consumer thread identifier */ |
24 | |
25 | HANDLE hMutex; /* handle to mutex */ |
26 | |
27 | HANDLE hThread; /* handle to thread */ |
28 | |
29 | /* |
30 | * Thread function. |
31 | */ |
32 | DWORD |
33 | PALAPI |
34 | ThreadFunction( LPVOID lpNoArg ) |
35 | { |
36 | |
37 | dwTestResult = ReleaseMutex(hMutex); |
38 | |
39 | return 0; |
40 | } |
41 | |
42 | int __cdecl main (int argc, char **argv) |
43 | { |
44 | |
45 | if(0 != (PAL_Initialize(argc, argv))) |
46 | { |
47 | return (FAIL); |
48 | } |
49 | |
50 | /* |
51 | * set dwTestResult so test fails even if ReleaseMutex is not called |
52 | */ |
53 | dwTestResult = 1; |
54 | |
55 | /* |
56 | * Create mutex |
57 | */ |
58 | hMutex = CreateMutexW ( |
59 | NULL, |
60 | TRUE, |
61 | NULL); |
62 | |
63 | if ( NULL == hMutex ) |
64 | { |
65 | Fail ( "hMutex = CreateMutex () - returned NULL\n" |
66 | "Failing Test.\nGetLastError returned %d\n" , GetLastError()); |
67 | } |
68 | |
69 | /* |
70 | * Create ThreadFunction |
71 | */ |
72 | hThread = CreateThread( |
73 | NULL, |
74 | 0, |
75 | ThreadFunction, |
76 | NULL, |
77 | 0, |
78 | &dwThreadId); |
79 | |
80 | if ( NULL == hThread ) |
81 | { |
82 | |
83 | Fail ( "CreateThread() returned NULL. Failing test.\n" |
84 | "GetLastError returned %d\n" , GetLastError()); |
85 | } |
86 | |
87 | /* |
88 | * Wait for ThreadFunction to complete |
89 | */ |
90 | WaitForSingleObject (hThread, INFINITE); |
91 | |
92 | if (dwTestResult) |
93 | { |
94 | Fail ("ReleaseMutex() test was expected to return 0.\n" |
95 | "It returned %d. Failing test.\n" , dwTestResult ); |
96 | } |
97 | |
98 | Trace ("ReleaseMutex() test returned 0.\nTest passed.\n" ); |
99 | |
100 | PAL_Terminate(); |
101 | return ( PASS ); |
102 | |
103 | } |
104 | |