|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include <stdio.h>
|
|
Packit |
1fb8d4 |
#include <winpr/crt.h>
|
|
Packit |
1fb8d4 |
#include <winpr/path.h>
|
|
Packit |
1fb8d4 |
#include <winpr/tchar.h>
|
|
Packit |
1fb8d4 |
#include <winpr/winpr.h>
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
static const TCHAR testPathBackslash[] = _T("C:\\Program Files\\");
|
|
Packit |
1fb8d4 |
static const TCHAR testPathNoBackslash[] = _T("C:\\Program Files");
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
int TestPathCchAddBackslash(int argc, char* argv[])
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
HRESULT status;
|
|
Packit |
1fb8d4 |
TCHAR Path[PATHCCH_MAX_CCH];
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/**
|
|
Packit |
1fb8d4 |
* PathCchAddBackslash returns S_OK if the function was successful,
|
|
Packit |
1fb8d4 |
* S_FALSE if the path string already ends in a backslash,
|
|
Packit |
1fb8d4 |
* or an error code otherwise.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
_tcscpy(Path, testPathNoBackslash);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Add a backslash to a path without a trailing backslash, expect S_OK */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
status = PathCchAddBackslash(Path, PATHCCH_MAX_CCH);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (status != S_OK)
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
_tprintf(_T("PathCchAddBackslash status: 0x%08") _T(PRIX32) _T("\n"), status);
|
|
Packit |
1fb8d4 |
return -1;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (_tcscmp(Path, testPathBackslash) != 0)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash);
|
|
Packit |
1fb8d4 |
return -1;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Add a backslash to a path with a trailing backslash, expect S_FALSE */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
_tcscpy(Path, testPathBackslash);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
status = PathCchAddBackslash(Path, PATHCCH_MAX_CCH);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (status != S_FALSE)
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
_tprintf(_T("PathCchAddBackslash status: 0x%08") _T(PRIX32) _T("\n"), status);
|
|
Packit |
1fb8d4 |
return -1;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (_tcscmp(Path, testPathBackslash) != 0)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash);
|
|
Packit |
1fb8d4 |
return -1;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Use NULL PSTR, expect FAILED(status) */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
status = PathCchAddBackslash(NULL, PATHCCH_MAX_CCH);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (SUCCEEDED(status))
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
_tprintf(_T("PathCchAddBackslash unexpectedly succeded with null buffer. Status: 0x%08") _T(
|
|
Packit Service |
5a9772 |
PRIX32) _T("\n"),
|
|
Packit Service |
5a9772 |
status);
|
|
Packit |
1fb8d4 |
return -1;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Use insufficient size value, expect FAILED(status) */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
_tcscpy(Path, _T("C:\\tmp"));
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
status = PathCchAddBackslash(Path, 7);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (SUCCEEDED(status))
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
_tprintf(_T("PathCchAddBackslash unexpectedly succeded with insufficient buffer size. ")
|
|
Packit Service |
5a9772 |
_T("Status: 0x%08") _T(PRIX32) _T("\n"),
|
|
Packit Service |
5a9772 |
status);
|
|
Packit |
1fb8d4 |
return -1;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Use minimum required size value, expect S_OK */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
_tcscpy(Path, _T("C:\\tmp"));
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
status = PathCchAddBackslash(Path, 8);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (status != S_OK)
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
_tprintf(_T("PathCchAddBackslash failed with status: 0x%08") _T(PRIX32) _T("\n"), status);
|
|
Packit |
1fb8d4 |
return -1;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
return 0;
|
|
Packit |
1fb8d4 |
}
|