Hans Leidekker : pdh: Implement and test PdhSetCounterScaleFactor and
PdhGetFormattedCounterValue .
Alexandre Julliard
julliard at wine.codeweavers.com
Tue Jul 10 08:02:33 CDT 2007
Module: wine
Branch: master
Commit: 0d516c5377bcce2410db0457bd063f76640bd4ae
URL: http://source.winehq.org/git/wine.git/?a=commit;h=0d516c5377bcce2410db0457bd063f76640bd4ae
Author: Hans Leidekker <hans at it.vu.nl>
Date: Mon Jul 9 20:55:13 2007 +0200
pdh: Implement and test PdhSetCounterScaleFactor and PdhGetFormattedCounterValue.
---
dlls/pdh/pdh.spec | 4 +-
dlls/pdh/pdh_main.c | 60 +++++++++++++++++++++++++++++++++++
dlls/pdh/tests/pdh.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 148 insertions(+), 2 deletions(-)
diff --git a/dlls/pdh/pdh.spec b/dlls/pdh/pdh.spec
index 42a66ed..6dfc73d 100644
--- a/dlls/pdh/pdh.spec
+++ b/dlls/pdh/pdh.spec
@@ -57,7 +57,7 @@
@ stub PdhGetDllVersion
@ stub PdhGetFormattedCounterArrayA
@ stub PdhGetFormattedCounterArrayW
-@ stub PdhGetFormattedCounterValue
+@ stdcall PdhGetFormattedCounterValue(ptr long ptr ptr)
@ stub PdhGetLogFileSize
@ stub PdhGetLogFileTypeA
@ stub PdhGetLogFileTypeW
@@ -123,7 +123,7 @@
@ stdcall PdhRemoveCounter(ptr)
@ stub PdhSelectDataSourceA
@ stub PdhSelectDataSourceW
-@ stub PdhSetCounterScaleFactor
+@ stdcall PdhSetCounterScaleFactor(ptr long)
@ stub PdhSetDefaultRealTimeDataSource
@ stub PdhSetLogSetRunID
@ stub PdhSetQueryTimeRange
diff --git a/dlls/pdh/pdh_main.c b/dlls/pdh/pdh_main.c
index f4b8b15..f89493e 100644
--- a/dlls/pdh/pdh_main.c
+++ b/dlls/pdh/pdh_main.c
@@ -19,6 +19,7 @@
*/
#include <stdarg.h>
+#include <math.h>
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
@@ -283,6 +284,49 @@ PDH_STATUS WINAPI PdhCollectQueryData( PDH_HQUERY handle )
}
/***********************************************************************
+ * PdhGetFormattedCounterValue (PDH.@)
+ */
+PDH_STATUS WINAPI PdhGetFormattedCounterValue( PDH_HCOUNTER handle, DWORD format,
+ LPDWORD type, PPDH_FMT_COUNTERVALUE value )
+{
+ LONG factor;
+ struct counter *counter = handle;
+
+ TRACE("%p %x %p %p\n", handle, format, type, value);
+
+ if (!value) return PDH_INVALID_ARGUMENT;
+ if (!counter) return PDH_INVALID_HANDLE;
+
+ if (counter->status) return PDH_INVALID_DATA;
+
+ factor = counter->scale ? counter->scale : counter->defaultscale;
+ if (format & PDH_FMT_LONG)
+ {
+ if (format & PDH_FMT_1000) value->u.longValue = counter->two.longvalue * 1000;
+ else value->u.longValue = counter->two.longvalue * pow( 10, factor );
+ }
+ else if (format & PDH_FMT_LARGE)
+ {
+ if (format & PDH_FMT_1000) value->u.longValue = counter->two.largevalue * 1000;
+ else value->u.largeValue = counter->two.largevalue * pow( 10, factor );
+ }
+ else if (format & PDH_FMT_DOUBLE)
+ {
+ if (format & PDH_FMT_1000) value->u.longValue = counter->two.doublevalue * 1000;
+ else value->u.doubleValue = counter->two.doublevalue * pow( 10, factor );
+ }
+ else
+ {
+ WARN("unknown format %x\n", format);
+ return PDH_INVALID_ARGUMENT;
+ }
+ value->CStatus = ERROR_SUCCESS;
+
+ if (type) *type = counter->type;
+ return ERROR_SUCCESS;
+}
+
+/***********************************************************************
* PdhOpenQueryA (PDH.@)
*/
PDH_STATUS WINAPI PdhOpenQueryA( LPCSTR source, DWORD_PTR userdata, PDH_HQUERY *query )
@@ -344,3 +388,19 @@ PDH_STATUS WINAPI PdhRemoveCounter( PDH_HCOUNTER handle )
return ERROR_SUCCESS;
}
+
+/***********************************************************************
+ * PdhSetCounterScaleFactor (PDH.@)
+ */
+PDH_STATUS WINAPI PdhSetCounterScaleFactor( PDH_HCOUNTER handle, LONG factor )
+{
+ struct counter *counter = handle;
+
+ TRACE("%p\n", handle);
+
+ if (!counter) return PDH_INVALID_HANDLE;
+ if (factor < PDH_MIN_SCALE || factor > PDH_MAX_SCALE) return PDH_INVALID_ARGUMENT;
+
+ counter->scale = factor;
+ return ERROR_SUCCESS;
+}
diff --git a/dlls/pdh/tests/pdh.c b/dlls/pdh/tests/pdh.c
index f6d6921..084fefc 100644
--- a/dlls/pdh/tests/pdh.c
+++ b/dlls/pdh/tests/pdh.c
@@ -95,8 +95,94 @@ static void test_add_remove_counter( void )
ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
}
+static void test_PdhGetFormattedCounterValue( void )
+{
+ PDH_STATUS ret;
+ PDH_HQUERY query;
+ PDH_HCOUNTER counter;
+ PDH_FMT_COUNTERVALUE value;
+
+ ret = PdhOpenQueryA( NULL, 0, &query );
+ ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
+
+ ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
+ ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
+
+ ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, NULL );
+ ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
+
+ ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, &value );
+ ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
+
+ ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, NULL );
+ ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
+
+ ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
+ ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
+
+ ret = PdhCollectQueryData( query );
+ ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
+
+ ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
+ ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
+
+ ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOSCALE, NULL, &value );
+ ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
+
+ ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOCAP100, NULL, &value );
+ ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
+
+ ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_1000, NULL, &value );
+ ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
+
+ ret = PdhSetCounterScaleFactor( counter, 2 );
+ ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
+
+ ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
+ ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
+
+ ret = PdhCloseQuery( query );
+ ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
+}
+
+static void test_PdhSetCounterScaleFactor( void )
+{
+ PDH_STATUS ret;
+ PDH_HQUERY query;
+ PDH_HCOUNTER counter;
+
+ ret = PdhOpenQueryA( NULL, 0, &query );
+ ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
+
+ ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
+ ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
+
+ ret = PdhSetCounterScaleFactor( NULL, 8 );
+ ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
+
+ ret = PdhSetCounterScaleFactor( NULL, 1 );
+ ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
+
+ ret = PdhSetCounterScaleFactor( counter, 8 );
+ ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
+
+ ret = PdhSetCounterScaleFactor( counter, -8 );
+ ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
+
+ ret = PdhSetCounterScaleFactor( counter, 7 );
+ ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
+
+ ret = PdhSetCounterScaleFactor( counter, 0 );
+ ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
+
+ ret = PdhCloseQuery( query );
+ ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
+}
+
START_TEST(pdh)
{
test_open_close_query();
test_add_remove_counter();
+ test_PdhGetFormattedCounterValue();
+ test_PdhSetCounterScaleFactor();
}
More information about the wine-cvs
mailing list