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