diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-14 15:57:56 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-14 15:57:56 +0400 |
commit | dd7c67343726a073679318394260d2da90f3bda1 (patch) | |
tree | f539e66639d73e969cea50735ccbc3c3dea4f4f0 /tests/System | |
parent | b006a0d096a60ad9d63e972857dde55f252a1ad7 (diff) |
Add more tests for FileMap
Diffstat (limited to 'tests/System')
-rw-r--r-- | tests/System/Torrent/FileMapSpec.hs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/tests/System/Torrent/FileMapSpec.hs b/tests/System/Torrent/FileMapSpec.hs index 23447e55..43c99d34 100644 --- a/tests/System/Torrent/FileMapSpec.hs +++ b/tests/System/Torrent/FileMapSpec.hs | |||
@@ -62,17 +62,48 @@ spec = do | |||
62 | BL.readFile (fst (layout !! 1)) `shouldReturn` "bbb" | 62 | BL.readFile (fst (layout !! 1)) `shouldReturn` "bbb" |
63 | BL.readFile (fst (layout !! 2)) `shouldReturn` "cc" | 63 | BL.readFile (fst (layout !! 2)) `shouldReturn` "cc" |
64 | 64 | ||
65 | let max_page_size = 4 * 1024 * 1024 | ||
66 | let long_bs = BL.replicate (fromIntegral max_page_size) 0 | ||
67 | |||
65 | it "no buffer underflow errors" $ do | 68 | it "no buffer underflow errors" $ do |
69 | m <- mmapFiles ReadWrite layout | ||
70 | writeBytes (1 - max_page_size) long_bs m | ||
71 | unmapFiles m | ||
72 | |||
73 | it "no buffer overflow errors" $ do | ||
74 | m <- mmapFiles ReadWrite layout | ||
75 | writeBytes 5 long_bs m | ||
76 | unmapFiles m | ||
77 | |||
78 | it "ignore underflow reads" $ do | ||
66 | m <- mmapFiles ReadOnly layout | 79 | m <- mmapFiles ReadOnly layout |
67 | readBytes (-1) 1 m `shouldReturn` "" | 80 | readBytes (-1) 1 m `shouldReturn` "" |
68 | readBytes (-5) 12 m `shouldReturn` "" | 81 | readBytes (-5) 12 m `shouldReturn` "" |
69 | unmapFiles m | 82 | unmapFiles m |
70 | 83 | ||
71 | it "no buffer overflow errors" $ do | 84 | it "ignore underflow writes" $ do |
72 | m <- mmapFiles ReadWrite layout | 85 | m <- mmapFiles ReadWrite layout |
73 | writeBytes 5 "ddddddddd" m | 86 | writeBytes 0 "aa" m |
74 | unmapFiles m | 87 | unmapFiles m |
75 | 88 | ||
89 | m <- mmapFiles ReadWrite layout | ||
90 | writeBytes (-1) "hhh" m | ||
91 | unmapFiles m | ||
92 | BL.readFile (fst (layout !! 0)) `shouldReturn` "aa" | ||
93 | |||
94 | it "crop overflow reads" $ do | ||
95 | m <- mmapFiles ReadWrite layout | ||
96 | writeBytes 5 "cc" m | ||
97 | unmapFiles m | ||
98 | |||
99 | m <- mmapFiles ReadOnly layout | ||
100 | readBytes 5 10 m `shouldReturn` "cc" | ||
101 | unmapFiles m | ||
102 | |||
103 | it "crop overflow writes" $ do | ||
104 | m <- mmapFiles ReadWrite layout | ||
105 | writeBytes 5 "ddddddddd" m | ||
106 | unmapFiles m | ||
76 | BL.readFile (fst (layout !! 2)) `shouldReturn` "dd" | 107 | BL.readFile (fst (layout !! 2)) `shouldReturn` "dd" |
77 | 108 | ||
78 | it "isomorphic to lazy bytestring" $ do | 109 | it "isomorphic to lazy bytestring" $ do |