summaryrefslogtreecommitdiff
path: root/setupapi/setupapi_windows_test.go
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-01 12:17:09 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-05 12:59:42 +0100
commit955d8dfe04fa87d265bb1ccb671db05a323eb86f (patch)
treea85f87d2524c9d2491877be6d57418dc8682f161 /setupapi/setupapi_windows_test.go
parent25e18d01e66f4949ee64651177b2ade7199893c1 (diff)
downloadwireguard-go-955d8dfe04fa87d265bb1ccb671db05a323eb86f.tar.gz
wireguard-go-955d8dfe04fa87d265bb1ccb671db05a323eb86f.zip
Add support for setupapi.SetupDiEnumDeviceInfo()
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'setupapi/setupapi_windows_test.go')
-rw-r--r--setupapi/setupapi_windows_test.go48
1 files changed, 35 insertions, 13 deletions
diff --git a/setupapi/setupapi_windows_test.go b/setupapi/setupapi_windows_test.go
index 017fc3d..8aa7221 100644
--- a/setupapi/setupapi_windows_test.go
+++ b/setupapi/setupapi_windows_test.go
@@ -12,7 +12,7 @@ import (
"golang.org/x/sys/windows"
)
-var guidDeviceClassNet = windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}}
+var deviceClassNetGUID = windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}}
var computerName string
func init() {
@@ -20,16 +20,16 @@ func init() {
}
func TestSetupDiGetClassDevsEx(t *testing.T) {
- dev_info_list, err := SetupDiGetClassDevsEx(&guidDeviceClassNet, "PCI", 0, DIGCF_PRESENT, DevInfo(0), computerName)
+ devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "PCI", 0, DIGCF_PRESENT, DevInfo(0), computerName)
if err == nil {
- dev_info_list.Close()
+ devInfoList.Close()
} else {
t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
}
- dev_info_list, err = SetupDiGetClassDevsEx(nil, "", 0, DIGCF_PRESENT, DevInfo(0), "")
+ devInfoList, err = SetupDiGetClassDevsEx(nil, "", 0, DIGCF_PRESENT, DevInfo(0), "")
if err == nil {
- dev_info_list.Close()
+ devInfoList.Close()
t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail")
} else {
if errWin, ok := err.(syscall.Errno); !ok || errWin != 87 /*ERROR_INVALID_PARAMETER*/ {
@@ -39,18 +39,18 @@ func TestSetupDiGetClassDevsEx(t *testing.T) {
}
func TestSetupDiGetDeviceInfoListDetailLocal(t *testing.T) {
- dev_info_list, err := SetupDiGetClassDevsEx(&guidDeviceClassNet, "", 0, DIGCF_PRESENT, DevInfo(0), "")
+ devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "")
if err != nil {
t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
}
- defer SetupDiDestroyDeviceInfoList(dev_info_list)
+ defer SetupDiDestroyDeviceInfoList(devInfoList)
- data, err := SetupDiGetDeviceInfoListDetail(dev_info_list)
+ data, err := SetupDiGetDeviceInfoListDetail(devInfoList)
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
}
- if data.ClassGUID != guidDeviceClassNet {
+ if data.ClassGUID != deviceClassNetGUID {
t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID")
}
@@ -64,18 +64,18 @@ func TestSetupDiGetDeviceInfoListDetailLocal(t *testing.T) {
}
func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) {
- dev_info_list, err := SetupDiGetClassDevsEx(&guidDeviceClassNet, "", 0, DIGCF_PRESENT, DevInfo(0), computerName)
+ devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), computerName)
if err != nil {
t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
}
- defer SetupDiDestroyDeviceInfoList(dev_info_list)
+ defer SetupDiDestroyDeviceInfoList(devInfoList)
- data, err := SetupDiGetDeviceInfoListDetail(dev_info_list)
+ data, err := SetupDiGetDeviceInfoListDetail(devInfoList)
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
}
- if data.ClassGUID != guidDeviceClassNet {
+ if data.ClassGUID != deviceClassNetGUID {
t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID")
}
@@ -87,3 +87,25 @@ func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) {
t.Error("SetupDiGetDeviceInfoListDetail returned different remote machine name")
}
}
+
+func TestSetupDiEnumDeviceInfo(t *testing.T) {
+ devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "")
+ if err != nil {
+ t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
+ }
+ defer SetupDiDestroyDeviceInfoList(devInfoList)
+
+ 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
+ }
+
+ if data.ClassGUID != deviceClassNetGUID {
+ t.Error("SetupDiEnumDeviceInfo returned different class GUID")
+ }
+ }
+}