summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Exchange/DownloadSpec.hs
blob: d46f2034f21d2231ea1fa591ee2e20940c44378c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{-# LANGUAGE RecordWildCards #-}
module Network.BitTorrent.Exchange.DownloadSpec (spec) where
import Control.Concurrent
import Data.ByteString as BS
import Data.ByteString.Lazy as BL
import Test.Hspec
import Test.QuickCheck

import Data.BEncode as BE
import Data.Torrent as Torrent
import Network.BitTorrent.Address
import Network.BitTorrent.Exchange.Download
import Network.BitTorrent.Exchange.Message

import Config
import Network.BitTorrent.CoreSpec ()


placeholderAddr :: PeerAddr IP
placeholderAddr = "0.0.0.0:0"

chunkBy :: Int -> BS.ByteString -> [BS.ByteString]
chunkBy s bs
  | BS.null bs = []
  | otherwise  = BS.take s bs : chunkBy s (BS.drop s bs)

withUpdates :: Updates s a -> IO a
withUpdates m = do
  Torrent {..} <- getTestTorrent
  let infoDictLen = fromIntegral $ BL.length $ BE.encode tInfoDict
  --mvar <- newMVar (nullStatus infoDictLen)
  --runUpdates mvar placeholderAddr m
  undefined

simulateFetch :: InfoDict -> Updates s (Maybe InfoDict)
simulateFetch dict = undefined

spec :: Spec
spec = do
  describe "scheduleBlock" $ do
    it "never schedule the same index twice" $ do
      pending

  describe "resetPending" $ do
    it "" $ do
      pending

  describe "cancelPending" $ do
    it "must not throw an exception if cancel the same piece twice" $ do
      pending

  describe "pushBlock" $ do
    it "assemble infodict from chunks" $ do
      Torrent {..} <- getTestTorrent
      mdict <- withUpdates $ simulateFetch tInfoDict
      mdict `shouldBe` Just tInfoDict

    it "must throw an exception if block if not requested" $ do
      pending