-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·139 lines (95 loc) · 4.71 KB
/
test.sh
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
#!/bin/bash
source functions.sh
function test_report()
{
echo
echo "input data: $1"
echo "output data: $2"
echo "expected data: $3"
}
echo -n "### get_fbus_crc "
sample_data="\x1E\x00\x0C\xD1\x00\x07\x00\x01\x00\x03\x00\x01\x60\x00"
test "$(get_fbus_crc "$sample_data")" == '\x72\xD5' && echo -n . || echo -n F
sample_data="\x1E\x00"
test "$(get_fbus_crc "$sample_data")" == '\x1E\x00' && echo -n . || echo -n F
sample_data="\x1e\x00\x0c\x02\x00\x38\x00\x01\x00\x02\x00\x00\x00\x55\x55\x01\x02\x2c\x11\x00\x00\x00\x00\x04\x82\x0c\x01\x08\x0b\x91\x73\x60\x50\x84\x36\xf3\x82\x0c\x02\x08\x07\x91\x73\x60\x99\x05\x11\xf5\x80\x08\x01\x01\x58\x55\x55\x55\x08\x04\x01\xa9\x01\x60"
expected_result="\x52\x5F"
result="$(get_fbus_crc "$sample_data")"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
echo
echo -n "### ascii_to_gsm7 "
sample_data="hello"
expected_result="\xE8\x32\x9B\xFD\x06"
test "$(ascii_to_gsm7 "$sample_data")" == "$expected_result" && echo -n . || echo -n F
sample_data="Hi All. This"
expected_result="\xC8\x34\x28\xC8\x66\xBB\x40\x54\x74\x7A\x0E"
test "$(ascii_to_gsm7 "$sample_data")" == "$expected_result" && echo -n . || echo -n F
sample_data="Testas"
expected_result="\xD4\xF2\x9C\x1E\x9E\x03"
result="$(ascii_to_gsm7 "$sample_data")"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
echo
echo -n "### encode_phone_number "
sample_data="+61411990010"
expected_result="\x07\x91\x16\x14\x91\x09\x10\xF0\x00\x00\x00\x00"
result="$(encode_phone_number "$sample_data")"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
sample_data="+3706001234567"
expected_result="\x08\x91\x73\x60\x00\x21\x43\x65\xF7\x00\x00\x00"
result="$(encode_phone_number "$sample_data")"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
sample_data="+37060012345678"
expected_result="\x08\x91\x73\x60\x00\x21\x43\x65\x87\x00\x00\x00"
result="$(encode_phone_number "$sample_data")"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
sample_data="+370600123456789"
expected_result="\x09\x91\x73\x60\x00\x21\x43\x65\x87\xF9\x00\x00"
result="$(encode_phone_number "$sample_data")"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
echo
echo -n "### get_fbus_crc "
sample_data="\x03\x01\x02"
expected_result="\x01\x01"
result="$(get_fbus_crc "$sample_data")"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
sample_data="\x1E\x00\x0C\xD1\x00\x07\x00\x01\x00\x03\x00\x01\x60\x00"
expected_result="\x72\xD5"
result="$(get_fbus_crc "$sample_data")"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
echo
echo -n "### build_sms_frame "
destnum="040378007400000000"
message="Hi All. This message was sent through F-Bus. Cool!!"
smsc="+61411990010"
sample_data="destnum $destnum; smsc $smsc; message $message"
expected_result="\
\x00\x01\x00\x01\x02\x00\
\x07\x91\x16\x14\x91\x09\x10\xF0\x00\x00\x00\x00\
\x15\x00\x00\x00\x33\
\x0A\x91\x40\x30\x87\x00\x47\x00\x00\x00\x00\x00\
\xA7\x00\x00\x00\x00\x00\x00\xC8\x34\x28\xC8\x66\xBB\x40\x54\x74\x7A\x0E\x6A\x97\xE7\xF3\xF0\xB9\x0C\xBA\x87\xE7\xA0\x79\xD9\x4D\x07\xD1\xD1\xF2\x77\xFD\x8C\x06\x19\x5B\xC2\xFA\xDC\x05\x1A\xBE\xDF\xEC\x50\x08"
result="$(build_sms_frame)"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
echo
echo -n "### fbus_encapsulate "
sample_data="\x00\x01\x00\x03\x00"
expected_result="\x1E\x00\x0C\x02\x00\x07${sample_data}\x01\x43\x00\x51\x06"
result="$(fbus_encapsulate "$sample_data")"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
echo
echo -n "### full message "
destnum="040378007400000000"
message="Hi All. This message was sent through F-Bus. Cool!!"
smsc="+61411990010"
sample_data="destnum $destnum; smsc $smsc; message $message"
expected_result="\
\x1E\x00\x0C\x02\x00\x59\
\x00\x01\x00\x01\x02\x00\
\x07\x91\x16\x14\x91\x09\x10\xF0\x00\x00\x00\x00\
\x15\x00\x00\x00\x33\
\x0A\x91\x40\x30\x87\x00\x47\x00\x00\x00\x00\x00\
\xA7\x00\x00\x00\x00\x00\x00\xC8\x34\x28\xC8\x66\xBB\x40\x54\x74\x7A\x0E\x6A\x97\xE7\xF3\xF0\xB9\x0C\xBA\x87\xE7\xA0\x79\xD9\x4D\x07\xD1\xD1\xF2\x77\xFD\x8C\x06\x19\x5B\xC2\xFA\xDC\x05\x1A\xBE\xDF\xEC\x50\x08\x01\
\x43\x00\x6A\x52"
result="$(fbus_encapsulate "$(build_sms_frame)")"
test "$result" == "$expected_result" && echo -n . || test_report "$sample_data" "$result" "$expected_result"
echo