Stop accessing SetupDiGetDeviceInfoListDetail() output on error

The data returned by SetupDiGetDeviceInfoListDetail() is nil on error
which will cause the test to crash should the function fail.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2019-02-04 11:45:37 +01:00 committed by Jason A. Donenfeld
parent e821cdabd2
commit 963be8e993

View file

@ -99,8 +99,7 @@ func TestSetupDiGetDeviceInfoListDetailLocal(t *testing.T) {
data, err := SetupDiGetDeviceInfoListDetail(devInfoList) data, err := SetupDiGetDeviceInfoListDetail(devInfoList)
if err != nil { if err != nil {
t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error()) t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
} } else {
if data.ClassGUID != deviceClassNetGUID { if data.ClassGUID != deviceClassNetGUID {
t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID") t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID")
} }
@ -113,6 +112,7 @@ func TestSetupDiGetDeviceInfoListDetailLocal(t *testing.T) {
t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine name") t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine name")
} }
} }
}
func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) { func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) {
devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), computerName) devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), computerName)
@ -124,8 +124,7 @@ func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) {
data, err := SetupDiGetDeviceInfoListDetail(devInfoList) data, err := SetupDiGetDeviceInfoListDetail(devInfoList)
if err != nil { if err != nil {
t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error()) t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
} } else {
if data.ClassGUID != deviceClassNetGUID { if data.ClassGUID != deviceClassNetGUID {
t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID") t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID")
} }
@ -138,6 +137,7 @@ func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) {
t.Error("SetupDiGetDeviceInfoListDetail returned different remote machine name") t.Error("SetupDiGetDeviceInfoListDetail returned different remote machine name")
} }
} }
}
func TestSetupDiEnumDeviceInfo(t *testing.T) { func TestSetupDiEnumDeviceInfo(t *testing.T) {
devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "") devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "")