4 "bitbucket.org/anacrolix/go.torrent/peer_protocol"
8 func r(i, b, l peer_protocol.Integer) Request {
9 return Request{i, chunkSpec{b, l}}
12 // Check the given Request is correct for various torrent offsets.
13 func TestTorrentRequest(t *testing.T) {
14 const s = 472183431 // Length of torrent.
15 for _, _case := range []struct {
16 off int64 // An offset into the torrent.
17 req Request // The expected Request. The zero value means !ok.
22 // One before the end of a piece.
23 {1<<18 - 1, r(0, 1<<18-16384, 16384)},
24 // Offset beyond torrent length.
25 {472 * 1 << 20, Request{}},
26 // One before the end of the torrent. Complicates the chunk length.
27 {s - 1, r((s-1)/(1<<18), (s-1)%(1<<18)/(16384)*(16384), 12935)},
29 // One before end of chunk.
30 {16383, r(0, 0, 16384)},
32 {16384, r(0, 16384, 16384)},
34 req, ok := torrentOffsetRequest(472183431, 1<<18, 16384, _case.off)
35 if (_case.req == Request{}) == ok {
36 t.Fatalf("expected %v, got %v", _case.req, req)
39 t.Fatalf("expected %v, got %v", _case.req, req)