diff options
Diffstat (limited to 'tests/suite.hs')
-rw-r--r-- | tests/suite.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/tests/suite.hs b/tests/suite.hs index ffcbc17..5ad3d05 100644 --- a/tests/suite.hs +++ b/tests/suite.hs | |||
@@ -1,7 +1,7 @@ | |||
1 | import Test.Framework (defaultMain, testGroup) | 1 | import Test.Framework (defaultMain, testGroup, Test) |
2 | import Test.Framework.Providers.HUnit | 2 | import Test.Framework.Providers.HUnit |
3 | 3 | ||
4 | import Test.HUnit | 4 | import Test.HUnit (Assertion, assertEqual, assertFailure) |
5 | 5 | ||
6 | import Codec.Encryption.OpenPGP.ASCIIArmor (decode, decodeLazy, encode, encodeLazy, multipartMerge) | 6 | import Codec.Encryption.OpenPGP.ASCIIArmor (decode, decodeLazy, encode, encodeLazy, multipartMerge) |
7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | 7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types |
@@ -27,6 +27,7 @@ testArmorDecode fp targets = do | |||
27 | Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as) | 27 | Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as) |
28 | where | 28 | where |
29 | getPayload (Armor _ _ pl) = pl | 29 | getPayload (Armor _ _ pl) = pl |
30 | getPayload _ = error "This should not happen." | ||
30 | 31 | ||
31 | testArmorMultipartDecode :: FilePath -> FilePath -> Assertion | 32 | testArmorMultipartDecode :: FilePath -> FilePath -> Assertion |
32 | testArmorMultipartDecode fp target = do | 33 | testArmorMultipartDecode fp target = do |
@@ -37,6 +38,7 @@ testArmorMultipartDecode fp target = do | |||
37 | Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as)) | 38 | Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as)) |
38 | where | 39 | where |
39 | getPayload (Armor _ _ pl) = pl | 40 | getPayload (Armor _ _ pl) = pl |
41 | getPayload _ = error "This should not happen." | ||
40 | 42 | ||
41 | testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion | 43 | testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion |
42 | testClearsignedDecodeBody fp target = do | 44 | testClearsignedDecodeBody fp target = do |
@@ -45,8 +47,10 @@ testClearsignedDecodeBody fp target = do | |||
45 | case decodeLazy bs of | 47 | case decodeLazy bs of |
46 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | 48 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp |
47 | Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a) | 49 | Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a) |
50 | _ -> assertFailure "This shouldn't happen." | ||
48 | where | 51 | where |
49 | getBody (ClearSigned _ txt _) = txt | 52 | getBody (ClearSigned _ txt _) = txt |
53 | getBody _ = error "This should not happen." | ||
50 | convertEndings = crlfUnlinesLazy . BLC8.lines | 54 | convertEndings = crlfUnlinesLazy . BLC8.lines |
51 | 55 | ||
52 | testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion | 56 | testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion |
@@ -56,8 +60,10 @@ testClearsignedDecodeSig fp target = do | |||
56 | case decodeLazy bs of | 60 | case decodeLazy bs of |
57 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | 61 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp |
58 | Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a) | 62 | Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a) |
63 | _ -> assertFailure "This shouldn't happen." | ||
59 | where | 64 | where |
60 | getSig (ClearSigned _ _ (Armor _ _ sig)) = sig | 65 | getSig (ClearSigned _ _ (Armor _ _ sig)) = sig |
66 | getSig _ = error "This should not happen." | ||
61 | 67 | ||
62 | testArmorEncode :: [FilePath] -> FilePath -> Assertion | 68 | testArmorEncode :: [FilePath] -> FilePath -> Assertion |
63 | testArmorEncode fps target = do | 69 | testArmorEncode fps target = do |
@@ -83,6 +89,7 @@ testStrictEncode fp = do | |||
83 | let fakearmors = [Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs, ClearSigned [("Hash","SHA1")] bs (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] bs)] | 89 | let fakearmors = [Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs, ClearSigned [("Hash","SHA1")] bs (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] bs)] |
84 | assertEqual ("strict encode") (encodeLazy fakearmors) (BL.fromChunks [(encode fakearmors)]) | 90 | assertEqual ("strict encode") (encodeLazy fakearmors) (BL.fromChunks [(encode fakearmors)]) |
85 | 91 | ||
92 | tests :: [Test] | ||
86 | tests = [ | 93 | tests = [ |
87 | testGroup "CRC24" [ | 94 | testGroup "CRC24" [ |
88 | testCase "CRC24: A" (testCRC24 (BC8.pack "A") 16680698) | 95 | testCase "CRC24: A" (testCRC24 (BC8.pack "A") 16680698) |
@@ -105,4 +112,5 @@ tests = [ | |||
105 | ] | 112 | ] |
106 | ] | 113 | ] |
107 | 114 | ||
115 | main :: IO () | ||
108 | main = defaultMain tests | 116 | main = defaultMain tests |