-
Notifications
You must be signed in to change notification settings - Fork 2
/
packet_test.go
45 lines (40 loc) · 1.04 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
package vlp16
import (
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestPacket_Unmarshal_TestData(t *testing.T) {
t.Parallel()
sc, done := newPacketRecordingScanner(t, "testdata/recording.bin")
defer done()
var numPackets int
for sc.Scan() {
var rawPacket RawPacket
copy(rawPacket[:], sc.Bytes())
var packet Packet
packet.UnmarshalRawPacket(&rawPacket)
numPackets++
assert.Equal(t, ReturnModeStrongest, packet.ReturnMode)
assert.Equal(t, ProductIDVLP16, packet.ProductID)
assert.Assert(
t,
time.Duration(packet.Timestamp)*time.Microsecond <= time.Hour,
"timestamp should be <= number of microseconds in an hour",
)
}
assert.Equal(t, 1000, numPackets)
}
func TestPacket_Unmarshal_Example(t *testing.T) {
t.Parallel()
actual := &Packet{}
actual.UnmarshalRawPacket(exampleRawPacket(t))
assert.DeepEqual(t, examplePacket(), actual)
}
func BenchmarkPacket_Unmarshal_Example(b *testing.B) {
packet := &Packet{}
exampleData := exampleRawPacket(b)
for i := 0; i < b.N; i++ {
packet.UnmarshalRawPacket(exampleData)
}
}