~ubuntu-branches/ubuntu/vivid/freerdp/vivid

« back to all changes in this revision

Viewing changes to winpr/libwinpr/file/test/TestFileFindFirstFile.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-11-11 12:20:50 UTC
  • mfrom: (1.2.5)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20141111122050-7z628f4ab38qxad5
Tags: upstream-1.1.0~git20140921.1.440916e+dfsg1
ImportĀ upstreamĀ versionĀ 1.1.0~git20140921.1.440916e+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
9
static TCHAR testFile1[] = _T("TestFile1");
 
10
 
 
11
int TestFileFindFirstFile(int argc, char* argv[])
 
12
{
 
13
        char* str;
 
14
        int length;
 
15
        HANDLE hFind;
 
16
        LPTSTR BasePath;
 
17
        WIN32_FIND_DATA FindData;
 
18
        TCHAR FilePath[PATHCCH_MAX_CCH];
 
19
 
 
20
        str = argv[1];
 
21
 
 
22
#ifdef UNICODE
 
23
        length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
 
24
        BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
 
25
        MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
 
26
        BasePath[length] = 0;
 
27
#else
 
28
        BasePath = _strdup(str);
 
29
        length = strlen(BasePath);
 
30
#endif
 
31
 
 
32
        CopyMemory(FilePath, BasePath, length * sizeof(TCHAR));
 
33
        FilePath[length] = 0;
 
34
 
 
35
        PathCchConvertStyle(BasePath, length, PATH_STYLE_WINDOWS);
 
36
        NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestFile1"));
 
37
 
 
38
        _tprintf(_T("Finding file: %s\n"), FilePath);
 
39
 
 
40
        hFind = FindFirstFile(FilePath, &FindData);
 
41
 
 
42
        if (hFind == INVALID_HANDLE_VALUE)
 
43
        {
 
44
                _tprintf(_T("FindFirstFile failure: %s (INVALID_HANDLE_VALUE -1)\n"), FilePath);
 
45
                return -1;
 
46
        }
 
47
 
 
48
        _tprintf(_T("FindFirstFile: %s"), FindData.cFileName);
 
49
 
 
50
        if (_tcscmp(FindData.cFileName, testFile1) != 0)
 
51
        {
 
52
                _tprintf(_T("FindFirstFile failure: Expected: %s, Actual: %s\n"),
 
53
                                testFile1, FindData.cFileName);
 
54
                return -1;
 
55
        }
 
56
 
 
57
        FindClose(hFind);
 
58
 
 
59
        return 0;
 
60
}