FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
TestFileFindNextFile.c
1
2#include <stdio.h>
3#include <winpr/crt.h>
4#include <winpr/file.h>
5#include <winpr/path.h>
6#include <winpr/tchar.h>
7#include <winpr/windows.h>
8
9static TCHAR testDirectory2File1[] = _T("TestDirectory2File1");
10static TCHAR testDirectory2File2[] = _T("TestDirectory2File2");
11
12int TestFileFindNextFile(int argc, char* argv[])
13{
14 char* str = NULL;
15 size_t length = 0;
16 BOOL status = 0;
17 HANDLE hFind = NULL;
18 LPTSTR BasePath = NULL;
19 WIN32_FIND_DATA FindData;
20 TCHAR FilePath[PATHCCH_MAX_CCH] = { 0 };
21 WINPR_UNUSED(argc);
22 str = argv[1];
23#ifdef UNICODE
24 BasePath = ConvertUtf8ToWChar(str, &length);
25
26 if (!BasePath)
27 {
28 _tprintf(_T("Unable to allocate memory"));
29 return -1;
30 }
31#else
32 BasePath = _strdup(str);
33
34 if (!BasePath)
35 {
36 printf("Unable to allocate memory");
37 return -1;
38 }
39
40 length = strlen(BasePath);
41#endif
42 /* Simple filter matching all files inside current directory */
43 CopyMemory(FilePath, BasePath, length * sizeof(TCHAR));
44 FilePath[length] = 0;
45 PathCchConvertStyle(BasePath, length, PATH_STYLE_WINDOWS);
46 NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestDirectory2"));
47 NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestDirectory2File*"));
48 free(BasePath);
49 _tprintf(_T("Finding file: %s\n"), FilePath);
50 hFind = FindFirstFile(FilePath, &FindData);
51
52 if (hFind == INVALID_HANDLE_VALUE)
53 {
54 _tprintf(_T("FindFirstFile failure: %s\n"), FilePath);
55 return -1;
56 }
57
58 _tprintf(_T("FindFirstFile: %s"), FindData.cFileName);
59
64 if ((_tcsncmp(FindData.cFileName, testDirectory2File1, ARRAYSIZE(testDirectory2File1)) != 0) &&
65 (_tcsncmp(FindData.cFileName, testDirectory2File2, ARRAYSIZE(testDirectory2File2)) != 0))
66 {
67 _tprintf(_T("FindFirstFile failure: Expected: %s, Actual: %s\n"), testDirectory2File1,
68 FindData.cFileName);
69 return -1;
70 }
71
72 status = FindNextFile(hFind, &FindData);
73
74 if (!status)
75 {
76 _tprintf(_T("FindNextFile failure: Expected: TRUE, Actual: %") _T(PRId32) _T("\n"), status);
77 return -1;
78 }
79
80 if ((_tcsncmp(FindData.cFileName, testDirectory2File1, ARRAYSIZE(testDirectory2File1)) != 0) &&
81 (_tcsncmp(FindData.cFileName, testDirectory2File2, ARRAYSIZE(testDirectory2File2)) != 0))
82 {
83 _tprintf(_T("FindNextFile failure: Expected: %s, Actual: %s\n"), testDirectory2File2,
84 FindData.cFileName);
85 return -1;
86 }
87
88 status = FindNextFile(hFind, &FindData);
89
90 if (status)
91 {
92 _tprintf(_T("FindNextFile failure: Expected: FALSE, Actual: %") _T(PRId32) _T("\n"),
93 status);
94 return -1;
95 }
96
97 FindClose(hFind);
98 return 0;
99}