summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClint Adams <clint@softwarefreedom.org>2012-04-25 16:38:48 -0400
committerClint Adams <clint@softwarefreedom.org>2012-04-25 16:38:48 -0400
commit5ed645493e10190f7cddd753bb058e8487037549 (patch)
tree7b80971ad747ff0d1e5e6651e1efe7fe29ec6db6 /tests
parentf907d986330ac5f88f9e921bdd6c0572d4691003 (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.asc7
-rw-r--r--tests/data/msg1.gpgbin0 -> 58 bytes
-rw-r--r--tests/suite.hs44
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-----
2Version: OpenPrivacy 0.99
3
4yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
5vBSFjNSiVHsuAA==
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 @@
1import Test.Framework (defaultMain, testGroup)
2import Test.Framework.Providers.HUnit
3
4import Test.HUnit
5
6import Codec.Encryption.OpenPGP.ASCIIArmor (armor, decodeArmor)
7import Codec.Encryption.OpenPGP.ASCIIArmor.Types
8
9import Data.ByteString (ByteString)
10import qualified Data.ByteString as B
11import qualified Data.ByteString.Char8 as BC8
12import Data.Digest.CRC24 (crc24)
13import Data.Word (Word32)
14
15testCRC24 :: ByteString -> Word32 -> Assertion
16testCRC24 bs crc = assertEqual "crc24" crc (crc24 bs)
17
18testArmorDecode :: FilePath -> FilePath -> Assertion
19testArmorDecode 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
26testArmorEncode :: FilePath -> FilePath -> Assertion
27testArmorEncode 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
32tests = [
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
44main = defaultMain tests