summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Exchange
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Network/BitTorrent/Exchange')
-rw-r--r--tests/Network/BitTorrent/Exchange/BitfieldSpec.hs13
-rw-r--r--tests/Network/BitTorrent/Exchange/ConnectionSpec.hs3
-rw-r--r--tests/Network/BitTorrent/Exchange/DownloadSpec.hs (renamed from tests/Network/BitTorrent/Exchange/Session/MetadataSpec.hs)32
-rw-r--r--tests/Network/BitTorrent/Exchange/MessageSpec.hs6
-rw-r--r--tests/Network/BitTorrent/Exchange/SessionSpec.hs2
5 files changed, 28 insertions, 28 deletions
diff --git a/tests/Network/BitTorrent/Exchange/BitfieldSpec.hs b/tests/Network/BitTorrent/Exchange/BitfieldSpec.hs
new file mode 100644
index 00000000..234965fa
--- /dev/null
+++ b/tests/Network/BitTorrent/Exchange/BitfieldSpec.hs
@@ -0,0 +1,13 @@
1{-# OPTIONS -fno-warn-orphans #-}
2module Network.BitTorrent.Exchange.BitfieldSpec (spec) where
3import Control.Applicative
4import Test.Hspec
5import Test.QuickCheck
6
7import Network.BitTorrent.Exchange.Bitfield
8
9instance Arbitrary Bitfield where
10 arbitrary = fromBitmap <$> arbitrary
11
12spec :: Spec
13spec = return () \ No newline at end of file
diff --git a/tests/Network/BitTorrent/Exchange/ConnectionSpec.hs b/tests/Network/BitTorrent/Exchange/ConnectionSpec.hs
index c21f55ef..d654cda1 100644
--- a/tests/Network/BitTorrent/Exchange/ConnectionSpec.hs
+++ b/tests/Network/BitTorrent/Exchange/ConnectionSpec.hs
@@ -8,8 +8,7 @@ import Test.Hspec
8import Test.QuickCheck 8import Test.QuickCheck
9 9
10import Data.Torrent 10import Data.Torrent
11import Data.Torrent.InfoHash 11import Network.BitTorrent.Address
12import Network.BitTorrent.Core
13import Network.BitTorrent.Exchange.Connection 12import Network.BitTorrent.Exchange.Connection
14import Network.BitTorrent.Exchange.Message 13import Network.BitTorrent.Exchange.Message
15 14
diff --git a/tests/Network/BitTorrent/Exchange/Session/MetadataSpec.hs b/tests/Network/BitTorrent/Exchange/DownloadSpec.hs
index 975ceb5b..d46f2034 100644
--- a/tests/Network/BitTorrent/Exchange/Session/MetadataSpec.hs
+++ b/tests/Network/BitTorrent/Exchange/DownloadSpec.hs
@@ -1,5 +1,5 @@
1{-# LANGUAGE RecordWildCards #-} 1{-# LANGUAGE RecordWildCards #-}
2module Network.BitTorrent.Exchange.Session.MetadataSpec (spec) where 2module Network.BitTorrent.Exchange.DownloadSpec (spec) where
3import Control.Concurrent 3import Control.Concurrent
4import Data.ByteString as BS 4import Data.ByteString as BS
5import Data.ByteString.Lazy as BL 5import Data.ByteString.Lazy as BL
@@ -7,11 +7,10 @@ import Test.Hspec
7import Test.QuickCheck 7import Test.QuickCheck
8 8
9import Data.BEncode as BE 9import Data.BEncode as BE
10import Data.Torrent 10import Data.Torrent as Torrent
11import Data.Torrent.Piece as P 11import Network.BitTorrent.Address
12import Network.BitTorrent.Core 12import Network.BitTorrent.Exchange.Download
13import Network.BitTorrent.Exchange.Message 13import Network.BitTorrent.Exchange.Message
14import Network.BitTorrent.Exchange.Session.Metadata
15 14
16import Config 15import Config
17import Network.BitTorrent.CoreSpec () 16import Network.BitTorrent.CoreSpec ()
@@ -25,27 +24,16 @@ chunkBy s bs
25 | BS.null bs = [] 24 | BS.null bs = []
26 | otherwise = BS.take s bs : chunkBy s (BS.drop s bs) 25 | otherwise = BS.take s bs : chunkBy s (BS.drop s bs)
27 26
28withUpdates :: Updates a -> IO a 27withUpdates :: Updates s a -> IO a
29withUpdates m = do 28withUpdates m = do
30 Torrent {..} <- getTestTorrent 29 Torrent {..} <- getTestTorrent
31 let infoDictLen = fromIntegral $ BL.length $ BE.encode tInfoDict 30 let infoDictLen = fromIntegral $ BL.length $ BE.encode tInfoDict
32 mvar <- newMVar (nullStatus infoDictLen) 31 --mvar <- newMVar (nullStatus infoDictLen)
33 runUpdates mvar placeholderAddr m 32 --runUpdates mvar placeholderAddr m
33 undefined
34 34
35simulateFetch :: InfoDict -> Updates (Maybe InfoDict) 35simulateFetch :: InfoDict -> Updates s (Maybe InfoDict)
36simulateFetch dict = go 36simulateFetch dict = undefined
37 where
38 blocks = chunkBy metadataPieceSize (BL.toStrict (BE.encode dict))
39 packPiece ix = P.Piece ix (blocks !! ix)
40 ih = idInfoHash dict
41
42 go = do
43 mix <- scheduleBlock
44 case mix of
45 Nothing -> return Nothing
46 Just ix -> do
47 mdict <- pushBlock (packPiece ix) ih
48 maybe go (return . Just) mdict
49 37
50spec :: Spec 38spec :: Spec
51spec = do 39spec = do
diff --git a/tests/Network/BitTorrent/Exchange/MessageSpec.hs b/tests/Network/BitTorrent/Exchange/MessageSpec.hs
index 63d814ff..d615b1ff 100644
--- a/tests/Network/BitTorrent/Exchange/MessageSpec.hs
+++ b/tests/Network/BitTorrent/Exchange/MessageSpec.hs
@@ -10,10 +10,10 @@ import Data.String
10import Test.Hspec 10import Test.Hspec
11import Test.QuickCheck 11import Test.QuickCheck
12 12
13import Data.Torrent.BitfieldSpec () 13import Data.TorrentSpec ()
14import Data.Torrent.InfoHashSpec () 14import Network.BitTorrent.Exchange.BitfieldSpec ()
15import Network.BitTorrent.CoreSpec () 15import Network.BitTorrent.CoreSpec ()
16import Network.BitTorrent.Core () 16import Network.BitTorrent.Address ()
17import Network.BitTorrent.Exchange.BlockSpec () 17import Network.BitTorrent.Exchange.BlockSpec ()
18import Network.BitTorrent.Exchange.Message 18import Network.BitTorrent.Exchange.Message
19 19
diff --git a/tests/Network/BitTorrent/Exchange/SessionSpec.hs b/tests/Network/BitTorrent/Exchange/SessionSpec.hs
index c2c76644..bf5b95a1 100644
--- a/tests/Network/BitTorrent/Exchange/SessionSpec.hs
+++ b/tests/Network/BitTorrent/Exchange/SessionSpec.hs
@@ -3,7 +3,7 @@ module Network.BitTorrent.Exchange.SessionSpec (spec) where
3import Test.Hspec 3import Test.Hspec
4 4
5import Data.Torrent 5import Data.Torrent
6import Network.BitTorrent.Core 6import Network.BitTorrent.Address
7import Network.BitTorrent.Exchange.Session 7import Network.BitTorrent.Exchange.Session
8 8
9import Config 9import Config