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
28 #include "wine/test.h"
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 );
40 static void init_function_ptrs( void )
42 pdh = GetModuleHandle( "pdh" );
43 GETFUNCPTR( PdhAddEnglishCounterA )
44 GETFUNCPTR( PdhAddEnglishCounterW )
45 GETFUNCPTR( PdhCollectQueryDataWithTime )
46 GETFUNCPTR( PdhValidatePathExA )
47 GETFUNCPTR( PdhValidatePathExW )
50 static const WCHAR processor_time[] =
51 {'%',' ','P','r','o','c','e','s','s','o','r',' ','T','i','m','e',0};
52 static const WCHAR uptime[] =
53 {'S','y','s','t','e','m',' ','U','p',' ','T','i','m','e',0};
55 static const WCHAR system_uptime[] =
56 {'\\','S','y','s','t','e','m','\\','S','y','s','t','e','m',' ','U','p',' ','T','i','m','e',0};
57 static const WCHAR system_downtime[] = /* does not exist */
58 {'\\','S','y','s','t','e','m','\\','S','y','s','t','e','m',' ','D','o','w','n',' ','T','i','m','e',0};
59 static const WCHAR percentage_processor_time[] =
60 {'\\','P','r','o','c','e','s','s','o','r','(','_','T','o','t','a','l',')',
61 '\\','%',' ','P','r','o','c','e','s','s','o','r',' ','T','i','m','e',0};
63 static void test_PdhOpenQueryA( void )
68 ret = PdhOpenQueryA( NULL, 0, NULL );
69 ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryA failed 0x%08x\n", ret);
71 ret = PdhOpenQueryA( NULL, 0, &query );
72 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
74 ret = PdhCloseQuery( NULL );
75 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
77 ret = PdhCloseQuery( &query );
78 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
80 ret = PdhCloseQuery( query );
81 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
83 ret = PdhCloseQuery( query );
84 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
87 static void test_PdhOpenQueryW( void )
92 ret = PdhOpenQueryW( NULL, 0, NULL );
93 ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryW failed 0x%08x\n", ret);
95 ret = PdhOpenQueryW( NULL, 0, &query );
96 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
98 ret = PdhCloseQuery( NULL );
99 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
101 ret = PdhCloseQuery( &query );
102 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
104 ret = PdhCloseQuery( query );
105 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
107 ret = PdhCloseQuery( query );
108 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
111 static void test_PdhAddCounterA( void )
115 PDH_HCOUNTER counter;
117 ret = PdhOpenQueryA( NULL, 0, &query );
118 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
120 ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, NULL );
121 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
123 ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, &counter );
124 ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterA failed 0x%08x\n", ret);
126 ret = PdhAddCounterA( query, NULL, 0, &counter );
127 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
129 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, NULL );
130 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
132 ret = PdhAddCounterA( query, "\\System\\System Down Time", 0, &counter );
133 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddCounterA failed 0x%08x\n", ret);
134 ok(!counter, "PdhAddCounterA failed %p\n", counter);
136 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
137 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
139 ret = PdhCollectQueryData( NULL );
140 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
142 ret = PdhCollectQueryData( counter );
143 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
145 ret = PdhCollectQueryData( query );
146 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
148 ret = PdhRemoveCounter( NULL );
149 ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08x\n", ret);
151 ret = PdhRemoveCounter( counter );
152 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
154 ret = PdhCloseQuery( query );
155 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
158 static void test_PdhAddCounterW( void )
162 PDH_HCOUNTER counter;
164 ret = PdhOpenQueryW( NULL, 0, &query );
165 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
167 ret = PdhAddCounterW( NULL, percentage_processor_time, 0, NULL );
168 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
170 ret = PdhAddCounterW( NULL, percentage_processor_time, 0, &counter );
171 ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterW failed 0x%08x\n", ret);
173 ret = PdhAddCounterW( query, NULL, 0, &counter );
174 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
176 ret = PdhAddCounterW( query, percentage_processor_time, 0, NULL );
177 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
179 ret = PdhAddCounterW( query, system_downtime, 0, &counter );
180 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddCounterW failed 0x%08x\n", ret);
181 ok(!counter, "PdhAddCounterW failed %p\n", counter);
183 ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
184 ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08x\n", ret);
186 ret = PdhCollectQueryData( NULL );
187 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
189 ret = PdhCollectQueryData( counter );
190 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
192 ret = PdhCollectQueryData( query );
193 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
195 ret = PdhRemoveCounter( NULL );
196 ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08x\n", ret);
198 ret = PdhRemoveCounter( counter );
199 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
201 ret = PdhCloseQuery( query );
202 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
205 static void test_PdhAddEnglishCounterA( void )
209 PDH_HCOUNTER counter;
211 ret = PdhOpenQueryA( NULL, 0, &query );
212 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
214 ret = PdhCollectQueryData( query );
215 ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
217 ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, NULL );
218 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
220 ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, &counter );
221 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
223 ret = pPdhAddEnglishCounterA( query, NULL, 0, &counter );
224 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
226 ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, NULL );
227 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
229 ret = pPdhAddEnglishCounterA( query, "\\System\\System Down Time", 0, &counter );
230 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
231 ok(!counter, "PdhAddEnglishCounterA failed %p\n", counter);
233 ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, &counter );
234 ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
236 ret = PdhCollectQueryData( query );
237 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
239 ret = PdhRemoveCounter( counter );
240 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
242 ret = PdhCloseQuery( query );
243 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
246 static void test_PdhAddEnglishCounterW( void )
250 PDH_HCOUNTER counter;
252 ret = PdhOpenQueryW( NULL, 0, &query );
253 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
255 ret = PdhCollectQueryData( query );
256 ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
258 ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, NULL );
259 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
261 ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, &counter );
262 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
264 ret = pPdhAddEnglishCounterW( query, NULL, 0, &counter );
265 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
267 ret = pPdhAddEnglishCounterW( query, system_uptime, 0, NULL );
268 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
270 ret = pPdhAddEnglishCounterW( query, system_downtime, 0, &counter );
271 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
272 ok(!counter, "PdhAddEnglishCounterA failed %p\n", counter);
274 ret = pPdhAddEnglishCounterW( query, system_uptime, 0, &counter );
275 ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
277 ret = PdhCollectQueryData( query );
278 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
280 ret = PdhRemoveCounter( counter );
281 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
283 ret = PdhCloseQuery( query );
284 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
287 static void test_PdhCollectQueryDataWithTime( void )
291 PDH_HCOUNTER counter;
294 ret = PdhOpenQueryA( NULL, 0, &query );
295 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
297 ret = PdhCollectQueryData( query );
298 ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
300 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
301 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
303 ret = pPdhCollectQueryDataWithTime( NULL, NULL );
304 ok(ret == PDH_INVALID_ARGUMENT, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
306 ret = pPdhCollectQueryDataWithTime( query, NULL );
307 ok(ret == PDH_INVALID_ARGUMENT, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
309 ret = pPdhCollectQueryDataWithTime( NULL, &time );
310 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
312 ret = pPdhCollectQueryDataWithTime( query, &time );
313 ok(ret == ERROR_SUCCESS, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
315 ret = PdhCloseQuery( query );
316 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
319 static void test_PdhGetFormattedCounterValue( void )
323 PDH_HCOUNTER counter;
324 PDH_FMT_COUNTERVALUE value;
326 ret = PdhOpenQueryA( NULL, 0, &query );
327 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
329 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
330 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
332 ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, NULL );
333 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
335 ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, &value );
336 ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
338 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, NULL );
339 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
341 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
342 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
344 ret = PdhCollectQueryData( query );
345 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
347 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
348 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
350 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOSCALE, NULL, &value );
351 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
353 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOCAP100, NULL, &value );
354 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
356 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_1000, NULL, &value );
357 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
359 ret = PdhSetCounterScaleFactor( counter, 2 );
360 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
362 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
363 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
365 ret = PdhCloseQuery( query );
366 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
369 static void test_PdhGetRawCounterValue( void )
373 PDH_HCOUNTER counter;
374 PDH_RAW_COUNTER value;
376 ret = PdhOpenQueryA( NULL, 0, &query );
377 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
379 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
380 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
382 ret = PdhGetRawCounterValue( NULL, NULL, &value );
383 ok(ret == PDH_INVALID_HANDLE, "PdhGetRawCounterValue failed 0x%08x\n", ret);
385 ret = PdhGetRawCounterValue( counter, NULL, NULL );
386 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetRawCounterValue failed 0x%08x\n", ret);
388 ret = PdhGetRawCounterValue( counter, NULL, &value );
389 ok(ret == ERROR_SUCCESS, "PdhGetRawCounterValue failed 0x%08x\n", ret);
390 ok(value.CStatus == ERROR_SUCCESS, "expected ERROR_SUCCESS got %x\n", value.CStatus);
392 ret = PdhCollectQueryData( query );
393 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
395 ret = PdhGetRawCounterValue( counter, NULL, &value );
396 ok(ret == ERROR_SUCCESS, "PdhGetRawCounterValue failed 0x%08x\n", ret);
397 ok(value.CStatus == ERROR_SUCCESS, "expected ERROR_SUCCESS got %x\n", value.CStatus);
399 ret = PdhCloseQuery( query );
400 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
403 static void test_PdhSetCounterScaleFactor( void )
407 PDH_HCOUNTER counter;
409 ret = PdhOpenQueryA( NULL, 0, &query );
410 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
412 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
413 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
415 ret = PdhSetCounterScaleFactor( NULL, 8 );
416 ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
418 ret = PdhSetCounterScaleFactor( NULL, 1 );
419 ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
421 ret = PdhSetCounterScaleFactor( counter, 8 );
422 ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
424 ret = PdhSetCounterScaleFactor( counter, -8 );
425 ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
427 ret = PdhSetCounterScaleFactor( counter, 7 );
428 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
430 ret = PdhSetCounterScaleFactor( counter, 0 );
431 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
433 ret = PdhCloseQuery( query );
434 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
437 static void test_PdhGetCounterTimeBase( void )
441 PDH_HCOUNTER counter;
444 ret = PdhOpenQueryA( NULL, 0, &query );
445 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
447 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
448 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
450 ret = PdhGetCounterTimeBase( NULL, NULL );
451 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
453 ret = PdhGetCounterTimeBase( NULL, &base );
454 ok(ret == PDH_INVALID_HANDLE, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
456 ret = PdhGetCounterTimeBase( counter, NULL );
457 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
459 ret = PdhGetCounterTimeBase( counter, &base );
460 ok(ret == ERROR_SUCCESS, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
462 ret = PdhCloseQuery( query );
463 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
466 static void test_PdhGetCounterInfoA( void )
470 PDH_HCOUNTER counter;
471 PDH_COUNTER_INFO_A info;
474 ret = PdhOpenQueryA( NULL, 0, &query );
475 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
477 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
478 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
480 ret = PdhGetCounterInfoA( NULL, 0, NULL, NULL );
481 ok(ret == PDH_INVALID_HANDLE || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
483 ret = PdhGetCounterInfoA( counter, 0, NULL, NULL );
484 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
486 ret = PdhGetCounterInfoA( counter, 0, NULL, &info );
487 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
489 size = sizeof(info) - 1;
490 ret = PdhGetCounterInfoA( counter, 0, &size, NULL );
491 ok(ret == PDH_MORE_DATA, "PdhGetCounterInfoA failed 0x%08x\n", ret);
494 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
495 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
496 ok(size == sizeof(info), "PdhGetCounterInfoA failed %d\n", size);
498 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
499 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
500 ok(info.lScale == 0, "lScale %d\n", info.lScale);
502 ret = PdhSetCounterScaleFactor( counter, 0 );
503 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
505 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
506 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
507 ok(info.lScale == 0, "lScale %d\n", info.lScale);
509 ret = PdhSetCounterScaleFactor( counter, -5 );
510 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
512 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
513 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
514 ok(info.lScale == -5, "lScale %d\n", info.lScale);
516 ret = PdhCloseQuery( query );
517 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
520 static void test_PdhGetCounterInfoW( void )
524 PDH_HCOUNTER counter;
525 PDH_COUNTER_INFO_W info;
528 ret = PdhOpenQueryW( NULL, 0, &query );
529 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
531 ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
532 ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08x\n", ret);
534 ret = PdhGetCounterInfoW( NULL, 0, NULL, NULL );
535 ok(ret == PDH_INVALID_HANDLE || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
537 ret = PdhGetCounterInfoW( counter, 0, NULL, NULL );
538 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
540 ret = PdhGetCounterInfoW( counter, 0, NULL, &info );
541 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
543 size = sizeof(info) - 1;
544 ret = PdhGetCounterInfoW( counter, 0, &size, NULL );
545 ok(ret == PDH_MORE_DATA, "PdhGetCounterInfoW failed 0x%08x\n", ret);
548 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
549 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
550 ok(size == sizeof(info), "PdhGetCounterInfoW failed %d\n", size);
552 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
553 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
554 ok(info.lScale == 0, "lScale %d\n", info.lScale);
556 ret = PdhSetCounterScaleFactor( counter, 0 );
557 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
559 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
560 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
561 ok(info.lScale == 0, "lScale %d\n", info.lScale);
563 ret = PdhSetCounterScaleFactor( counter, -5 );
564 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
566 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
567 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
568 ok(info.lScale == -5, "lScale %d\n", info.lScale);
570 ret = PdhCloseQuery( query );
571 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
574 static void test_PdhLookupPerfIndexByNameA( void )
579 ret = PdhLookupPerfIndexByNameA( NULL, NULL, NULL );
580 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
582 ret = PdhLookupPerfIndexByNameA( NULL, NULL, &index );
583 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
585 ret = PdhLookupPerfIndexByNameA( NULL, "No Counter", &index );
586 ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
588 ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", NULL );
589 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
591 ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", &index );
592 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
593 ok(index == 6, "PdhLookupPerfIndexByNameA failed %d\n", index);
595 ret = PdhLookupPerfIndexByNameA( NULL, "System Up Time", &index );
596 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
597 ok(index == 674, "PdhLookupPerfIndexByNameA failed %d\n", index);
600 static void test_PdhLookupPerfIndexByNameW( void )
605 static const WCHAR no_counter[] = {'N','o',' ','C','o','u','n','t','e','r',0};
607 ret = PdhLookupPerfIndexByNameW( NULL, NULL, NULL );
608 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
610 ret = PdhLookupPerfIndexByNameW( NULL, NULL, &index );
611 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
613 ret = PdhLookupPerfIndexByNameW( NULL, no_counter, &index );
614 ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
616 ret = PdhLookupPerfIndexByNameW( NULL, processor_time, NULL );
617 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
619 ret = PdhLookupPerfIndexByNameW( NULL, processor_time, &index );
620 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
621 ok(index == 6, "PdhLookupPerfIndexByNameW failed %d\n", index);
623 ret = PdhLookupPerfIndexByNameW( NULL, uptime, &index );
624 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
625 ok(index == 674, "PdhLookupPerfIndexByNameW failed %d\n", index);
628 static void test_PdhLookupPerfNameByIndexA( void )
631 char buffer[PDH_MAX_COUNTER_NAME] = "!!";
634 ret = PdhLookupPerfNameByIndexA( NULL, 0, NULL, NULL );
635 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
638 ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
639 ok(ret == PDH_MORE_DATA || ret == PDH_INSUFFICIENT_BUFFER, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
641 size = sizeof(buffer);
642 ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
643 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
644 ok(!lstrcmpA( buffer, "% Processor Time" ),
645 "PdhLookupPerfNameByIndexA failed, got %s expected \'%% Processor Time\'\n", buffer);
646 ok(size == sizeof("% Processor Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
648 size = sizeof(buffer);
649 ret = PdhLookupPerfNameByIndexA( NULL, 674, buffer, &size );
650 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
651 ok(!lstrcmpA( buffer, "System Up Time" ),
652 "PdhLookupPerfNameByIndexA failed, got %s expected \'System Up Time\'\n", buffer);
653 ok(size == sizeof("System Up Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
656 static void test_PdhLookupPerfNameByIndexW( void )
659 WCHAR buffer[PDH_MAX_COUNTER_NAME];
662 ret = PdhLookupPerfNameByIndexW( NULL, 0, NULL, NULL );
663 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
666 ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
667 ok(ret == PDH_MORE_DATA || ret == PDH_INSUFFICIENT_BUFFER, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
669 size = sizeof(buffer) / sizeof(WCHAR);
670 ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
671 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
672 ok(size == sizeof(processor_time) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
674 size = sizeof(buffer) / sizeof(WCHAR);
675 ret = PdhLookupPerfNameByIndexW( NULL, 674, buffer, &size );
676 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
677 ok(size == sizeof(uptime) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
680 static void test_PdhValidatePathA( void )
684 ret = PdhValidatePathA( NULL );
685 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathA failed 0x%08x\n", ret);
687 ret = PdhValidatePathA( "" );
688 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathA failed 0x%08x\n", ret);
690 ret = PdhValidatePathA( "\\System" );
691 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathA failed 0x%08x\n", ret);
693 ret = PdhValidatePathA( "System Up Time" );
694 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathA failed 0x%08x\n", ret);
696 ret = PdhValidatePathA( "\\System\\System Down Time" );
697 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathA failed 0x%08x\n", ret);
699 ret = PdhValidatePathA( "\\System\\System Up Time" );
700 ok(ret == ERROR_SUCCESS, "PdhValidatePathA failed 0x%08x\n", ret);
703 static void test_PdhValidatePathW( void )
707 static const WCHAR empty[] = {0};
708 static const WCHAR system[] = {'\\','S','y','s','t','e','m',0};
710 ret = PdhValidatePathW( NULL );
711 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathW failed 0x%08x\n", ret);
713 ret = PdhValidatePathW( empty );
714 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathW failed 0x%08x\n", ret);
716 ret = PdhValidatePathW( system );
717 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathW failed 0x%08x\n", ret);
719 ret = PdhValidatePathW( uptime );
720 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathW failed 0x%08x\n", ret);
722 ret = PdhValidatePathW( system_downtime );
723 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathW failed 0x%08x\n", ret);
725 ret = PdhValidatePathW( system_uptime );
726 ok(ret == ERROR_SUCCESS, "PdhValidatePathW failed 0x%08x\n", ret);
729 static void test_PdhValidatePathExA( void )
733 ret = pPdhValidatePathExA( NULL, NULL );
734 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExA failed 0x%08x\n", ret);
736 ret = pPdhValidatePathExA( NULL, "" );
737 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExA failed 0x%08x\n", ret);
739 ret = pPdhValidatePathExA( NULL, "\\System" );
740 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExA failed 0x%08x\n", ret);
742 ret = pPdhValidatePathExA( NULL, "System Up Time" );
743 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExA failed 0x%08x\n", ret);
745 ret = pPdhValidatePathExA( NULL, "\\System\\System Down Time" );
746 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathExA failed 0x%08x\n", ret);
748 ret = pPdhValidatePathExA( NULL, "\\System\\System Up Time" );
749 ok(ret == ERROR_SUCCESS, "PdhValidatePathExA failed 0x%08x\n", ret);
752 static void test_PdhValidatePathExW( void )
756 static const WCHAR empty[] = {0};
757 static const WCHAR system[] = {'\\','S','y','s','t','e','m',0};
759 ret = pPdhValidatePathExW( NULL, NULL );
760 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExW failed 0x%08x\n", ret);
762 ret = pPdhValidatePathExW( NULL, empty );
763 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExW failed 0x%08x\n", ret);
765 ret = pPdhValidatePathExW( NULL, system );
766 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExW failed 0x%08x\n", ret);
768 ret = pPdhValidatePathExW( NULL, uptime );
769 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExW failed 0x%08x\n", ret);
771 ret = pPdhValidatePathExW( NULL, system_downtime );
772 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathExW failed 0x%08x\n", ret);
774 ret = pPdhValidatePathExW( NULL, system_uptime );
775 ok(ret == ERROR_SUCCESS, "PdhValidatePathExW failed 0x%08x\n", ret);
778 static void test_PdhCollectQueryDataEx(void)
782 PDH_HCOUNTER counter;
787 status = PdhOpenQueryA( NULL, 0, &query );
788 ok(status == ERROR_SUCCESS, "PdhOpenQuery failed 0x%08x\n", status);
790 event = CreateEventA( NULL, FALSE, FALSE, "winetest" );
791 ok(event != NULL, "CreateEvent failed\n");
793 status = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
794 ok(status == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", status);
796 status = PdhCollectQueryDataEx( NULL, 1, event );
797 ok(status == PDH_INVALID_HANDLE, "PdhCollectQueryDataEx failed 0x%08x\n", status);
799 status = PdhCollectQueryDataEx( query, 1, NULL );
800 ok(status == ERROR_SUCCESS, "PdhCollectQueryDataEx failed 0x%08x\n", status);
802 status = PdhCollectQueryDataEx( query, 1, event );
803 ok(status == ERROR_SUCCESS, "PdhCollectQueryDataEx failed 0x%08x\n", status);
805 status = PdhCollectQueryData( query );
806 ok(status == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", status);
808 for (i = 0; i < 3; i++)
810 if (WaitForSingleObject( event, INFINITE ) == WAIT_OBJECT_0)
812 PDH_FMT_COUNTERVALUE value;
814 status = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
815 ok(status == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", status);
817 trace( "uptime %x%08x\n", (DWORD)(U(value).largeValue >> 32), (DWORD)U(value).largeValue );
821 ret = CloseHandle( event );
822 ok(ret, "CloseHandle failed\n");
824 status = PdhCloseQuery( query );
825 ok(status == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", status);
830 if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH)
832 skip("non-english locale\n");
835 init_function_ptrs();
837 test_PdhOpenQueryA();
838 test_PdhOpenQueryW();
840 test_PdhAddCounterA();
841 test_PdhAddCounterW();
843 if (pPdhAddEnglishCounterA) test_PdhAddEnglishCounterA();
844 if (pPdhAddEnglishCounterW) test_PdhAddEnglishCounterW();
845 if (pPdhCollectQueryDataWithTime) test_PdhCollectQueryDataWithTime();
847 test_PdhGetFormattedCounterValue();
848 test_PdhGetRawCounterValue();
849 test_PdhSetCounterScaleFactor();
850 test_PdhGetCounterTimeBase();
852 test_PdhGetCounterInfoA();
853 test_PdhGetCounterInfoW();
855 test_PdhLookupPerfIndexByNameA();
856 test_PdhLookupPerfIndexByNameW();
858 test_PdhLookupPerfNameByIndexA();
859 test_PdhLookupPerfNameByIndexW();
861 test_PdhValidatePathA();
862 test_PdhValidatePathW();
864 if (pPdhValidatePathExA) test_PdhValidatePathExA();
865 if (pPdhValidatePathExW) test_PdhValidatePathExW();
867 test_PdhCollectQueryDataEx();