diff options
-rw-r--r-- | bittorrent.cabal | 9 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker/Message.hs | 2 | ||||
-rw-r--r-- | tests/Data/Torrent/ProgressSpec.hs | 13 | ||||
-rw-r--r-- | tests/Network/BitTorrent/Core/PeerIdSpec.hs | 15 | ||||
-rw-r--r-- | tests/Network/BitTorrent/Tracker/MessageSpec.hs | 47 |
5 files changed, 83 insertions, 3 deletions
diff --git a/bittorrent.cabal b/bittorrent.cabal index 403837ba..dbc9d96a 100644 --- a/bittorrent.cabal +++ b/bittorrent.cabal | |||
@@ -143,10 +143,13 @@ test-suite spec | |||
143 | type: exitcode-stdio-1.0 | 143 | type: exitcode-stdio-1.0 |
144 | hs-source-dirs: tests | 144 | hs-source-dirs: tests |
145 | main-is: Spec.hs | 145 | main-is: Spec.hs |
146 | other-modules: Data.Torrent.MagnetSpec | 146 | other-modules: Data.Torrent.ClientSpec |
147 | Data.Torrent.InfoHashSpec | 147 | Data.Torrent.InfoHashSpec |
148 | Data.Torrent.MagnetSpec | ||
148 | Data.Torrent.MetainfoSpec | 149 | Data.Torrent.MetainfoSpec |
149 | Data.Torrent.ClientSpec | 150 | Data.Torrent.ProgressSpec |
151 | Network.BitTorrent.Core.PeerIdSpec | ||
152 | Network.BitTorrent.Tracker.MessageSpec | ||
150 | build-depends: base == 4.* | 153 | build-depends: base == 4.* |
151 | , bytestring | 154 | , bytestring |
152 | , directory | 155 | , directory |
@@ -161,7 +164,7 @@ test-suite spec | |||
161 | , hspec | 164 | , hspec |
162 | , QuickCheck | 165 | , QuickCheck |
163 | , quickcheck-instances | 166 | , quickcheck-instances |
164 | 167 | , http-types | |
165 | , bencoding | 168 | , bencoding |
166 | , bittorrent | 169 | , bittorrent |
167 | ghc-options: -Wall -fno-warn-orphans | 170 | ghc-options: -Wall -fno-warn-orphans |
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs index e49a9e58..53d7a946 100644 --- a/src/Network/BitTorrent/Tracker/Message.hs +++ b/src/Network/BitTorrent/Tracker/Message.hs | |||
@@ -417,6 +417,8 @@ missingOffset = 101 | |||
417 | invalidOffset :: Int | 417 | invalidOffset :: Int |
418 | invalidOffset = 150 | 418 | invalidOffset = 150 |
419 | 419 | ||
420 | -- TODO use Network.HTTP.Types.Status | ||
421 | |||
420 | -- | Get HTTP response error code from a announce params parse | 422 | -- | Get HTTP response error code from a announce params parse |
421 | -- failure. | 423 | -- failure. |
422 | -- | 424 | -- |
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 @@ | |||
1 | {-# OPTIONS -fno-warn-orphans #-} | ||
2 | module Data.Torrent.ProgressSpec (spec) where | ||
3 | import Control.Applicative | ||
4 | import Test.Hspec | ||
5 | import Test.QuickCheck | ||
6 | import Data.Torrent.Progress | ||
7 | |||
8 | |||
9 | instance Arbitrary Progress where | ||
10 | arbitrary = Progress <$> arbitrary <*> arbitrary <*> arbitrary | ||
11 | |||
12 | spec :: Spec | ||
13 | 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 @@ | |||
1 | module Network.BitTorrent.Core.PeerIdSpec (spec) where | ||
2 | import Control.Applicative | ||
3 | import Test.Hspec | ||
4 | import Test.QuickCheck | ||
5 | import Network.BitTorrent.Core.PeerId | ||
6 | |||
7 | |||
8 | instance Arbitrary PeerId where | ||
9 | arbitrary = oneof | ||
10 | [ azureusStyle defaultClientId defaultVersionNumber <$> arbitrary | ||
11 | , shadowStyle 'X' defaultVersionNumber <$> arbitrary | ||
12 | ] | ||
13 | |||
14 | spec :: Spec | ||
15 | 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 @@ | |||
1 | {-# OPTIONS -fno-warn-orphans #-} | ||
2 | module Network.BitTorrent.Tracker.MessageSpec (spec) where | ||
3 | |||
4 | import Control.Applicative | ||
5 | import Data.BEncode as BE | ||
6 | import Data.ByteString.Lazy as BL | ||
7 | import Data.Maybe | ||
8 | import Data.Word | ||
9 | import Network | ||
10 | import Network.URI | ||
11 | import Test.Hspec | ||
12 | import Test.QuickCheck | ||
13 | import Network.HTTP.Types.URI | ||
14 | |||
15 | import Data.Torrent.InfoHashSpec hiding (spec) | ||
16 | import Data.Torrent.ProgressSpec hiding (spec) | ||
17 | import Network.BitTorrent.Core.PeerIdSpec hiding (spec) | ||
18 | |||
19 | import Network.BitTorrent.Tracker.Message | ||
20 | |||
21 | |||
22 | prop_bencode :: Eq a => BEncode a => a -> Bool | ||
23 | prop_bencode a = BE.decode (BL.toStrict (BE.encode a)) == return a | ||
24 | |||
25 | --prop_urlencode :: Eq a => URLDecoded a => URLEncoded a => a -> Bool | ||
26 | --prop_urlencode a = urlDecode (T.pack (urlEncode a)) == a | ||
27 | |||
28 | instance Arbitrary Event where | ||
29 | arbitrary = elements [minBound..maxBound] | ||
30 | |||
31 | instance Arbitrary PortNumber where | ||
32 | arbitrary = fromIntegral <$> (arbitrary :: Gen Word16) | ||
33 | |||
34 | instance Arbitrary AnnounceQuery where | ||
35 | arbitrary = AnnounceQuery | ||
36 | <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary | ||
37 | <*> arbitrary <*> arbitrary <*> arbitrary | ||
38 | |||
39 | baseURI :: URI | ||
40 | baseURI = fromJust $ parseURI "http://a" | ||
41 | |||
42 | spec :: Spec | ||
43 | spec = do | ||
44 | describe "Announce" $ do | ||
45 | return () | ||
46 | describe "Scrape" $ do | ||
47 | return () | ||