-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpacket_test.go
77 lines (66 loc) · 2.06 KB
/
packet_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
package dcc
import (
"os"
"testing"
"time"
"github.com/hsanjuan/go-dcc/driver/dummy"
)
func TestSend(t *testing.T) {
if os.Getenv("TRAVIS") == "true" {
// This facilitates that tests pass on travis :(
dummy.ByteOneMax = 94 * time.Microsecond
}
d := &dummy.DCCDummy{}
p := NewBroadcastIdlePacket(d)
d.TracksOn()
p.Send()
time.Sleep(1 * time.Second)
packetStr := dummy.GuessBuffer.String()
t.Log("Pckt: ", p.String())
t.Log("Sent: ", packetStr)
if packetStr != p.String() {
t.Error("should have sent the encoded package")
}
}
func TestNewPacket(t *testing.T) {
p := NewPacket(&dummy.DCCDummy{}, 0xFF, []byte{0x01})
if p.String() != "11111111111111110111111110000000010111111101" {
t.Error("Bad packet: ", p.String())
}
}
func TestNewBaselinePacket(t *testing.T) {
p := NewBaselinePacket(&dummy.DCCDummy{}, 0xFF, []byte{0x01})
if p.String() != "11111111111111110011111110000000010011111101" {
t.Error("Bad packet: ", p.String())
}
}
func TestIdlePacket(t *testing.T) {
p := NewBroadcastIdlePacket(&dummy.DCCDummy{})
if p.String() != "11111111111111110111111110000000000111111111" {
t.Error("Bad idle packet")
}
}
func TestNewSpeedAndDirectionPacket(t *testing.T) {
p := NewSpeedAndDirectionPacket(&dummy.DCCDummy{}, 0xFF, 0xFF, Forward)
if p.String() != "11111111111111110011111110011111110000000001" {
t.Error("Bad speed and direction packet: ", p.String())
}
}
func TestNewFunctionGroupOnePacket(t *testing.T) {
p := NewFunctionGroupOnePacket(&dummy.DCCDummy{}, 0xFF, true, true, true, true, true)
if p.String() != "11111111111111110111111110100111110011000001" {
t.Error("Bad Function Group One packet: ", p.String())
}
}
func TestNewBroadcastResetPacket(t *testing.T) {
p := NewBroadcastResetPacket(&dummy.DCCDummy{})
if p.String() != "11111111111111110000000000000000000000000001" {
t.Error("Bad reset packet")
}
}
func TestNewBroadcastStopPacket(t *testing.T) {
p := NewBroadcastStopPacket(&dummy.DCCDummy{}, Backward, true, false)
if p.String() != "11111111111111110000000000010000000010000001" {
t.Error("Bad stop packet: ", p.String())
}
}