diff options
author | Simon Rozman <simon@rozman.si> | 2019-02-05 11:44:47 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-05 12:59:42 +0100 |
commit | 99a3b628e9f2405a4acaa84c7a8fb74cfa6bbe6e (patch) | |
tree | e92139a9bdc5d0d41b72e09e5a69628203cc9b90 /setupapi/setupapi_windows_test.go | |
parent | e7ffce0d21ee87f36a86d854fed5a6d18d9fa4bf (diff) |
setupapi: Add support for SetupDi(Get|Set)DeviceRegistryProperty()
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'setupapi/setupapi_windows_test.go')
-rw-r--r-- | setupapi/setupapi_windows_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/setupapi/setupapi_windows_test.go b/setupapi/setupapi_windows_test.go index 81a0a09..93ae42a 100644 --- a/setupapi/setupapi_windows_test.go +++ b/setupapi/setupapi_windows_test.go @@ -179,6 +179,56 @@ func TestSetupDiOpenDevRegKey(t *testing.T) { } } +func TestSetupDiGetDeviceRegistryProperty(t *testing.T) { + devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "") + if err != nil { + t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error()) + } + defer devInfoList.Close() + + for i := 0; true; i++ { + data, err := devInfoList.EnumDeviceInfo(i) + if err != nil { + if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ { + break + } + continue + } + + val, err := devInfoList.GetDeviceRegistryProperty(data, SPDRP_CLASS) + if err != nil { + t.Errorf("Error calling SetupDiGetDeviceRegistryProperty(SPDRP_CLASS): %s", err.Error()) + } else if class, ok := val.(string); !ok || strings.ToLower(class) != "net" { + t.Errorf("SetupDiGetDeviceRegistryProperty(SPDRP_CLASS) should return \"Net\"") + } + + val, err = devInfoList.GetDeviceRegistryProperty(data, SPDRP_CLASSGUID) + if err != nil { + t.Errorf("Error calling SetupDiGetDeviceRegistryProperty(SPDRP_CLASSGUID): %s", err.Error()) + } /* TODO: Parse GUID string: else if classGUID, ok := val.(string); !ok || parseGUID(classGUID) != deviceClassNetGUID { + t.Errorf("SetupDiGetDeviceRegistryProperty(SPDRP_CLASSGUID) should return %x", deviceClassNetGUID) + }*/ + + val, err = devInfoList.GetDeviceRegistryProperty(data, SPDRP_COMPATIBLEIDS) + if err != nil { + // Some devices have no SPDRP_COMPATIBLEIDS. + if errWin, ok := err.(syscall.Errno); !ok || errWin != 13 /*windows.ERROR_INVALID_DATA*/ { + t.Errorf("Error calling SetupDiGetDeviceRegistryProperty(SPDRP_COMPATIBLEIDS): %s", err.Error()) + } + } + + val, err = devInfoList.GetDeviceRegistryProperty(data, SPDRP_CONFIGFLAGS) + if err != nil { + t.Errorf("Error calling SetupDiGetDeviceRegistryProperty(SPDRP_CONFIGFLAGS): %s", err.Error()) + } + + val, err = devInfoList.GetDeviceRegistryProperty(data, SPDRP_DEVICE_POWER_DATA) + if err != nil { + t.Errorf("Error calling SetupDiGetDeviceRegistryProperty(SPDRP_DEVICE_POWER_DATA): %s", err.Error()) + } + } +} + func TestSetupDiGetDeviceInstallParams(t *testing.T) { devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "") if err != nil { |