From 5ed645493e10190f7cddd753bb058e8487037549 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Wed, 25 Apr 2012 16:38:48 -0400 Subject: Separate ASCII armor codec into its own package, change license to ISC, and change API toward Stephen Paul Weber's proposal. --- tests/data/msg1.asc | 7 +++++++ tests/data/msg1.gpg | Bin 0 -> 58 bytes tests/suite.hs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/data/msg1.asc create mode 100644 tests/data/msg1.gpg create mode 100644 tests/suite.hs (limited to 'tests') 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 @@ +-----BEGIN PGP MESSAGE----- +Version: OpenPrivacy 0.99 + +yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS +vBSFjNSiVHsuAA== +=njUN +-----END PGP MESSAGE----- diff --git a/tests/data/msg1.gpg b/tests/data/msg1.gpg new file mode 100644 index 0000000..ddb79ea Binary files /dev/null and b/tests/data/msg1.gpg 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 @@ +import Test.Framework (defaultMain, testGroup) +import Test.Framework.Providers.HUnit + +import Test.HUnit + +import Codec.Encryption.OpenPGP.ASCIIArmor (armor, decodeArmor) +import Codec.Encryption.OpenPGP.ASCIIArmor.Types + +import Data.ByteString (ByteString) +import qualified Data.ByteString as B +import qualified Data.ByteString.Char8 as BC8 +import Data.Digest.CRC24 (crc24) +import Data.Word (Word32) + +testCRC24 :: ByteString -> Word32 -> Assertion +testCRC24 bs crc = assertEqual "crc24" crc (crc24 bs) + +testArmorDecode :: FilePath -> FilePath -> Assertion +testArmorDecode fp target = do + bs <- B.readFile $ "tests/data/" ++ fp + tbs <- B.readFile $ "tests/data/" ++ target + case decodeArmor bs of + Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp + Right (Armor at hdrs pl) -> do assertEqual ("for " ++ fp) tbs pl + +testArmorEncode :: FilePath -> FilePath -> Assertion +testArmorEncode fp target = do + bs <- B.readFile $ "tests/data/" ++ fp + tbs <- B.readFile $ "tests/data/" ++ target + assertEqual ("literaldata") (armor (Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs)) tbs + +tests = [ + testGroup "CRC24" [ + testCase "CRC24: A" (testCRC24 (BC8.pack "A") 16680698) + , testCase "CRC24: Haskell" (testCRC24 (BC8.pack "Haskell") 15612750) + , testCase "CRC24: hOpenPGP and friends" (testCRC24 (BC8.pack "hOpenPGP and friends") 11940960) + ] + , testGroup "ASCII armor" [ + testCase "Decode sample armor" (testArmorDecode "msg1.asc" "msg1.gpg") + , testCase "Encode sample armor" (testArmorEncode "msg1.gpg" "msg1.asc") + ] + ] + +main = defaultMain tests -- cgit v1.2.3