Exemplo n.º 1
0
        public void TestAllUniquePiecesChosenByNextPiece()
        {
            MetaInfoFile file = new MetaInfoFile(Constants.SingleFileTorrent);

            file.Parse();
            Manager          manager   = new Manager();
            TorrentContext   tc        = new TorrentContext(file, new Selector(), new DiskIO(manager), Constants.DestinationDirectory);
            HashSet <UInt32> pieces    = new HashSet <UInt32>();
            Selector         selector  = new Selector();
            UInt32           nextPiece = 0;

            for (UInt32 pieceNumber = 0; pieceNumber < tc.numberOfPieces; pieceNumber++)
            {
                tc.IncrementPeerCount(pieceNumber);
            }
            while (selector.NextPiece(tc, ref nextPiece))
            {
                if ((nextPiece >= 0) && (nextPiece < tc.numberOfPieces))
                {
                    pieces.Add(nextPiece);
                    tc.MarkPieceMissing(nextPiece, false);
                }
            }
            Assert.False(selector.NextPiece(tc, ref nextPiece));
            Assert.Equal(tc.numberOfPieces, pieces.Count);
        }
Exemplo n.º 2
0
        public void TestMarkPieceMissingWithInvalidPieceNumber()
        {
            MetaInfoFile file = new MetaInfoFile(Constants.SingleFileTorrent);

            file.Parse();
            TorrentContext tc = new TorrentContext(file, new Selector(), new DiskIO(new Manager()), Constants.DestinationDirectory);

            Assert.Throws <IndexOutOfRangeException>(() => tc.MarkPieceMissing(Constants.InvalidPieceNumber, true));
        }
Exemplo n.º 3
0
        public void TestReturnCorrectLastMissingPieceOnCallToNextPiece(UInt32 expected)
        {
            MetaInfoFile file = new MetaInfoFile(Constants.SingleFileTorrent);

            file.Parse();
            Manager        manager  = new Manager();
            TorrentContext tc       = new TorrentContext(file, new Selector(), new DiskIO(manager), Constants.DestinationDirectory);
            UInt32         actual   = 0;
            Selector       selector = new Selector();

            for (UInt32 pieceNumber = 0; pieceNumber < tc.numberOfPieces; pieceNumber++)
            {
                tc.IncrementPeerCount(pieceNumber);
                tc.MarkPieceMissing(pieceNumber, false);
            }
            tc.MarkPieceMissing(expected, true);
            Assert.True(selector.NextPiece(tc, ref actual));
            Assert.Equal(expected, actual);
        }
Exemplo n.º 4
0
        public void TestNoMissingPiecesOnCallToNextPiece()
        {
            MetaInfoFile file = new MetaInfoFile(Constants.SingleFileTorrent);

            file.Parse();
            Manager        manager   = new Manager();
            TorrentContext tc        = new TorrentContext(file, new Selector(), new DiskIO(manager), Constants.DestinationDirectory);
            UInt32         nextPiece = 0;
            Selector       selector  = new Selector();

            for (UInt32 pieceNumber = 0; pieceNumber < tc.numberOfPieces; pieceNumber++)
            {
                tc.IncrementPeerCount(pieceNumber);
                tc.MarkPieceMissing(pieceNumber, false);
            }
            Assert.False(selector.NextPiece(tc, ref nextPiece));
        }