2012-10-19 00:58:27 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/file.h>
|
|
|
|
#include <winpr/path.h>
|
|
|
|
#include <winpr/tchar.h>
|
|
|
|
#include <winpr/windows.h>
|
|
|
|
|
2012-10-19 05:11:12 +04:00
|
|
|
static TCHAR testFile1[] = _T("TestFile1");
|
2012-10-19 00:58:27 +04:00
|
|
|
|
|
|
|
int TestFileFindFirstFile(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
char* str;
|
|
|
|
int length;
|
|
|
|
HANDLE hFind;
|
|
|
|
LPTSTR BasePath;
|
|
|
|
WIN32_FIND_DATA FindData;
|
|
|
|
TCHAR FilePath[PATHCCH_MAX_CCH];
|
|
|
|
|
|
|
|
str = argv[1];
|
|
|
|
|
|
|
|
#ifdef UNICODE
|
|
|
|
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
|
|
|
|
BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
|
2015-04-03 17:21:01 +03:00
|
|
|
if (!BasePath)
|
|
|
|
{
|
|
|
|
_tprintf(_T("Unable to allocate memory\n"));
|
|
|
|
return -1;
|
|
|
|
}
|
2012-10-19 00:58:27 +04:00
|
|
|
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
|
|
|
|
BasePath[length] = 0;
|
|
|
|
#else
|
|
|
|
BasePath = _strdup(str);
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!BasePath)
|
|
|
|
{
|
|
|
|
printf("Unable to allocate memory\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-10-19 00:58:27 +04:00
|
|
|
length = strlen(BasePath);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CopyMemory(FilePath, BasePath, length * sizeof(TCHAR));
|
|
|
|
FilePath[length] = 0;
|
|
|
|
|
2012-10-19 05:11:12 +04:00
|
|
|
PathCchConvertStyle(BasePath, length, PATH_STYLE_WINDOWS);
|
2012-10-19 00:58:27 +04:00
|
|
|
NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestFile1"));
|
|
|
|
|
|
|
|
_tprintf(_T("Finding file: %s\n"), FilePath);
|
|
|
|
|
|
|
|
hFind = FindFirstFile(FilePath, &FindData);
|
|
|
|
|
|
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2013-03-15 23:03:48 +04:00
|
|
|
_tprintf(_T("FindFirstFile failure: %s (INVALID_HANDLE_VALUE -1)\n"), FilePath);
|
2012-10-19 00:58:27 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
_tprintf(_T("FindFirstFile: %s"), FindData.cFileName);
|
|
|
|
|
|
|
|
if (_tcscmp(FindData.cFileName, testFile1) != 0)
|
|
|
|
{
|
2013-03-15 23:03:48 +04:00
|
|
|
_tprintf(_T("FindFirstFile failure: Expected: %s, Actual: %s\n"),
|
2012-10-19 00:58:27 +04:00
|
|
|
testFile1, FindData.cFileName);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FindClose(hFind);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|