gameux: Loading of game statistics implemented.
[wine] / dlls / pdh / tests / pdh.c
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 static void init_function_ptrs( void )
41 {
42     pdh = GetModuleHandle( "pdh" );
43     GETFUNCPTR( PdhAddEnglishCounterA )
44     GETFUNCPTR( PdhAddEnglishCounterW )
45     GETFUNCPTR( PdhCollectQueryDataWithTime )
46     GETFUNCPTR( PdhValidatePathExA )
47     GETFUNCPTR( PdhValidatePathExW )
48 }
49
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};
54
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};
62
63 static void test_PdhOpenQueryA( void )
64 {
65     PDH_STATUS ret;
66     PDH_HQUERY query;
67
68     ret = PdhOpenQueryA( NULL, 0, NULL );
69     ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryA failed 0x%08x\n", ret);
70
71     ret = PdhOpenQueryA( NULL, 0, &query );
72     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
73
74     ret = PdhCloseQuery( NULL );
75     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
76
77     ret = PdhCloseQuery( &query );
78     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
79
80     ret = PdhCloseQuery( query );
81     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
82
83     ret = PdhCloseQuery( query );
84     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
85 }
86
87 static void test_PdhOpenQueryW( void )
88 {
89     PDH_STATUS ret;
90     PDH_HQUERY query;
91
92     ret = PdhOpenQueryW( NULL, 0, NULL );
93     ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryW failed 0x%08x\n", ret);
94
95     ret = PdhOpenQueryW( NULL, 0, &query );
96     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW 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
111 static void test_PdhAddCounterA( void )
112 {
113     PDH_STATUS ret;
114     PDH_HQUERY query;
115     PDH_HCOUNTER counter;
116
117     ret = PdhOpenQueryA( NULL, 0, &query );
118     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
119
120     ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, NULL );
121     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
122
123     ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, &counter );
124     ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterA failed 0x%08x\n", ret);
125
126     ret = PdhAddCounterA( query, NULL, 0, &counter );
127     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
128
129     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, NULL );
130     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
131
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);
135
136     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
137     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
138
139     ret = PdhCollectQueryData( NULL );
140     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
141
142     ret = PdhCollectQueryData( counter );
143     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
144
145     ret = PdhCollectQueryData( query );
146     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
147
148     ret = PdhRemoveCounter( NULL );
149     ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08x\n", ret);
150
151     ret = PdhRemoveCounter( counter );
152     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
153
154     ret = PdhCloseQuery( query );
155     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
156 }
157
158 static void test_PdhAddCounterW( void )
159 {
160     PDH_STATUS ret;
161     PDH_HQUERY query;
162     PDH_HCOUNTER counter;
163
164     ret = PdhOpenQueryW( NULL, 0, &query );
165     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
166
167     ret = PdhAddCounterW( NULL, percentage_processor_time, 0, NULL );
168     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
169
170     ret = PdhAddCounterW( NULL, percentage_processor_time, 0, &counter );
171     ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterW failed 0x%08x\n", ret);
172
173     ret = PdhAddCounterW( query, NULL, 0, &counter );
174     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
175
176     ret = PdhAddCounterW( query, percentage_processor_time, 0, NULL );
177     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
178
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);
182
183     ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
184     ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08x\n", ret);
185
186     ret = PdhCollectQueryData( NULL );
187     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
188
189     ret = PdhCollectQueryData( counter );
190     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
191
192     ret = PdhCollectQueryData( query );
193     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
194
195     ret = PdhRemoveCounter( NULL );
196     ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08x\n", ret);
197
198     ret = PdhRemoveCounter( counter );
199     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
200
201     ret = PdhCloseQuery( query );
202     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
203 }
204
205 static void test_PdhAddEnglishCounterA( void )
206 {
207     PDH_STATUS ret;
208     PDH_HQUERY query;
209     PDH_HCOUNTER counter;
210
211     ret = PdhOpenQueryA( NULL, 0, &query );
212     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
213
214     ret = PdhCollectQueryData( query );
215     ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
216
217     ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, NULL );
218     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
219
220     ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, &counter );
221     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
222
223     ret = pPdhAddEnglishCounterA( query, NULL, 0, &counter );
224     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
225
226     ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, NULL );
227     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
228
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);
232
233     ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, &counter );
234     ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
235
236     ret = PdhCollectQueryData( query );
237     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
238
239     ret = PdhRemoveCounter( counter );
240     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
241
242     ret = PdhCloseQuery( query );
243     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
244 }
245
246 static void test_PdhAddEnglishCounterW( void )
247 {
248     PDH_STATUS ret;
249     PDH_HQUERY query;
250     PDH_HCOUNTER counter;
251
252     ret = PdhOpenQueryW( NULL, 0, &query );
253     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
254
255     ret = PdhCollectQueryData( query );
256     ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
257
258     ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, NULL );
259     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
260
261     ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, &counter );
262     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
263
264     ret = pPdhAddEnglishCounterW( query, NULL, 0, &counter );
265     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
266
267     ret = pPdhAddEnglishCounterW( query, system_uptime, 0, NULL );
268     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
269
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);
273
274     ret = pPdhAddEnglishCounterW( query, system_uptime, 0, &counter );
275     ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
276
277     ret = PdhCollectQueryData( query );
278     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
279
280     ret = PdhRemoveCounter( counter );
281     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
282
283     ret = PdhCloseQuery( query );
284     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
285 }
286
287 static void test_PdhCollectQueryDataWithTime( void )
288 {
289     PDH_STATUS ret;
290     PDH_HQUERY query;
291     PDH_HCOUNTER counter;
292     LONGLONG time;
293
294     ret = PdhOpenQueryA( NULL, 0, &query );
295     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
296
297     ret = PdhCollectQueryData( query );
298     ok(ret == PDH_NO_DATA, "PdhCollectQueryData failed 0x%08x\n", ret);
299
300     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
301     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
302
303     ret = pPdhCollectQueryDataWithTime( NULL, NULL );
304     ok(ret == PDH_INVALID_ARGUMENT, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
305
306     ret = pPdhCollectQueryDataWithTime( query, NULL );
307     ok(ret == PDH_INVALID_ARGUMENT, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
308
309     ret = pPdhCollectQueryDataWithTime( NULL, &time );
310     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
311
312     ret = pPdhCollectQueryDataWithTime( query, &time );
313     ok(ret == ERROR_SUCCESS, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
314
315     ret = PdhCloseQuery( query );
316     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
317 }
318
319 static void test_PdhGetFormattedCounterValue( void )
320 {
321     PDH_STATUS ret;
322     PDH_HQUERY query;
323     PDH_HCOUNTER counter;
324     PDH_FMT_COUNTERVALUE value;
325
326     ret = PdhOpenQueryA( NULL, 0, &query );
327     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
328
329     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
330     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
331
332     ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, NULL );
333     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
334
335     ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, &value );
336     ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
337
338     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, NULL );
339     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
340
341     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
342     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
343
344     ret = PdhCollectQueryData( query );
345     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
346
347     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
348     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
349
350     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOSCALE, NULL, &value );
351     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
352
353     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOCAP100, NULL, &value );
354     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
355
356     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_1000, NULL, &value );
357     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
358
359     ret = PdhSetCounterScaleFactor( counter, 2 );
360     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
361
362     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
363     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
364
365     ret = PdhCloseQuery( query );
366     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
367 }
368
369 static void test_PdhGetRawCounterValue( void )
370 {
371     PDH_STATUS ret;
372     PDH_HQUERY query;
373     PDH_HCOUNTER counter;
374     PDH_RAW_COUNTER value;
375
376     ret = PdhOpenQueryA( NULL, 0, &query );
377     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
378
379     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
380     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
381
382     ret = PdhGetRawCounterValue( NULL, NULL, &value );
383     ok(ret == PDH_INVALID_HANDLE, "PdhGetRawCounterValue failed 0x%08x\n", ret);
384
385     ret = PdhGetRawCounterValue( counter, NULL, NULL );
386     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetRawCounterValue failed 0x%08x\n", ret);
387
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);
391
392     ret = PdhCollectQueryData( query );
393     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
394
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);
398
399     ret = PdhCloseQuery( query );
400     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
401 }
402
403 static void test_PdhSetCounterScaleFactor( void )
404 {
405     PDH_STATUS ret;
406     PDH_HQUERY query;
407     PDH_HCOUNTER counter;
408
409     ret = PdhOpenQueryA( NULL, 0, &query );
410     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
411
412     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
413     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
414
415     ret = PdhSetCounterScaleFactor( NULL, 8 );
416     ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
417
418     ret = PdhSetCounterScaleFactor( NULL, 1 );
419     ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
420
421     ret = PdhSetCounterScaleFactor( counter, 8 );
422     ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
423
424     ret = PdhSetCounterScaleFactor( counter, -8 );
425     ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
426
427     ret = PdhSetCounterScaleFactor( counter, 7 );
428     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
429
430     ret = PdhSetCounterScaleFactor( counter, 0 );
431     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
432
433     ret = PdhCloseQuery( query );
434     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
435 }
436
437 static void test_PdhGetCounterTimeBase( void )
438 {
439     PDH_STATUS ret;
440     PDH_HQUERY query;
441     PDH_HCOUNTER counter;
442     LONGLONG base;
443
444     ret = PdhOpenQueryA( NULL, 0, &query );
445     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
446
447     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
448     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
449
450     ret = PdhGetCounterTimeBase( NULL, NULL );
451     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
452
453     ret = PdhGetCounterTimeBase( NULL, &base );
454     ok(ret == PDH_INVALID_HANDLE, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
455
456     ret = PdhGetCounterTimeBase( counter, NULL );
457     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
458
459     ret = PdhGetCounterTimeBase( counter, &base );
460     ok(ret == ERROR_SUCCESS, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
461
462     ret = PdhCloseQuery( query );
463     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
464 }
465
466 static void test_PdhGetCounterInfoA( void )
467 {
468     PDH_STATUS ret;
469     PDH_HQUERY query;
470     PDH_HCOUNTER counter;
471     PDH_COUNTER_INFO_A info;
472     DWORD size;
473
474     ret = PdhOpenQueryA( NULL, 0, &query );
475     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
476
477     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
478     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
479
480     ret = PdhGetCounterInfoA( NULL, 0, NULL, NULL );
481     ok(ret == PDH_INVALID_HANDLE || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
482
483     ret = PdhGetCounterInfoA( counter, 0, NULL, NULL );
484     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
485
486     ret = PdhGetCounterInfoA( counter, 0, NULL, &info );
487     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
488
489     size = sizeof(info) - 1;
490     ret = PdhGetCounterInfoA( counter, 0, &size, NULL );
491     ok(ret == PDH_MORE_DATA || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
492
493     size = sizeof(info);
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);
497
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);
501
502     ret = PdhSetCounterScaleFactor( counter, 0 );
503     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
504
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);
508
509     ret = PdhSetCounterScaleFactor( counter, -5 );
510     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
511
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);
515
516     ret = PdhCloseQuery( query );
517     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
518 }
519
520 static void test_PdhGetCounterInfoW( void )
521 {
522     PDH_STATUS ret;
523     PDH_HQUERY query;
524     PDH_HCOUNTER counter;
525     PDH_COUNTER_INFO_W info;
526     DWORD size;
527
528     ret = PdhOpenQueryW( NULL, 0, &query );
529     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
530
531     ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
532     ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08x\n", ret);
533
534     ret = PdhGetCounterInfoW( NULL, 0, NULL, NULL );
535     ok(ret == PDH_INVALID_HANDLE || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
536
537     ret = PdhGetCounterInfoW( counter, 0, NULL, NULL );
538     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
539
540     ret = PdhGetCounterInfoW( counter, 0, NULL, &info );
541     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
542
543     size = sizeof(info) - 1;
544     ret = PdhGetCounterInfoW( counter, 0, &size, NULL );
545     ok(ret == PDH_MORE_DATA || ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
546
547     size = sizeof(info);
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);
551
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);
555
556     ret = PdhSetCounterScaleFactor( counter, 0 );
557     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
558
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);
562
563     ret = PdhSetCounterScaleFactor( counter, -5 );
564     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
565
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);
569
570     ret = PdhCloseQuery( query );
571     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
572 }
573
574 static void test_PdhLookupPerfIndexByNameA( void )
575 {
576     PDH_STATUS ret;
577     DWORD index;
578
579     ret = PdhLookupPerfIndexByNameA( NULL, NULL, NULL );
580     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
581
582     ret = PdhLookupPerfIndexByNameA( NULL, NULL, &index );
583     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
584
585     ret = PdhLookupPerfIndexByNameA( NULL, "No Counter", &index );
586     ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
587
588     ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", NULL );
589     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
590
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);
594
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);
598 }
599
600 static void test_PdhLookupPerfIndexByNameW( void )
601 {
602     PDH_STATUS ret;
603     DWORD index;
604
605     static const WCHAR no_counter[] = {'N','o',' ','C','o','u','n','t','e','r',0};
606
607     ret = PdhLookupPerfIndexByNameW( NULL, NULL, NULL );
608     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
609
610     ret = PdhLookupPerfIndexByNameW( NULL, NULL, &index );
611     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
612
613     ret = PdhLookupPerfIndexByNameW( NULL, no_counter, &index );
614     ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
615
616     ret = PdhLookupPerfIndexByNameW( NULL, processor_time, NULL );
617     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
618
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);
622
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);
626 }
627
628 static void test_PdhLookupPerfNameByIndexA( void )
629 {
630     PDH_STATUS ret;
631     char buffer[PDH_MAX_COUNTER_NAME] = "!!";
632     DWORD size;
633
634     ret = PdhLookupPerfNameByIndexA( NULL, 0, NULL, NULL );
635     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
636
637     size = 0;
638     ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
639     ok(ret == PDH_MORE_DATA || ret == PDH_INSUFFICIENT_BUFFER, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
640
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);
647
648     size = sizeof(buffer);
649     ret = PdhLookupPerfNameByIndexA( NULL, 674, NULL, &size );
650     ok(ret == PDH_INVALID_ARGUMENT ||
651        ret == PDH_MORE_DATA, /* win2k3 */
652        "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
653
654     size = sizeof(buffer);
655     ret = PdhLookupPerfNameByIndexA( NULL, 674, buffer, &size );
656     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
657     ok(!lstrcmpA( buffer, "System Up Time" ),
658        "PdhLookupPerfNameByIndexA failed, got %s expected \'System Up Time\'\n", buffer);
659     ok(size == sizeof("System Up Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
660 }
661
662 static void test_PdhLookupPerfNameByIndexW( void )
663 {
664     PDH_STATUS ret;
665     WCHAR buffer[PDH_MAX_COUNTER_NAME];
666     DWORD size;
667
668     ret = PdhLookupPerfNameByIndexW( NULL, 0, NULL, NULL );
669     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
670
671     size = 0;
672     ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
673     ok(ret == PDH_MORE_DATA || ret == PDH_INSUFFICIENT_BUFFER, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
674
675     size = sizeof(buffer) / sizeof(WCHAR);
676     ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
677     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
678     ok(size == sizeof(processor_time) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
679
680     size = sizeof(buffer) / sizeof(WCHAR);
681     ret = PdhLookupPerfNameByIndexW( NULL, 674, NULL, &size );
682     ok(ret == PDH_INVALID_ARGUMENT ||
683        ret == PDH_MORE_DATA, /* win2k3 */
684        "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
685
686     size = sizeof(buffer) / sizeof(WCHAR);
687     ret = PdhLookupPerfNameByIndexW( NULL, 674, buffer, &size );
688     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
689     ok(size == sizeof(uptime) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
690 }
691
692 static void test_PdhValidatePathA( void )
693 {
694     PDH_STATUS ret;
695
696     ret = PdhValidatePathA( NULL );
697     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathA failed 0x%08x\n", ret);
698
699     ret = PdhValidatePathA( "" );
700     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathA failed 0x%08x\n", ret);
701
702     ret = PdhValidatePathA( "\\System" );
703     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathA failed 0x%08x\n", ret);
704
705     ret = PdhValidatePathA( "System Up Time" );
706     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathA failed 0x%08x\n", ret);
707
708     ret = PdhValidatePathA( "\\System\\System Down Time" );
709     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathA failed 0x%08x\n", ret);
710
711     ret = PdhValidatePathA( "\\System\\System Up Time" );
712     ok(ret == ERROR_SUCCESS, "PdhValidatePathA failed 0x%08x\n", ret);
713 }
714
715 static void test_PdhValidatePathW( void )
716 {
717     PDH_STATUS ret;
718
719     static const WCHAR empty[] = {0};
720     static const WCHAR system[] = {'\\','S','y','s','t','e','m',0};
721
722     ret = PdhValidatePathW( NULL );
723     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathW failed 0x%08x\n", ret);
724
725     ret = PdhValidatePathW( empty );
726     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathW failed 0x%08x\n", ret);
727
728     ret = PdhValidatePathW( system );
729     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathW failed 0x%08x\n", ret);
730
731     ret = PdhValidatePathW( uptime );
732     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathW failed 0x%08x\n", ret);
733
734     ret = PdhValidatePathW( system_downtime );
735     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathW failed 0x%08x\n", ret);
736
737     ret = PdhValidatePathW( system_uptime );
738     ok(ret == ERROR_SUCCESS, "PdhValidatePathW failed 0x%08x\n", ret);
739 }
740
741 static void test_PdhValidatePathExA( void )
742 {
743     PDH_STATUS ret;
744
745     ret = pPdhValidatePathExA( NULL, NULL );
746     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExA failed 0x%08x\n", ret);
747
748     ret = pPdhValidatePathExA( NULL, "" );
749     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExA failed 0x%08x\n", ret);
750
751     ret = pPdhValidatePathExA( NULL, "\\System" );
752     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExA failed 0x%08x\n", ret);
753
754     ret = pPdhValidatePathExA( NULL, "System Up Time" );
755     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExA failed 0x%08x\n", ret);
756
757     ret = pPdhValidatePathExA( NULL, "\\System\\System Down Time" );
758     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathExA failed 0x%08x\n", ret);
759
760     ret = pPdhValidatePathExA( NULL, "\\System\\System Up Time" );
761     ok(ret == ERROR_SUCCESS, "PdhValidatePathExA failed 0x%08x\n", ret);
762 }
763
764 static void test_PdhValidatePathExW( void )
765 {
766     PDH_STATUS ret;
767
768     static const WCHAR empty[] = {0};
769     static const WCHAR system[] = {'\\','S','y','s','t','e','m',0};
770
771     ret = pPdhValidatePathExW( NULL, NULL );
772     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExW failed 0x%08x\n", ret);
773
774     ret = pPdhValidatePathExW( NULL, empty );
775     ok(ret == PDH_INVALID_ARGUMENT, "PdhValidatePathExW failed 0x%08x\n", ret);
776
777     ret = pPdhValidatePathExW( NULL, system );
778     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExW failed 0x%08x\n", ret);
779
780     ret = pPdhValidatePathExW( NULL, uptime );
781     ok(ret == PDH_CSTATUS_BAD_COUNTERNAME, "PdhValidatePathExW failed 0x%08x\n", ret);
782
783     ret = pPdhValidatePathExW( NULL, system_downtime );
784     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhValidatePathExW failed 0x%08x\n", ret);
785
786     ret = pPdhValidatePathExW( NULL, system_uptime );
787     ok(ret == ERROR_SUCCESS, "PdhValidatePathExW failed 0x%08x\n", ret);
788 }
789
790 static void test_PdhCollectQueryDataEx(void)
791 {
792     PDH_STATUS status;
793     PDH_HQUERY query;
794     PDH_HCOUNTER counter;
795     HANDLE event;
796     BOOL ret;
797     UINT i;
798
799     status = PdhOpenQueryA( NULL, 0, &query );
800     ok(status == ERROR_SUCCESS, "PdhOpenQuery failed 0x%08x\n", status);
801
802     event = CreateEventA( NULL, FALSE, FALSE, "winetest" );
803     ok(event != NULL, "CreateEvent failed\n");
804
805     status = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
806     ok(status == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", status);
807
808     status = PdhCollectQueryDataEx( NULL, 1, event );
809     ok(status == PDH_INVALID_HANDLE, "PdhCollectQueryDataEx failed 0x%08x\n", status);
810
811     status = PdhCollectQueryDataEx( query, 1, NULL );
812     ok(status == ERROR_SUCCESS, "PdhCollectQueryDataEx failed 0x%08x\n", status);
813
814     status = PdhCollectQueryDataEx( query, 1, event );
815     ok(status == ERROR_SUCCESS, "PdhCollectQueryDataEx failed 0x%08x\n", status);
816
817     status = PdhCollectQueryData( query );
818     ok(status == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", status);
819
820     for (i = 0; i < 3; i++)
821     {
822         if (WaitForSingleObject( event, INFINITE ) == WAIT_OBJECT_0)
823         {
824             PDH_FMT_COUNTERVALUE value;
825
826             status = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
827             ok(status == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", status);
828
829             trace( "uptime %x%08x\n", (DWORD)(U(value).largeValue >> 32), (DWORD)U(value).largeValue );
830         }
831     }
832
833     ret = CloseHandle( event );
834     ok(ret, "CloseHandle failed\n");
835
836     status = PdhCloseQuery( query );
837     ok(status == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", status);
838 }
839
840 static void test_PdhMakeCounterPathA(void)
841 {
842     PDH_STATUS ret;
843     PDH_COUNTER_PATH_ELEMENTS_A e;
844     char buffer[1024];
845     DWORD buflen;
846
847     ret = PdhMakeCounterPathA(NULL, NULL, NULL, 0);
848     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
849
850     buflen = 0;
851     ret = PdhMakeCounterPathA(NULL, NULL, &buflen, 0);
852     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
853
854     buflen = 0;
855     ret = PdhMakeCounterPathA(NULL, buffer, &buflen, 0);
856     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
857
858     buflen = sizeof(buffer);
859     memset(&e, 0, sizeof(e));
860     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
861     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
862
863     buffer[0] = 0;
864     buflen = sizeof(buffer);
865     e.szMachineName = (char *)"machine";
866     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
867     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
868     ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
869
870     buffer[0] = 0;
871     buflen = sizeof(buffer);
872     e.szObjectName = (char *)"object";
873     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
874     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
875     ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
876
877     buffer[0] = 0;
878     buflen = sizeof(buffer);
879     e.szInstanceName = (char *)"instance";
880     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
881     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
882     ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
883
884     buffer[0] = 0;
885     buflen = sizeof(buffer);
886     e.szParentInstance = (char *)"parent";
887     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
888     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
889     ok(!strcmp(buffer, ""), "expected \"machine\" got %s\n", buffer);
890
891     buffer[0] = 0;
892     buflen = sizeof(buffer);
893     e.dwInstanceIndex = 1;
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);
897
898     buffer[0] = 0;
899     buflen = sizeof(buffer);
900     e.szCounterName = (char *)"counter";
901     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
902     ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
903     ok(!strcmp(buffer, "\\\\machine\\object(parent/instance#1)\\counter"),
904        "expected \"\\\\machine\\object(parent/instance#1)\\counter\" got %s\n", buffer);
905
906     buffer[0] = 0;
907     buflen = sizeof(buffer);
908     e.szParentInstance = NULL;
909     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
910     ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
911     ok(!strcmp(buffer, "\\\\machine\\object(instance#1)\\counter"),
912        "expected \"\\\\machine\\object(instance#1)\\counter\" got %s\n", buffer);
913
914     buffer[0] = 0;
915     buflen = sizeof(buffer);
916     e.szInstanceName = NULL;
917     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
918     ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
919     ok(!strcmp(buffer, "\\\\machine\\object\\counter"),
920        "expected \"\\\\machine\\object\\counter\" got %s\n", buffer);
921
922     buffer[0] = 0;
923     buflen = sizeof(buffer);
924     e.szMachineName = NULL;
925     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
926     ok(ret == ERROR_SUCCESS, "PdhMakeCounterPathA failed 0x%08x\n", ret);
927     ok(!strcmp(buffer, "\\object\\counter"),
928        "expected \"\\object\\counter\" got %s\n", buffer);
929
930     buffer[0] = 0;
931     buflen = sizeof(buffer);
932     e.szObjectName = NULL;
933     ret = PdhMakeCounterPathA(&e, buffer, &buflen, 0);
934     ok(ret == PDH_INVALID_ARGUMENT, "PdhMakeCounterPathA failed 0x%08x\n", ret);
935 }
936
937 static void test_PdhGetDllVersion(void)
938 {
939     PDH_STATUS ret;
940     DWORD version;
941
942     ret = PdhGetDllVersion(NULL);
943     ok(ret == PDH_INVALID_ARGUMENT ||
944        broken(ret == ERROR_SUCCESS), /* Vista+ */
945        "Expected PdhGetDllVersion to return PDH_INVALID_ARGUMENT, got %d\n", ret);
946
947     ret = PdhGetDllVersion(&version);
948     ok(ret == ERROR_SUCCESS,
949        "Expected PdhGetDllVersion to return ERROR_SUCCESS, got %d\n", ret);
950
951     if (ret == ERROR_SUCCESS)
952     {
953         ok(version == PDH_CVERSION_WIN50 ||
954            version == PDH_VERSION,
955            "Expected version number to be PDH_CVERSION_WIN50 or PDH_VERSION, got %u\n", version);
956     }
957 }
958
959 START_TEST(pdh)
960 {
961     if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH)
962     {
963         skip("non-english locale\n");
964         return;
965     }
966     init_function_ptrs();
967
968     test_PdhOpenQueryA();
969     test_PdhOpenQueryW();
970
971     test_PdhAddCounterA();
972     test_PdhAddCounterW();
973
974     if (pPdhAddEnglishCounterA) test_PdhAddEnglishCounterA();
975     if (pPdhAddEnglishCounterW) test_PdhAddEnglishCounterW();
976     if (pPdhCollectQueryDataWithTime) test_PdhCollectQueryDataWithTime();
977
978     test_PdhGetFormattedCounterValue();
979     test_PdhGetRawCounterValue();
980     test_PdhSetCounterScaleFactor();
981     test_PdhGetCounterTimeBase();
982
983     test_PdhGetCounterInfoA();
984     test_PdhGetCounterInfoW();
985
986     test_PdhLookupPerfIndexByNameA();
987     test_PdhLookupPerfIndexByNameW();
988
989     test_PdhLookupPerfNameByIndexA();
990     test_PdhLookupPerfNameByIndexW();
991
992     test_PdhValidatePathA();
993     test_PdhValidatePathW();
994
995     if (pPdhValidatePathExA) test_PdhValidatePathExA();
996     if (pPdhValidatePathExW) test_PdhValidatePathExW();
997
998     test_PdhCollectQueryDataEx();
999     test_PdhMakeCounterPathA();
1000     test_PdhGetDllVersion();
1001 }