comctl32: We can now store binary files in the repository.
[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
36 #define GETFUNCPTR(func) p##func = (void *)GetProcAddress( pdh, #func );
37
38 static void init_function_ptrs( void )
39 {
40     pdh = GetModuleHandle( "pdh" );
41     GETFUNCPTR( PdhAddEnglishCounterA )
42     GETFUNCPTR( PdhAddEnglishCounterW )
43     GETFUNCPTR( PdhCollectQueryDataWithTime )
44 }
45
46 static const WCHAR processor_time[] =
47     {'%',' ','P','r','o','c','e','s','s','o','r',' ','T','i','m','e',0};
48 static const WCHAR uptime[] =
49     {'S','y','s','t','e','m',' ','U','p',' ','T','i','m','e',0};
50
51 static const WCHAR system_uptime[] =
52     {'\\','S','y','s','t','e','m','\\','S','y','s','t','e','m',' ','U','p',' ','T','i','m','e',0};
53 static const WCHAR system_downtime[] = /* does not exist */
54     {'\\','S','y','s','t','e','m','\\','S','y','s','t','e','m',' ','D','o','w','n',' ','T','i','m','e',0};
55 static const WCHAR percentage_processor_time[] =
56     {'\\','P','r','o','c','e','s','s','o','r','(','_','T','o','t','a','l',')',
57      '\\','%',' ','P','r','o','c','e','s','s','o','r',' ','T','i','m','e',0};
58
59 static void test_PdhOpenQueryA( void )
60 {
61     PDH_STATUS ret;
62     PDH_HQUERY query;
63
64     ret = PdhOpenQueryA( NULL, 0, NULL );
65     ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryA failed 0x%08x\n", ret);
66
67     ret = PdhOpenQueryA( NULL, 0, &query );
68     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
69
70     ret = PdhCloseQuery( NULL );
71     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
72
73     ret = PdhCloseQuery( &query );
74     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
75
76     ret = PdhCloseQuery( query );
77     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
78
79     ret = PdhCloseQuery( query );
80     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
81 }
82
83 static void test_PdhOpenQueryW( void )
84 {
85     PDH_STATUS ret;
86     PDH_HQUERY query;
87
88     ret = PdhOpenQueryW( NULL, 0, NULL );
89     ok(ret == PDH_INVALID_ARGUMENT, "PdhOpenQueryW failed 0x%08x\n", ret);
90
91     ret = PdhOpenQueryW( NULL, 0, &query );
92     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
93
94     ret = PdhCloseQuery( NULL );
95     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
96
97     ret = PdhCloseQuery( &query );
98     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
99
100     ret = PdhCloseQuery( query );
101     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
102
103     ret = PdhCloseQuery( query );
104     ok(ret == PDH_INVALID_HANDLE, "PdhCloseQuery failed 0x%08x\n", ret);
105 }
106
107 static void test_PdhAddCounterA( void )
108 {
109     PDH_STATUS ret;
110     PDH_HQUERY query;
111     PDH_HCOUNTER counter;
112
113     ret = PdhOpenQueryA( NULL, 0, &query );
114     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
115
116     ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, NULL );
117     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
118
119     ret = PdhAddCounterA( NULL, "\\System\\System Up Time", 0, &counter );
120     ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterA failed 0x%08x\n", ret);
121
122     ret = PdhAddCounterA( query, NULL, 0, &counter );
123     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
124
125     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, NULL );
126     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterA failed 0x%08x\n", ret);
127
128     ret = PdhAddCounterA( query, "\\System\\System Down Time", 0, &counter );
129     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddCounterA failed 0x%08x\n", ret);
130     ok(!counter, "PdhAddCounterA failed %p\n", counter);
131
132     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
133     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
134
135     ret = PdhCollectQueryData( NULL );
136     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
137
138     ret = PdhCollectQueryData( counter );
139     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
140
141     ret = PdhCollectQueryData( query );
142     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
143
144     ret = PdhRemoveCounter( NULL );
145     ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08x\n", ret);
146
147     ret = PdhRemoveCounter( counter );
148     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
149
150     ret = PdhCloseQuery( query );
151     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
152 }
153
154 static void test_PdhAddCounterW( void )
155 {
156     PDH_STATUS ret;
157     PDH_HQUERY query;
158     PDH_HCOUNTER counter;
159
160     ret = PdhOpenQueryW( NULL, 0, &query );
161     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
162
163     ret = PdhAddCounterW( NULL, percentage_processor_time, 0, NULL );
164     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
165
166     ret = PdhAddCounterW( NULL, percentage_processor_time, 0, &counter );
167     ok(ret == PDH_INVALID_HANDLE, "PdhAddCounterW failed 0x%08x\n", ret);
168
169     ret = PdhAddCounterW( query, NULL, 0, &counter );
170     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
171
172     ret = PdhAddCounterW( query, percentage_processor_time, 0, NULL );
173     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddCounterW failed 0x%08x\n", ret);
174
175     ret = PdhAddCounterW( query, system_downtime, 0, &counter );
176     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddCounterW failed 0x%08x\n", ret);
177     ok(!counter, "PdhAddCounterW failed %p\n", counter);
178
179     ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
180     ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08x\n", ret);
181
182     ret = PdhCollectQueryData( NULL );
183     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
184
185     ret = PdhCollectQueryData( counter );
186     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryData failed 0x%08x\n", ret);
187
188     ret = PdhCollectQueryData( query );
189     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
190
191     ret = PdhRemoveCounter( NULL );
192     ok(ret == PDH_INVALID_HANDLE, "PdhRemoveCounter failed 0x%08x\n", ret);
193
194     ret = PdhRemoveCounter( counter );
195     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
196
197     ret = PdhCloseQuery( query );
198     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
199 }
200
201 static void test_PdhAddEnglishCounterA( void )
202 {
203     PDH_STATUS ret;
204     PDH_HQUERY query;
205     PDH_HCOUNTER counter;
206
207     ret = PdhOpenQueryA( NULL, 0, &query );
208     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
209
210     ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, NULL );
211     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
212
213     ret = pPdhAddEnglishCounterA( NULL, "\\System\\System Up Time", 0, &counter );
214     ok(ret == PDH_INVALID_HANDLE, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
215
216     ret = pPdhAddEnglishCounterA( query, NULL, 0, &counter );
217     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
218
219     ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, NULL );
220     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
221
222     ret = pPdhAddEnglishCounterA( query, "\\System\\System Down Time", 0, &counter );
223     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
224     ok(!counter, "PdhAddEnglishCounterA failed %p\n", counter);
225
226     ret = pPdhAddEnglishCounterA( query, "\\System\\System Up Time", 0, &counter );
227     ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterA failed 0x%08x\n", ret);
228
229     ret = PdhCollectQueryData( query );
230     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
231
232     ret = PdhRemoveCounter( counter );
233     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
234
235     ret = PdhCloseQuery( query );
236     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
237 }
238
239 static void test_PdhAddEnglishCounterW( void )
240 {
241     PDH_STATUS ret;
242     PDH_HQUERY query;
243     PDH_HCOUNTER counter;
244
245     ret = PdhOpenQueryW( NULL, 0, &query );
246     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
247
248     ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, NULL );
249     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
250
251     ret = pPdhAddEnglishCounterW( NULL, system_uptime, 0, &counter );
252     ok(ret == PDH_INVALID_HANDLE, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
253
254     ret = pPdhAddEnglishCounterW( query, NULL, 0, &counter );
255     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
256
257     ret = pPdhAddEnglishCounterW( query, system_uptime, 0, NULL );
258     ok(ret == PDH_INVALID_ARGUMENT, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
259
260     ret = pPdhAddEnglishCounterW( query, system_downtime, 0, &counter );
261     ok(ret == PDH_CSTATUS_NO_COUNTER, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
262     ok(!counter, "PdhAddEnglishCounterA failed %p\n", counter);
263
264     ret = pPdhAddEnglishCounterW( query, system_uptime, 0, &counter );
265     ok(ret == ERROR_SUCCESS, "PdhAddEnglishCounterW failed 0x%08x\n", ret);
266
267     ret = PdhCollectQueryData( query );
268     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
269
270     ret = PdhRemoveCounter( counter );
271     ok(ret == ERROR_SUCCESS, "PdhRemoveCounter failed 0x%08x\n", ret);
272
273     ret = PdhCloseQuery( query );
274     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
275 }
276
277 static void test_PdhCollectQueryDataWithTime( void )
278 {
279     PDH_STATUS ret;
280     PDH_HQUERY query;
281     PDH_HCOUNTER counter;
282     LONGLONG time;
283
284     ret = PdhOpenQueryA( NULL, 0, &query );
285     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
286
287     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
288     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
289
290     ret = pPdhCollectQueryDataWithTime( NULL, NULL );
291     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
292
293     ret = pPdhCollectQueryDataWithTime( query, NULL );
294     ok(ret == ERROR_SUCCESS, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
295
296     ret = pPdhCollectQueryDataWithTime( NULL, &time );
297     ok(ret == PDH_INVALID_HANDLE, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
298
299     ret = pPdhCollectQueryDataWithTime( query, &time );
300     ok(ret == ERROR_SUCCESS, "PdhCollectQueryDataWithTime failed 0x%08x\n", ret);
301
302     ret = PdhCloseQuery( query );
303     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
304 }
305
306 static void test_PdhGetFormattedCounterValue( void )
307 {
308     PDH_STATUS ret;
309     PDH_HQUERY query;
310     PDH_HCOUNTER counter;
311     PDH_FMT_COUNTERVALUE value;
312
313     ret = PdhOpenQueryA( NULL, 0, &query );
314     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
315
316     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
317     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
318
319     ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, NULL );
320     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
321
322     ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, &value );
323     ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
324
325     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, NULL );
326     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
327
328     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
329     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
330
331     ret = PdhCollectQueryData( query );
332     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
333
334     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
335     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
336
337     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOSCALE, NULL, &value );
338     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
339
340     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOCAP100, NULL, &value );
341     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
342
343     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_1000, NULL, &value );
344     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
345
346     ret = PdhSetCounterScaleFactor( counter, 2 );
347     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
348
349     ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
350     ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
351
352     ret = PdhCloseQuery( query );
353     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
354 }
355
356 static void test_PdhGetRawCounterValue( void )
357 {
358     PDH_STATUS ret;
359     PDH_HQUERY query;
360     PDH_HCOUNTER counter;
361     PDH_RAW_COUNTER value;
362
363     ret = PdhOpenQueryA( NULL, 0, &query );
364     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
365
366     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
367     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
368
369     ret = PdhGetRawCounterValue( NULL, NULL, &value );
370     ok(ret == PDH_INVALID_HANDLE, "PdhGetRawCounterValue failed 0x%08x\n", ret);
371
372     ret = PdhGetRawCounterValue( counter, NULL, NULL );
373     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetRawCounterValue failed 0x%08x\n", ret);
374
375     ret = PdhGetRawCounterValue( counter, NULL, &value );
376     ok(ret == ERROR_SUCCESS, "PdhGetRawCounterValue failed 0x%08x\n", ret);
377     ok(value.CStatus == ERROR_SUCCESS, "expected ERROR_SUCCESS got %x\n", value.CStatus);
378
379     ret = PdhCollectQueryData( query );
380     ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
381
382     ret = PdhGetRawCounterValue( counter, NULL, &value );
383     ok(ret == ERROR_SUCCESS, "PdhGetRawCounterValue failed 0x%08x\n", ret);
384     ok(value.CStatus == ERROR_SUCCESS, "expected ERROR_SUCCESS got %x\n", value.CStatus);
385
386     ret = PdhCloseQuery( query );
387     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
388 }
389
390 static void test_PdhSetCounterScaleFactor( void )
391 {
392     PDH_STATUS ret;
393     PDH_HQUERY query;
394     PDH_HCOUNTER counter;
395
396     ret = PdhOpenQueryA( NULL, 0, &query );
397     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
398
399     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
400     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
401
402     ret = PdhSetCounterScaleFactor( NULL, 8 );
403     ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
404
405     ret = PdhSetCounterScaleFactor( NULL, 1 );
406     ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
407
408     ret = PdhSetCounterScaleFactor( counter, 8 );
409     ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
410
411     ret = PdhSetCounterScaleFactor( counter, -8 );
412     ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
413
414     ret = PdhSetCounterScaleFactor( counter, 7 );
415     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
416
417     ret = PdhSetCounterScaleFactor( counter, 0 );
418     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
419
420     ret = PdhCloseQuery( query );
421     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
422 }
423
424 static void test_PdhGetCounterTimeBase( void )
425 {
426     PDH_STATUS ret;
427     PDH_HQUERY query;
428     PDH_HCOUNTER counter;
429     LONGLONG base;
430
431     ret = PdhOpenQueryA( NULL, 0, &query );
432     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
433
434     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
435     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
436
437     ret = PdhGetCounterTimeBase( NULL, NULL );
438     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
439
440     ret = PdhGetCounterTimeBase( NULL, &base );
441     ok(ret == PDH_INVALID_HANDLE, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
442
443     ret = PdhGetCounterTimeBase( counter, NULL );
444     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
445
446     ret = PdhGetCounterTimeBase( counter, &base );
447     ok(ret == ERROR_SUCCESS, "PdhGetCounterTimeBase failed 0x%08x\n", ret);
448
449     ret = PdhCloseQuery( query );
450     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
451 }
452
453 static void test_PdhGetCounterInfoA( void )
454 {
455     PDH_STATUS ret;
456     PDH_HQUERY query;
457     PDH_HCOUNTER counter;
458     PDH_COUNTER_INFO_A info;
459     DWORD size;
460
461     ret = PdhOpenQueryA( NULL, 0, &query );
462     ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
463
464     ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
465     ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
466
467     ret = PdhGetCounterInfoA( NULL, 0, NULL, NULL );
468     ok(ret == PDH_INVALID_HANDLE, "PdhGetCounterInfoA failed 0x%08x\n", ret);
469
470     ret = PdhGetCounterInfoA( counter, 0, NULL, NULL );
471     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
472
473     ret = PdhGetCounterInfoA( counter, 0, NULL, &info );
474     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoA failed 0x%08x\n", ret);
475
476     size = sizeof(info) - 1;
477     ret = PdhGetCounterInfoA( counter, 0, &size, NULL );
478     ok(ret == PDH_MORE_DATA, "PdhGetCounterInfoA failed 0x%08x\n", ret);
479
480     size = sizeof(info);
481     ret = PdhGetCounterInfoA( counter, 0, &size, &info );
482     ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
483     ok(size == sizeof(info), "PdhGetCounterInfoA failed %d\n", size);
484
485     ret = PdhGetCounterInfoA( counter, 0, &size, &info );
486     ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
487     ok(info.lScale == 0, "lScale %d\n", info.lScale);
488
489     ret = PdhSetCounterScaleFactor( counter, 0 );
490     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
491
492     ret = PdhGetCounterInfoA( counter, 0, &size, &info );
493     ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
494     ok(info.lScale == 0, "lScale %d\n", info.lScale);
495
496     ret = PdhSetCounterScaleFactor( counter, -5 );
497     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
498
499     ret = PdhGetCounterInfoA( counter, 0, &size, &info );
500     ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoA failed 0x%08x\n", ret);
501     ok(info.lScale == -5, "lScale %d\n", info.lScale);
502
503     ret = PdhCloseQuery( query );
504     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
505 }
506
507 static void test_PdhGetCounterInfoW( void )
508 {
509     PDH_STATUS ret;
510     PDH_HQUERY query;
511     PDH_HCOUNTER counter;
512     PDH_COUNTER_INFO_W info;
513     DWORD size;
514
515     ret = PdhOpenQueryW( NULL, 0, &query );
516     ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08x\n", ret);
517
518     ret = PdhAddCounterW( query, percentage_processor_time, 0, &counter );
519     ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08x\n", ret);
520
521     ret = PdhGetCounterInfoW( NULL, 0, NULL, NULL );
522     ok(ret == PDH_INVALID_HANDLE, "PdhGetCounterInfoW failed 0x%08x\n", ret);
523
524     ret = PdhGetCounterInfoW( counter, 0, NULL, NULL );
525     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
526
527     ret = PdhGetCounterInfoW( counter, 0, NULL, &info );
528     ok(ret == PDH_INVALID_ARGUMENT, "PdhGetCounterInfoW failed 0x%08x\n", ret);
529
530     size = sizeof(info) - 1;
531     ret = PdhGetCounterInfoW( counter, 0, &size, NULL );
532     ok(ret == PDH_MORE_DATA, "PdhGetCounterInfoW failed 0x%08x\n", ret);
533
534     size = sizeof(info);
535     ret = PdhGetCounterInfoW( counter, 0, &size, &info );
536     ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
537     ok(size == sizeof(info), "PdhGetCounterInfoW failed %d\n", size);
538
539     ret = PdhGetCounterInfoW( counter, 0, &size, &info );
540     ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
541     ok(info.lScale == 0, "lScale %d\n", info.lScale);
542
543     ret = PdhSetCounterScaleFactor( counter, 0 );
544     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
545
546     ret = PdhGetCounterInfoW( counter, 0, &size, &info );
547     ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
548     ok(info.lScale == 0, "lScale %d\n", info.lScale);
549
550     ret = PdhSetCounterScaleFactor( counter, -5 );
551     ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
552
553     ret = PdhGetCounterInfoW( counter, 0, &size, &info );
554     ok(ret == ERROR_SUCCESS, "PdhGetCounterInfoW failed 0x%08x\n", ret);
555     ok(info.lScale == -5, "lScale %d\n", info.lScale);
556
557     ret = PdhCloseQuery( query );
558     ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
559 }
560
561 static void test_PdhLookupPerfIndexByNameA( void )
562 {
563     PDH_STATUS ret;
564     DWORD index;
565
566     ret = PdhLookupPerfIndexByNameA( NULL, NULL, NULL );
567     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
568
569     ret = PdhLookupPerfIndexByNameA( NULL, NULL, &index );
570     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
571
572     ret = PdhLookupPerfIndexByNameA( NULL, "No Counter", &index );
573     ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
574
575     ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", NULL );
576     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
577
578     ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", &index );
579     ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
580     ok(index == 6, "PdhLookupPerfIndexByNameA failed %d\n", index);
581
582     ret = PdhLookupPerfIndexByNameA( NULL, "System Up Time", &index );
583     ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
584     ok(index == 674, "PdhLookupPerfIndexByNameA failed %d\n", index);
585 }
586
587 static void test_PdhLookupPerfIndexByNameW( void )
588 {
589     PDH_STATUS ret;
590     DWORD index;
591
592     static const WCHAR no_counter[] = {'N','o',' ','C','o','u','n','t','e','r',0};
593
594     ret = PdhLookupPerfIndexByNameW( NULL, NULL, NULL );
595     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
596
597     ret = PdhLookupPerfIndexByNameW( NULL, NULL, &index );
598     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
599
600     ret = PdhLookupPerfIndexByNameW( NULL, no_counter, &index );
601     ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
602
603     ret = PdhLookupPerfIndexByNameW( NULL, processor_time, NULL );
604     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
605
606     ret = PdhLookupPerfIndexByNameW( NULL, processor_time, &index );
607     ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
608     ok(index == 6, "PdhLookupPerfIndexByNameW failed %d\n", index);
609
610     ret = PdhLookupPerfIndexByNameW( NULL, uptime, &index );
611     ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
612     ok(index == 674, "PdhLookupPerfIndexByNameW failed %d\n", index);
613 }
614
615 static void test_PdhLookupPerfNameByIndexA( void )
616 {
617     PDH_STATUS ret;
618     char buffer[PDH_MAX_COUNTER_NAME] = "!!";
619     DWORD size;
620
621     ret = PdhLookupPerfNameByIndexA( NULL, 0, NULL, NULL );
622     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
623
624     size = 1;
625     ret = PdhLookupPerfNameByIndexA( NULL, 0, NULL, &size );
626     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
627     ok(size == 1, "PdhLookupPerfNameByIndexA failed %d\n", size);
628
629     size = sizeof(buffer);
630     ret = PdhLookupPerfNameByIndexA( NULL, 0, buffer, &size );
631     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
632     ok(!strcmp(buffer, "!!"), "PdhLookupPerfNameByIndexA failed %s\n", buffer);
633
634     size = 0;
635     ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
636     ok(ret == PDH_MORE_DATA, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
637     ok(size == sizeof("% Processor Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
638
639     size = sizeof(buffer);
640     ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
641     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
642     ok(!lstrcmpA( buffer, "% Processor Time" ),
643        "PdhLookupPerfNameByIndexA failed, got %s expected \'%% Processor Time\'\n", buffer);
644     ok(size == sizeof("% Processor Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
645
646     size = 0;
647     ret = PdhLookupPerfNameByIndexA( NULL, 674, NULL, &size );
648     ok(ret == PDH_MORE_DATA, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
649     ok(size == sizeof("System Up Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
650
651     size = sizeof(buffer);
652     ret = PdhLookupPerfNameByIndexA( NULL, 674, buffer, &size );
653     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
654     ok(!lstrcmpA( buffer, "System Up Time" ),
655        "PdhLookupPerfNameByIndexA failed, got %s expected \'System Up Time\'\n", buffer);
656     ok(size == sizeof("System Up Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
657 }
658
659 static void test_PdhLookupPerfNameByIndexW( void )
660 {
661     PDH_STATUS ret;
662     WCHAR buffer[PDH_MAX_COUNTER_NAME];
663     DWORD size;
664
665     ret = PdhLookupPerfNameByIndexW( NULL, 0, NULL, NULL );
666     ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
667
668     size = 1;
669     ret = PdhLookupPerfNameByIndexW( NULL, 0, NULL, &size );
670     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
671     ok(size == 1, "PdhLookupPerfNameByIndexW failed %d\n", size);
672
673     size = sizeof(buffer) / sizeof(WCHAR);
674     ret = PdhLookupPerfNameByIndexW( NULL, 0, buffer, &size );
675     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
676
677     size = 0;
678     ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
679     ok(ret == PDH_MORE_DATA, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
680     ok(size == sizeof(processor_time) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
681
682     size = sizeof(buffer) / sizeof(WCHAR);
683     ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
684     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
685     ok(size == sizeof(processor_time) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
686
687     size = 0;
688     ret = PdhLookupPerfNameByIndexW( NULL, 674, NULL, &size );
689     ok(ret == PDH_MORE_DATA, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
690     ok(size == sizeof(uptime) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
691
692     size = sizeof(buffer) / sizeof(WCHAR);
693     ret = PdhLookupPerfNameByIndexW( NULL, 674, buffer, &size );
694     ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
695     ok(size == sizeof(uptime) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
696 }
697
698 START_TEST(pdh)
699 {
700     init_function_ptrs();
701
702     test_PdhOpenQueryA();
703     test_PdhOpenQueryW();
704
705     test_PdhAddCounterA();
706     test_PdhAddCounterW();
707
708     if (pPdhAddEnglishCounterA) test_PdhAddEnglishCounterA();
709     if (pPdhAddEnglishCounterW) test_PdhAddEnglishCounterW();
710     if (pPdhCollectQueryDataWithTime) test_PdhCollectQueryDataWithTime();
711
712     test_PdhGetFormattedCounterValue();
713     test_PdhGetRawCounterValue();
714     test_PdhSetCounterScaleFactor();
715     test_PdhGetCounterTimeBase();
716
717     test_PdhGetCounterInfoA();
718     test_PdhGetCounterInfoW();
719
720     test_PdhLookupPerfIndexByNameA();
721     test_PdhLookupPerfIndexByNameW();
722
723     test_PdhLookupPerfNameByIndexA();
724     test_PdhLookupPerfNameByIndexW();
725 }