forked from dh1tw/goHamlib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoHamlib_test.go
337 lines (294 loc) · 8.34 KB
/
goHamlib_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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
package goHamlib_test
import (
"testing"
"github.com/dl1igc/goHamlib"
)
// Test consistency of Vfo Value and Name maps
func TestVfoMaps(t *testing.T) {
// Test VFOValue map
for vfoName, VFOValue := range goHamlib.VFOValue {
_, ok := goHamlib.VFOName[VFOValue]
if !ok {
t.Fatalf("VFO %d does not exist in VfoName map", VFOValue)
}
if vfoName != goHamlib.VFOName[VFOValue] {
t.Fatalf("Name of VFO inconsisted: %s", vfoName)
}
}
// Test VfoName map
for VFOValue, vfoName := range goHamlib.VFOName {
_, ok := goHamlib.VFOValue[vfoName]
if !ok {
t.Fatalf("VFO %s does not exist in VFOValue map", vfoName)
}
if VFOValue != goHamlib.VFOValue[vfoName] {
t.Fatalf("Value of VFO inconsisted: %s", vfoName)
}
}
}
// Test consistency of OperationValue and OperationName maps
func TestOperationMaps(t *testing.T) {
// Test OperationValue map
for opName, opValue := range goHamlib.VFOOperationValue {
_, ok := goHamlib.VFOOperationName[opValue]
if !ok {
t.Fatalf("Operation %d does not exist in OperationName map", opValue)
}
if opName != goHamlib.VFOOperationName[opValue] {
t.Fatalf("Name of Operation inconsisted: %s", opName)
}
}
// Test OperationName map
for opValue, opName := range goHamlib.VFOOperationName {
_, ok := goHamlib.VFOOperationValue[opName]
if !ok {
t.Fatalf("Operation %s does not exist in OperationValue map", opName)
}
if opValue != goHamlib.VFOOperationValue[opName] {
t.Fatalf("Value of Operation inconsisted: %s", opName)
}
}
}
// Test consistency of ModeValue and ModeName maps
func TestModeMaps(t *testing.T) {
// Test ModeValue map
for modeName, modeValue := range goHamlib.ModeValue {
_, ok := goHamlib.ModeName[modeValue]
if !ok {
t.Fatalf("Mode %d does not exist in ModeName map", modeValue)
}
if modeName != goHamlib.ModeName[modeValue] {
t.Fatalf("Name of Mode inconsisted: %s", modeName)
}
}
// Test ModeName map
for modeValue, modeName := range goHamlib.ModeName {
_, ok := goHamlib.ModeValue[modeName]
if !ok {
t.Fatalf("Mode %s does not exist in ModeValue map", modeName)
}
if modeValue != goHamlib.ModeValue[modeName] {
t.Fatalf("Value of Mode inconsisted: %s", modeName)
}
}
}
// Test consistency of RigPowerValue and RigPowerName maps
func TestRigPowerMaps(t *testing.T) {
// Test ModeValue map
for rpName, rpValue := range goHamlib.RigPowerValue {
_, ok := goHamlib.RigPowerName[rpValue]
if !ok {
t.Fatalf("RigPower %d does not exist in RigPowerName map", rpValue)
}
if rpName != goHamlib.RigPowerName[rpValue] {
t.Fatalf("Name of RigPower inconsisted: %s", rpName)
}
}
// Test RigPowerName map
for rpValue, rpName := range goHamlib.RigPowerName {
_, ok := goHamlib.RigPowerValue[rpName]
if !ok {
t.Fatalf("RigPower %s does not exist in RigPowerValue map", rpName)
}
if rpValue != goHamlib.RigPowerValue[rpName] {
t.Fatalf("Value of RigPower inconsisted: %s", rpName)
}
}
}
// Test consistency of LevelValue and LevelName maps
func TestLevelMaps(t *testing.T) {
// Test LevelValue map
for lName, lValue := range goHamlib.LevelValue {
_, ok := goHamlib.LevelName[lValue]
if !ok {
t.Fatalf("Level %d does not exist in LevelName map", lValue)
}
if lName != goHamlib.LevelName[lValue] {
t.Fatalf("Name of Level inconsisted: %s", lName)
}
}
// Test LevelName map
for lValue, lName := range goHamlib.LevelName {
_, ok := goHamlib.LevelValue[lName]
if !ok {
t.Fatalf("Level %s does not exist in LevelValue map", lName)
}
if lValue != goHamlib.LevelValue[lName] {
t.Fatalf("Value of Level inconsisted: %s", lName)
}
}
}
// Test consistency of ParmValue and ParmName maps
func TestParmMaps(t *testing.T) {
// Test ParmValue map
for pName, pValue := range goHamlib.ParmValue {
_, ok := goHamlib.ParmName[pValue]
if !ok {
t.Fatalf("Parm %d does not exist in ParmName map", pValue)
}
if pName != goHamlib.ParmName[pValue] {
t.Fatalf("Name of Parm inconsisted: %s", pName)
}
}
// Test ParmName map
for pValue, pName := range goHamlib.ParmName {
_, ok := goHamlib.ParmValue[pName]
if !ok {
t.Fatalf("Parm %s does not exist in ParmValue map", pName)
}
if pValue != goHamlib.ParmValue[pName] {
t.Fatalf("Value of Parm inconsisted: %s", pName)
}
}
}
// Test consistency of FuncValue and FuncName maps
func TestFuncMaps(t *testing.T) {
// Test FuncValue map
for fName, fValue := range goHamlib.FuncValue {
_, ok := goHamlib.FuncName[fValue]
if !ok {
t.Fatalf("Func %d does not exist in FuncName map", fValue)
}
if fName != goHamlib.FuncName[fValue] {
t.Fatalf("Name of Func inconsisted: %s", fName)
}
}
// Test FuncName map
for fValue, fName := range goHamlib.FuncName {
_, ok := goHamlib.FuncValue[fName]
if !ok {
t.Fatalf("Func %s does not exist in FuncValue map", fName)
}
if fValue != goHamlib.FuncValue[fName] {
t.Fatalf("Value of Func inconsisted: %s", fName)
}
}
}
// Test consistency of PttValue and PttName maps
func TestPttMaps(t *testing.T) {
// Test PttValue map
for pName, pValue := range goHamlib.PttValue {
_, ok := goHamlib.PttName[pValue]
if !ok {
t.Fatalf("Ptt %d does not exist in PttName map", pValue)
}
if pName != goHamlib.PttName[pValue] {
t.Fatalf("Name of Ptt inconsisted: %s", pName)
}
}
// Test PttName map
for pValue, pName := range goHamlib.PttName {
_, ok := goHamlib.PttValue[pName]
if !ok {
t.Fatalf("Ptt %s does not exist in PttValue map", pName)
}
if pValue != goHamlib.PttValue[pName] {
t.Fatalf("Value of Ptt inconsisted: %s", pName)
}
}
}
// Test consistency of AntValue and AntName maps
func TestAntennaMaps(t *testing.T) {
// Test AntValue map
for aName, aValue := range goHamlib.AntValue {
_, ok := goHamlib.AntName[aValue]
if !ok {
t.Fatalf("Antenna %d does not exist in AntName map", aValue)
}
if aName != goHamlib.AntName[aValue] {
t.Fatalf("Name of Antenna inconsisted: %s", aName)
}
}
// Test AntName map
for aValue, aName := range goHamlib.AntName {
_, ok := goHamlib.AntValue[aName]
if !ok {
t.Fatalf("Antenna %s does not exist in AntValue map", aName)
}
if aValue != goHamlib.AntValue[aName] {
t.Fatalf("Value of Antenna inconsisted: %s", aName)
}
}
}
// Test consistency of DebugLevelValue and DebugLevelName maps
func TestDebugLevelMaps(t *testing.T) {
// Test DebugLevelValue map
for dName, dValue := range goHamlib.DebugLevelValue {
_, ok := goHamlib.DebugLevelName[dValue]
if !ok {
t.Fatalf("Debug Level %d does not exist in DebugLevelName map", dValue)
}
if dName != goHamlib.DebugLevelName[dValue] {
t.Fatalf("Name of Debug Level inconsisted: %s", dName)
}
}
// Test DebugLevelName map
for dValue, dName := range goHamlib.DebugLevelName {
_, ok := goHamlib.DebugLevelValue[dName]
if !ok {
t.Fatalf("DebugLevel %s does not exist in DebugLevelValue map", dName)
}
if dValue != goHamlib.DebugLevelValue[dName] {
t.Fatalf("Value of DebugLevel inconsisted: %s", dName)
}
}
}
func TestCIntToBool(t *testing.T) {
x, err := goHamlib.CIntToBool(0)
if err != nil || x != false {
t.Fatalf("0 should result in false")
}
x, err = goHamlib.CIntToBool(1)
if err != nil || x != true {
t.Fatalf("1 should result in true")
}
_, err = goHamlib.CIntToBool(-1)
if err == nil {
t.Fatalf("-1 should result in err")
}
_, err = goHamlib.CIntToBool(2)
if err == nil {
t.Fatalf("2 should result in err")
}
}
func TestBoolToInt(t *testing.T) {
x, err := goHamlib.BoolToCint(true)
if err != nil || x != 1 {
t.Fatal("true should result in 1")
}
x, err = goHamlib.BoolToCint(false)
if err != nil || x != 0 {
t.Fatal("false should result in 0")
}
x, err = goHamlib.BoolToCint(false)
if err != nil || x != 0 {
t.Fatal("false should result in 0")
}
}
func TestListModels(t *testing.T) {
supported := goHamlib.ListModels()
if len(supported) < 10 {
t.Errorf("expected at least 10 supported hamlib models")
}
foundDummy := false
for _, v := range supported {
if v.Manufacturer == "Hamlib" && v.Model == "Dummy" {
foundDummy = true
}
}
if !foundDummy {
t.Errorf("did not find the hamlib standard dummy driver")
}
}
func TestDebugCallback(t *testing.T) {
called := 0
goHamlib.SetDebugCallback(func(lvl goHamlib.DebugLevel, msg string) {
called++
})
goHamlib.SetDebugLevel(goHamlib.DebugTrace)
goHamlib.ListModels()
goHamlib.SetDebugLevel(goHamlib.DebugWarn)
if called == 0 {
t.Errorf("expected a debug message, got none")
}
}