summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClint Adams <clint@debian.org>2012-04-26 19:34:16 -0400
committerClint Adams <clint@debian.org>2012-04-26 19:34:16 -0400
commit1ddca48c27cece9352e85ce6188f697eb9124750 (patch)
tree2fd164848c8ba34180c27a843cb69ab720469c24 /tests
parent716dd382221343e5da5daf1a9a8ac40304a7d74b (diff)
Introduce some lazy bytestrings internally.
Diffstat (limited to 'tests')
-rw-r--r--tests/suite.hs18
1 files changed, 10 insertions, 8 deletions
diff --git a/tests/suite.hs b/tests/suite.hs
index 838a5f3..ffe8b50 100644
--- a/tests/suite.hs
+++ b/tests/suite.hs
@@ -9,7 +9,9 @@ import Codec.Encryption.OpenPGP.ASCIIArmor.Utils
9 9
10import Data.ByteString (ByteString) 10import Data.ByteString (ByteString)
11import qualified Data.ByteString as B 11import qualified Data.ByteString as B
12import qualified Data.ByteString.Lazy as BL
12import qualified Data.ByteString.Char8 as BC8 13import qualified Data.ByteString.Char8 as BC8
14import qualified Data.ByteString.Lazy.Char8 as BLC8
13import Data.Digest.CRC24 (crc24) 15import Data.Digest.CRC24 (crc24)
14import Data.Word (Word32) 16import Data.Word (Word32)
15 17
@@ -19,7 +21,7 @@ testCRC24 bs crc = assertEqual "crc24" crc (crc24 bs)
19testArmorDecode :: FilePath -> [FilePath] -> Assertion 21testArmorDecode :: FilePath -> [FilePath] -> Assertion
20testArmorDecode fp targets = do 22testArmorDecode fp targets = do
21 bs <- B.readFile $ "tests/data/" ++ fp 23 bs <- B.readFile $ "tests/data/" ++ fp
22 tbss <- mapM (\target -> B.readFile $ "tests/data/" ++ target) targets 24 tbss <- mapM (\target -> BL.readFile $ "tests/data/" ++ target) targets
23 case decode bs of 25 case decode bs of
24 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp 26 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
25 Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as) 27 Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as)
@@ -29,7 +31,7 @@ testArmorDecode fp targets = do
29testArmorMultipartDecode :: FilePath -> FilePath -> Assertion 31testArmorMultipartDecode :: FilePath -> FilePath -> Assertion
30testArmorMultipartDecode fp target = do 32testArmorMultipartDecode fp target = do
31 bs <- B.readFile $ "tests/data/" ++ fp 33 bs <- B.readFile $ "tests/data/" ++ fp
32 tbs <- B.readFile $ "tests/data/" ++ target 34 tbs <- BL.readFile $ "tests/data/" ++ target
33 case decode bs of 35 case decode bs of
34 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp 36 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
35 Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as)) 37 Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as))
@@ -39,18 +41,18 @@ testArmorMultipartDecode fp target = do
39testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion 41testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion
40testClearsignedDecodeBody fp target = do 42testClearsignedDecodeBody fp target = do
41 bs <- B.readFile $ "tests/data/" ++ fp 43 bs <- B.readFile $ "tests/data/" ++ fp
42 tbs <- B.readFile $ "tests/data/" ++ target 44 tbs <- BL.readFile $ "tests/data/" ++ target
43 case decode bs of 45 case decode bs of
44 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp 46 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
45 Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a) 47 Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a)
46 where 48 where
47 getBody (ClearSigned _ txt _) = txt 49 getBody (ClearSigned _ txt _) = txt
48 convertEndings = crlfUnlines . BC8.lines 50 convertEndings = crlfUnlinesLazy . BLC8.lines
49 51
50testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion 52testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion
51testClearsignedDecodeSig fp target = do 53testClearsignedDecodeSig fp target = do
52 bs <- B.readFile $ "tests/data/" ++ fp 54 bs <- B.readFile $ "tests/data/" ++ fp
53 tbs <- B.readFile $ "tests/data/" ++ target 55 tbs <- BL.readFile $ "tests/data/" ++ target
54 case decode bs of 56 case decode bs of
55 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp 57 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
56 Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a) 58 Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a)
@@ -59,14 +61,14 @@ testClearsignedDecodeSig fp target = do
59 61
60testArmorEncode :: [FilePath] -> FilePath -> Assertion 62testArmorEncode :: [FilePath] -> FilePath -> Assertion
61testArmorEncode fps target = do 63testArmorEncode fps target = do
62 bss <- mapM (\fp -> B.readFile $ "tests/data/" ++ fp) fps 64 bss <- mapM (\fp -> BL.readFile $ "tests/data/" ++ fp) fps
63 tbs <- B.readFile $ "tests/data/" ++ target 65 tbs <- B.readFile $ "tests/data/" ++ target
64 assertEqual ("literaldata") tbs (encode (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss)) 66 assertEqual ("literaldata") tbs (encode (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss))
65 67
66testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion 68testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion
67testClearsignedEncode ftxt fsig ftarget = do 69testClearsignedEncode ftxt fsig ftarget = do
68 txt <- B.readFile $ "tests/data/" ++ ftxt 70 txt <- BL.readFile $ "tests/data/" ++ ftxt
69 sig <- B.readFile $ "tests/data/" ++ fsig 71 sig <- BL.readFile $ "tests/data/" ++ fsig
70 target <- B.readFile $ "tests/data/" ++ ftarget 72 target <- B.readFile $ "tests/data/" ++ ftarget
71 assertEqual ("clearsigned encode") target (encode [ClearSigned [("Hash","SHA1")] txt (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] sig)]) 73 assertEqual ("clearsigned encode") target (encode [ClearSigned [("Hash","SHA1")] txt (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] sig)])
72 74