summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-08 08:03:21 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-08 08:03:21 +0400
commit18f29191f6092ba502b27a64b7b4abebeaa6dc88 (patch)
treec9fdfe51bcd34be58becde33fc7a6afe658a0f17 /tests/Network/BitTorrent
parent61c25c415049af15e88a18644e1f2df794140320 (diff)
Newtype protocol string in handshake
Diffstat (limited to 'tests/Network/BitTorrent')
-rw-r--r--tests/Network/BitTorrent/Exchange/MessageSpec.hs17
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 @@
1module Network.BitTorrent.Exchange.MessageSpec (spec) where 1module Network.BitTorrent.Exchange.MessageSpec (spec) where
2import Control.Applicative 2import Control.Applicative
3import Control.Exception
3import Data.ByteString as BS 4import Data.ByteString as BS
4import Data.Default 5import Data.Default
5import Data.List as L 6import Data.List as L
6import Data.Set as S 7import Data.Set as S
7import Data.Serialize as S 8import Data.Serialize as S
9import Data.String
8import Test.Hspec 10import Test.Hspec
9import Test.QuickCheck 11import Test.QuickCheck
10 12
@@ -19,6 +21,9 @@ instance Arbitrary Extension where
19instance Arbitrary Caps where 21instance Arbitrary Caps where
20 arbitrary = toCaps <$> arbitrary 22 arbitrary = toCaps <$> arbitrary
21 23
24instance Arbitrary ProtocolString where
25 arbitrary = fromString <$> (arbitrary `suchThat` ((200 <) . L.length))
26
22instance Arbitrary Handshake where 27instance 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