summaryrefslogtreecommitdiff
path: root/tests/Main.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-06-07 03:37:11 +0400
committerSam T <pxqr.sta@gmail.com>2013-06-07 03:37:11 +0400
commit095f22bba763aba8303322b104ae39e2ff2807c2 (patch)
tree2743e5c025e6934b247cee593fd693c23bb01892 /tests/Main.hs
parent558616b7dcc8955ab08fe8b194cdd5e128aba3f4 (diff)
~ Fix bug in torrent bencode instance.
Also add encoding tests for torrent module.
Diffstat (limited to 'tests/Main.hs')
-rw-r--r--tests/Main.hs43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/Main.hs b/tests/Main.hs
index 0aa6423f..ff571b6b 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -2,20 +2,35 @@
2module Main (main) where 2module Main (main) where
3 3
4import Control.Applicative 4import Control.Applicative
5import qualified Data.ByteString.Lazy as Lazy
5import Data.IntervalSet 6import Data.IntervalSet
6import Data.List as L 7import Data.List as L
7import Data.Ord 8import Data.Ord
9import Data.Maybe
8import Data.Word 10import Data.Word
11import Data.Text as T
12import Network.URI
9 13
10import Test.Framework (defaultMain) 14import Test.Framework (defaultMain)
11import Test.Framework.Providers.QuickCheck2 (testProperty) 15import Test.Framework.Providers.QuickCheck2 (testProperty)
12import Test.QuickCheck 16import Test.QuickCheck
13 17
18import Data.BEncode
14import Data.Bitfield as BF 19import Data.Bitfield as BF
20import Data.Torrent
15import Network.BitTorrent as BT 21import Network.BitTorrent as BT
16 22
23import Debug.Trace
17import Encoding 24import Encoding
18 25
26
27instance Arbitrary URI where
28 arbitrary = pure $ fromJust
29 $ parseURI "http://exsample.com:80/123365_asd"
30
31instance Arbitrary Text where
32 arbitrary = T.pack <$> arbitrary
33
19{----------------------------------------------------------------------- 34{-----------------------------------------------------------------------
20 Bitfield 35 Bitfield
21-----------------------------------------------------------------------} 36-----------------------------------------------------------------------}
@@ -51,8 +66,29 @@ prop_differenceDeMorgan a b c =
51 Torrent 66 Torrent
52-----------------------------------------------------------------------} 67-----------------------------------------------------------------------}
53 68
69prop_properBEncode :: Show a => BEncodable a => Eq a => T a -> a -> Bool
70prop_properBEncode _ expected = actual == Right expected
71 where
72 actual = decoded $ Lazy.toStrict $ encoded expected
73
74
54-- TODO tests for torrent: encoding <-> decoding 75-- TODO tests for torrent: encoding <-> decoding
76instance Arbitrary FileInfo where
77 arbitrary = FileInfo <$> arbitrary <*> arbitrary <*> arbitrary
55 78
79instance Arbitrary ContentInfo where
80 arbitrary = oneof
81 [ SingleFile <$> arbitrary <*> arbitrary <*> arbitrary
82 <*> arbitrary <*> arbitrary <*> arbitrary
83 , MultiFile <$> arbitrary <*> arbitrary <*> arbitrary
84 <*> arbitrary <*> arbitrary
85 ]
86
87instance Arbitrary Torrent where
88 arbitrary = torrent <$> arbitrary
89 <*> arbitrary <*> arbitrary <*> arbitrary
90 <*> arbitrary <*> arbitrary <*> arbitrary
91 <*> arbitrary <*> pure Nothing <*> arbitrary
56 92
57main :: IO () 93main :: IO ()
58main = defaultMain 94main = defaultMain
@@ -60,4 +96,11 @@ main = defaultMain
60 , testProperty "rarest in range" prop_rarestInRange 96 , testProperty "rarest in range" prop_rarestInRange
61 , testProperty "min less that max" prop_minMax 97 , testProperty "min less that max" prop_minMax
62 , testProperty "difference de morgan" prop_differenceDeMorgan 98 , testProperty "difference de morgan" prop_differenceDeMorgan
99
100 , testProperty "file info encoding" $
101 prop_properBEncode (T :: T FileInfo)
102 , testProperty "content info encoding" $
103 prop_properBEncode (T :: T ContentInfo)
104 , testProperty "torrent encoding" $
105 prop_properBEncode (T :: T Torrent)
63 ] 106 ]