]> git.rkrishnan.org Git - functorrent.git/blob - test/MetainfoTests.hs
add a new test file for multifile torrent
[functorrent.git] / test / MetainfoTests.hs
1 -- | Tests for Metainfo module
2
3 {-
4  - Copyright (C) 2015-2016 Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
5  -
6  - This file is part of FuncTorrent.
7  -
8  - FuncTorrent is free software; you can redistribute it and/or modify
9  - it under the terms of the GNU General Public License as published by
10  - the Free Software Foundation; either version 3 of the License, or
11  - (at your option) any later version.
12  -
13  - FuncTorrent is distributed in the hope that it will be useful,
14  - but WITHOUT ANY WARRANTY; without even the implied warranty of
15  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  - GNU General Public License for more details.
17  -
18  - You should have received a copy of the GNU General Public License
19  - along with FuncTorrent; if not,  see <http://www.gnu.org/licenses/>
20  -}
21
22 module MetainfoTests where
23
24 import Prelude hiding (readFile)
25
26 import FuncTorrent.Metainfo
27
28 import Control.Monad (liftM)
29 import Test.Hspec
30 import Data.ByteString (readFile)
31
32 tests :: IO ()
33 tests = do
34   fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent"
35   let minfo = torrentToMetainfo fc
36   putStrLn $ show minfo
37   hspec $ do
38     describe "read and interpret a torrent file 1" $ do
39       it "valid torrent file" $ do
40         (torrentToMetainfo fc) `shouldNotBe` (Left "parse error")
41       it "valid announce list" $ do
42         case torrentToMetainfo fc of
43           Left _ -> pending
44           Right metainfo -> do
45             announceList metainfo `shouldSatisfy` (not . null)
46       it "valid piece length" $ do
47         case torrentToMetainfo fc of
48           Left _ -> pending
49           Right metainfo -> do
50             let (Just info') = info metainfo
51             pieceLength info' `shouldBe` (524288 :: Integer)
52       it "Not a multifile torrent" $ do
53         case torrentToMetainfo fc of
54           Left _ -> pending
55           Right metainfo -> do 
56             let (Just i) = info metainfo
57             (length (filemeta i)) `shouldSatisfy` (== 0)
58
59     describe "read and interpret a multifile torrent file" $ do
60       it "valid multifile torrent file" $ do
61         fc <- readFile "data/multifile.torrent"
62         (torrentToMetainfo fc) `shouldNotBe` (Left "parse error")
63       it "valid multifile torrent with multiple files" $ do
64         fc <- readFile "data/multifile.torrent"
65         case torrentToMetainfo fc of
66           Left _ -> pending
67           Right metainfo -> do 
68             let (Just i) = info metainfo
69             (length (filemeta i)) `shouldSatisfy` (> 1)