]> Sergey Matveev's repositories - btrtrc.git/blob - peer_protocol/protocol_test.go
7a7b8dd1ac1d109caafaa8811c6c5a86e8a68fb4
[btrtrc.git] / peer_protocol / protocol_test.go
1 package peer_protocol
2
3 import (
4         "testing"
5 )
6
7 func TestConstants(t *testing.T) {
8         // check that iota works as expected in the const block
9         if NotInterested != 3 {
10                 t.FailNow()
11         }
12 }
13 func TestBitfieldEncode(t *testing.T) {
14         bm := make(Bitfield, 37)
15         bm[2] = true
16         bm[7] = true
17         bm[32] = true
18         s := string(bm.Encode())
19         const expected = "\x21\x00\x00\x00\x80"
20         if s != expected {
21                 t.Fatalf("got %#v, expected %#v", s, expected)
22         }
23 }
24
25 func TestHaveEncode(t *testing.T) {
26         actual := string(Have(42).Encode())
27         expected := "\x04\x00\x00\x00\x2a"
28         if actual != expected {
29                 t.Fatalf("expected %#v, got %#v", expected, actual)
30         }
31 }