aboutsummaryrefslogtreecommitdiffstats
path: root/setupapi/setupapi_windows_test.go
diff options
context:
space:
mode:
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")
+ }
+}