diff options
Diffstat (limited to 'tests/Network')
-rw-r--r-- | tests/Network/BitTorrent/Exchange/MessageSpec.hs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tests/Network/BitTorrent/Exchange/MessageSpec.hs b/tests/Network/BitTorrent/Exchange/MessageSpec.hs index 8d1041dd..38a20112 100644 --- a/tests/Network/BitTorrent/Exchange/MessageSpec.hs +++ b/tests/Network/BitTorrent/Exchange/MessageSpec.hs | |||
@@ -1,10 +1,12 @@ | |||
1 | module Network.BitTorrent.Exchange.MessageSpec (spec) where | 1 | module Network.BitTorrent.Exchange.MessageSpec (spec) where |
2 | import Control.Applicative | 2 | import Control.Applicative |
3 | import Control.Exception | ||
3 | import Data.ByteString as BS | 4 | import Data.ByteString as BS |
4 | import Data.Default | 5 | import Data.Default |
5 | import Data.List as L | 6 | import Data.List as L |
6 | import Data.Set as S | 7 | import Data.Set as S |
7 | import Data.Serialize as S | 8 | import Data.Serialize as S |
9 | import Data.String | ||
8 | import Test.Hspec | 10 | import Test.Hspec |
9 | import Test.QuickCheck | 11 | import Test.QuickCheck |
10 | 12 | ||
@@ -19,6 +21,9 @@ instance Arbitrary Extension where | |||
19 | instance Arbitrary Caps where | 21 | instance Arbitrary Caps where |
20 | arbitrary = toCaps <$> arbitrary | 22 | arbitrary = toCaps <$> arbitrary |
21 | 23 | ||
24 | instance Arbitrary ProtocolString where | ||
25 | arbitrary = fromString <$> (arbitrary `suchThat` ((200 <) . L.length)) | ||
26 | |||
22 | instance Arbitrary Handshake where | 27 | instance Arbitrary Handshake where |
23 | arbitrary = Handshake <$> arbitrary <*> arbitrary | 28 | arbitrary = Handshake <$> arbitrary <*> arbitrary |
24 | <*> arbitrary <*> arbitrary | 29 | <*> arbitrary <*> arbitrary |
@@ -33,11 +38,13 @@ spec = do | |||
33 | S.fromList (fromCaps (toCaps (S.toList extSet) :: Caps)) | 38 | S.fromList (fromCaps (toCaps (S.toList extSet) :: Caps)) |
34 | `shouldBe` extSet | 39 | `shouldBe` extSet |
35 | 40 | ||
41 | describe "ProtocolString" $ do | ||
42 | it "fail to construct invalid string" $ do | ||
43 | let str = L.replicate 500 'x' | ||
44 | evaluate (fromString str :: ProtocolString) | ||
45 | `shouldThrow` | ||
46 | errorCall ("fromString: ProtocolString too long: " ++ str) | ||
47 | |||
36 | describe "Handshake" $ do | 48 | describe "Handshake" $ do |
37 | it "properly serialized" $ property $ \ hs -> | 49 | it "properly serialized" $ property $ \ hs -> |
38 | S.decode (S.encode hs ) `shouldBe` Right (hs :: Handshake) | 50 | S.decode (S.encode hs ) `shouldBe` Right (hs :: Handshake) |
39 | |||
40 | it "fail if protocol string is too long" $ do | ||
41 | pid <- genPeerId | ||
42 | let hs = (defaultHandshake def pid) {hsProtocol = BS.replicate 256 0} | ||
43 | S.decode (S.encode hs) `shouldBe` Right hs \ No newline at end of file | ||