From 2ed8ba6370da4a216acbc58751e89773e8dfd1af Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Thu, 5 Dec 2013 02:58:19 +0400 Subject: Rename tracker Message module --- tests/Network/BitTorrent/Tracker/MessageSpec.hs | 65 ++++++++++++++++++++++ tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs | 2 +- .../Network/BitTorrent/Tracker/RPC/MessageSpec.hs | 65 ---------------------- tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs | 2 +- 4 files changed, 67 insertions(+), 67 deletions(-) create mode 100644 tests/Network/BitTorrent/Tracker/MessageSpec.hs delete mode 100644 tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs (limited to 'tests/Network') diff --git a/tests/Network/BitTorrent/Tracker/MessageSpec.hs b/tests/Network/BitTorrent/Tracker/MessageSpec.hs new file mode 100644 index 00000000..8ae1a1cc --- /dev/null +++ b/tests/Network/BitTorrent/Tracker/MessageSpec.hs @@ -0,0 +1,65 @@ +{-# LANGUAGE RecordWildCards #-} +{-# OPTIONS -fno-warn-orphans #-} +module Network.BitTorrent.Tracker.MessageSpec + ( spec + , validateInfo + , arbitrarySample + ) where + +import Control.Applicative +import Data.List as L +import Data.Maybe +import Data.Word +import Network +import Test.Hspec +import Test.QuickCheck + +import Data.Torrent.InfoHashSpec () +import Data.Torrent.ProgressSpec () +import Network.BitTorrent.Core.PeerIdSpec () + +import Network.BitTorrent.Tracker.Message as Message +import Network.BitTorrent.Core.PeerAddr + + +--prop_bencode :: Eq a => BEncode a => a -> Bool +--prop_bencode a = BE.decode (BL.toStrict (BE.encode a)) == return a + +--prop_urlencode :: Eq a => URLDecoded a => URLEncoded a => a -> Bool +--prop_urlencode a = urlDecode (T.pack (urlEncode a)) == a + +instance Arbitrary Event where + arbitrary = elements [minBound..maxBound] + +instance Arbitrary PortNumber where + arbitrary = fromIntegral <$> (arbitrary :: Gen Word16) + +instance Arbitrary AnnounceQuery where + arbitrary = AnnounceQuery + <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary + <*> arbitrary <*> arbitrary <*> arbitrary + +validateInfo :: AnnounceQuery -> AnnounceInfo -> Expectation +validateInfo _ Message.Failure {..} = error "validateInfo: failure" +validateInfo AnnounceQuery {..} AnnounceInfo {..} = do + respComplete `shouldSatisfy` isJust + respIncomplete `shouldSatisfy` isJust + respMinInterval `shouldSatisfy` isNothing + respWarning `shouldSatisfy` isNothing + peerList `shouldSatisfy` L.all (isNothing . peerID) + fromJust respComplete + fromJust respIncomplete `shouldBe` L.length peerList + where + peerList = getPeerList respPeers + +arbitrarySample :: Arbitrary a => IO a +arbitrarySample = L.head <$> sample' arbitrary + +spec :: Spec +spec = do + describe "Announce" $ do + it "properly url encoded" $ property $ \ q -> + parseAnnounceQuery (renderAnnounceQuery q) + `shouldBe` Right q + + describe "Scrape" $ do + return () diff --git a/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs index 141a2597..6ff68cdf 100644 --- a/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs +++ b/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs @@ -9,7 +9,7 @@ import Data.Maybe import Network.URI import Test.Hspec -import Network.BitTorrent.Tracker.RPC.MessageSpec hiding (spec) +import Network.BitTorrent.Tracker.MessageSpec hiding (spec) import Network.BitTorrent.Tracker.RPC.HTTP diff --git a/tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs deleted file mode 100644 index f8cf052a..00000000 --- a/tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs +++ /dev/null @@ -1,65 +0,0 @@ -{-# LANGUAGE RecordWildCards #-} -{-# OPTIONS -fno-warn-orphans #-} -module Network.BitTorrent.Tracker.RPC.MessageSpec - ( spec - , validateInfo - , arbitrarySample - ) where - -import Control.Applicative -import Data.List as L -import Data.Maybe -import Data.Word -import Network -import Test.Hspec -import Test.QuickCheck - -import Data.Torrent.InfoHashSpec () -import Data.Torrent.ProgressSpec () -import Network.BitTorrent.Core.PeerIdSpec () - -import Network.BitTorrent.Tracker.RPC.Message as Message -import Network.BitTorrent.Core.PeerAddr - - ---prop_bencode :: Eq a => BEncode a => a -> Bool ---prop_bencode a = BE.decode (BL.toStrict (BE.encode a)) == return a - ---prop_urlencode :: Eq a => URLDecoded a => URLEncoded a => a -> Bool ---prop_urlencode a = urlDecode (T.pack (urlEncode a)) == a - -instance Arbitrary Event where - arbitrary = elements [minBound..maxBound] - -instance Arbitrary PortNumber where - arbitrary = fromIntegral <$> (arbitrary :: Gen Word16) - -instance Arbitrary AnnounceQuery where - arbitrary = AnnounceQuery - <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary - <*> arbitrary <*> arbitrary <*> arbitrary - -validateInfo :: AnnounceQuery -> AnnounceInfo -> Expectation -validateInfo _ Message.Failure {..} = error "validateInfo: failure" -validateInfo AnnounceQuery {..} AnnounceInfo {..} = do - respComplete `shouldSatisfy` isJust - respIncomplete `shouldSatisfy` isJust - respMinInterval `shouldSatisfy` isNothing - respWarning `shouldSatisfy` isNothing - peerList `shouldSatisfy` L.all (isNothing . peerID) - fromJust respComplete + fromJust respIncomplete `shouldBe` L.length peerList - where - peerList = getPeerList respPeers - -arbitrarySample :: Arbitrary a => IO a -arbitrarySample = L.head <$> sample' arbitrary - -spec :: Spec -spec = do - describe "Announce" $ do - it "properly url encoded" $ property $ \ q -> - parseAnnounceQuery (renderAnnounceQuery q) - `shouldBe` Right q - - describe "Scrape" $ do - return () diff --git a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs index 4954ee25..53babbb3 100644 --- a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs +++ b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs @@ -8,7 +8,7 @@ import Data.Maybe import Network.URI import Test.Hspec -import Network.BitTorrent.Tracker.RPC.MessageSpec hiding (spec) +import Network.BitTorrent.Tracker.MessageSpec hiding (spec) import Network.BitTorrent.Tracker.RPC.UDP -- cgit v1.2.3