diff options
Diffstat (limited to 'setupapi/setupapi_windows_test.go')
-rw-r--r-- | setupapi/setupapi_windows_test.go | 48 |
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") + } + } +} |