-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsubmit_test.go
159 lines (143 loc) ยท 5.46 KB
/
submit_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
package ucp
import (
"bytes"
"fmt"
"testing"
"github.com/go-gsm/charset"
)
func TestSubmit(t *testing.T) {
actual := encodeMessage([]byte("01"), "Voyager", "09495696599", "Hello world",
alphaNumericMessage, "", 23, 1, 1)
data := struct {
actual []byte
expected []byte
}{
actual,
[]byte("\x0201/00126/O/51/09495696599/0ED6773E7C2ECB1B//1//1/////////////3/88/48656C6C6F20776F726C64////1////5039//020100060101070101///47\x03"),
}
if !bytes.Equal(data.expected, data.actual) {
t.Errorf("Expected %s, got %s\n", data.expected, data.actual)
}
}
func TestConvertToUCS2(t *testing.T) {
ucs2TestCases := []struct {
name string
input string
expected string
}{
{
"smiley emoji",
"๐",
"D83DDE03",
},
{
`lower case letter "a"`,
"a",
"0061",
},
}
for _, testCase := range ucs2TestCases {
actual := fmt.Sprintf("%04X", string(charset.EncodeUcs2(testCase.input)))
if actual != testCase.expected {
t.Errorf("testcase %s: Expected %v, got %v\n", testCase.name, testCase.expected, actual)
}
}
}
func TestGetDataCodingScheme(t *testing.T) {
dcsTestCases := []struct {
name string
input string
expected string
}{
{
"alphanumeric",
alphaNumericMessage,
dataCodingSchemeASCII,
},
{
"transparent data",
transparentData,
dataCodingSchemeUCS2,
},
}
for _, testCase := range dcsTestCases {
actual := getDataCodingScheme(testCase.input)
if actual != testCase.expected {
t.Errorf("testcase %s: Expected %v, got %v\n", testCase.name, testCase.expected, actual)
}
}
}
func TestGetMessageType(t *testing.T) {
getMessageTypeTestCases := []struct {
name string
input string
expected string
}{
{
"alpha numeric",
"hello world",
alphaNumericMessage,
},
{
"unicode",
"hello ไธ็",
transparentData,
},
}
for _, testCase := range getMessageTypeTestCases {
actual := getMessageType(testCase.input)
if actual != testCase.expected {
t.Errorf("testcase %s: Expected %v, got %v\n", testCase.name, testCase.expected, actual)
}
}
}
func TestGetMessageParts(t *testing.T) {
getMessagePartsTestCases := []struct {
name string
input string
expected []string
}{
{
"ascii parts",
"Did you ever hear the tragedy of Darth Plagueis The Wise? I thought not. It's not a story the Jedi would tell you. It's a Sith legend. Darth Plagueis was a Dark Lord of the Sith, so powerful and so wise he could use the Force to influence the midichlorians to create life... He had such a knowledge of the dark side that he could even keep the ones he cared about from dying. The dark side of the Force is a pathway to many abilities some consider to be unnatural. He became so powerful... the only thing he was afraid of was losing his power, which eventually, of course, he did. Unfortunately, he taught his apprentice everything he knew, then his apprentice killed him in his sleep. Ironic. He could save others from death, but not himself.",
[]string{
"Did you ever hear the tragedy of Darth Plagueis The Wise? I thought not. It's not a story the Jedi would tell you. It's a Sith legend. Darth Plagueis was",
" a Dark Lord of the Sith, so powerful and so wise he could use the Force to influence the midichlorians to create life... He had such a knowledge of the ",
"dark side that he could even keep the ones he cared about from dying. The dark side of the Force is a pathway to many abilities some consider to be unnat",
"ural. He became so powerful... the only thing he was afraid of was losing his power, which eventually, of course, he did. Unfortunately, he taught his ap",
"prentice everything he knew, then his apprentice killed him in his sleep. Ironic. He could save others from death, but not himself."},
},
{
"unicode parts",
"๐๐๐๐๐๐๐๐๐๐ good shit goเฑฆิ sHit๐ thats โ some good๐๐shit right๐๐there๐๐๐ rightโthere โโif i do ฦฝaาฏ so my self ๐ฏ i say so ๐ฏ thats what im talking about right there right there (chorus: สณแถฆแตสฐแต แตสฐแตสณแต) mMMMMแทะ๐ฏ ๐๐ ๐ะO0ะเฌ OOOOOะเฌ เฌ Ooooแตแตแตแตแตแตแตแตแต๐ ๐๐ ๐ ๐ฏ ๐ ๐ ๐ ๐ ๐๐Good shit",
[]string{
"๐๐๐๐๐๐๐๐๐๐ good shit goเฑฆิ sHit",
"๐ thats โ some good๐๐shit right๐๐there๐๐",
"๐ rightโthere โโif i do ฦฝaาฏ so my self ๐ฏ i say so ",
"๐ฏ thats what im talking about right there right there (chorus",
": สณแถฆแตสฐแต แตสฐแตสณแต) mMMMMแทะ๐ฏ ๐๐ ๐ะO0",
"ะเฌ OOOOOะเฌ เฌ Ooooแตแตแตแตแตแตแตแตแต๐ ๐๐ ",
"๐ ๐ฏ ๐ ๐ ๐ ๐ ๐๐Good shit"},
},
}
for _, testCase := range getMessagePartsTestCases {
actual := getMessageParts(testCase.input)
if len(testCase.expected) != len(actual) {
t.Errorf("testcase %s: Expected %v, got %v\n", testCase.name, len(testCase.expected), len(actual))
}
for i := 0; i < len(testCase.expected); i++ {
if testCase.expected[i] != actual[i] {
t.Errorf("testcase %s: Expected %q, got %q\n", testCase.name, testCase.expected[i], actual[i])
}
}
}
}
func BenchmarkEnodeMsg(b *testing.B) {
message := "The quick brown fox jumps over the lazy dog is an English-language pangram - a sentence that contains all of the letters of the alphabet."
sender := "Voyager"
receiver := "09191234567"
for n := 0; n < b.N; n++ {
encodeMessage([]byte("01"), sender, receiver, message, alphaNumericMessage,
"", 23, 1, 1)
}
}