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(..), DynamicInfo(..), 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 (SingleFileInfo file') = dyninfo $ info m
40 (FileInfo _ _ name') = file'
41 name' `shouldNotBe` ""
42 it "torrent-file-2" $ do
43 c <- BC.readFile "data/test2.torrent"
44 let (Right m) = torrentToMetainfo (BC.toStrict c)
45 (SingleFileInfo file') = dyninfo $ info m
46 (FileInfo _ _ name') = file'
47 name' `shouldNotBe` ""
48 it "torrent-file-3" $ do
49 c <- BC.readFile "data/test3.torrent"
50 let (Right m) = torrentToMetainfo (BC.toStrict c)
51 (SingleFileInfo file') = dyninfo $ info m
52 (FileInfo _ _ name') = file'
53 name' `shouldNotBe` ""
54 it "torrent-file-4" $ do
55 c <- BC.readFile "data/test4.torrent"
56 let (Right m) = torrentToMetainfo (BC.toStrict c)
57 length (announceList m) `shouldBe` 3
58 let (MultiFileInfo dname' files') = dyninfo $ info m
59 length files' `shouldBe` 9 -- 9 files in the torrent
60 dname' `shouldBe` "NASA_NTRS_Archive_19740027163"