Skip tests without error if psapi.dll could not be loaded.
[wine/multimedia.git] / dlls / psapi / tests / module.c
blobe587f0574b0085946f5e3366c65bf4366defe00f
1 /*
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
19 #include <stdarg.h>
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"
28 /* Function ptrs */
29 static HMODULE dll;
30 static DWORD (WINAPI *pGetModuleBaseNameA)(HANDLE, HANDLE, LPSTR, DWORD);
32 static void test_module_base_name(void)
33 { DWORD retval;
34 char buffer[MAX_PATH];
35 HMODULE self, modself;
36 DWORD exact;
38 if (!pGetModuleBaseNameA) return;
40 self = OpenProcess( PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,
41 FALSE, GetCurrentProcessId());
42 if (!self) {
43 ok(0, "OpenProcess() failed\n");
44 return;
46 modself = GetModuleHandle(NULL);
47 if (!modself) {
48 ok(0, "GetModuleHandle() failed\n");
49 return;
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;
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",
63 GetLastError());
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",
70 GetLastError());
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",
77 GetLastError());
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",
85 GetLastError());
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",
94 GetLastError());
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",
105 GetLastError());
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",
118 GetLastError());
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);
126 ok(retval == 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",
130 GetLastError());
131 ok(exact == strlen(buffer),
132 "buffer content length wrong, got %d(%s) expected %ld\n",
133 strlen(buffer), buffer, exact);
136 START_TEST(module)
138 dll = LoadLibrary("psapi.dll");
139 if (!dll) {
140 trace("LoadLibraryA(psapi.dll) failed: skipping tests with target module\n");
141 return;
144 pGetModuleBaseNameA = (void*) GetProcAddress(dll, "GetModuleBaseNameA");
146 test_module_base_name();
148 FreeLibrary(dll);