7 "bitbucket.org/anacrolix/go.torrent/peer_protocol"
10 func r(i, b, l peer_protocol.Integer) request {
11 return request{i, chunkSpec{b, l}}
14 // Check the given Request is correct for various torrent offsets.
15 func TestTorrentRequest(t *testing.T) {
16 const s = 472183431 // Length of torrent.
17 for _, _case := range []struct {
18 off int64 // An offset into the torrent.
19 req request // The expected Request. The zero value means !ok.
24 // One before the end of a piece.
25 {1<<18 - 1, r(0, 1<<18-16384, 16384)},
26 // Offset beyond torrent length.
27 {472 * 1 << 20, request{}},
28 // One before the end of the torrent. Complicates the chunk length.
29 {s - 1, r((s-1)/(1<<18), (s-1)%(1<<18)/(16384)*(16384), 12935)},
31 // One before end of chunk.
32 {16383, r(0, 0, 16384)},
34 {16384, r(0, 16384, 16384)},
36 req, ok := torrentOffsetRequest(472183431, 1<<18, 16384, _case.off)
37 if (_case.req == request{}) == ok {
38 t.Fatalf("expected %v, got %v", _case.req, req)
41 t.Fatalf("expected %v, got %v", _case.req, req)
46 func TestTorrentDoubleClose(t *testing.T) {
47 tt, err := newTorrent(InfoHash{}, nil)
51 wg := sync.WaitGroup{}
52 for i := 0; i < 2; i++ {
62 func TestAppendToCopySlice(t *testing.T) {
63 orig := []int{1, 2, 3}
64 dupe := append([]int{}, orig...)