6 "github.com/anacrolix/torrent/peer_protocol"
9 func r(i, b, l peer_protocol.Integer) request {
10 return request{i, chunkSpec{b, l}}
13 // Check the given Request is correct for various torrent offsets.
14 func TestTorrentRequest(t *testing.T) {
15 const s = 472183431 // Length of torrent.
16 for _, _case := range []struct {
17 off int64 // An offset into the torrent.
18 req request // The expected Request. The zero value means !ok.
23 // One before the end of a piece.
24 {1<<18 - 1, r(0, 1<<18-16384, 16384)},
25 // Offset beyond torrent length.
26 {472 * 1 << 20, request{}},
27 // One before the end of the torrent. Complicates the chunk length.
28 {s - 1, r((s-1)/(1<<18), (s-1)%(1<<18)/(16384)*(16384), 12935)},
30 // One before end of chunk.
31 {16383, r(0, 0, 16384)},
33 {16384, r(0, 16384, 16384)},
35 req, ok := torrentOffsetRequest(472183431, 1<<18, 16384, _case.off)
36 if (_case.req == request{}) == ok {
37 t.Fatalf("expected %v, got %v", _case.req, req)
40 t.Fatalf("expected %v, got %v", _case.req, req)
45 func TestAppendToCopySlice(t *testing.T) {
46 orig := []int{1, 2, 3}
47 dupe := append([]int{}, orig...)
54 func TestTorrentString(t *testing.T) {
56 s := tor.InfoHash().HexString()
57 if s != "0000000000000000000000000000000000000000" {