summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClint Adams <clint@debian.org>2012-04-26 20:28:40 -0400
committerClint Adams <clint@debian.org>2012-04-26 20:28:40 -0400
commit8c34729c62ba64c810fbfa73719ae7f7110c0fbe (patch)
treec510a323f4c4a49cfb19ca3ba3132e8a80dc48d1 /tests
parent1ddca48c27cece9352e85ce6188f697eb9124750 (diff)
More laziness.
Diffstat (limited to 'tests')
-rw-r--r--tests/suite.hs39
1 files changed, 26 insertions, 13 deletions
diff --git a/tests/suite.hs b/tests/suite.hs
index ffe8b50..ffcbc17 100644
--- a/tests/suite.hs
+++ b/tests/suite.hs
@@ -3,7 +3,7 @@ import Test.Framework.Providers.HUnit
3 3
4import Test.HUnit 4import Test.HUnit
5 5
6import Codec.Encryption.OpenPGP.ASCIIArmor (encode, decode, multipartMerge) 6import Codec.Encryption.OpenPGP.ASCIIArmor (decode, decodeLazy, encode, encodeLazy, multipartMerge)
7import Codec.Encryption.OpenPGP.ASCIIArmor.Types 7import Codec.Encryption.OpenPGP.ASCIIArmor.Types
8import Codec.Encryption.OpenPGP.ASCIIArmor.Utils 8import Codec.Encryption.OpenPGP.ASCIIArmor.Utils
9 9
@@ -20,9 +20,9 @@ testCRC24 bs crc = assertEqual "crc24" crc (crc24 bs)
20 20
21testArmorDecode :: FilePath -> [FilePath] -> Assertion 21testArmorDecode :: FilePath -> [FilePath] -> Assertion
22testArmorDecode fp targets = do 22testArmorDecode fp targets = do
23 bs <- B.readFile $ "tests/data/" ++ fp 23 bs <- BL.readFile $ "tests/data/" ++ fp
24 tbss <- mapM (\target -> BL.readFile $ "tests/data/" ++ target) targets 24 tbss <- mapM (\target -> BL.readFile $ "tests/data/" ++ target) targets
25 case decode bs of 25 case decodeLazy bs of
26 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp 26 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
27 Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as) 27 Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as)
28 where 28 where
@@ -30,9 +30,9 @@ testArmorDecode fp targets = do
30 30
31testArmorMultipartDecode :: FilePath -> FilePath -> Assertion 31testArmorMultipartDecode :: FilePath -> FilePath -> Assertion
32testArmorMultipartDecode fp target = do 32testArmorMultipartDecode fp target = do
33 bs <- B.readFile $ "tests/data/" ++ fp 33 bs <- BL.readFile $ "tests/data/" ++ fp
34 tbs <- BL.readFile $ "tests/data/" ++ target 34 tbs <- BL.readFile $ "tests/data/" ++ target
35 case decode bs of 35 case decodeLazy bs of
36 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp 36 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
37 Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as)) 37 Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as))
38 where 38 where
@@ -40,9 +40,9 @@ testArmorMultipartDecode fp target = do
40 40
41testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion 41testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion
42testClearsignedDecodeBody fp target = do 42testClearsignedDecodeBody fp target = do
43 bs <- B.readFile $ "tests/data/" ++ fp 43 bs <- BL.readFile $ "tests/data/" ++ fp
44 tbs <- BL.readFile $ "tests/data/" ++ target 44 tbs <- BL.readFile $ "tests/data/" ++ target
45 case decode bs of 45 case decodeLazy bs of
46 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp 46 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
47 Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a) 47 Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a)
48 where 48 where
@@ -51,9 +51,9 @@ testClearsignedDecodeBody fp target = do
51 51
52testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion 52testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion
53testClearsignedDecodeSig fp target = do 53testClearsignedDecodeSig fp target = do
54 bs <- B.readFile $ "tests/data/" ++ fp 54 bs <- BL.readFile $ "tests/data/" ++ fp
55 tbs <- BL.readFile $ "tests/data/" ++ target 55 tbs <- BL.readFile $ "tests/data/" ++ target
56 case decode bs of 56 case decodeLazy bs of
57 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp 57 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
58 Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a) 58 Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a)
59 where 59 where
@@ -62,15 +62,26 @@ testClearsignedDecodeSig fp target = do
62testArmorEncode :: [FilePath] -> FilePath -> Assertion 62testArmorEncode :: [FilePath] -> FilePath -> Assertion
63testArmorEncode fps target = do 63testArmorEncode fps target = do
64 bss <- mapM (\fp -> BL.readFile $ "tests/data/" ++ fp) fps 64 bss <- mapM (\fp -> BL.readFile $ "tests/data/" ++ fp) fps
65 tbs <- B.readFile $ "tests/data/" ++ target 65 tbs <- BL.readFile $ "tests/data/" ++ target
66 assertEqual ("literaldata") tbs (encode (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss)) 66 assertEqual ("literaldata") tbs (encodeLazy (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss))
67 67
68testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion 68testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion
69testClearsignedEncode ftxt fsig ftarget = do 69testClearsignedEncode ftxt fsig ftarget = do
70 txt <- BL.readFile $ "tests/data/" ++ ftxt 70 txt <- BL.readFile $ "tests/data/" ++ ftxt
71 sig <- BL.readFile $ "tests/data/" ++ fsig 71 sig <- BL.readFile $ "tests/data/" ++ fsig
72 target <- B.readFile $ "tests/data/" ++ ftarget 72 target <- BL.readFile $ "tests/data/" ++ ftarget
73 assertEqual ("clearsigned encode") target (encode [ClearSigned [("Hash","SHA1")] txt (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] sig)]) 73 assertEqual ("clearsigned encode") target (encodeLazy [ClearSigned [("Hash","SHA1")] txt (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] sig)])
74
75testStrictDecode :: FilePath -> Assertion
76testStrictDecode fp = do
77 bs <- BL.readFile $ "tests/data/" ++ fp
78 assertEqual ("strict decode") (decodeLazy bs :: Either String [Armor]) (decode (B.concat . BL.toChunks $ bs) :: Either String [Armor])
79
80testStrictEncode :: FilePath -> Assertion
81testStrictEncode fp = do
82 bs <- BL.readFile $ "tests/data/" ++ fp
83 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)])
74 85
75tests = [ 86tests = [
76 testGroup "CRC24" [ 87 testGroup "CRC24" [
@@ -89,6 +100,8 @@ tests = [
89 , testCase "Encode sample armor" (testArmorEncode ["msg1.gpg"] "msg1.asc") 100 , testCase "Encode sample armor" (testArmorEncode ["msg1.gpg"] "msg1.asc")
90 , testCase "Encode multiple sample armors" (testArmorEncode ["msg1.gpg","msg1.gpg","msg1.gpg"] "msg1c.asc") 101 , testCase "Encode multiple sample armors" (testArmorEncode ["msg1.gpg","msg1.gpg","msg1.gpg"] "msg1c.asc")
91 , testCase "Encode clear-signed sig" (testClearsignedEncode "msg3" "msg3.sig" "msg3.asc") 102 , testCase "Encode clear-signed sig" (testClearsignedEncode "msg3" "msg3.sig" "msg3.asc")
103 , testCase "Decode from strict ByteString" (testStrictDecode "msg1.asc")
104 , testCase "Encode to strict ByteString" (testStrictEncode "msg1.gpg")
92 ] 105 ]
93 ] 106 ]
94 107