]> git.rkrishnan.org Git - functorrent.git/blobdiff - test/MetainfoTests.hs
metainfotests: refactor
[functorrent.git] / test / MetainfoTests.hs
index 86ecf482e16c7079886896b631d90d9a29dfe503..a9043db8ec70eea5ae94c1905c76c878fa2d1454 100644 (file)
@@ -1,17 +1,68 @@
 -- | Tests for Metainfo module
 
+{-
+ - Copyright (C) 2015-2016 Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
+ -
+ - This file is part of FuncTorrent.
+ -
+ - FuncTorrent is free software; you can redistribute it and/or modify
+ - it under the terms of the GNU General Public License as published by
+ - the Free Software Foundation; either version 3 of the License, or
+ - (at your option) any later version.
+ -
+ - FuncTorrent is distributed in the hope that it will be useful,
+ - but WITHOUT ANY WARRANTY; without even the implied warranty of
+ - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ - GNU General Public License for more details.
+ -
+ - You should have received a copy of the GNU General Public License
+ - along with FuncTorrent; if not,  see <http://www.gnu.org/licenses/>
+ -}
+
 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 announceList" $ do
-      fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent"
-      (torrentToMetainfo fc) `shouldNotBe` (Left "parse error")
+tests = do
+  fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent"
+  let minfo = torrentToMetainfo fc
+  hspec $ do
+    describe "read and interpret a torrent file 1" $ do
+      it "valid torrent file" $ do
+        minfo `shouldNotBe` (Left "parse error")
+      it "valid announce list" $ do
+        case minfo of
+          Left _ -> pending
+          Right metainfo -> do
+            announceList metainfo `shouldSatisfy` (not . null)
+      it "valid piece length" $ do
+        case minfo of
+          Left _ -> pending
+          Right metainfo -> do
+            let (Just info') = info metainfo
+            pieceLength info' `shouldBe` (524288 :: Integer)
+      it "Not a multifile torrent" $ do
+        case minfo of
+          Left _ -> pending
+          Right metainfo -> do 
+            let (Just i) = info metainfo
+            (length (filemeta i)) `shouldSatisfy` (== 1)
 
+    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)