summaryrefslogtreecommitdiff
path: root/tests/System/Torrent
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-05 20:06:13 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-05 20:06:13 +0400
commit3eaa3003d9ece714595dffbf07202ee90336d05f (patch)
tree4dfa6528139a37dc194da60cb01161ebff9fd5d9 /tests/System/Torrent
parentb925e91c5e53a4300e5b0511e8811c5f1af9e803 (diff)
Add storage streaming
Diffstat (limited to 'tests/System/Torrent')
-rw-r--r--tests/System/Torrent/StorageSpec.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/System/Torrent/StorageSpec.hs b/tests/System/Torrent/StorageSpec.hs
index 8267b7a5..d2185961 100644
--- a/tests/System/Torrent/StorageSpec.hs
+++ b/tests/System/Torrent/StorageSpec.hs
@@ -1,6 +1,8 @@
1module System.Torrent.StorageSpec (spec) where 1module System.Torrent.StorageSpec (spec) where
2import Control.Exception 2import Control.Exception
3import Data.ByteString.Lazy as BL 3import Data.ByteString.Lazy as BL
4import Data.Conduit as C
5import Data.Conduit.List as C
4import System.FilePath 6import System.FilePath
5import System.Directory 7import System.Directory
6import System.IO.Unsafe 8import System.IO.Unsafe
@@ -25,6 +27,12 @@ createLayout :: IO ()
25createLayout = 27createLayout =
26 bracket (open ReadWriteEx 0 layout) close (const (return ())) 28 bracket (open ReadWriteEx 0 layout) close (const (return ()))
27 29
30psize :: PieceSize
31psize = 16
32
33pcount :: PieceCount
34pcount = 11
35
28spec :: Spec 36spec :: Spec
29spec = before createLayout $ do 37spec = before createLayout $ do
30 describe "writePiece" $ do 38 describe "writePiece" $ do
@@ -56,3 +64,21 @@ spec = before createLayout $ do
56 withStorage ReadOnly 100 layout $ \ s -> do 64 withStorage ReadOnly 100 layout $ \ s -> do
57 _ <- readPiece 1 s 65 _ <- readPiece 1 s
58 readPiece 2 s `shouldThrow` (== InvalidIndex 2) 66 readPiece 2 s `shouldThrow` (== InvalidIndex 2)
67
68 describe "sourceStorage" $ do
69 it "should source all chunks" $ do
70 withStorage ReadOnly psize layout $ \ s -> do
71 n <- sourceStorage s $$ C.fold (\ n _ -> succ n) 0
72 n `shouldBe` pcount
73
74 -- this test should fail if 'sourceStorage' test fail
75 describe "sinkStorage" $ do
76 it "should write all chunks" $ do
77 let byteVal = 0
78 let bzeroPiece p = p { pieceData = BL.replicate (BL.length (pieceData p)) byteVal }
79 let isZeroPiece p = (== byteVal) `BL.all` pieceData p
80
81 withStorage ReadWrite psize layout $ \ s -> do
82 sourceStorage s $= C.map bzeroPiece $$ sinkStorage s
83 b <- sourceStorage s $$ C.fold (\ b p -> b && isZeroPiece p) True
84 b `shouldBe` True