Blame winpr/libwinpr/file/test/TestFileFindFirstFile.c

Packit 1fb8d4
Packit 1fb8d4
#include <stdio.h>
Packit 1fb8d4
#include <winpr/crt.h>
Packit 1fb8d4
#include <winpr/file.h>
Packit 1fb8d4
#include <winpr/path.h>
Packit 1fb8d4
#include <winpr/tchar.h>
Packit 1fb8d4
#include <winpr/windows.h>
Packit 1fb8d4
Packit 1fb8d4
static TCHAR testFile1[] = _T("TestFile1");
Packit 1fb8d4
Packit 1fb8d4
int TestFileFindFirstFile(int argc, char* argv[])
Packit 1fb8d4
{
Packit 1fb8d4
	char* str;
Packit 1fb8d4
	int length;
Packit 1fb8d4
	HANDLE hFind;
Packit 1fb8d4
	LPTSTR BasePath;
Packit 1fb8d4
	WIN32_FIND_DATA FindData;
Packit 1fb8d4
	TCHAR FilePath[PATHCCH_MAX_CCH];
Packit 1fb8d4
	str = argv[1];
Packit 1fb8d4
#ifdef UNICODE
Packit 1fb8d4
	length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
Packit Service 5a9772
	BasePath = (WCHAR*)calloc((length + 1), sizeof(WCHAR));
Packit 1fb8d4
Packit 1fb8d4
	if (!BasePath)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("Unable to allocate memory\n"));
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
	MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR)BasePath, length * sizeof(WCHAR));
Packit 1fb8d4
	BasePath[length] = 0;
Packit 1fb8d4
#else
Packit 1fb8d4
	BasePath = _strdup(str);
Packit 1fb8d4
Packit 1fb8d4
	if (!BasePath)
Packit 1fb8d4
	{
Packit 1fb8d4
		printf("Unable to allocate memory\n");
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	length = strlen(BasePath);
Packit 1fb8d4
#endif
Packit 1fb8d4
	CopyMemory(FilePath, BasePath, length * sizeof(TCHAR));
Packit 1fb8d4
	FilePath[length] = 0;
Packit 1fb8d4
	PathCchConvertStyle(BasePath, length, PATH_STYLE_WINDOWS);
Packit 1fb8d4
	NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestFile1"));
Packit 1fb8d4
	free(BasePath);
Packit 1fb8d4
	_tprintf(_T("Finding file: %s\n"), FilePath);
Packit 1fb8d4
	hFind = FindFirstFile(FilePath, &FindData);
Packit 1fb8d4
Packit 1fb8d4
	if (hFind == INVALID_HANDLE_VALUE)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("FindFirstFile failure: %s (INVALID_HANDLE_VALUE -1)\n"), FilePath);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	_tprintf(_T("FindFirstFile: %s"), FindData.cFileName);
Packit 1fb8d4
Packit 1fb8d4
	if (_tcscmp(FindData.cFileName, testFile1) != 0)
Packit 1fb8d4
	{
Packit Service 5a9772
		_tprintf(_T("FindFirstFile failure: Expected: %s, Actual: %s\n"), testFile1,
Packit Service 5a9772
		         FindData.cFileName);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	FindClose(hFind);
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}