2014-03-17 14:44:22 +00:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
2014-03-20 05:58:09 +00:00
|
|
|
"os"
|
2014-03-17 14:44:22 +00:00
|
|
|
"testing"
|
2014-08-21 08:24:19 +00:00
|
|
|
|
|
|
|
"bitbucket.org/anacrolix/go.torrent/testutil"
|
|
|
|
"bitbucket.org/anacrolix/go.torrent/util"
|
|
|
|
"github.com/anacrolix/libtorgo/bencode"
|
2014-03-17 14:44:22 +00:00
|
|
|
)
|
|
|
|
|
2014-08-21 08:07:06 +00:00
|
|
|
func TestClientDefault(t *testing.T) {
|
|
|
|
cl, err := NewClient(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
cl.Stop()
|
|
|
|
}
|
|
|
|
|
2014-03-17 14:44:22 +00:00
|
|
|
func TestAddTorrentNoSupportedTrackerSchemes(t *testing.T) {
|
|
|
|
t.SkipNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddTorrentNoUsableURLs(t *testing.T) {
|
|
|
|
t.SkipNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddPeersToUnknownTorrent(t *testing.T) {
|
|
|
|
t.SkipNow()
|
|
|
|
}
|
2014-03-20 05:58:09 +00:00
|
|
|
|
|
|
|
func TestPieceHashSize(t *testing.T) {
|
2014-04-08 16:36:05 +00:00
|
|
|
if pieceHash.Size() != 20 {
|
2014-03-20 05:58:09 +00:00
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTorrentInitialState(t *testing.T) {
|
|
|
|
dir, mi := testutil.GreetingTestTorrent()
|
|
|
|
defer os.RemoveAll(dir)
|
2014-08-21 08:24:19 +00:00
|
|
|
tor, err := newTorrent(func() (ih InfoHash) {
|
|
|
|
util.CopyExact(ih[:], mi.Info.Hash)
|
|
|
|
return
|
|
|
|
}(), nil)
|
2014-06-28 09:38:31 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-07-13 07:37:12 +00:00
|
|
|
err = tor.setMetadata(mi.Info.Info, dir, mi.Info.Bytes)
|
2014-03-20 05:58:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(tor.Pieces) != 1 {
|
|
|
|
t.Fatal("wrong number of pieces")
|
|
|
|
}
|
|
|
|
p := tor.Pieces[0]
|
|
|
|
if len(p.PendingChunkSpecs) != 1 {
|
2014-07-09 16:59:37 +00:00
|
|
|
t.Fatalf("should only be 1 chunk: %v", p.PendingChunkSpecs)
|
2014-03-20 05:58:09 +00:00
|
|
|
}
|
2014-04-08 16:36:05 +00:00
|
|
|
if _, ok := p.PendingChunkSpecs[chunkSpec{
|
2014-03-20 05:58:09 +00:00
|
|
|
Length: 13,
|
|
|
|
}]; !ok {
|
|
|
|
t.Fatal("pending chunk spec is incorrect")
|
|
|
|
}
|
|
|
|
}
|
2014-06-29 09:07:43 +00:00
|
|
|
|
|
|
|
func TestUnmarshalPEXMsg(t *testing.T) {
|
|
|
|
var m peerExchangeMessage
|
|
|
|
if err := bencode.Unmarshal([]byte("d5:added12:\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0ce"), &m); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(m.Added) != 2 {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
if m.Added[0].Port != 0x506 {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|