summaryrefslogtreecommitdiff
path: root/software/communication/data_link_test.go
blob: 91b941da3054f8880da0dc58bc979d2e433e8950 (plain)
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
package communication

import (
	"reflect"
	"testing"
)

func TestUnslip(t *testing.T) {
	input := []byte{
		0xFF, 0x12, SLIP_END,
	}

	bytes := make(chan byte)
	frames := make(chan []byte)

	go func() {
		for _, v := range input {
			bytes <- v
		}
	}()

	go func() {
		for {
			frames <- unslip(bytes)
		}
	}()

	frame := <-frames
	expected := []byte{0xFF, 0x12}
	if !reflect.DeepEqual(frame, expected) {
		t.Fatalf("Frame '%v' does not match expected '%v'\n", frame, expected)
	}
}