From 863f7a236b86f562309748273f3087035a999ee7 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Mon, 3 Mar 2014 03:09:34 +0400 Subject: Rename Wire.hs to Connection.hs --- .../Network/BitTorrent/Exchange/ConnectionSpec.hs | 59 ++++++++++++++++++++++ tests/Network/BitTorrent/Exchange/WireSpec.hs | 59 ---------------------- 2 files changed, 59 insertions(+), 59 deletions(-) create mode 100644 tests/Network/BitTorrent/Exchange/ConnectionSpec.hs delete mode 100644 tests/Network/BitTorrent/Exchange/WireSpec.hs (limited to 'tests/Network') diff --git a/tests/Network/BitTorrent/Exchange/ConnectionSpec.hs b/tests/Network/BitTorrent/Exchange/ConnectionSpec.hs new file mode 100644 index 00000000..c21f55ef --- /dev/null +++ b/tests/Network/BitTorrent/Exchange/ConnectionSpec.hs @@ -0,0 +1,59 @@ +{-# LANGUAGE RecordWildCards #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +module Network.BitTorrent.Exchange.ConnectionSpec (spec) where +import Control.Applicative +import Control.Monad.Trans +import Data.Default +import Test.Hspec +import Test.QuickCheck + +import Data.Torrent +import Data.Torrent.InfoHash +import Network.BitTorrent.Core +import Network.BitTorrent.Exchange.Connection +import Network.BitTorrent.Exchange.Message + +import Config +import Network.BitTorrent.Exchange.MessageSpec () + +nullSession :: InfoHash -> PeerId -> SessionLink () +nullSession ih pid = SessionLink ih pid Nothing Nothing () + +instance Arbitrary Options where + arbitrary = return def + +instance Arbitrary ConnectionPrefs where + arbitrary = ConnectionPrefs <$> arbitrary <*> pure def + <*> arbitrary <*> arbitrary + +withWire :: ConnectionPrefs -> Wire () () -> IO () +withWire prefs wire = + withRemote $ \ ClientOpts {..} -> do + pid <- genPeerId + t <- getTestTorrent + let ih = idInfoHash (tInfoDict t) + let cfg = ConnectionConfig prefs (nullSession ih pid) (wire) + let addr = PeerAddr Nothing "127.0.0.1" peerPort + connectWire addr cfg + +spec :: Spec +spec = do + describe "connectWire" $ do + it "can establish connection with all possible preferences" $ + property $ \ prefs -> do + withWire prefs (return ()) + + it "must not connect with invalid topic" $ do + pending + + describe "acceptWire" $ do + it "" $ do + pending + + describe "messaging" $ do + it "first message is bitfield" $ do + withWire def $ do + msg <- recvMessage + let isBitfield (Available (Bitfield _)) = True + isBitfield _ = False + liftIO $ msg `shouldSatisfy` isBitfield diff --git a/tests/Network/BitTorrent/Exchange/WireSpec.hs b/tests/Network/BitTorrent/Exchange/WireSpec.hs deleted file mode 100644 index 293e1bd6..00000000 --- a/tests/Network/BitTorrent/Exchange/WireSpec.hs +++ /dev/null @@ -1,59 +0,0 @@ -{-# LANGUAGE RecordWildCards #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -module Network.BitTorrent.Exchange.WireSpec (spec) where -import Control.Applicative -import Control.Monad.Trans -import Data.Default -import Test.Hspec -import Test.QuickCheck - -import Data.Torrent -import Data.Torrent.InfoHash -import Network.BitTorrent.Core -import Network.BitTorrent.Exchange.Message -import Network.BitTorrent.Exchange.Wire - -import Config -import Network.BitTorrent.Exchange.MessageSpec () - -nullSession :: InfoHash -> PeerId -> SessionLink () -nullSession ih pid = SessionLink ih pid Nothing Nothing () - -instance Arbitrary Options where - arbitrary = return def - -instance Arbitrary ConnectionPrefs where - arbitrary = ConnectionPrefs <$> arbitrary <*> pure def - <*> arbitrary <*> arbitrary - -withWire :: ConnectionPrefs -> Wire () () -> IO () -withWire prefs wire = - withRemote $ \ ClientOpts {..} -> do - pid <- genPeerId - t <- getTestTorrent - let ih = idInfoHash (tInfoDict t) - let cfg = ConnectionConfig prefs (nullSession ih pid) (wire) - let addr = PeerAddr Nothing "127.0.0.1" peerPort - connectWire addr cfg - -spec :: Spec -spec = do - describe "connectWire" $ do - it "can establish connection with all possible preferences" $ - property $ \ prefs -> do - withWire prefs (return ()) - - it "must not connect with invalid topic" $ do - pending - - describe "acceptWire" $ do - it "" $ do - pending - - describe "messaging" $ do - it "first message is bitfield" $ do - withWire def $ do - msg <- recvMessage - let isBitfield (Available (Bitfield _)) = True - isBitfield _ = False - liftIO $ msg `shouldSatisfy` isBitfield -- cgit v1.2.3