kernelbase: Implement PathAllocCombine.

Signed-off-by: Zhiyi Zhang <zzhang@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Zhiyi Zhang 2018-11-26 10:31:03 +08:00 committed by Alexandre Julliard
parent af88297f4a
commit abcfcb1d7e
5 changed files with 166 additions and 13 deletions

View File

@ -1,5 +1,5 @@
@ stdcall PathAllocCanonicalize(wstr long ptr) kernelbase.PathAllocCanonicalize
@ stub PathAllocCombine
@ stdcall PathAllocCombine(wstr wstr long ptr) kernelbase.PathAllocCombine
@ stdcall PathCchAddBackslash(wstr long) kernelbase.PathCchAddBackslash
@ stdcall PathCchAddBackslashEx(wstr long ptr ptr) kernelbase.PathCchAddBackslashEx
@ stdcall PathCchAddExtension(wstr long wstr) kernelbase.PathCchAddExtension

View File

@ -1024,7 +1024,7 @@
@ stdcall PathAddExtensionA(str str) shlwapi.PathAddExtensionA
@ stdcall PathAddExtensionW(wstr wstr) shlwapi.PathAddExtensionW
@ stdcall PathAllocCanonicalize(wstr long ptr)
# @ stub PathAllocCombine
@ stdcall PathAllocCombine(wstr wstr long ptr)
@ stdcall PathAppendA(str str) shlwapi.PathAppendA
@ stdcall PathAppendW(wstr wstr) shlwapi.PathAppendW
@ stdcall PathCanonicalizeA(ptr str) shlwapi.PathCanonicalizeA

View File

@ -308,6 +308,63 @@ HRESULT WINAPI PathAllocCanonicalize(const WCHAR *path_in, DWORD flags, WCHAR **
return S_OK;
}
HRESULT WINAPI PathAllocCombine(const WCHAR *path1, const WCHAR *path2, DWORD flags, WCHAR **out)
{
SIZE_T combined_length, length2;
WCHAR *combined_path;
BOOL from_path2 = FALSE;
HRESULT hr;
TRACE("%s %s %#x %p\n", wine_dbgstr_w(path1), wine_dbgstr_w(path2), flags, out);
if ((!path1 && !path2) || !out)
{
if (out) *out = NULL;
return E_INVALIDARG;
}
if (!path1 || !path2) return PathAllocCanonicalize(path1 ? path1 : path2, flags, out);
/* If path2 is fully qualified, use path2 only */
if (path2 && ((isalphaW(path2[0]) && path2[1] == ':') || (path2[0] == '\\' && path2[1] == '\\')))
{
path1 = path2;
path2 = NULL;
from_path2 = TRUE;
}
length2 = path2 ? strlenW(path2) : 0;
/* path1 length + path2 length + possible backslash + NULL */
combined_length = strlenW(path1) + length2 + 2;
combined_path = HeapAlloc(GetProcessHeap(), 0, combined_length * sizeof(WCHAR));
if (!combined_path)
{
*out = NULL;
return E_OUTOFMEMORY;
}
lstrcpyW(combined_path, path1);
PathCchStripPrefix(combined_path, combined_length);
if (from_path2) PathCchAddBackslashEx(combined_path, combined_length, NULL, NULL);
if (path2 && path2[0])
{
if (path2[0] == '\\' && path2[1] != '\\')
{
PathCchStripToRoot(combined_path, combined_length);
path2++;
}
PathCchAddBackslashEx(combined_path, combined_length, NULL, NULL);
lstrcatW(combined_path, path2);
}
hr = PathAllocCanonicalize(combined_path, flags, out);
HeapFree(GetProcessHeap(), 0, combined_path);
return hr;
}
HRESULT WINAPI PathCchAddBackslash(WCHAR *path, SIZE_T size)
{
return PathCchAddBackslashEx(path, size, NULL, NULL);

View File

@ -31,6 +31,7 @@
#include "wine/test.h"
HRESULT (WINAPI *pPathAllocCanonicalize)(const WCHAR *path_in, DWORD flags, WCHAR **path_out);
HRESULT (WINAPI *pPathAllocCombine)(const WCHAR *path1, const WCHAR *path2, DWORD flags, WCHAR **out);
HRESULT (WINAPI *pPathCchAddBackslash)(WCHAR *out, SIZE_T size);
HRESULT (WINAPI *pPathCchAddBackslashEx)(WCHAR *out, SIZE_T size, WCHAR **endptr, SIZE_T *remaining);
HRESULT (WINAPI *pPathCchAddExtension)(WCHAR *path, SIZE_T size, const WCHAR *extension);
@ -352,13 +353,14 @@ static void test_PathAllocCanonicalize(void)
}
}
static const struct
struct combine_test
{
const char *path1;
const char *path2;
const char *result;
}
combine_test[] =
const CHAR *path1;
const CHAR *path2;
const CHAR *result;
};
static const struct combine_test combine_tests[] =
{
/* normal paths */
{"C:\\", "a", "C:\\a" },
@ -366,21 +368,112 @@ combine_test[] =
{"C:", "a", "C:\\a" },
{"C:\\", ".", "C:\\" },
{"C:\\", "..", "C:\\" },
{"\\a", "b", "\\a\\b" },
{"C:\\a", "", "C:\\a" },
{"\\", "a", "\\a"},
{"\\a", "b", "\\a\\b" },
/* normal UNC paths */
{"\\\\192.168.1.1\\test", "a", "\\\\192.168.1.1\\test\\a" },
{"\\\\192.168.1.1\\test", "..", "\\\\192.168.1.1" },
{"\\\\", "a", "\\\\a"},
{"\\\\?\\Volume{e51a1864-6f2d-4019-b73d-f4e60e600c26}\\", "a",
"\\\\?\\Volume{e51a1864-6f2d-4019-b73d-f4e60e600c26}\\a"},
/* NT paths */
{"\\\\?\\C:\\", "a", "C:\\a" },
{"\\\\?\\C:\\", "..", "C:\\" },
{"\\\\?\\C:", "a", "C:\\a"},
/* NT UNC path */
{"\\\\?\\UNC\\", "a", "\\\\a"},
{"\\\\?\\UNC\\192.168.1.1\\test", "a", "\\\\192.168.1.1\\test\\a" },
{"\\\\?\\UNC\\192.168.1.1\\test", "..", "\\\\192.168.1.1" },
/* Second path begins with a single backslash */
{"C:a\\b", "\\1", "C:\\1"},
{"C:\\a\\b", "\\1", "C:\\1"},
{"\\a\\b", "\\1", "\\1"},
{"\\\\a\\b", "\\1", "\\\\a\\b\\1"},
{"\\\\a\\b\\c", "\\1", "\\\\a\\b\\1"},
{"\\\\?\\UNC\\a", "\\1", "\\\\a\\1"},
{"\\\\?\\Volume{e51a1864-6f2d-4019-b73d-f4e60e600c26}a", "\\1",
"\\\\?\\Volume{e51a1864-6f2d-4019-b73d-f4e60e600c26}\\1"},
{"\\\\?\\Volume{e51a1864-6f2d-4019-b73d-f4e60e600c26}\\a", "\\1",
"\\\\?\\Volume{e51a1864-6f2d-4019-b73d-f4e60e600c26}\\1"},
{"C:\\a\\b", "\\", "C:\\"},
/* Second path is fully qualified */
{"X:\\", "C:", "C:\\"},
{"X:\\", "C:\\", "C:\\"},
{"X:\\", "\\\\", "\\\\"},
{"X:\\", "\\\\?\\C:", "C:\\"},
{"X:\\", "\\\\?\\C:\\", "C:\\"},
{"X:\\", "\\\\?\\UNC\\", "\\\\"},
{"X:\\", "\\\\?\\Volume{e51a1864-6f2d-4019-b73d-f4e60e600c26}\\",
"\\\\?\\Volume{e51a1864-6f2d-4019-b73d-f4e60e600c26}\\"},
/* Canonicalization */
{"C:\\a", ".\\b", "C:\\a\\b"},
{"C:\\a", "..\\b", "C:\\b"},
/* Other */
{"", "", "\\"},
{"a", "b", "a\\b"}
};
static void test_PathAllocCombine(void)
{
WCHAR path1W[PATHCCH_MAX_CCH];
WCHAR path2W[PATHCCH_MAX_CCH];
WCHAR *resultW;
CHAR resultA[PATHCCH_MAX_CCH];
HRESULT hr;
INT i;
if (!pPathAllocCombine)
{
win_skip("PathAllocCombine() is not available.\n");
return;
}
resultW = (WCHAR *)0xdeadbeef;
hr = pPathAllocCombine(NULL, NULL, 0, &resultW);
ok(hr == E_INVALIDARG, "expect hr %#x, got %#x\n", E_INVALIDARG, hr);
ok(resultW == NULL, "expect resultW null, got %p\n", resultW);
MultiByteToWideChar(CP_ACP, 0, "\\a", -1, path1W, ARRAY_SIZE(path1W));
hr = pPathAllocCombine(path1W, NULL, 0, &resultW);
ok(hr == S_OK, "expect hr %#x, got %#x\n", S_OK, hr);
WideCharToMultiByte(CP_ACP, 0, resultW, -1, resultA, ARRAY_SIZE(resultA), NULL, NULL);
ok(!lstrcmpA(resultA, "\\a"), "expect \\a, got %s\n", resultA);
MultiByteToWideChar(CP_ACP, 0, "\\b", -1, path2W, ARRAY_SIZE(path2W));
hr = pPathAllocCombine(NULL, path2W, 0, &resultW);
ok(hr == S_OK, "expect hr %#x, got %#x\n", S_OK, hr);
WideCharToMultiByte(CP_ACP, 0, resultW, -1, resultA, ARRAY_SIZE(resultA), NULL, NULL);
ok(!lstrcmpA(resultA, "\\b"), "expect \\b, got %s\n", resultA);
hr = pPathAllocCombine(path1W, path2W, 0, NULL);
ok(hr == E_INVALIDARG, "expect hr %#x, got %#x\n", E_INVALIDARG, hr);
for (i = 0; i < ARRAY_SIZE(combine_tests); i++)
{
const struct combine_test *t = combine_tests + i;
MultiByteToWideChar(CP_ACP, 0, t->path1, -1, path1W, ARRAY_SIZE(path1W));
MultiByteToWideChar(CP_ACP, 0, t->path2, -1, path2W, ARRAY_SIZE(path2W));
hr = pPathAllocCombine(path1W, path2W, 0, &resultW);
ok(hr == S_OK, "combine %s %s expect hr %#x, got %#x\n", t->path1, t->path2, S_OK, hr);
if (SUCCEEDED(hr))
{
WideCharToMultiByte(CP_ACP, 0, resultW, -1, resultA, ARRAY_SIZE(resultA), NULL, NULL);
ok(!lstrcmpA(resultA, t->result), "combine %s %s expect result %s, got %s\n", t->path1, t->path2, t->result,
resultA);
LocalFree(resultW);
}
}
}
static void test_PathCchCombineEx(void)
{
WCHAR expected[MAX_PATH] = {'C',':','\\','a',0};
@ -421,11 +514,11 @@ static void test_PathCchCombineEx(void)
"Combination of %s + %s returned %s, expected %s\n",
wine_dbgstr_w(p1), wine_dbgstr_w(p2), wine_dbgstr_w(output), wine_dbgstr_w(expected));
for (i = 0; i < ARRAY_SIZE(combine_test); i++)
for (i = 0; i < ARRAY_SIZE(combine_tests); i++)
{
MultiByteToWideChar(CP_ACP, 0, combine_test[i].path1, -1, p1, MAX_PATH);
MultiByteToWideChar(CP_ACP, 0, combine_test[i].path2, -1, p2, MAX_PATH);
MultiByteToWideChar(CP_ACP, 0, combine_test[i].result, -1, expected, MAX_PATH);
MultiByteToWideChar(CP_ACP, 0, combine_tests[i].path1, -1, p1, MAX_PATH);
MultiByteToWideChar(CP_ACP, 0, combine_tests[i].path2, -1, p2, MAX_PATH);
MultiByteToWideChar(CP_ACP, 0, combine_tests[i].result, -1, expected, MAX_PATH);
hr = pPathCchCombineEx(output, MAX_PATH, p1, p2, 0);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
@ -1935,6 +2028,7 @@ START_TEST(path)
HMODULE hmod = LoadLibraryA("kernelbase.dll");
pPathAllocCanonicalize = (void *)GetProcAddress(hmod, "PathAllocCanonicalize");
pPathAllocCombine = (void *)GetProcAddress(hmod, "PathAllocCombine");
pPathCchCombineEx = (void *)GetProcAddress(hmod, "PathCchCombineEx");
pPathCchAddBackslash = (void *)GetProcAddress(hmod, "PathCchAddBackslash");
pPathCchAddBackslashEx = (void *)GetProcAddress(hmod, "PathCchAddBackslashEx");
@ -1954,6 +2048,7 @@ START_TEST(path)
pPathIsUNCEx = (void *)GetProcAddress(hmod, "PathIsUNCEx");
test_PathAllocCanonicalize();
test_PathAllocCombine();
test_PathCchCombineEx();
test_PathCchAddBackslash();
test_PathCchAddBackslashEx();

View File

@ -27,6 +27,7 @@
#define PATHCCH_MAX_CCH 0x8000
HRESULT WINAPI PathAllocCanonicalize(const WCHAR *path_in, DWORD flags, WCHAR **path_out);
HRESULT WINAPI PathAllocCombine(const WCHAR *path1, const WCHAR *path2, DWORD flags, WCHAR **out);
HRESULT WINAPI PathCchAddBackslash(WCHAR *path, SIZE_T size);
HRESULT WINAPI PathCchAddBackslashEx(WCHAR *path, SIZE_T size, WCHAR **end, SIZE_T *remaining);
HRESULT WINAPI PathCchAddExtension(WCHAR *path, SIZE_T size, const WCHAR *extension);