summaryrefslogtreecommitdiffhomepage
path: root/setupapi/setupapi_windows_test.go
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-04 15:50:59 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-05 12:59:42 +0100
commit35f72239ac428c41e9e3bba9f06c67d0eff3de8a (patch)
tree99b5230cbd1b0834486cff31a9e8f3eda4190264 /setupapi/setupapi_windows_test.go
parentc15cbefc1283ce630d35573856fed2bf71eb0292 (diff)
Add support for setupapi.SetupDi(Get|Set)SelectedDevice()
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'setupapi/setupapi_windows_test.go')
-rw-r--r--setupapi/setupapi_windows_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/setupapi/setupapi_windows_test.go b/setupapi/setupapi_windows_test.go
index 4e07ed2..8d5453f 100644
--- a/setupapi/setupapi_windows_test.go
+++ b/setupapi/setupapi_windows_test.go
@@ -251,3 +251,42 @@ func TestSetupDiClassGuidsFromNameEx(t *testing.T) {
t.Errorf("SetupDiClassGuidsFromNameEx(\"foobar-34274a51-a6e6-45f0-80d6-c62be96dd5fe\") should return an empty GUID set")
}
}
+
+func TestSetupDiGetSelectedDevice(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 := SetupDiEnumDeviceInfo(devInfoList, i)
+ if err != nil {
+ if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ {
+ break
+ }
+ continue
+ }
+
+ err = SetupDiSetSelectedDevice(devInfoList, data)
+ if err != nil {
+ t.Errorf("Error calling SetupDiSetSelectedDevice: %s", err.Error())
+ }
+
+ data2, err := SetupDiGetSelectedDevice(devInfoList)
+ if err != nil {
+ t.Errorf("Error calling SetupDiGetSelectedDevice: %s", err.Error())
+ } else if *data != *data2 {
+ t.Error("SetupDiGetSelectedDevice returned different data than was set by SetupDiSetSelectedDevice")
+ }
+ }
+
+ err = SetupDiSetSelectedDevice(devInfoList, nil)
+ if err == nil {
+ t.Errorf("SetupDiSetSelectedDevice(nil) should fail")
+ } else {
+ if errWin, ok := err.(syscall.Errno); !ok || errWin != 87 /*ERROR_INVALID_PARAMETER*/ {
+ t.Errorf("SetupDiSetSelectedDevice(nil) should fail with ERROR_INVALID_USER_BUFFER")
+ }
+ }
+}