summaryrefslogtreecommitdiff
path: root/test-src/DataencQC.hs
blob: d35c09cc27f18a9da582cb7eaa6e085070373ab3 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{-# OPTIONS_GHC -XTemplateHaskell #-}

{-
 - Copyright : (c) 2007 Magnus Therning
 - License   : BSD3
 -}

module DataencQC
    where

import Test.Framework.TH

import Data.Maybe
import Data.Word
import Test.QuickCheck
import Test.Framework.Providers.QuickCheck2

import qualified Codec.Binary.Uu as Uu
import qualified Codec.Binary.Uu as Xx
import qualified Codec.Binary.Base85 as Base85
import qualified Codec.Binary.Base64 as Base64
import qualified Codec.Binary.Base64Url as Base64Url
import qualified Codec.Binary.Base32 as Base32
import qualified Codec.Binary.Base32Hex as Base32Hex
import qualified Codec.Binary.Base16 as Base16
import qualified Codec.Binary.Yenc as Yenc
import qualified Codec.Binary.QuotedPrintable as QP
import qualified Codec.Binary.PythonString as Py
import qualified Codec.Binary.Url as Url

-- {{{1 uuencode properties
prop_uuEncode ws = ws == (fromJust . Uu.decode . Uu.encode) ws
    where types = ws::[Word8]

prop_uuChop n ws = s == (Uu.unchop . Uu.chop n) s
    where
        types = (n :: Int, ws::[Word8])
        s = Uu.encode ws

prop_uuCombined n ws = ws == fromJust (Uu.decode $ Uu.unchop $ Uu.chop n $ Uu.encode ws)
    where types = (n::Int, ws::[Word8])

-- {{{1 xxencode properties
prop_xxEncode ws = ws == (fromJust . Xx.decode . Xx.encode) ws
    where types = ws::[Word8]

prop_xxChop n ws = s == (Xx.unchop . Xx.chop n) s
    where
        types = (n:: Int, ws::[Word8])
        s = Xx.encode ws

prop_xxCombined n ws = ws == fromJust (Xx.decode $ Xx.unchop $ Xx.chop n $ Xx.encode ws)
    where types = (n::Int, ws::[Word8])

-- {{{1 base85 properties
prop_base85Encode ws = ws == fromJust (Base85.decode $ Base85.encode ws)
    where types = ws::[Word8]

prop_base85Chop n s = s == Base85.unchop (Base85.chop n s)
    where types = (n::Int, s::String)

-- {{{1 base64 properties
prop_base64Encode ws = ws == fromJust (Base64.decode $ Base64.encode ws)
    where types = ws::[Word8]

prop_base64Chop n s = s == Base64.unchop (Base64.chop n s)
    where types = (n::Int, s::String)

-- {{{1 base64url properties
prop_base64UrlEncode ws = ws == fromJust (Base64Url.decode $ Base64Url.encode ws)
    where types = ws::[Word8]

prop_base64UrlChop n s = s == Base64Url.unchop (Base64Url.chop n s)
    where types = (n::Int, s::String)

-- {{{1 base32
prop_base32Encode ws = ws == fromJust (Base32.decode $ Base32.encode ws)
    where types = ws::[Word8]

prop_base32Chop n s = s == Base32.unchop (Base32.chop n s)
    where types = (n::Int, s::String)

-- {{{1 base32hex
prop_base32HexEncode ws = ws == fromJust (Base32Hex.decode $ Base32Hex.encode ws)
    where types = ws::[Word8]

prop_base32HexChop n s = s == Base32Hex.unchop (Base32Hex.chop n s)
    where types = (n::Int, s::String)

-- {{{1 base16
prop_base16Encode ws = ws == fromJust (Base16.decode $ Base16.encode ws)
    where types = ws::[Word8]

prop_base16Chop n s = s == Base16.unchop (Base16.chop n s)
    where types = (n::Int, s::String)

-- {{{1 yEncoding
prop_yencEncode ws = ws == fromJust (Yenc.decode $ Yenc.encode ws)
    where types = ws ::[Word8]

prop_yencChop n ws = ws == Yenc.unchop (Yenc.chop n ws)
    where types = (n::Int, ws :: [Word8])

-- {{{1 qp
prop_qpEncode ws = ws == fromJust (QP.decode $ QP.encode ws)
    where types = ws :: [Word8]

prop_qpChop n ws = s == (QP.unchop . QP.chop n) s
    where
        types = (n::Int, ws::[Word8])
        s = QP.encode ws

prop_qpCombined n ws = ws == fromJust (QP.decode $ QP.unchop $ QP.chop n $ QP.encode ws)
    where types = (n::Int, ws::[Word8])

-- {{{1 py
prop_pyEncode ws = ws == fromJust (Py.decode $ Py.encode ws)
    where types = ws :: [Word8]

prop_pyChop n s = s == Py.unchop (Py.chop n s)
    where types = (n :: Int, s :: String)

prop_pyCombined n ws = ws == fromJust (runAll ws)
    where runAll = Py.decode . Py.unchop . Py.chop n . Py.encode

-- {{{1 url
prop_urlEncode ws = ws == fromJust (Url.decode $ Url.encode ws)
    where types = ws :: [Word8]

prop_urlChop n s = s == Url.unchop (Url.chop n s)
    where types = (n :: Int, s :: String)

prop_urlCombined n ws = ws == fromJust (runAll ws)
    where runAll = Url.decode . Url.unchop . Url.chop n . Url.encode

-- {{{1 all the tests
allTests = $(testGroupGenerator)