| 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: GetFullPathNameA.c (test 1) |
| 8 | ** |
| 9 | ** Purpose: Tests the PAL implementation of the GetFullPathNameA function. |
| 10 | ** |
| 11 | ** |
| 12 | **===================================================================*/ |
| 13 | |
| 14 | #include <palsuite.h> |
| 15 | |
| 16 | const char* szFileName = "testing.tmp" ; |
| 17 | |
| 18 | int __cdecl main(int argc, char *argv[]) |
| 19 | { |
| 20 | DWORD dwRc = 0; |
| 21 | char szReturnedPath[_MAX_DIR+1]; |
| 22 | char szShortBuff[2]; |
| 23 | LPSTR pPathPtr; |
| 24 | HANDLE hFile = NULL; |
| 25 | |
| 26 | |
| 27 | if (0 != PAL_Initialize(argc,argv)) |
| 28 | { |
| 29 | return FAIL; |
| 30 | } |
| 31 | |
| 32 | /* perform a short buffer test */ |
| 33 | if (GetFullPathNameA(szFileName, 2, szShortBuff, &pPathPtr) <= 2) |
| 34 | { |
| 35 | /* this test should have failed but didn't */ |
| 36 | Fail("GetFullPathNameA: ERROR -> The API was passed a buffer that was" |
| 37 | " too small for the path name and yet it apparently passed.\n" ); |
| 38 | } |
| 39 | |
| 40 | memset(szReturnedPath, 0, _MAX_DIR+1); |
| 41 | dwRc = GetFullPathNameA(szFileName, |
| 42 | _MAX_DIR, |
| 43 | szReturnedPath, |
| 44 | &pPathPtr); |
| 45 | |
| 46 | if (dwRc == 0) |
| 47 | { |
| 48 | // this test should have passed but didn't |
| 49 | Fail("GetFullPathNameA: ERROR -> Function failed for the " |
| 50 | "file \"%s\" with error code: %ld.\n" , szFileName, GetLastError()); |
| 51 | } |
| 52 | |
| 53 | // the returned value should be the current directory with the |
| 54 | // file name appended |
| 55 | hFile = CreateFileA(szFileName, |
| 56 | GENERIC_READ, |
| 57 | FILE_SHARE_READ, |
| 58 | NULL, |
| 59 | CREATE_ALWAYS, |
| 60 | FILE_ATTRIBUTE_NORMAL, |
| 61 | NULL); |
| 62 | if (hFile == INVALID_HANDLE_VALUE) |
| 63 | { |
| 64 | Fail("GetFullPathNameA: ERROR -> CreateFileA failed to create " |
| 65 | "file \"%s\" with error code: %ld.\n" , |
| 66 | szFileName, |
| 67 | GetLastError()); |
| 68 | } |
| 69 | if (CloseHandle(hFile) != TRUE) |
| 70 | { |
| 71 | Fail("GetFullPathNameA: ERROR -> CloseHandle failed with error " |
| 72 | "code: %ld.\n" , GetLastError()); |
| 73 | } |
| 74 | |
| 75 | // now try to create the file based on the returned value with the |
| 76 | // CREATE_NEW option which should fail since the file should |
| 77 | // already exist |
| 78 | hFile = CreateFileA(szReturnedPath, |
| 79 | GENERIC_READ, |
| 80 | FILE_SHARE_READ, |
| 81 | NULL, |
| 82 | CREATE_NEW, |
| 83 | FILE_ATTRIBUTE_NORMAL, |
| 84 | NULL); |
| 85 | if (hFile != INVALID_HANDLE_VALUE) |
| 86 | { |
| 87 | Fail("GetFullPathNameA: ERROR -> CreateFileA was able to " |
| 88 | "CREATE_NEW the returned file \"%s\". The returned file " |
| 89 | "name is therefore apparently wrong.\n" , |
| 90 | szReturnedPath); |
| 91 | if (CloseHandle(hFile) != TRUE) |
| 92 | { |
| 93 | Fail("GetFullPathNameA: ERROR -> CloseHandle failed with " |
| 94 | "error code: %ld.\n" , GetLastError()); |
| 95 | } |
| 96 | if ((DeleteFileA(szReturnedPath) != TRUE) || |
| 97 | (DeleteFileA(szFileName) != TRUE)) |
| 98 | { |
| 99 | Fail("GetFullPathNameA: ERROR -> DeleteFileA failed to " |
| 100 | "delete the test files with error code: %ld.\n" , |
| 101 | GetLastError()); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // now make sure the pPathPtr is the same as the file name |
| 106 | if (strcmp(pPathPtr, szFileName) != 0) |
| 107 | { |
| 108 | Fail("GetFullPathNameA: ERROR -> %s != %s\n" , |
| 109 | pPathPtr, szFileName); |
| 110 | } |
| 111 | if (DeleteFileA(szFileName) != TRUE) |
| 112 | { |
| 113 | Fail("GetFullPathNameA: ERROR -> DeleteFileA failed to " |
| 114 | "delete \"%s\" with error code: %ld.\n" , |
| 115 | szFileName, |
| 116 | GetLastError()); |
| 117 | } |
| 118 | |
| 119 | PAL_Terminate(); |
| 120 | return PASS; |
| 121 | } |
| 122 | |
| 123 | |