makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / pdh / tests / pdh.c
blob0a17906afbd131ffe1bffb653bd04264c6f8666e
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[] =
75 {'%',' ','P','r','o','c','e','s','s','o','r',' ','T','i','m','e',0};
76 static const WCHAR uptime[] =
77 {'S','y','s','t','e','m',' ','U','p',' ','T','i','m','e',0};
79 static const WCHAR system_uptime[] =
80 {'\\','S','y','s','t','e','m','\\','S','y','s','t','e','m',' ','U','p',' ','T','i','m','e',0};
81 static const WCHAR nonexistent_counter[] =
82 {'\\','S','y','s','t','e','m','\\','S','y','s','t','e','m',' ','D','o','w','n',' ','T','i','m','e',0};
83 static const WCHAR percentage_processor_time[] =
84 {'\\','P','r','o','c','e','s','s','o','r','(','_','T','o','t','a','l',')',
85 '\\','%',' ','P','r','o','c','e','s','s','o','r',' ','T','i','m','e',0};
87 static void test_PdhOpenQueryA( void )
89 PDH_STATUS ret;
90 PDH_HQUERY query;
92 ret = PdhOpenQueryA( NULL, 0, NULL );
93 ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryA failed 0x%08x\n", ret);
95 ret = PdhOpenQueryA( NULL, 0, &query );
96 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA 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_PdhOpenQueryW( void )
113 PDH_STATUS ret;
114 PDH_HQUERY query;
116 ret = PdhOpenQueryW( NULL, 0, NULL );
117 ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryW failed 0x%08x\n", ret);
119 ret = PdhOpenQueryW( NULL, 0, &query );
120 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
122 ret = PdhCloseQuery( NULL );
123 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
125 ret = PdhCloseQuery( &query );
126 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
128 ret = PdhCloseQuery( query );
129 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
131 ret = PdhCloseQuery( query );
132 ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
135 static void test_PdhAddCounterA( void )
137 PDH_STATUS ret;
138 PDH_HQUERY query;
139 PDH_HCOUNTER counter;
141 ret = PdhOpenQueryA( NULL, 0, &query );
142 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
144 ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, NULL );
145 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
147 ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, &counter );
148 ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterA failed 0x%08x\n", ret);
150 ret = PdhAddCounterA( query, NULL, 0, &counter );
151 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
153 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, NULL );
154 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
156 ret = PdhAddCounterA( query, "\\System\\Nonexistent Counter", 0, &counter );
157 ok(ret == PDH_CSTATUS_NO_COUNTER ||
158 broken(ret == PDH_INVALID_PATH), /* Win2K */
159 "PdhAddCounterA failed 0x%08x\n", ret);
160 ok(!counter, "PdhAddCounterA failed %p\n", counter);
162 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
163 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
165 ret = PdhCollectQueryData( NULL );
166 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
168 ret = PdhCollectQueryData( counter );
169 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
171 ret = PdhCollectQueryData( query );
172 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
174 ret = PdhRemoveCounter( NULL );
175 ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08x\n", ret);
177 ret = PdhRemoveCounter( counter );
178 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
180 ret = PdhCloseQuery( query );
181 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
184 static void test_PdhAddCounterW( void )
186 PDH_STATUS ret;
187 PDH_HQUERY query;
188 PDH_HCOUNTER counter;
190 ret = PdhOpenQueryW( NULL, 0, &query );
191 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
193 ret = PdhAddCounterW( NULL, percentage_processor_time, 0, NULL );
194 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
196 ret = PdhAddCounterW( NULL, percentage_processor_time, 0, &counter );
197 ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterW failed 0x%08x\n", ret);
199 ret = PdhAddCounterW( query, NULL, 0, &counter );
200 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
202 ret = PdhAddCounterW( query, percentage_processor_time, 0, NULL );
203 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
205 ret = PdhAddCounterW( query, nonexistent_counter, 0, &counter );
206 ok(ret == PDH_CSTATUS_NO_COUNTER ||
207 broken(ret == PDH_INVALID_PATH), /* Win2K */
208 "PdhAddCounterW failed 0x%08x\n", ret);
209 ok(!counter, "PdhAddCounterW failed %p\n", counter);
211 ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
212 ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08x\n", ret);
214 ret = PdhCollectQueryData( NULL );
215 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
217 ret = PdhCollectQueryData( counter );
218 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
220 ret = PdhCollectQueryData( query );
221 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
223 ret = PdhRemoveCounter( NULL );
224 ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08x\n", ret);
226 ret = PdhRemoveCounter( counter );
227 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
229 ret = PdhCloseQuery( query );
230 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
233 static void test_PdhAddEnglishCounterA( void )
235 PDH_STATUS ret;
236 PDH_HQUERY query;
237 PDH_HCOUNTER counter;
239 ret = PdhOpenQueryA( NULL, 0, &query );
240 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
242 ret = PdhCollectQueryData( query );
243 ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
245 ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, NULL );
246 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
248 ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, &counter );
249 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
251 ret = pPdhAddEnglishCounterA( query, NULL, 0, &counter );
252 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
254 ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, NULL );
255 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
257 ret = pPdhAddEnglishCounterA( query, "\\System\\System Down Time", 0, &counter );
258 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
259 ok(!counter, "PdhAddEnglishCounterA failed %p\n", counter);
261 ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, &counter );
262 ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
264 ret = PdhCollectQueryData( query );
265 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
267 ret = PdhRemoveCounter( counter );
268 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
270 ret = PdhCloseQuery( query );
271 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
274 static void test_PdhAddEnglishCounterW( void )
276 PDH_STATUS ret;
277 PDH_HQUERY query;
278 PDH_HCOUNTER counter;
280 ret = PdhOpenQueryW( NULL, 0, &query );
281 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
283 ret = PdhCollectQueryData( query );
284 ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
286 ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, NULL );
287 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
289 ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, &counter );
290 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
292 ret = pPdhAddEnglishCounterW( query, NULL, 0, &counter );
293 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
295 ret = pPdhAddEnglishCounterW( query, system_uptime, 0, NULL );
296 ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
298 ret = pPdhAddEnglishCounterW( query, nonexistent_counter, 0, &counter );
299 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
300 ok(!counter, "PdhAddEnglishCounterA failed %p\n", counter);
302 ret = pPdhAddEnglishCounterW( query, system_uptime, 0, &counter );
303 ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
305 ret = PdhCollectQueryData( query );
306 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
308 ret = PdhRemoveCounter( counter );
309 ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
311 ret = PdhCloseQuery( query );
312 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
315 static void test_PdhCollectQueryDataWithTime( void )
317 PDH_STATUS ret;
318 PDH_HQUERY query;
319 PDH_HCOUNTER counter;
320 LONGLONG time;
322 ret = PdhOpenQueryA( NULL, 0, &query );
323 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
325 ret = PdhCollectQueryData( query );
326 ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
328 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
329 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
331 ret = pPdhCollectQueryDataWithTime( NULL, NULL );
332 ok(ret == PDH_INVALID_ARGUMENT, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
334 ret = pPdhCollectQueryDataWithTime( query, NULL );
335 ok(ret == PDH_INVALID_ARGUMENT, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
337 ret = pPdhCollectQueryDataWithTime( NULL, &time );
338 ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
340 ret = pPdhCollectQueryDataWithTime( query, &time );
341 ok(ret == ERROR_SUCCESS, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
343 ret = PdhCloseQuery( query );
344 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
347 static void test_PdhGetFormattedCounterValue( void )
349 PDH_STATUS ret;
350 PDH_HQUERY query;
351 PDH_HCOUNTER counter;
352 PDH_FMT_COUNTERVALUE value;
354 ret = PdhOpenQueryA( NULL, 0, &query );
355 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
357 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
358 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
360 ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, NULL );
361 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
363 ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, &value );
364 ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
366 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, NULL );
367 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
369 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
370 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
372 ret = PdhCollectQueryData( query );
373 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
375 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
376 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
378 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOSCALE, NULL, &value );
379 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
381 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOCAP100, NULL, &value );
382 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
384 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_1000, NULL, &value );
385 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
387 ret = PdhSetCounterScaleFactor( counter, 2 );
388 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
390 ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
391 ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
393 ret = PdhCloseQuery( query );
394 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
397 static void test_PdhGetRawCounterValue( void )
399 PDH_STATUS ret;
400 PDH_HQUERY query;
401 PDH_HCOUNTER counter;
402 PDH_RAW_COUNTER value;
404 ret = PdhOpenQueryA( NULL, 0, &query );
405 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
407 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
408 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
410 ret = PdhGetRawCounterValue( NULL, NULL, &value );
411 ok(ret == PDH_INVALID_HANDLE, "PdhGetRawCounterValue failed 0x%08x\n", ret);
413 ret = PdhGetRawCounterValue( counter, NULL, NULL );
414 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetRawCounterValue failed 0x%08x\n", ret);
416 ret = PdhGetRawCounterValue( counter, NULL, &value );
417 ok(ret == ERROR_SUCCESS, "PdhGetRawCounterValue failed 0x%08x\n", ret);
418 ok(value.CStatus == ERROR_SUCCESS, "expected ERROR_SUCCESS got %x\n", value.CStatus);
420 ret = PdhCollectQueryData( query );
421 ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
423 ret = PdhGetRawCounterValue( counter, NULL, &value );
424 ok(ret == ERROR_SUCCESS, "PdhGetRawCounterValue failed 0x%08x\n", ret);
425 ok(value.CStatus == ERROR_SUCCESS, "expected ERROR_SUCCESS got %x\n", value.CStatus);
427 ret = PdhCloseQuery( query );
428 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
431 static void test_PdhSetCounterScaleFactor( void )
433 PDH_STATUS ret;
434 PDH_HQUERY query;
435 PDH_HCOUNTER counter;
437 ret = PdhOpenQueryA( NULL, 0, &query );
438 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
440 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
441 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
443 ret = PdhSetCounterScaleFactor( NULL, 8 );
444 ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
446 ret = PdhSetCounterScaleFactor( NULL, 1 );
447 ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
449 ret = PdhSetCounterScaleFactor( counter, 8 );
450 ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
452 ret = PdhSetCounterScaleFactor( counter, -8 );
453 ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
455 ret = PdhSetCounterScaleFactor( counter, 7 );
456 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
458 ret = PdhSetCounterScaleFactor( counter, 0 );
459 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
461 ret = PdhCloseQuery( query );
462 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
465 static void test_PdhGetCounterTimeBase( void )
467 PDH_STATUS ret;
468 PDH_HQUERY query;
469 PDH_HCOUNTER counter;
470 LONGLONG base;
472 ret = PdhOpenQueryA( NULL, 0, &query );
473 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
475 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
476 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
478 ret = PdhGetCounterTimeBase( NULL, NULL );
479 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
481 ret = PdhGetCounterTimeBase( NULL, &base );
482 ok(ret == PDH_INVALID_HANDLE, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
484 ret = PdhGetCounterTimeBase( counter, NULL );
485 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
487 ret = PdhGetCounterTimeBase( counter, &base );
488 ok(ret == ERROR_SUCCESS, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
490 ret = PdhCloseQuery( query );
491 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
494 static void test_PdhGetCounterInfoA( void )
496 PDH_STATUS ret;
497 PDH_HQUERY query;
498 PDH_HCOUNTER counter;
499 PDH_COUNTER_INFO_A info;
500 DWORD size;
502 ret = PdhOpenQueryA( NULL, 0, &query );
503 ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
505 ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
506 ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
508 ret = PdhGetCounterInfoA( NULL, 0, NULL, NULL );
509 ok(ret == PDH_INVALID_HANDLE || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
511 ret = PdhGetCounterInfoA( counter, 0, NULL, NULL );
512 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
514 ret = PdhGetCounterInfoA( counter, 0, NULL, &info );
515 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
517 size = sizeof(info) - 1;
518 ret = PdhGetCounterInfoA( counter, 0, &size, NULL );
519 ok(ret == PDH_MORE_DATA || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
521 size = sizeof(info);
522 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
523 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
524 ok(size == sizeof(info), "PdhGetCounterInfoA failed %d\n", size);
526 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
527 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
528 ok(info.lScale == 0, "lScale %d\n", info.lScale);
530 ret = PdhSetCounterScaleFactor( counter, 0 );
531 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
533 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
534 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
535 ok(info.lScale == 0, "lScale %d\n", info.lScale);
537 ret = PdhSetCounterScaleFactor( counter, -5 );
538 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
540 ret = PdhGetCounterInfoA( counter, 0, &size, &info );
541 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
542 ok(info.lScale == -5, "lScale %d\n", info.lScale);
544 ret = PdhCloseQuery( query );
545 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
548 static void test_PdhGetCounterInfoW( void )
550 PDH_STATUS ret;
551 PDH_HQUERY query;
552 PDH_HCOUNTER counter;
553 PDH_COUNTER_INFO_W info;
554 DWORD size;
556 ret = PdhOpenQueryW( NULL, 0, &query );
557 ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
559 ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
560 ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08x\n", ret);
562 ret = PdhGetCounterInfoW( NULL, 0, NULL, NULL );
563 ok(ret == PDH_INVALID_HANDLE || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
565 ret = PdhGetCounterInfoW( counter, 0, NULL, NULL );
566 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
568 ret = PdhGetCounterInfoW( counter, 0, NULL, &info );
569 ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
571 size = sizeof(info) - 1;
572 ret = PdhGetCounterInfoW( counter, 0, &size, NULL );
573 ok(ret == PDH_MORE_DATA || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
575 size = sizeof(info);
576 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
577 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
578 ok(size == sizeof(info), "PdhGetCounterInfoW failed %d\n", size);
580 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
581 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
582 ok(info.lScale == 0, "lScale %d\n", info.lScale);
584 ret = PdhSetCounterScaleFactor( counter, 0 );
585 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
587 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
588 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
589 ok(info.lScale == 0, "lScale %d\n", info.lScale);
591 ret = PdhSetCounterScaleFactor( counter, -5 );
592 ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
594 ret = PdhGetCounterInfoW( counter, 0, &size, &info );
595 ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
596 ok(info.lScale == -5, "lScale %d\n", info.lScale);
598 ret = PdhCloseQuery( query );
599 ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
602 static void test_PdhLookupPerfIndexByNameA( void )
604 PDH_STATUS ret;
605 DWORD index;
607 ret = PdhLookupPerfIndexByNameA( NULL, NULL, NULL );
608 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
610 ret = PdhLookupPerfIndexByNameA( NULL, NULL, &index );
611 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
613 ret = PdhLookupPerfIndexByNameA( NULL, "No Counter", &index );
614 ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
616 ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", NULL );
617 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
619 ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", &index );
620 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
621 ok(index == 6, "PdhLookupPerfIndexByNameA failed %d\n", index);
623 ret = PdhLookupPerfIndexByNameA( NULL, "System Up Time", &index );
624 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
625 ok(index == 674, "PdhLookupPerfIndexByNameA failed %d\n", index);
628 static void test_PdhLookupPerfIndexByNameW( void )
630 PDH_STATUS ret;
631 DWORD index;
633 static const WCHAR no_counter[] = {'N','o',' ','C','o','u','n','t','e','r',0};
635 ret = PdhLookupPerfIndexByNameW( NULL, NULL, NULL );
636 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
638 ret = PdhLookupPerfIndexByNameW( NULL, NULL, &index );
639 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
641 ret = PdhLookupPerfIndexByNameW( NULL, no_counter, &index );
642 ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
644 ret = PdhLookupPerfIndexByNameW( NULL, processor_time, NULL );
645 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
647 ret = PdhLookupPerfIndexByNameW( NULL, processor_time, &index );
648 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
649 ok(index == 6, "PdhLookupPerfIndexByNameW failed %d\n", index);
651 ret = PdhLookupPerfIndexByNameW( NULL, uptime, &index );
652 ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
653 ok(index == 674, "PdhLookupPerfIndexByNameW failed %d\n", index);
656 static void test_PdhLookupPerfNameByIndexA( void )
658 PDH_STATUS ret;
659 char buffer[PDH_MAX_COUNTER_NAME] = "!!";
660 DWORD size;
662 ret = PdhLookupPerfNameByIndexA( NULL, 0, NULL, NULL );
663 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
665 size = 0;
666 ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
667 ok(ret == PDH_MORE_DATA || ret == PDH_INSUFFICIENT_BUFFER, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
669 size = sizeof(buffer);
670 ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
671 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
672 ok(!lstrcmpA( buffer, "% Processor Time" ),
673 "PdhLookupPerfNameByIndexA failed, got %s expected \'%% Processor Time\'\n", buffer);
674 ok(size == sizeof("% Processor Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
676 size = sizeof(buffer);
677 ret = PdhLookupPerfNameByIndexA( NULL, 674, NULL, &size );
678 ok(ret == PDH_INVALID_ARGUMENT ||
679 ret == PDH_MORE_DATA, /* win2k3 */
680 "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
682 size = sizeof(buffer);
683 ret = PdhLookupPerfNameByIndexA( NULL, 674, buffer, &size );
684 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
685 ok(!lstrcmpA( buffer, "System Up Time" ),
686 "PdhLookupPerfNameByIndexA failed, got %s expected \'System Up Time\'\n", buffer);
687 ok(size == sizeof("System Up Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
690 static void test_PdhLookupPerfNameByIndexW( void )
692 PDH_STATUS ret;
693 WCHAR buffer[PDH_MAX_COUNTER_NAME];
694 DWORD size;
696 ret = PdhLookupPerfNameByIndexW( NULL, 0, NULL, NULL );
697 ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
699 size = 0;
700 ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
701 ok(ret == PDH_MORE_DATA || ret == PDH_INSUFFICIENT_BUFFER, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
703 size = ARRAY_SIZE(buffer);
704 ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
705 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
706 ok(size == ARRAY_SIZE(processor_time), "PdhLookupPerfNameByIndexW failed %d\n", size);
708 size = ARRAY_SIZE(buffer);
709 ret = PdhLookupPerfNameByIndexW( NULL, 674, NULL, &size );
710 ok(ret == PDH_INVALID_ARGUMENT ||
711 ret == PDH_MORE_DATA, /* win2k3 */
712 "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
714 size = ARRAY_SIZE(buffer);
715 ret = PdhLookupPerfNameByIndexW( NULL, 674, buffer, &size );
716 ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
717 ok(size == ARRAY_SIZE(uptime), "PdhLookupPerfNameByIndexW failed %d\n", size);
720 static void test_PdhValidatePathA( void )
722 PDH_STATUS ret;
724 ret = PdhValidatePathA( NULL );
725 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathA failed 0x%08x\n", ret);
727 ret = PdhValidatePathA( "" );
728 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathA failed 0x%08x\n", ret);
730 ret = PdhValidatePathA( "\\System" );
731 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathA failed 0x%08x\n", ret);
733 ret = PdhValidatePathA( "System Up Time" );
734 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathA failed 0x%08x\n", ret);
736 ret = PdhValidatePathA( "\\System\\Nonexistent Counter" );
737 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathA failed 0x%08x\n", ret);
739 ret = PdhValidatePathA( "\\System\\System Up Time" );
740 ok(ret == ERROR_SUCCESS, "PdhValidatePathA failed 0x%08x\n", ret);
743 static void test_PdhValidatePathW( void )
745 PDH_STATUS ret;
747 static const WCHAR empty[] = {0};
748 static const WCHAR system[] = {'\\','S','y','s','t','e','m',0};
750 ret = PdhValidatePathW( NULL );
751 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathW failed 0x%08x\n", ret);
753 ret = PdhValidatePathW( empty );
754 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathW failed 0x%08x\n", ret);
756 ret = PdhValidatePathW( system );
757 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathW failed 0x%08x\n", ret);
759 ret = PdhValidatePathW( uptime );
760 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathW failed 0x%08x\n", ret);
762 ret = PdhValidatePathW( nonexistent_counter );
763 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathW failed 0x%08x\n", ret);
765 ret = PdhValidatePathW( system_uptime );
766 ok(ret == ERROR_SUCCESS, "PdhValidatePathW failed 0x%08x\n", ret);
769 static void test_PdhValidatePathExA( void )
771 PDH_STATUS ret;
773 ret = pPdhValidatePathExA( NULL, NULL );
774 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExA failed 0x%08x\n", ret);
776 ret = pPdhValidatePathExA( NULL, "" );
777 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExA failed 0x%08x\n", ret);
779 ret = pPdhValidatePathExA( NULL, "\\System" );
780 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExA failed 0x%08x\n", ret);
782 ret = pPdhValidatePathExA( NULL, "System Up Time" );
783 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExA failed 0x%08x\n", ret);
785 ret = pPdhValidatePathExA( NULL, "\\System\\System Down Time" );
786 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathExA failed 0x%08x\n", ret);
788 ret = pPdhValidatePathExA( NULL, "\\System\\System Up Time" );
789 ok(ret == ERROR_SUCCESS, "PdhValidatePathExA failed 0x%08x\n", ret);
792 static void test_PdhValidatePathExW( void )
794 PDH_STATUS ret;
796 static const WCHAR empty[] = {0};
797 static const WCHAR system[] = {'\\','S','y','s','t','e','m',0};
799 ret = pPdhValidatePathExW( NULL, NULL );
800 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExW failed 0x%08x\n", ret);
802 ret = pPdhValidatePathExW( NULL, empty );
803 ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExW failed 0x%08x\n", ret);
805 ret = pPdhValidatePathExW( NULL, system );
806 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExW failed 0x%08x\n", ret);
808 ret = pPdhValidatePathExW( NULL, uptime );
809 ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExW failed 0x%08x\n", ret);
811 ret = pPdhValidatePathExW( NULL, nonexistent_counter );
812 ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathExW failed 0x%08x\n", ret);
814 ret = pPdhValidatePathExW( NULL, system_uptime );
815 ok(ret == ERROR_SUCCESS, "PdhValidatePathExW failed 0x%08x\n", ret);
818 static void test_PdhCollectQueryDataEx(void)
820 PDH_STATUS status;
821 PDH_HQUERY query;
822 PDH_HCOUNTER counter;
823 HANDLE event;
824 BOOL ret;
825 UINT i;
827 status = PdhOpenQueryA( NULL, 0, &query );
828 ok(status == ERROR_SUCCESS, "PdhOpenQuery failed 0x%08x\n", status);
830 event = CreateEventA( NULL, FALSE, FALSE, "winetest" );
831 ok(event != NULL, "CreateEvent failed\n");
833 status = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
834 ok(status == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", status);
836 status = PdhCollectQueryDataEx( NULL, 1, event );
837 ok(status == PDH_INVALID_HANDLE, "PdhCollectQueryDataEx failed 0x%08x\n", status);
839 status = PdhCollectQueryDataEx( query, 1, NULL );
840 ok(status == ERROR_SUCCESS, "PdhCollectQueryDataEx failed 0x%08x\n", status);
842 status = PdhCollectQueryDataEx( query, 1, event );
843 ok(status == ERROR_SUCCESS, "PdhCollectQueryDataEx failed 0x%08x\n", status);
845 status = PdhCollectQueryData( query );
846 ok(status == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", status);
848 for (i = 0; i < 3; i++)
850 if (WaitForSingleObject( event, INFINITE ) == WAIT_OBJECT_0)
852 PDH_FMT_COUNTERVALUE value;
854 status = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
855 ok(status == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", status);
857 trace( "uptime %s\n", wine_dbgstr_longlong(U(value).largeValue) );
861 ret = CloseHandle( event );
862 ok(ret, "CloseHandle failed\n");
864 status = PdhCloseQuery( query );
865 ok(status == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", status);
868 static void test_PdhMakeCounterPathA(void)
870 PDH_STATUS ret;
871 PDH_COUNTER_PATH_ELEMENTS_A e;
872 char buffer[1024];
873 DWORD buflen;
875 ret = PdhMakeCounterPathA(NULL, NULL, NULL, 0);
876 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
878 buflen = 0;
879 ret = PdhMakeCounterPathA(NULL, NULL, &buflen, 0);
880 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
882 buflen = 0;
883 ret = PdhMakeCounterPathA(NULL, buffer, &buflen, 0);
884 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
886 buflen = sizeof(buffer);
887 memset(&e, 0, sizeof(e));
888 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
889 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
891 buffer[0] = 0;
892 buflen = sizeof(buffer);
893 e.szMachineName = (char *)"machine";
894 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
895 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
896 ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
898 buffer[0] = 0;
899 buflen = sizeof(buffer);
900 e.szObjectName = (char *)"object";
901 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
902 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
903 ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
905 buffer[0] = 0;
906 buflen = sizeof(buffer);
907 e.szInstanceName = (char *)"instance";
908 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
909 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
910 ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
912 buffer[0] = 0;
913 buflen = sizeof(buffer);
914 e.szParentInstance = (char *)"parent";
915 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
916 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
917 ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
919 buffer[0] = 0;
920 buflen = sizeof(buffer);
921 e.dwInstanceIndex = 1;
922 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
923 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
924 ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
926 buffer[0] = 0;
927 buflen = sizeof(buffer);
928 e.szCounterName = (char *)"counter";
929 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
930 ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
931 ok(!strcmp(buffer, "\\\\machine\\object(parent/instance#1)\\counter"),
932 "expected \"\\\\machine\\object(parent/instance#1)\\counter\" got %s\n", buffer);
934 buffer[0] = 0;
935 buflen = sizeof(buffer);
936 e.szParentInstance = NULL;
937 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
938 ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
939 ok(!strcmp(buffer, "\\\\machine\\object(instance#1)\\counter"),
940 "expected \"\\\\machine\\object(instance#1)\\counter\" got %s\n", buffer);
942 buffer[0] = 0;
943 buflen = sizeof(buffer);
944 e.szInstanceName = NULL;
945 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
946 ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
947 ok(!strcmp(buffer, "\\\\machine\\object\\counter"),
948 "expected \"\\\\machine\\object\\counter\" got %s\n", buffer);
950 buffer[0] = 0;
951 buflen = sizeof(buffer);
952 e.szMachineName = NULL;
953 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
954 ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
955 ok(!strcmp(buffer, "\\object\\counter"),
956 "expected \"\\object\\counter\" got %s\n", buffer);
958 buffer[0] = 0;
959 buflen = sizeof(buffer);
960 e.szObjectName = NULL;
961 ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
962 ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
965 static void test_PdhGetDllVersion(void)
967 PDH_STATUS ret;
968 DWORD version;
970 ret = PdhGetDllVersion(NULL);
971 ok(ret == PDH_INVALID_ARGUMENT ||
972 broken(ret == ERROR_SUCCESS), /* Vista+ */
973 "Expected PdhGetDllVersion to return PDH_INVALID_ARGUMENT, got %d\n", ret);
975 ret = PdhGetDllVersion(&version);
976 ok(ret == ERROR_SUCCESS,
977 "Expected PdhGetDllVersion to return ERROR_SUCCESS, got %d\n", ret);
979 if (ret == ERROR_SUCCESS)
981 ok(version == PDH_CVERSION_WIN50 ||
982 version == PDH_VERSION,
983 "Expected version number to be PDH_CVERSION_WIN50 or PDH_VERSION, got %u\n", version);
987 START_TEST(pdh)
989 if (!is_lang_english())
991 skip("An English UI is needed for the pdh tests\n");
992 return;
994 init_function_ptrs();
996 test_PdhOpenQueryA();
997 test_PdhOpenQueryW();
999 test_PdhAddCounterA();
1000 test_PdhAddCounterW();
1002 if (pPdhAddEnglishCounterA) test_PdhAddEnglishCounterA();
1003 if (pPdhAddEnglishCounterW) test_PdhAddEnglishCounterW();
1004 if (pPdhCollectQueryDataWithTime) test_PdhCollectQueryDataWithTime();
1006 test_PdhGetFormattedCounterValue();
1007 test_PdhGetRawCounterValue();
1008 test_PdhSetCounterScaleFactor();
1009 test_PdhGetCounterTimeBase();
1011 test_PdhGetCounterInfoA();
1012 test_PdhGetCounterInfoW();
1014 test_PdhLookupPerfIndexByNameA();
1015 test_PdhLookupPerfIndexByNameW();
1017 test_PdhLookupPerfNameByIndexA();
1018 test_PdhLookupPerfNameByIndexW();
1020 test_PdhValidatePathA();
1021 test_PdhValidatePathW();
1023 if (pPdhValidatePathExA) test_PdhValidatePathExA();
1024 if (pPdhValidatePathExW) test_PdhValidatePathExW();
1026 test_PdhCollectQueryDataEx();
1027 test_PdhMakeCounterPathA();
1028 test_PdhGetDllVersion();