From e25e6620e9b648284b07c065199d3732e3360472 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Fri, 28 Jul 2017 18:51:48 +0530 Subject: [PATCH] add a new test file for multifile torrent --- data/multifile.torrent | 2 ++ test/MetainfoTests.hs | 56 ++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 data/multifile.torrent diff --git a/data/multifile.torrent b/data/multifile.torrent new file mode 100644 index 0000000..fbd8035 --- /dev/null +++ b/data/multifile.torrent @@ -0,0 +1,2 @@ +d8:announce30:udp://example.tracker.org:696910:created by26:Enhanced-CTorrent/dnh3.3.213:creation datei1501246364e4:infod5:filesld6:lengthi1947461e4:pathl14:rust-talk.htmleed6:lengthi250e4:pathl4:.git6:configeed6:lengthi1262e4:pathl4:.git4:logs4:refs7:remotes6:origin6:mastereed6:lengthi195e4:pathl4:.git4:logs4:refs7:remotes6:origin4:HEADeed6:lengthi1671e4:pathl4:.git4:logs4:refs5:heads6:mastereed6:lengthi1671e4:pathl4:.git4:logs4:HEADeed6:lengthi41e4:pathl4:.git4:refs7:remotes6:origin6:mastereed6:lengthi32e4:pathl4:.git4:refs7:remotes6:origin4:HEADeed6:lengthi41e4:pathl4:.git4:refs5:heads6:mastereed6:lengthi240e4:pathl4:.git4:info7:excludeeed6:lengthi107e4:pathl4:.git11:packed-refseed6:lengthi212e4:pathl4:.git7:objects2:bc38:03296a94a64bdf66731b8e5d636aec86af5d38eed6:lengthi3656e4:pathl4:.git7:objects2:3238:3f53f70937f01b21a8aab05215d15353daf5b9eed6:lengthi212e4:pathl4:.git7:objects2:6a38:0af23e7ccf42f8f18cf92e7979ee3f519cc15beed6:lengthi8907e4:pathl4:.git7:objects2:1c38:839031c31daac86f5c192356c1bc27cbb0abbfeed6:lengthi212e4:pathl4:.git7:objects2:db38:0d94c478c786fb75828a5fea332ef35278dbb8eed6:lengthi172e4:pathl4:.git7:objects2:2538:7f24227cdf72cfd8fb9e5b178c0cc6ef2878d7eed6:lengthi159e4:pathl4:.git7:objects2:c038:8eb6d42faec475bf80276757fb705c8fc7e564eed6:lengthi175e4:pathl4:.git7:objects2:9938:34f6982f30b04f8dfb41e0900ea26d6af418beeed6:lengthi251856e4:pathl4:.git7:objects2:a738:1ecb52b270a9f475613a6b37b89660d4348497eed6:lengthi82e4:pathl4:.git7:objects2:dd38:27ca9e6377d791413d29e0361b99cbca709a6beed6:lengthi180e4:pathl4:.git7:objects2:ee38:f448b48dfaa7f89d5b42eb3287789d86a6492ceed6:lengthi185e4:pathl4:.git7:objects2:5038:b9b750e9e76fa1c9b63ccccfcad2f43d733e2aeed6:lengthi53e4:pathl4:.git7:objects2:ed38:de6d9cb4392573151ee69588bfd667f00330b3eed6:lengthi3071e4:pathl4:.git7:objects2:6538:8f853e2a922261056a1c37bc673bbe823ce93beed6:lengthi3551e4:pathl4:.git7:objects2:2d38:6e639e9b89f3e5a7b6adb6174834131163b2d5eed6:lengthi7118e4:pathl4:.git7:objects2:ae38:c1588d9d21c8354df3f43c0336dfd0118950aaeed6:lengthi4212e4:pathl4:.git7:objects2:d138:1c3412424ba82e2d15fea5323e7fa07cfcfab4eed6:lengthi127e4:pathl4:.git7:objects2:d138:25e95480586680a44bccdfbc5a0630ddd9dc28eed6:lengthi209e4:pathl4:.git7:objects2:5c38:1a842476f193a3b1a9ef0158d7bba1a4bbd09feed6:lengthi170e4:pathl4:.git7:objects2:5c38:a8fb2ad39cf7ea68ec4f0c2058c0b5ba1802eeeed6:lengthi179e4:pathl4:.git7:objects2:2138:5514df0373bbd207d21f97268396565a10d22aeed6:lengthi168e4:pathl4:.git7:objects2:bd38:6511711d209a70728ad6bf8396d6b8e5c03a25eed6:lengthi268200e4:pathl4:.git7:objects2:5f38:c537c304882d8e66fdd3843767ee9bc4016a47eed6:lengthi4877e4:pathl4:.git7:objects2:de38:912f3f237202a026e7215f0d8a528cf34685cfeed6:lengthi50e4:pathl4:.git7:objects2:5138:7761cf20ef747ef4c8bccd36d5b91562d30b54eed6:lengthi6379e4:pathl4:.git7:objects2:9838:78bcfeb4b0e6e34e965661f82b81a1204ce13beed6:lengthi181e4:pathl4:.git7:objects2:0838:ae175e53e210e3ec8778d000850e4c8933f7f4eed6:lengthi209e4:pathl4:.git7:objects2:0338:078247eccf575736fe05ac20511006e3c2425beed6:lengthi208e4:pathl4:.git7:objects2:3738:cc1e81c89842454098e3e567b50d54bd724e73eed6:lengthi172e4:pathl4:.git7:objects2:c838:40a93468f09050168065349ed50bdb1b81c8d9eed6:lengthi149e4:pathl4:.git7:objects2:5d38:f8fd53243deed3c4bab083696136ba3b5b3ed2eed6:lengthi177e4:pathl4:.git7:objects2:f338:89555a58dc0026672238fc513795ef15179aaaeed6:lengthi421317e4:pathl4:.git7:objects2:b338:e6ecfd18bcc8b03491ccbf57482b43b4f24a35eed6:lengthi54e4:pathl4:.git7:objects2:b338:5f015d7a61c3f38d3434b0eb025c4b8f9660b2eed6:lengthi7170e4:pathl4:.git7:objects2:ce38:bc2dcb02f45bd4286d98d7ad3698a0e8956081eed6:lengthi149e4:pathl4:.git7:objects2:b238:81b3872b10ddcf1d1a4c5bbdcfa4bff3e582edeed6:lengthi546003e4:pathl4:.git7:objects2:6638:271567042dd7261efdbe6f82f5a21a0d9f2998eed6:lengthi149e4:pathl4:.git7:objects2:0f38:a6956e26b31350c5ce575cde13f35290f13dc6eed6:lengthi178e4:pathl4:.git7:objects2:8b38:57274ce4be5f6698f8c5d3efcd27e2f3013799eed6:lengthi39886e4:pathl4:.git7:objects2:6c38:5069cb3d39a5ccb9331cf7e0f369f5634646f0eed6:lengthi3375e4:pathl4:.git7:objects4:pack50:pack-cf807eb749e3a7179e14c6fb035398fade743c41.packeed6:lengthi1240e4:pathl4:.git7:objects4:pack49:pack-cf807eb749e3a7179e14c6fb035398fade743c41.idxeed6:lengthi6798e4:pathl4:.git7:objects2:7838:59298bec0639706db4fe21b770c352dd11541beed6:lengthi1239e4:pathl4:.git5:hooks25:prepare-commit-msg.sampleeed6:lengthi478e4:pathl4:.git5:hooks21:applypatch-msg.sampleeed6:lengthi1348e4:pathl4:.git5:hooks15:pre-push.sampleeed6:lengthi1642e4:pathl4:.git5:hooks17:pre-commit.sampleeed6:lengthi4898e4:pathl4:.git5:hooks17:pre-rebase.sampleeed6:lengthi544e4:pathl4:.git5:hooks18:pre-receive.sampleeed6:lengthi424e4:pathl4:.git5:hooks21:pre-applypatch.sampleeed6:lengthi189e4:pathl4:.git5:hooks18:post-update.sampleeed6:lengthi3610e4:pathl4:.git5:hooks13:update.sampleeed6:lengthi896e4:pathl4:.git5:hooks17:commit-msg.sampleeed6:lengthi73e4:pathl4:.git11:descriptioneed6:lengthi7e4:pathl4:.git14:COMMIT_EDITMSGeed6:lengthi23e4:pathl4:.git4:HEADeed6:lengthi870e4:pathl4:.git5:indexeed6:lengthi41e4:pathl4:.git9:ORIG_HEADeed6:lengthi79e4:pathl4:.git10:FETCH_HEADeed6:lengthi125e4:pathl7:test1.ceed6:lengthi8024e4:pathl9:notes.orgeed6:lengthi22222e4:pathl12:rust-talk.mdeed6:lengthi455284e4:pathl3:img18:17022211_55_48.jpgeed6:lengthi431399e4:pathl3:img6:p2.pngeed6:lengthi277300e4:pathl3:img6:p3.pngeed6:lengthi552847e4:pathl3:img6:p1.pngeed6:lengthi43717e4:pathl3:img5:a.pngeed6:lengthi82e4:pathl8:build.sheed6:lengthi15754e4:pathl13:rust-talk.orgeee4:name3:org12:piece lengthi262144e6:pieces420:°˜Êø~Óõ‹«púþ&nåeÄ7=°‘¡p×បÿLqœR¸qöê:æðñ©Éÿ¢¯ÅlådÌ4­hëqCmOÊp«Ôòéª$.ʅOÐÌO jÙi= ¤ÛÄEÒj.Γƒ³ÜÙÅ9ÅòO†²*iü²þÕjøaA¸u(dÝd·¶mê—öU¿qgìœ ͘{ Í` ;.#b(ÿ®‰ÞEÆÈ=üˆÚW m5dw2¥4JÑu­2Ã8†Ùã:h>ZIÝZªÅÛ[P¦«|ðÜPî +iW…à©×4çÆÅþ½ßîEú{»ÍŒ3'ͧœ¦¡§hC 3H®ró„CÔäÓhρ«È¶Îâ*±Ç¼.ê¬ÄÄ!Ö™7ÞöE¶Ù0>©©(“?‚{V'v›Ò|õ #ê}ðÂZžJà)"ZÔ߻ġàee \ No newline at end of file diff --git a/test/MetainfoTests.hs b/test/MetainfoTests.hs index 86aa0ff..9f1a2e2 100644 --- a/test/MetainfoTests.hs +++ b/test/MetainfoTests.hs @@ -24,26 +24,46 @@ module MetainfoTests where import Prelude hiding (readFile) import FuncTorrent.Metainfo + +import Control.Monad (liftM) import Test.Hspec import Data.ByteString (readFile) tests :: IO () -tests = hspec $ do - describe "read and interpret a torrent file 1" $ do - it "valid torrent file" $ do - fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent" - (torrentToMetainfo fc) `shouldNotBe` (Left "parse error") - it "valid announce list" $ do - fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent" - case torrentToMetainfo fc of - Left _ -> pending - Right metainfo -> do - announceList metainfo `shouldSatisfy` (not . null) - it "valid piece length" $ do - fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent" - case torrentToMetainfo fc of - Left _ -> pending - Right metainfo -> do - let (Just info') = info metainfo - pieceLength info' `shouldBe` (524288 :: Integer) +tests = do + fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent" + let minfo = torrentToMetainfo fc + putStrLn $ show minfo + hspec $ do + describe "read and interpret a torrent file 1" $ do + it "valid torrent file" $ do + (torrentToMetainfo fc) `shouldNotBe` (Left "parse error") + it "valid announce list" $ do + case torrentToMetainfo fc of + Left _ -> pending + Right metainfo -> do + announceList metainfo `shouldSatisfy` (not . null) + it "valid piece length" $ do + case torrentToMetainfo fc of + Left _ -> pending + Right metainfo -> do + let (Just info') = info metainfo + pieceLength info' `shouldBe` (524288 :: Integer) + it "Not a multifile torrent" $ do + case torrentToMetainfo fc of + Left _ -> pending + Right metainfo -> do + let (Just i) = info metainfo + (length (filemeta i)) `shouldSatisfy` (== 0) + describe "read and interpret a multifile torrent file" $ do + it "valid multifile torrent file" $ do + fc <- readFile "data/multifile.torrent" + (torrentToMetainfo fc) `shouldNotBe` (Left "parse error") + it "valid multifile torrent with multiple files" $ do + fc <- readFile "data/multifile.torrent" + case torrentToMetainfo fc of + Left _ -> pending + Right metainfo -> do + let (Just i) = info metainfo + (length (filemeta i)) `shouldSatisfy` (> 1) -- 2.37.2