-
Notifications
You must be signed in to change notification settings - Fork 10
/
reader_test.go
112 lines (104 loc) · 5.88 KB
/
reader_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
package ucp
import (
"bufio"
"log"
"os"
"reflect"
"runtime"
"strings"
"sync"
"testing"
)
func TestReaderSubmitSm(t *testing.T) {
reader := bufio.NewReader(strings.NewReader("\x02\x30\x31\x2f\x30\x30\x30\x34\x34\x2f\x52\x2f\x35\x31\x2f\x41" +
"\x2f\x2f\x30\x39\x31\x39\x31\x32\x33\x34\x35\x36\x37\x3a\x31\x31" +
"\x30\x39\x31\x37\x31\x37\x33\x36\x33\x39\x2f\x39\x35\x03"))
wg := new(sync.WaitGroup)
closeChan := make(chan struct{}, 1)
submitSmRespCh := make(chan []string, 1)
readLoop(reader, wg, closeChan, submitSmRespCh, nil, nil,
&Client{logger: log.New(os.Stdout, "debug ", 0)})
runtime.Gosched()
actual := <-submitSmRespCh
expected := []string{"01", "00044", "R", "51", "A", "", "09191234567:110917173639", "95"}
close(closeChan)
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expected %q, got %q\n", expected, actual)
}
}
func TestReaderDeliverNotif(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(
"\x02\x30\x30\x2f\x30\x30\x33\x30\x34\x2f\x4f\x2f\x35\x33\x2f\x32" +
"\x33\x37\x31\x2f\x30\x39\x31\x39\x31\x32\x33\x34\x35\x36\x37\x2f" +
"\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x31\x31\x30\x39" +
"\x31\x37\x31\x36\x30\x32\x35\x30\x2f\x30\x2f\x30\x30\x30\x2f\x31" +
"\x31\x30\x39\x31\x37\x31\x36\x30\x32\x35\x32\x2f\x33\x2f\x2f\x34" +
"\x44\x36\x35\x37\x33\x37\x33\x36\x31\x36\x37\x36\x35\x32\x30\x36" +
"\x36\x36\x46\x37\x32\x32\x30\x32\x42\x33\x36\x33\x33\x33\x39\x33" +
"\x37\x33\x37\x33\x30\x33\x35\x33\x39\x33\x37\x33\x38\x33\x34\x33" +
"\x38\x32\x43\x32\x30\x37\x37\x36\x39\x37\x34\x36\x38\x32\x30\x36" +
"\x39\x36\x34\x36\x35\x36\x45\x37\x34\x36\x39\x36\x36\x36\x39\x36" +
"\x33\x36\x31\x37\x34\x36\x39\x36\x46\x36\x45\x32\x30\x33\x31\x33" +
"\x37\x33\x30\x33\x39\x33\x31\x33\x31\x33\x31\x33\x36\x33\x30\x33" +
"\x32\x33\x35\x33\x30\x32\x30\x36\x38\x36\x31\x37\x33\x32\x30\x36" +
"\x32\x36\x35\x36\x35\x36\x45\x32\x30\x36\x34\x36\x35\x36\x43\x36" +
"\x39\x37\x36\x36\x35\x37\x32\x36\x35\x36\x34\x32\x30\x36\x46\x36" +
"\x45\x32\x30\x33\x32\x33\x30\x33\x31\x33\x37\x32\x44\x33\x30\x33" +
"\x39\x32\x44\x33\x31\x33\x31\x32\x30\x36\x31\x37\x34\x32\x30\x33" +
"\x31\x33\x36\x33\x41\x33\x30\x33\x32\x33\x41\x33\x35\x33\x32\x32" +
"\x45\x2f\x31\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x39" +
"\x31\x03"))
wg := new(sync.WaitGroup)
closeChan := make(chan struct{}, 1)
deliverNotifCh := make(chan []string, 1)
readLoop(reader, wg, closeChan, nil, deliverNotifCh, nil,
&Client{logger: log.New(os.Stdout, "debug ", 0)})
runtime.Gosched()
actual := <-deliverNotifCh
expected := []string{"00", "00304", "O", "53", "2371", "09191234567", "", "", "", "", "", "", "", "", "", "", "", "", "110917160250", "0", "000", "110917160252", "3", "", "4D65737361676520666F72202B3633393737303539373834382C2077697468206964656E74696669636174696F6E2031373039313131363032353020686173206265656E2064656C697665726564206F6E20323031372D30392D31312061742031363A30323A35322E", "1", "", "", "", "", "", "", "", "", "", "", "", "91"}
close(closeChan)
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expected %q, got %q\n", expected, actual)
}
}
func TestReaderDeliverMsg(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(
"\x02\x32\x36\x2f\x30\x30\x34\x30\x38\x2f\x4f\x2f\x35\x32\x2f\x32" +
"\x33\x37\x31\x2f\x30\x39\x31\x39\x31\x32\x33\x34\x35\x36\x37\x2f" +
"\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x30\x30\x30\x30\x2f" +
"\x31\x32\x31\x30\x31\x37\x30\x31\x30\x32\x30\x38\x2f\x2f\x2f\x2f" +
"\x33\x2f\x2f\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34\x31\x34" +
"\x31\x34\x31\x2f\x2f\x2f\x30\x2f\x2f\x2f\x2f\x2f\x2f\x2f\x30\x32" +
"\x30\x31\x30\x30\x2f\x2f\x2f\x42\x46\x03"))
wg := new(sync.WaitGroup)
closeChan := make(chan struct{}, 1)
deliverMsgCh := make(chan []string, 1)
readLoop(reader, wg, closeChan, nil, nil, deliverMsgCh,
&Client{logger: log.New(os.Stdout, "debug ", 0)})
runtime.Gosched()
actual := <-deliverMsgCh
expected := []string{"26", "00408", "O", "52", "2371", "09191234567", "", "", "", "", "", "", "", "", "", "", "", "0000", "121017010208", "", "", "", "3", "", "41414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141", "", "", "0", "", "", "", "", "", "", "020100", "", "", "BF"}
close(closeChan)
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expected %q, got %q\n", expected, actual)
}
}