summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-26 07:40:18 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-26 07:40:18 +0400
commitbec54f38a42f1f48aa9577a853c0288d46eec3ff (patch)
treedb9e9ca8f0c66a219b3227c34cd604deeb0b8845 /tests/Network/BitTorrent
parentca7ff6f0fc6e5e64a7d76784428da0f27c34175c (diff)
Add tests for NodeInfo module
Diffstat (limited to 'tests/Network/BitTorrent')
-rw-r--r--tests/Network/BitTorrent/Core/NodeSpec.hs39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/Network/BitTorrent/Core/NodeSpec.hs b/tests/Network/BitTorrent/Core/NodeSpec.hs
index b3bdf134..3f27f9eb 100644
--- a/tests/Network/BitTorrent/Core/NodeSpec.hs
+++ b/tests/Network/BitTorrent/Core/NodeSpec.hs
@@ -1,13 +1,16 @@
1{-# OPTIONS -fno-warn-orphans #-}
1module Network.BitTorrent.Core.NodeSpec (spec) where 2module Network.BitTorrent.Core.NodeSpec (spec) where
2import Control.Applicative 3import Control.Applicative
4import Data.Serialize as S
5import Data.String
3import Test.Hspec 6import Test.Hspec
4import Test.QuickCheck 7import Test.QuickCheck
5 8
6import Network.BitTorrent.Core.Node 9import Network.BitTorrent.Core
7import Network.BitTorrent.Core.PeerAddrSpec () 10import Network.BitTorrent.Core.PeerAddrSpec ()
8 11
9instance Arbitrary NodeId where 12instance Arbitrary NodeId where
10 arbitrary = undefined 13 arbitrary = fromString <$> vector 20
11 14
12instance Arbitrary a => Arbitrary (NodeAddr a) where 15instance Arbitrary a => Arbitrary (NodeAddr a) where
13 arbitrary = NodeAddr <$> arbitrary <*> arbitrary 16 arbitrary = NodeAddr <$> arbitrary <*> arbitrary
@@ -16,4 +19,34 @@ instance Arbitrary a => Arbitrary (NodeInfo a) where
16 arbitrary = NodeInfo <$> arbitrary <*> arbitrary 19 arbitrary = NodeInfo <$> arbitrary <*> arbitrary
17 20
18spec :: Spec 21spec :: Spec
19spec = return () \ No newline at end of file 22spec = do
23 describe "NodeId" $ do
24 it "properly serialized" $ do
25 S.decode "mnopqrstuvwxyz123456"
26 `shouldBe` Right ("mnopqrstuvwxyz123456" :: NodeId)
27
28 S.encode ("mnopqrstuvwxyz123456" :: NodeId)
29 `shouldBe` "mnopqrstuvwxyz123456"
30
31 it "properly serialized (iso)" $ property $ \ nid ->
32 S.decode (S.encode nid) `shouldBe`
33 Right (nid :: NodeId)
34
35 describe "NodeAddr" $ do
36 it "properly serialized" $ do
37 S.decode "\127\0\0\1\1\2" `shouldBe`
38 Right ("127.0.0.1:258" :: NodeAddr IPv4)
39
40 it "properly serialized (iso)" $ property $ \ nid ->
41 S.decode (S.encode nid) `shouldBe`
42 Right (nid :: NodeAddr IPv4)
43
44 describe "NodeInfo" $ do
45 it "properly serialized" $ do
46 S.decode "mnopqrstuvwxyz123456\
47 \\127\0\0\1\1\2" `shouldBe` Right
48 (NodeInfo "mnopqrstuvwxyz123456" "127.0.0.1:258" :: NodeInfo IPv4)
49
50 it "properly serialized (iso)" $ property $ \ nid ->
51 S.decode (S.encode nid) `shouldBe`
52 Right (nid :: NodeInfo IPv4)