From 0ec645b8e89c9b0177377812f7e4035c2c94ce1b Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Tue, 26 Nov 2013 06:25:25 +0400 Subject: Add Arbitrary instance for AnnounceQuery --- tests/Data/Torrent/ProgressSpec.hs | 13 +++++++ tests/Network/BitTorrent/Core/PeerIdSpec.hs | 15 ++++++++ tests/Network/BitTorrent/Tracker/MessageSpec.hs | 47 +++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 tests/Data/Torrent/ProgressSpec.hs create mode 100644 tests/Network/BitTorrent/Core/PeerIdSpec.hs create mode 100644 tests/Network/BitTorrent/Tracker/MessageSpec.hs (limited to 'tests') diff --git a/tests/Data/Torrent/ProgressSpec.hs b/tests/Data/Torrent/ProgressSpec.hs new file mode 100644 index 00000000..32efbd7a --- /dev/null +++ b/tests/Data/Torrent/ProgressSpec.hs @@ -0,0 +1,13 @@ +{-# OPTIONS -fno-warn-orphans #-} +module Data.Torrent.ProgressSpec (spec) where +import Control.Applicative +import Test.Hspec +import Test.QuickCheck +import Data.Torrent.Progress + + +instance Arbitrary Progress where + arbitrary = Progress <$> arbitrary <*> arbitrary <*> arbitrary + +spec :: Spec +spec = return () diff --git a/tests/Network/BitTorrent/Core/PeerIdSpec.hs b/tests/Network/BitTorrent/Core/PeerIdSpec.hs new file mode 100644 index 00000000..7ed8a976 --- /dev/null +++ b/tests/Network/BitTorrent/Core/PeerIdSpec.hs @@ -0,0 +1,15 @@ +module Network.BitTorrent.Core.PeerIdSpec (spec) where +import Control.Applicative +import Test.Hspec +import Test.QuickCheck +import Network.BitTorrent.Core.PeerId + + +instance Arbitrary PeerId where + arbitrary = oneof + [ azureusStyle defaultClientId defaultVersionNumber <$> arbitrary + , shadowStyle 'X' defaultVersionNumber <$> arbitrary + ] + +spec :: Spec +spec = return () \ No newline at end of file diff --git a/tests/Network/BitTorrent/Tracker/MessageSpec.hs b/tests/Network/BitTorrent/Tracker/MessageSpec.hs new file mode 100644 index 00000000..62b4ab04 --- /dev/null +++ b/tests/Network/BitTorrent/Tracker/MessageSpec.hs @@ -0,0 +1,47 @@ +{-# OPTIONS -fno-warn-orphans #-} +module Network.BitTorrent.Tracker.MessageSpec (spec) where + +import Control.Applicative +import Data.BEncode as BE +import Data.ByteString.Lazy as BL +import Data.Maybe +import Data.Word +import Network +import Network.URI +import Test.Hspec +import Test.QuickCheck +import Network.HTTP.Types.URI + +import Data.Torrent.InfoHashSpec hiding (spec) +import Data.Torrent.ProgressSpec hiding (spec) +import Network.BitTorrent.Core.PeerIdSpec hiding (spec) + +import Network.BitTorrent.Tracker.Message + + +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 + +baseURI :: URI +baseURI = fromJust $ parseURI "http://a" + +spec :: Spec +spec = do + describe "Announce" $ do + return () + describe "Scrape" $ do + return () -- cgit v1.2.3