2 * Unit tests for module/DLL/library API
4 * Copyright (c) 2004 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/test.h"
24 static BOOL cmpStrAW(const char* a, const WCHAR* b, DWORD lenA, DWORD lenB)
28 DWORD len = MultiByteToWideChar( AreFileApisANSI() ? CP_ACP : CP_OEMCP, 0,
29 a, lenA, aw, sizeof(aw) / sizeof(aw[0]) );
30 if (len != lenB) return FALSE;
31 return memcmp(aw, b, len * sizeof(WCHAR)) == 0;
34 static void testGetModuleFileName(const char* name)
39 DWORD len1A, len1W, len2A, len2W;
41 hMod = (name) ? GetModuleHandle(name) : NULL;
43 /* first test, with enough space in buffer */
44 memset(bufA, '-', sizeof(bufA));
45 len1A = GetModuleFileNameA(hMod, bufA, sizeof(bufA));
46 ok(len1A > 0, "Getting module filename for handle %p\n", hMod);
47 memset(bufW, '-', sizeof(bufW));
48 len1W = GetModuleFileNameW(hMod, bufW, sizeof(bufW) / sizeof(WCHAR));
49 ok(len1W > 0, "Getting module filename for handle %p\n", hMod);
50 ok(len1A == strlen(bufA), "Unexpected length of GetModuleFilenameA (%ld/%d)\n", len1A, strlen(bufA));
51 ok(len1W == lstrlenW(bufW), "Unexpected length of GetModuleFilenameW (%ld/%d)\n", len1W, lstrlenW(bufW));
52 ok(cmpStrAW(bufA, bufW, len1A, len1W), "Comparing GetModuleFilenameAW results\n");
54 /* second test with a buffer too small */
55 memset(bufA, '-', sizeof(bufA));
56 len2A = GetModuleFileNameA(hMod, bufA, len1A / 2);
57 ok(len2A > 0, "Getting module filename for handle %p\n", hMod);
58 memset(bufW, '-', sizeof(bufW));
59 len2W = GetModuleFileNameW(hMod, bufW, len1W / 2);
60 ok(len2W > 0, "Getting module filename for handle %p\n", hMod);
61 ok(cmpStrAW(bufA, bufW, len2A, len2W), "Comparing GetModuleFilenameAW results with buffer too small\n" );
62 ok(len1A / 2 == len2A, "Correct length in GetModuleFilenameA with buffer too small (%ld/%ld)\n", len1A / 2, len2A);
63 ok(len1W / 2 == len2W, "Correct length in GetModuleFilenameW with buffer too small (%ld/%ld)\n", len1W / 2, len2W);
66 static void testGetModuleFileName_Wrong(void)
71 /* test wrong handle */
73 ok(GetModuleFileNameW((void*)0xffffffff, bufW, sizeof(bufW) / sizeof(WCHAR)) == 0, "Unexpected success in module handle\n");
74 ok(bufW[0] == '*', "When failing, buffer shouldn't be written to\n");
77 ok(GetModuleFileNameA((void*)0xffffffff, bufA, sizeof(bufA)) == 0, "Unexpected success in module handle\n");
78 ok(bufA[0] == '*', "When failing, buffer shouldn't be written to\n");
83 testGetModuleFileName(NULL);
84 testGetModuleFileName("kernel32.dll");
85 testGetModuleFileName_Wrong();