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: FindNextFileW.c
8**
9** Purpose: Tests the PAL implementation of the FindNextFileW 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
19const WCHAR szwDot[] = {'.','\0'};
20const WCHAR szwDotDot[] = {'.','.','\0'};
21const WCHAR szwStar[] = {'*','\0'};
22const WCHAR szwStarDotStar[] = {'*','.','*','\0'};
23
24
25static void DoTest(const WCHAR* szwDir,
26 const WCHAR* szwResult1,
27 const WCHAR* szwResult2)
28{
29 HANDLE hFind;
30 WIN32_FIND_DATAW findFileData;
31
32 /*
33 ** find the first
34 */
35 if ((hFind = FindFirstFileW(szwDir, &findFileData)) == INVALID_HANDLE_VALUE)
36 {
37 Fail("FindNextFileW: ERROR -> FindFirstFileW(\"%S\") failed. "
38 "GetLastError returned %u.\n",
39 szwStar,
40 GetLastError());
41 }
42
43 /* did we find the expected */
44 if (wcscmp(szwResult1, findFileData.cFileName) != 0)
45 {
46 if (!FindClose(hFind))
47 {
48 Trace("FindNextFileW: ERROR -> Failed to close the find handle. "
49 "GetLastError returned %u.\n",
50 GetLastError());
51 }
52 Fail("FindNextFileW: ERROR -> FindFirstFile(\"%S\") didn't find"
53 " the expected \"%S\" but found \"%S\" instead.\n",
54 szwDir,
55 szwResult1,
56 findFileData.cFileName);
57 }
58
59 /* we found the first expected, let's see if we find the next expected*/
60 if (!FindNextFileW(hFind, &findFileData))
61 {
62 Trace("FindNextFileW: ERROR -> FindNextFileW should have found \"%S\""
63 " but failed. GetLastError returned %u.\n",
64 szwResult2,
65 GetLastError());
66 if (!FindClose(hFind))
67 {
68 Trace("FindNextFileW: 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 (wcscmp(szwResult2, findFileData.cFileName) != 0)
77 {
78 if (!FindClose(hFind))
79 {
80 Trace("FindNextFileW: ERROR -> Failed to close the find handle. "
81 "GetLastError returned %u.\n",
82 GetLastError());
83 }
84 Fail("FindNextFileW: ERROR -> FindNextFileW based on \"%S\" didn't find"
85 " the expected \"%S\" but found \"%S\" instead.\n",
86 szwDir,
87 szwResult2,
88 findFileData.cFileName);
89 }
90}
91
92int __cdecl main(int argc, char *argv[])
93{
94
95 if (0 != PAL_Initialize(argc,argv))
96 {
97 return FAIL;
98 }
99
100 DoTest(szwStar, szwDot, szwDotDot);
101 DoTest(szwStarDotStar, szwDot, szwDotDot);
102
103
104 PAL_Terminate();
105
106 return PASS;
107}
108