-
Notifications
You must be signed in to change notification settings - Fork 0
/
descriptors_test.go
158 lines (150 loc) · 4.75 KB
/
descriptors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Copyright (c) 2015-2023 The libusb developers. All rights reserved.
// Project site: https://github.com/gotmc/libusb
// Use of this source code is governed by a MIT-style license that
// can be found in the LICENSE.txt file for the project.
package libusb
import (
"testing"
)
const (
failCheck = `✗` // UTF-8 u2717
passCheck = `✓` // UTF-8 u2713
)
func TestBcdType(t *testing.T) {
testCases := []struct {
bcdValue uint16
bcdString string
bcdDecimal float64
}{
{0x0300, "0x0300 (3.00)", 3.0},
{0x0200, "0x0200 (2.00)", 2.0},
{0x0110, "0x0110 (1.10)", 1.1},
{0x0100, "0x0100 (1.00)", 1.0},
}
t.Log("Given the need to test the bcd type")
{
for _, testCase := range testCases {
b := bcd(testCase.bcdValue)
t.Logf("\tWhen getting the string for bcd %#04x", testCase.bcdValue)
computedString := b.String()
if computedString != testCase.bcdString {
t.Errorf("\t%v Should have computed %s but got %s", failCheck, testCase.bcdString, computedString)
} else {
t.Logf("\t%v Should compute %s", passCheck, computedString)
}
}
}
}
func TestClassCodeStringMethod(t *testing.T) {
testCases := []struct {
class classCode
expected string
}{
{perInterface, "Each interface specifies its own class information and all interfaces operate independently."},
{audio, "Audio class."},
{comm, "Communications class."},
{hid, "Human Interface Device class."},
{physical, "Physical."},
{printer, "Printer class."},
{image, "Image class."},
{massStorage, "Mass storage class."},
{hub, "Hub class."},
{data, "Data class."},
{smartCard, "Smart Card."},
{contentSecurity, "Content Security."},
{video, "Video."},
{personalHealthcare, "Personal Healthcare."},
{diagnosticDevice, "Diagnostic Device."},
{wireless, "Wireless class."},
{application, "Application class."},
{vendorSpec, "Class is vendor-specific."},
}
t.Log("Given the need to test the classCode.String() method")
{
for _, testCase := range testCases {
t.Logf("\tWhen getting classCode %d's string", testCase.class)
computed := testCase.class.String()
if computed != testCase.expected {
t.Errorf("\t%v Should have yielded: %s, but got %s", failCheck, testCase.expected, computed)
} else {
t.Logf("\t%v Should yield: %s", passCheck, computed)
}
}
}
}
func TestDescriptortypeStringMethod(t *testing.T) {
testCases := []struct {
desc descriptorType
expected string
}{
{descDevice, "Device descriptor."},
{descConfig, "Configuration descriptor."},
{descString, "String descriptor."},
{descInterface, "Interface descriptor."},
{descEndpoint, "Endpoint descriptor."},
{descBos, "BOS descriptor."},
{descDeviceCapability, "Device Capability descriptor."},
{descHid, "HID descriptor."},
{descReport, "HID report descriptor."},
{descPhysical, "Physical descriptor."},
{descHub, "Hub descriptor."},
{descSuperspeedHub, "SuperSpeed Hub descriptor."},
{descEndpointCompanion, "SuperSpeed Endpoint Companion descriptor."},
}
t.Log("Given the need to test the descriptorType.String() method")
{
for _, testCase := range testCases {
t.Logf("\tWhen getting descriptorType %d's string", testCase.desc)
computed := testCase.desc.String()
if computed != testCase.expected {
t.Errorf("\t%v Should have yielded: %s, but got %s", failCheck, testCase.expected, computed)
} else {
t.Logf("\t%v Should yield: %s", passCheck, computed)
}
}
}
}
func TestEndpointDirectionStringMethod(t *testing.T) {
testCases := []struct {
end EndpointDirection
expected string
}{
{endpointOut, "Out: host-to-device."},
{endpointIn, "In: device-to-host."},
}
t.Log("Given the need to test the endpointDirection.String() method")
{
for _, testCase := range testCases {
t.Logf("\tWhen getting endpointDirection %d's string", testCase.end)
computed := testCase.end.String()
if computed != testCase.expected {
t.Errorf("\t%v Should have yielded: %s, but got %s", failCheck, testCase.expected, computed)
} else {
t.Logf("\t%v Should yield: %s", passCheck, computed)
}
}
}
}
func TestTransferTypeStringMethod(t *testing.T) {
testCases := []struct {
transfer TransferType
expected string
}{
{ControlTransfer, "Control endpoint."},
{IsochronousTransfer, "Isochronous endpoint."},
{BulkTransfer, "Bulk endpoint."},
{InterruptTransfer, "Interrupt endpoint."},
}
t.Log("Given the need to test the endpointDirection.String() method")
{
for _, testCase := range testCases {
t.Logf("\tWhen getting endpointDirection %d's string", testCase.transfer)
computed := testCase.transfer.String()
if computed != testCase.expected {
t.Errorf("\t%v Should have yielded: %s, but got %s", failCheck, testCase.expected, computed)
} else {
t.Logf("\t%v Should yield: %s", passCheck, computed)
}
}
}
}