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: ReadFile.c (test 1) |
8 | ** |
9 | ** Purpose: Tests the PAL implementation of the ReadFile function. |
10 | ** This test will attempt to read from a NULL handle and from |
11 | ** a file without read permissions set. |
12 | ** |
13 | ** |
14 | **===================================================================*/ |
15 | |
16 | #include <palsuite.h> |
17 | |
18 | |
19 | int __cdecl main(int argc, char *argv[]) |
20 | { |
21 | HANDLE hFile = NULL; |
22 | DWORD dwByteCount = 0; |
23 | DWORD dwBytesRead = 0; |
24 | BOOL bRc = FALSE; |
25 | char szBuffer[256]; |
26 | char* szNonReadableFile = {"nonreadablefile.txt" }; |
27 | |
28 | if (0 != PAL_Initialize(argc,argv)) |
29 | { |
30 | return FAIL; |
31 | } |
32 | |
33 | memset(szBuffer, 0, 256); |
34 | |
35 | /* Read from a NULL handle |
36 | */ |
37 | |
38 | bRc = ReadFile(hFile, szBuffer, 20, &dwBytesRead, NULL); |
39 | |
40 | if (bRc == TRUE) |
41 | { |
42 | Fail("ReadFile: ERROR -> Able to read from a NULL handle\n" ); |
43 | } |
44 | |
45 | |
46 | /* Read from a file without read permissions |
47 | */ |
48 | |
49 | #if WIN32 |
50 | |
51 | #else |
52 | /* attempt to read from the unreadable file |
53 | * open a file without read permissions |
54 | */ |
55 | hFile = CreateFile(szNonReadableFile, |
56 | GENERIC_WRITE, |
57 | FILE_SHARE_WRITE, |
58 | NULL, |
59 | OPEN_EXISTING, |
60 | FILE_ATTRIBUTE_NORMAL, |
61 | NULL); |
62 | |
63 | if(hFile == INVALID_HANDLE_VALUE) |
64 | { |
65 | dwByteCount = GetLastError(); |
66 | Fail("ReadFile: ERROR -> Unable to create file \"%s\".\n" , |
67 | szNonReadableFile); |
68 | } |
69 | |
70 | bRc = ReadFile(hFile, szBuffer, 20, &dwBytesRead, NULL); |
71 | |
72 | if (bRc == TRUE) |
73 | { |
74 | Fail("ReadFile: ERROR -> Able to read from a file without read " |
75 | "permissions\n" ); |
76 | } |
77 | #endif |
78 | |
79 | |
80 | PAL_Terminate(); |
81 | return PASS; |
82 | } |
83 | |