-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvisa_test.go
134 lines (131 loc) · 3.31 KB
/
visa_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
// Copyright (c) 2015-2024 The usbtmc developers. All rights reserved.
// Project site: https://github.com/gotmc/usbtmc
// 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 usbtmc
import (
"errors"
"testing"
)
func TestParsingVisaResourceString(t *testing.T) {
testCases := []struct {
resourceString string
interfaceType string
boardIndex int
manufacturerID int
modelCode int
serialNumber string
interfaceIndex int
resourceClass string
isError bool
errorString error
}{
{
"usb0::2391::1031::MY44123456::INSTR",
"USB", 0, 2391, 1031, "MY44123456", 0, "INSTR",
false, errors.New(""),
},
{
"USB::1234::5678::INSTR",
"USB", 0, 1234, 5678, "", 0, "INSTR",
false, errors.New(""),
},
{
"USB::1234::5678::SERIAL::INSTR",
"USB", 0, 1234, 5678, "SERIAL", 0, "INSTR",
false, errors.New(""),
},
{
"USB0::0x1234::0x5678::INSTR",
"USB", 0, 4660, 22136, "", 0, "INSTR",
false, errors.New(""),
},
{
"USB0::0x0957::0x2007::MY57004760::0::INSTR",
"USB", 0, 2391, 8199, "MY57004760", 0, "INSTR",
false, errors.New(""),
},
{
"UBS::1234::5678::INSTR",
"", 0, 0, 0, "", 0, "",
true, errors.New("visa: interface type was not usb"),
},
{
"USB::1234::5678::INTSR",
"USB", 0, 1234, 5678, "", 0, "",
true, errors.New("visa: resource class was not instr"),
},
}
for _, testCase := range testCases {
resource, err := NewVisaResource(testCase.resourceString)
if resource.interfaceType != testCase.interfaceType {
t.Errorf(
"interfaceType == %s, want %s for resource %s",
resource.interfaceType,
testCase.interfaceType,
testCase.resourceString,
)
}
if resource.boardIndex != testCase.boardIndex {
t.Errorf(
"boardIndex == %d, want %d for resource %s",
resource.boardIndex,
testCase.boardIndex,
testCase.resourceString,
)
}
if resource.manufacturerID != testCase.manufacturerID {
t.Errorf(
"manufacturerID == %d, want %d for resource %s",
resource.manufacturerID,
testCase.manufacturerID,
testCase.resourceString,
)
}
if resource.modelCode != testCase.modelCode {
t.Errorf(
"modelCode == %d, want %d for resource %s",
resource.modelCode,
testCase.modelCode,
testCase.resourceString,
)
}
if resource.serialNumber != testCase.serialNumber {
t.Errorf(
"serialNumber == %s, want %s for resource %s",
resource.serialNumber,
testCase.serialNumber,
testCase.resourceString,
)
}
if resource.interfaceIndex != testCase.interfaceIndex {
t.Errorf(
"interfaceIndex == %d, want %d for resource %s",
resource.interfaceIndex,
testCase.interfaceIndex,
testCase.resourceString,
)
}
if resource.resourceClass != testCase.resourceClass {
t.Errorf(
"resourceClass == %s, want %s for resource %s",
resource.resourceClass,
testCase.resourceClass,
testCase.resourceString,
)
}
if err != nil && testCase.isError {
if err.Error() != testCase.errorString.Error() {
t.Errorf(
"err == %s, want %s for resource %s",
err,
testCase.errorString,
testCase.resourceString,
)
}
}
if err != nil && !testCase.isError {
t.Errorf("Unhandled error: %q for resource %s", err, testCase.resourceString)
}
}
}