~rbn/neinp

ref: 280ca11dc4f314d4bb506de2f219eb70dd959227 neinp/message/read_test.go -rw-r--r-- 691 bytes
280ca11dRuben Schuller update go.mod 1 year, 2 months ago
                                                                                
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
package message

import (
	"bytes"
	"testing"
)

func TestTReadEncodeDecode(t *testing.T) {
	var buf bytes.Buffer
	a := &TRead{Fid: 1, Offset: 2, Count: 3}
	_, err := a.encode(&buf)
	if err != nil {
		t.Error(err)
	}

	b := &TRead{}
	_, err = b.decode(&buf)
	if err != nil {
		t.Error(err)
	}

	if *a != *b {
		t.Log(a, b)
		t.Fail()
	}
}

func TestRReadEncodeDecode(t *testing.T) {
	var buf bytes.Buffer
	a := &RRead{Count: 4, Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}}
	_, err := a.encode(&buf)
	if err != nil {
		t.Error(err)
	}

	b := &RRead{}
	_, err = b.decode(&buf)
	if err != nil {
		t.Error(err)
	}

	if a.Count != b.Count || !bytes.Equal(a.Data, b.Data) {
		t.Log(a, b)
		t.Fail()
	}
}