File: GZiptest.hs

package info (click to toggle)
missingpy 0.1.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,400 kB
  • ctags: 17
  • sloc: haskell: 1,566; makefile: 118; python: 47; ansic: 37
file content (85 lines) | stat: -rw-r--r-- 3,264 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{-# OPTIONS -fallow-overlapping-instances #-}
{- arch-tag: GZip tests main file
Copyright (C) 2005 John Goerzen <jgoerzen@complete.org>

This program 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 2 of the License, or
(at your option) any later version.

This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}

module GZiptest(tests) where
import HUnit
import Python.Exceptions
import MissingPy.FileArchive.GZip
import Data.List
import MissingH.IO.HVIO
import System.IO
import System.IO.Error
import Testutil
import System.Directory
import qualified Control.Exception

finally = Control.Exception.finally

f fn exp = TestCase $ do gzf <- openGz ("testsrc/gzfiles/" ++ fn) ReadMode 9
                         c <- vGetContents gzf
                         exp @=? c
                         vClose gzf
                             

test_gunzip =
    [
     f "t1.gz" "Test 1"
    ,f "empty.gz" ""
     --    , "t1bad has errors
    ,f "t2.gz" "Test 1Test 2"
    ,TestCase $ handlePy exc2ioerror $
                do gzf <- openGz "testsrc/gzfiles/t1bad.gz" ReadMode 1
                   assertRaises "crc" (Control.Exception.IOException $ userError "Python exceptions.IOError: CRC check failed") 
                      (handlePy exc2ioerror $ do c <- vGetContents gzf
                                                 "nonexistant bad data" @=? c
                      )
                   vClose gzf
    ,TestCase $ do gzf <- openGz "testsrc/gzfiles/zeros.gz" ReadMode 1
                   c <- vGetContents gzf
                   10485760 @=? length c
                   vClose gzf
    --,f "zeros.gz" (replicate 10485760 '\0')
    ]

test_gzip = TestCase $ 
    handlePy exc2ioerror $
    do gzf <- openGz "testsrc/gzfiles/deleteme.gz" ReadWriteMode 9
       finally (do vPutStr gzf "Test 2\n"
                   vSeek gzf AbsoluteSeek 7
                   vFlush gzf
                   vPutStr gzf "Test 3\n"
                   vPutStr gzf (replicate 1048576 't')
                   vPutChar gzf '\n'
                   vClose gzf
                   gzf2 <- openGz "testsrc/gzfiles/deleteme.gz" ReadMode 9
                   vGetLine gzf2 >>= (@=? "Test 2")
                   vGetLine gzf2 >>= (@=? "Test 3")
                   vRewind gzf2
                   c <- vGetContents gzf2
                   ("Test 2\nTest 3\n" ++ (replicate 1048576 't') ++ "\n") 
                      @=? c
                   assertRaises "eof" (Control.Exception.IOException $ mkIOError eofErrorType "" Nothing Nothing) (vGetLine gzf2)
                   vClose gzf2
               ) (removeFile "testsrc/gzfiles/deleteme.gz")
                   

tests = TestList [TestLabel "gzip" test_gzip,
                  TestLabel "gunzip" (TestList test_gunzip)

                 ]