summaryrefslogtreecommitdiff
path: root/tests/Main.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-04 02:09:45 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-04 02:09:45 +0400
commit6906ff501b31ea0328c6db4038ada43e53a7d46b (patch)
tree45a2f471f84abce6b5561da7e4ad16dbb2e4cc23 /tests/Main.hs
parentb86c21c92187008a692ad6ee8b33b4edd50447d3 (diff)
~ Move info hash test to main test suite.
Diffstat (limited to 'tests/Main.hs')
-rw-r--r--tests/Main.hs40
1 files changed, 30 insertions, 10 deletions
diff --git a/tests/Main.hs b/tests/Main.hs
index bcadc97e..3c7bfcd3 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -16,7 +16,9 @@ import Data.Text as T
16 16
17import Network 17import Network
18import Network.URI 18import Network.URI
19
19import System.Directory 20import System.Directory
21import System.FilePath
20 22
21import Test.QuickCheck as QC 23import Test.QuickCheck as QC
22import Test.HUnit as HU 24import Test.HUnit as HU
@@ -105,6 +107,18 @@ instance Arbitrary Torrent where
105 <*> arbitrary <*> arbitrary <*> arbitrary 107 <*> arbitrary <*> arbitrary <*> arbitrary
106 <*> arbitrary <*> pure Nothing <*> arbitrary 108 <*> arbitrary <*> pure Nothing <*> arbitrary
107 109
110-- TODO add a few more torrents here
111torrentList :: [(FilePath, String)]
112torrentList =
113 [ ( "res" </> "dapper-dvd-amd64.iso.torrent"
114 , "0221caf96aa3cb94f0f58d458e78b0fc344ad8bf")
115 ]
116
117checkInfoHash :: (FilePath, String) -> Assertion
118checkInfoHash (path, expectedHash) = check =<< fromFile path
119 where
120 check t = expectedHash @=? show (ppInfoHash (tInfoHash t))
121
108{----------------------------------------------------------------------- 122{-----------------------------------------------------------------------
109 Handshake 123 Handshake
110-----------------------------------------------------------------------} 124-----------------------------------------------------------------------}
@@ -210,6 +224,10 @@ prop_messageEncoding msg
210 MemMap 224 MemMap
211-----------------------------------------------------------------------} 225-----------------------------------------------------------------------}
212 226
227tmpdir :: FilePath
228tmpdir = "tmp"
229
230boundaryTest :: Assertion
213boundaryTest = do 231boundaryTest = do
214 f <- mallocTo (Fixed.interval 0 1) Fixed.empty 232 f <- mallocTo (Fixed.interval 0 1) Fixed.empty
215 f <- mallocTo (Fixed.interval 1 2) f 233 f <- mallocTo (Fixed.interval 1 2) f
@@ -218,16 +236,18 @@ boundaryTest = do
218 bs <- readBytes (Fixed.interval 0 2) f 236 bs <- readBytes (Fixed.interval 0 2) f
219 "\x1\x2" @=? bs 237 "\x1\x2" @=? bs
220 238
239mmapSingle :: Assertion
221mmapSingle = do 240mmapSingle = do
222 f <- mmapTo "single.test" (10, 5) 5 Fixed.empty 241 f <- mmapTo (tmpdir </> "single.test") (10, 5) 5 Fixed.empty
223 writeBytes (Fixed.interval 5 5) "abcde" f 242 writeBytes (Fixed.interval 5 5) "abcde" f
224 bs <- readBytes (Fixed.interval 5 5) f 243 bs <- readBytes (Fixed.interval 5 5) f
225 "abcde" @=? bs 244 "abcde" @=? bs
226 245
246coalesceTest :: Assertion
227coalesceTest = do 247coalesceTest = do
228 f <- mmapTo "a.test" (0, 1) 10 Fixed.empty 248 f <- mmapTo (tmpdir </> "a.test") (0, 1) 10 Fixed.empty
229 f <- mmapTo "bc.test" (0, 2) 12 f 249 f <- mmapTo (tmpdir </> "bc.test") (0, 2) 12 f
230 f <- mmapTo "c.test" (0, 1) 13 f 250 f <- mmapTo (tmpdir </> "c.test") (0, 1) 13 f
231 writeBytes (Fixed.interval 10 4) "abcd" f 251 writeBytes (Fixed.interval 10 4) "abcd" f
232 bs <- readBytes (Fixed.interval 10 4) f 252 bs <- readBytes (Fixed.interval 10 4) f
233 "abcd" @=? bs 253 "abcd" @=? bs
@@ -243,6 +263,7 @@ allTests =
243 , testProperty "rarest in range" prop_rarestInRange 263 , testProperty "rarest in range" prop_rarestInRange
244 , testProperty "min less that max" prop_minMax 264 , testProperty "min less that max" prop_minMax
245 , testProperty "difference de morgan" prop_differenceDeMorgan 265 , testProperty "difference de morgan" prop_differenceDeMorgan
266
246 -- torrent module 267 -- torrent module
247 , testProperty "file info encoding" $ 268 , testProperty "file info encoding" $
248 prop_properBEncode (T :: T FileInfo) 269 prop_properBEncode (T :: T FileInfo)
@@ -250,9 +271,11 @@ allTests =
250 prop_properBEncode (T :: T ContentInfo) 271 prop_properBEncode (T :: T ContentInfo)
251 , testProperty "torrent encoding" $ 272 , testProperty "torrent encoding" $
252 prop_properBEncode (T :: T Torrent) 273 prop_properBEncode (T :: T Torrent)
253 274 ] ++
254 -- handshake module 275 fmap (testCase "info hash" . checkInfoHash) torrentList
255 , testProperty "handshake encoding" $ 276 ++
277 [ -- handshake module
278 testProperty "handshake encoding" $
256 prop_cerealEncoding (T :: T Handshake) 279 prop_cerealEncoding (T :: T Handshake)
257 , testProperty "message encoding" prop_messageEncoding 280 , testProperty "message encoding" prop_messageEncoding
258 281
@@ -264,8 +287,5 @@ allTests =
264 287
265main :: IO () 288main :: IO ()
266main = do 289main = do
267 let tmpdir = "tmp" -- for mem map test cases
268 createDirectoryIfMissing True tmpdir 290 createDirectoryIfMissing True tmpdir
269 setCurrentDirectory tmpdir
270
271 defaultMain allTests 291 defaultMain allTests