8 "bitbucket.org/anacrolix/go.torrent/peer_protocol"
11 func r(i, b, l peer_protocol.Integer) request {
12 return request{i, chunkSpec{b, l}}
15 // Check the given Request is correct for various torrent offsets.
16 func TestTorrentRequest(t *testing.T) {
17 const s = 472183431 // Length of torrent.
18 for _, _case := range []struct {
19 off int64 // An offset into the torrent.
20 req request // The expected Request. The zero value means !ok.
25 // One before the end of a piece.
26 {1<<18 - 1, r(0, 1<<18-16384, 16384)},
27 // Offset beyond torrent length.
28 {472 * 1 << 20, request{}},
29 // One before the end of the torrent. Complicates the chunk length.
30 {s - 1, r((s-1)/(1<<18), (s-1)%(1<<18)/(16384)*(16384), 12935)},
32 // One before end of chunk.
33 {16383, r(0, 0, 16384)},
35 {16384, r(0, 16384, 16384)},
37 req, ok := torrentOffsetRequest(472183431, 1<<18, 16384, _case.off)
38 if (_case.req == request{}) == ok {
39 t.Fatalf("expected %v, got %v", _case.req, req)
42 t.Fatalf("expected %v, got %v", _case.req, req)
47 func TestTorrentDoubleClose(t *testing.T) {
48 tt, err := newTorrent(InfoHash{})
49 tt.pruneTimer = time.NewTimer(0)
53 wg := sync.WaitGroup{}
54 for i := 0; i < 2; i++ {
64 func TestAppendToCopySlice(t *testing.T) {
65 orig := []int{1, 2, 3}
66 dupe := append([]int{}, orig...)
73 func TestTorrentString(t *testing.T) {
75 s := tor.InfoHash.HexString()
76 if s != "0000000000000000000000000000000000000000" {