diff options
Diffstat (limited to 'tests/suite.hs')
-rw-r--r-- | tests/suite.hs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/tests/suite.hs b/tests/suite.hs index 272295a..45a2fb2 100644 --- a/tests/suite.hs +++ b/tests/suite.hs | |||
@@ -3,7 +3,7 @@ import Test.Framework.Providers.HUnit | |||
3 | 3 | ||
4 | import Test.HUnit | 4 | import Test.HUnit |
5 | 5 | ||
6 | import Codec.Encryption.OpenPGP.ASCIIArmor (armor, decodeArmor) | 6 | import Codec.Encryption.OpenPGP.ASCIIArmor (armor, decode) |
7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | 7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types |
8 | 8 | ||
9 | import Data.ByteString (ByteString) | 9 | import Data.ByteString (ByteString) |
@@ -15,13 +15,15 @@ import Data.Word (Word32) | |||
15 | testCRC24 :: ByteString -> Word32 -> Assertion | 15 | testCRC24 :: ByteString -> Word32 -> Assertion |
16 | testCRC24 bs crc = assertEqual "crc24" crc (crc24 bs) | 16 | testCRC24 bs crc = assertEqual "crc24" crc (crc24 bs) |
17 | 17 | ||
18 | testArmorDecode :: FilePath -> FilePath -> Assertion | 18 | testArmorDecode :: FilePath -> [FilePath] -> Assertion |
19 | testArmorDecode fp target = do | 19 | testArmorDecode fp targets = do |
20 | bs <- B.readFile $ "tests/data/" ++ fp | 20 | bs <- B.readFile $ "tests/data/" ++ fp |
21 | tbs <- B.readFile $ "tests/data/" ++ target | 21 | tbss <- mapM (\target -> B.readFile $ "tests/data/" ++ target) targets |
22 | case decodeArmor bs of | 22 | case decode bs of |
23 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | 23 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp |
24 | Right (Armor at hdrs pl) -> do assertEqual ("for " ++ fp) tbs pl | 24 | Right as -> do assertEqual ("for " ++ fp) tbss (map getPayload as) |
25 | where | ||
26 | getPayload (Armor _ _ pl) = pl | ||
25 | 27 | ||
26 | testArmorEncode :: FilePath -> FilePath -> Assertion | 28 | testArmorEncode :: FilePath -> FilePath -> Assertion |
27 | testArmorEncode fp target = do | 29 | testArmorEncode fp target = do |
@@ -36,7 +38,9 @@ tests = [ | |||
36 | , testCase "CRC24: hOpenPGP and friends" (testCRC24 (BC8.pack "hOpenPGP and friends") 11940960) | 38 | , testCase "CRC24: hOpenPGP and friends" (testCRC24 (BC8.pack "hOpenPGP and friends") 11940960) |
37 | ] | 39 | ] |
38 | , testGroup "ASCII armor" [ | 40 | , testGroup "ASCII armor" [ |
39 | testCase "Decode sample armor" (testArmorDecode "msg1.asc" "msg1.gpg") | 41 | testCase "Decode sample armor" (testArmorDecode "msg1.asc" ["msg1.gpg"]) |
42 | , testCase "Decode sample armor with cruft" (testArmorDecode "msg1a.asc" ["msg1.gpg"]) | ||
43 | , testCase "Decode multiple sample armors" (testArmorDecode "msg1b.asc" ["msg1.gpg","msg1.gpg","msg1.gpg"]) | ||
40 | , testCase "Encode sample armor" (testArmorEncode "msg1.gpg" "msg1.asc") | 44 | , testCase "Encode sample armor" (testArmorEncode "msg1.gpg" "msg1.asc") |
41 | ] | 45 | ] |
42 | ] | 46 | ] |