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 ERROR_INVALID_HANDLE
== GetLastError(),
63 "last error wrong, got %ld expected ERROR_INVALID_PARAMETER/"
64 "ERROR_INVALID_HANDLE (98)\n", GetLastError());
66 SetLastError(ERROR_SUCCESS
);
67 retval
= pGetModuleBaseNameA( NULL
, NULL
, NULL
, MAX_PATH
);
68 ok(!retval
, "function result wrong, got %ld expected 0\n", retval
);
69 ok( ERROR_INVALID_PARAMETER
== GetLastError() ||
70 ERROR_INVALID_HANDLE
== GetLastError(),
71 "last error wrong, got %ld expected ERROR_INVALID_PARAMETER/"
72 "ERROR_INVALID_HANDLE (98)\n", GetLastError());
74 SetLastError(ERROR_SUCCESS
);
75 retval
= pGetModuleBaseNameA( NULL
, NULL
, buffer
, 0);
76 ok(!retval
, "function result wrong, got %ld expected 0\n", retval
);
77 ok( ERROR_INVALID_PARAMETER
== GetLastError() ||
78 ERROR_INVALID_HANDLE
== GetLastError(),
79 "last error wrong, got %ld expected ERROR_INVALID_PARAMETER/"
80 "ERROR_INVALID_HANDLE (98)\n", GetLastError());
82 memset(buffer
, 0, sizeof(buffer
));
83 SetLastError(ERROR_SUCCESS
);
84 retval
= pGetModuleBaseNameA( NULL
, NULL
, buffer
, 1);
85 ok(!retval
, "function result wrong, got %ld expected 0\n", retval
);
86 ok(ERROR_INVALID_HANDLE
== GetLastError(),
87 "last error wrong, got %ld expected ERROR_INVALID_HANDLE\n",
90 memset(buffer
, 0, sizeof(buffer
));
91 SetLastError(ERROR_SUCCESS
);
92 retval
= pGetModuleBaseNameA( self
, NULL
, buffer
, 1);
93 ok(!retval
|| retval
== 1,
94 "function result wrong, got %ld expected 0 (98)/1\n", retval
);
95 ok((retval
&& ERROR_SUCCESS
== GetLastError()) ||
96 (!retval
&& ERROR_MOD_NOT_FOUND
== GetLastError()),
97 "last error wrong, got %ld expected ERROR_SUCCESS/"
98 "ERROR_MOD_NOT_FOUND (98)\n", GetLastError());
99 ok(1 == strlen(buffer
) || !strlen(buffer
),
100 "buffer content length wrong, got %d(%s) expected 0 (98,XP)/1\n",
101 strlen(buffer
), buffer
);
103 memset(buffer
, 0, sizeof(buffer
));
104 SetLastError(ERROR_SUCCESS
);
105 retval
= pGetModuleBaseNameA( self
, modself
, buffer
, 1);
106 ok(retval
== 1, "function result wrong, got %ld expected 1\n", retval
);
107 ok(ERROR_SUCCESS
== GetLastError(),
108 "last error wrong, got %ld expected ERROR_SUCCESS\n",
110 ok((!strlen(buffer
)) || (1 == strlen(buffer
)),
111 "buffer content length wrong, got %d(%s) expected 0 (XP)/1\n",
112 strlen(buffer
), buffer
);
114 SetLastError(ERROR_SUCCESS
);
115 memset(buffer
, 0, sizeof(buffer
));
116 retval
= pGetModuleBaseNameA( self
, NULL
, buffer
, exact
);
117 ok( !retval
|| retval
== exact
,
118 "function result wrong, got %ld expected 0 (98)/%ld\n", retval
, exact
);
119 ok( (retval
&& ERROR_SUCCESS
== GetLastError()) ||
120 (!retval
&& ERROR_MOD_NOT_FOUND
== GetLastError()),
121 "last error wrong, got %ld expected ERROR_SUCCESS/"
122 "ERROR_MOD_NOT_FOUND (98)\n", GetLastError());
123 ok((retval
&& (exact
== strlen(buffer
) || exact
-1 == strlen(buffer
))) ||
124 (!retval
&& !strlen(buffer
)),
125 "buffer content length wrong, got %d(%s) expected 0(98)/%ld(XP)/%ld\n",
126 strlen(buffer
), buffer
, exact
-1, exact
);
128 SetLastError(ERROR_SUCCESS
);
129 memset(buffer
, 0, sizeof(buffer
));
130 retval
= pGetModuleBaseNameA( self
, modself
, buffer
, exact
);
131 ok(retval
== exact
|| retval
== exact
-1,
132 "function result wrong, got %ld expected %ld(98)/%ld\n",
133 retval
, exact
-1, exact
);
134 ok(ERROR_SUCCESS
== GetLastError(),
135 "last error wrong, got %ld expected ERROR_SUCCESS\n",
137 ok(exact
== strlen(buffer
) || exact
-1 == strlen(buffer
),
138 "buffer content length wrong, got %d(%s) expected %ld(98,XP)/%ld\n",
139 strlen(buffer
), buffer
, exact
-1, exact
);
144 dll
= LoadLibrary("psapi.dll");
146 trace("LoadLibraryA(psapi.dll) failed: skipping tests with target module\n");
150 pGetModuleBaseNameA
= (void*) GetProcAddress(dll
, "GetModuleBaseNameA");
152 test_module_base_name();