kernel32/tests: Add tests for GetDllDirectory.
This commit is contained in:
parent
5e1599d8c0
commit
5d5fd2fa9b
|
@ -21,6 +21,11 @@
|
|||
#include "wine/test.h"
|
||||
#include <windows.h>
|
||||
|
||||
static DWORD (WINAPI *pGetDllDirectoryA)(DWORD,LPSTR);
|
||||
static DWORD (WINAPI *pGetDllDirectoryW)(DWORD,LPWSTR);
|
||||
|
||||
static BOOL (WINAPI *pSetDllDirectoryA)(LPCSTR);
|
||||
|
||||
static BOOL is_unicode_enabled = TRUE;
|
||||
|
||||
static BOOL cmpStrAW(const char* a, const WCHAR* b, DWORD lenA, DWORD lenB)
|
||||
|
@ -386,6 +391,114 @@ static void testLoadLibraryEx(void)
|
|||
|
||||
}
|
||||
|
||||
static void testGetDllDirectory(void)
|
||||
{
|
||||
CHAR bufferA[MAX_PATH];
|
||||
WCHAR bufferW[MAX_PATH];
|
||||
size_t length;
|
||||
DWORD ret;
|
||||
int i;
|
||||
static const char *dll_directories[] =
|
||||
{
|
||||
"",
|
||||
"C:\\Some\\Path",
|
||||
"C:\\Some\\Path\\",
|
||||
"Q:\\A\\Long\\Path with spaces that\\probably\\doesn't exist!",
|
||||
};
|
||||
const int test_count = sizeof(dll_directories) / sizeof(dll_directories[0]);
|
||||
|
||||
if (!pGetDllDirectoryA || !pGetDllDirectoryW)
|
||||
{
|
||||
win_skip("GetDllDirectory not available\n");
|
||||
return;
|
||||
}
|
||||
if (!pSetDllDirectoryA)
|
||||
{
|
||||
win_skip("SetDllDirectoryA not available\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < test_count; i++)
|
||||
{
|
||||
length = strlen(dll_directories[i]);
|
||||
if (!pSetDllDirectoryA(dll_directories[i]))
|
||||
{
|
||||
skip("i=%d, SetDllDirectoryA failed\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* no buffer, determine length */
|
||||
ret = pGetDllDirectoryA(0, NULL);
|
||||
ok(ret == length + 1, "Expected %u, got %u\n", length + 1, ret);
|
||||
|
||||
ret = pGetDllDirectoryW(0, NULL);
|
||||
ok(ret == length + 1, "Expected %u, got %u\n", length + 1, ret);
|
||||
|
||||
/* buffer of exactly the right size */
|
||||
bufferA[length] = 'A';
|
||||
bufferA[length + 1] = 'A';
|
||||
ret = pGetDllDirectoryA(length + 1, bufferA);
|
||||
ok(ret == length, "i=%d, Expected %u, got %u\n", i, length, ret);
|
||||
ok(bufferA[length + 1] == 'A', "i=%d, Buffer overflow\n", i);
|
||||
ok(strcmp(bufferA, dll_directories[i]) == 0, "i=%d, Wrong path returned: '%s'\n", i, bufferA);
|
||||
|
||||
bufferW[length] = 'A';
|
||||
bufferW[length + 1] = 'A';
|
||||
ret = pGetDllDirectoryW(length + 1, bufferW);
|
||||
ok(ret == length, "i=%d, Expected %u, got %u\n", i, length, ret);
|
||||
ok(bufferW[length + 1] == 'A', "i=%d, Buffer overflow\n", i);
|
||||
ok(cmpStrAW(dll_directories[i], bufferW, length, length),
|
||||
"i=%d, Wrong path returned: %s\n", i, wine_dbgstr_w(bufferW));
|
||||
|
||||
/* zero size buffer
|
||||
* the A version always null-terminates the buffer,
|
||||
* the W version doesn't do it on some platforms */
|
||||
bufferA[0] = 'A';
|
||||
ret = pGetDllDirectoryA(0, bufferA);
|
||||
ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
|
||||
ok(bufferA[0] == 0, "i=%d, Buffer not null terminated\n", i);
|
||||
|
||||
bufferW[0] = 'A';
|
||||
ret = pGetDllDirectoryW(0, bufferW);
|
||||
ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
|
||||
ok(bufferW[0] == 0 || /* XP, 2003 */
|
||||
broken(bufferW[0] == 'A'), "i=%d, Buffer overflow\n", i);
|
||||
|
||||
/* buffer just one too short */
|
||||
bufferA[0] = 'A';
|
||||
ret = pGetDllDirectoryA(length, bufferA);
|
||||
ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
|
||||
ok(bufferA[0] == 0, "i=%d, Buffer not null terminated\n", i);
|
||||
|
||||
bufferW[0] = 'A';
|
||||
ret = pGetDllDirectoryW(length, bufferW);
|
||||
ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
|
||||
ok(bufferW[0] == 0 || /* XP, 2003 */
|
||||
broken(bufferW[0] == 'A'), "i=%d, Buffer overflow\n", i);
|
||||
|
||||
/* no buffer, but too short length */
|
||||
ret = pGetDllDirectoryA(length, NULL);
|
||||
ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
|
||||
|
||||
ret = pGetDllDirectoryW(length, NULL);
|
||||
ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
|
||||
}
|
||||
|
||||
/* unset whatever we did so following tests won't be affected */
|
||||
pSetDllDirectoryA(NULL);
|
||||
}
|
||||
|
||||
static void init_pointers(void)
|
||||
{
|
||||
HMODULE hKernel32 = GetModuleHandleA("kernel32.dll");
|
||||
|
||||
#define MAKEFUNC(f) (p##f = (void*)GetProcAddress(hKernel32, #f))
|
||||
MAKEFUNC(GetDllDirectoryA);
|
||||
MAKEFUNC(GetDllDirectoryW);
|
||||
MAKEFUNC(SetDllDirectoryA);
|
||||
#undef MAKEFUNC
|
||||
}
|
||||
|
||||
START_TEST(module)
|
||||
{
|
||||
WCHAR filenameW[MAX_PATH];
|
||||
|
@ -400,10 +513,14 @@ START_TEST(module)
|
|||
is_unicode_enabled = FALSE;
|
||||
}
|
||||
|
||||
init_pointers();
|
||||
|
||||
testGetModuleFileName(NULL);
|
||||
testGetModuleFileName("kernel32.dll");
|
||||
testGetModuleFileName_Wrong();
|
||||
|
||||
testGetDllDirectory();
|
||||
|
||||
testLoadLibraryA();
|
||||
testNestedLoadLibraryA();
|
||||
testLoadLibraryA_Wrong();
|
||||
|
|
Loading…
Reference in New Issue