diff options
Diffstat (limited to 'tests/suite.hs')
-rw-r--r-- | tests/suite.hs | 18 |
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 | ||
10 | import Data.ByteString (ByteString) | 10 | import Data.ByteString (ByteString) |
11 | import qualified Data.ByteString as B | 11 | import qualified Data.ByteString as B |
12 | import qualified Data.ByteString.Lazy as BL | ||
12 | import qualified Data.ByteString.Char8 as BC8 | 13 | import qualified Data.ByteString.Char8 as BC8 |
14 | import qualified Data.ByteString.Lazy.Char8 as BLC8 | ||
13 | import Data.Digest.CRC24 (crc24) | 15 | import Data.Digest.CRC24 (crc24) |
14 | import Data.Word (Word32) | 16 | import Data.Word (Word32) |
15 | 17 | ||
@@ -19,7 +21,7 @@ testCRC24 bs crc = assertEqual "crc24" crc (crc24 bs) | |||
19 | testArmorDecode :: FilePath -> [FilePath] -> Assertion | 21 | testArmorDecode :: FilePath -> [FilePath] -> Assertion |
20 | testArmorDecode fp targets = do | 22 | testArmorDecode 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 | |||
29 | testArmorMultipartDecode :: FilePath -> FilePath -> Assertion | 31 | testArmorMultipartDecode :: FilePath -> FilePath -> Assertion |
30 | testArmorMultipartDecode fp target = do | 32 | testArmorMultipartDecode 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 | |||
39 | testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion | 41 | testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion |
40 | testClearsignedDecodeBody fp target = do | 42 | testClearsignedDecodeBody 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 | ||
50 | testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion | 52 | testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion |
51 | testClearsignedDecodeSig fp target = do | 53 | testClearsignedDecodeSig 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 | ||
60 | testArmorEncode :: [FilePath] -> FilePath -> Assertion | 62 | testArmorEncode :: [FilePath] -> FilePath -> Assertion |
61 | testArmorEncode fps target = do | 63 | testArmorEncode 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 | ||
66 | testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion | 68 | testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion |
67 | testClearsignedEncode ftxt fsig ftarget = do | 69 | testClearsignedEncode 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 | ||