-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslconn_test.go
114 lines (107 loc) · 2.64 KB
/
slconn_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
package slink
import (
"io/ioutil"
"os"
"testing"
)
func TestNewSLCD(t *testing.T) {
slconn := NewSLCD()
defer FreeSLCD(slconn)
if slconn == nil {
t.Error("unable to create new SLCD")
}
}
func TestSetNetDly(t *testing.T) {
slconn := NewSLCD()
defer FreeSLCD(slconn)
if slconn == nil {
t.Error("unable to create new SLCD")
}
if slconn.NetDly() != 30 {
t.Error("NetDly unexpected default value")
}
slconn.SetNetDly(10)
if slconn.NetDly() != 10 {
t.Error("NetDly not set")
}
}
func TestSetNetTo(t *testing.T) {
slconn := NewSLCD()
defer FreeSLCD(slconn)
if slconn == nil {
t.Error("unable to create new SLCD")
}
if slconn.NetTo() != 600 {
t.Error("NetTo unexpected default value")
}
slconn.SetNetTo(10)
if slconn.NetTo() != 10 {
t.Error("NetTo not set")
}
}
func TestSetNetKeepAlive(t *testing.T) {
slconn := NewSLCD()
defer FreeSLCD(slconn)
if slconn == nil {
t.Error("unable to create new SLCD")
}
if slconn.KeepAlive() != 0 {
t.Error("KeepAlive unexpected default value")
}
slconn.SetKeepAlive(10)
if slconn.KeepAlive() != 10 {
t.Error("KeepAlive not set")
}
}
func TestReadStreamList(t *testing.T) {
slconn := NewSLCD()
defer FreeSLCD(slconn)
if slconn == nil {
t.Error("unable to create new SLCD")
}
tf, err := ioutil.TempFile("", "slconn_test")
if err != nil {
t.Error("unable to open temporary file")
}
defer os.Remove(tf.Name())
ioutil.WriteFile(tf.Name(), ([]byte)("# A comment\nGE ISP BH?.D\nNL HGN\nMN AGU BH? HH?\n"), 0644)
count, err := slconn.ReadStreamList(tf.Name(), "")
if err != nil {
t.Error("unable to read stream list, invalid format")
}
if count != 4 {
t.Error("unable to read stream list, incorrect count")
}
count, err = slconn.ReadStreamList(tf.Name(), "H??")
if err != nil {
t.Error("unable to read stream list, invalid format")
}
if count != 4 {
t.Error("unable to read stream list, incorrect count")
}
}
func TestParseStreamList(t *testing.T) {
slconn := NewSLCD()
defer FreeSLCD(slconn)
if slconn == nil {
t.Error("unable to create new SLCD")
}
count, err := slconn.ParseStreamList("IU_KONO:BHE BHN,GE_WLF,MN_AQU:HH?.D", "")
if err != nil {
t.Error("unable to parse stream list, invalid string")
}
if count != 3 {
t.Error("unable to parse stream list, wrong count")
}
count, err = slconn.ParseStreamList("IU_KONO:BHE BHN,GE_WLF,MN_AQU:HH?.D", "H??")
if err != nil {
t.Error("unable to parse stream list, invalid string")
}
if count != 3 {
t.Error("unable to parse stream list, wrong count")
}
count, err = slconn.ParseStreamList("IU__KONO:BHE BHN,GE_WLF,MN_AQU:HH?.D", "")
if err == nil {
t.Error("shouldn't be able to parse stream list, invalid string")
}
}