2 * Copyright (C) 2004 Stefan Leichter
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/test.h"
30 static DWORD (WINAPI
*pGetModuleBaseNameA
)(HANDLE
, HANDLE
, LPSTR
, DWORD
);
32 static void test_module_base_name(void)
34 char buffer
[MAX_PATH
];
35 HMODULE self
, modself
;
38 if (!pGetModuleBaseNameA
) return;
40 self
= OpenProcess( PROCESS_QUERY_INFORMATION
|PROCESS_VM_READ
,
41 FALSE
, GetCurrentProcessId());
43 ok(0, "OpenProcess() failed\n");
46 modself
= GetModuleHandle(NULL
);
48 ok(0, "GetModuleHandle() failed\n");
51 exact
= pGetModuleBaseNameA( self
, modself
, buffer
, MAX_PATH
);
53 ok(0, "GetModuleBaseNameA failed unexpected with error 0x%08lx\n",
58 SetLastError(ERROR_SUCCESS
);
59 retval
= pGetModuleBaseNameA( NULL
, NULL
, NULL
, 0);
60 ok(!retval
, "function result wrong, got %ld expected 0\n", retval
);
61 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
62 "last error wrong, got 0x%08lx expected ERROR_INVALID_PARAMETER\n",
65 SetLastError(ERROR_SUCCESS
);
66 retval
= pGetModuleBaseNameA( NULL
, NULL
, NULL
, MAX_PATH
);
67 ok(!retval
, "function result wrong, got %ld expected 0\n", retval
);
68 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
69 "last error wrong, got 0x%08lx expected ERROR_INVALID_PARAMETER\n",
72 SetLastError(ERROR_SUCCESS
);
73 retval
= pGetModuleBaseNameA( NULL
, NULL
, buffer
, 0);
74 ok(!retval
, "function result wrong, got %ld expected 0\n", retval
);
75 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
76 "last error wrong, got 0x%08lx expected ERROR_INVALID_PARAMETER\n",
79 memset(buffer
, 0, sizeof(buffer
));
80 SetLastError(ERROR_SUCCESS
);
81 retval
= pGetModuleBaseNameA( NULL
, NULL
, buffer
, 1);
82 ok(!retval
, "function result wrong, got %ld expected 0\n", retval
);
83 ok(ERROR_INVALID_HANDLE
== GetLastError(),
84 "last error wrong, got 0x%08lx expected ERROR_INVALID_HANDLE\n",
87 memset(buffer
, 0, sizeof(buffer
));
88 SetLastError(ERROR_SUCCESS
);
89 /* GetModuleFileNameEx may need to be fixed first ? */
90 retval
= pGetModuleBaseNameA( self
, NULL
, buffer
, 1);
91 todo_wine
ok(retval
== 1, "function result wrong, got %ld expected 1\n", retval
);
92 todo_wine
ok(ERROR_SUCCESS
== GetLastError(),
93 "last error wrong, got 0x%08lx expected ERROR_SUCCESS\n",
95 todo_wine
ok(1 == strlen(buffer
),
96 "buffer content length wrong, got %d(%s) expected 1\n",
97 strlen(buffer
), buffer
);
99 memset(buffer
, 0, sizeof(buffer
));
100 SetLastError(ERROR_SUCCESS
);
101 retval
= pGetModuleBaseNameA( self
, modself
, buffer
, 1);
102 ok(retval
== 1, "function result wrong, got %ld expected 1\n", retval
);
103 ok(ERROR_SUCCESS
== GetLastError(),
104 "last error wrong, got 0x%08lx expected ERROR_SUCCESS\n",
106 ok(1 == strlen(buffer
),
107 "buffer content length wrong, got %d(%s) expected 1\n",
108 strlen(buffer
), buffer
);
110 SetLastError(ERROR_SUCCESS
);
111 memset(buffer
, 0, sizeof(buffer
));
112 retval
= pGetModuleBaseNameA( self
, NULL
, buffer
, exact
);
113 /* GetModuleFileNameEx may need to be fixed first ? */
114 todo_wine
ok(retval
== exact
,
115 "function result wrong, got %ld expected %ld\n", retval
, exact
);
116 todo_wine
ok(ERROR_SUCCESS
== GetLastError(),
117 "last error wrong, got 0x%08lx expected ERROR_SUCCESS\n",
119 todo_wine
ok(exact
== strlen(buffer
),
120 "buffer content length wrong, got %d(%s) expected %ld\n",
121 strlen(buffer
), buffer
, exact
);
123 SetLastError(ERROR_SUCCESS
);
124 memset(buffer
, 0, sizeof(buffer
));
125 retval
= pGetModuleBaseNameA( self
, modself
, buffer
, exact
);
127 "function result wrong, got %ld expected %ld\n", retval
, exact
);
128 ok(ERROR_SUCCESS
== GetLastError(),
129 "last error wrong, got 0x%08lx expected ERROR_SUCCESS\n",
131 ok(exact
== strlen(buffer
),
132 "buffer content length wrong, got %d(%s) expected %ld\n",
133 strlen(buffer
), buffer
, exact
);
138 dll
= LoadLibrary("psapi.dll");
140 trace("LoadLibraryA(psapi.dll) failed: skipping tests with target module\n");
144 pGetModuleBaseNameA
= (void*) GetProcAddress(dll
, "GetModuleBaseNameA");
146 test_module_base_name();