winpr: fix PathCchAddExtension
The HRESULT S_FALSE does not indicate an error: - return E_INVALIDARG instead of S_FALSE - return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) instead of S_FALSE Also extended/fixed the corresponding ctest
This commit is contained in:
parent
03b0472c29
commit
17ceafbb0c
@ -17,10 +17,10 @@ HRESULT PATH_CCH_ADD_EXTENSION(PWSTR pszPath, size_t cchPath, PCWSTR pszExt)
|
||||
size_t pszPathLength;
|
||||
|
||||
if (!pszPath)
|
||||
return S_FALSE;
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!pszExt)
|
||||
return S_FALSE;
|
||||
return E_INVALIDARG;
|
||||
|
||||
pszExtLength = lstrlenW(pszExt);
|
||||
pszPathLength = lstrlenW(pszPath);
|
||||
@ -45,7 +45,7 @@ HRESULT PATH_CCH_ADD_EXTENSION(PWSTR pszPath, size_t cchPath, PCWSTR pszExt)
|
||||
return S_OK;
|
||||
}
|
||||
#endif
|
||||
return S_FALSE;
|
||||
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
|
||||
}
|
||||
|
||||
#else
|
||||
@ -59,10 +59,10 @@ HRESULT PATH_CCH_ADD_EXTENSION(PSTR pszPath, size_t cchPath, PCSTR pszExt)
|
||||
size_t pszPathLength;
|
||||
|
||||
if (!pszPath)
|
||||
return S_FALSE;
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!pszExt)
|
||||
return S_FALSE;
|
||||
return E_INVALIDARG;
|
||||
|
||||
pszExtLength = lstrlenA(pszExt);
|
||||
pszPathLength = lstrlenA(pszPath);
|
||||
@ -87,7 +87,7 @@ HRESULT PATH_CCH_ADD_EXTENSION(PSTR pszPath, size_t cchPath, PCSTR pszExt)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
return S_FALSE;
|
||||
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -14,7 +14,7 @@ int TestPathCchAddExtension(int argc, char* argv[])
|
||||
{
|
||||
HRESULT status;
|
||||
TCHAR Path[PATHCCH_MAX_CCH];
|
||||
|
||||
|
||||
/* Path: no extension, Extension: dot */
|
||||
|
||||
_tcscpy(Path, testPathNoExtension);
|
||||
@ -87,6 +87,45 @@ int TestPathCchAddExtension(int argc, char* argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Path: NULL */
|
||||
|
||||
status = PathCchAddExtension(NULL, PATHCCH_MAX_CCH, testExtDot);
|
||||
if (status != E_INVALIDARG)
|
||||
{
|
||||
_tprintf(_T("PathCchAddExtension with null buffer returned status: 0x%08X (expected E_INVALIDARG)\n"), status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Extension: NULL */
|
||||
|
||||
status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, NULL);
|
||||
if (status != E_INVALIDARG)
|
||||
{
|
||||
_tprintf(_T("PathCchAddExtension with null extension returned status: 0x%08X (expected E_INVALIDARG)\n"), status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Insufficient Buffer size */
|
||||
|
||||
_tcscpy(Path, _T("C:\\456789"));
|
||||
status = PathCchAddExtension(Path, 9 + 4, _T(".jpg"));
|
||||
if (SUCCEEDED(status))
|
||||
{
|
||||
_tprintf(_T("PathCchAddExtension with insufficient buffer unexpectedly succeeded with status: 0x%08X\n"), status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Minimum required buffer size */
|
||||
|
||||
_tcscpy(Path, _T("C:\\456789"));
|
||||
status = PathCchAddExtension(Path, 9 + 4 + 1, _T(".jpg"));
|
||||
if (FAILED(status))
|
||||
{
|
||||
_tprintf(_T("PathCchAddExtension with sufficient buffer unexpectedly failed with status: 0x%08X\n"), status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user