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: test.c |
8 | ** |
9 | ** Purpose: Test for CloseHandle function |
10 | ** |
11 | ** |
12 | **=========================================================*/ |
13 | |
14 | /* Depends on: CreateFile and WriteFile */ |
15 | |
16 | #include <palsuite.h> |
17 | |
18 | int __cdecl main(int argc, char *argv[]) |
19 | { |
20 | |
21 | HANDLE FileHandle = NULL; |
22 | LPDWORD WriteBuffer; /* Used with WriteFile */ |
23 | |
24 | /* |
25 | * Initialize the PAL and return FAILURE if this fails |
26 | */ |
27 | |
28 | if(0 != (PAL_Initialize(argc, argv))) |
29 | { |
30 | return FAIL; |
31 | } |
32 | |
33 | WriteBuffer = (LPDWORD)malloc(sizeof(WORD)); |
34 | |
35 | if ( WriteBuffer == NULL ) |
36 | { |
37 | Fail("ERROR: Failed to allocate memory for WriteBuffer pointer. " |
38 | "Can't properly exec test case without this.\n" ); |
39 | } |
40 | |
41 | |
42 | /* Create a file, since this returns to us a HANDLE we can use */ |
43 | FileHandle = CreateFile("testfile" , |
44 | GENERIC_READ | GENERIC_WRITE,0,NULL,CREATE_ALWAYS, |
45 | FILE_ATTRIBUTE_NORMAL, |
46 | NULL); |
47 | |
48 | /* Should be able to close this handle */ |
49 | if(CloseHandle(FileHandle) == 0) |
50 | { |
51 | free(WriteBuffer); |
52 | Fail("ERROR: (Test 1) Attempted to close a HANDLE on a file, but the " |
53 | "return value was <=0, indicating failure.\n" ); |
54 | } |
55 | |
56 | free(WriteBuffer); |
57 | |
58 | PAL_Terminate(); |
59 | return PASS; |
60 | } |
61 | |
62 | |
63 | |
64 | |
65 | |