From: Vibhav Pant vibhavp@gmail.com
--- dlls/cfgmgr32/tests/cfgmgr32.c | 206 +++++++++++++++++++++++---------- 1 file changed, 142 insertions(+), 64 deletions(-)
diff --git a/dlls/cfgmgr32/tests/cfgmgr32.c b/dlls/cfgmgr32/tests/cfgmgr32.c index 02741d0d963..8156a137173 100644 --- a/dlls/cfgmgr32/tests/cfgmgr32.c +++ b/dlls/cfgmgr32/tests/cfgmgr32.c @@ -500,14 +500,115 @@ static void test_CM_Get_Device_Interface_List(void) ok(ret == CR_NO_SUCH_DEVICE_INTERFACE || broken(ret == CR_INVALID_DATA) /* w7 */, "got %#lx.\n", ret); }
+struct test_property +{ + DEVPROPKEY key; + DEVPROPTYPE type; +}; + +DEFINE_DEVPROPKEY(DEVPKEY_dummy, 0xdeadbeef, 0xdead, 0xbeef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 1); + +static void test_dev_object_iface_props( int line, const DEV_OBJECT *obj, const struct test_property *exp_props, + DWORD props_len ) +{ + DWORD i, rem_props = props_len, buf_len = 0; + const DEV_OBJECT *objects = NULL; + DEVPROPCOMPKEY prop_key = {0}; + HDEVINFO set; + HRESULT hr; + + set = SetupDiCreateDeviceInfoListExW( NULL, NULL, NULL, NULL ); + ok_( __FILE__, line )( set != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed: %lu\n", + GetLastError() ); + todo_wine ok_( __FILE__, line )( obj->cPropertyCount >= props_len, "got cPropertyCount %lu, should be >= %lu\n", + obj->cPropertyCount, props_len ); + for (i = 0; i < obj->cPropertyCount && rem_props; i++) + { + const DEVPROPERTY *property = &obj->pProperties[i]; + ULONG j; + + for (j = 0; j < props_len; j++) + { + if (IsEqualDevPropKey( property->CompKey.Key, exp_props[j].key )) + { + SP_INTERFACE_DEVICE_DATA iface_data = {0}; + DEVPROPTYPE type = DEVPROP_TYPE_EMPTY; + ULONG size = 0; + CONFIGRET ret; + BYTE *buf; + + winetest_push_context( "exp_props[%lu]", j ); + rem_props--; + ok_( __FILE__, line )( property->Type == exp_props[j].type, "got type %#lx\n", property->Type ); + /* Ensure the value matches the value retrieved via SetupDiGetDeviceInterfacePropertyW */ + buf = calloc( property->BufferSize, 1 ); + iface_data.cbSize = sizeof( iface_data ); + ret = SetupDiOpenDeviceInterfaceW( set, obj->pszObjectId, 0, &iface_data ); + ok_( __FILE__, line )( ret, "SetupDiOpenDeviceInterfaceW failed: %lu\n", GetLastError() ); + ret = SetupDiGetDeviceInterfacePropertyW( set, &iface_data, &property->CompKey.Key, &type, buf, + property->BufferSize, &size, 0 ); + ok_( __FILE__, line )( ret, "SetupDiGetDeviceInterfacePropertyW failed: %lu\n", GetLastError() ); + SetupDiDeleteDeviceInterfaceData( set, &iface_data ); + + ok_( __FILE__, line )( size == property->BufferSize, "got size %lu\n", size ); + ok_( __FILE__, line )( type == property->Type, "got type %#lx\n", type ); + if (size == property->BufferSize) + { + switch (type) + { + case DEVPROP_TYPE_STRING: + ok_( __FILE__, line )( !wcsicmp( (WCHAR *)buf, (WCHAR *)property->Buffer ), + "got instance id %s != %s\n", debugstr_w( (WCHAR *)buf ), + debugstr_w( (WCHAR *)property->Buffer ) ); + break; + default: + ok_( __FILE__, line )( !memcmp( buf, property->Buffer, size ), + "got mistmatching property values\n" ); + break; + } + } + free( buf ); + winetest_pop_context(); + break; + } + } + } + todo_wine ok_( __FILE__, line )( rem_props == 0, "got rem %lu != 0\n", rem_props ); + SetupDiDestroyDeviceInfoList( set ); + + /* Get all objects, but only with a single requested property. */ + prop_key.Key = exp_props[0].key; + prop_key.LocaleName = NULL; + prop_key.Store = DEVPROP_STORE_SYSTEM; + hr = DevGetObjects( DevObjectTypeDeviceInterface, 0, 1, &prop_key, 0, NULL, &buf_len, &objects ); + ok_( __FILE__, line )( hr == S_OK, "got hr %#lx\n", hr ); + ok_( __FILE__, line )( buf_len, "got buf_len %lu\n", buf_len ); + ok_( __FILE__, line )( !!objects, "got objects %p\n", objects ); + + for (i = 0; i < buf_len; i++) + { + const DEV_OBJECT *obj = &objects[i]; + + winetest_push_context( "objects[%lu]", i ); + todo_wine ok_( __FILE__, line )( obj->cPropertyCount == 1, "got cPropertyCount %lu != 1\n", + obj->cPropertyCount ); + todo_wine ok_( __FILE__, line )( !!obj->pProperties, "got pProperties %p\n", obj->pProperties ); + if (obj->pProperties) + ok_( __FILE__, line )( IsEqualDevPropKey( obj->pProperties[0].CompKey.Key, exp_props[0].key ), + "got property {%s, %#lx} != {%s, %#lx}\n", + debugstr_guid( &obj->pProperties[0].CompKey.Key.fmtid ), + obj->pProperties[0].CompKey.Key.pid, debugstr_guid( &exp_props[0].key.fmtid ), + exp_props[0].key.pid ); + winetest_pop_context(); + } + DevFreeObjects( buf_len, objects ); +} + static void test_DevGetObjects( void ) { struct { DEV_OBJECT_TYPE object_type; - struct { - DEVPROPKEY key; - DEVPROPTYPE type; - } exp_props[3]; + struct test_property exp_props[3]; ULONG props_len; } test_cases[] = { { @@ -530,7 +631,7 @@ static void test_DevGetObjects( void ) }, }; const DEV_OBJECT *objects = NULL; - HDEVINFO set; + DEVPROPCOMPKEY prop_key = {0}; HRESULT hr; ULONG i, len = 0;
@@ -555,6 +656,13 @@ static void test_DevGetObjects( void ) hr = DevGetObjects( DevObjectTypeDeviceInterface, 0xdeadbeef, 0, NULL, 0, (void *)0xdeadbeef, &len, &objects ); ok( hr == E_INVALIDARG, "got hr %#lx\n", hr );
+ prop_key.Key = test_cases[0].exp_props[0].key; + prop_key.Store = DEVPROP_STORE_SYSTEM; + prop_key.LocaleName = NULL; + /* DevQueryFlagAllProperties is mutually exlusive with requesting specific properties. */ + hr = DevGetObjects( DevObjectTypeDeviceInterface, DevQueryFlagAllProperties, 1, &prop_key, 0, NULL, &len, &objects ); + todo_wine ok( hr == E_INVALIDARG, "got hr %#lx\n", hr ); + len = 0xdeadbeef; objects = (DEV_OBJECT *)0xdeadbeef; hr = DevGetObjects( DevObjectTypeUnknown, DevQueryFlagNone, 0, NULL, 0, NULL, &len, &objects ); @@ -569,9 +677,6 @@ static void test_DevGetObjects( void ) ok( len == 0, "got len %lu\n", len ); ok( !objects, "got objects %p\n", objects );
- set = SetupDiCreateDeviceInfoListExW( NULL, NULL, NULL, NULL ); - ok( set != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed: %lu\n", GetLastError() ); - for (i = 0; i < ARRAY_SIZE( test_cases ); i++) { const DEV_OBJECT *objects = NULL; @@ -584,71 +689,44 @@ static void test_DevGetObjects( void ) ok( hr == S_OK, "got hr %#lx\n", hr ); for (j = 0; j < len; j++) { - ULONG rem_props = test_cases[i].props_len, k; const DEV_OBJECT *obj = &objects[j];
winetest_push_context( "device %s", debugstr_w( obj->pszObjectId ) ); ok( obj->ObjectType == test_cases[i].object_type, "got ObjectType %d\n", obj->ObjectType ); - todo_wine ok( obj->cPropertyCount >= test_cases[i].props_len, "got cPropertyCount %lu, should be >= %lu\n", - obj->cPropertyCount, test_cases[i].props_len ); - for (k = 0; k < obj->cPropertyCount && rem_props; k++) - { - const DEVPROPERTY *property = &obj->pProperties[k]; - ULONG l; - - for (l = 0; l < test_cases[i].props_len; l++) - { - if (IsEqualDevPropKey( property->CompKey.Key, test_cases[i].exp_props[l].key )) - { - SP_INTERFACE_DEVICE_DATA iface_data = {0}; - DEVPROPTYPE type = DEVPROP_TYPE_EMPTY; - ULONG size = 0; - CONFIGRET ret; - BYTE *buf; - - winetest_push_context( "exp_props[%lu]", l ); - rem_props--; - ok( property->Type == test_cases[i].exp_props[l].type, "got type %#lx\n", property->Type ); - - /* Ensure the value matches the value retrieved via SetupDiGetDeviceInterfacePropertyW */ - buf = calloc( property->BufferSize, 1 ); - iface_data.cbSize = sizeof( iface_data ); - ret = SetupDiOpenDeviceInterfaceW( set, obj->pszObjectId, 0, &iface_data ); - ok( ret, "SetupDiOpenDeviceInterfaceW failed: %lu\n", GetLastError() ); - ret = SetupDiGetDeviceInterfacePropertyW( set, &iface_data, &property->CompKey.Key, &type, buf, - property->BufferSize, &size, 0 ); - ok( ret, "SetupDiGetDeviceInterfacePropertyW failed: %lu\n", GetLastError() ); - SetupDiDeleteDeviceInterfaceData( set, &iface_data ); - - ok( size == property->BufferSize, "got size %lu\n", size ); - ok( type == property->Type, "got type %#lx\n", type ); - if (size == property->BufferSize) - { - switch (type) - { - case DEVPROP_TYPE_STRING: - ok( !wcsicmp( (WCHAR *)buf, (WCHAR *)property->Buffer ), "got instance id %s != %s\n", - debugstr_w( (WCHAR *)buf ), debugstr_w( (WCHAR *)property->Buffer ) ); - break; - default: - ok( !memcmp( buf, property->Buffer, size ), "got mistmatching property values\n" ); - break; - } - } - free( buf ); - winetest_pop_context(); - break; - } - } - } - todo_wine ok( rem_props == 0, "got rem %lu != 0\n", rem_props ); + test_dev_object_iface_props( __LINE__, obj, test_cases[i].exp_props, test_cases[i].props_len ); winetest_pop_context(); } - winetest_pop_context(); DevFreeObjects( len, objects ); + winetest_pop_context(); }
- SetupDiDestroyDeviceInfoList( set ); + /* Non-existent device properties will still have an entry in the returned DEV_OBJECT, albeit with Type set to + * DEVPROP_TYPE_EMPTY. */ + len = 0; + objects = NULL; + prop_key.Key = DEVPKEY_dummy; + hr = DevGetObjects( DevObjectTypeDeviceInterface, 0, 1, &prop_key, 0, NULL, &len, &objects ); + ok( hr == S_OK, "got hr %#lx\n", hr ); + ok( len, "got len %lu\n", len ); + ok( !!objects, "got objects %p\n", objects ); + for (i = 0; i < len; i++) + { + const DEV_OBJECT *obj = &objects[i]; + + winetest_push_context( "objects[%lu]", i ); + todo_wine ok( obj->cPropertyCount == 1, "got cPropertyCount %lu != 1\n", obj->cPropertyCount ); + todo_wine ok( !!obj->pProperties, "got pProperties %p\n", obj->pProperties ); + if (obj->pProperties) + { + ok( IsEqualDevPropKey( obj->pProperties[0].CompKey.Key, DEVPKEY_dummy ), + "got property {%s, %#lx} != {%s, %#lx}\n", debugstr_guid( &obj->pProperties[0].CompKey.Key.fmtid ), + obj->pProperties[0].CompKey.Key.pid, debugstr_guid( &DEVPKEY_dummy.fmtid ), DEVPKEY_dummy.pid ); + ok( obj->pProperties[0].Type == DEVPROP_TYPE_EMPTY, "got Type %#lx != %#x", obj->pProperties[0].Type, + DEVPROP_TYPE_EMPTY ); + } + winetest_pop_context(); + } + DevFreeObjects( len, objects ); }
START_TEST(cfgmgr32)