@@ -61,6 +61,9 @@ testData = "This is the test data for FileSystem.Handle ??`!@#$%^&*~~))`]"
61testDataLarge :: String
61testDataLarge :: String
62testDataLarge = concat $ replicate 6000 testData
62testDataLarge = concat $ replicate 6000 testData
65+testBinData = "01234567890123456789012345678901234567890123456789"
64executor :: (Handle -> SerialT IO Char) -> IO (SerialT IO Char)
67executor :: (Handle -> SerialT IO Char) -> IO (SerialT IO Char)
65executor f =
68executor f =
66 withSystemTempDirectory "fs_handle" $ \fp -> do
69 withSystemTempDirectory "fs_handle" $ \fp -> do
@@ -152,6 +155,53 @@ testWriteWithChunk =
152 let arr = Array.fromList ls
155 let arr = Array.fromList ls
153 return (testDataLarge == utf8ToString arr)
156 return (testDataLarge == utf8ToString arr)
159+testReadChunksFromToWith :: Int -> Int -> Int -> String -> Property
160+testReadChunksFromToWith from to buffSize expRes =
168+ withSystemTempDirectory "fs_handle" $ \fp -> do
169+ let fpathRead = fp </> "tmp_read.txt"
170+ writeFile fpathRead testBinData
171+ h <- openFile fpathRead ReadMode
172+ ls <- Stream.toList $
174+ Handle.readChunksFromToWith
175+ (from, to, buffSize, h)
176+ return ( expRes == show ls)
178+-- Test for first byte
179+testReadChunksFromToWithFirstByte :: Property
180+testReadChunksFromToWithFirstByte = testReadChunksFromToWith 0 0 15 "[[48]]"
182+-- Test for second byte
183+testReadChunksFromToWithSecondByte :: Property
184+testReadChunksFromToWithSecondByte = testReadChunksFromToWith 1 1 15 "[[49]]"
186+-- Test for second to 10th bytes
187+testReadChunksFromToWithSecondToTenthBytes :: Property
188+testReadChunksFromToWithSecondToTenthBytes =
189+ testReadChunksFromToWith 1 10 15 "[[49,50,51,52,53,54,55,56,57,48]]"
191+-- Test for offset of buffer size
192+testReadChunksFromToWithBuffSizeOffset :: Property
193+testReadChunksFromToWithBuffSizeOffset =
194+ testReadChunksFromToWith 15 25 15 "[[53,54,55,56,57,48,49,50,51,52,53]]"
196+-- Test with multi buffer size
197+testReadChunksFromToWithMultiBuff :: Property
198+testReadChunksFromToWithMultiBuff =
199+ testReadChunksFromToWith
200+ 5 22 5 "[[53,54,55,56,57],[48,49,50,51,52],[53,54,55,56,57],[48,49,50]]"
202+testReadChunksFromToWithRangeInvalid :: Property
203+testReadChunksFromToWithRangeInvalid = testReadChunksFromToWith 15 5 15 "[]"
155moduleName :: String
205moduleName :: String
156moduleName = "FileSystem.Handle"
206moduleName = "FileSystem.Handle"
@@ -166,6 +216,12 @@ main =
166 prop "readWithBufferOf" $ testRead readWithBufferFromHandle
216 prop "readWithBufferOf" $ testRead readWithBufferFromHandle
167 prop "readChunks" $ testRead readChunksFromHandle
217 prop "readChunks" $ testRead readChunksFromHandle
168 prop "readChunksWithBufferOf" $ testRead readChunksWithBuffer
218 prop "readChunksWithBufferOf" $ testRead readChunksWithBuffer
219+ prop "readChunksFromToWithFirstByte" testReadChunksFromToWithFirstByte
220+ prop "readChunksFromToWithSecondByte" testReadChunksFromToWithSecondByte
221+ prop "readChunksFromToWithSecondToTenthBytes" testReadChunksFromToWithSecondToTenthBytes
222+ prop "readChunksFromToWithBuffSizeOffset" testReadChunksFromToWithBuffSizeOffset
223+ prop "readChunksFromToWithMultiBuff" testReadChunksFromToWithMultiBuff
224+ prop "readChunksFromToWithRangeInvalid" testReadChunksFromToWithRangeInvalid
169 describe "Write To Handle" $ do
225 describe "Write To Handle" $ do
170 prop "write" $ testWrite Handle.write
226 prop "write" $ testWrite Handle.write
171 prop "writeWithBufferOf" $ testWrite $ Handle.writeWithBufferOf 1024
227 prop "writeWithBufferOf" $ testWrite $ Handle.writeWithBufferOf 1024