2 - Copyright (C) 2015-2016 Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
4 - This file is part of FuncTorrent.
6 - FuncTorrent is free software; you can redistribute it and/or modify
7 - it under the terms of the GNU General Public License as published by
8 - the Free Software Foundation; either version 3 of the License, or
9 - (at your option) any later version.
11 - FuncTorrent is distributed in the hope that it will be useful,
12 - but WITHOUT ANY WARRANTY; without even the implied warranty of
13 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 - GNU General Public License for more details.
16 - You should have received a copy of the GNU General Public License
17 - along with FuncTorrent; if not, see <http://www.gnu.org/licenses/>
20 {-# LANGUAGE OverloadedStrings #-}
22 module MetainfoSpec where
26 import FuncTorrent.Metainfo (Info(..), Metainfo(..), FileInfo(..), torrentToMetainfo)
27 import qualified Data.ByteString.Lazy.Char8 as BC (readFile, toStrict)
28 import qualified Data.ByteString as B
32 describe "Bencode" $ do
33 it "torrent-file-1" $ do
34 c <- BC.readFile "data/test1.torrent"
35 let (Right m) = torrentToMetainfo (BC.toStrict c)
36 length (announceList m) `shouldBe` 1
37 pieceLength (info m) `shouldBe` 524288
38 pieces (info m) `shouldSatisfy` (\p -> B.length p `mod` 20 == 0)
39 let fs = files $ info m
40 (FileInfo _ _ name') = head fs
41 name' `shouldNotBe` ""
42 length fs `shouldBe` 1
43 it "torrent-file-2" $ do
44 c <- BC.readFile "data/test2.torrent"
45 let (Right m) = torrentToMetainfo (BC.toStrict c)
47 (FileInfo _ _ name') = head fs
48 name' `shouldNotBe` ""
49 length fs `shouldBe` 1
50 it "torrent-file-3" $ do
51 c <- BC.readFile "data/test3.torrent"
52 let (Right m) = torrentToMetainfo (BC.toStrict c)
54 (FileInfo _ _ name') = head fs
55 name' `shouldNotBe` ""
56 length fs `shouldBe` 1
57 it "torrent-file-4" $ do
58 c <- BC.readFile "data/test4.torrent"
59 let (Right m) = torrentToMetainfo (BC.toStrict c)
60 length (announceList m) `shouldBe` 3
61 let fs = files $ info m
63 length fs `shouldBe` 9 -- 9 files in the torrent
64 p `shouldStartWith` "NASA_NTRS_Archive_19740027163"