forked from warthog618/sms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstoctet_test.go
110 lines (96 loc) · 2.43 KB
/
firstoctet_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
// SPDX-License-Identifier: MIT
//
// Copyright © 2020 Kent Gibson <[email protected]>.
package tpdu_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/warthog618/sms/encoding/tpdu"
)
func TestFirstOctetLP(t *testing.T) {
assert.False(t, tpdu.FirstOctet(0).LP())
assert.True(t, tpdu.FirstOctet(tpdu.FoLP).LP())
}
func TestFirstOctetMMS(t *testing.T) {
assert.False(t, tpdu.FirstOctet(0).MMS())
assert.True(t, tpdu.FirstOctet(tpdu.FoMMS).MMS())
}
func TestFirstMTI(t *testing.T) {
patterns := []struct {
inout tpdu.MessageType
}{
{tpdu.MtCommand},
{tpdu.MtDeliver},
{tpdu.MtSubmit},
{tpdu.MtReserved},
}
for _, p := range patterns {
assert.Equal(t, p.inout, tpdu.FirstOctet(p.inout).MTI())
}
}
func TestFirstOctetRD(t *testing.T) {
assert.False(t, tpdu.FirstOctet(0).RD())
assert.True(t, tpdu.FirstOctet(tpdu.FoRD).RD())
}
func TestFirstOctetRP(t *testing.T) {
assert.False(t, tpdu.FirstOctet(0).RP())
assert.True(t, tpdu.FirstOctet(tpdu.FoRP).RP())
}
func TestFirstOctetSRI(t *testing.T) {
assert.False(t, tpdu.FirstOctet(0).SRI())
assert.True(t, tpdu.FirstOctet(tpdu.FoSRI).SRI())
}
func TestFirstOctetSRR(t *testing.T) {
assert.False(t, tpdu.FirstOctet(0).SRR())
assert.True(t, tpdu.FirstOctet(tpdu.FoSRR).SRR())
}
func TestFirstOctetSRQ(t *testing.T) {
assert.False(t, tpdu.FirstOctet(0).SRQ())
assert.True(t, tpdu.FirstOctet(tpdu.FoSRQ).SRQ())
}
func TestFirstOctetUDHI(t *testing.T) {
assert.False(t, tpdu.FirstOctet(0).UDHI())
assert.True(t, tpdu.FirstOctet(tpdu.FoUDHI).UDHI())
}
func TestFirstOctetVPF(t *testing.T) {
patterns := []struct {
in tpdu.FirstOctet
out tpdu.ValidityPeriodFormat
}{
{0, tpdu.VpfNotPresent},
{0x10, tpdu.VpfRelative},
{0x18, tpdu.VpfAbsolute},
{0x08, tpdu.VpfEnhanced},
}
for _, p := range patterns {
fo := tpdu.FirstOctet(p.in)
assert.Equal(t, p.out, fo.VPF())
}
}
func TestFirstWithMTI(t *testing.T) {
patterns := []struct {
inout tpdu.MessageType
}{
{tpdu.MtCommand},
{tpdu.MtDeliver},
{tpdu.MtSubmit},
{tpdu.MtReserved},
}
for _, p := range patterns {
fo := tpdu.FirstOctet(0).WithMTI(p.inout)
assert.Equal(t, p.inout, fo.MTI())
}
}
func TestFirstOctetWithVPF(t *testing.T) {
patterns := []struct {
inout tpdu.ValidityPeriodFormat
}{
{tpdu.VpfNotPresent},
{tpdu.VpfRelative},
{tpdu.VpfAbsolute},
{tpdu.VpfEnhanced},
}
for _, p := range patterns {
assert.Equal(t, p.inout, tpdu.FirstOctet(0).WithVPF(p.inout).VPF())
}
}