| 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: findnextfilea.c |
| 8 | ** |
| 9 | ** Purpose: Tests the PAL implementation of the FindNextFileA function. |
| 10 | ** Tests '*' and '*.*' to ensure that '.' and '..' are |
| 11 | ** returned in the expected order |
| 12 | ** |
| 13 | ** |
| 14 | **===================================================================*/ |
| 15 | |
| 16 | #include <palsuite.h> |
| 17 | |
| 18 | |
| 19 | const char* szDot = "." ; |
| 20 | const char* szDotDot = ".." ; |
| 21 | const char* szStar = "*" ; |
| 22 | const char* szStarDotStar = "*.*" ; |
| 23 | |
| 24 | |
| 25 | static void DoTest(const char* szDir, |
| 26 | const char* szResult1, |
| 27 | const char* szResult2) |
| 28 | { |
| 29 | HANDLE hFind; |
| 30 | WIN32_FIND_DATA findFileData; |
| 31 | |
| 32 | /* |
| 33 | ** find the first |
| 34 | */ |
| 35 | if ((hFind = FindFirstFileA(szDir, &findFileData)) == INVALID_HANDLE_VALUE) |
| 36 | { |
| 37 | Fail("FindNextFileA: ERROR -> FindFirstFileA(\"%s\") failed. " |
| 38 | "GetLastError returned %u.\n" , |
| 39 | szStar, |
| 40 | GetLastError()); |
| 41 | } |
| 42 | |
| 43 | /* did we find the expected */ |
| 44 | if (strcmp(szResult1, findFileData.cFileName) != 0) |
| 45 | { |
| 46 | if (!FindClose(hFind)) |
| 47 | { |
| 48 | Trace("FindNextFileA: ERROR -> Failed to close the find handle. " |
| 49 | "GetLastError returned %u.\n" , |
| 50 | GetLastError()); |
| 51 | } |
| 52 | Fail("FindNextFileA: ERROR -> FindFirstFile(\"%s\") didn't find" |
| 53 | " the expected \"%s\" but found \"%s\" instead.\n" , |
| 54 | szDir, |
| 55 | szResult1, |
| 56 | findFileData.cFileName); |
| 57 | } |
| 58 | |
| 59 | /* we found the first expected, let's see if we find the next expected*/ |
| 60 | if (!FindNextFileA(hFind, &findFileData)) |
| 61 | { |
| 62 | Trace("FindNextFileA: ERROR -> FindNextFileA should have found \"%s\"" |
| 63 | " but failed. GetLastError returned %u.\n" , |
| 64 | szResult2, |
| 65 | GetLastError()); |
| 66 | if (!FindClose(hFind)) |
| 67 | { |
| 68 | Trace("FindNextFileA: ERROR -> Failed to close the find handle. " |
| 69 | "GetLastError returned %u.\n" , |
| 70 | GetLastError()); |
| 71 | } |
| 72 | Fail("" ); |
| 73 | } |
| 74 | |
| 75 | /* we found something, but was it '.' */ |
| 76 | if (strcmp(szResult2, findFileData.cFileName) != 0) |
| 77 | { |
| 78 | if (!FindClose(hFind)) |
| 79 | { |
| 80 | Trace("FindNextFileA: ERROR -> Failed to close the find handle. " |
| 81 | "GetLastError returned %u.\n" , |
| 82 | GetLastError()); |
| 83 | } |
| 84 | Fail("FindNextFileA: ERROR -> FindNextFileA based on \"%s\" didn't find" |
| 85 | " the expected \"%s\" but found \"%s\" instead.\n" , |
| 86 | szDir, |
| 87 | szResult2, |
| 88 | findFileData.cFileName); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | int __cdecl main(int argc, char *argv[]) |
| 93 | { |
| 94 | |
| 95 | if (0 != PAL_Initialize(argc,argv)) |
| 96 | { |
| 97 | return FAIL; |
| 98 | } |
| 99 | |
| 100 | DoTest(szStar, szDot, szDotDot); |
| 101 | DoTest(szStarDotStar, szDot, szDotDot); |
| 102 | |
| 103 | |
| 104 | PAL_Terminate(); |
| 105 | |
| 106 | return PASS; |
| 107 | } |
| 108 | |