Commit 81f55420 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

shlwapi/tests: Simplify length calculation in test_UrlApplyScheme().

parent 5775cfd8
...@@ -38,43 +38,40 @@ static const WCHAR winehqW[] = L"http://www.winehq.org/"; ...@@ -38,43 +38,40 @@ static const WCHAR winehqW[] = L"http://www.winehq.org/";
static const char winehqA[] = "http://www.winehq.org/"; static const char winehqA[] = "http://www.winehq.org/";
static const CHAR untouchedA[] = "untouched"; static const CHAR untouchedA[] = "untouched";
#define TEST_APPLY_MAX_LENGTH INTERNET_MAX_URL_LENGTH
typedef struct _TEST_URL_APPLY { typedef struct _TEST_URL_APPLY {
const char * url; const char * url;
DWORD flags; DWORD flags;
HRESULT res; HRESULT res;
DWORD newlen;
const char * newurl; const char * newurl;
} TEST_URL_APPLY; } TEST_URL_APPLY;
static const TEST_URL_APPLY TEST_APPLY[] = { static const TEST_URL_APPLY TEST_APPLY[] = {
{"www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"}, {"www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, "http://www.winehq.org"},
{"www.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 21, "http://www.winehq.org"}, {"www.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, "http://www.winehq.org"},
{"www.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"}, {"www.winehq.org", URL_APPLY_DEFAULT, S_OK, "http://www.winehq.org"},
{"ftp.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 20, "ftp://ftp.winehq.org"}, {"ftp.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, "ftp://ftp.winehq.org"},
{"ftp.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 20, "ftp://ftp.winehq.org"}, {"ftp.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, "ftp://ftp.winehq.org"},
{"ftp.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://ftp.winehq.org"}, {"ftp.winehq.org", URL_APPLY_DEFAULT, S_OK, "http://ftp.winehq.org"},
{"winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"}, {"winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, "http://winehq.org"},
{"winehq.org", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA}, {"winehq.org", URL_APPLY_GUESSSCHEME, S_FALSE},
{"winehq.org", URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"}, {"winehq.org", URL_APPLY_DEFAULT, S_OK, "http://winehq.org"},
{"http://www.winehq.org", URL_APPLY_GUESSSCHEME , S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA}, {"http://www.winehq.org", URL_APPLY_GUESSSCHEME, S_FALSE},
{"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_FORCEAPPLY, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA}, {"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_FORCEAPPLY, S_FALSE},
{"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_FORCEAPPLY | URL_APPLY_DEFAULT, S_OK, 28, "http://http://www.winehq.org"}, {"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_FORCEAPPLY | URL_APPLY_DEFAULT, S_OK, "http://http://www.winehq.org"},
{"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA}, {"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_FALSE},
{"", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 7, "http://"}, {"", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, "http://"},
{"", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA}, {"", URL_APPLY_GUESSSCHEME, S_FALSE},
{"", URL_APPLY_DEFAULT, S_OK, 7, "http://"}, {"", URL_APPLY_DEFAULT, S_OK, "http://"},
{"u:\\windows", URL_APPLY_GUESSFILE | URL_APPLY_DEFAULT, S_OK, 18, "file:///u:/windows"}, {"u:\\windows", URL_APPLY_GUESSFILE | URL_APPLY_DEFAULT, S_OK, "file:///u:/windows"},
{"u:\\windows", URL_APPLY_GUESSFILE, S_OK, 18, "file:///u:/windows"}, {"u:\\windows", URL_APPLY_GUESSFILE, S_OK, "file:///u:/windows"},
{"u:\\windows", URL_APPLY_DEFAULT, S_OK, 17, "http://u:\\windows"}, {"u:\\windows", URL_APPLY_DEFAULT, S_OK, "http://u:\\windows"},
{"file:///c:/windows", URL_APPLY_GUESSFILE , S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA}, {"file:///c:/windows", URL_APPLY_GUESSFILE, S_FALSE},
{"aa:\\windows", URL_APPLY_GUESSFILE , S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA}, {"aa:\\windows", URL_APPLY_GUESSFILE, S_FALSE},
{"\\\\server\\share", URL_APPLY_DEFAULT, S_OK, 21, "http://\\\\server\\share"}, {"\\\\server\\share", URL_APPLY_DEFAULT, S_OK, "http://\\\\server\\share"},
{"\\\\server\\share", URL_APPLY_GUESSFILE, S_OK, 19, "file://server/share"}, {"\\\\server\\share", URL_APPLY_GUESSFILE, S_OK, "file://server/share"},
{"\\\\server\\share", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA}, {"\\\\server\\share", URL_APPLY_GUESSSCHEME, S_FALSE},
{"file://server/share", URL_APPLY_GUESSFILE, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA}, {"file://server/share", URL_APPLY_GUESSFILE, S_FALSE},
{"file://server/share", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA}, {"file://server/share", URL_APPLY_GUESSSCHEME, S_FALSE},
}; };
/* ################ */ /* ################ */
...@@ -482,43 +479,50 @@ static void FreeWideString(LPWSTR wszString) ...@@ -482,43 +479,50 @@ static void FreeWideString(LPWSTR wszString)
static void test_UrlApplyScheme(void) static void test_UrlApplyScheme(void)
{ {
CHAR newurl[TEST_APPLY_MAX_LENGTH]; WCHAR urlW[INTERNET_MAX_URL_LENGTH], newurlW[INTERNET_MAX_URL_LENGTH], expectW[INTERNET_MAX_URL_LENGTH];
WCHAR urlW[TEST_APPLY_MAX_LENGTH]; char newurl[INTERNET_MAX_URL_LENGTH];
WCHAR newurlW[TEST_APPLY_MAX_LENGTH];
HRESULT res; HRESULT res;
DWORD len; DWORD len;
DWORD i; DWORD i;
for (i = 0; i < ARRAY_SIZE(TEST_APPLY); i++) { for (i = 0; i < ARRAY_SIZE(TEST_APPLY); i++) {
len = TEST_APPLY_MAX_LENGTH; len = ARRAY_SIZE(newurl);
lstrcpyA(newurl, untouchedA); strcpy(newurl, "untouched");
res = UrlApplySchemeA(TEST_APPLY[i].url, newurl, &len, TEST_APPLY[i].flags); res = UrlApplySchemeA(TEST_APPLY[i].url, newurl, &len, TEST_APPLY[i].flags);
ok( res == TEST_APPLY[i].res, ok( res == TEST_APPLY[i].res,
"#%dA: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res); "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
if (res == S_OK)
ok( len == TEST_APPLY[i].newlen, {
"#%dA: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen); ok(len == strlen(newurl), "Test %u: Expected length %u, got %u.\n", i, strlen(newurl), len);
ok(!strcmp(newurl, TEST_APPLY[i].newurl), "Test %u: Expected %s, got %s.\n",
ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl), i, debugstr_a(TEST_APPLY[i].newurl), debugstr_a(newurl));
"#%dA: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl); }
else
{
ok(len == ARRAY_SIZE(newurl), "Test %u: Got length %u.\n", i, len);
ok(!strcmp(newurl, "untouched"), "Test %u: Got %s.\n", i, debugstr_a(newurl));
}
/* returned length is in character */ /* returned length is in character */
len = TEST_APPLY_MAX_LENGTH; MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].url, -1, urlW, ARRAY_SIZE(urlW));
lstrcpyA(newurl, untouchedA); MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].newurl, -1, expectW, ARRAY_SIZE(expectW));
MultiByteToWideChar(CP_ACP, 0, newurl, -1, newurlW, len);
MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].url, -1, urlW, len);
len = ARRAY_SIZE(newurlW);
wcscpy(newurlW, L"untouched");
res = UrlApplySchemeW(urlW, newurlW, &len, TEST_APPLY[i].flags); res = UrlApplySchemeW(urlW, newurlW, &len, TEST_APPLY[i].flags);
WideCharToMultiByte(CP_ACP, 0, newurlW, -1, newurl, TEST_APPLY_MAX_LENGTH, NULL, NULL);
ok( res == TEST_APPLY[i].res, ok( res == TEST_APPLY[i].res,
"#%dW: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res); "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
if (res == S_OK)
ok( len == TEST_APPLY[i].newlen, {
"#%dW: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen); ok(len == wcslen(newurlW), "Test %u: Expected length %u, got %u.\n", i, wcslen(newurlW), len);
ok(!wcscmp(newurlW, expectW), "Test %u: Expected %s, got %s.\n",
ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl), i, debugstr_w(expectW), debugstr_w(newurlW));
"#%dW: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl); }
else
{
ok(len == ARRAY_SIZE(newurlW), "Test %u: Got length %u.\n", i, len);
ok(!wcscmp(newurlW, L"untouched"), "Test %u: Got %s.\n", i, debugstr_w(newurlW));
}
} }
/* buffer too small */ /* buffer too small */
...@@ -533,16 +537,16 @@ static void test_UrlApplyScheme(void) ...@@ -533,16 +537,16 @@ static void test_UrlApplyScheme(void)
/* NULL as parameter. The length and the buffer are not modified */ /* NULL as parameter. The length and the buffer are not modified */
lstrcpyA(newurl, untouchedA); lstrcpyA(newurl, untouchedA);
len = TEST_APPLY_MAX_LENGTH; len = ARRAY_SIZE(newurl);
res = UrlApplySchemeA(NULL, newurl, &len, TEST_APPLY[0].flags); res = UrlApplySchemeA(NULL, newurl, &len, TEST_APPLY[0].flags);
ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res); ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len); ok(len == ARRAY_SIZE(newurl), "got len %d\n", len);
ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA); ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
len = TEST_APPLY_MAX_LENGTH; len = ARRAY_SIZE(newurl);
res = UrlApplySchemeA(TEST_APPLY[0].url, NULL, &len, TEST_APPLY[0].flags); res = UrlApplySchemeA(TEST_APPLY[0].url, NULL, &len, TEST_APPLY[0].flags);
ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res); ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len); ok(len == ARRAY_SIZE(newurl), "got len %d\n", len);
lstrcpyA(newurl, untouchedA); lstrcpyA(newurl, untouchedA);
res = UrlApplySchemeA(TEST_APPLY[0].url, newurl, NULL, TEST_APPLY[0].flags); res = UrlApplySchemeA(TEST_APPLY[0].url, newurl, NULL, TEST_APPLY[0].flags);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment