summaryrefslogtreecommitdiff
path: root/setupapi/setupapi_windows_test.go
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-01 11:39:57 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-05 12:59:42 +0100
commit45959c116aae4c81e0be7bec8ab21d2f715caddf (patch)
treed2fa7c436463ca1366a7330924055c3483456b82 /setupapi/setupapi_windows_test.go
parentd41bc015ccc06feedd21c0a87b0a44a02b74d530 (diff)
downloadwireguard-go-45959c116aae4c81e0be7bec8ab21d2f715caddf.tar.gz
wireguard-go-45959c116aae4c81e0be7bec8ab21d2f715caddf.zip
Add support for setupapi.SetupDiGetDeviceInfoListDetail()
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'setupapi/setupapi_windows_test.go')
-rw-r--r--setupapi/setupapi_windows_test.go64
1 files changed, 57 insertions, 7 deletions
diff --git a/setupapi/setupapi_windows_test.go b/setupapi/setupapi_windows_test.go
index 709dd18..017fc3d 100644
--- a/setupapi/setupapi_windows_test.go
+++ b/setupapi/setupapi_windows_test.go
@@ -12,15 +12,15 @@ import (
"golang.org/x/sys/windows"
)
-func TestSetupDiGetClassDevsEx(t *testing.T) {
- guidDeviceClassNet := windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}}
+var guidDeviceClassNet = windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}}
+var computerName string
- compName, err := windows.ComputerName()
- if err != nil {
- t.Errorf("Error getting computer name: %s", err.Error())
- }
+func init() {
+ computerName, _ = windows.ComputerName()
+}
- dev_info_list, err := SetupDiGetClassDevsEx(&guidDeviceClassNet, "PCI", 0, DIGCF_PRESENT, DevInfo(0), compName)
+func TestSetupDiGetClassDevsEx(t *testing.T) {
+ dev_info_list, err := SetupDiGetClassDevsEx(&guidDeviceClassNet, "PCI", 0, DIGCF_PRESENT, DevInfo(0), computerName)
if err == nil {
dev_info_list.Close()
} else {
@@ -37,3 +37,53 @@ func TestSetupDiGetClassDevsEx(t *testing.T) {
}
}
}
+
+func TestSetupDiGetDeviceInfoListDetailLocal(t *testing.T) {
+ dev_info_list, err := SetupDiGetClassDevsEx(&guidDeviceClassNet, "", 0, DIGCF_PRESENT, DevInfo(0), "")
+ if err != nil {
+ t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
+ }
+ defer SetupDiDestroyDeviceInfoList(dev_info_list)
+
+ data, err := SetupDiGetDeviceInfoListDetail(dev_info_list)
+ if err != nil {
+ t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
+ }
+
+ if data.ClassGUID != guidDeviceClassNet {
+ t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID")
+ }
+
+ if data.RemoteMachineHandle != windows.Handle(0) {
+ t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine handle")
+ }
+
+ if data.RemoteMachineName != "" {
+ t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine name")
+ }
+}
+
+func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) {
+ dev_info_list, err := SetupDiGetClassDevsEx(&guidDeviceClassNet, "", 0, DIGCF_PRESENT, DevInfo(0), computerName)
+ if err != nil {
+ t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
+ }
+ defer SetupDiDestroyDeviceInfoList(dev_info_list)
+
+ data, err := SetupDiGetDeviceInfoListDetail(dev_info_list)
+ if err != nil {
+ t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
+ }
+
+ if data.ClassGUID != guidDeviceClassNet {
+ t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID")
+ }
+
+ if data.RemoteMachineHandle == windows.Handle(0) {
+ t.Error("SetupDiGetDeviceInfoListDetail returned NULL remote machine handle")
+ }
+
+ if data.RemoteMachineName != computerName {
+ t.Error("SetupDiGetDeviceInfoListDetail returned different remote machine name")
+ }
+}