revert 17709 for it break streach for windows mode. That why I did only got black...
[reactos.git] / reactos / regtests / winetests / psapi / module.c
1 /*
2 * Copyright (C) 2004 Stefan Leichter
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <stdarg.h>
20
21 #include "wine/test.h"
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winerror.h"
25 #include "wingdi.h"
26 #include "psapi.h"
27
28 /* Function ptrs */
29 static HMODULE dll;
30 static DWORD (WINAPI *pGetModuleBaseNameA)(HANDLE, HANDLE, LPSTR, DWORD);
31
32 static void test_module_base_name(void)
33 { DWORD retval;
34 char buffer[MAX_PATH];
35 HMODULE self, modself;
36 DWORD exact;
37
38 if (!pGetModuleBaseNameA) return;
39
40 self = OpenProcess( PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,
41 FALSE, GetCurrentProcessId());
42 if (!self) {
43 ok(0, "OpenProcess() failed\n");
44 return;
45 }
46 modself = GetModuleHandle(NULL);
47 if (!modself) {
48 ok(0, "GetModuleHandle() failed\n");
49 return;
50 }
51 exact = pGetModuleBaseNameA( self, modself, buffer, MAX_PATH);
52 if (!exact) {
53 ok(0, "GetModuleBaseNameA failed unexpected with error 0x%08lx\n",
54 GetLastError());
55 return;
56 }
57
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());
65
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());
73
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());
81
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",
88 GetLastError());
89
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 #ifndef __REACTOS__
96 ok((retval && ERROR_SUCCESS == GetLastError()) ||
97 (!retval && ERROR_MOD_NOT_FOUND == GetLastError()),
98 "last error wrong, got %ld expected ERROR_SUCCESS/"
99 "ERROR_MOD_NOT_FOUND (98)\n", GetLastError());
100 #endif
101 ok(1 == strlen(buffer) || !strlen(buffer),
102 "buffer content length wrong, got %d(%s) expected 0 (98,XP)/1\n",
103 strlen(buffer), buffer);
104
105 memset(buffer, 0, sizeof(buffer));
106 SetLastError(ERROR_SUCCESS);
107 retval = pGetModuleBaseNameA( self, modself, buffer, 1);
108 #ifndef __REACTOS__
109 ok(retval == 1, "function result wrong, got %ld expected 1\n", retval);
110 #endif
111 ok(ERROR_SUCCESS == GetLastError(),
112 "last error wrong, got %ld expected ERROR_SUCCESS\n",
113 GetLastError());
114 ok((!strlen(buffer)) || (1 == strlen(buffer)),
115 "buffer content length wrong, got %d(%s) expected 0 (XP)/1\n",
116 strlen(buffer), buffer);
117
118 SetLastError(ERROR_SUCCESS);
119 memset(buffer, 0, sizeof(buffer));
120 retval = pGetModuleBaseNameA( self, NULL, buffer, exact);
121 ok( !retval || retval == exact,
122 "function result wrong, got %ld expected 0 (98)/%ld\n", retval, exact);
123 #ifndef __REACTOS__
124 ok( (retval && ERROR_SUCCESS == GetLastError()) ||
125 (!retval && ERROR_MOD_NOT_FOUND == GetLastError()),
126 "last error wrong, got %ld expected ERROR_SUCCESS/"
127 "ERROR_MOD_NOT_FOUND (98)\n", GetLastError());
128 #endif
129 ok((retval && (exact == strlen(buffer) || exact -1 == strlen(buffer))) ||
130 (!retval && !strlen(buffer)),
131 "buffer content length wrong, got %d(%s) expected 0(98)/%ld(XP)/%ld\n",
132 strlen(buffer), buffer, exact -1, exact);
133
134 SetLastError(ERROR_SUCCESS);
135 memset(buffer, 0, sizeof(buffer));
136 retval = pGetModuleBaseNameA( self, modself, buffer, exact);
137 ok(retval == exact || retval == exact -1,
138 "function result wrong, got %ld expected %ld(98)/%ld\n",
139 retval, exact -1, exact);
140 ok(ERROR_SUCCESS == GetLastError(),
141 "last error wrong, got %ld expected ERROR_SUCCESS\n",
142 GetLastError());
143 ok(exact == strlen(buffer) || exact -1 == strlen(buffer),
144 "buffer content length wrong, got %d(%s) expected %ld(98,XP)/%ld\n",
145 strlen(buffer), buffer, exact -1, exact);
146 }
147
148 START_TEST(module)
149 {
150 dll = LoadLibrary("psapi.dll");
151 if (!dll) {
152 trace("LoadLibraryA(psapi.dll) failed: skipping tests with target module\n");
153 return;
154 }
155
156 pGetModuleBaseNameA = (void*) GetProcAddress(dll, "GetModuleBaseNameA");
157
158 test_module_base_name();
159
160 FreeLibrary(dll);
161 }