summaryrefslogtreecommitdiffhomepage
path: root/setupapi/setupapi_windows_test.go
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-04 15:21:19 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-05 12:59:42 +0100
commitc15cbefc1283ce630d35573856fed2bf71eb0292 (patch)
treefa1b6181aee92f78a6537ac10269484f5c84b6d5 /setupapi/setupapi_windows_test.go
parentdd998ca86ac47869e2ff577b63b961e470a88c9b (diff)
Reorder data-types and functions to match SetupAPI.h
Adding functions with non-consistent order made setupapi package a mess. While we could reorder data-types and functions by alphabet - it would make searching easier - it would put ...Get... and ...Set... functions quite apart. Therefore, the SetupAPI.h order was adopted. Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'setupapi/setupapi_windows_test.go')
-rw-r--r--setupapi/setupapi_windows_test.go192
1 files changed, 95 insertions, 97 deletions
diff --git a/setupapi/setupapi_windows_test.go b/setupapi/setupapi_windows_test.go
index bfe82f6..4e07ed2 100644
--- a/setupapi/setupapi_windows_test.go
+++ b/setupapi/setupapi_windows_test.go
@@ -20,79 +20,6 @@ func init() {
computerName, _ = windows.ComputerName()
}
-func TestSetupDiClassNameFromGuidEx(t *testing.T) {
- deviceClassNetName, err := SetupDiClassNameFromGuidEx(&deviceClassNetGUID, "")
- if err != nil {
- t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
- } else if strings.ToLower(deviceClassNetName) != "net" {
- t.Errorf("SetupDiClassNameFromGuidEx(%x) should return \"Net\"", deviceClassNetGUID)
- }
-
- deviceClassNetName, err = SetupDiClassNameFromGuidEx(&deviceClassNetGUID, computerName)
- if err != nil {
- t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
- } else if strings.ToLower(deviceClassNetName) != "net" {
- t.Errorf("SetupDiClassNameFromGuidEx(%x) should return \"Net\"", deviceClassNetGUID)
- }
-
- _, err = SetupDiClassNameFromGuidEx(nil, "")
- if err == nil {
- t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail")
- } else {
- if errWin, ok := err.(syscall.Errno); !ok || errWin != 1784 /*ERROR_INVALID_USER_BUFFER*/ {
- t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail with ERROR_INVALID_USER_BUFFER")
- }
- }
-}
-
-func TestSetupDiClassGuidsFromNameEx(t *testing.T) {
- ClassGUIDs, err := SetupDiClassGuidsFromNameEx("Net", "")
- if err != nil {
- t.Errorf("Error calling SetupDiClassGuidsFromNameEx: %s", err.Error())
- } else {
- found := false
- for i := range ClassGUIDs {
- if ClassGUIDs[i] == deviceClassNetGUID {
- found = true
- break
- }
- }
- if !found {
- t.Errorf("SetupDiClassGuidsFromNameEx(\"Net\") should return %x", deviceClassNetGUID)
- }
- }
-
- ClassGUIDs, err = SetupDiClassGuidsFromNameEx("foobar-34274a51-a6e6-45f0-80d6-c62be96dd5fe", computerName)
- if err != nil {
- t.Errorf("Error calling SetupDiClassGuidsFromNameEx: %s", err.Error())
- } else if len(ClassGUIDs) != 0 {
- t.Errorf("SetupDiClassGuidsFromNameEx(\"foobar-34274a51-a6e6-45f0-80d6-c62be96dd5fe\") should return an empty GUID set")
- }
-}
-
-func TestSetupDiCreateDeviceInfo(t *testing.T) {
- devInfoList, err := SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, computerName)
- if err != nil {
- t.Errorf("Error calling SetupDiCreateDeviceInfoListEx: %s", err.Error())
- }
- defer devInfoList.Close()
-
- deviceClassNetName, err := SetupDiClassNameFromGuidEx(&deviceClassNetGUID, computerName)
- if err != nil {
- t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
- }
-
- devInfoData, err := SetupDiCreateDeviceInfo(devInfoList, deviceClassNetName, &deviceClassNetGUID, "This is a test device", 0, DICD_GENERATE_ID)
- if err != nil {
- // Access denied is expected, as the SetupDiCreateDeviceInfo() require elevation to succeed.
- if errWin, ok := err.(syscall.Errno); !ok || errWin != windows.ERROR_ACCESS_DENIED {
- t.Errorf("Error calling SetupDiCreateDeviceInfo: %s", err.Error())
- }
- } else if devInfoData.ClassGUID != deviceClassNetGUID {
- t.Error("SetupDiCreateDeviceInfo returned different class GUID")
- }
-}
-
func TestSetupDiCreateDeviceInfoListEx(t *testing.T) {
devInfoList, err := SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, "")
if err == nil {
@@ -116,26 +43,7 @@ func TestSetupDiCreateDeviceInfoListEx(t *testing.T) {
}
}
-func TestSetupDiGetClassDevsEx(t *testing.T) {
- devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "PCI", 0, DIGCF_PRESENT, DevInfo(0), computerName)
- if err == nil {
- devInfoList.Close()
- } else {
- t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
- }
-
- devInfoList, err = SetupDiGetClassDevsEx(nil, "", 0, DIGCF_PRESENT, DevInfo(0), "")
- if err == nil {
- devInfoList.Close()
- t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail")
- } else {
- if errWin, ok := err.(syscall.Errno); !ok || errWin != 87 /*ERROR_INVALID_PARAMETER*/ {
- t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail with ERROR_INVALID_PARAMETER")
- }
- }
-}
-
-func TestSetupDiGetDeviceInfoListDetailLocal(t *testing.T) {
+func TestSetupDiGetDeviceInfoListDetail(t *testing.T) {
devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "")
if err != nil {
t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
@@ -158,16 +66,14 @@ func TestSetupDiGetDeviceInfoListDetailLocal(t *testing.T) {
t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine name")
}
}
-}
-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)
if err != nil {
t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
}
defer devInfoList.Close()
- data, err := SetupDiGetDeviceInfoListDetail(devInfoList)
+ data, err = SetupDiGetDeviceInfoListDetail(devInfoList)
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
} else {
@@ -185,6 +91,29 @@ func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) {
}
}
+func TestSetupDiCreateDeviceInfo(t *testing.T) {
+ devInfoList, err := SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, computerName)
+ if err != nil {
+ t.Errorf("Error calling SetupDiCreateDeviceInfoListEx: %s", err.Error())
+ }
+ defer devInfoList.Close()
+
+ deviceClassNetName, err := SetupDiClassNameFromGuidEx(&deviceClassNetGUID, computerName)
+ if err != nil {
+ t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
+ }
+
+ devInfoData, err := SetupDiCreateDeviceInfo(devInfoList, deviceClassNetName, &deviceClassNetGUID, "This is a test device", 0, DICD_GENERATE_ID)
+ if err != nil {
+ // Access denied is expected, as the SetupDiCreateDeviceInfo() require elevation to succeed.
+ if errWin, ok := err.(syscall.Errno); !ok || errWin != windows.ERROR_ACCESS_DENIED {
+ t.Errorf("Error calling SetupDiCreateDeviceInfo: %s", err.Error())
+ }
+ } else if devInfoData.ClassGUID != deviceClassNetGUID {
+ t.Error("SetupDiCreateDeviceInfo returned different class GUID")
+ }
+}
+
func TestSetupDiEnumDeviceInfo(t *testing.T) {
devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "")
if err != nil {
@@ -207,6 +136,25 @@ func TestSetupDiEnumDeviceInfo(t *testing.T) {
}
}
+func TestSetupDiGetClassDevsEx(t *testing.T) {
+ devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "PCI", 0, DIGCF_PRESENT, DevInfo(0), computerName)
+ if err == nil {
+ devInfoList.Close()
+ } else {
+ t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
+ }
+
+ devInfoList, err = SetupDiGetClassDevsEx(nil, "", 0, DIGCF_PRESENT, DevInfo(0), "")
+ if err == nil {
+ devInfoList.Close()
+ t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail")
+ } else {
+ if errWin, ok := err.(syscall.Errno); !ok || errWin != 87 /*ERROR_INVALID_PARAMETER*/ {
+ t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail with ERROR_INVALID_PARAMETER")
+ }
+ }
+}
+
func TestSetupDiOpenDevRegKey(t *testing.T) {
devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "")
if err != nil {
@@ -253,3 +201,53 @@ func TestSetupDiGetDeviceInstallParams(t *testing.T) {
}
}
}
+
+func TestSetupDiClassNameFromGuidEx(t *testing.T) {
+ deviceClassNetName, err := SetupDiClassNameFromGuidEx(&deviceClassNetGUID, "")
+ if err != nil {
+ t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
+ } else if strings.ToLower(deviceClassNetName) != "net" {
+ t.Errorf("SetupDiClassNameFromGuidEx(%x) should return \"Net\"", deviceClassNetGUID)
+ }
+
+ deviceClassNetName, err = SetupDiClassNameFromGuidEx(&deviceClassNetGUID, computerName)
+ if err != nil {
+ t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
+ } else if strings.ToLower(deviceClassNetName) != "net" {
+ t.Errorf("SetupDiClassNameFromGuidEx(%x) should return \"Net\"", deviceClassNetGUID)
+ }
+
+ _, err = SetupDiClassNameFromGuidEx(nil, "")
+ if err == nil {
+ t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail")
+ } else {
+ if errWin, ok := err.(syscall.Errno); !ok || errWin != 1784 /*ERROR_INVALID_USER_BUFFER*/ {
+ t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail with ERROR_INVALID_USER_BUFFER")
+ }
+ }
+}
+
+func TestSetupDiClassGuidsFromNameEx(t *testing.T) {
+ ClassGUIDs, err := SetupDiClassGuidsFromNameEx("Net", "")
+ if err != nil {
+ t.Errorf("Error calling SetupDiClassGuidsFromNameEx: %s", err.Error())
+ } else {
+ found := false
+ for i := range ClassGUIDs {
+ if ClassGUIDs[i] == deviceClassNetGUID {
+ found = true
+ break
+ }
+ }
+ if !found {
+ t.Errorf("SetupDiClassGuidsFromNameEx(\"Net\") should return %x", deviceClassNetGUID)
+ }
+ }
+
+ ClassGUIDs, err = SetupDiClassGuidsFromNameEx("foobar-34274a51-a6e6-45f0-80d6-c62be96dd5fe", computerName)
+ if err != nil {
+ t.Errorf("Error calling SetupDiClassGuidsFromNameEx: %s", err.Error())
+ } else if len(ClassGUIDs) != 0 {
+ t.Errorf("SetupDiClassGuidsFromNameEx(\"foobar-34274a51-a6e6-45f0-80d6-c62be96dd5fe\") should return an empty GUID set")
+ }
+}