xref: /reactos/modules/rostests/winetests/pdh/pdh.c (revision 943bcb0f)
1 /*
2  * Tests for pdh.dll (Performance Data Helper)
3  *
4  * Copyright 2007 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include <stdio.h>
22 
23 #include "windows.h"
24 
25 #include "pdh.h"
26 #include "pdhmsg.h"
27 
28 #include "wine/test.h"
29 
30 static HMODULE pdh;
31 
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);
37 
38 #define GETFUNCPTR(func) p##func = (void *)GetProcAddress( pdh, #func );
39 
40 
41 /* Returns true if the user interface is in English. Note that this does not
42  * presume of the formatting of dates, numbers, etc.
43  */
is_lang_english(void)44 static BOOL is_lang_english(void)
45 {
46     static HMODULE hkernel32 = NULL;
47     static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
48     static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
49 
50     if (!hkernel32)
51     {
52         hkernel32 = GetModuleHandleA("kernel32.dll");
53         pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
54         pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
55     }
56     if (pGetThreadUILanguage)
57         return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
58     if (pGetUserDefaultUILanguage)
59         return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
60 
61     return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
62 }
63 
init_function_ptrs(void)64 static void init_function_ptrs( void )
65 {
66     pdh = GetModuleHandleA( "pdh" );
67     GETFUNCPTR( PdhAddEnglishCounterA )
68     GETFUNCPTR( PdhAddEnglishCounterW )
69     GETFUNCPTR( PdhCollectQueryDataWithTime )
70     GETFUNCPTR( PdhValidatePathExA )
71     GETFUNCPTR( PdhValidatePathExW )
72 }
73 
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};
78 
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};
86 
test_PdhOpenQueryA(void)87 static void test_PdhOpenQueryA( void )
88 {
89     PDH_STATUS ret;
90     PDH_HQUERY query;
91 
92     ret = PdhOpenQueryA( NULL, 0, NULL );
93     ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryA failed 0x%08x\n", ret);
94 
95     ret = PdhOpenQueryA( NULL, 0, &query );
96     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
97 
98     ret = PdhCloseQuery( NULL );
99     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
100 
101     ret = PdhCloseQuery( &query );
102     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
103 
104     ret = PdhCloseQuery( query );
105     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
106 
107     ret = PdhCloseQuery( query );
108     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
109 }
110 
test_PdhOpenQueryW(void)111 static void test_PdhOpenQueryW( void )
112 {
113     PDH_STATUS ret;
114     PDH_HQUERY query;
115 
116     ret = PdhOpenQueryW( NULL, 0, NULL );
117     ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryW failed 0x%08x\n", ret);
118 
119     ret = PdhOpenQueryW( NULL, 0, &query );
120     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
121 
122     ret = PdhCloseQuery( NULL );
123     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
124 
125     ret = PdhCloseQuery( &query );
126     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
127 
128     ret = PdhCloseQuery( query );
129     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
130 
131     ret = PdhCloseQuery( query );
132     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
133 }
134 
test_PdhAddCounterA(void)135 static void test_PdhAddCounterA( void )
136 {
137     PDH_STATUS ret;
138     PDH_HQUERY query;
139     PDH_HCOUNTER counter;
140 
141     ret = PdhOpenQueryA( NULL, 0, &query );
142     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
143 
144     ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, NULL );
145     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
146 
147     ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, &counter );
148     ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterA failed 0x%08x\n", ret);
149 
150     ret = PdhAddCounterA( query, NULL, 0, &counter );
151     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
152 
153     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, NULL );
154     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
155 
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);
161 
162     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
163     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
164 
165     ret = PdhCollectQueryData( NULL );
166     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
167 
168     ret = PdhCollectQueryData( counter );
169     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
170 
171     ret = PdhCollectQueryData( query );
172     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
173 
174     ret = PdhRemoveCounter( NULL );
175     ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08x\n", ret);
176 
177     ret = PdhRemoveCounter( counter );
178     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
179 
180     ret = PdhCloseQuery( query );
181     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
182 }
183 
test_PdhAddCounterW(void)184 static void test_PdhAddCounterW( void )
185 {
186     PDH_STATUS ret;
187     PDH_HQUERY query;
188     PDH_HCOUNTER counter;
189 
190     ret = PdhOpenQueryW( NULL, 0, &query );
191     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
192 
193     ret = PdhAddCounterW( NULL, percentage_processor_time, 0, NULL );
194     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
195 
196     ret = PdhAddCounterW( NULL, percentage_processor_time, 0, &counter );
197     ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterW failed 0x%08x\n", ret);
198 
199     ret = PdhAddCounterW( query, NULL, 0, &counter );
200     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
201 
202     ret = PdhAddCounterW( query, percentage_processor_time, 0, NULL );
203     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
204 
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);
210 
211     ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
212     ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08x\n", ret);
213 
214     ret = PdhCollectQueryData( NULL );
215     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
216 
217     ret = PdhCollectQueryData( counter );
218     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
219 
220     ret = PdhCollectQueryData( query );
221     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
222 
223     ret = PdhRemoveCounter( NULL );
224     ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08x\n", ret);
225 
226     ret = PdhRemoveCounter( counter );
227     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
228 
229     ret = PdhCloseQuery( query );
230     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
231 }
232 
test_PdhAddEnglishCounterA(void)233 static void test_PdhAddEnglishCounterA( void )
234 {
235     PDH_STATUS ret;
236     PDH_HQUERY query;
237     PDH_HCOUNTER counter;
238 
239     ret = PdhOpenQueryA( NULL, 0, &query );
240     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
241 
242     ret = PdhCollectQueryData( query );
243     ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
244 
245     ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, NULL );
246     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
247 
248     ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, &counter );
249     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
250 
251     ret = pPdhAddEnglishCounterA( query, NULL, 0, &counter );
252     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
253 
254     ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, NULL );
255     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
256 
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);
260 
261     ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, &counter );
262     ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
263 
264     ret = PdhCollectQueryData( query );
265     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
266 
267     ret = PdhRemoveCounter( counter );
268     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
269 
270     ret = PdhCloseQuery( query );
271     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
272 }
273 
test_PdhAddEnglishCounterW(void)274 static void test_PdhAddEnglishCounterW( void )
275 {
276     PDH_STATUS ret;
277     PDH_HQUERY query;
278     PDH_HCOUNTER counter;
279 
280     ret = PdhOpenQueryW( NULL, 0, &query );
281     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
282 
283     ret = PdhCollectQueryData( query );
284     ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
285 
286     ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, NULL );
287     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
288 
289     ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, &counter );
290     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
291 
292     ret = pPdhAddEnglishCounterW( query, NULL, 0, &counter );
293     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
294 
295     ret = pPdhAddEnglishCounterW( query, system_uptime, 0, NULL );
296     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
297 
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);
301 
302     ret = pPdhAddEnglishCounterW( query, system_uptime, 0, &counter );
303     ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
304 
305     ret = PdhCollectQueryData( query );
306     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
307 
308     ret = PdhRemoveCounter( counter );
309     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
310 
311     ret = PdhCloseQuery( query );
312     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
313 }
314 
test_PdhCollectQueryDataWithTime(void)315 static void test_PdhCollectQueryDataWithTime( void )
316 {
317     PDH_STATUS ret;
318     PDH_HQUERY query;
319     PDH_HCOUNTER counter;
320     LONGLONG time;
321 
322     ret = PdhOpenQueryA( NULL, 0, &query );
323     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
324 
325     ret = PdhCollectQueryData( query );
326     ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
327 
328     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
329     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
330 
331     ret = pPdhCollectQueryDataWithTime( NULL, NULL );
332     ok(ret == PDH_INVALID_ARGUMENT, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
333 
334     ret = pPdhCollectQueryDataWithTime( query, NULL );
335     ok(ret == PDH_INVALID_ARGUMENT, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
336 
337     ret = pPdhCollectQueryDataWithTime( NULL, &time );
338     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
339 
340     ret = pPdhCollectQueryDataWithTime( query, &time );
341     ok(ret == ERROR_SUCCESS, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
342 
343     ret = PdhCloseQuery( query );
344     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
345 }
346 
test_PdhGetFormattedCounterValue(void)347 static void test_PdhGetFormattedCounterValue( void )
348 {
349     PDH_STATUS ret;
350     PDH_HQUERY query;
351     PDH_HCOUNTER counter;
352     PDH_FMT_COUNTERVALUE value;
353 
354     ret = PdhOpenQueryA( NULL, 0, &query );
355     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
356 
357     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
358     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
359 
360     ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, NULL );
361     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
362 
363     ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, &value );
364     ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
365 
366     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, NULL );
367     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
368 
369     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
370     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
371 
372     ret = PdhCollectQueryData( query );
373     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
374 
375     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
376     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
377 
378     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOSCALE, NULL, &value );
379     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
380 
381     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOCAP100, NULL, &value );
382     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
383 
384     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_1000, NULL, &value );
385     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
386 
387     ret = PdhSetCounterScaleFactor( counter, 2 );
388     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
389 
390     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
391     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
392 
393     ret = PdhCloseQuery( query );
394     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
395 }
396 
test_PdhGetRawCounterValue(void)397 static void test_PdhGetRawCounterValue( void )
398 {
399     PDH_STATUS ret;
400     PDH_HQUERY query;
401     PDH_HCOUNTER counter;
402     PDH_RAW_COUNTER value;
403 
404     ret = PdhOpenQueryA( NULL, 0, &query );
405     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
406 
407     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
408     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
409 
410     ret = PdhGetRawCounterValue( NULL, NULL, &value );
411     ok(ret == PDH_INVALID_HANDLE, "PdhGetRawCounterValue failed 0x%08x\n", ret);
412 
413     ret = PdhGetRawCounterValue( counter, NULL, NULL );
414     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetRawCounterValue failed 0x%08x\n", ret);
415 
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);
419 
420     ret = PdhCollectQueryData( query );
421     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
422 
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);
426 
427     ret = PdhCloseQuery( query );
428     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
429 }
430 
test_PdhSetCounterScaleFactor(void)431 static void test_PdhSetCounterScaleFactor( void )
432 {
433     PDH_STATUS ret;
434     PDH_HQUERY query;
435     PDH_HCOUNTER counter;
436 
437     ret = PdhOpenQueryA( NULL, 0, &query );
438     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
439 
440     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
441     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
442 
443     ret = PdhSetCounterScaleFactor( NULL, 8 );
444     ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
445 
446     ret = PdhSetCounterScaleFactor( NULL, 1 );
447     ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
448 
449     ret = PdhSetCounterScaleFactor( counter, 8 );
450     ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
451 
452     ret = PdhSetCounterScaleFactor( counter, -8 );
453     ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
454 
455     ret = PdhSetCounterScaleFactor( counter, 7 );
456     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
457 
458     ret = PdhSetCounterScaleFactor( counter, 0 );
459     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
460 
461     ret = PdhCloseQuery( query );
462     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
463 }
464 
test_PdhGetCounterTimeBase(void)465 static void test_PdhGetCounterTimeBase( void )
466 {
467     PDH_STATUS ret;
468     PDH_HQUERY query;
469     PDH_HCOUNTER counter;
470     LONGLONG base;
471 
472     ret = PdhOpenQueryA( NULL, 0, &query );
473     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
474 
475     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
476     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
477 
478     ret = PdhGetCounterTimeBase( NULL, NULL );
479     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
480 
481     ret = PdhGetCounterTimeBase( NULL, &base );
482     ok(ret == PDH_INVALID_HANDLE, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
483 
484     ret = PdhGetCounterTimeBase( counter, NULL );
485     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
486 
487     ret = PdhGetCounterTimeBase( counter, &base );
488     ok(ret == ERROR_SUCCESS, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
489 
490     ret = PdhCloseQuery( query );
491     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
492 }
493 
test_PdhGetCounterInfoA(void)494 static void test_PdhGetCounterInfoA( void )
495 {
496     PDH_STATUS ret;
497     PDH_HQUERY query;
498     PDH_HCOUNTER counter;
499     PDH_COUNTER_INFO_A info;
500     DWORD size;
501 
502     ret = PdhOpenQueryA( NULL, 0, &query );
503     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
504 
505     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
506     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
507 
508     ret = PdhGetCounterInfoA( NULL, 0, NULL, NULL );
509     ok(ret == PDH_INVALID_HANDLE || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
510 
511     ret = PdhGetCounterInfoA( counter, 0, NULL, NULL );
512     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
513 
514     ret = PdhGetCounterInfoA( counter, 0, NULL, &info );
515     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
516 
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);
520 
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);
525 
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);
529 
530     ret = PdhSetCounterScaleFactor( counter, 0 );
531     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
532 
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);
536 
537     ret = PdhSetCounterScaleFactor( counter, -5 );
538     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
539 
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);
543 
544     ret = PdhCloseQuery( query );
545     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
546 }
547 
test_PdhGetCounterInfoW(void)548 static void test_PdhGetCounterInfoW( void )
549 {
550     PDH_STATUS ret;
551     PDH_HQUERY query;
552     PDH_HCOUNTER counter;
553     PDH_COUNTER_INFO_W info;
554     DWORD size;
555 
556     ret = PdhOpenQueryW( NULL, 0, &query );
557     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
558 
559     ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
560     ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08x\n", ret);
561 
562     ret = PdhGetCounterInfoW( NULL, 0, NULL, NULL );
563     ok(ret == PDH_INVALID_HANDLE || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
564 
565     ret = PdhGetCounterInfoW( counter, 0, NULL, NULL );
566     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
567 
568     ret = PdhGetCounterInfoW( counter, 0, NULL, &info );
569     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
570 
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);
574 
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);
579 
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);
583 
584     ret = PdhSetCounterScaleFactor( counter, 0 );
585     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
586 
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);
590 
591     ret = PdhSetCounterScaleFactor( counter, -5 );
592     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
593 
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);
597 
598     ret = PdhCloseQuery( query );
599     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
600 }
601 
test_PdhLookupPerfIndexByNameA(void)602 static void test_PdhLookupPerfIndexByNameA( void )
603 {
604     PDH_STATUS ret;
605     DWORD index;
606 
607     ret = PdhLookupPerfIndexByNameA( NULL, NULL, NULL );
608     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
609 
610     ret = PdhLookupPerfIndexByNameA( NULL, NULL, &index );
611     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
612 
613     ret = PdhLookupPerfIndexByNameA( NULL, "No Counter", &index );
614     ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
615 
616     ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", NULL );
617     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
618 
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);
622 
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);
626 }
627 
test_PdhLookupPerfIndexByNameW(void)628 static void test_PdhLookupPerfIndexByNameW( void )
629 {
630     PDH_STATUS ret;
631     DWORD index;
632 
633     static const WCHAR no_counter[] = {'N','o',' ','C','o','u','n','t','e','r',0};
634 
635     ret = PdhLookupPerfIndexByNameW( NULL, NULL, NULL );
636     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
637 
638     ret = PdhLookupPerfIndexByNameW( NULL, NULL, &index );
639     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
640 
641     ret = PdhLookupPerfIndexByNameW( NULL, no_counter, &index );
642     ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
643 
644     ret = PdhLookupPerfIndexByNameW( NULL, processor_time, NULL );
645     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
646 
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);
650 
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);
654 }
655 
test_PdhLookupPerfNameByIndexA(void)656 static void test_PdhLookupPerfNameByIndexA( void )
657 {
658     PDH_STATUS ret;
659     char buffer[PDH_MAX_COUNTER_NAME] = "!!";
660     DWORD size;
661 
662     ret = PdhLookupPerfNameByIndexA( NULL, 0, NULL, NULL );
663     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
664 
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);
668 
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);
675 
676     size = sizeof(buffer);
677     ret = PdhLookupPerfNameByIndexA( NULL, 238, buffer, &size );
678     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
679     ok(!lstrcmpA( buffer, "Processor" ),
680        "PdhLookupPerfNameByIndexA failed, got %s expected \'Processor\'\n", buffer);
681     ok(size == sizeof("Processor"), "PdhLookupPerfNameByIndexA failed %d\n", size);
682 
683     size = sizeof(buffer);
684     ret = PdhLookupPerfNameByIndexA( NULL, 674, NULL, &size );
685     ok(ret == PDH_INVALID_ARGUMENT ||
686        ret == PDH_MORE_DATA, /* win2k3 */
687        "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
688 
689     size = sizeof(buffer);
690     ret = PdhLookupPerfNameByIndexA( NULL, 674, buffer, &size );
691     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
692     ok(!lstrcmpA( buffer, "System Up Time" ),
693        "PdhLookupPerfNameByIndexA failed, got %s expected \'System Up Time\'\n", buffer);
694     ok(size == sizeof("System Up Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
695 }
696 
test_PdhLookupPerfNameByIndexW(void)697 static void test_PdhLookupPerfNameByIndexW( void )
698 {
699     PDH_STATUS ret;
700     WCHAR buffer[PDH_MAX_COUNTER_NAME];
701     DWORD size;
702 
703     ret = PdhLookupPerfNameByIndexW( NULL, 0, NULL, NULL );
704     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
705 
706     size = 0;
707     ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
708     ok(ret == PDH_MORE_DATA || ret == PDH_INSUFFICIENT_BUFFER, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
709 
710     size = ARRAY_SIZE(buffer);
711     ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
712     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
713     ok(size == ARRAY_SIZE(processor_time), "PdhLookupPerfNameByIndexW failed %d\n", size);
714 
715     size = ARRAY_SIZE(buffer);
716     ret = PdhLookupPerfNameByIndexW( NULL, 674, NULL, &size );
717     ok(ret == PDH_INVALID_ARGUMENT ||
718        ret == PDH_MORE_DATA, /* win2k3 */
719        "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
720 
721     size = ARRAY_SIZE(buffer);
722     ret = PdhLookupPerfNameByIndexW( NULL, 674, buffer, &size );
723     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
724     ok(size == ARRAY_SIZE(uptime), "PdhLookupPerfNameByIndexW failed %d\n", size);
725 }
726 
test_PdhValidatePathA(void)727 static void test_PdhValidatePathA( void )
728 {
729     PDH_STATUS ret;
730 
731     ret = PdhValidatePathA( NULL );
732     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathA failed 0x%08x\n", ret);
733 
734     ret = PdhValidatePathA( "" );
735     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathA failed 0x%08x\n", ret);
736 
737     ret = PdhValidatePathA( "\\System" );
738     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathA failed 0x%08x\n", ret);
739 
740     ret = PdhValidatePathA( "System Up Time" );
741     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathA failed 0x%08x\n", ret);
742 
743     ret = PdhValidatePathA( "\\System\\Nonexistent Counter" );
744     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathA failed 0x%08x\n", ret);
745 
746     ret = PdhValidatePathA( "\\System\\System Up Time" );
747     ok(ret == ERROR_SUCCESS, "PdhValidatePathA failed 0x%08x\n", ret);
748 }
749 
test_PdhValidatePathW(void)750 static void test_PdhValidatePathW( void )
751 {
752     PDH_STATUS ret;
753 
754     static const WCHAR empty[] = {0};
755     static const WCHAR system[] = {'\\','S','y','s','t','e','m',0};
756 
757     ret = PdhValidatePathW( NULL );
758     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathW failed 0x%08x\n", ret);
759 
760     ret = PdhValidatePathW( empty );
761     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathW failed 0x%08x\n", ret);
762 
763     ret = PdhValidatePathW( system );
764     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathW failed 0x%08x\n", ret);
765 
766     ret = PdhValidatePathW( uptime );
767     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathW failed 0x%08x\n", ret);
768 
769     ret = PdhValidatePathW( nonexistent_counter );
770     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathW failed 0x%08x\n", ret);
771 
772     ret = PdhValidatePathW( system_uptime );
773     ok(ret == ERROR_SUCCESS, "PdhValidatePathW failed 0x%08x\n", ret);
774 }
775 
test_PdhValidatePathExA(void)776 static void test_PdhValidatePathExA( void )
777 {
778     PDH_STATUS ret;
779 
780     ret = pPdhValidatePathExA( NULL, NULL );
781     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExA failed 0x%08x\n", ret);
782 
783     ret = pPdhValidatePathExA( NULL, "" );
784     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExA failed 0x%08x\n", ret);
785 
786     ret = pPdhValidatePathExA( NULL, "\\System" );
787     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExA failed 0x%08x\n", ret);
788 
789     ret = pPdhValidatePathExA( NULL, "System Up Time" );
790     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExA failed 0x%08x\n", ret);
791 
792     ret = pPdhValidatePathExA( NULL, "\\System\\System Down Time" );
793     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathExA failed 0x%08x\n", ret);
794 
795     ret = pPdhValidatePathExA( NULL, "\\System\\System Up Time" );
796     ok(ret == ERROR_SUCCESS, "PdhValidatePathExA failed 0x%08x\n", ret);
797 }
798 
test_PdhValidatePathExW(void)799 static void test_PdhValidatePathExW( void )
800 {
801     PDH_STATUS ret;
802 
803     static const WCHAR empty[] = {0};
804     static const WCHAR system[] = {'\\','S','y','s','t','e','m',0};
805 
806     ret = pPdhValidatePathExW( NULL, NULL );
807     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExW failed 0x%08x\n", ret);
808 
809     ret = pPdhValidatePathExW( NULL, empty );
810     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExW failed 0x%08x\n", ret);
811 
812     ret = pPdhValidatePathExW( NULL, system );
813     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExW failed 0x%08x\n", ret);
814 
815     ret = pPdhValidatePathExW( NULL, uptime );
816     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExW failed 0x%08x\n", ret);
817 
818     ret = pPdhValidatePathExW( NULL, nonexistent_counter );
819     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathExW failed 0x%08x\n", ret);
820 
821     ret = pPdhValidatePathExW( NULL, system_uptime );
822     ok(ret == ERROR_SUCCESS, "PdhValidatePathExW failed 0x%08x\n", ret);
823 }
824 
test_PdhCollectQueryDataEx(void)825 static void test_PdhCollectQueryDataEx(void)
826 {
827     PDH_STATUS status;
828     PDH_HQUERY query;
829     PDH_HCOUNTER counter;
830     HANDLE event;
831     BOOL ret;
832     UINT i;
833 
834     status = PdhOpenQueryA( NULL, 0, &query );
835     ok(status == ERROR_SUCCESS, "PdhOpenQuery failed 0x%08x\n", status);
836 
837     event = CreateEventA( NULL, FALSE, FALSE, "winetest" );
838     ok(event != NULL, "CreateEvent failed\n");
839 
840     status = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
841     ok(status == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", status);
842 
843     status = PdhCollectQueryDataEx( NULL, 1, event );
844     ok(status == PDH_INVALID_HANDLE, "PdhCollectQueryDataEx failed 0x%08x\n", status);
845 
846     status = PdhCollectQueryDataEx( query, 1, NULL );
847     ok(status == ERROR_SUCCESS, "PdhCollectQueryDataEx failed 0x%08x\n", status);
848 
849     status = PdhCollectQueryDataEx( query, 1, event );
850     ok(status == ERROR_SUCCESS, "PdhCollectQueryDataEx failed 0x%08x\n", status);
851 
852     status = PdhCollectQueryData( query );
853     ok(status == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", status);
854 
855     for (i = 0; i < 3; i++)
856     {
857         if (WaitForSingleObject( event, INFINITE ) == WAIT_OBJECT_0)
858         {
859             PDH_FMT_COUNTERVALUE value;
860 
861             status = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
862             ok(status == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", status);
863 
864             trace( "uptime %s\n", wine_dbgstr_longlong(U(value).largeValue) );
865         }
866     }
867 
868     ret = CloseHandle( event );
869     ok(ret, "CloseHandle failed\n");
870 
871     status = PdhCloseQuery( query );
872     ok(status == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", status);
873 }
874 
test_PdhMakeCounterPathA(void)875 static void test_PdhMakeCounterPathA(void)
876 {
877     PDH_STATUS ret;
878     PDH_COUNTER_PATH_ELEMENTS_A e;
879     char buffer[1024];
880     DWORD buflen;
881 
882     ret = PdhMakeCounterPathA(NULL, NULL, NULL, 0);
883     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
884 
885     buflen = 0;
886     ret = PdhMakeCounterPathA(NULL, NULL, &buflen, 0);
887     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
888 
889     buflen = 0;
890     ret = PdhMakeCounterPathA(NULL, buffer, &buflen, 0);
891     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
892 
893     buflen = sizeof(buffer);
894     memset(&e, 0, sizeof(e));
895     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
896     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
897 
898     buffer[0] = 0;
899     buflen = sizeof(buffer);
900     e.szMachineName = (char *)"machine";
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);
904 
905     buffer[0] = 0;
906     buflen = sizeof(buffer);
907     e.szObjectName = (char *)"object";
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);
911 
912     buffer[0] = 0;
913     buflen = sizeof(buffer);
914     e.szInstanceName = (char *)"instance";
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);
918 
919     buffer[0] = 0;
920     buflen = sizeof(buffer);
921     e.szParentInstance = (char *)"parent";
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);
925 
926     buffer[0] = 0;
927     buflen = sizeof(buffer);
928     e.dwInstanceIndex = 1;
929     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
930     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
931     ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
932 
933     buffer[0] = 0;
934     buflen = sizeof(buffer);
935     e.szCounterName = (char *)"counter";
936     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
937     ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
938     ok(!strcmp(buffer, "\\\\machine\\object(parent/instance#1)\\counter"),
939        "expected \"\\\\machine\\object(parent/instance#1)\\counter\" got %s\n", buffer);
940 
941     buffer[0] = 0;
942     buflen = sizeof(buffer);
943     e.szParentInstance = NULL;
944     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
945     ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
946     ok(!strcmp(buffer, "\\\\machine\\object(instance#1)\\counter"),
947        "expected \"\\\\machine\\object(instance#1)\\counter\" got %s\n", buffer);
948 
949     buffer[0] = 0;
950     buflen = sizeof(buffer);
951     e.szInstanceName = NULL;
952     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
953     ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
954     ok(!strcmp(buffer, "\\\\machine\\object\\counter"),
955        "expected \"\\\\machine\\object\\counter\" got %s\n", buffer);
956 
957     buffer[0] = 0;
958     buflen = sizeof(buffer);
959     e.szMachineName = NULL;
960     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
961     ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
962     ok(!strcmp(buffer, "\\object\\counter"),
963        "expected \"\\object\\counter\" got %s\n", buffer);
964 
965     buffer[0] = 0;
966     buflen = sizeof(buffer);
967     e.szObjectName = NULL;
968     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
969     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
970 }
971 
test_PdhGetDllVersion(void)972 static void test_PdhGetDllVersion(void)
973 {
974     PDH_STATUS ret;
975     DWORD version;
976 
977     ret = PdhGetDllVersion(NULL);
978     ok(ret == PDH_INVALID_ARGUMENT ||
979        broken(ret == ERROR_SUCCESS), /* Vista+ */
980        "Expected PdhGetDllVersion to return PDH_INVALID_ARGUMENT, got %d\n", ret);
981 
982     ret = PdhGetDllVersion(&version);
983     ok(ret == ERROR_SUCCESS,
984        "Expected PdhGetDllVersion to return ERROR_SUCCESS, got %d\n", ret);
985 
986     if (ret == ERROR_SUCCESS)
987     {
988         ok(version == PDH_CVERSION_WIN50 ||
989            version == PDH_VERSION,
990            "Expected version number to be PDH_CVERSION_WIN50 or PDH_VERSION, got %u\n", version);
991     }
992 }
993 
START_TEST(pdh)994 START_TEST(pdh)
995 {
996     if (!is_lang_english())
997     {
998         skip("An English UI is needed for the pdh tests\n");
999         return;
1000     }
1001     init_function_ptrs();
1002 
1003     test_PdhOpenQueryA();
1004     test_PdhOpenQueryW();
1005 
1006     test_PdhAddCounterA();
1007     test_PdhAddCounterW();
1008 
1009     if (pPdhAddEnglishCounterA) test_PdhAddEnglishCounterA();
1010     if (pPdhAddEnglishCounterW) test_PdhAddEnglishCounterW();
1011     if (pPdhCollectQueryDataWithTime) test_PdhCollectQueryDataWithTime();
1012 
1013     test_PdhGetFormattedCounterValue();
1014     test_PdhGetRawCounterValue();
1015     test_PdhSetCounterScaleFactor();
1016     test_PdhGetCounterTimeBase();
1017 
1018     test_PdhGetCounterInfoA();
1019     test_PdhGetCounterInfoW();
1020 
1021     test_PdhLookupPerfIndexByNameA();
1022     test_PdhLookupPerfIndexByNameW();
1023 
1024     test_PdhLookupPerfNameByIndexA();
1025     test_PdhLookupPerfNameByIndexW();
1026 
1027     test_PdhValidatePathA();
1028     test_PdhValidatePathW();
1029 
1030     if (pPdhValidatePathExA) test_PdhValidatePathExA();
1031     if (pPdhValidatePathExW) test_PdhValidatePathExW();
1032 
1033     test_PdhCollectQueryDataEx();
1034     test_PdhMakeCounterPathA();
1035     test_PdhGetDllVersion();
1036 }
1037