diff options
Diffstat (limited to 'tests/System/Torrent/StorageSpec.hs')
-rw-r--r-- | tests/System/Torrent/StorageSpec.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/System/Torrent/StorageSpec.hs b/tests/System/Torrent/StorageSpec.hs index 8d9dfd8f..8267b7a5 100644 --- a/tests/System/Torrent/StorageSpec.hs +++ b/tests/System/Torrent/StorageSpec.hs | |||
@@ -1,5 +1,6 @@ | |||
1 | module System.Torrent.StorageSpec (spec) where | 1 | module System.Torrent.StorageSpec (spec) where |
2 | import Control.Exception | 2 | import Control.Exception |
3 | import Data.ByteString.Lazy as BL | ||
3 | import System.FilePath | 4 | import System.FilePath |
4 | import System.Directory | 5 | import System.Directory |
5 | import System.IO.Unsafe | 6 | import System.IO.Unsafe |
@@ -32,11 +33,26 @@ spec = before createLayout $ do | |||
32 | writePiece (Piece 0 "") s `shouldThrow` (== StorageIsRO) | 33 | writePiece (Piece 0 "") s `shouldThrow` (== StorageIsRO) |
33 | close s | 34 | close s |
34 | 35 | ||
36 | it "should fail if piece size do not match" $ do | ||
37 | withStorage ReadWrite 1 layout $ \ s -> | ||
38 | writePiece (Piece 0 "") s `shouldThrow` (== InvalidSize 0) | ||
39 | |||
35 | it "should fail on negative index" $ do | 40 | it "should fail on negative index" $ do |
36 | withStorage ReadWrite 0 layout $ \ s -> | 41 | withStorage ReadWrite 0 layout $ \ s -> |
37 | writePiece (Piece (-1) "") s `shouldThrow` (== InvalidIndex (-1)) | 42 | writePiece (Piece (-1) "") s `shouldThrow` (== InvalidIndex (-1)) |
38 | 43 | ||
44 | it "should fail on out of upper bound index" $ do | ||
45 | withStorage ReadWrite 100 layout $ \ s -> do | ||
46 | let bs = BL.replicate 100 0 | ||
47 | writePiece (Piece 1 bs) s | ||
48 | writePiece (Piece 2 bs) s `shouldThrow` (== InvalidIndex 2) | ||
49 | |||
39 | describe "readPiece" $ do | 50 | describe "readPiece" $ do |
40 | it "should fail on negative index" $ | 51 | it "should fail on negative index" $ |
41 | withStorage ReadOnly 0 layout $ \ s -> | 52 | withStorage ReadOnly 0 layout $ \ s -> |
42 | readPiece (-1) s `shouldThrow` (== InvalidIndex (-1)) | 53 | readPiece (-1) s `shouldThrow` (== InvalidIndex (-1)) |
54 | |||
55 | it "should fail on out of upper bound index" $ do | ||
56 | withStorage ReadOnly 100 layout $ \ s -> do | ||
57 | _ <- readPiece 1 s | ||
58 | readPiece 2 s `shouldThrow` (== InvalidIndex 2) | ||