mmdevapi: Query MemoryWineUnixFuncs virtual memory and store the resulting handle.
[wine.git] / dlls / pdh / tests / pdh.c
blob195fd89eba58714dd91d05ff0e8b81d701fa664d
1 /*
2 * Tests for pdh.dll (Performance Data Helper)
4 * Copyright 2007 Hans Leidekker
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdio.h>
23 #include "windows.h"
25 #include "pdh.h"
26 #include "pdhmsg.h"
28 #include "wine/test.h"
30 static HMODULE pdh;
32 static PDH_STATUS (WINAPI *pPdhAddEnglishCounterA)(PDH_HQUERY, LPCSTR, DWORD_PTR, PDH_HCOUNTER *);
33 static PDH_STATUS (WINAPI *pPdhAddEnglishCounterW)(PDH_HQUERY, LPCWSTR, DWORD_PTR, PDH_HCOUNTER *);
34 static PDH_STATUS (WINAPI *pPdhCollectQueryDataWithTime)(PDH_HQUERY, LONGLONG *);
35 static PDH_STATUS (WINAPI *pPdhValidatePathExA)(PDH_HLOG, LPCSTR);
36 static PDH_STATUS (WINAPI *pPdhValidatePathExW)(PDH_HLOG, LPCWSTR);
38 #define GETFUNCPTR(func) p##func = (void *)GetProcAddress( pdh, #func );
41 /* Returns true if the user interface is in English. Note that this does not
42 * presume of the formatting of dates, numbers, etc.
44 static BOOL is_lang_english(void)
46 static HMODULE hkernel32 = NULL;
47 static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
48 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
50 if (!hkernel32)
52 hkernel32 = GetModuleHandleA("kernel32.dll");
53 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
54 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
56 if (pGetThreadUILanguage)
57 return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
58 if (pGetUserDefaultUILanguage)
59 return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
61 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
64 static void init_function_ptrs( void )
66 pdh = GetModuleHandleA( "pdh" );
67 GETFUNCPTR( PdhAddEnglishCounterA )
68 GETFUNCPTR( PdhAddEnglishCounterW )
69 GETFUNCPTR( PdhCollectQueryDataWithTime )
70 GETFUNCPTR( PdhValidatePathExA )
71 GETFUNCPTR( PdhValidatePathExW )
74 static const WCHAR processor_time[] = L"% Processor Time";
75 static const WCHAR uptime[] = L"System Up Time";
77 static const WCHAR system_uptime[] = L"\\System\\System Up Time";
78 static const WCHAR nonexistent_counter[] = L"\\System\\System Down Time";
79 static const WCHAR percentage_processor_time[] = L"\\Processor(_Total)\\% Processor Time";
81 static void test_PdhOpenQueryA( void )
83 PDH_STATUS ret;
84 PDH_HQUERY query;
86 ret = PdhOpenQueryA( NULL, 0, NULL );
87 ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryA failed 0x%08lx\n", ret);
89 ret = PdhOpenQueryA( NULL, 0, &query );
90 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", ret);
92 ret = PdhCloseQuery( NULL );
93 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08lx\n", ret);
95 ret = PdhCloseQuery( &query );
96 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08lx\n", ret);
98 ret = PdhCloseQuery( query );
99 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
101 ret = PdhCloseQuery( query );
102 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08lx\n", ret);
105 static void test_PdhOpenQueryW( void )
107 PDH_STATUS ret;
108 PDH_HQUERY query;
110 ret = PdhOpenQueryW( NULL, 0, NULL );
111 ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryW failed 0x%08lx\n", ret);
113 ret = PdhOpenQueryW( NULL, 0, &query );
114 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08lx\n", ret);
116 ret = PdhCloseQuery( NULL );
117 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08lx\n", ret);
119 ret = PdhCloseQuery( &query );
120 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08lx\n", ret);
122 ret = PdhCloseQuery( query );
123 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
125 ret = PdhCloseQuery( query );
126 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08lx\n", ret);
129 static void test_PdhAddCounterA( void )
131 PDH_STATUS ret;
132 PDH_HQUERY query;
133 PDH_HCOUNTER counter;
135 ret = PdhOpenQueryA( NULL, 0, &query );
136 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", ret);
138 ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, NULL );
139 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08lx\n", ret);
141 ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, &counter );
142 ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterA failed 0x%08lx\n", ret);
144 ret = PdhAddCounterA( query, NULL, 0, &counter );
145 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08lx\n", ret);
147 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, NULL );
148 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08lx\n", ret);
150 ret = PdhAddCounterA( query, "\\System\\Nonexistent Counter", 0, &counter );
151 ok(ret == PDH_CSTATUS_NO_COUNTER ||
152 broken(ret == PDH_INVALID_PATH), /* Win2K */
153 "PdhAddCounterA failed 0x%08lx\n", ret);
154 ok(!counter, "PdhAddCounterA failed %p\n", counter);
156 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
157 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", ret);
159 ret = PdhCollectQueryData( NULL );
160 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08lx\n", ret);
162 ret = PdhCollectQueryData( counter );
163 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08lx\n", ret);
165 ret = PdhCollectQueryData( query );
166 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", ret);
168 ret = PdhRemoveCounter( NULL );
169 ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08lx\n", ret);
171 ret = PdhRemoveCounter( counter );
172 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08lx\n", ret);
174 ret = PdhCloseQuery( query );
175 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
178 static void test_PdhAddCounterW( void )
180 PDH_STATUS ret;
181 PDH_HQUERY query;
182 PDH_HCOUNTER counter;
184 ret = PdhOpenQueryW( NULL, 0, &query );
185 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08lx\n", ret);
187 ret = PdhAddCounterW( NULL, percentage_processor_time, 0, NULL );
188 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08lx\n", ret);
190 ret = PdhAddCounterW( NULL, percentage_processor_time, 0, &counter );
191 ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterW failed 0x%08lx\n", ret);
193 ret = PdhAddCounterW( query, NULL, 0, &counter );
194 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08lx\n", ret);
196 ret = PdhAddCounterW( query, percentage_processor_time, 0, NULL );
197 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08lx\n", ret);
199 ret = PdhAddCounterW( query, nonexistent_counter, 0, &counter );
200 ok(ret == PDH_CSTATUS_NO_COUNTER ||
201 broken(ret == PDH_INVALID_PATH), /* Win2K */
202 "PdhAddCounterW failed 0x%08lx\n", ret);
203 ok(!counter, "PdhAddCounterW failed %p\n", counter);
205 ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
206 ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08lx\n", ret);
208 ret = PdhCollectQueryData( NULL );
209 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08lx\n", ret);
211 ret = PdhCollectQueryData( counter );
212 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08lx\n", ret);
214 ret = PdhCollectQueryData( query );
215 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", ret);
217 ret = PdhRemoveCounter( NULL );
218 ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08lx\n", ret);
220 ret = PdhRemoveCounter( counter );
221 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08lx\n", ret);
223 ret = PdhCloseQuery( query );
224 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
227 static void test_PdhAddEnglishCounterA( void )
229 PDH_STATUS ret;
230 PDH_HQUERY query;
231 PDH_HCOUNTER counter;
233 ret = PdhOpenQueryA( NULL, 0, &query );
234 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", ret);
236 ret = PdhCollectQueryData( query );
237 ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08lx\n", ret);
239 ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, NULL );
240 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08lx\n", ret);
242 ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, &counter );
243 ok(ret == PDH_INVALID_HANDLE || broken(ret == PDH_INVALID_ARGUMENT) /* win10 <= 1909 */,
244 "PdhAddEnglishCounterA failed 0x%08lx\n", ret);
246 ret = pPdhAddEnglishCounterA( query, NULL, 0, &counter );
247 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08lx\n", ret);
249 ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, NULL );
250 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08lx\n", ret);
252 ret = pPdhAddEnglishCounterA( query, "\\System\\System Down Time", 0, &counter );
253 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddEnglishCounterA failed 0x%08lx\n", ret);
254 ok(!counter, "PdhAddEnglishCounterA failed %p\n", counter);
256 ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, &counter );
257 ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterA failed 0x%08lx\n", ret);
259 ret = PdhCollectQueryData( query );
260 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", ret);
262 ret = PdhRemoveCounter( counter );
263 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08lx\n", ret);
265 ret = PdhCloseQuery( query );
266 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
269 static void test_PdhAddEnglishCounterW( void )
271 PDH_STATUS ret;
272 PDH_HQUERY query;
273 PDH_HCOUNTER counter;
275 ret = PdhOpenQueryW( NULL, 0, &query );
276 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08lx\n", ret);
278 ret = PdhCollectQueryData( query );
279 ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08lx\n", ret);
281 ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, NULL );
282 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08lx\n", ret);
284 ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, &counter );
285 ok(ret == PDH_INVALID_HANDLE || broken(ret == PDH_INVALID_ARGUMENT) /* win10 <= 1909 */,
286 "PdhAddEnglishCounterW failed 0x%08lx\n", ret);
288 ret = pPdhAddEnglishCounterW( query, NULL, 0, &counter );
289 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08lx\n", ret);
291 ret = pPdhAddEnglishCounterW( query, system_uptime, 0, NULL );
292 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08lx\n", ret);
294 ret = pPdhAddEnglishCounterW( query, nonexistent_counter, 0, &counter );
295 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddEnglishCounterW failed 0x%08lx\n", ret);
296 ok(!counter, "PdhAddEnglishCounterA failed %p\n", counter);
298 ret = pPdhAddEnglishCounterW( query, system_uptime, 0, &counter );
299 ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterW failed 0x%08lx\n", ret);
301 ret = PdhCollectQueryData( query );
302 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", ret);
304 ret = PdhRemoveCounter( counter );
305 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08lx\n", ret);
307 ret = PdhCloseQuery( query );
308 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
311 static void test_PdhCollectQueryDataWithTime( void )
313 PDH_STATUS ret;
314 PDH_HQUERY query;
315 PDH_HCOUNTER counter;
316 LONGLONG time;
318 ret = PdhOpenQueryA( NULL, 0, &query );
319 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", ret);
321 ret = PdhCollectQueryData( query );
322 ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08lx\n", ret);
324 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
325 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", ret);
327 ret = pPdhCollectQueryDataWithTime( NULL, NULL );
328 ok(ret == PDH_INVALID_ARGUMENT, "PdhCollectQueryDataWithTime failed 0x%08lx\n", ret);
330 ret = pPdhCollectQueryDataWithTime( query, NULL );
331 ok(ret == PDH_INVALID_ARGUMENT, "PdhCollectQueryDataWithTime failed 0x%08lx\n", ret);
333 ret = pPdhCollectQueryDataWithTime( NULL, &time );
334 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryDataWithTime failed 0x%08lx\n", ret);
336 ret = pPdhCollectQueryDataWithTime( query, &time );
337 ok(ret == ERROR_SUCCESS, "PdhCollectQueryDataWithTime failed 0x%08lx\n", ret);
339 ret = PdhCloseQuery( query );
340 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
343 static void test_PdhGetFormattedCounterValue( void )
345 PDH_STATUS ret;
346 PDH_HQUERY query;
347 PDH_HCOUNTER counter;
348 PDH_FMT_COUNTERVALUE value;
350 ret = PdhOpenQueryA( NULL, 0, &query );
351 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", ret);
353 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
354 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", ret);
356 ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, NULL );
357 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08lx\n", ret);
359 ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, &value );
360 ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterValue failed 0x%08lx\n", ret);
362 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, NULL );
363 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08lx\n", ret);
365 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
366 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08lx\n", ret);
368 ret = PdhCollectQueryData( query );
369 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", ret);
371 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
372 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08lx\n", ret);
374 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOSCALE, NULL, &value );
375 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08lx\n", ret);
377 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOCAP100, NULL, &value );
378 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08lx\n", ret);
380 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_1000, NULL, &value );
381 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08lx\n", ret);
383 ret = PdhSetCounterScaleFactor( counter, 2 );
384 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
386 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
387 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08lx\n", ret);
389 ret = PdhCloseQuery( query );
390 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
393 static void test_PdhGetRawCounterValue( void )
395 PDH_STATUS ret;
396 PDH_HQUERY query;
397 PDH_HCOUNTER counter;
398 PDH_RAW_COUNTER value;
400 ret = PdhOpenQueryA( NULL, 0, &query );
401 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", ret);
403 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
404 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", ret);
406 ret = PdhGetRawCounterValue( NULL, NULL, &value );
407 ok(ret == PDH_INVALID_HANDLE, "PdhGetRawCounterValue failed 0x%08lx\n", ret);
409 ret = PdhGetRawCounterValue( counter, NULL, NULL );
410 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetRawCounterValue failed 0x%08lx\n", ret);
412 ret = PdhGetRawCounterValue( counter, NULL, &value );
413 ok(ret == ERROR_SUCCESS, "PdhGetRawCounterValue failed 0x%08lx\n", ret);
414 ok(value.CStatus == ERROR_SUCCESS, "expected ERROR_SUCCESS got %lx\n", value.CStatus);
416 ret = PdhCollectQueryData( query );
417 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", ret);
419 ret = PdhGetRawCounterValue( counter, NULL, &value );
420 ok(ret == ERROR_SUCCESS, "PdhGetRawCounterValue failed 0x%08lx\n", ret);
421 ok(value.CStatus == ERROR_SUCCESS, "expected ERROR_SUCCESS got %lx\n", value.CStatus);
423 ret = PdhCloseQuery( query );
424 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
427 static void test_PdhSetCounterScaleFactor( void )
429 PDH_STATUS ret;
430 PDH_HQUERY query;
431 PDH_HCOUNTER counter;
433 ret = PdhOpenQueryA( NULL, 0, &query );
434 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", ret);
436 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
437 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", ret);
439 ret = PdhSetCounterScaleFactor( NULL, 8 );
440 ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
442 ret = PdhSetCounterScaleFactor( NULL, 1 );
443 ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
445 ret = PdhSetCounterScaleFactor( counter, 8 );
446 ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
448 ret = PdhSetCounterScaleFactor( counter, -8 );
449 ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
451 ret = PdhSetCounterScaleFactor( counter, 7 );
452 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
454 ret = PdhSetCounterScaleFactor( counter, 0 );
455 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
457 ret = PdhCloseQuery( query );
458 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
461 static void test_PdhGetCounterTimeBase( void )
463 PDH_STATUS ret;
464 PDH_HQUERY query;
465 PDH_HCOUNTER counter;
466 LONGLONG base;
468 ret = PdhOpenQueryA( NULL, 0, &query );
469 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", ret);
471 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
472 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", ret);
474 ret = PdhGetCounterTimeBase( NULL, NULL );
475 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08lx\n", ret);
477 ret = PdhGetCounterTimeBase( NULL, &base );
478 ok(ret == PDH_INVALID_HANDLE, "PdhGetCounterTimeBase failed 0x%08lx\n", ret);
480 ret = PdhGetCounterTimeBase( counter, NULL );
481 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08lx\n", ret);
483 ret = PdhGetCounterTimeBase( counter, &base );
484 ok(ret == ERROR_SUCCESS, "PdhGetCounterTimeBase failed 0x%08lx\n", ret);
486 ret = PdhCloseQuery( query );
487 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
490 static void test_PdhGetCounterInfoA( void )
492 PDH_STATUS ret;
493 PDH_HQUERY query;
494 PDH_HCOUNTER counter;
495 PDH_COUNTER_INFO_A info;
496 DWORD size;
498 ret = PdhOpenQueryA( NULL, 0, &query );
499 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", ret);
501 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
502 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", ret);
504 ret = PdhGetCounterInfoA( NULL, 0, NULL, NULL );
505 ok(ret == PDH_INVALID_HANDLE || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08lx\n", ret);
507 ret = PdhGetCounterInfoA( counter, 0, NULL, NULL );
508 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08lx\n", ret);
510 ret = PdhGetCounterInfoA( counter, 0, NULL, &info );
511 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08lx\n", ret);
513 size = sizeof(info) - 1;
514 ret = PdhGetCounterInfoA( counter, 0, &size, NULL );
515 ok(ret == PDH_MORE_DATA || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08lx\n", ret);
517 size = sizeof(info);
518 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
519 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08lx\n", ret);
520 ok(size == sizeof(info), "PdhGetCounterInfoA failed %ld\n", size);
522 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
523 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08lx\n", ret);
524 ok(info.lScale == 0, "lScale %ld\n", info.lScale);
526 ret = PdhSetCounterScaleFactor( counter, 0 );
527 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
529 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
530 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08lx\n", ret);
531 ok(info.lScale == 0, "lScale %ld\n", info.lScale);
533 ret = PdhSetCounterScaleFactor( counter, -5 );
534 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
536 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
537 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08lx\n", ret);
538 ok(info.lScale == -5, "lScale %ld\n", info.lScale);
540 ret = PdhCloseQuery( query );
541 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
544 static void test_PdhGetCounterInfoW( void )
546 PDH_STATUS ret;
547 PDH_HQUERY query;
548 PDH_HCOUNTER counter;
549 PDH_COUNTER_INFO_W info;
550 DWORD size;
552 ret = PdhOpenQueryW( NULL, 0, &query );
553 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08lx\n", ret);
555 ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
556 ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08lx\n", ret);
558 ret = PdhGetCounterInfoW( NULL, 0, NULL, NULL );
559 ok(ret == PDH_INVALID_HANDLE || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08lx\n", ret);
561 ret = PdhGetCounterInfoW( counter, 0, NULL, NULL );
562 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08lx\n", ret);
564 ret = PdhGetCounterInfoW( counter, 0, NULL, &info );
565 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08lx\n", ret);
567 size = sizeof(info) - 1;
568 ret = PdhGetCounterInfoW( counter, 0, &size, NULL );
569 ok(ret == PDH_MORE_DATA || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08lx\n", ret);
571 size = sizeof(info);
572 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
573 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08lx\n", ret);
574 ok(size == sizeof(info), "PdhGetCounterInfoW failed %ld\n", size);
576 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
577 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08lx\n", ret);
578 ok(info.lScale == 0, "lScale %ld\n", info.lScale);
580 ret = PdhSetCounterScaleFactor( counter, 0 );
581 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
583 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
584 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08lx\n", ret);
585 ok(info.lScale == 0, "lScale %ld\n", info.lScale);
587 ret = PdhSetCounterScaleFactor( counter, -5 );
588 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08lx\n", ret);
590 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
591 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08lx\n", ret);
592 ok(info.lScale == -5, "lScale %ld\n", info.lScale);
594 ret = PdhCloseQuery( query );
595 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret);
598 static void test_PdhLookupPerfIndexByNameA( void )
600 PDH_STATUS ret;
601 DWORD index;
603 ret = PdhLookupPerfIndexByNameA( NULL, NULL, NULL );
604 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08lx\n", ret);
606 ret = PdhLookupPerfIndexByNameA( NULL, NULL, &index );
607 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08lx\n", ret);
609 ret = PdhLookupPerfIndexByNameA( NULL, "No Counter", &index );
610 ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameA failed 0x%08lx\n", ret);
612 ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", NULL );
613 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08lx\n", ret);
615 ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", &index );
616 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameA failed 0x%08lx\n", ret);
617 ok(index == 6, "PdhLookupPerfIndexByNameA failed %ld\n", index);
619 ret = PdhLookupPerfIndexByNameA( NULL, "System Up Time", &index );
620 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameA failed 0x%08lx\n", ret);
621 ok(index == 674, "PdhLookupPerfIndexByNameA failed %ld\n", index);
624 static void test_PdhLookupPerfIndexByNameW( void )
626 PDH_STATUS ret;
627 DWORD index;
629 ret = PdhLookupPerfIndexByNameW( NULL, NULL, NULL );
630 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08lx\n", ret);
632 ret = PdhLookupPerfIndexByNameW( NULL, NULL, &index );
633 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08lx\n", ret);
635 ret = PdhLookupPerfIndexByNameW( NULL, L"No Counter", &index );
636 ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameW failed 0x%08lx\n", ret);
638 ret = PdhLookupPerfIndexByNameW( NULL, processor_time, NULL );
639 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08lx\n", ret);
641 ret = PdhLookupPerfIndexByNameW( NULL, processor_time, &index );
642 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameW failed 0x%08lx\n", ret);
643 ok(index == 6, "PdhLookupPerfIndexByNameW failed %ld\n", index);
645 ret = PdhLookupPerfIndexByNameW( NULL, uptime, &index );
646 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameW failed 0x%08lx\n", ret);
647 ok(index == 674, "PdhLookupPerfIndexByNameW failed %ld\n", index);
650 static void test_PdhLookupPerfNameByIndexA( void )
652 PDH_STATUS ret;
653 char buffer[PDH_MAX_COUNTER_NAME] = "!!";
654 DWORD size;
656 ret = PdhLookupPerfNameByIndexA( NULL, 0, NULL, NULL );
657 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexA failed 0x%08lx\n", ret);
659 size = 0;
660 ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
661 ok(ret == PDH_MORE_DATA || ret == PDH_INSUFFICIENT_BUFFER, "PdhLookupPerfNameByIndexA failed 0x%08lx\n", ret);
663 size = sizeof(buffer);
664 ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
665 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08lx\n", ret);
666 ok(!lstrcmpA( buffer, "% Processor Time" ),
667 "PdhLookupPerfNameByIndexA failed, got %s expected \'%% Processor Time\'\n", buffer);
668 ok(size == sizeof("% Processor Time"), "PdhLookupPerfNameByIndexA failed %ld\n", size);
670 size = sizeof(buffer);
671 ret = PdhLookupPerfNameByIndexA( NULL, 674, NULL, &size );
672 ok(ret == PDH_INVALID_ARGUMENT ||
673 ret == PDH_MORE_DATA, /* win2k3 */
674 "PdhLookupPerfNameByIndexA failed 0x%08lx\n", ret);
676 size = sizeof(buffer);
677 ret = PdhLookupPerfNameByIndexA( NULL, 674, buffer, &size );
678 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08lx\n", ret);
679 ok(!lstrcmpA( buffer, "System Up Time" ),
680 "PdhLookupPerfNameByIndexA failed, got %s expected \'System Up Time\'\n", buffer);
681 ok(size == sizeof("System Up Time"), "PdhLookupPerfNameByIndexA failed %ld\n", size);
684 static void test_PdhLookupPerfNameByIndexW( void )
686 PDH_STATUS ret;
687 WCHAR buffer[PDH_MAX_COUNTER_NAME];
688 DWORD size;
690 ret = PdhLookupPerfNameByIndexW( NULL, 0, NULL, NULL );
691 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexW failed 0x%08lx\n", ret);
693 size = 0;
694 ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
695 ok(ret == PDH_MORE_DATA || ret == PDH_INSUFFICIENT_BUFFER, "PdhLookupPerfNameByIndexW failed 0x%08lx\n", ret);
697 size = ARRAY_SIZE(buffer);
698 ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
699 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08lx\n", ret);
700 ok(size == ARRAY_SIZE(processor_time), "PdhLookupPerfNameByIndexW failed %ld\n", size);
702 size = ARRAY_SIZE(buffer);
703 ret = PdhLookupPerfNameByIndexW( NULL, 674, NULL, &size );
704 ok(ret == PDH_INVALID_ARGUMENT ||
705 ret == PDH_MORE_DATA, /* win2k3 */
706 "PdhLookupPerfNameByIndexW failed 0x%08lx\n", ret);
708 size = ARRAY_SIZE(buffer);
709 ret = PdhLookupPerfNameByIndexW( NULL, 674, buffer, &size );
710 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08lx\n", ret);
711 ok(size == ARRAY_SIZE(uptime), "PdhLookupPerfNameByIndexW failed %ld\n", size);
714 static void test_PdhValidatePathA( void )
716 PDH_STATUS ret;
718 ret = PdhValidatePathA( NULL );
719 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathA failed 0x%08lx\n", ret);
721 ret = PdhValidatePathA( "" );
722 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathA failed 0x%08lx\n", ret);
724 ret = PdhValidatePathA( "\\System" );
725 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathA failed 0x%08lx\n", ret);
727 ret = PdhValidatePathA( "System Up Time" );
728 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathA failed 0x%08lx\n", ret);
730 ret = PdhValidatePathA( "\\System\\Nonexistent Counter" );
731 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathA failed 0x%08lx\n", ret);
733 ret = PdhValidatePathA( "\\System\\System Up Time" );
734 ok(ret == ERROR_SUCCESS, "PdhValidatePathA failed 0x%08lx\n", ret);
737 static void test_PdhValidatePathW( void )
739 PDH_STATUS ret;
741 ret = PdhValidatePathW( NULL );
742 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathW failed 0x%08lx\n", ret);
744 ret = PdhValidatePathW( L"" );
745 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathW failed 0x%08lx\n", ret);
747 ret = PdhValidatePathW( L"\\System" );
748 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathW failed 0x%08lx\n", ret);
750 ret = PdhValidatePathW( uptime );
751 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathW failed 0x%08lx\n", ret);
753 ret = PdhValidatePathW( nonexistent_counter );
754 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathW failed 0x%08lx\n", ret);
756 ret = PdhValidatePathW( system_uptime );
757 ok(ret == ERROR_SUCCESS, "PdhValidatePathW failed 0x%08lx\n", ret);
760 static void test_PdhValidatePathExA( void )
762 PDH_STATUS ret;
764 ret = pPdhValidatePathExA( NULL, NULL );
765 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExA failed 0x%08lx\n", ret);
767 ret = pPdhValidatePathExA( NULL, "" );
768 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExA failed 0x%08lx\n", ret);
770 ret = pPdhValidatePathExA( NULL, "\\System" );
771 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExA failed 0x%08lx\n", ret);
773 ret = pPdhValidatePathExA( NULL, "System Up Time" );
774 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExA failed 0x%08lx\n", ret);
776 ret = pPdhValidatePathExA( NULL, "\\System\\System Down Time" );
777 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathExA failed 0x%08lx\n", ret);
779 ret = pPdhValidatePathExA( NULL, "\\System\\System Up Time" );
780 ok(ret == ERROR_SUCCESS, "PdhValidatePathExA failed 0x%08lx\n", ret);
783 static void test_PdhValidatePathExW( void )
785 PDH_STATUS ret;
787 ret = pPdhValidatePathExW( NULL, NULL );
788 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExW failed 0x%08lx\n", ret);
790 ret = pPdhValidatePathExW( NULL, L"" );
791 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExW failed 0x%08lx\n", ret);
793 ret = pPdhValidatePathExW( NULL, L"\\System" );
794 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExW failed 0x%08lx\n", ret);
796 ret = pPdhValidatePathExW( NULL, uptime );
797 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExW failed 0x%08lx\n", ret);
799 ret = pPdhValidatePathExW( NULL, nonexistent_counter );
800 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathExW failed 0x%08lx\n", ret);
802 ret = pPdhValidatePathExW( NULL, system_uptime );
803 ok(ret == ERROR_SUCCESS, "PdhValidatePathExW failed 0x%08lx\n", ret);
806 static void test_PdhCollectQueryDataEx(void)
808 PDH_STATUS status;
809 PDH_HQUERY query;
810 PDH_HCOUNTER counter;
811 HANDLE event;
812 BOOL ret;
813 UINT i;
815 status = PdhOpenQueryA( NULL, 0, &query );
816 ok(status == ERROR_SUCCESS, "PdhOpenQuery failed 0x%08lx\n", status);
818 event = CreateEventA( NULL, FALSE, FALSE, "winetest" );
819 ok(event != NULL, "CreateEvent failed\n");
821 status = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
822 ok(status == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", status);
824 status = PdhCollectQueryDataEx( NULL, 1, event );
825 ok(status == PDH_INVALID_HANDLE, "PdhCollectQueryDataEx failed 0x%08lx\n", status);
827 status = PdhCollectQueryDataEx( query, 1, NULL );
828 ok(status == ERROR_SUCCESS, "PdhCollectQueryDataEx failed 0x%08lx\n", status);
830 status = PdhCollectQueryDataEx( query, 1, event );
831 ok(status == ERROR_SUCCESS, "PdhCollectQueryDataEx failed 0x%08lx\n", status);
833 status = PdhCollectQueryData( query );
834 ok(status == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", status);
836 for (i = 0; i < 3; i++)
838 if (WaitForSingleObject( event, INFINITE ) == WAIT_OBJECT_0)
840 PDH_FMT_COUNTERVALUE value;
842 status = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
843 ok(status == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08lx\n", status);
845 trace( "uptime %s\n", wine_dbgstr_longlong(U(value).largeValue) );
849 ret = CloseHandle( event );
850 ok(ret, "CloseHandle failed\n");
852 status = PdhCloseQuery( query );
853 ok(status == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", status);
856 static void test_PdhMakeCounterPathA(void)
858 PDH_STATUS ret;
859 PDH_COUNTER_PATH_ELEMENTS_A e;
860 char buffer[1024];
861 DWORD buflen;
863 ret = PdhMakeCounterPathA(NULL, NULL, NULL, 0);
864 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
866 buflen = 0;
867 ret = PdhMakeCounterPathA(NULL, NULL, &buflen, 0);
868 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
870 if (0) { /* Crashes on Windows 10 >= 2004 */
871 buflen = 0;
872 ret = PdhMakeCounterPathA(NULL, buffer, &buflen, 0);
873 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
876 buflen = sizeof(buffer);
877 memset(&e, 0, sizeof(e));
878 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
879 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
881 buffer[0] = 0;
882 buflen = sizeof(buffer);
883 e.szMachineName = (char *)"machine";
884 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
885 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
886 ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
888 buffer[0] = 0;
889 buflen = sizeof(buffer);
890 e.szObjectName = (char *)"object";
891 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
892 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
893 ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
895 buffer[0] = 0;
896 buflen = sizeof(buffer);
897 e.szInstanceName = (char *)"instance";
898 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
899 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
900 ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
902 buffer[0] = 0;
903 buflen = sizeof(buffer);
904 e.szParentInstance = (char *)"parent";
905 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
906 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
907 ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
909 buffer[0] = 0;
910 buflen = sizeof(buffer);
911 e.dwInstanceIndex = 1;
912 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
913 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
914 ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
916 buffer[0] = 0;
917 buflen = sizeof(buffer);
918 e.szCounterName = (char *)"counter";
919 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
920 ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
921 ok(!strcmp(buffer, "\\\\machine\\object(parent/instance#1)\\counter"),
922 "expected \"\\\\machine\\object(parent/instance#1)\\counter\" got %s\n", buffer);
924 buffer[0] = 0;
925 buflen = sizeof(buffer);
926 e.szParentInstance = NULL;
927 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
928 ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
929 ok(!strcmp(buffer, "\\\\machine\\object(instance#1)\\counter"),
930 "expected \"\\\\machine\\object(instance#1)\\counter\" got %s\n", buffer);
932 buffer[0] = 0;
933 buflen = sizeof(buffer);
934 e.szInstanceName = NULL;
935 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
936 ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
937 ok(!strcmp(buffer, "\\\\machine\\object\\counter"),
938 "expected \"\\\\machine\\object\\counter\" got %s\n", buffer);
940 buffer[0] = 0;
941 buflen = sizeof(buffer);
942 e.szMachineName = NULL;
943 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
944 ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
945 ok(!strcmp(buffer, "\\object\\counter"),
946 "expected \"\\object\\counter\" got %s\n", buffer);
948 buffer[0] = 0;
949 buflen = sizeof(buffer);
950 e.szObjectName = NULL;
951 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
952 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08lx\n", ret);
955 static void test_PdhGetDllVersion(void)
957 PDH_STATUS ret;
958 DWORD version;
960 ret = PdhGetDllVersion(NULL);
961 ok(ret == PDH_INVALID_ARGUMENT ||
962 broken(ret == ERROR_SUCCESS), /* Vista+ */
963 "Expected PdhGetDllVersion to return PDH_INVALID_ARGUMENT, got %ld\n", ret);
965 ret = PdhGetDllVersion(&version);
966 ok(ret == ERROR_SUCCESS,
967 "Expected PdhGetDllVersion to return ERROR_SUCCESS, got %ld\n", ret);
969 if (ret == ERROR_SUCCESS)
971 ok(version == PDH_CVERSION_WIN50 ||
972 version == PDH_VERSION,
973 "Expected version number to be PDH_CVERSION_WIN50 or PDH_VERSION, got %lu\n", version);
977 START_TEST(pdh)
979 if (!is_lang_english())
981 skip("An English UI is needed for the pdh tests\n");
982 return;
984 init_function_ptrs();
986 test_PdhOpenQueryA();
987 test_PdhOpenQueryW();
989 test_PdhAddCounterA();
990 test_PdhAddCounterW();
992 if (pPdhAddEnglishCounterA) test_PdhAddEnglishCounterA();
993 if (pPdhAddEnglishCounterW) test_PdhAddEnglishCounterW();
994 if (pPdhCollectQueryDataWithTime) test_PdhCollectQueryDataWithTime();
996 test_PdhGetFormattedCounterValue();
997 test_PdhGetRawCounterValue();
998 test_PdhSetCounterScaleFactor();
999 test_PdhGetCounterTimeBase();
1001 test_PdhGetCounterInfoA();
1002 test_PdhGetCounterInfoW();
1004 test_PdhLookupPerfIndexByNameA();
1005 test_PdhLookupPerfIndexByNameW();
1007 test_PdhLookupPerfNameByIndexA();
1008 test_PdhLookupPerfNameByIndexW();
1010 test_PdhValidatePathA();
1011 test_PdhValidatePathW();
1013 if (pPdhValidatePathExA) test_PdhValidatePathExA();
1014 if (pPdhValidatePathExW) test_PdhValidatePathExW();
1016 test_PdhCollectQueryDataEx();
1017 test_PdhMakeCounterPathA();
1018 test_PdhGetDllVersion();