diff options
Diffstat (limited to 'tests/Network')
-rw-r--r-- | tests/Network/BitTorrent/Core/NodeSpec.hs | 39 |
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 #-} | ||
1 | module Network.BitTorrent.Core.NodeSpec (spec) where | 2 | module Network.BitTorrent.Core.NodeSpec (spec) where |
2 | import Control.Applicative | 3 | import Control.Applicative |
4 | import Data.Serialize as S | ||
5 | import Data.String | ||
3 | import Test.Hspec | 6 | import Test.Hspec |
4 | import Test.QuickCheck | 7 | import Test.QuickCheck |
5 | 8 | ||
6 | import Network.BitTorrent.Core.Node | 9 | import Network.BitTorrent.Core |
7 | import Network.BitTorrent.Core.PeerAddrSpec () | 10 | import Network.BitTorrent.Core.PeerAddrSpec () |
8 | 11 | ||
9 | instance Arbitrary NodeId where | 12 | instance Arbitrary NodeId where |
10 | arbitrary = undefined | 13 | arbitrary = fromString <$> vector 20 |
11 | 14 | ||
12 | instance Arbitrary a => Arbitrary (NodeAddr a) where | 15 | instance 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 | ||
18 | spec :: Spec | 21 | spec :: Spec |
19 | spec = return () \ No newline at end of file | 22 | spec = 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) | ||