c4cd60110a
Fix multiple inplementation errors including the incorrect usage of S_FALSE. Make this function behave like the Windows 8 implementation and the according MSDN specification. - return S_OK if the extension was NOT found - if no extension was found, ppszExt must point to the string's terminating null - return E_INVALIDARG if pszPath is not null-terminated within the cchPath range - return E_INVALIDARG if pszPath is NULL - return E_INVALIDARG if ppszExt is NULL - return E_INVALIDARG if cchPath is Zero - return E_NOTIMPL instead of S_OK in PathPathCchFindExtensionW() Also extended/fixed the TestPathCchFindExtension ctest
107 lines
2.6 KiB
C
107 lines
2.6 KiB
C
|
|
#include <stdio.h>
|
|
#include <winpr/crt.h>
|
|
#include <winpr/path.h>
|
|
#include <winpr/tchar.h>
|
|
#include <winpr/winpr.h>
|
|
|
|
static const char testPathExtension[] = "C:\\Windows\\System32\\cmd.exe";
|
|
|
|
int TestPathCchFindExtension(int argc, char* argv[])
|
|
{
|
|
PCSTR pszExt;
|
|
PCSTR pszTmp;
|
|
HRESULT hr;
|
|
|
|
/* Test invalid args */
|
|
|
|
hr = PathCchFindExtensionA(NULL, sizeof(testPathExtension), &pszExt);
|
|
if (SUCCEEDED(hr))
|
|
{
|
|
printf("PathCchFindExtensionA unexpectedly succeeded with pszPath = NULL. result: 0x%08X\n", (ULONG)hr);
|
|
return -1;
|
|
}
|
|
|
|
hr = PathCchFindExtensionA(testPathExtension, 0, &pszExt);
|
|
if (SUCCEEDED(hr))
|
|
{
|
|
printf("PathCchFindExtensionA unexpectedly succeeded with cchPath = 0. result: 0x%08X\n", (ULONG)hr);
|
|
return -1;
|
|
}
|
|
|
|
hr = PathCchFindExtensionA(testPathExtension, sizeof(testPathExtension), NULL);
|
|
if (SUCCEEDED(hr))
|
|
{
|
|
printf("PathCchFindExtensionA unexpectedly succeeded with ppszExt = NULL. result: 0x%08X\n", (ULONG)hr);
|
|
return -1;
|
|
}
|
|
|
|
|
|
/* Test missing null-termination of pszPath */
|
|
|
|
hr = PathCchFindExtensionA(_T("c:\\456.789"), 9, &pszExt);
|
|
if (SUCCEEDED(hr))
|
|
{
|
|
printf("PathCchFindExtensionA unexpectedly succeeded with unterminated pszPath. result: 0x%08X\n", (ULONG)hr);
|
|
return -1;
|
|
}
|
|
|
|
|
|
/* Test passing of an empty terminated string (must succeed) */
|
|
|
|
pszExt = NULL;
|
|
pszTmp = _T("");
|
|
hr = PathCchFindExtensionA(pszTmp, 1, &pszExt);
|
|
if (hr != S_OK)
|
|
{
|
|
printf("PathCchFindExtensionA failed with an empty terminated string. result: 0x%08X\n", (ULONG)hr);
|
|
return -1;
|
|
}
|
|
/* pszExt must point to the strings terminating 0 now */
|
|
if (pszExt != pszTmp)
|
|
{
|
|
printf("PathCchFindExtensionA failed with an empty terminated string: pszExt pointer mismatch\n");
|
|
return -1;
|
|
}
|
|
|
|
|
|
/* Test a path without file extension (must succeed) */
|
|
|
|
pszExt = NULL;
|
|
pszTmp = _T("c:\\4.678\\");
|
|
hr = PathCchFindExtensionA(pszTmp, 10, &pszExt);
|
|
if (hr != S_OK)
|
|
{
|
|
printf("PathCchFindExtensionA failed with a directory path. result: 0x%08X\n", (ULONG)hr);
|
|
return -1;
|
|
}
|
|
/* The extension must not have been found and pszExt must point to the
|
|
* strings terminating NULL now */
|
|
if (pszExt != &pszTmp[9])
|
|
{
|
|
printf("PathCchFindExtensionA failed with a directory path: pszExt pointer mismatch\n");
|
|
return -1;
|
|
}
|
|
|
|
|
|
/* Non-special tests */
|
|
|
|
pszExt = NULL;
|
|
if (PathCchFindExtensionA(testPathExtension, sizeof(testPathExtension), &pszExt) != S_OK)
|
|
{
|
|
printf("PathCchFindExtensionA failure: expected S_OK\n");
|
|
return -1;
|
|
}
|
|
|
|
if (!pszExt || _tcscmp(pszExt, _T(".exe")))
|
|
{
|
|
printf("PathCchFindExtensionA failure: unexpected extension\n");
|
|
return -1;
|
|
}
|
|
|
|
printf("Extension: %s\n", pszExt);
|
|
|
|
return 0;
|
|
}
|
|
|