diff options
author | Clint Adams <clint@softwarefreedom.org> | 2012-04-25 16:38:48 -0400 |
---|---|---|
committer | Clint Adams <clint@softwarefreedom.org> | 2012-04-25 16:38:48 -0400 |
commit | 5ed645493e10190f7cddd753bb058e8487037549 (patch) | |
tree | 7b80971ad747ff0d1e5e6651e1efe7fe29ec6db6 /tests | |
parent | f907d986330ac5f88f9e921bdd6c0572d4691003 (diff) |
Separate ASCII armor codec into its own package, change license to ISC, and change API toward Stephen Paul Weber's proposal.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/msg1.asc | 7 | ||||
-rw-r--r-- | tests/data/msg1.gpg | bin | 0 -> 58 bytes | |||
-rw-r--r-- | tests/suite.hs | 44 |
3 files changed, 51 insertions, 0 deletions
diff --git a/tests/data/msg1.asc b/tests/data/msg1.asc new file mode 100644 index 0000000..832d3bb --- /dev/null +++ b/tests/data/msg1.asc | |||
@@ -0,0 +1,7 @@ | |||
1 | -----BEGIN PGP MESSAGE----- | ||
2 | Version: OpenPrivacy 0.99 | ||
3 | |||
4 | yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS | ||
5 | vBSFjNSiVHsuAA== | ||
6 | =njUN | ||
7 | -----END PGP MESSAGE----- | ||
diff --git a/tests/data/msg1.gpg b/tests/data/msg1.gpg new file mode 100644 index 0000000..ddb79ea --- /dev/null +++ b/tests/data/msg1.gpg | |||
Binary files differ | |||
diff --git a/tests/suite.hs b/tests/suite.hs new file mode 100644 index 0000000..272295a --- /dev/null +++ b/tests/suite.hs | |||
@@ -0,0 +1,44 @@ | |||
1 | import Test.Framework (defaultMain, testGroup) | ||
2 | import Test.Framework.Providers.HUnit | ||
3 | |||
4 | import Test.HUnit | ||
5 | |||
6 | import Codec.Encryption.OpenPGP.ASCIIArmor (armor, decodeArmor) | ||
7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | ||
8 | |||
9 | import Data.ByteString (ByteString) | ||
10 | import qualified Data.ByteString as B | ||
11 | import qualified Data.ByteString.Char8 as BC8 | ||
12 | import Data.Digest.CRC24 (crc24) | ||
13 | import Data.Word (Word32) | ||
14 | |||
15 | testCRC24 :: ByteString -> Word32 -> Assertion | ||
16 | testCRC24 bs crc = assertEqual "crc24" crc (crc24 bs) | ||
17 | |||
18 | testArmorDecode :: FilePath -> FilePath -> Assertion | ||
19 | testArmorDecode fp target = do | ||
20 | bs <- B.readFile $ "tests/data/" ++ fp | ||
21 | tbs <- B.readFile $ "tests/data/" ++ target | ||
22 | case decodeArmor bs of | ||
23 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | ||
24 | Right (Armor at hdrs pl) -> do assertEqual ("for " ++ fp) tbs pl | ||
25 | |||
26 | testArmorEncode :: FilePath -> FilePath -> Assertion | ||
27 | testArmorEncode fp target = do | ||
28 | bs <- B.readFile $ "tests/data/" ++ fp | ||
29 | tbs <- B.readFile $ "tests/data/" ++ target | ||
30 | assertEqual ("literaldata") (armor (Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs)) tbs | ||
31 | |||
32 | tests = [ | ||
33 | testGroup "CRC24" [ | ||
34 | testCase "CRC24: A" (testCRC24 (BC8.pack "A") 16680698) | ||
35 | , testCase "CRC24: Haskell" (testCRC24 (BC8.pack "Haskell") 15612750) | ||
36 | , testCase "CRC24: hOpenPGP and friends" (testCRC24 (BC8.pack "hOpenPGP and friends") 11940960) | ||
37 | ] | ||
38 | , testGroup "ASCII armor" [ | ||
39 | testCase "Decode sample armor" (testArmorDecode "msg1.asc" "msg1.gpg") | ||
40 | , testCase "Encode sample armor" (testArmorEncode "msg1.gpg" "msg1.asc") | ||
41 | ] | ||
42 | ] | ||
43 | |||
44 | main = defaultMain tests | ||